(ast: SchemaAST.AST): DocumentConverts a Schema AST into a Document.
When to use
Use when you have a single Schema AST and need a schema representation document.
Details
Shared/recursive sub-schemas are extracted into the references map.
Example (Converting a Schema to a Document)
import { Schema, SchemaRepresentation } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number
})
const doc = SchemaRepresentation.fromAST(Person.ast)
console.log(doc.representation._tag)
// "Objects"export const const fromAST: (
ast: SchemaAST.AST
) => Document
Converts a Schema AST into a
Document
.
When to use
Use when you have a single Schema AST and need a schema representation
document.
Details
Shared/recursive sub-schemas are extracted into the references map.
Example (Converting a Schema to a Document)
import { Schema, SchemaRepresentation } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number
})
const doc = SchemaRepresentation.fromAST(Person.ast)
console.log(doc.representation._tag)
// "Objects"
fromAST: (ast: SchemaAST.ASTast: import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated 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 Document = {
readonly representation: Representation
readonly references: References
}
A single
Representation
together with its named
References
.
When to use
Use when representing a single Schema AST together with its named references
before reconstructing a runtime Schema, converting to JSON Schema, or
wrapping it as a
MultiDocument
.
Document = import InternalRepresentationInternalRepresentation.function fromAST(
ast: SchemaAST.AST
): SchemaRepresentation.Document
fromAST