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

Switch from ajv to io-ts for config validation; validate configs on save in the API/dashboard; start work on creating io-ts schemas for all plugins

This commit is contained in:
Dragory 2019-07-11 12:23:57 +03:00
parent 1ecce52973
commit 3f4724b699
14 changed files with 256 additions and 41 deletions

View file

@ -0,0 +1,39 @@
import { GlobalPlugin, IBasePluginConfig, IPluginOptions, logger } from "knub";
import { PluginRuntimeError } from "../PluginRuntimeError";
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 { isSnowflake, isUnicodeEmoji, resolveMember, resolveUser, UnknownUser } from "../utils";
import { Member, User } from "eris";
import { performance } from "perf_hooks";
import { validateStrict } from "../validatorUtils";
const SLOW_RESOLVE_THRESHOLD = 1500;
export class GlobalZeppelinPlugin<TConfig extends {} = IBasePluginConfig> extends GlobalPlugin<TConfig> {
protected static configSchema: t.TypeC<any>;
public static dependencies = [];
public static validateOptions(options: IPluginOptions): string[] | null {
// Validate config values
if (this.configSchema) {
if (options.config) {
const errors = validateStrict(this.configSchema, options.config);
if (errors) return errors;
}
if (options.overrides) {
for (const override of options.overrides) {
if (override.config) {
const errors = validateStrict(this.configSchema, override.config);
if (errors) return errors;
}
}
}
}
// No errors, return null
return null;
}
}