mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-18 15:45:03 +00:00
Typing fixes; show last reload time in !about
This commit is contained in:
parent
d6599c78b7
commit
24afc0a503
26 changed files with 154 additions and 75 deletions
|
@ -1,7 +1,42 @@
|
|||
import * as t from "io-ts";
|
||||
import { pipe } from "fp-ts/lib/pipeable";
|
||||
import { fold } from "fp-ts/lib/Either";
|
||||
import { PathReporter } from "io-ts/lib/PathReporter";
|
||||
import { noop } from "./utils";
|
||||
|
||||
// From io-ts/lib/PathReporter
|
||||
function stringify(v) {
|
||||
if (typeof v === "function") {
|
||||
return t.getFunctionName(v);
|
||||
}
|
||||
if (typeof v === "number" && !isFinite(v)) {
|
||||
if (isNaN(v)) {
|
||||
return "NaN";
|
||||
}
|
||||
return v > 0 ? "Infinity" : "-Infinity";
|
||||
}
|
||||
return JSON.stringify(v);
|
||||
}
|
||||
|
||||
// From io-ts/lib/PathReporter
|
||||
// tslint:disable
|
||||
function getContextPath(context) {
|
||||
return context
|
||||
.map(function(_a) {
|
||||
var key = _a.key,
|
||||
type = _a.type;
|
||||
return key + ": " + type.name;
|
||||
})
|
||||
.join("/");
|
||||
}
|
||||
// tslint:enable
|
||||
|
||||
const report = fold((errors: any) => {
|
||||
return errors.map(err => {
|
||||
if (err.message) return err.message;
|
||||
const context = err.context.map(c => c.key).filter(k => k && !k.startsWith("{"));
|
||||
return `Invalid value <${stringify(err.value)}> supplied to <${context.join("/")}>`;
|
||||
});
|
||||
}, noop);
|
||||
|
||||
/**
|
||||
* Validates the given value against the given schema while also disallowing extra properties
|
||||
|
@ -12,7 +47,7 @@ export function validateStrict(schema: t.Type<any, any, any>, value: any): strin
|
|||
return pipe(
|
||||
validationResult,
|
||||
fold(
|
||||
err => PathReporter.report(validationResult),
|
||||
err => report(validationResult),
|
||||
result => {
|
||||
// Make sure there are no extra properties
|
||||
if (JSON.stringify(value) !== JSON.stringify(result)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue