Generate typed asynchronous service capability bindings

This commit is contained in:
Timothy J. Aveni
2026-09-20 20:35:16 -07:00
parent 21502ed023
commit c4ae58831d
13 changed files with 192 additions and 21 deletions
+27
View File
@@ -0,0 +1,27 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { asyncObjectPlan } from "./async-fixture.js";
import { generateRemoteTypeScriptBindings, generatePortableTypeScriptBindings } from "../src/bindings/portable.js";
test("remote adapters expose selected typed calls, lifetimes and explicit transaction identities", async () => {
const plan = await asyncObjectPlan();
const schema = plan.definition.bindingSchema;
const source = generateRemoteTypeScriptBindings(schema, "async:controller-runtime@1");
assert.match(source, /readonly signal: AbortSignal/);
assert.match(source, /readonly "summary.set":.*options: ServerMutationOptions/);
assert.match(source, /readonly "summarize.call": \(input: string\) => Promise<string>/);
assert.doesNotMatch(source, /readonly "summary.get"|context\.conform|readonly snapshot:/);
assert.doesNotMatch(
generatePortableTypeScriptBindings(schema, "async:controller-runtime@1", { target: "browser" }),
/readonly "refresh"/,
);
const entry = schema.packages.find((p) => p.revisionId === "async:controller-runtime@1")!.exports[0]!;
entry.dependencyPorts[0]!.requirement = {
kind: "state",
valueType: { kind: "scalar", name: "string" },
primitives: ["write"],
};
assert.throws(
() => generateRemoteTypeScriptBindings(schema, "async:controller-runtime@1"),
/named transaction capability/,
);
});