github codama-idl/codama @codama/visitors-core@1.8.0

latest releases: @codama/visitors@1.8.0, @codama/errors@1.8.0, @codama/renderers-core@1.3.9...
6 hours ago

Minor Changes

  • #1000 b1f6a75 Thanks @lorisleiva! - Regenerate identityVisitor and mergeVisitor from @codama/spec via the new visitorsCore generator in @codama-internal/spec-generators. Both visitors previously lived as ~1100 lines of hand-written per-node dispatch; the mechanical walk now lives under src/generated/. src/identityVisitor.ts is now a thin wrapper layering six semantic overrides (enum-variant empty-downgrade, hidden-prefix/suffix empty-bypass, conditional-value null-collapse, resolver empty-dependsOn collapse) via extendVisitor; src/mergeVisitor.ts ships directly from the generated tree.

    Three behaviour changes shake out:

    • enumTypeNode.size and pdaValueNode.programId are now actually walked by identityVisitor. The hand-written code passed both through unchanged, silently dropping any caller-applied transforms.
    • Every required-array child attribute now uniformly tolerates undefined at runtime. The hand-written guard previously applied only to programNode.events and programNode.constants. Making it uniform lets identityVisitor safely normalise a partial IDL JSON parsed via createFromJson. A follow-up PR will promote the affected programNode children to optionalAttribute(...) on the spec side, after which the guard becomes naturally derivable from the spec.
    • enumStructVariantTypeNode.discriminator and enumTupleVariantTypeNode.discriminator are now preserved when the variant survives the wrapper's empty-downgrade.

Patch Changes

  • #997 0b3a781 Thanks @lorisleiva! - Regenerate the xxxNodeInput types and xxxNode() constructors of @codama/nodes from the encoded @codama/spec description, via a new nodes generator inside @codama-internal/spec-generators. The runtime *_NODE_KINDS arrays (STANDALONE_TYPE_NODE_KINDS, REGISTERED_VALUE_NODE_KINDS, INSTRUCTION_INPUT_VALUE_NODE_KINDS, …, and the top-level REGISTERED_NODE_KINDS) are now generated from the spec's union definitions instead of being maintained by hand. A new top-level CODAMA_VERSION constant, typed as CodamaVersion and pinned to the spec version at generation time, is the single source of truth for the version @codama/nodes was built against — rootNode() reads it directly when tagging the document.

    The bulk of the surface lives under packages/nodes/src/generated/ and is produced on every pnpm generate run. The previously hand-maintained constructors and kinds-arrays are gone; only hand-written helpers (isNode, assertIsNode, getAllPrograms, getAllInstructions, getAllInstructionsWithSubs, isScalarEnum, isDataEnum, isSignedInteger, the NestedTypeNode resolvers, parseOptionalAccountStrategy, the legacy constantValueNodeFromString / constantPdaSeedNodeFromString flavours, etc.) survive at the top of packages/nodes/src/. The package's index.ts re-exports the generated tree alongside them.

    Two intentional behaviour changes shake out of the rebuild:

    • docs is now omitted entirely from the encoded shape when it would be empty. Constructors that accept a docs?: DocsInput parameter previously emitted docs: [] on the frozen node when the caller said nothing about docs; they now drop the docs key altogether. This matches the Rust side, keeps absent documentation out of serialised IDLs, and aligns with the docs?: Docs optional field already declared by @codama/node-types. removeDocsVisitor in @codama/visitors-core is updated to delete the docs key rather than blank it to [], following the same convention.
    • rootNode().version now reflects the spec version @codama/nodes was generated against, not the runtime package version. The constructor previously read the __VERSION__ build-time global injected from the package's npm_package_version; it now reads the generated CODAMA_VERSION constant. In practice the two have always tracked the same release cadence so the change is invisible at HEAD, but it makes the architectural intent explicit: the version pinned in the IDL is the spec version, not the package version. The __VERSION__ build-time global and its packages/nodes/src/types/global.d.ts declaration are removed accordingly.

    The legacy plural-noun constants (TYPE_NODES, VALUE_NODES, CONTEXTUAL_VALUE_NODES, INSTRUCTION_INPUT_VALUE_NODES, COUNT_NODES, DISCRIMINATOR_NODES, LINK_NODES, PDA_SEED_NODES, ENUM_VARIANT_TYPE_NODES) are preserved as alias re-exports of the new canonical *_NODE_KINDS names.

    The generator drives almost entirely from the spec, with a minimal per-node configuration table carrying only the conveniences the spec can't express: which spec attributes appear as bare positional parameters (the rest land in a trailing options bag), and per-attribute overrides for defaulted values, string-coercion patterns on link targets, and the handful of bespoke body expressions (instructionByteDeltaNode.withHeader). The renderer derives signature shapes, generic parameters, return types, the XxxNodeInput declarations, the Partial<> wrapping decision, the name: string relaxation, the docs?: DocsInput / drop-if-empty handling, and the conditional-spread of optional attributes from the spec directly. An auto-import scan walks each rendered file and pulls in any spec or hand-written identifier the source references, so the configuration never declares imports. Generic-parameter lifting and ordering rely on the same narrowableDataAttributes + genericParamOrder tables the nodeTypes generator uses, keeping the constructor's generics in lockstep with the interface's.

  • Updated dependencies [0b3a781]:

    • @codama/nodes@1.8.0
    • @codama/errors@1.8.0

Don't miss a new codama release

NewReleases is sending notifications on new releases.