import { TypeLevel } from "@tsplus/stdlib/type-level"; import { Either } from "@tsplus/stdlib/data/Either/definition"; declare const validSym: unique symbol; declare const namedSym: unique symbol; /** * @tsplus derive nominal */ export interface Brand { [namedSym]: { [k in K]: K; }; } export declare namespace Brand { type valid = typeof validSym; type name = typeof namedSym; type Validated = A & Brand.Valid; /** * @tsplus derive nominal */ interface Valid { [validSym]: { [k in K]: A; }; } type IsValidated

> = { [k in keyof P[Brand.valid]]: P extends P[Brand.valid][k] ? 0 : 1; }[keyof P[Brand.valid]] extends 0 ? unknown : never; type Unbranded

= P extends infer Q & Brands

? Q : P; type Unnamed

= P extends infer Q & Names

? Q : P; type Brands

= P extends Valid ? TypeLevel.UnionToIntersection<{ [k in keyof P[Brand.valid]]: P extends P[Brand.valid][k] ? k extends string ? Valid : never : never; }[keyof P[Brand.valid]]> : unknown; type Names

= P extends Brand ? TypeLevel.UnionToIntersection<{ [k in keyof P[Brand.name]]: k extends string ? Brand : never; }[keyof P[Brand.name]]> : unknown; interface FailedValidation { readonly _tag: "FailedValidation"; readonly brands: string[]; readonly message: string; } /** * @tsplus type Brand.MakeValidated * @tsplus derive nominal */ interface MakeValidated { make: (value: Unnamed>) => Either; unsafeMake: (value: Unnamed>) => A; } /** * @tsplus type Brand.Make * @tsplus derive nominal */ interface Make { make: (value: Unnamed>) => A; } /** * @tsplus type Brand.Validation * @tsplus derive nominal */ interface Validation { readonly validate: (a: A) => a is A & Brand.Valid; } type ValidatedWith> = X extends Validation ? Validated : never; /** * @tsplus type Brand/Ops */ interface Ops { readonly validation: (predicate: (a: A) => boolean) => Brand.Validation; } } export declare function validation(predicate: (a: A) => boolean): Brand.Validation; export declare const Brand: Brand.Ops; export declare class FailedValidationException extends Error implements Brand.FailedValidation { readonly brands: string[]; readonly _tag = "FailedValidation"; constructor(brands: string[]); } export declare class FailedValidationError implements Brand.FailedValidation { readonly brands: string[]; readonly _tag = "FailedValidation"; constructor(brands: string[]); get message(): string; } export type MinLen = Brand.Valid<{ length: number; }, `MinLen(${N})`>; export type MaxLen = Brand.Valid<{ length: number; }, `MaxLen(${N})`>; export type RangeLen = MinLen & MaxLen; /** * @tsplus derive Brand.Validation<_, _> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMinLenValidation(...[min]: V extends `MinLen(${infer N extends number})` ? [N] : never): Brand.Validation; /** * @tsplus derive Brand.Validation<_, _> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMaxLenValidation(...[max]: V extends `MaxLen(${infer N extends number})` ? [N] : never): Brand.Validation; export type Regex = Brand.Validated; /** * @tsplus derive Brand.Validation<_, _> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveRegexValidation(...[regexStr]: V extends `Regex(${infer R extends string})` ? [R] : never): Brand.Validation; export type Min = Brand.Validated; export type Max = Brand.Validated; export type Range = Min & Max; /** * @tsplus derive Brand.Validation<_, _> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMinValidation(...[min]: V extends `Min(${infer N extends number})` ? [N] : never): Brand.Validation; /** * @tsplus derive Brand.Validation<_, _> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMaxValidation(...[max]: V extends `Max(${infer N extends number})` ? [N] : never): Brand.Validation; /** * @tsplus derive Brand.MakeValidated<_> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMakeMakeValidated(...[brands]: [ brands: A extends Brand.Valid ? { [k in (keyof A[Brand.valid]) & string]: Brand.Validation; } : {} ]): Brand.MakeValidated; /** * @tsplus derive Brand.Make<_> 10 * @tsplus location "@tsplus/runtime/Brand" */ export declare function deriveMake(..._: []): Brand.Make; /** * @tsplus implicit * @tsplus location "@tsplus/runtime/Brand" */ export declare const Positive: Brand.Validation; export type Positive = Brand.ValidatedWith; /** * @tsplus implicit * @tsplus location "@tsplus/runtime/Brand" */ export declare const Int: Brand.Validation; export type Int = Brand.ValidatedWith; /** * @tsplus implicit * @tsplus location "@tsplus/runtime/Brand" */ export declare const Finite: Brand.Validation; export type Finite = Brand.ValidatedWith; /** * @tsplus implicit * @tsplus location "@tsplus/runtime/Brand" */ export declare const UUID: Brand.Validation; export type UUID = Brand.ValidatedWith; export {}; //# sourceMappingURL=Brand.d.ts.map