From 0fb25e4f39e87e6a32049f4628eeed4c5060cf5f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 27 Nov 2026 22:03:36 +0100 Subject: [PATCH] Thing contract, TypeScript: the Slot arm at key 13 with a ParamName codec; names test and refusals at key 14 Co-Authored-By: Claude Sonnet 5.5 --- packages/thing-contract/src/codecs.ts | 4 ++++ packages/thing-contract/src/types.ts | 11 ++++++++++- packages/thing-contract/test/builders.ts | 2 +- packages/thing-contract/test/codecs.test.ts | 4 ++-- packages/thing-contract/test/names.test.ts | 8 +++++--- packages/thing-contract/test/refusals.test.ts | 2 +- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/thing-contract/src/codecs.ts b/packages/thing-contract/src/codecs.ts index 1c1be30..eb55dfc 100644 --- a/packages/thing-contract/src/codecs.ts +++ b/packages/thing-contract/src/codecs.ts @@ -40,6 +40,7 @@ const readOnlyList = (item: Codec): Codec => { }; // source.rs +export const paramName = present(codecs.slots({ 0: ["name", text] }, named("ParamName"))); export const textSourceParam = present(codecs.slots({ 0: ["name", text] }, named("TextSourceParam"))); export const numberSourceParam = present(codecs.slots({ 0: ["name", text] }, named("NumberSourceParam"))); export const boolSourceParam = present(codecs.slots({ 0: ["name", text] }, named("BoolSourceParam"))); @@ -461,6 +462,8 @@ export const useNode = present(codecs.slots( named("UseNode"), )); +export const slotNode = present(codecs.slots({ 0: ["param", paramName] }, named("SlotNode"))); + const nodeUnion = present( codecs.union( "Node", @@ -478,6 +481,7 @@ const nodeUnion = present( 10: ["Plot", plotNode], 11: ["Embed", embedNode], 12: ["Use", useNode], + 13: ["Slot", slotNode], }, named("Node"), ), diff --git a/packages/thing-contract/src/types.ts b/packages/thing-contract/src/types.ts index 57adb24..40155a9 100644 --- a/packages/thing-contract/src/types.ts +++ b/packages/thing-contract/src/types.ts @@ -198,7 +198,16 @@ export type Node = | Arm<"Overlay", OverlayNode> | Arm<"Plot", PlotNode> | Arm<"Embed", EmbedNode> - | Arm<"Use", UseNode>; + | Arm<"Use", UseNode> + | Arm<"Slot", SlotNode>; +/** + * Where a composition body places the nodes passed for its Slot parameter `param`. Only a child list of a composition + * body holds one, and resolve refuses it elsewhere. It carries no NodeCommon: the argument's nodes, keeping their + * caller-scope ids, replace it. + */ +export interface SlotNode { + readonly param: ParamName; +} export interface BoxNode { readonly common: NodeCommon; readonly style: BoxStyle; diff --git a/packages/thing-contract/test/builders.ts b/packages/thing-contract/test/builders.ts index f1cd1e1..f343de4 100644 --- a/packages/thing-contract/test/builders.ts +++ b/packages/thing-contract/test/builders.ts @@ -450,7 +450,7 @@ export function fullComposition(): CompositionDocument { { name: "act", kind: { kind: "Command" } }, { name: "body", kind: { kind: "Slot" } }, ], - body: boxed("panel-root", [text("panel-title", "t"), innerUse]), + body: boxed("panel-root", [text("panel-title", "t"), innerUse, { kind: "Slot", param: { name: "body" } }]), }; } diff --git a/packages/thing-contract/test/codecs.test.ts b/packages/thing-contract/test/codecs.test.ts index a349306..b038568 100644 --- a/packages/thing-contract/test/codecs.test.ts +++ b/packages/thing-contract/test/codecs.test.ts @@ -12,8 +12,8 @@ const entries = Object.entries(codecs) as [string, { typeName?: string; decode(r const rustName = (key: string) => key[0].toUpperCase() + key.slice(1); const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt"))); -test("the package exports one hundred and one codecs", () => { - assert.equal(entries.length, 101); +test("the package exports one hundred and three codecs", () => { + assert.equal(entries.length, 103); }); test("every codec's type name is a type of the C# package", () => { diff --git a/packages/thing-contract/test/names.test.ts b/packages/thing-contract/test/names.test.ts index 51bdcf1..0fa2e55 100644 --- a/packages/thing-contract/test/names.test.ts +++ b/packages/thing-contract/test/names.test.ts @@ -13,10 +13,12 @@ const NS = "GameCult.Thing.Contract."; const names = new Set(nonEmptyLines(join(parityDir, "type-names.txt"))); const entries = Object.entries(codecs) as [string, { typeName?: string; members?: readonly { typeName: string }[] }][]; -test("ParamName and Scalar are Rust names the C# package does not have; each arm has its own codec", () => { - assert.equal(names.has(`${NS}ParamName`), false); +test("Scalar is a Rust name the C# package does not have; ParamName is its type for a slot; each Param arm has its own codec", () => { assert.equal(names.has(`${NS}Scalar`), false); - for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /\.(ParamName|Scalar)$/u, key); + for (const [key, codec] of entries) assert.doesNotMatch(codec.typeName ?? "", /.Scalar$/u, key); + assert.ok(names.has(`${NS}ParamName`)); + assert.equal(codecs.paramName.typeName, `${NS}ParamName`); + assert.equal(codecs.slotNode.typeName, `${NS}SlotNode`); const arms = { textSourceParam: "TextSourceParam", numberSourceParam: "NumberSourceParam", diff --git a/packages/thing-contract/test/refusals.test.ts b/packages/thing-contract/test/refusals.test.ts index 26e83bf..f7183e4 100644 --- a/packages/thing-contract/test/refusals.test.ts +++ b/packages/thing-contract/test/refusals.test.ts @@ -45,7 +45,7 @@ test("a Thing 1 flat map is not a command result", () => { }); test("an unknown Node arm is refused naming the union and the key", () => { - assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 13/); + assert.match(refusal(read(surfaceDocument, "node-unknown-arm.bin")), /Union Node: unknown arm key 14/); }); test("an unknown Outcome arm is refused naming the union and the key", () => {