(ast: AST): ASTReturns 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)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const encodedAst = SchemaAST.toEncoded(schema.ast)
console.log(encodedAst._tag) // "String"export const const toEncoded: (ast: AST) => ASTReturns 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)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const encodedAst = SchemaAST.toEncoded(schema.ast)
console.log(encodedAst._tag) // "String"
toEncoded = memoize<AST, AST>(f: (a: AST) => AST): (ast: AST) => ASTCreates a memoized function whose input is an object, caching results by
object identity.
When to use
Use to reuse the result of a synchronous computation whose output is stable
for a given object reference.
Details
Each memoized wrapper owns a private WeakMap keyed by object identity.
Cached undefined results are still returned because the cache is checked
with WeakMap.has.
Gotchas
Structurally equal objects do not share cache entries. If the same object is
mutated after its first call, later calls still return the cached result for
that reference.
memoize((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 => {
return const toType: <A extends AST>(ast: A) => AStrips 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 (
Arrays
,
Objects
,
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"
toType(const flip: (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.
flip(ast: ASTast))
})