(ast: AST): ASTSwaps the decode and encode directions of an AST's Encoding chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
export const const flip: anySwaps the decode and encode directions of an AST's
Encoding
chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
flip = import memoizememoize((ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST): type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST => {
if (ast: ASTast.Base.encoding: Encoding | undefinedencoding) {
return function flipEncoding(
ast: AST,
encoding: Encoding
): AST
flipEncoding(ast: ASTast, ast: ASTast.Base.encoding: Encoding | undefined(property) Base.encoding: {
0: Link;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Link>>): Array<Link>; (...items: Array<Link | ConcatArray<Link>>): Array<Link> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Link>;
indexOf: (searchElement: Link, fromIndex?: number) => number;
lastIndexOf: (searchElement: Link, fromIndex?: number) => number;
every: { (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Link, index: number, array: ReadonlyArray<Link>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Link, index: number, array: ReadonlyArray<Link>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => unknown, thisArg?: any): Array<Link> };
reduce: { (callbackfn: (previousValue: Link, currentValue: Link, currentIndex: number, array: ReadonlyArray<Link>) => Link): Link; (callbackfn: (previousValue: Link, currentValue: Link, currentIndex: number, array: ReadonlyArray<Link>) => Link, in…;
reduceRight: { (callbackfn: (previousValue: Link, currentValue: Link, currentIndex: number, array: ReadonlyArray<Link>) => Link): Link; (callbackfn: (previousValue: Link, currentValue: Link, currentIndex: number, array: ReadonlyArray<Link>) => Link, in…;
find: { (predicate: (value: Link, index: number, obj: ReadonlyArray<Link>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Link, index: number, obj: ReadonlyArray<Link>) => unknown, thisArg?: any): Link | undefined };
findIndex: (predicate: (value: Link, index: number, obj: ReadonlyArray<Link>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Link]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Link>;
includes: (searchElement: Link, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Link, index: number, array: Array<Link>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Link | undefined;
findLast: { (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => unknown, thisArg?: any): Link | undefined };
findLastIndex: (predicate: (value: Link, index: number, array: ReadonlyArray<Link>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Link>;
toSorted: (compareFn?: ((a: Link, b: Link) => number) | undefined) => Array<Link>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Link>): Array<Link>; (start: number, deleteCount?: number): Array<Link> };
with: (index: number, value: Link) => Array<Link>;
}
encoding)
}
const const out: anyout: any = ast: ASTast
return const out: anyout.flip?.(const flip: anySwaps the decode and encode directions of an AST's
Encoding
chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
flip) ?? const out: anyout.recur?.(const flip: anySwaps the decode and encode directions of an AST's
Encoding
chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
flip) ?? const out: anyout
})