feat(rpc): scaffold the package and shared contract types
This commit is contained in:
@@ -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"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user