feat(rpc): scaffold the package and shared contract types

This commit is contained in:
2026-08-05 09:52:48 +05:30
parent 63e6148cdb
commit e1fca3eddf
6 changed files with 137 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import { v } from "@wrnexus/validation";
import type { InferInput, ProcedureDef, ServiceContract } from "../src/types.ts";
describe("rpc types", () => {
test("InferInput extracts the validated shape from a schema", () => {
const schema = v.object({ userId: v.string(), amountCents: v.number() });
// Compile-time assertion: assigning a correctly-shaped value must typecheck.
const value: InferInput<typeof schema> = { userId: "u1", amountCents: 10 };
expect(value.userId).toBe("u1");
});
test("a contract carries its procedure map", () => {
const contract: ServiceContract<{ ping: ProcedureDef }> = {
name: "demo",
procedures: { ping: {} },
};
expect(contract.name).toBe("demo");
expect(Object.keys(contract.procedures)).toEqual(["ping"]);
});
});