/** * @since 1.0.0 */ import * as Either from "@fp-ts/core/Either"; import * as Option from "@fp-ts/core/Option"; import type { Predicate, Refinement } from "@fp-ts/core/Predicate"; /** * @since 1.0.0 * @category symbols */ export declare const BrandTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type BrandTypeId = typeof BrandTypeId; /** * @since 1.0.0 * @category symbols */ export declare const NominalConstructorTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type NominalConstructorTypeId = typeof NominalConstructorTypeId; /** * @since 1.0.0 * @category symbols */ export declare const RefinedConstructorsTypeId: unique symbol; /** * @since 1.0.0 * @category symbols */ export type RefinedConstructorsTypeId = typeof RefinedConstructorsTypeId; /** * @since 1.0.0 * @category models */ export interface Brand { readonly [BrandTypeId]: { readonly [k in K]: K; }; } /** * @since 1.0.0 */ export declare namespace Brand { /** * @since 1.0.0 * @category models */ interface BrandErrors extends ReadonlyArray { } /** * @since 1.0.0 * @category models */ interface RefinementError { readonly meta: unknown; readonly message: string; } /** * @since 1.0.0 * @category models */ type Constructor> = Brand.NominalConstructor | Brand.RefinedConstructors; /** * @since 1.0.0 * @category models */ interface NominalConstructor> { readonly [NominalConstructorTypeId]: NominalConstructorTypeId; /** * Constructs a branded type from a value of type `A`. */ (args: Omit, BrandTypeId>): A; } /** * @since 1.0.0 * @category models */ interface RefinedConstructors> { readonly [RefinedConstructorsTypeId]: RefinedConstructorsTypeId; /** * Constructs a branded type from a value of type `A`, throwing an error if * the provided `A` is not valid. */ of: (args: Brand.Unbranded) => A; /** * Constructs a branded type from a value of type `A`, returning `Some` * if the provided `A` is valid, `None` otherwise. */ option: (args: Brand.Unbranded) => Option.Option; /** * Constructs a branded type from a value of type `A`, returning `Right` * if the provided `A` is valid, `Left` otherwise. */ either: (args: Brand.Unbranded) => Either.Either; /** * Attempts to refine the provided value of type `A`, returning `true` if * the provided `A` is valid, `false` otherwise. */ refine: Refinement, Brand.Unbranded & A>; } /** * A utility type to extract a branded type from a `Brand.Constructor`. * * @since 1.0.0 * @category models */ type FromConstructor = A extends Brand.Constructor ? B : never; /** * A utility type to extract the value type from a brand. * * @since 1.0.0 * @category models */ type Unbranded

= P extends infer Q & Brands

? Q : P; /** * A utility type to extract the brands from a branded type. * * @since 1.0.0 * @category models */ type Brands

= P extends Brand ? Brand.UnionToIntersection<{ [k in keyof P[BrandTypeId]]: k extends string ? Brand : never; }[keyof P[BrandTypeId]]> : never; /** * @since 1.0.0 * @category models */ type EnsureCommonBase, ...Array>]> = { [B in keyof Brands]: Brand.Unbranded> extends Brand.Unbranded> ? Brand.Unbranded> extends Brand.Unbranded> ? Brands[B] : Brands[B] : "ERROR: All brands should have the same base type"; }; /** * @since 1.0.0 * @category models */ type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; } /** * @since 1.0.0 * @category constructors */ export declare const error: (message: string, meta?: unknown) => Brand.BrandErrors; /** * @since 1.0.0 * @category constructors */ export declare const errors: (...errors: Array) => Brand.BrandErrors; /** * Returns `true` if the provided `Brand` is nominal, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isNominal: >(u: Brand.Constructor) => u is Brand.NominalConstructor; /** * Returns `true` if the provided `Brand` is refined, `false` otherwise. * * @since 1.0.0 * @category refinements */ export declare const isRefined: >(u: Brand.Constructor) => u is Brand.RefinedConstructors; /** * @since 1.0.0 * @category constructors */ export declare const nominal: >() => Brand.NominalConstructor; /** * @since 1.0.0 * @category constructors */ export declare const refined: >(refinement: Predicate>, onFailure: (a: Brand.Unbranded) => Brand.BrandErrors) => Brand.RefinedConstructors; /** * Composes two brands together to form a single branded type. * * @since 1.0.0 * @category mutations */ export declare const all: , ...Brand.Constructor[]]>(...brands: Brand.EnsureCommonBase) => Brand.RefinedConstructors; }[number]> extends infer X extends Brand ? X : Brand>; //# sourceMappingURL=Brand.d.ts.map