diff --git a/packages/thing-contract/src/keys.ts b/packages/thing-contract/src/keys.ts index e87000e..ca40192 100644 --- a/packages/thing-contract/src/keys.ts +++ b/packages/thing-contract/src/keys.ts @@ -5,11 +5,11 @@ import { segment, seq, version } from "./domain.js"; export function surfaceKey(providerId: string, label: string): string { - return `thing:surface:${providerId}.${segment.decode(label)}`; + return `thing:surface:${providerId}.${segment.encode(label)}`; } export function compositionKey(publisher: string, name: string, versionNumber: number | bigint): string { - return `thing:composition:${publisher}.${segment.decode(name)}.v${version.decode(versionNumber)}`; + return `thing:composition:${publisher}.${segment.encode(name)}.v${version.encode(versionNumber)}`; } export function invocationKey(invocationId: string): string { @@ -17,9 +17,9 @@ export function invocationKey(invocationId: string): string { } export function resultKey(invocationId: string, position: number): string { - return `thing:result:${invocationId}.${seq.decode(position)}`; + return `thing:result:${invocationId}.${seq.encode(position)}`; } export function assetCatalogKey(providerId: string, catalogId: string): string { - return `thing:asset_catalog:${providerId}.${segment.decode(catalogId)}`; + return `thing:asset_catalog:${providerId}.${segment.encode(catalogId)}`; } diff --git a/packages/thing-contract/src/result.ts b/packages/thing-contract/src/result.ts index ad5ed06..cdd18fd 100644 --- a/packages/thing-contract/src/result.ts +++ b/packages/thing-contract/src/result.ts @@ -27,7 +27,7 @@ export class CommandResult { private constructor(key: typeof door, invocationId: string, position: number, outcome: Outcome) { if (key !== door) throw new Error("a CommandResult is built by its factories"); this.invocationId = invocationId; - this.seq = seq.decode(position); + this.seq = seq.encode(position); this.outcome = outcome; Object.freeze(this); } diff --git a/packages/thing-contract/test/deep.test.ts b/packages/thing-contract/test/deep.test.ts index 7ea7bfa..f6b8d34 100644 --- a/packages/thing-contract/test/deep.test.ts +++ b/packages/thing-contract/test/deep.test.ts @@ -37,7 +37,7 @@ const admits = (levels: number): boolean => { test("the deepest Box chain the bound admits round-trips on the default stack, and one more is refused", () => { let deepest = 1; while (admits(deepest + 1)) deepest++; - assert.equal(deepest, 84, "the bound admits 84 Box levels above the leaf"); + assert.equal(deepest, 83, "the bound admits 83 Box levels above the text leaf, 84 nodes deep"); assert.ok(!admits(deepest + 1)); const value = chain(deepest); diff --git a/packages/thing-contract/test/keys.test.ts b/packages/thing-contract/test/keys.test.ts index 2f0423c..c228a89 100644 --- a/packages/thing-contract/test/keys.test.ts +++ b/packages/thing-contract/test/keys.test.ts @@ -38,6 +38,9 @@ test("a result key refuses a seq below 1 and a composition key a version below 0 assert.throws(() => resultKey("x", 0), /Seq must be at least 1/); assert.throws(() => compositionKey("pub", "card", -1), /Version must be at least 0/); assert.equal(compositionKey("pub", "card", 0), "thing:composition:pub.card.v0"); + assert.throws(() => compositionKey("pub", "card", 1.5), /int64/); + assert.throws(() => resultKey("x", 1.5), /int32/); + assert.throws(() => resultKey("x", 2 ** 31), /int32/); }); test("keys are injective over their field sets", () => {