/** * Represents Effect schemas as runtime trees. * * Every `Schema` has an AST made from nodes for declarations, primitives, * literals, arrays, objects, unions, suspended schemas, checks, annotations, * encoding links, and parsing context. Most users work with the higher-level * `Schema` module. Use `SchemaAST` when you need to inspect schema nodes, build * ASTs programmatically, change encoded or decoded views, collect issues, or * run low-level schema checks. * * @stability stable * @since 4.0.0 */ import * as Effect from "./Effect.ts"; import * as Pipeable from "./Pipeable.ts"; import type * as Schema from "./Schema.ts"; import * as SchemaIssue from "./SchemaIssue.ts"; import * as SchemaTransformation from "./SchemaTransformation.ts"; import type * as Types from "./Types.ts"; /** * Discriminated union of all AST node types. * * **Details** * * Every `Schema` has an `.ast` property of this type. Use the guard functions * ({@link isString}, {@link isObjects}, etc.) to narrow to a specific variant, * then access variant-specific fields. * * - All variants share the `annotations`, `checks`, `encoding`, and `context` * fields. * - Discriminate on the `_tag` field (e.g. `"String"`, `"Objects"`, `"Union"`). * * @see {@link isAST} * @stability stable * @category models * @since 4.0.0 */ export type AST = Declaration | Null | Undefined | Void | Never | Unknown | Any | String | Number | Boolean | BigInt | Symbol | Literal | UniqueSymbol | ObjectKeyword | Enum | TemplateLiteral | Arrays | Objects | Union | Suspend; /** * Returns `true` if the value is an {@link AST} node (any variant). * * **Details** * * Uses the internal `TypeId` brand to distinguish AST nodes from arbitrary * objects. * * @see {@link AST} * @stability stable * @category guards * @since 4.0.0 */ export declare function isAST(u: unknown): u is AST; /** * Narrows an {@link AST} to {@link Declaration}. * * **When to use** * * Use to recognize declaration AST nodes before running declaration-specific * handling. * * @see {@link Declaration} for the AST node type narrowed by this guard * * @stability stable * @category guards * @since 3.10.0 */ export declare const isDeclaration: (ast: AST) => ast is Declaration; /** * Narrows an {@link AST} to {@link Null}. * * **When to use** * * Use to recognize an AST node that represents exactly the `null` literal when * inspecting, traversing, or transforming schema ASTs. * * @see {@link Null} for the AST node type narrowed by this guard * @see {@link null_ null} for the singleton `Null` AST instance * @see {@link isLiteral} for exact primitive literal AST nodes * * @stability stable * @category guards * @since 4.0.0 */ export declare const isNull: (ast: AST) => ast is Null; /** * Narrows an {@link AST} to {@link Undefined}. * * **When to use** * * Use to identify AST nodes that represent exactly the JavaScript `undefined` * value. * * @see {@link isVoid} for narrowing AST nodes that represent TypeScript `void` instead of exact `undefined` * * @stability stable * @category guards * @since 4.0.0 */ export declare const isUndefined: (ast: AST) => ast is Undefined; /** * Narrows an {@link AST} to {@link Void}. * * **When to use** * * Use to identify AST nodes that represent the TypeScript `void` type before * handling `Void`-specific schema behavior. * * @see {@link isUndefined} for narrowing AST nodes that represent the literal `undefined` value instead of TypeScript `void` * * @stability stable * @category guards * @since 4.0.0 */ export declare const isVoid: (ast: AST) => ast is Void; /** * Narrows an {@link AST} to {@link Never}. * * **When to use** * * Use to detect the AST node for a schema that can never match before handling * other schema variants. * * @see {@link Never} for the AST node type narrowed by this guard * @see {@link never} for the singleton `Never` AST instance * * @stability stable * @category guards * @since 4.0.0 */ export declare const isNever: (ast: AST) => ast is Never; /** * Narrows an {@link AST} to {@link Unknown}. * * **When to use** * * Use when you need to inspect a schema AST and handle the `Unknown` node * variant specifically. * * @see {@link isAny} for the guard for the `Any` node, whose parsed result is typed as `any` rather than `unknown` * * @stability stable * @category guards * @since 4.0.0 */ export declare const isUnknown: (ast: AST) => ast is Unknown; /** * Narrows an {@link AST} to {@link Any}. * * **When to use** * * Use when you need to inspect a schema AST and handle the `Any` node * variant specifically. * * @see {@link isUnknown} for the guard for the `Unknown` node, whose parsed result is typed as `unknown` rather than `any` * * @stability stable * @category guards * @since 4.0.0 */ export declare const isAny: (ast: AST) => ast is Any; /** * Narrows an {@link AST} to {@link String}. * * **When to use** * * Use to detect schema AST nodes that match any string value while inspecting * or transforming a Schema AST. * * @see {@link String} for the AST node class narrowed by this guard * @see {@link string} for the singleton `String` AST instance * @see {@link isLiteral} for exact primitive literal AST nodes, including exact string literals * * @stability stable * @category guards * @since 4.0.0 */ export declare const isString: (ast: AST) => ast is String; /** * Narrows an {@link AST} to {@link Number}. * * **When to use** * * Use to detect `Number` AST nodes while inspecting, traversing, or transforming * schema ASTs. * * @stability stable * @category guards * @since 4.0.0 */ export declare const isNumber: (ast: AST) => ast is Number; /** * Narrows an {@link AST} to {@link Boolean}. * * **When to use** * * Use to identify the `Boolean` AST variant while inspecting, traversing, or * transforming schema definitions. * * @see {@link Boolean} for the AST node type matched by this guard * @see {@link boolean} for the singleton instance to use when constructing a boolean AST directly * * @stability stable * @category guards * @since 4.0.0 */ export declare const isBoolean: (ast: AST) => ast is Boolean; /** * Narrows an {@link AST} to {@link BigInt}. * * **When to use** * * Use to identify bigint AST nodes while inspecting or transforming schema ASTs. * * @see {@link BigInt} for the AST node matched by this guard * @see {@link bigInt} for the singleton instance; use `isBigInt` when narrowing an existing `AST` value * * @stability stable * @category guards * @since 4.0.0 */ export declare const isBigInt: (ast: AST) => ast is BigInt; /** * Narrows an {@link AST} to {@link Symbol}. * * **When to use** * * Use to narrow an `AST` node before handling the `Symbol` variant for schemas * that accept any JavaScript symbol value. * * @see {@link isUniqueSymbol} for the sibling guard that narrows the `UniqueSymbol` variant for one exact symbol value * * @stability stable * @category guards * @since 4.0.0 */ export declare const isSymbol: (ast: AST) => ast is Symbol; /** * Narrows an {@link AST} to {@link Literal}. * * **When to use** * * Use to recognize exact string, number, boolean, or bigint literal AST nodes. * * @see {@link Literal} for the AST node type narrowed by this guard * @see {@link LiteralValue} for the values stored by literal nodes * * @stability stable * @category guards * @since 3.10.0 */ export declare const isLiteral: (ast: AST) => ast is Literal; /** * Narrows an {@link AST} to {@link UniqueSymbol}. * * @stability stable * @category guards * @since 3.10.0 */ export declare const isUniqueSymbol: (ast: AST) => ast is UniqueSymbol; /** * Narrows an {@link AST} to {@link ObjectKeyword}. * * **When to use** * * Use to identify the AST node for the TypeScript `object` keyword when * inspecting or transforming a Schema AST. * * @see {@link ObjectKeyword} for the AST node matched by this guard * @see {@link objectKeyword} for the singleton `ObjectKeyword` AST instance * @see {@link isObjects} for struct and record AST nodes * * @stability stable * @category guards * @since 3.10.0 */ export declare const isObjectKeyword: (ast: AST) => ast is ObjectKeyword; /** * Narrows an {@link AST} to {@link Enum}. * * **When to use** * * Use to recognize enum AST nodes before reading enum cases or running * enum-specific handling. * * @see {@link Enum} for the AST node type narrowed by this guard * * @stability stable * @category guards * @since 4.0.0 */ export declare const isEnum: (ast: AST) => ast is Enum; /** * Narrows an {@link AST} to {@link TemplateLiteral}. * * @stability stable * @category guards * @since 3.10.0 */ export declare const isTemplateLiteral: (ast: AST) => ast is TemplateLiteral; /** * Narrows an {@link AST} to {@link Arrays}. * * **When to use** * * Use to recognize array-like AST nodes before reading their element, rest, or * mutability metadata. * * @see {@link Arrays} for the AST node type narrowed by this guard * * @stability stable * @category guards * @since 4.0.0 */ export declare const isArrays: (ast: AST) => ast is Arrays; /** * Narrows an {@link AST} to {@link Objects}. * * @stability stable * @category guards * @since 4.0.0 */ export declare const isObjects: (ast: AST) => ast is Objects; /** * Narrows an {@link AST} to {@link Union}. * * @stability stable * @category guards * @since 3.10.0 */ export declare const isUnion: (ast: AST) => ast is Union; /** * Narrows an {@link AST} to {@link Suspend}. * * @stability stable * @category guards * @since 3.10.0 */ export declare const isSuspend: (ast: AST) => ast is Suspend; /** * Represents a single step in an {@link Encoding} chain. * * **Details** * * A link pairs a target {@link AST} with a `Transformation` or `Middleware` * that converts values between the current node and the target. * * - `to` — the AST node on the other side of this transformation step. * - `transformation` — the bidirectional conversion logic (decode/encode). * * Links are composed into a non-empty array ({@link Encoding}) attached to * AST nodes that have a different encoded representation. * * @see {@link Encoding} * @see {@link decodeTo} * @stability stable * @category models * @since 4.0.0 */ export interface Link { readonly to: AST; readonly transformation: SchemaTransformation.Transformation | SchemaTransformation.Middleware; } /** * Constructs a {@link Link}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Link: new (to: AST, transformation: SchemaTransformation.Transformation | SchemaTransformation.Middleware) => Link; /** * A non-empty chain of {@link Link} values representing the transformation * steps between a schema's decoded (type) form and its encoded (wire) form. * * **Details** * * Stored on an AST node's `encoding` field. When `undefined`, the node has no * encoding transformation (type and encoded forms are identical). * * @see {@link Link} * @see {@link toEncoded} * @stability stable * @category models * @since 4.0.0 */ export type Encoding = readonly [Link, ...Array]; /** * Options that control schema parsing, validation, transformation, and output behavior. * * **Details** * * Pass to `Schema.decodeUnknownEffect`, `Schema.encodeEffect`, and related APIs to customize * error reporting, excess property handling, check execution, and product * concurrency. Options apply throughout the parse; schema annotations do not * override them. * * - `errors` — `"first"` (default) stops at the first error; `"all"` collects * every error. * - `onExcessProperty` — `"ignore"` (default) strips unknown object keys; * `"error"` fails. * - `disableChecks` — skips validation checks while still applying defaults and * transformations. * - `concurrency` — controls concurrent parsing of tuple elements, array * elements, struct fields, and record entries using the same semantics as * `Effect.forEach`; the default is sequential. * - `reportInput` — includes rejected input values in value-bearing schema * issues. * * Object property order is unspecified, including in values passed to checks. * Decoding and encoding do not guarantee preservation of input key order. * * @stability stable * @category options * @since 3.10.0 */ export interface ParseOptions { /** * Controls how many parsing errors are reported. * * **Details** * * The default, `"first"`, stops at the first error. Set the option to `"all"` * to collect every parsing error, which can help with debugging or with * presenting more complete error messages to a user. * * @default "first" */ readonly errors?: "first" | "all" | undefined; /** * Controls how object parsing handles keys that are not declared by the schema. * * **Details** * * The default, `"ignore"`, strips unspecified properties from the output. Use * `"error"` to fail when an excess property is present. A key is covered by a * declared property or any index signature selecting that key. This applies * to structs, records, and structs with rest. Values must satisfy every * applicable index signature. Empty structs keep their non-nullish behavior. * * An excess property is an enumerable own property that is not covered by a * declared property or an index signature. Non-enumerable own properties, * such as `Error#stack`, are ignored unless explicitly declared by the * schema. Index signatures likewise select only enumerable own properties. * * @default "ignore" */ readonly onExcessProperty?: "ignore" | "error" | undefined; /** * Whether to disable checks while still applying defaults and * transformations. */ readonly disableChecks?: boolean | undefined; /** * Controls how many children of a product schema may parse concurrently. * * **Details** * * This option has the same concurrency semantics as {@link Effect.forEach}. * It applies to tuples, arrays, structs, records, and structs with rest. Each * nested product applies the limit independently. Union members remain * sequential, though products inside the current union member still receive * the option. * * Array and tuple outputs retain their element order. Other observable work, * including issue accumulation and colliding transformed record keys, follows * effect completion order when concurrency is greater than `1`. * * **Gotchas** * * With `errors: "first"`, the first observed child failure interrupts the * remaining children and may not belong to the earliest product position. * Concurrent children may perform effects before another child fails. * * @default undefined */ readonly concurrency?: Types.Concurrency | undefined; /** * Whether schema issues should retain and report rejected input values. * * **Details** * * When enabled, value-bearing issues created by the parser expose an `input` * field. Built-in formatters may include reported input in default messages. * The input is retained by reference rather than copied. * * **Gotchas** * * Enabling this option can retain or disclose secrets, personally * identifiable information, and large object graphs. The `input` field is * enumerable and may be included by object enumeration, spread, or * serialization. Issues returned directly by user-defined declarations, * checks, transformations, and middleware are not modified; their authors * decide whether to retain an input. To respect this option, pass the * callback's input and parse options directly to a value-bearing issue * constructor. Custom messages and annotations remain the caller's * responsibility regardless of this option. * Formatting an issue with `SchemaIssue.makeFormatterDefault()`, reading * `SchemaError.message`, or formatting a Standard Schema failure can disclose * retained input. * * @default false */ readonly reportInput?: boolean | undefined; } /** * Represents per-property metadata attached to an AST node's `context` field. * * **Details** * * Tracks whether a property key is optional, mutable, has a constructor * default, or carries key-level annotations. Typically set by helpers like * {@link optionalKey} and `Schema.mutableKey`. * * - `isOptional` — the property key may be absent from the input. * - `isMutable` — the property is `readonly` when `false`. * - `constructorDefault` — an effect evaluated during construction to supply * missing values. * - `annotations` — key-level annotations (e.g. description of the key * itself). * * @see `Schema.optionalKey` * @see {@link isOptional} * @stability stable * @category models * @since 4.0.0 */ export interface Context { readonly isOptional: boolean; readonly isMutable: boolean; /** Used for constructor default values (e.g. `withConstructorDefault` API) */ readonly constructorDefault: Effect.Effect | undefined; readonly annotations: Schema.Annotations.Key | undefined; } /** * Constructs a {@link Context}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Context: new (isOptional: boolean, isMutable: boolean, /** Used for constructor default values (e.g. `withConstructorDefault` API) */ constructorDefault?: Effect.Effect | undefined, annotations?: Schema.Annotations.Key | undefined) => Context; /** * Non-empty array of validation {@link Check} values attached to an AST node's * `checks` field. * * **Details** * * Checks are run after basic type matching succeeds. They represent * refinements like `minLength`, `pattern`, `int`, etc. * * @see {@link Check} * @see {@link Filter} * @see {@link FilterGroup} * @stability stable * @category models * @since 4.0.0 */ export type Checks = readonly [Check, ...Array>]; declare const TypeId = "~effect/Schema"; interface ASTNode { readonly [TypeId]: typeof TypeId; readonly _tag: string; readonly annotations: Schema.Annotations.Annotations | undefined; readonly checks: Checks | undefined; readonly encoding: Encoding | undefined; readonly context: Context | undefined; toString(): string; } type DeclarationRun = (typeParameters: ReadonlyArray) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect; /** * AST node for user-defined opaque types with custom parsing logic. * * **When to use** * * Use when you need a custom schema AST node because none of the built-in * nodes fit. * * **Details** * * - `typeParameters` — inner schemas this declaration is parameterized over * (e.g. the element type for a custom collection). * - `run` — factory that receives `typeParameters` and returns a parser that * validates or transforms raw input. The `Effect` returned by the parser must * complete synchronously. * * @see {@link isDeclaration} * @stability stable * @category models * @since 4.0.0 */ export interface Declaration extends ASTNode { readonly _tag: "Declaration"; readonly typeParameters: ReadonlyArray; readonly run: DeclarationRun; readonly encodingChecks: Checks | undefined; /** * Parser factory {@link flip} swaps in, so a declaration can behave * differently when encoding. `undefined` reuses `run`. */ readonly encodingRun: DeclarationRun | undefined; } /** * Constructs a {@link Declaration}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Declaration: new (typeParameters: ReadonlyArray, run: DeclarationRun, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks, encodingRun?: DeclarationRun) => Declaration; /** * AST node matching the `null` literal value. * * **Details** * * Parsing succeeds only when the input is exactly `null`. * * @see {@link null_ null} * @see {@link isNull} * @stability stable * @category models * @since 4.0.0 */ export interface Null extends ASTNode { readonly _tag: "Null"; } /** * Constructs a {@link Null}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Null: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Null; declare const null_: Null; export { /** * Provides the singleton {@link Null} AST instance. * * **When to use** * * Use when you need the shared AST node for exact null values while inspecting * or constructing schema ASTs. * * @stability stable * @category constants * @since 4.0.0 */ null_ as null }; /** * AST node matching the `undefined` value. * * **Details** * * Parsing succeeds only when the input is exactly `undefined`. * * @see {@link undefined} * @see {@link isUndefined} * @stability stable * @category models * @since 4.0.0 */ export interface Undefined extends ASTNode { readonly _tag: "Undefined"; } /** * Constructs a {@link Undefined}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Undefined: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Undefined; declare const undefined_: Undefined; export { /** * Provides the singleton {@link Undefined} AST instance. * * **When to use** * * Use when you need the shared AST node for exact undefined values while * inspecting or constructing schema ASTs. * * @stability stable * @category constants * @since 4.0.0 */ undefined_ as undefined }; /** * AST node matching TypeScript `void` return-value semantics. * * **When to use** * * Use when you need an AST node for a value whose result is intentionally * ignored. * * **Details** * * Parsers built from this node accept any present runtime input and map it to * `undefined`. Public schemas built from it may still expose `void` as their * typed decoded and encoded representation. * * @see {@link undefined} for the AST singleton that matches only exact `undefined` * @see {@link void_ void} * @see {@link isVoid} * @stability stable * @category models * @since 4.0.0 */ export interface Void extends ASTNode { readonly _tag: "Void"; } /** * Constructs a {@link Void}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Void: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Void; declare const void_: Void; export { /** * Provides the singleton {@link Void} AST instance. * * **When to use** * * Use when constructing or comparing AST nodes for TypeScript `void` return * values whose result is intentionally ignored. * * **Details** * * The node parses any present runtime value as `undefined`; schemas may still * expose `void` on their typed decoded and encoded sides. * * @see {@link Void} for the AST node class * @see {@link undefined} for the sibling AST singleton that matches exactly `undefined` * @see {@link isVoid} for narrowing an AST to a `Void` node * * @stability stable * @category constructors * @since 4.0.0 */ void_ as void }; /** * AST node representing the `never` type — no value matches. * * **Details** * * Parsing always fails. Useful as a placeholder in unions or as the result * of narrowing that eliminates all options. * * @see {@link never} * @see {@link isNever} * @stability stable * @category models * @since 4.0.0 */ export interface Never extends ASTNode { readonly _tag: "Never"; } /** * Constructs a {@link Never}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Never: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Never; /** * Provides the singleton {@link Never} AST instance. * * **When to use** * * Use to reuse the canonical bottom-type AST node when constructing, * comparing, or returning ASTs. * * @see {@link Never} for the AST node class * @see {@link isNever} for narrowing an AST to a `Never` node * * @stability stable * @category constructors * @since 4.0.0 */ export declare const never: Never; /** * AST node representing the `any` type — every value matches. * * @see {@link any} * @see {@link isAny} * * @stability stable * @category models * @since 4.0.0 */ export interface Any extends ASTNode { readonly _tag: "Any"; } /** * Constructs a {@link Any}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Any: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Any; /** * Provides the singleton {@link Any} AST instance. * * **When to use** * * Use when you need the singleton AST node for the TypeScript `any` type and * intentionally want parsing to accept every input value. * * @see {@link unknown} for the sibling AST singleton that also accepts every value while preserving the safer `unknown` type * * @stability stable * @category constructors * @since 4.0.0 */ export declare const any: Any; /** * AST node representing the `unknown` type — every value matches. * * **Details** * * Unlike {@link Any}, this is type-safe: the parsed result is typed as * `unknown` rather than `any`. * * @see {@link unknown} * @see {@link isUnknown} * @stability stable * @category models * @since 4.0.0 */ export interface Unknown extends ASTNode { readonly _tag: "Unknown"; } /** * Constructs a {@link Unknown}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Unknown: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Unknown; /** * Provides the singleton {@link Unknown} AST instance. * * **When to use** * * Use when you need the reusable AST singleton for a schema node that accepts * every value while keeping parsed values opaque. * * @see {@link any} for the singleton that accepts every value as `any` * * @stability stable * @category constructors * @since 4.0.0 */ export declare const unknown: Unknown; /** * AST node matching the TypeScript `object` type — accepts objects, arrays, * and functions (anything non-primitive and non-null). * * @see {@link objectKeyword} * @see {@link isObjectKeyword} * * @stability stable * @category models * @since 4.0.0 */ export interface ObjectKeyword extends ASTNode { readonly _tag: "ObjectKeyword"; } /** * Constructs a {@link ObjectKeyword}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const ObjectKeyword: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => ObjectKeyword; /** * Provides the singleton {@link ObjectKeyword} AST instance. * * **When to use** * * Use to reuse the canonical AST node for the TypeScript `object` keyword when * building or comparing `SchemaAST` values directly. * * @see {@link ObjectKeyword} for the AST node class * @see {@link isObjectKeyword} for narrowing an AST to an `ObjectKeyword` node * * @stability stable * @category constructors * @since 3.10.0 */ export declare const objectKeyword: ObjectKeyword; /** * AST node representing a TypeScript `enum`. * * **Details** * * Holds `enums` as an array of `[name, value]` pairs where values are * `string | number`. Parsing succeeds when the input matches any enum value. * * @see {@link isEnum} * @stability stable * @category models * @since 4.0.0 */ export interface Enum extends ASTNode { readonly _tag: "Enum"; readonly enums: ReadonlyArray; } /** * Constructs a {@link Enum}. Numeric values must be finite. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Enum: new (enums: ReadonlyArray, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context) => Enum; /** * AST node representing a TypeScript template literal type * (e.g. `` `user_${string}` ``). * * **Details** * * `parts` is an array of AST nodes; each part contributes to matching * strings at runtime. * * @see {@link isTemplateLiteral} * @stability stable * @category models * @since 4.0.0 */ export interface TemplateLiteral extends ASTNode { readonly _tag: "TemplateLiteral"; readonly parts: ReadonlyArray; } /** * Constructs a {@link TemplateLiteral}. * * **Gotchas** * * Throws if a part contains an encoding, including inside unions or nested * template literals. Parts must describe their values without transformations. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const TemplateLiteral: new (parts: ReadonlyArray, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context) => TemplateLiteral; /** * AST node matching a specific `unique symbol` value. * * **Details** * * Parsing succeeds only when the input is reference-equal to the stored * `symbol`. * * @see {@link isUniqueSymbol} * @stability stable * @category models * @since 4.0.0 */ export interface UniqueSymbol extends ASTNode { readonly _tag: "UniqueSymbol"; readonly symbol: symbol; } /** * Constructs a {@link UniqueSymbol}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const UniqueSymbol: new (symbol: symbol, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context) => UniqueSymbol; /** * The set of primitive types that can appear as a {@link Literal} value. * * @see {@link Literal} * * @stability stable * @category models * @since 3.10.0 */ export type LiteralValue = string | number | boolean | bigint; /** * AST node matching an exact primitive value (string, number, boolean, or * bigint). * * **Details** * * Parsing succeeds only when the input is strictly equal (`===`) to the * stored `literal`, preserving the input value. Both `0` and `-0` are accepted * by either zero literal, and parsing preserves the input's sign. Numeric * literals must be finite. `Infinity`, `-Infinity`, and `NaN` are rejected at * construction time. * * **Example** (Creating a literal AST) * * ```ts import.meta.vitest * import { SchemaAST } from "effect" * * const ast = new SchemaAST.Literal("active") * ast.literal // => "active" * ``` * * @see {@link LiteralValue} * @see {@link isLiteral} * @stability stable * @category models * @since 4.0.0 */ export interface Literal extends ASTNode { readonly _tag: "Literal"; readonly literal: LiteralValue; } /** * Constructs a {@link Literal}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Literal: new (literal: LiteralValue, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context) => Literal; /** * AST node matching any `string` value. * * @see {@link string} * @see {@link isString} * * @stability stable * @category models * @since 4.0.0 */ export interface String extends ASTNode { readonly _tag: "String"; } /** * Constructs a {@link String}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const String: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => String; /** * Provides the singleton {@link String} AST instance. * * **When to use** * * Use as the shared `SchemaAST` node for unconstrained JavaScript strings. * * @see {@link String} for the AST node class * @see {@link isString} for narrowing an AST to a string node * * @stability stable * @category constructors * @since 4.0.0 */ export declare const string: String; /** * AST node matching any `number` value (including `NaN`, `Infinity`, * `-Infinity`). * * **Details** * * Default JSON serialization: * * - Finite numbers are serialized as JSON numbers. * - `Infinity`, `-Infinity`, and `NaN` are serialized as JSON strings. * * If the node has an `isFinite` or `isInt` check, the string fallback is * skipped since non-finite values cannot occur. * * @see {@link number} * @see {@link isNumber} * @stability stable * @category models * @since 4.0.0 */ export interface Number extends ASTNode { readonly _tag: "Number"; } /** * Constructs a {@link Number}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Number: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Number; /** * Provides the singleton {@link Number} AST instance. * * **When to use** * * Use when you need the canonical `SchemaAST` node for schemas that accept any * JavaScript number value. * * @see {@link Number} for the AST node class and serialization behavior * @see {@link Literal} for exact finite numeric literal AST nodes * * @stability stable * @category constructors * @since 4.0.0 */ export declare const number: Number; /** * AST node matching any `boolean` value (`true` or `false`). * * @see {@link boolean} * @see {@link isBoolean} * * @stability stable * @category models * @since 4.0.0 */ export interface Boolean extends ASTNode { readonly _tag: "Boolean"; } /** * Constructs a {@link Boolean}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Boolean: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Boolean; /** * Provides the singleton {@link Boolean} AST instance. * * **When to use** * * Use to reuse the standard AST node that accepts either `true` or `false` when * constructing schema ASTs directly. * * @see {@link Boolean} for the AST node class * @see {@link Literal} for exact boolean literal AST nodes * * @stability stable * @category constructors * @since 4.0.0 */ export declare const boolean: Boolean; /** * AST node matching any `symbol` value. * * **When to use** * * Use when you need the AST node class for schemas that match any JavaScript * symbol value. * * **Details** * * When serialized to a string-based codec, symbols are converted via * `Symbol.keyFor` and must be registered with `Symbol.for`. * * @see {@link symbol} * @see {@link isSymbol} * @stability stable * @category models * @since 4.0.0 */ export interface Symbol extends ASTNode { readonly _tag: "Symbol"; } /** * Constructs a {@link Symbol}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Symbol: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => Symbol; /** * Provides the singleton {@link Symbol} AST instance. * * **When to use** * * Use to reuse the singleton AST node for schemas that match any JavaScript * symbol value. * * **Gotchas** * * String-based codecs can encode only symbols registered with `Symbol.for`, * because the implementation uses `Symbol.keyFor`. * * @see {@link UniqueSymbol} for an AST node that matches one specific symbol * * @stability stable * @category constructors * @since 4.0.0 */ export declare const symbol: Symbol; /** * AST node matching any `bigint` value. * * **Details** * * When serialized to a string-based codec, bigints are converted to/from * their decimal string representation. * * @see {@link bigInt} * @see {@link isBigInt} * @stability stable * @category models * @since 4.0.0 */ export interface BigInt extends ASTNode { readonly _tag: "BigInt"; } /** * Constructs a {@link BigInt}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const BigInt: new (annotations?: Schema.Annotations.Annotations | undefined, checks?: Checks | undefined, encoding?: Encoding | undefined, context?: Context | undefined) => BigInt; /** * Provides the singleton {@link BigInt} AST instance. * * **When to use** * * Use to reuse the canonical `BigInt` AST node when constructing, inspecting, * or transforming schemas at the AST level. * * @see {@link BigInt} for the AST node class and string-codec behavior * @see {@link isBigInt} for narrowing an AST to a `BigInt` node * * @stability stable * @category constructors * @since 4.0.0 */ export declare const bigInt: BigInt; /** * AST node for array-like types — both tuples and arrays. * * **When to use** * * Use when constructing or inspecting AST nodes for tuple or array-like schemas, * including rest elements. * * **Details** * * - `elements` — positional element types (tuple elements). An element is * optional if its context's `isOptional` field is `true`. * - `rest` — the rest/variadic element types. When non-empty, the first * entry is the "spread" type (e.g. `...Array`), and subsequent * entries are trailing positional elements after the spread. * - `isMutable` — whether the resulting array is `readonly` (`false`) or * mutable (`true`). * * **Gotchas** * * Construction enforces TypeScript ordering rules: a required element * cannot follow an optional one, and an optional element cannot follow a * rest element. * * **Example** (Inspecting a tuple AST) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.Tuple([Schema.String, Schema.Number]) * const ast = schema.ast * * if (SchemaAST.isArrays(ast)) { * [ast.elements.length, ast.rest.length] // => [2, 0] * } * ``` * * @see {@link isArrays} * @see {@link Objects} * @stability stable * @category models * @since 4.0.0 */ export interface Arrays extends ASTNode { readonly _tag: "Arrays"; readonly isMutable: boolean; readonly elements: ReadonlyArray; readonly rest: ReadonlyArray; readonly encodingChecks: Checks | undefined; } /** * Constructs a {@link Arrays}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Arrays: new (isMutable: boolean, elements: ReadonlyArray, rest: ReadonlyArray, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks) => Arrays; /** * Represents a named property within an {@link Objects} node. * * **Details** * * Pairs a `name` (any `PropertyKey`) with a `type` ({@link AST}). The * property's optionality and mutability are determined by the `type`'s * {@link Context}. * * @see {@link Objects} * @stability stable * @category models * @since 4.0.0 */ export interface PropertySignature { readonly name: PropertyKey; readonly type: AST; } /** * Constructs a {@link PropertySignature}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const PropertySignature: new (name: PropertyKey, type: AST) => PropertySignature; type IndexSignatureParameter = String | Number | Symbol | TemplateLiteral | Union; /** * Represents an index signature entry within an {@link Objects} node. * * **When to use** * * Use when constructing or inspecting object AST entries for record-like keys * and values. * * **Details** * * - `parameter` — the key type AST (e.g. {@link String} for `string` keys, * {@link TemplateLiteral} for patterned keys). * - `type` — the value type SchemaAST. * * **Gotchas** * * Using `Schema.optionalKey` on the value type is not allowed for index * signatures (throws at construction); use `Schema.optional` instead. * * @see {@link Objects} * @see {@link PropertySignature} * @stability stable * @category models * @since 4.0.0 */ export interface IndexSignature { readonly parameter: IndexSignatureParameter; readonly type: AST; } /** * Constructs a {@link IndexSignature}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const IndexSignature: new (parameter: AST, type: AST) => IndexSignature; /** * AST node for object-like schemas, including structs and records. * * **When to use** * * Use when constructing or inspecting AST nodes for structs or records rather * than array-like schemas. * * **Details** * * - `propertySignatures` — named properties with their types (struct fields). * - `indexSignatures` — index signature entries (record patterns), each with * a `parameter` AST for matching keys and a `type` AST for values. * * An `Objects` node with no properties and no index signatures performs only a * non-nullish check: it accepts any value except `null` and `undefined`, * including primitive values. * * **Gotchas** * * Duplicate property names throw at construction time. * * **Example** (Inspecting a struct AST) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.Struct({ name: Schema.String }) * const ast = schema.ast * * if (SchemaAST.isObjects(ast)) { * ast.propertySignatures.map((ps) => [ps.name, ps.type._tag]) // => [["name", "String"]] * } * ``` * * @see {@link isObjects} * @see {@link PropertySignature} * @see {@link IndexSignature} * @see {@link Arrays} * @stability stable * @category models * @since 4.0.0 */ export interface Objects extends ASTNode { readonly _tag: "Objects"; readonly propertySignatures: ReadonlyArray; readonly indexSignatures: ReadonlyArray; readonly encodingChecks: Checks | undefined; } /** * Constructs a {@link Objects}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Objects: new (propertySignatures: ReadonlyArray, indexSignatures: ReadonlyArray, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks) => Objects; /** * AST node representing a union of schemas. * * **Details** * * - `types` — the member AST nodes. * - `options.mode` selects matching behavior. `"anyOf"` succeeds on the first match; * `"oneOf"` requires exactly one member to match (fails if multiple do). * * During parsing, members are tried in order. An internal candidate index * narrows which members to try based on the runtime type of the input and * discriminant ("sentinel") fields, making large unions efficient. * * **Example** (Inspecting a union AST) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.Union([Schema.String, Schema.Number]) * const ast = schema.ast * * if (SchemaAST.isUnion(ast)) { * [ast.types.length, ast.options?.mode ?? "anyOf"] // => [2, "anyOf"] * } * ``` * * @see {@link isUnion} * @stability stable * @category models * @since 4.0.0 */ export interface Union extends ASTNode { readonly _tag: "Union"; readonly types: ReadonlyArray; readonly options: UnionOptions | undefined; readonly encodingChecks: Checks | undefined; } /** * Local matching options stored on {@link Union} nodes. * * @stability stable * @category options * @since 4.0.0 */ export interface UnionOptions { /** Defaults to `"anyOf"`; `"oneOf"` requires exactly one matching member. */ readonly mode?: "anyOf" | "oneOf" | undefined; } /** * Constructs a {@link Union}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Union: new (types: ReadonlyArray, options?: UnionOptions, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks) => Union; /** * AST node for lazy/recursive schemas. * * **Details** * * Wraps a thunk (`() => AST`) that is memoized on first call. Use this to * define recursive or mutually recursive schemas without infinite loops at * construction time. * * **Example** (Defining recursive schema ASTs) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * interface Category { * readonly name: string * readonly children: ReadonlyArray * } * * const Category = Schema.Struct({ * name: Schema.String, * children: Schema.Array(Schema.suspend((): Schema.Codec => Category)) * }) * * SchemaAST.isObjects(Category.ast) // => true * ``` * * @see {@link isSuspend} * @stability stable * @category models * @since 4.0.0 */ export interface Suspend extends ASTNode { readonly _tag: "Suspend"; readonly thunk: () => AST; } /** * Constructs a {@link Suspend}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Suspend: new (thunk: () => AST, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context) => Suspend; /** * Represents a single validation check attached to an AST node. * * **Details** * * - `run` — the validation function. Returns `undefined` on success, or an * `Issue` on failure. * - `annotations` — optional filter-level annotations (expected message, * representation, arbitrary constraint hints). * - `aborted` — when `true`, parsing stops immediately after this filter * fails (no further checks run). * * Use `.annotate()` to add metadata and `.abort()` to mark as aborting. * Combine with another check via `.and()` to form a {@link FilterGroup}. * * @see {@link FilterGroup} * @see {@link Check} * @see {@link isPattern} * @stability stable * @category models * @since 4.0.0 */ export interface Filter extends Pipeable.Pipeable { readonly _tag: "Filter"; readonly run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined; readonly annotations: Schema.Annotations.Filter | undefined; /** * Whether the parsing process should be aborted after this check has failed. */ readonly aborted: boolean; annotate(annotations: Schema.Annotations.Filter): Filter; abort(): Filter; and(other: Check, annotations?: Schema.Annotations.Filter): FilterGroup; } /** * Constructs a {@link Filter}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const Filter: new (run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined, annotations?: Schema.Annotations.Filter | undefined, /** * Whether the parsing process should be aborted after this check has failed. */ aborted?: boolean) => Filter; /** * Represents a composite validation check grouping multiple {@link Check} values. * * **Details** * * Created by calling `.and()` on a {@link Filter} or another `FilterGroup`. * All inner checks are run; failures from aborted filters still stop * evaluation. * * @see {@link Filter} * @see {@link Check} * @stability stable * @category models * @since 4.0.0 */ export interface FilterGroup extends Pipeable.Pipeable { readonly _tag: "FilterGroup"; readonly checks: readonly [ Check, ...Array> ]; readonly annotations: Schema.Annotations.Filter | undefined; annotate(annotations: Schema.Annotations.Filter): FilterGroup; and(other: Check, annotations?: Schema.Annotations.Filter): FilterGroup; } /** * Constructs a {@link FilterGroup}. * * @stability stable * @category constructors * @since 4.0.0 */ export declare const FilterGroup: new (checks: readonly [ Check, ...Array> ], annotations?: Schema.Annotations.Filter | undefined) => FilterGroup; /** * A validation check — either a single {@link Filter} or a composite * {@link FilterGroup}. * * **Details** * * Stored in an AST node's {@link Checks} array. * * @see {@link Filter} * @see {@link FilterGroup} * @stability stable * @category models * @since 4.0.0 */ export type Check = Filter | FilterGroup; /** * Creates a {@link Filter} that validates strings by running `RegExp.test`. * * **When to use** * * Use when string validation should be represented as a schema `Filter` backed * by a regular expression. * * **Details** * * The filter can be used with `Schema.check` or attached directly to a * `String` AST node through checks. The regular expression is cloned and its * `lastIndex` is reset before each test, so global and sticky expressions are * deterministic and the provided regular expression is not mutated. The * regular expression source is stored in annotations for serialization and * arbitrary generation. * * **Gotchas** * * Arbitrary metadata preserves both `regExp.source` and `regExp.flags`. * Implementations that cannot consume all flags may still use the source as a * generation hint because the Schema filter validates every generated value. * JSON Schema has no way to carry JavaScript regular-expression flags. Unless * annotations provide `toJsonSchema`, the RegExp constraint is omitted from * JSON Schema export. * * **Example** (Validating an email pattern) * * ```ts import.meta.vitest * import { SchemaAST } from "effect" * * const emailFilter = SchemaAST.isPattern(/^[^@]+@[^@]+$/) * emailFilter.run("alice@example.com", SchemaAST.string, {}) // => undefined * emailFilter.run("invalid", SchemaAST.string, {})?._tag // => "InvalidValue" * ``` * * @see {@link Filter} * @stability stable * @category constructors * @since 4.0.0 */ export declare function isPattern(regExp: globalThis.RegExp, annotations?: Schema.Annotations.Filter): Filter; export declare function mapOrSame(as: ReadonlyArray, f: (a: A) => A): ReadonlyArray; /** * Attaches a `Transformation` to the `to` AST, making it decode from the * `from` AST and encode back to it. * * **Details** * * This is the low-level primitive behind `Schema.decodeTo`. It appends a * {@link Link} to the `to` node's encoding chain. * * - Returns a new AST with the same type as `to`. * * @see {@link Link} * @see {@link Encoding} * @see {@link flip} * @stability stable * @category transforming * @since 4.0.0 */ export declare function decodeTo(from: AST, to: A, transformation: SchemaTransformation.Transformation): A; /** * Returns `true` if the AST node represents an optional property. * * **Details** * * Checks `ast.context?.isOptional`. Defaults to `false` when no * {@link Context} is set. * * @see `Schema.optionalKey` * @see {@link Context} * @stability stable * @category predicates * @since 4.0.0 */ export declare function isOptional(ast: AST): boolean; /** * Strips all encoding transformations from an AST, returning the decoded * (type-level) representation. * * **Details** * * - Memoized: same input reference → same output reference. * - Recursively walks into composite nodes ({@link Arrays}, {@link Objects}, * {@link Union}, {@link Suspend}). * * **Example** (Getting the type AST) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.NumberFromString * const typeAst = SchemaAST.toType(schema.ast) * typeAst._tag // => "Number" * ``` * * @see {@link toEncoded} * @see {@link flip} * @stability stable * @category transforming * @since 4.0.0 */ export declare const toType: (a: A) => A; /** * Returns the encoded (wire-format) AST by flipping and then stripping * encodings. * * **Details** * * Equivalent to `toType(flip(ast))`. This gives you the AST that describes * the shape of the serialized/encoded data. * * - Memoized: same input reference → same output reference. * * **Example** (Getting the encoded AST) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.NumberFromString * const encodedAst = SchemaAST.toEncoded(schema.ast) * encodedAst._tag // => "String" * ``` * * @see {@link toType} * @see {@link flip} * @stability stable * @category transforming * @since 4.0.0 */ export declare const toEncoded: (a: AST) => AST; /** * Swaps the decode and encode directions of an AST's {@link Encoding} chain. * * **Details** * * After flipping, what was decoding becomes encoding and vice versa. This is * the core operation behind `Schema.encodeEffect` — encoding a value is decoding * with a flipped SchemaAST. * * - Memoized: same input reference → same output reference. * - Recursively walks composite nodes. * * @see {@link toType} * @see {@link toEncoded} * @stability stable * @category transforming * @since 4.0.0 */ export declare const flip: (ast: AST) => AST; /** * Returns all annotations from the AST node. * * **Details** * * If the node has {@link Checks}, returns annotations from the last check * (which is where user-supplied annotations end up after `.pipe(Schema.annotate(...))`). * Otherwise returns the node's `annotations` directly. * * **Example** (Reading annotations) * * ```ts import.meta.vitest * import { Schema, SchemaAST } from "effect" * * const schema = Schema.String.annotate({ title: "Name" }) * const annotations = SchemaAST.resolve(schema.ast) * annotations?.title // => "Name" * ``` * * @see {@link resolveAt} * @see {@link resolveIdentifier} * @see {@link resolveTitle} * @see {@link resolveDescription} * @stability stable * @category annotations * @since 4.0.0 */ export declare const resolve: (ast: AST) => Schema.Annotations.Annotations | undefined; /** * Returns a single annotation value by key from the AST node. * * **Details** * * Like {@link resolve}, reads from the last check's annotations when checks * are present. Returns `undefined` if the key is not found. * * @see {@link resolve} * @stability stable * @category annotations * @since 4.0.0 */ export declare const resolveAt: (key: string) => (ast: AST) => A | undefined; /** * Returns the `identifier` annotation from the AST node, if set. * * **Details** * * The identifier is typically set by `Schema.annotate({ identifier: "..." })` * and is used for error messages and schema identification. * * @see {@link resolve} * @see {@link resolveTitle} * @stability stable * @category annotations * @since 4.0.0 */ export declare const resolveIdentifier: (ast: AST) => string | undefined; /** * Returns the `title` annotation from the AST node, if set. * * @see {@link resolve} * @see {@link resolveIdentifier} * @see {@link resolveDescription} * * @stability stable * @category annotations * @since 4.0.0 */ export declare const resolveTitle: (ast: AST) => string | undefined; /** * Returns the `description` annotation from the AST node, if set. * * @see {@link resolve} * @see {@link resolveTitle} * @see {@link resolveIdentifier} * * @stability stable * @category annotations * @since 4.0.0 */ export declare const resolveDescription: (ast: AST) => string | undefined; //# sourceMappingURL=SchemaAST.d.ts.map