@quenk/preconditions
Version:
Make data satisfy constraints before using.
39 lines (38 loc) • 1.41 kB
TypeScript
import { Record } from '@quenk/noni/lib/data/record';
import { BaseOptions, CompileContext } from '.';
import { PreconditionSpec, Schema } from '..';
/**
* Code output.
*/
export type Code = string;
export interface Options extends BaseOptions {
/**
* async if true, changes the default options to be suitable for generating
* an async precondition.
*
* Builtins are disabled and the default key name is changed to
* "asyncPreconditions". For function compilation, the async functions are
* used instead of the regular ones. Defaults to false.
*/
async: boolean;
}
/**
* StringContext is used for compilation of a schema to a synchronous
* precondition string of code.
*/
export declare class StringContext extends CompileContext<Code> {
identity: string;
optional: (code: Code) => string;
and: (left: Code, right: Code) => string;
or: (left: Code, right: Code) => string;
properties: (props: Record<Code>, addProps?: string) => string;
items: (prec: Code) => string;
get: (spec: PreconditionSpec<Code>) => import("@quenk/noni/lib/data/maybe").Maybe<string>;
}
/**
* compile a schema into a string.
*
* This function produces a string that can be used for code generation from
* templates.
*/
export declare const compile: (opts: Partial<Options>, schema: Schema) => import("@quenk/noni/lib/control/except").Except<string>;