Minor Changes
-
#997
0b3a781Thanks @lorisleiva! - Regenerate thexxxNodeInputtypes andxxxNode()constructors of@codama/nodesfrom the encoded@codama/specdescription, via a newnodesgenerator inside@codama-internal/spec-generators. The runtime*_NODE_KINDSarrays (STANDALONE_TYPE_NODE_KINDS,REGISTERED_VALUE_NODE_KINDS,INSTRUCTION_INPUT_VALUE_NODE_KINDS, …, and the top-levelREGISTERED_NODE_KINDS) are now generated from the spec's union definitions instead of being maintained by hand. A new top-levelCODAMA_VERSIONconstant, typed asCodamaVersionand pinned to the spec version at generation time, is the single source of truth for the version@codama/nodeswas 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 everypnpm generaterun. The previously hand-maintained constructors and kinds-arrays are gone; only hand-written helpers (isNode,assertIsNode,getAllPrograms,getAllInstructions,getAllInstructionsWithSubs,isScalarEnum,isDataEnum,isSignedInteger, theNestedTypeNoderesolvers,parseOptionalAccountStrategy, the legacyconstantValueNodeFromString/constantPdaSeedNodeFromStringflavours, etc.) survive at the top ofpackages/nodes/src/. The package'sindex.tsre-exports the generated tree alongside them.Two intentional behaviour changes shake out of the rebuild:
docsis now omitted entirely from the encoded shape when it would be empty. Constructors that accept adocs?: DocsInputparameter previously emitteddocs: []on the frozen node when the caller said nothing about docs; they now drop thedocskey altogether. This matches the Rust side, keeps absent documentation out of serialised IDLs, and aligns with thedocs?: Docsoptional field already declared by@codama/node-types.removeDocsVisitorin@codama/visitors-coreis updated to delete thedocskey rather than blank it to[], following the same convention.rootNode().versionnow reflects the spec version@codama/nodeswas generated against, not the runtime package version. The constructor previously read the__VERSION__build-time global injected from the package'snpm_package_version; it now reads the generatedCODAMA_VERSIONconstant. 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 itspackages/nodes/src/types/global.d.tsdeclaration 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_KINDSnames.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
optionsbag), 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, theXxxNodeInputdeclarations, thePartial<>wrapping decision, thename: stringrelaxation, thedocs?: 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 samenarrowableDataAttributes+genericParamOrdertables thenodeTypesgenerator uses, keeping the constructor's generics in lockstep with the interface's.