flowjv
Version:
Flow based approach to JSON validation!
38 lines (37 loc) • 2.77 kB
TypeScript
import { IKeyPath } from "../helper/immutable";
export declare type IJSONExpression<IData = any, IContext = any> = number | string | boolean | IOperation<IData, IContext> | IFunctionExectution<IData, IContext> | {
func: IFunctionExectution<IData, IContext>;
deps: {
data?: string[];
context?: string[];
};
};
declare type IFunctionExectution<IData, IContext> = ({ data, context, ref, }: {
data: Partial<IData>;
context: IContext;
ref: any;
}) => any;
export declare type IOperation<IData = any, IContext = any> = IDataAccessOperation<IData, IContext> | ITernaryOperation | INegationOperation | ILogicalOperation | IComparisonOperation | INumberOperation | IStringOperation;
export declare type IDataAccessOperation<IData, IContext> = ["$data", string, string?] | ["$context", string, string?] | ["$ref"];
export declare type ITernaryOperation = [
"?:",
IJSONExpression,
IJSONExpression,
IJSONExpression
];
export declare type INegationOperation = ["!", IJSONExpression];
export declare type ILogicalOperation = ["enum", IJSONExpression, ...IJSONExpression[]] | ["===", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["!==", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["||", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["&&", IJSONExpression, IJSONExpression, ...IJSONExpression[]];
export declare type IComparisonOperation = [">", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | [">=", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["<", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["<=", IJSONExpression, IJSONExpression, ...IJSONExpression[]];
export declare type INumberOperation = ["+", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["-", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["*", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["/", IJSONExpression, IJSONExpression, ...IJSONExpression[]] | ["%", IJSONExpression, IJSONExpression, ...IJSONExpression[]];
export declare type IStringOperation = ["str:fmt:email", IJSONExpression] | ["str:len", IJSONExpression];
export interface IJSONExpressionData<IData, IContext> {
data?: IData;
context?: IContext;
refPath?: IKeyPath;
}
declare type IJSONExpressionReturnType = string | number | boolean | null;
export declare const execJSONExpression: <IData = any, IContext = any>(logic: IJSONExpression<IData, IContext>, data: IJSONExpressionData<IData, IContext>) => IJSONExpressionReturnType;
export declare type IDependsOn = string[];
export declare function getDependencies(expr: IJSONExpression): IDependsOn | null;
export declare function combineDependencies(d1: IDependsOn | null, d2: IDependsOn | null): string[] | null;
export {};