ZeppelinPluginBlueprint.configSchema is now required. Validate deep partial config schema before running config preprocessor.

This commit is contained in:
Dragory 2020-07-30 20:10:50 +03:00
parent 3265a2a8da
commit f6d55f1060
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
10 changed files with 50 additions and 12 deletions

View file

@ -5,7 +5,7 @@ import { TMarkdown } from "../types";
export interface ZeppelinPluginBlueprint<TPluginType extends BasePluginType = BasePluginType>
extends PluginBlueprint<TPluginType> {
configSchema?: t.TypeC<any>;
configSchema: t.TypeC<any>;
showInDocs?: boolean;
info?: {
@ -19,21 +19,24 @@ export interface ZeppelinPluginBlueprint<TPluginType extends BasePluginType = Ba
export function zeppelinPlugin<TPartialBlueprint extends Omit<ZeppelinPluginBlueprint, "name">>(
name: string,
blueprint: TPartialBlueprint,
): TPartialBlueprint & { name: string };
): TPartialBlueprint & { name: string; configPreprocessor: ZeppelinPluginBlueprint["configPreprocessor"] };
export function zeppelinPlugin<TPluginType extends BasePluginType>(): <
TPartialBlueprint extends Omit<ZeppelinPluginBlueprint<TPluginType>, "name">
>(
name: string,
blueprint: TPartialBlueprint,
) => TPartialBlueprint & { name: string; configPreprocessor: PluginBlueprint<TPluginType>["configPreprocessor"] };
) => TPartialBlueprint & {
name: string;
configPreprocessor: ZeppelinPluginBlueprint<TPluginType>["configPreprocessor"];
};
export function zeppelinPlugin(...args) {
if (args.length) {
const blueprint: ZeppelinPluginBlueprint = plugin(...(args as Parameters<typeof plugin>));
const blueprint = (plugin(...(args as Parameters<typeof plugin>)) as unknown) as ZeppelinPluginBlueprint;
blueprint.configPreprocessor = getPluginConfigPreprocessor(blueprint, blueprint.configPreprocessor);
return blueprint;
} else {
return zeppelinPlugin;
return zeppelinPlugin as (name, blueprint) => ZeppelinPluginBlueprint;
}
}