2026-09-20 00:14:08 -07:00
|
|
|
/** Qualification artifact emitted after tests, never a production fixture dependency. */
|
|
|
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
|
|
|
import { loadReaderWorkspace } from "./reader-fixture.js";
|
2026-09-20 01:05:02 -07:00
|
|
|
import { compileKernelProgram } from "../src/execution-world/kernel.js";
|
2026-09-20 02:42:13 -07:00
|
|
|
import { compileQueryProgram } from "../src/execution-world/queries.js";
|
2026-09-20 00:14:08 -07:00
|
|
|
import { compileExecutionPlan } from "../src/execution-world/plan.js";
|
|
|
|
|
import { generatePortableTypeScriptBindings } from "../src/bindings/portable.js";
|
2026-09-20 01:49:56 -07:00
|
|
|
import { generatePortableClientBindings } from "../src/bindings/portable-client.js";
|
|
|
|
|
import { loadCompositeWorkspace } from "./composite-fixture.js";
|
2026-09-20 00:14:08 -07:00
|
|
|
const plan = compileExecutionPlan(await loadReaderWorkspace());
|
|
|
|
|
await mkdir("dist/portable-reader", { recursive: true });
|
|
|
|
|
for (const target of ["browser", "server"])
|
|
|
|
|
await writeFile(
|
|
|
|
|
`dist/portable-reader/${target}.ts`,
|
|
|
|
|
generatePortableTypeScriptBindings(plan.definition.bindingSchema, "package:reader-runtime@1", { target }),
|
|
|
|
|
);
|
|
|
|
|
await writeFile("dist/portable-reader/plan.json", JSON.stringify(plan));
|
2026-09-20 01:05:02 -07:00
|
|
|
await writeFile("dist/portable-reader/kernel.json", JSON.stringify(compileKernelProgram(plan)));
|
2026-09-20 02:42:13 -07:00
|
|
|
await writeFile("dist/portable-reader/queries.json", JSON.stringify(compileQueryProgram(plan)));
|
2026-09-20 01:49:56 -07:00
|
|
|
await writeFile("dist/portable-reader/client.ts", generatePortableClientBindings(plan, { target: "browser" }));
|
2026-09-20 00:25:53 -07:00
|
|
|
const serviceWorkspace = structuredClone(plan.definition.workspace);
|
|
|
|
|
serviceWorkspace.atoms = [];
|
|
|
|
|
serviceWorkspace.conformances = [];
|
|
|
|
|
serviceWorkspace.constructors = [];
|
|
|
|
|
serviceWorkspace.interfaceImports = [];
|
|
|
|
|
serviceWorkspace.sharedAttachments = [];
|
|
|
|
|
serviceWorkspace.packageImports[0]!.queries = [];
|
|
|
|
|
serviceWorkspace.packageImports[0]!.checkedQueries = [];
|
|
|
|
|
const original = serviceWorkspace.packageImports[0]!.exports.find((e) => e.kind === "function")!;
|
|
|
|
|
serviceWorkspace.packageImports[0]!.exports = [
|
|
|
|
|
{
|
|
|
|
|
...original,
|
|
|
|
|
kind: "function",
|
|
|
|
|
execution: { kind: "remote" },
|
|
|
|
|
inputType: { kind: "scalar", name: "string" },
|
|
|
|
|
outputType: { kind: "scalar", name: "string" },
|
|
|
|
|
dependencyPorts: [],
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
await writeFile("dist/portable-reader/service-plan.json", JSON.stringify(compileExecutionPlan(serviceWorkspace)));
|
2026-09-20 01:49:56 -07:00
|
|
|
const composite = compileExecutionPlan(await loadCompositeWorkspace());
|
|
|
|
|
await mkdir("dist/portable-reader/composite", { recursive: true });
|
|
|
|
|
await writeFile("dist/portable-reader/composite/plan.json", JSON.stringify(composite));
|
|
|
|
|
await writeFile("dist/portable-reader/composite/kernel.json", JSON.stringify(compileKernelProgram(composite)));
|
|
|
|
|
for (const target of ["browser", "server"])
|
|
|
|
|
for (const [name, revision] of [
|
|
|
|
|
["reader", "package:reader-runtime@1"],
|
|
|
|
|
["comment", "package:comment-runtime@1"],
|
|
|
|
|
] as const)
|
|
|
|
|
await writeFile(
|
|
|
|
|
`dist/portable-reader/composite/${name}-${target}.ts`,
|
|
|
|
|
generatePortableTypeScriptBindings(composite.definition.bindingSchema, revision, { target }),
|
|
|
|
|
);
|
2026-09-20 19:42:24 -07:00
|
|
|
|
|
|
|
|
const { portableGenericPlan } = await import("./portable-generic-fixture.js");
|
|
|
|
|
const generic = portableGenericPlan();
|
|
|
|
|
const genericPackage = generic.definition.bindingSchema.packages[0]!;
|
|
|
|
|
await mkdir("dist/portable-reader/generic", { recursive: true });
|
|
|
|
|
for (const target of ["browser", "server"]) {
|
|
|
|
|
await writeFile(
|
|
|
|
|
`dist/portable-reader/generic/${target}.ts`,
|
|
|
|
|
generatePortableTypeScriptBindings(generic.definition.bindingSchema, genericPackage.revisionId, { target }),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
const stringEntry = genericPackage.exports.find((e) => e.inputType.kind === "scalar")!;
|
|
|
|
|
const listEntry = genericPackage.exports.find((e) => e.inputType.kind === "list")!;
|
|
|
|
|
await writeFile(
|
|
|
|
|
"dist/portable-reader/generic/implementation.ts",
|
|
|
|
|
`
|
|
|
|
|
import { createRegistry, type PortableImplementation } from "./gen/qx.js";
|
|
|
|
|
export const registry = createRegistry({
|
|
|
|
|
${JSON.stringify(stringEntry.displayName)}: context => context.input.toUpperCase(),
|
|
|
|
|
${JSON.stringify(listEntry.displayName)}: context => context.input.map(value => value + 1n),
|
|
|
|
|
});
|
|
|
|
|
// The specialization must retain its actual contract, not become unknown or any.
|
|
|
|
|
const negative: PortableImplementation = {
|
|
|
|
|
// @ts-expect-error a string specialization cannot return a number
|
|
|
|
|
${JSON.stringify(stringEntry.displayName)}: context => context.input.length,
|
|
|
|
|
${JSON.stringify(listEntry.displayName)}: context => {
|
|
|
|
|
// @ts-expect-error input collections are read-only
|
|
|
|
|
context.input.push(0n);
|
|
|
|
|
// @ts-expect-error integer values are exact bigint, not number
|
|
|
|
|
const lostPrecision: number = context.input[0]!;
|
|
|
|
|
return context.input;
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
void negative;
|
|
|
|
|
`,
|
|
|
|
|
);
|
2026-09-20 20:20:47 -07:00
|
|
|
|
|
|
|
|
const { asyncObjectPlan } = await import("./async-fixture.js");
|
2026-09-20 22:15:15 -07:00
|
|
|
const { treePlan } = await import("./tree-fixture.js");
|
|
|
|
|
const tree = await treePlan();
|
|
|
|
|
await mkdir("dist/portable-reader/tree", { recursive: true });
|
|
|
|
|
await writeFile("dist/portable-reader/tree/plan.json", JSON.stringify(tree));
|
|
|
|
|
await writeFile("dist/portable-reader/tree/kernel.json", JSON.stringify(compileKernelProgram(tree)));
|
2026-09-20 21:51:43 -07:00
|
|
|
const { compile: compileAcceptance } = await import("./acceptance-fixture.js");
|
|
|
|
|
const acceptance = compileAcceptance();
|
|
|
|
|
if (!acceptance.ok) throw Error(JSON.stringify(acceptance.diagnostics));
|
|
|
|
|
const acceptancePlan = compileExecutionPlan(acceptance.workspace);
|
|
|
|
|
await mkdir("dist/portable-reader/acceptance", { recursive: true });
|
|
|
|
|
await writeFile("dist/portable-reader/acceptance/plan.json", JSON.stringify(acceptancePlan));
|
|
|
|
|
await writeFile("dist/portable-reader/acceptance/kernel.json", JSON.stringify(compileKernelProgram(acceptancePlan)));
|
2026-09-20 21:40:14 -07:00
|
|
|
const { recurringTaskPlan } = await import("./recurring-fixture.js");
|
|
|
|
|
const recurringPlan = await recurringTaskPlan();
|
|
|
|
|
await mkdir("dist/portable-reader/recurring", { recursive: true });
|
|
|
|
|
await writeFile("dist/portable-reader/recurring/plan.json", JSON.stringify(recurringPlan));
|
|
|
|
|
await writeFile("dist/portable-reader/recurring/kernel.json", JSON.stringify(compileKernelProgram(recurringPlan)));
|
2026-09-20 20:20:47 -07:00
|
|
|
const { generateRemoteTypeScriptBindings } = await import("../src/bindings/portable.js");
|
|
|
|
|
const asyncPlan = await asyncObjectPlan();
|
|
|
|
|
await mkdir("dist/portable-reader/async", { recursive: true });
|
|
|
|
|
await writeFile("dist/portable-reader/async/plan.json", JSON.stringify(asyncPlan));
|
|
|
|
|
await writeFile("dist/portable-reader/async/kernel.json", JSON.stringify(compileKernelProgram(asyncPlan)));
|
|
|
|
|
for (const [name, revision] of [
|
|
|
|
|
["controller", "async:controller-runtime@1"],
|
|
|
|
|
["provider", "async:provider-runtime@2"],
|
|
|
|
|
] as const)
|
|
|
|
|
await writeFile(
|
|
|
|
|
`dist/portable-reader/async/${name}.ts`,
|
|
|
|
|
generateRemoteTypeScriptBindings(asyncPlan.definition.bindingSchema, revision),
|
|
|
|
|
);
|