3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-18 07:35:02 +00:00

Configs are not decoded as well as validated by io-ts. Improvements to config validation, error messages, and TSafeRegex type.

This commit is contained in:
Dragory 2019-08-04 15:44:41 +03:00
parent 2163d43dd1
commit 242bfe2b39
5 changed files with 223 additions and 74 deletions

View file

@ -37,7 +37,7 @@ export const MINUTES = 60 * SECONDS;
export const HOURS = 60 * MINUTES;
export const DAYS = 24 * HOURS;
export function tNullable(type: t.Mixed) {
export function tNullable<T extends t.Type<any, any, unknown>>(type: T) {
return t.union([type, t.undefined, t.null]);
}
@ -574,6 +574,19 @@ export class UnknownUser {
}
}
export function deepKeyIntersect(obj, keyReference) {
const result = {};
for (const [key, value] of Object.entries(obj)) {
if (!keyReference.hasOwnProperty(key)) continue;
if (value != null && typeof value === "object" && typeof keyReference[key] === "object") {
result[key] = deepKeyIntersect(value, keyReference[key]);
} else {
result[key] = value;
}
}
return result;
}
const unknownUsers = new Set();
const unknownMembers = new Set();