flowjv
Version:
Flow based approach to JSON validation!
42 lines (41 loc) • 1.82 kB
TypeScript
import type { IFlowConfig, IPayload, IValidation } from "../helper";
import type { IKeyPath } from "../../../helper/immutable";
export interface ISimpleCommon<IData = {}, IContext = {}> {
isRequired?: boolean;
validations?: IValidation<IData, IContext>[];
errMsgs?: {
type?: string;
required?: string;
};
}
export declare type ISimpleStringType<IData = {}, IContext = {}, uiType = {}> = uiType & {
type: "string";
label?: string;
} & ISimpleCommon<IData, IContext>;
export declare type ISimpleNumberType<IData = {}, IContext = {}, uiType = {}> = uiType & {
type: "number";
label?: string;
} & ISimpleCommon<IData, IContext>;
export declare type ISimpleBooleanType<IData = {}, IContext = {}, uiType = {}> = uiType & {
type: "boolean";
label?: string;
} & ISimpleCommon<IData, IContext>;
export declare type ISimpleEnumType<IData = {}, IContext = {}, uiType = {}> = uiType & {
type: "enum";
label?: string;
items: {
label?: string;
value: any;
}[];
} & ISimpleCommon<IData, IContext>;
export declare type ISimpleCustomType<IData = {}, IContext = {}, uiType = {}> = uiType & {
type: "custom";
} & ISimpleCommon<IData, IContext>;
export declare type ISimpleType<IData = {}, IContext = {}, stringUI = {}, numberUI = {}, booleanUI = {}, enumUI = {}, customUI = {}> = ISimpleStringType<IData, IContext, stringUI> | ISimpleNumberType<IData, IContext, numberUI> | ISimpleBooleanType<IData, IContext, booleanUI> | ISimpleEnumType<IData, IContext, enumUI> | ISimpleCustomType<IData, IContext, customUI>;
export declare type ISimplePayload = IPayload & {
refPath: IKeyPath;
};
export declare function validateSimpleType(schema: ISimpleType, payload: ISimplePayload, config: IFlowConfig): {
isValid: boolean;
errors: string[];
};