feat(tii): type-directed argument encoding to the TaggedArg wire form#36
Merged
Conversation
Mirror the Rust reference: marshal every arg through one recursive walk over (ParamType, value) in `tii/encode.ts`, wired into `intoResolveRequest`. A scalar leaf renders bare at the top level (the resolver coerces it via the flat type) and tagged when nested in an aggregate; aggregates (list/tuple/map/record/variant) render to the self-describing tagged form. No separate scalar/aggregate path. Records map the user's by-name object to positional `struct` fields in declared (`required`-array) order; variants resolve the case index from the `oneOf` ordering; map keys are `string` leaves, pairs sorted. Ill- shaped values are rejected before sending. BREAKING: the `record` ParamType now carries ordered `RecordField[]` (`[name, type]`) instead of a name->type object, with a by-name `field` accessor. Tests drive the shared cross-SDK oracle (accept + reject vectors). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Parity with the Rust SDK: encodes an argument of an aggregate type (record,
List,Map,Tuple, variant) into the TRPTaggedArgwire form. Newtii/encode.ts, wired intointoResolveRequest.One walk, not two paths
encode(param, value)is a single recursive walk over(type, value)— scalars are the leaf cases. A scalar leaf renders bare at the top level (resolver coerces via the flat TIR type) and tagged when nested; aggregates always render to their tagged structural form. Bare top-level scalars keep their pre-existing wire shape, so scalar-only protocols are unaffected.Encoding rules
structfields in declared order, from the schema'srequiredarray (tx3cemits source order;propertiesis alphabetized and must not drive order).constructor= theoneOfcase index.[key, value]pairs; keys arestringleaves (the.tiierases the key type), pairs sorted.Breaking change
The
recordParamTypenow carries orderedRecordField[]([name, type]) instead of aRecord<string, ParamType>, with a by-namefieldaccessor. Coordinated breaking SDK change; version bump + publish are a separate release step.Tests
Vector-driven over the shared cross-SDK oracle (
tests/fixtures/wire-vectors.json, mirrored fromsdk-spec): accept vectors encode byte-equal, reject vectors throw; plus theMetafield-order regression, top-level-bare vs nested-tagged, and an end-to-endintoResolveRequestcheck.npm run test:unit(150) +type-checkgreen.🤖 Generated with Claude Code