@quenk/preconditions
Version:
Make data satisfy constraints before using.
105 lines (104 loc) • 4.34 kB
TypeScript
import * as base from '../../';
import * as async from '../../async';
import { Maybe } from '@quenk/noni/lib/data/maybe';
import { Record } from '@quenk/noni/lib/data/record';
import { Value } from '@quenk/noni/lib/data/jsonx';
import { Type } from '@quenk/noni/lib/data/type';
import { PreconditionSpec, Schema } from '..';
import { BaseOptions, CompileContext } from '.';
/**
* Precondition specialized to jsonx values.
*/
export type Precondition = base.Precondition<Value, Value>;
/**
* Preconditions specialized to jsonx values.
*/
export type Preconditions = Record<Precondition>;
type Provide<T> = (...args: Type[]) => T;
/**
* Provider provides a precondition given some arguments.
*/
export type Provider = Provide<Precondition>;
/**
* PreconditionsAvailable is a namespaced map or a map of providers.
*/
export interface PreconditionsAvailable extends Record<Provider | Record<Provider>> {
}
/**
* Options that can be configured when compiling functions.
*/
export interface Options extends BaseOptions {
/**
* preconditions is used to resolve precondition references.
*/
preconditions: PreconditionsAvailable;
}
/**
* @internal
*/
export declare const defaultAvailables: PreconditionsAvailable;
/**
* FunctionContext is used for compilation of a schema to a synchronous
* precondition function.
*/
export declare class FunctionContext extends CompileContext<Precondition, Options> {
identity: <A>(value: A) => import("../../result").Result<A, A>;
optional: <A, B>(p: base.Precondition<A, A | B>) => base.Precondition<A, A | B>;
and: <A, B, C>(l: base.Precondition<A, B>, r: base.Precondition<B, C>) => base.Precondition<A, C>;
or: <A, B>(left: base.Precondition<A, B>, right: base.Precondition<A, B>) => base.Precondition<A, B>;
properties: (props: Preconditions, addProps?: Precondition) => base.Precondition<Value, Value>;
items: (prec: Precondition) => Precondition;
get: (spec: PreconditionSpec<Precondition>) => Maybe<Precondition>;
}
/**
* compile a schema into a single precondition function.
*/
export declare const compile: (opts: Partial<Options>, schema: Schema) => import("@quenk/noni/lib/control/except").Except<Precondition>;
/**
* AsyncPrecondition specialized to jsonx values.
*/
export type AsyncPrecondition = async.AsyncPrecondition<Value, Value>;
/**
* AsyncPreconditions specialized to jsonx values.
*/
export type AsyncPreconditions = Record<AsyncPrecondition>;
/**
* AsyncProvider provides an async precondition given some arguments.
*/
export type AsyncProvider = (...args: Type[]) => AsyncPrecondition;
/**
* AsyncOptions used for async precondition compilation.
*/
export interface AsyncOptions extends BaseOptions {
/**
* asyncPreconditions is used to resolve async precondition
* references.
*/
asyncPreconditions: AsyncPreconditionsAvailable;
}
/**
* AsyncPreconditionsAvailable is a namespaced map or a map of async providers.
*/
export interface AsyncPreconditionsAvailable extends Record<AsyncProvider | Record<AsyncProvider>> {
}
/**
* AsyncFunctionContext is used for compilation of a schema to an async
* precondition function.
*/
export declare class AsyncFunctionContext extends CompileContext<AsyncPrecondition, AsyncOptions> {
identity: <A>(value: A) => import("@quenk/noni/lib/control/monad/future").Future<import("../../result").Result<A, A>>;
optional: <A, B>(p: async.AsyncPrecondition<A, A | B>) => async.AsyncPrecondition<A, A | B>;
and: <A, B, C>(l: async.AsyncPrecondition<A, B>, r: async.AsyncPrecondition<B, C>) => async.AsyncPrecondition<A, C>;
or: <A, B>(l: async.AsyncPrecondition<A, B>, r: async.AsyncPrecondition<A, B>) => async.AsyncPrecondition<A, B>;
properties: (asyncProps: AsyncPreconditions, addProps?: AsyncPrecondition) => async.AsyncPrecondition<Value, Value>;
items: (prec: AsyncPrecondition) => AsyncPrecondition;
get: (spec: PreconditionSpec<AsyncPrecondition>) => Maybe<AsyncPrecondition>;
}
/**
* compileAsync a schema into a single async precondition function.
*
* This function disables builtins and changes the default precondition key to
* "asyncPreconditions".
*/
export declare const compileAsync: (opts: Partial<AsyncOptions>, schema: Schema) => import("@quenk/noni/lib/control/except").Except<AsyncPrecondition>;
export {};