import { Pattern, TagUnion } from './match'; import { SimpleNominal } from './Nominal'; import { Result } from './Result'; import { TaggedUnion } from './TaggedUnion'; declare type InferType> = A['_raw']; declare type UnknownNominal = SimpleNominal; declare type Match = (pattern: Pattern<'tag', ADT, A>) => (adt: ADT) => A; export declare type Refined = { /** * **Use at own risk.** * * Favour `from` unless you are certain the data conforms to the correct structure. */ unsafeFrom: (a: InferType) => A; from: (a: InferType) => Result; is: (a: InferType) => a is A; handleError: Match; }; export declare const refine: (p: (a: InferType) => Result>) => Refined; export declare namespace Refined { namespace Boolean { export type And, R extends Refined> = Refined>; export const And: , R extends Refined>(l: L, r: R) => And; export type Or, R extends Refined> = Refined | ExtractError>; export const Or: , R extends Refined>(l: L, r: R) => Or; type ExtractError = A extends Refined ? E : never; export {}; } namespace String { type StringNominal = SimpleNominal; export type MatchesRegex = Refined; export namespace MatchesRegex { type E = TaggedUnion<{ MatchesRegexError: {}; }>; const E: { tag: "MatchesRegexError"; }; const refinement: (s: RegExp) => MatchesRegex; } export {}; } namespace Iterable { type IterableNominal = SimpleNominal>; export type MinLength = Refined & { minLength: number; }; export namespace MinLength { type E = TaggedUnion<{ MinLengthError: { minLength: number; }; }>; const E: (args: import("./TaggedUnion").UntaggedMember<{ tag: "MinLengthError"; minLength: number; }, "MinLengthError">) => { tag: "MinLengthError"; minLength: number; }; const refinement: (minLength: number) => MinLength; } export type MaxLength = Refined & { maxLength: number; }; export namespace MaxLength { type E = TaggedUnion<{ MaxLengthError: { maxLength: number; }; }>; const E: (args: import("./TaggedUnion").UntaggedMember<{ tag: "MaxLengthError"; maxLength: number; }, "MaxLengthError">) => { tag: "MaxLengthError"; maxLength: number; }; const refinement: (maxLength: number) => MaxLength; } export type MinMaxLength = Refined.Boolean.And, MaxLength> & { minLength: number; maxLength: number; }; export namespace MinMaxLength { const refinement: (minLength: number, maxLength: number) => MinMaxLength; } export {}; } namespace Number { type NumberNominal = SimpleNominal; export type Less = Refined & { max: number; }; export namespace Less { type E = TaggedUnion<{ LessError: {}; }>; const E: { tag: "LessError"; }; const refinement: (max: number) => Less; } export type LessEqual = Refined & { max: number; }; export namespace LessEqual { type E = TaggedUnion<{ LessEqualError: {}; }>; const E: { tag: "LessEqualError"; }; const refinement: (max: number) => LessEqual; } export type Greater = Refined & { min: number; }; export namespace Greater { type E = TaggedUnion<{ GreaterError: {}; }>; const E: { tag: "GreaterError"; }; const refinement: (min: number) => Greater; } export type GreaterEqual = Refined & { min: number; }; export namespace GreaterEqual { type E = TaggedUnion<{ GreaterEqualError: {}; }>; const E: { tag: "GreaterEqualError"; }; const refinement: (min: number) => GreaterEqual; } export namespace Bounds { type Inclusive = Boolean.And, LessEqual> & { min: number; max: number; }; const Inclusive: (min: number, max: number) => Inclusive; type Exclusive = Boolean.And, Less> & { min: number; max: number; }; const Exclusive: (min: number, max: number) => Exclusive; type LowerInclusiveUpperExclusive = Boolean.And, Less> & { min: number; max: number; }; const LowerInclusiveUpperExclusive: (min: number, max: number) => LowerInclusiveUpperExclusive; type LowerExclusiveUpperInclusive = Boolean.And, LessEqual> & { min: number; max: number; }; const LowerExclusiveUpperInclusive: (min: number, max: number) => LowerExclusiveUpperInclusive; } export {}; } } export {};