Repository navigation
[2.x] Adapt to spec 2.0.0-rc.1 - #1196
lorisleiva wants to merge 1 commit into
Conversation
|
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Bumps the living @codama/spec pin from 2.0.0-rc.0 to 2.0.0-rc.1 and adapts the repo to the three spec changes that shipped in it:
instructionNode.returnData?: TypeNode(spec #185) — regenerated node types / constructors /identityVisitor/mergeVisitor, walk-order and generic-order entries inspec-generators, a newinInstructionReturnDatabucket ingetDefinedTypeHistogramVisitor,returnDataadded toINSTRUCTION_UPDATE_KEYS, andnodes-from-anchorv00/v01 now map Anchor'sreturnsonto it.enumValueNode.valuewidens to anyValueNode(spec #184) —EnumValuePayload/ENUM_VALUE_PAYLOAD_KINDSremoved, identity visitor assertsVALUE_NODES.- Official
codama.*plugin docs (spec #186) and the shorterpluginsdocblock — docblock-only regeneration across ~90 files.
I went through the full diff (not just the first 100 files in the listing) plus the untouched consumers that the new tests exercise. The code looks correct to me:
createSubInstructionsFromEnumDataVisitoralready spreads...nodeinto each sub-instruction, soreturnDatapropagates without a source change — the new test just pins that behaviour.unwrapInstructionDataDefinedTypesVisitorkeys offtotal === 1 && directlyAsInstructionData === 1, so a type used in bothdataandreturnDatais correctly left alone (new test covers it).dynamic-codecs'visitEnumVariantTypealready wraps any variant payload underdata, so the value visitor and codec agree for integer payloads etc. And sincereturnDatais a plainTypeNode,getNodeValueCodec([root, program, ix, ix.returnData])already yields a return-data decoder for free — no follow-up needed there.IdlV00Instruction.returns/IdlV01Instruction.returnswere already typed;typeNodeFromAnchorV00was already imported in v00;typeNodeFromAnchorV01(idlType, generics)signature matches.VALUE_NODESis already imported inidentityVisitor.ts.- Test arithmetic checks out (
expectMergeVisitorCount5 and 3, delete-nodes predicatepath.length === 2only hits the return-data integer).
Things to watch
No changeset. CONTRIBUTING.md says every user-facing change needs one, and the repo is in rc pre mode (.changeset/pre.json), so changesets are what produce the rc.1 changelog entries. This PR has several user-facing changes worth a line each: new returnData attribute (nodes/node-types/visitors-core/visitors/nodes-from-anchor), removal of EnumValuePayload + ENUM_VALUE_PAYLOAD_KINDS, and the DefinedTypeHistogram shape change (inInstructionReturnData is a new required key, so anyone constructing histograms by hand breaks). If the rc line is intentionally batching under the seeded major changeset, ignore this — but I didn't see that stated anywhere.
Positional generics shift. TReturnData is inserted after TData in InstructionNode<…> / InstructionNodeInput<…> / instructionNode<…>. Anyone passing explicit type args positionally (e.g. InstructionNode<string, [], TData, TRemainingAccounts>) will silently get the wrong slot. Generated from spec, so nothing to change here — just worth a mention in the changeset / release notes.
Pre-existing, non-blocking: getLinkUsage distinguishes data vs returnData by reference equality (child === owner.returnData). If a caller hands the same link object to both (const t = definedTypeLinkNode('x'); instructionNode({ data: t, returnData: t })), both occurrences now classify as return data, since that check runs first. The existing child === owner.data check had the same reference-equality caveat and the built-in consumers aren't affected (total is 2 either way), so I wouldn't change anything — just noting it in case a histogram test ever uses a shared reference and looks off.
For subsequent reviewers
- Generated dirs are regenerated by CI and fail on diff, so the
node-types/nodes/visitors-corebulk is mechanically verified; focus on the hand-written bits:getDefinedTypeHistogramVisitor.ts,updateInstructionsVisitor.ts,spec-generators/src/{shared/defaults,visitorsCore/options}.ts, and the twonodes-from-anchorinstruction converters. - Confirm whether a changeset is expected on this branch.

This PR updates Codama to
@codama/spec@2.0.0-rc.1.instructionNodegains an optionalreturnDatatype node, describing the data an instruction returns to its caller. It is supported by the node types, constructors and core visitors, can be set viaupdateInstructionsVisitor, is counted under a newinInstructionReturnDataentry of the defined type histogram, and is filled from Anchor'sreturnsbynodes-from-anchor.enumValueNode.valueaccepts any value node, so variants whose data is neither a struct nor a tuple can be expressed as values, e.g.enumValueNode('operation', 'amount', { value: integerValueNode('42') }). TheEnumValuePayloadtype andENUM_VALUE_PAYLOAD_KINDSconstant are removed.codama.resolverandcodama.extraArgumentplugins.