Delta-Pack - v0.2.9
    Preparing search index...

    Function parseSchemaYml

    • Parse a YAML schema definition into Delta-Pack type objects.

      This function converts a YAML schema string into a record of named types that can be passed to load. Use this when you want to define schemas in YAML files rather than TypeScript code.

      Parameters

      • yamlContent: string

        The YAML schema as a string

      Returns Record<string, NamedType>

      A record mapping type names to their parsed NamedType definitions

      const yaml = `
      Position:
      x: float(precision=0.01)
      y: float(precision=0.01)

      Player:
      name: string
      score: uint
      position: Position

      Direction:
      - up
      - down
      - left
      - right
      `;

      const types = parseSchemaYml(yaml);
      const api = load<Player>(types.Player);
      // Load schema from file
      import { readFileSync } from "fs";

      const schema = parseSchemaYml(readFileSync("schema.yml", "utf-8"));
      const api = load(schema.GameState);

      YAML schema syntax:

      • Objects: Key-value pairs where values are property types
      • Enums: Arrays of string literals
      • Unions: Arrays where all items are references to other schema types
      • Primitives: string, int, uint, float, boolean
      • Parameterized: int(min=0, max=100), float(precision=0.01)
      • Containers: Type[] (array), Type? (optional), <Key, Value> (record)
      • References: Use the type name directly (e.g., position: Position)