effect-io-ai

Package: effect
Module: SchemaAST

SchemaAST.Objects

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

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)

import { Schema, SchemaAST } from "effect"

const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast

if (SchemaAST.isObjects(ast)) {
  for (const ps of ast.propertySignatures) {
    console.log(ps.name, ps.type._tag)
  }
  // "name" "String"
}

See

Signature

declare class Objects { constructor(
    propertySignatures: ReadonlyArray<PropertySignature>,
    indexSignatures: ReadonlyArray<IndexSignature>,
    annotations?: Schema.Annotations.Annotations,
    checks?: Checks,
    encoding?: Encoding,
    context?: Context,
    encodingChecks?: Checks
  ) }

Source

Since v4.0.0