Custom Validation Adapter
Wrap any schema library into a JobTypes registry and check it with the conformance suite.
Validation adapters are thin wrappers around schema libraries that produce a JobTypes registry. You can write one for any schema library, following the same pattern as the Zod, Valibot, TypeBox and ArkType adapters, and validate it with the conformance suite.
Conformance
validationAdapterConformanceCases from queuert/conformance check that:
- The adapter's eight runtime methods (
getTypeNames,validateEntry,encodeInput,decodeInput,encodeOutput,decodeOutput,validateContinueWith,validateBlockers) behave correctly. - Schema validation failures are wrapped in
JobTypeValidationErrorwith the rightcode,typeNameandcause. - The schema-to-shape inference (
z.infer,Static<>,T["infer"],v.InferOutput, etc.) threads through to the phantom job type definitions correctly.
The last point is enforced at compile time: each builder in the context has a precise return type, so an inference bug in your adapter trips a TypeScript error where the context is declared, before any case runs. The suite drives no test runner: register one test per case and run it against the context. The Zod example's spec:
src/zod-adapter.spec.ts
import {
type ValidationAdapterConformanceContext,
validationAdapterConformanceCases,
} from "queuert/conformance";
import { describe, test } from "vitest";
import { z } from "zod";
import { createZodJobTypes } from "./zod-adapter.ts";
describe("zod adapter conformance", () => {
const context: ValidationAdapterConformanceContext = {
basic: {
buildEntry: () =>
createZodJobTypes({
main: {
entry: true,
input: z.object({ id: z.string() }),
output: z.object({ ok: z.boolean() }),
},
}),
buildNonEntry: () =>
createZodJobTypes({
internal: {
input: z.object({ id: z.string() }),
output: z.object({ ok: z.boolean() }),
},
}),
buildContinuationOnly: () =>
createZodJobTypes({
main: {
entry: true,
input: z.object({ id: z.string() }),
continueWith: z.object({ typeName: z.literal("next") }),
},
next: {
input: z.object({ data: z.string() }),
output: z.object({ done: z.boolean() }),
},
}),
},
continuations: {
buildNominal: () =>
createZodJobTypes({
step1: {
entry: true,
input: z.object({ id: z.string() }),
continueWith: z.object({ typeName: z.literal("step2") }),
},
step2: {
input: z.object({ data: z.unknown() }),
output: z.object({ done: z.boolean() }),
},
}),
buildStructural: () =>
createZodJobTypes({
router: {
entry: true,
input: z.object({ route: z.string() }),
continueWith: z.object({ input: z.object({ payload: z.string() }) }),
},
handler: {
input: z.object({ payload: z.string() }),
output: z.object({ handled: z.boolean() }),
},
}),
},
blockers: {
buildNominal: () =>
createZodJobTypes({
main: {
entry: true,
input: z.object({ id: z.string() }),
output: z.object({ done: z.boolean() }),
blockers: z.array(z.object({ typeName: z.literal("auth") })),
},
auth: {
entry: true,
input: z.object({ token: z.string() }),
output: z.object({ userId: z.string() }),
},
}),
buildStructural: () =>
createZodJobTypes({
main: {
entry: true,
input: z.object({ id: z.string() }),
output: z.object({ done: z.boolean() }),
blockers: z.array(z.object({ input: z.object({ token: z.string() }) })),
},
auth: {
entry: true,
input: z.object({ token: z.string() }),
output: z.object({ userId: z.string() }),
},
}),
},
external: {
buildWithExternalSlice: () => {
const notifications = createZodJobTypes({
"notifications.send-notification": {
entry: true,
input: z.object({ userId: z.string(), message: z.string() }),
output: z.object({ sentAt: z.string() }),
},
});
return createZodJobTypes(
{
"orders.place-order": {
entry: true,
input: z.object({ userId: z.string() }),
continueWith: z.object({ typeName: z.literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: z.object({ orderId: z.number() }),
output: z.object({ confirmedAt: z.string() }),
blockers: z.tuple([
z.object({ typeName: z.literal("notifications.send-notification") }),
]),
},
},
notifications,
);
},
buildWithExternalSlices: () => {
const notifications = createZodJobTypes({
"notifications.send-notification": {
entry: true,
input: z.object({ userId: z.string(), message: z.string() }),
output: z.object({ sentAt: z.string() }),
},
});
const payments = createZodJobTypes({
"payments.charge": {
entry: true,
input: z.object({ amount: z.number() }),
output: z.object({ receiptId: z.string() }),
},
});
return createZodJobTypes(
{
"orders.place-order": {
entry: true,
input: z.object({ userId: z.string() }),
continueWith: z.object({ typeName: z.literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: z.object({ orderId: z.number() }),
output: z.object({ confirmedAt: z.string() }),
blockers: z.tuple([
z.object({ typeName: z.literal("notifications.send-notification") }),
z.object({ typeName: z.literal("payments.charge") }),
]),
},
},
[notifications, payments] as const,
);
},
},
};
for (const conformanceCase of validationAdapterConformanceCases) {
test(conformanceCase.title, async () => {
await conformanceCase.run(context);
});
}
});The exact phantom shape each builder must produce is encoded in the ValidationAdapterConformanceContext type. The full API is in the conformance reference.