import * as Option from "./Option.ts"; import * as Result from "./Result.ts"; import type * as Schema from "./Schema.ts"; import * as AST from "./SchemaAST.ts"; import type * as Issue from "./SchemaIssue.ts"; import type * as Types from "./Types.ts"; declare const TypeId = "~effect/Brand"; /** * A generic interface that defines a branded type. * * @since 2.0.0 * @category models */ export interface Brand { readonly [TypeId]: { readonly [K in Keys]: Keys; }; } /** * A constructor for a branded type that provides validation and safe * construction methods. * * @category models * @since 2.0.0 */ export interface Constructor> { /** * Constructs a branded type from a value of type `Unbranded`, throwing an * error if the provided value is not valid. */ (unbranded: Brand.Unbranded): B; /** * Constructs a branded type from a value of type `Unbranded`, returning * `Some` if the provided value is valid, `None` otherwise. */ option(unbranded: Brand.Unbranded): Option.Option; /** * Constructs a branded type from a value of type `Unbranded`, returning * `Success` if the provided value is valid, `Failure` * otherwise. */ result(unbranded: Brand.Unbranded): Result.Result; /** * Attempts to refine the provided value of type `Unbranded`, returning * `true` if the provided value is a valid branded type, `false` otherwise. */ is(unbranded: Brand.Unbranded): unbranded is Brand.Unbranded & B; } /** * A `BrandError` is returned when a branded type is constructed from an invalid * value. * * @category models * @since 4.0.0 */ export declare class BrandError { constructor(issue: Issue.Issue); /** * @since 4.0.0 */ readonly _tag = "BrandError"; /** * @since 4.0.0 */ readonly name: string; /** * @since 4.0.0 */ readonly issue: Issue.Issue; /** * @since 4.0.0 */ get message(): string; /** * @since 4.0.0 */ toString(): string; } /** * @since 2.0.0 */ export declare namespace Brand { /** * A utility type to extract a branded type from a `Constructor`. * * @since 2.0.0 */ type FromConstructor = C extends Constructor ? B : never; /** * A utility type to extract the unbranded value type from a brand. * * @since 2.0.0 */ type Unbranded> = B extends infer U & Brands ? U : B; /** * A utility type to extract the keys of a branded type. * * @since 2.0.0 */ type Keys> = keyof B[typeof TypeId]; /** * A utility type to extract the brands from a branded type. * * @since 2.0.0 */ type Brands> = Types.UnionToIntersection<{ [K in Keys]: K extends string ? Brand : never; }[Keys]>; /** * A utility type that checks that all brands have the same base type. * * @since 2.0.0 */ 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"; }; } /** * A type alias for creating branded types more concisely. * * @category alias * @since 2.0.0 */ export type Branded = A & Brand; /** * This function returns a `Constructor` that **does not apply any runtime * checks**, it just returns the provided value. It can be used to create * nominal types that allow distinguishing between two values of the same type * but with different meanings. * * If you also want to perform some validation, see {@link make} or * {@link check} or {@link refine}. * * @category constructors * @since 2.0.0 */ export declare function nominal>(): Constructor; /** * Returns a `Constructor` that can construct a branded type from an * unbranded value using the provided `filter` predicate as validation of * the input data. * * If you don't want to perform any validation but only distinguish between two * values of the same type but with different meanings, see {@link nominal}. * * @category constructors * @since 2.0.0 */ export declare function make>(filter: (unbranded: Brand.Unbranded) => Schema.FilterOutput): Constructor; /** * @since 4.0.0 */ export declare function check>(...checks: readonly [ AST.Check>, ...Array>> ]): Constructor; /** * Combines two or more brands together to form a single branded type. This API * is useful when you want to validate that the input data passes multiple brand * validators. * * @category combining * @since 2.0.0 */ export declare function all, ...Array>]>(...brands: Brand.EnsureCommonBase): Constructor; }[number]> extends infer X extends Brand ? X : Brand>; export {}; //# sourceMappingURL=Brand.d.ts.map