UNPKG

@rbxts/rotype

Version:

Advanced runtime type checking library

44 lines (43 loc) 3.11 kB
import { Ctx } from "../context"; import { Issue } from "../errors"; import { Result } from "../result"; import type { InferInput, InferOutput, Schema } from "../schema"; export type Action<I, O> = (data: I, ctx: Ctx) => Result<O, Issue[]>; export declare function Pipe<I, O>(schema: Schema<I, O>, ...actions: Action<O, any>[]): Schema<I, any>; export declare function Trim(): Action<string, string>; export declare function TrimStart(): Action<string, string>; export declare function TrimEnd(): Action<string, string>; export declare function Regex(pat: string, message?: string): Action<string, string>; export declare function MinLength(min: number): Action<string | Array<unknown>, any>; export declare function MaxLength(max: number): Action<string | Array<unknown>, any>; export declare function NonEmpty(): Action<string | Array<unknown>, any>; export declare function ToLowerCase(): Action<string, string>; export declare function ToUpperCase(): Action<string, string>; export declare function MinValue(min: number): Action<number, number>; export declare function MaxValue(max: number): Action<number, number>; export declare function MultipleOf(step: number): Action<number, number>; export declare function Integer(): Action<number, number>; export declare function Finite(): Action<number, number>; export declare function Transform<I, O>(fn: (v: I) => O): Action<I, O>; export declare function Check<I>(predicate: (v: I) => boolean, message?: string): Action<I, I>; export declare function Record<VS extends Schema<any, any>>(valueSchema: VS): Schema<Record<string, InferInput<VS>>, Record<string, InferOutput<VS>>>; export declare function Intersection<A extends Schema<any, any>, B extends Schema<any, any>>(a: A, b: B): Schema<InferInput<A> & InferInput<B>, InferOutput<A> & InferOutput<B>>; export declare function Merge<A extends Schema<Record<string, any>, any>, B extends Schema<Record<string, any>, any>>(a: A, b: B): Schema<InferInput<A> & InferInput<B>, InferOutput<A> & InferOutput<B>>; export declare function Enumerations<T extends readonly string[]>(values: T): Schema<T[number]>; export type Brand<B extends string, T> = T & { readonly __brand: B; }; export type Flavor<F extends string, T> = T & { readonly __flavor?: F; }; export declare function Brand<B extends string>(_: B): Action<any, Brand<B, any>>; export declare function Flavor<F extends string>(_: F): Action<any, Flavor<F, any>>; export declare function ReadonlyAction<T>(): Action<T, Readonly<T>>; export { ReadonlyAction as readonly }; export declare function RawTransform<I, O>(fn: (v: I, ctx: Ctx) => Result<O, Issue[]>): Action<I, O>; export declare function ToMinValue(min: number): Action<number, number>; export declare function ToMaxValue(max: number): Action<number, number>; export declare function Clamp(min: number, max: number): Action<number, number>; export declare function Abs(): Action<number, number>; export declare function DeepPartial<S extends Schema<any, any>>(schema: S): Schema<any, any>; export declare function DeepRequired<S extends Schema<any, any>>(schema: S): Schema<any, any>;