node-dextrin - v0.4.0
    Preparing search index...

    Class DXNStruct

    Opaque DXN struct value, produced when no schema is known for its name (DXN.md §1.4: "a reader lacking the schema... returns an opaque tagged value rather than failing").

    fields is one of two shapes, deliberately not normalized to a single common one — .dxn's keyed literal form carries field names; .dxnb's wire form is always positional (DXN.md §2.1) and never carries names at all. Without a schema there is no way to recover one shape from the other, so this class says which shape it actually is rather than pretend they're interchangeable — mirrors Dextrin.Struct exactly.

    version is the schema version the struct was written with — %Name(3){...}, DXN.md §4.8 — or null when it was written without one.

    extra holds the fields a struct carries beyond its declared ones (DXN.md §4.7), as [key, value] pairs in the order they were written: a name for a named field, any other map key (§1.6) as itself. In text they are entries after the fields or the items; in .dxnb, one trailing tag-215 map.

    bases and drops are what a %schema or %shape is built from (DXNS.md §4b): bases the head's extends and includes names, as [kind, name, version] in the order written (version null when the head names none), and drops the body's - field names. Every other struct has none; the schema compiler reads them.

    Index
    • Parameters

      • name: string
      • fields:
            | { pairs: [string, unknown][]; type: "keyed" }
            | { type: "positional"; values: unknown[] }
      • Optionalversion: number | null = null
      • Optionalextra: [unknown, unknown][] = []
      • Optionalbases: Base[] = []
      • Optionaldrops: string[] = []

      Returns export=

    bases: Base[]
    drops: string[]
    dxnType: string
    extra: [unknown, unknown][]
    fields:
        | { pairs: [string, unknown][]; type: "keyed" }
        | { type: "positional"; values: unknown[] }
    name: string
    version: number | null
    • The - field entries of a %schema or %shape that leaves inherited fields out (DXNS.md §4b), as they are written.

      Returns string[]

    • Whether this is a %schema or %shape built from others (DXNS.md §4b): one naming a base, or leaving a field out.

      Returns boolean

    • How this struct opens when written at version: its head, then the extends and includes clauses a %schema or %shape is built from (DXNS.md §4b), in the order the bases were written, and one space before the body. Shared by every text writer, so they agree.

      Parameters

      • Optionalversion: number | null = ...

      Returns string

      new DXNStruct('schema', {type: 'keyed', pairs: []}, 2, [], [['extends', 'User', 3], ['includes', 'Audit', null]]).opening(2)
      // => '%schema(2) extends User(3) includes Audit '
    • This struct holding fields instead, and otherwise unchanged — what every walk over a struct's fields goes through, so a walk never rebuilds a struct from its name and loses its version, or what it is built from.

      Parameters

      • fields:
            | { pairs: [string, unknown][]; type: "keyed" }
            | { type: "positional"; values: unknown[] }

      Returns export=

    • An entry's key as an extra field's key: a keyword, symbol or string is a name (its text); any other map key (DXN.md §1.6) is kept as itself.

      Parameters

      • key: unknown

      Returns unknown

    • How a struct literal opens: %Name, or %Name(3) when it carries a version. Shared by every writer, so they agree.

      Parameters

      • name: string
      • Optionalversion: number | null = null

      Returns string

    • Whether key is a name — a keyword, symbol or string — and so can be a field name rather than only an extra field's key.

      Parameters

      • key: unknown

      Returns boolean

    • Parameters

      • name: string
      • pairs: [string, unknown][]
      • Optionalversion: number | null = null
      • Optionalextra: [unknown, unknown][] = []

      Returns export=

    • The other direction: a .dxnb type name read back into its name and version, or null when its version is not a positive integer.

      Parameters

      • text: string

      Returns { name: string; version: number | null } | null

    • Parameters

      • name: string
      • values: unknown[]
      • Optionalversion: number | null = null
      • Optionalextra: [unknown, unknown][] = []

      Returns export=

    • The struct's name as .dxnb writes it: Name, or Name(3) when it carries a version (DXN.md §2.4, §4.8).

      Parameters

      • name: string
      • Optionalversion: number | null = null

      Returns string