Validation
Runtime validation of job inputs, outputs, continuations and blockers with Zod, Valibot, TypeBox or ArkType.
Queuert's runtime validation follows an adapter pattern. The core provides createJobTypes, which accepts raw validation and codec functions. Schema-specific adapters (Zod, Valibot, TypeBox, ArkType) are implemented in user-land, wrapping their respective schema libraries into the JobTypes interface.
Each adapter:
- Accepts schema definitions in the library's native format.
- Infers the job type definitions from the schemas, providing the same compile-time safety as
defineJobTypes. - Calls
createJobTypeswith functions that delegate to the schema library.
When to use runtime validation instead of the type-only defineJobTypes is covered in the Runtime Validation guide.
Runtime form vs stored form
A job type definition's input and output describe the runtime form — what a handler receives and what a client read returns. The stored form is what the state adapter persists, and it must be JSON-serializable.
The two forms are bridged by an encoder and a decoder for each of input and output:
encodeInput/encodeOutputrun on every write, turning the runtime form into the stored form.decodeInput/decodeOutputrun on every read, turning the stored form back into the runtime form.
For most schemas the two forms are identical and both methods are a validation pass that returns the value unchanged. They diverge when a schema transforms — a Date in the handler stored as an ISO string, for instance. Whatever an encoder returns is checked against isJsonSerializable by createJobTypes itself, so an adapter that lets a Date reach storage fails on the first write, before anything is stored.
defineJobTypes has no codec, so the runtime form is the stored form: it constrains input and output to JSON-serializable types at compile time, and a definition carrying a Date, Map or bigint is a type error.
Define job types
src/index.ts
// Define job types with Zod schemas
const jobTypes = createZodJobTypes({
// Entry point with nominal continuation validation
"fetch-data": {
entry: true,
input: z.object({
url: z.url(),
headers: z.record(z.string(), z.string()).optional(),
}),
// Nominal validation: validates by type name
continueWith: z.object({
typeName: z.literal("process-data"),
}),
},
// Continuation job
"process-data": {
input: z.object({
data: z.object({
items: z.array(z.number()),
source: z.string(),
}),
}),
output: z.object({
processed: z.boolean(),
itemCount: z.number(),
}),
},
// Entry point with structural blocker validation
"batch-process": {
entry: true,
input: z.object({
batchId: z.string(),
}),
output: z.object({
success: z.boolean(),
}),
// Structural validation: any blocker with { token: string } input is valid
blockers: z.array(
z.object({
input: z.object({ token: z.string() }),
}),
),
},
// Auth job - can be used as blocker due to structural match
auth: {
entry: true,
input: z.object({
token: z.string(),
}),
output: z.object({
userId: z.string(),
}),
},
});src/index.ts
// Define job types with Valibot schemas
const jobTypes = createValibotJobTypes({
// Entry point with nominal continuation validation
"fetch-data": {
entry: true,
input: v.object({
url: v.pipe(v.string(), v.url()),
headers: v.optional(v.record(v.string(), v.string())),
}),
// Nominal validation: validates by type name
continueWith: v.object({
typeName: v.literal("process-data"),
}),
},
// Continuation job
"process-data": {
input: v.object({
data: v.unknown(),
}),
output: v.object({
processed: v.boolean(),
itemCount: v.number(),
}),
},
// Entry point with structural blocker validation
"batch-process": {
entry: true,
input: v.object({
batchId: v.string(),
}),
output: v.object({
success: v.boolean(),
}),
// Structural validation: any blocker with { token: string } input is valid
blockers: v.array(
v.object({
input: v.object({ token: v.string() }),
}),
),
},
// Auth job - can be used as blocker due to structural match
auth: {
entry: true,
input: v.object({
token: v.string(),
}),
output: v.object({
userId: v.string(),
}),
},
});src/index.ts
// URL format for TypeBox (simplified pattern)
const UrlString = Type.String({ pattern: "^https?://" });
// Define job types with TypeBox schemas
const jobTypes = createTypeBoxJobTypes({
// Entry point with nominal continuation validation
"fetch-data": {
entry: true,
input: Type.Object({
url: UrlString,
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
}),
// Nominal validation: validates by type name
continueWith: Type.Object({
typeName: Type.Literal("process-data"),
}),
},
// Continuation job
"process-data": {
input: Type.Object({
data: Type.Unknown(),
}),
output: Type.Object({
processed: Type.Boolean(),
itemCount: Type.Number(),
}),
},
// Entry point with structural blocker validation
"batch-process": {
entry: true,
input: Type.Object({
batchId: Type.String(),
}),
output: Type.Object({
success: Type.Boolean(),
}),
// Structural validation: any blocker with { token: string } input is valid
blockers: Type.Array(
Type.Object({
input: Type.Object({ token: Type.String() }),
}),
),
},
// Auth job - can be used as blocker due to structural match
auth: {
entry: true,
input: Type.Object({
token: Type.String(),
}),
output: Type.Object({
userId: Type.String(),
}),
},
});src/index.ts
// Define job types with ArkType schemas
const jobTypes = createArkTypeJobTypes({
// Entry point with nominal continuation validation
"fetch-data": {
entry: true,
input: type({
url: "string.url",
"headers?": "Record<string, string>",
}),
// Nominal validation: validates by type name
continueWith: type({
typeName: "'process-data'",
}),
},
// Continuation job
"process-data": {
input: type({
data: "unknown",
}),
output: type({
processed: "boolean",
itemCount: "number",
}),
},
// Entry point with structural blocker validation
"batch-process": {
entry: true,
input: type({
batchId: "string",
}),
output: type({
success: "boolean",
}),
// Structural validation: any blocker with { token: string } input is valid
blockers: type({
input: { token: "string" },
}).array(),
},
// Auth job - can be used as blocker due to structural match
auth: {
entry: true,
input: type({
token: "string",
}),
output: type({
userId: "string",
}),
},
});The adapter
Complete adapter implementations for each library. What each one costs per job is on the Runtime Performance page.
src/zod-adapter.ts
/**
* Zod Adapter for Queuert Runtime Validation
*
* This is a user-land adapter that shows how to integrate Zod with Queuert's
* runtime validation system. The same pattern applies to Valibot, ArkType,
* or any other validation library.
*
* Every schema here is identity: `z.input` equals `z.output`, so each field's
* encoder and decoder are the same validation pass. A schema that transforms
* would be applied again on every read; see `examples/validation/codec-zod` for the
* transforming case, where the runtime form and the stored form differ (a
* `Date` handler-side, an ISO string at rest).
*
* Each schema is compiled once with `z.compile`, so the parse that runs on every
* job read and write takes Zod's generated fast path. A schema Zod cannot compile
* keeps its regular parser.
*/
import {
type BaseJobTypeDefinitions,
type JobTypesDefinitions,
type JobTypeDefinitionErrors,
type JobTypeReference,
type JobTypes,
type ValidatedJobTypeDefinitions,
createJobTypes,
} from "queuert";
import { z } from "zod";
/**
* Schema definition for a single job type using Zod.
*/
export type ZodJobTypeSchema = {
/** Whether this job type can start a chain (entry point). Default: false */
entry?: boolean;
/** Zod schema for validating job input */
input: z.ZodType;
/** Zod schema for validating job output. Omit if job must continue. */
output?: z.ZodType;
/**
* Zod schema for validating continuation targets.
* Receives { typeName, input } object at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Nominal: validate by type name only
* continueWith: z.object({ typeName: z.literal("step2") })
*
* // Structural: validate by input shape only
* continueWith: z.object({ input: z.object({ payload: z.unknown() }) })
*
* // Both: validate type name and input shape
* continueWith: z.object({ typeName: z.literal("step2"), input: z.object({ data: z.string() }) })
*/
continueWith?: z.ZodType<JobTypeReference>;
/**
* Zod schema for validating blocker references.
* Receives array of { typeName, input } objects at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Fixed blockers by name (tuple)
* blockers: z.tuple([
* z.object({ typeName: z.literal("auth") }),
* z.object({ typeName: z.literal("config") }),
* ])
*
* // Variable blockers by name (array)
* blockers: z.array(z.object({ typeName: z.literal("processor") }))
*
* // Structural validation: any blocker with matching input shape
* blockers: z.array(z.object({ input: z.object({ token: z.string() }) }))
*/
blockers?: z.ZodType<readonly JobTypeReference[]>;
};
/**
* Infer BaseJobTypeDefinitions from Zod schemas.
* This enables compile-time type safety for the job types.
*/
type InferZodJobTypes<T extends Record<string, ZodJobTypeSchema>> = {
[K in keyof T & string]: {
entry: T[K]["entry"] extends true ? true : undefined;
input: z.infer<T[K]["input"]>;
output: T[K]["output"] extends z.ZodType ? z.infer<T[K]["output"]> : undefined;
continueWith: T[K]["continueWith"] extends z.ZodType<infer U>
? U extends JobTypeReference
? U
: JobTypeReference
: undefined;
blockers: T[K]["blockers"] extends z.ZodType<infer U>
? U extends readonly JobTypeReference[]
? U
: readonly JobTypeReference[]
: undefined;
};
};
/**
* Create a Zod-based job type registry.
*
* This adapter:
* 1. Accepts Zod schemas for each job type
* 2. Infers TypeScript types from the schemas
* 3. Validates at runtime using Zod's .parse() method
*
* Errors thrown by Zod are caught by the core registry and wrapped
* in JobTypeValidationError with the appropriate error code.
*
* @example
* const jobTypes = createZodJobTypes({
* "process-data": {
* entry: true,
* input: z.object({ dataId: z.string() }),
* output: z.object({ result: z.number() }),
* },
* "send-notification": {
* entry: true,
* input: z.object({ userId: z.string(), message: z.string() }),
* output: z.object({ sent: z.boolean() }),
* },
* });
*/
export const createZodJobTypes = <
const T extends Record<string, ZodJobTypeSchema>,
const TExternal extends
| JobTypes<BaseJobTypeDefinitions>
| readonly JobTypes<BaseJobTypeDefinitions>[] = readonly [],
>(
schemas: [InferZodJobTypes<T>] extends [
ValidatedJobTypeDefinitions<InferZodJobTypes<T>, JobTypesDefinitions<TExternal>>,
]
? T
: JobTypeDefinitionErrors<InferZodJobTypes<T>, JobTypesDefinitions<TExternal>>,
_externalDefinitions?: TExternal,
) => {
const _schemas = Object.fromEntries(
Object.entries(schemas as Record<string, ZodJobTypeSchema>).map(([typeName, schema]) => [
typeName,
{
entry: schema.entry,
input: z.compile(schema.input),
output: schema.output && z.compile(schema.output),
continueWith: schema.continueWith && z.compile(schema.continueWith),
blockers: schema.blockers && z.compile(schema.blockers),
},
]),
);
const getSchema = (typeName: string): ZodJobTypeSchema => {
const schema = _schemas[typeName];
if (!schema) {
throw new Error(`Unknown job type: ${typeName}`);
}
return schema;
};
const parseInput = (typeName: string, input: unknown): unknown =>
getSchema(typeName).input.parse(input);
const parseOutput = (typeName: string, output: unknown): unknown => {
const schema = getSchema(typeName).output;
if (!schema) throw new Error(`Job type "${typeName}" does not have an output schema`);
return schema.parse(output);
};
return createJobTypes<InferZodJobTypes<T>, JobTypesDefinitions<TExternal>>({
getTypeNames: () => Object.keys(_schemas),
validateEntry: (typeName) => {
const schema = getSchema(typeName);
if (schema.entry !== true) {
throw new Error(`Job type "${typeName}" is not an entry point`);
}
},
encodeInput: parseInput,
decodeInput: parseInput,
encodeOutput: parseOutput,
decodeOutput: parseOutput,
validateContinueWith: (typeName, continuation) => {
const schema = getSchema(typeName);
if (schema.continueWith) {
schema.continueWith.parse(continuation);
} else {
throw new Error(`Job type "${typeName}" does not support continuations`);
}
},
validateBlockers: (typeName, blockers) => {
const schema = getSchema(typeName);
if (schema.blockers) {
schema.blockers.parse(blockers);
} else if (blockers.length > 0) {
throw new Error(`Job type "${typeName}" does not support blockers`);
}
},
});
};src/valibot-adapter.ts
/**
* Valibot Adapter for Queuert Runtime Validation
*
* This is a user-land adapter that shows how to integrate Valibot with Queuert's
* runtime validation system. The same pattern applies to Zod, ArkType,
* or any other validation library.
*
* The stored form equals the runtime form, so one validation pass serves as both
* encoder and decoder and returns the value it checked. A schema that transforms
* would be applied again on every read; use a codec adapter such as
* `examples/validation/codec-zod` for one.
*/
import {
type BaseJobTypeDefinitions,
type JobTypesDefinitions,
type JobTypeDefinitionErrors,
type JobTypeReference,
type JobTypes,
type ValidatedJobTypeDefinitions,
createJobTypes,
} from "queuert";
import * as v from "valibot";
/**
* Schema definition for a single job type using Valibot.
*/
export type ValibotJobTypeSchema = {
/** Whether this job type can start a chain (entry point). Default: false */
entry?: boolean;
/** Valibot schema for validating job input */
input: v.GenericSchema;
/** Valibot schema for validating job output. Omit if job must continue. */
output?: v.GenericSchema;
/**
* Valibot schema for validating continuation targets.
* Receives { typeName, input } object at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Nominal: validate by type name only
* continueWith: v.object({ typeName: v.literal("step2") })
*
* // Structural: validate by input shape only
* continueWith: v.object({ input: v.object({ payload: v.unknown() }) })
*
* // Both: validate type name and input shape
* continueWith: v.object({ typeName: v.literal("step2"), input: v.object({ data: v.string() }) })
*/
continueWith?: v.GenericSchema<JobTypeReference>;
/**
* Valibot schema for validating blocker references.
* Receives array of { typeName, input } objects at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Fixed blockers by name (tuple)
* blockers: v.tuple([
* v.object({ typeName: v.literal("auth") }),
* v.object({ typeName: v.literal("config") }),
* ])
*
* // Variable blockers by name (array)
* blockers: v.array(v.object({ typeName: v.literal("processor") }))
*
* // Structural validation: any blocker with matching input shape
* blockers: v.array(v.object({ input: v.object({ token: v.string() }) }))
*/
blockers?: v.GenericSchema<readonly JobTypeReference[]>;
};
/**
* Infer BaseJobTypeDefinitions from Valibot schemas.
* This enables compile-time type safety for the job types.
*/
type InferValibotJobTypes<T extends Record<string, ValibotJobTypeSchema>> = {
[K in keyof T & string]: {
entry: T[K]["entry"] extends true ? true : undefined;
input: v.InferOutput<T[K]["input"]>;
output: T[K]["output"] extends v.GenericSchema ? v.InferOutput<T[K]["output"]> : undefined;
continueWith: T[K]["continueWith"] extends v.GenericSchema<infer U>
? U extends JobTypeReference
? U
: JobTypeReference
: undefined;
blockers: T[K]["blockers"] extends v.GenericSchema<infer U>
? U extends readonly JobTypeReference[]
? U
: readonly JobTypeReference[]
: undefined;
};
};
/**
* Create a Valibot-based job type registry.
*
* This adapter:
* 1. Accepts Valibot schemas for each job type
* 2. Infers TypeScript types from the schemas
* 3. Validates at runtime using Valibot's parse() function
*
* Errors thrown by Valibot are caught by the core registry and wrapped
* in JobTypeValidationError with the appropriate error code.
*
* @example
* const jobTypes = createValibotJobTypes({
* "process-data": {
* entry: true,
* input: v.object({ dataId: v.string() }),
* output: v.object({ result: v.number() }),
* },
* "send-notification": {
* entry: true,
* input: v.object({ userId: v.string(), message: v.string() }),
* output: v.object({ sent: v.boolean() }),
* },
* });
*/
export const createValibotJobTypes = <
const T extends Record<string, ValibotJobTypeSchema>,
const TExternal extends
| JobTypes<BaseJobTypeDefinitions>
| readonly JobTypes<BaseJobTypeDefinitions>[] = readonly [],
>(
schemas: [InferValibotJobTypes<T>] extends [
ValidatedJobTypeDefinitions<InferValibotJobTypes<T>, JobTypesDefinitions<TExternal>>,
]
? T
: JobTypeDefinitionErrors<InferValibotJobTypes<T>, JobTypesDefinitions<TExternal>>,
_externalDefinitions?: TExternal,
) => {
const _schemas = schemas as Record<string, ValibotJobTypeSchema>;
const getSchema = (typeName: string): ValibotJobTypeSchema => {
const schema = _schemas[typeName];
if (!schema) {
throw new Error(`Unknown job type: ${typeName}`);
}
return schema;
};
const parseInput = (typeName: string, input: unknown): unknown =>
v.parse(getSchema(typeName).input, input);
const parseOutput = (typeName: string, output: unknown): unknown => {
const schema = getSchema(typeName).output;
if (!schema) throw new Error(`Job type "${typeName}" does not have an output schema`);
return v.parse(schema, output);
};
return createJobTypes<InferValibotJobTypes<T>, JobTypesDefinitions<TExternal>>({
getTypeNames: () => Object.keys(_schemas),
validateEntry: (typeName) => {
const schema = getSchema(typeName);
if (schema.entry !== true) {
throw new Error(`Job type "${typeName}" is not an entry point`);
}
},
encodeInput: parseInput,
decodeInput: parseInput,
encodeOutput: parseOutput,
decodeOutput: parseOutput,
validateContinueWith: (typeName, continuation) => {
const schema = getSchema(typeName);
if (schema.continueWith) {
v.parse(schema.continueWith, continuation);
} else {
throw new Error(`Job type "${typeName}" does not support continuations`);
}
},
validateBlockers: (typeName, blockers) => {
const schema = getSchema(typeName);
if (schema.blockers) {
v.parse(schema.blockers, blockers);
} else if (blockers.length > 0) {
throw new Error(`Job type "${typeName}" does not support blockers`);
}
},
});
};src/typebox-adapter.ts
/**
* TypeBox Adapter for Queuert Runtime Validation
*
* This is a user-land adapter that shows how to integrate TypeBox with Queuert's
* runtime validation system. The same pattern applies to Zod, Valibot, ArkType,
* or any other validation library.
*
* Each schema is compiled once with `TypeCompiler.Compile`, so the check that runs
* on every job read and write is generated code rather than TypeBox's interpreter.
*
* The stored form equals the runtime form, so one check serves as both encoder and
* decoder and returns the value unchanged; transforms (`Type.Transform`) are not
* applied. Use a codec adapter such as `examples/validation/codec-zod` when the two forms differ.
*/
import type { Static, TSchema } from "@sinclair/typebox";
import { type TypeCheck, type ValueErrorIterator, TypeCompiler } from "@sinclair/typebox/compiler";
import {
type BaseJobTypeDefinitions,
type JobTypesDefinitions,
type JobTypeDefinitionErrors,
type JobTypeReference,
type JobTypes,
type ValidatedJobTypeDefinitions,
createJobTypes,
} from "queuert";
/**
* Schema definition for a single job type using TypeBox.
*/
type TypeBoxSchemaFor<T> = TSchema & { static: T };
export type TypeBoxJobTypeSchema = {
/** Whether this job type can start a chain (entry point). Default: false */
entry?: boolean;
/** TypeBox schema for validating job input */
input: TSchema;
/** TypeBox schema for validating job output. Omit if job must continue. */
output?: TSchema;
/**
* TypeBox schema for validating continuation targets.
* Receives { typeName, input } object at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Nominal: validate by type name only
* continueWith: Type.Object({ typeName: Type.Literal("step2") })
*
* // Structural: validate by input shape only
* continueWith: Type.Object({ input: Type.Object({ payload: Type.Unknown() }) })
*
* // Both: validate type name and input shape
* continueWith: Type.Object({ typeName: Type.Literal("step2"), input: Type.Object({ data: Type.String() }) })
*/
continueWith?: TypeBoxSchemaFor<JobTypeReference>;
/**
* TypeBox schema for validating blocker references.
* Receives array of { typeName, input } objects at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Fixed blockers by name (tuple)
* blockers: Type.Tuple([
* Type.Object({ typeName: Type.Literal("auth") }),
* Type.Object({ typeName: Type.Literal("config") }),
* ])
*
* // Variable blockers by name (array)
* blockers: Type.Array(Type.Object({ typeName: Type.Literal("processor") }))
*
* // Structural validation: any blocker with matching input shape
* blockers: Type.Array(Type.Object({ input: Type.Object({ token: Type.String() }) }))
*/
blockers?: TypeBoxSchemaFor<readonly JobTypeReference[]>;
};
/**
* Infer BaseJobTypeDefinitions from TypeBox schemas.
* This enables compile-time type safety for the job types.
*/
type InferTypeBoxJobTypes<T extends Record<string, TypeBoxJobTypeSchema>> = {
[K in keyof T & string]: {
entry: T[K]["entry"] extends true ? true : undefined;
input: Static<T[K]["input"]>;
output: T[K]["output"] extends TSchema ? Static<T[K]["output"]> : undefined;
continueWith: T[K]["continueWith"] extends TSchema
? Static<T[K]["continueWith"]> extends infer U extends JobTypeReference
? U
: JobTypeReference
: undefined;
blockers: T[K]["blockers"] extends TSchema
? Static<T[K]["blockers"]> extends infer U extends readonly JobTypeReference[]
? U
: readonly JobTypeReference[]
: undefined;
};
};
/**
* Validation error thrown when TypeBox validation fails.
*/
class TypeBoxValidationError extends Error {
readonly errors: ValueErrorIterator;
constructor(message: string, errors: ValueErrorIterator) {
super(message);
this.errors = errors;
this.name = "TypeBoxValidationError";
}
}
/** A job type's schemas, each compiled once. */
type CompiledJobTypeSchema = {
entry?: boolean;
input: TypeCheck<TSchema>;
output?: TypeCheck<TSchema>;
continueWith?: TypeCheck<TSchema>;
blockers?: TypeCheck<TSchema>;
};
/**
* Validate data with a compiled schema and return it unchanged.
* Throws TypeBoxValidationError listing every error if validation fails.
*/
const parse = (check: TypeCheck<TSchema>, data: unknown): unknown => {
if (check.Check(data)) return data;
const messages = [...check.Errors(data)].map((e) => `${e.path}: ${e.message}`).join(", ");
throw new TypeBoxValidationError(`Validation failed: ${messages}`, check.Errors(data));
};
/**
* Create a TypeBox-based job type registry.
*
* This adapter:
* 1. Accepts TypeBox schemas for each job type
* 2. Infers TypeScript types from the schemas
* 3. Validates at runtime with schemas compiled by TypeBox's TypeCompiler
*
* Errors thrown by TypeBox are caught by the core registry and wrapped
* in JobTypeValidationError with the appropriate error code.
*
* @example
* const jobTypes = createTypeBoxJobTypes({
* "process-data": {
* entry: true,
* input: Type.Object({ dataId: Type.String() }),
* output: Type.Object({ result: Type.Number() }),
* },
* "send-notification": {
* entry: true,
* input: Type.Object({ userId: Type.String(), message: Type.String() }),
* output: Type.Object({ sent: Type.Boolean() }),
* },
* });
*/
export const createTypeBoxJobTypes = <
const T extends Record<string, TypeBoxJobTypeSchema>,
const TExternal extends
| JobTypes<BaseJobTypeDefinitions>
| readonly JobTypes<BaseJobTypeDefinitions>[] = readonly [],
>(
schemas: [InferTypeBoxJobTypes<T>] extends [
ValidatedJobTypeDefinitions<InferTypeBoxJobTypes<T>, JobTypesDefinitions<TExternal>>,
]
? T
: JobTypeDefinitionErrors<InferTypeBoxJobTypes<T>, JobTypesDefinitions<TExternal>>,
_externalDefinitions?: TExternal,
) => {
const _schemas = Object.fromEntries(
Object.entries(schemas as Record<string, TypeBoxJobTypeSchema>).map(
([typeName, schema]): [string, CompiledJobTypeSchema] => [
typeName,
{
entry: schema.entry,
input: TypeCompiler.Compile(schema.input),
output: schema.output && TypeCompiler.Compile(schema.output),
continueWith: schema.continueWith && TypeCompiler.Compile(schema.continueWith),
blockers: schema.blockers && TypeCompiler.Compile(schema.blockers),
},
],
),
);
const getSchema = (typeName: string): CompiledJobTypeSchema => {
const schema = _schemas[typeName];
if (!schema) {
throw new Error(`Unknown job type: ${typeName}`);
}
return schema;
};
const parseInput = (typeName: string, input: unknown): unknown =>
parse(getSchema(typeName).input, input);
const parseOutput = (typeName: string, output: unknown): unknown => {
const schema = getSchema(typeName).output;
if (!schema) throw new Error(`Job type "${typeName}" does not have an output schema`);
return parse(schema, output);
};
return createJobTypes<InferTypeBoxJobTypes<T>, JobTypesDefinitions<TExternal>>({
getTypeNames: () => Object.keys(_schemas),
validateEntry: (typeName) => {
const schema = getSchema(typeName);
if (schema.entry !== true) {
throw new Error(`Job type "${typeName}" is not an entry point`);
}
},
encodeInput: parseInput,
decodeInput: parseInput,
encodeOutput: parseOutput,
decodeOutput: parseOutput,
validateContinueWith: (typeName, continuation) => {
const schema = getSchema(typeName);
if (schema.continueWith) {
parse(schema.continueWith, continuation);
} else {
throw new Error(`Job type "${typeName}" does not support continuations`);
}
},
validateBlockers: (typeName, blockers) => {
const schema = getSchema(typeName);
if (schema.blockers) {
parse(schema.blockers, blockers);
} else if (blockers.length > 0) {
throw new Error(`Job type "${typeName}" does not support blockers`);
}
},
});
};src/arktype-adapter.ts
/**
* ArkType Adapter for Queuert Runtime Validation
*
* This is a user-land adapter that shows how to integrate ArkType with Queuert's
* runtime validation system. The same pattern applies to Zod, Valibot,
* or any other validation library.
*
* The stored form equals the runtime form, so one validation pass serves as both
* encoder and decoder and returns the value it checked. A schema that transforms
* would be applied again on every read; use a codec adapter such as
* `examples/validation/codec-zod` for one.
*/
import type { Type } from "arktype";
import {
type BaseJobTypeDefinitions,
type JobTypeDefinitionErrors,
type JobTypeReference,
type JobTypes,
type JobTypesDefinitions,
type ValidatedJobTypeDefinitions,
createJobTypes,
} from "queuert";
/**
* Schema definition for a single job type using ArkType.
*/
export type ArkTypeJobTypeSchema = {
/** Whether this job type can start a chain (entry point). Default: false */
entry?: boolean;
/** ArkType schema for validating job input */
input: Type;
/** ArkType schema for validating job output. Omit if job must continue. */
output?: Type;
/**
* ArkType schema for validating continuation targets.
* Receives { typeName, input } object at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Nominal: validate by type name only
* continueWith: type({ typeName: "'step2'" })
*
* // Structural: validate by input shape only
* continueWith: type({ input: { payload: "unknown" } })
*
* // Both: validate type name and input shape
* continueWith: type({ typeName: "'step2'", input: { data: "string" } })
*/
continueWith?: Type<JobTypeReference>;
/**
* ArkType schema for validating blocker references.
* Receives array of { typeName, input } objects at runtime.
* Schema can validate typeName (nominal), input (structural), or both.
*
* @example
* // Fixed blockers by name (tuple)
* blockers: type([{ typeName: "'auth'" }, { typeName: "'config'" }])
*
* // Variable blockers by name (array)
* blockers: type({ typeName: "'processor'" }).array())
*
* // Structural validation: any blocker with matching input shape
* blockers: type({ input: { token: "string" } }).array())
*/
blockers?: Type<readonly JobTypeReference[]>;
};
/**
* Infer BaseJobTypeDefinitions from ArkType schemas.
* This enables compile-time type safety for the job types.
*/
type InferArkTypeJobTypes<T extends Record<string, ArkTypeJobTypeSchema>> = {
[K in keyof T & string]: {
entry: T[K]["entry"] extends true ? true : undefined;
input: T[K]["input"]["infer"];
output: T[K]["output"] extends Type ? T[K]["output"]["infer"] : undefined;
continueWith: T[K]["continueWith"] extends Type<infer U>
? U extends JobTypeReference
? U
: JobTypeReference
: undefined;
blockers: T[K]["blockers"] extends Type<infer U>
? U extends readonly JobTypeReference[]
? U
: readonly JobTypeReference[]
: undefined;
};
};
/**
* Create an ArkType-based job type registry.
*
* This adapter:
* 1. Accepts ArkType schemas for each job type
* 2. Infers TypeScript types from the schemas
* 3. Validates at runtime using ArkType's .assert() method
*
* Errors thrown by ArkType are caught by the core registry and wrapped
* in JobTypeValidationError with the appropriate error code.
*
* @example
* const jobTypes = createArkTypeJobTypes({
* "process-data": {
* entry: true,
* input: type({ dataId: "string" }),
* output: type({ result: "number" }),
* },
* "send-notification": {
* entry: true,
* input: type({ userId: "string", message: "string" }),
* output: type({ sent: "boolean" }),
* },
* });
*/
export const createArkTypeJobTypes = <
const T extends Record<string, ArkTypeJobTypeSchema>,
const TExternal extends
| JobTypes<BaseJobTypeDefinitions>
| readonly JobTypes<BaseJobTypeDefinitions>[] = readonly [],
>(
schemas: [InferArkTypeJobTypes<T>] extends [
ValidatedJobTypeDefinitions<InferArkTypeJobTypes<T>, JobTypesDefinitions<TExternal>>,
]
? T
: JobTypeDefinitionErrors<InferArkTypeJobTypes<T>, JobTypesDefinitions<TExternal>>,
_externalDefinitions?: TExternal,
) => {
const _schemas = schemas as Record<string, ArkTypeJobTypeSchema>;
const getSchema = (typeName: string): ArkTypeJobTypeSchema => {
const schema = _schemas[typeName];
if (!schema) {
throw new Error(`Unknown job type: ${typeName}`);
}
return schema;
};
const parseInput = (typeName: string, input: unknown): unknown =>
getSchema(typeName).input.assert(input);
const parseOutput = (typeName: string, output: unknown): unknown => {
const schema = getSchema(typeName).output;
if (!schema) throw new Error(`Job type "${typeName}" does not have an output schema`);
return schema.assert(output);
};
return createJobTypes<InferArkTypeJobTypes<T>, JobTypesDefinitions<TExternal>>({
getTypeNames: () => Object.keys(_schemas),
validateEntry: (typeName) => {
const schema = getSchema(typeName);
if (schema.entry !== true) {
throw new Error(`Job type "${typeName}" is not an entry point`);
}
},
encodeInput: parseInput,
decodeInput: parseInput,
encodeOutput: parseOutput,
decodeOutput: parseOutput,
validateContinueWith: (typeName, continuation) => {
const schema = getSchema(typeName);
if (schema.continueWith) {
schema.continueWith.assert(continuation);
} else {
throw new Error(`Job type "${typeName}" does not support continuations`);
}
},
validateBlockers: (typeName, blockers) => {
const schema = getSchema(typeName);
if (schema.blockers) {
schema.blockers.assert(blockers);
} else if (blockers.length > 0) {
throw new Error(`Job type "${typeName}" does not support blockers`);
}
},
});
};The JobTypes interface
The JobTypes object validates at each boundary:
JobTypes
- getTypeNames (all)Returns known type names, used to route merged slices and to pick which values are decoded.
- validateEntry entry?: booleanValidates job type can start a chain.
- encodeInput / decodeInput input: unknownConverts input between runtime and stored form.
- encodeOutput / decodeOutput output?: unknownConverts output between runtime and stored form.
- validateContinueWith continueWith?: ReferenceValidates continuation target.
- validateBlockers blockers?: Reference[]Validates blocker references.
A rejected value throws JobTypeValidationError; its codes and how it surfaces are in Runtime Validation.
Codec calls
Each codec method takes the typeName and the value. An adapter whose schemas only validate passes one function as both the encoder and the decoder of a field, so a schema that transforms would be applied again on every read; transforming schemas belong in a codec adapter such as the validation/codec-zod example. The encoders are the gate: they run on every write, and a value they reject never reaches the database. The decoders run on every read and only for type names the registry lists in getTypeNames. When a decoder throws, the read that needed the value fails with JobTypeValidationError.
Caution
input and output do not match the declared types; a decoder that rejects an older stored shape makes every read of that row — including a dashboard page listing it — fail. Delete the chains of a job type before removing it, and change a schema in a way that still decodes rows written under the previous one.Conformance
Each example checks its adapter with validationAdapterConformanceCases; see Custom validation adapter.
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);
});
}
});src/valibot-adapter.spec.ts
import {
type ValidationAdapterConformanceContext,
validationAdapterConformanceCases,
} from "queuert/conformance";
import * as v from "valibot";
import { describe, test } from "vitest";
import { createValibotJobTypes } from "./valibot-adapter.ts";
describe("valibot adapter conformance", () => {
const context: ValidationAdapterConformanceContext = {
basic: {
buildEntry: () =>
createValibotJobTypes({
main: {
entry: true,
input: v.object({ id: v.string() }),
output: v.object({ ok: v.boolean() }),
},
}),
buildNonEntry: () =>
createValibotJobTypes({
internal: {
input: v.object({ id: v.string() }),
output: v.object({ ok: v.boolean() }),
},
}),
buildContinuationOnly: () =>
createValibotJobTypes({
main: {
entry: true,
input: v.object({ id: v.string() }),
continueWith: v.object({ typeName: v.literal("next") }),
},
next: {
input: v.object({ data: v.string() }),
output: v.object({ done: v.boolean() }),
},
}),
},
continuations: {
buildNominal: () =>
createValibotJobTypes({
step1: {
entry: true,
input: v.object({ id: v.string() }),
continueWith: v.object({ typeName: v.literal("step2") }),
},
step2: {
input: v.object({ data: v.unknown() }),
output: v.object({ done: v.boolean() }),
},
}),
buildStructural: () =>
createValibotJobTypes({
router: {
entry: true,
input: v.object({ route: v.string() }),
continueWith: v.object({ input: v.object({ payload: v.string() }) }),
},
handler: {
input: v.object({ payload: v.string() }),
output: v.object({ handled: v.boolean() }),
},
}),
},
blockers: {
buildNominal: () =>
createValibotJobTypes({
main: {
entry: true,
input: v.object({ id: v.string() }),
output: v.object({ done: v.boolean() }),
blockers: v.array(v.object({ typeName: v.literal("auth") })),
},
auth: {
entry: true,
input: v.object({ token: v.string() }),
output: v.object({ userId: v.string() }),
},
}),
buildStructural: () =>
createValibotJobTypes({
main: {
entry: true,
input: v.object({ id: v.string() }),
output: v.object({ done: v.boolean() }),
blockers: v.array(v.object({ input: v.object({ token: v.string() }) })),
},
auth: {
entry: true,
input: v.object({ token: v.string() }),
output: v.object({ userId: v.string() }),
},
}),
},
external: {
buildWithExternalSlice: () => {
const notifications = createValibotJobTypes({
"notifications.send-notification": {
entry: true,
input: v.object({ userId: v.string(), message: v.string() }),
output: v.object({ sentAt: v.string() }),
},
});
return createValibotJobTypes(
{
"orders.place-order": {
entry: true,
input: v.object({ userId: v.string() }),
continueWith: v.object({ typeName: v.literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: v.object({ orderId: v.number() }),
output: v.object({ confirmedAt: v.string() }),
blockers: v.tuple([
v.object({ typeName: v.literal("notifications.send-notification") }),
]),
},
},
notifications,
);
},
buildWithExternalSlices: () => {
const notifications = createValibotJobTypes({
"notifications.send-notification": {
entry: true,
input: v.object({ userId: v.string(), message: v.string() }),
output: v.object({ sentAt: v.string() }),
},
});
const payments = createValibotJobTypes({
"payments.charge": {
entry: true,
input: v.object({ amount: v.number() }),
output: v.object({ receiptId: v.string() }),
},
});
return createValibotJobTypes(
{
"orders.place-order": {
entry: true,
input: v.object({ userId: v.string() }),
continueWith: v.object({ typeName: v.literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: v.object({ orderId: v.number() }),
output: v.object({ confirmedAt: v.string() }),
blockers: v.tuple([
v.object({ typeName: v.literal("notifications.send-notification") }),
v.object({ typeName: v.literal("payments.charge") }),
]),
},
},
[notifications, payments] as const,
);
},
},
};
for (const conformanceCase of validationAdapterConformanceCases) {
test(conformanceCase.title, async () => {
await conformanceCase.run(context);
});
}
});src/typebox-adapter.spec.ts
import { Type } from "@sinclair/typebox";
import {
type ValidationAdapterConformanceContext,
validationAdapterConformanceCases,
} from "queuert/conformance";
import { describe, test } from "vitest";
import { createTypeBoxJobTypes } from "./typebox-adapter.ts";
describe("typebox adapter conformance", () => {
const context: ValidationAdapterConformanceContext = {
basic: {
buildEntry: () =>
createTypeBoxJobTypes({
main: {
entry: true,
input: Type.Object({ id: Type.String() }),
output: Type.Object({ ok: Type.Boolean() }),
},
}),
buildNonEntry: () =>
createTypeBoxJobTypes({
internal: {
input: Type.Object({ id: Type.String() }),
output: Type.Object({ ok: Type.Boolean() }),
},
}),
buildContinuationOnly: () =>
createTypeBoxJobTypes({
main: {
entry: true,
input: Type.Object({ id: Type.String() }),
continueWith: Type.Object({ typeName: Type.Literal("next") }),
},
next: {
input: Type.Object({ data: Type.String() }),
output: Type.Object({ done: Type.Boolean() }),
},
}),
},
continuations: {
buildNominal: () =>
createTypeBoxJobTypes({
step1: {
entry: true,
input: Type.Object({ id: Type.String() }),
continueWith: Type.Object({ typeName: Type.Literal("step2") }),
},
step2: {
input: Type.Object({ data: Type.Unknown() }),
output: Type.Object({ done: Type.Boolean() }),
},
}),
buildStructural: () =>
createTypeBoxJobTypes({
router: {
entry: true,
input: Type.Object({ route: Type.String() }),
continueWith: Type.Object({ input: Type.Object({ payload: Type.String() }) }),
},
handler: {
input: Type.Object({ payload: Type.String() }),
output: Type.Object({ handled: Type.Boolean() }),
},
}),
},
blockers: {
buildNominal: () =>
createTypeBoxJobTypes({
main: {
entry: true,
input: Type.Object({ id: Type.String() }),
output: Type.Object({ done: Type.Boolean() }),
blockers: Type.Array(Type.Object({ typeName: Type.Literal("auth") })),
},
auth: {
entry: true,
input: Type.Object({ token: Type.String() }),
output: Type.Object({ userId: Type.String() }),
},
}),
buildStructural: () =>
createTypeBoxJobTypes({
main: {
entry: true,
input: Type.Object({ id: Type.String() }),
output: Type.Object({ done: Type.Boolean() }),
blockers: Type.Array(Type.Object({ input: Type.Object({ token: Type.String() }) })),
},
auth: {
entry: true,
input: Type.Object({ token: Type.String() }),
output: Type.Object({ userId: Type.String() }),
},
}),
},
external: {
buildWithExternalSlice: () => {
const notifications = createTypeBoxJobTypes({
"notifications.send-notification": {
entry: true,
input: Type.Object({ userId: Type.String(), message: Type.String() }),
output: Type.Object({ sentAt: Type.String() }),
},
});
return createTypeBoxJobTypes(
{
"orders.place-order": {
entry: true,
input: Type.Object({ userId: Type.String() }),
continueWith: Type.Object({ typeName: Type.Literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: Type.Object({ orderId: Type.Number() }),
output: Type.Object({ confirmedAt: Type.String() }),
blockers: Type.Tuple([
Type.Object({ typeName: Type.Literal("notifications.send-notification") }),
]),
},
},
notifications,
);
},
buildWithExternalSlices: () => {
const notifications = createTypeBoxJobTypes({
"notifications.send-notification": {
entry: true,
input: Type.Object({ userId: Type.String(), message: Type.String() }),
output: Type.Object({ sentAt: Type.String() }),
},
});
const payments = createTypeBoxJobTypes({
"payments.charge": {
entry: true,
input: Type.Object({ amount: Type.Number() }),
output: Type.Object({ receiptId: Type.String() }),
},
});
return createTypeBoxJobTypes(
{
"orders.place-order": {
entry: true,
input: Type.Object({ userId: Type.String() }),
continueWith: Type.Object({ typeName: Type.Literal("orders.confirm-order") }),
},
"orders.confirm-order": {
input: Type.Object({ orderId: Type.Number() }),
output: Type.Object({ confirmedAt: Type.String() }),
blockers: Type.Tuple([
Type.Object({ typeName: Type.Literal("notifications.send-notification") }),
Type.Object({ typeName: Type.Literal("payments.charge") }),
]),
},
},
[notifications, payments] as const,
);
},
},
};
for (const conformanceCase of validationAdapterConformanceCases) {
test(conformanceCase.title, async () => {
await conformanceCase.run(context);
});
}
});src/arktype-adapter.spec.ts
import { type } from "arktype";
import {
type ValidationAdapterConformanceContext,
validationAdapterConformanceCases,
} from "queuert/conformance";
import { describe, test } from "vitest";
import { createArkTypeJobTypes } from "./arktype-adapter.ts";
describe("arktype adapter conformance", () => {
const context: ValidationAdapterConformanceContext = {
basic: {
buildEntry: () =>
createArkTypeJobTypes({
main: {
entry: true,
input: type({ id: "string" }),
output: type({ ok: "boolean" }),
},
}),
buildNonEntry: () =>
createArkTypeJobTypes({
internal: {
input: type({ id: "string" }),
output: type({ ok: "boolean" }),
},
}),
buildContinuationOnly: () =>
createArkTypeJobTypes({
main: {
entry: true,
input: type({ id: "string" }),
continueWith: type({ typeName: "'next'" }),
},
next: {
input: type({ data: "string" }),
output: type({ done: "boolean" }),
},
}),
},
continuations: {
buildNominal: () =>
createArkTypeJobTypes({
step1: {
entry: true,
input: type({ id: "string" }),
continueWith: type({ typeName: "'step2'" }),
},
step2: {
input: type({ data: "unknown" }),
output: type({ done: "boolean" }),
},
}),
buildStructural: () =>
createArkTypeJobTypes({
router: {
entry: true,
input: type({ route: "string" }),
continueWith: type({ input: { payload: "string" } }),
},
handler: {
input: type({ payload: "string" }),
output: type({ handled: "boolean" }),
},
}),
},
blockers: {
buildNominal: () =>
createArkTypeJobTypes({
main: {
entry: true,
input: type({ id: "string" }),
output: type({ done: "boolean" }),
blockers: type({ typeName: "'auth'" }).array(),
},
auth: {
entry: true,
input: type({ token: "string" }),
output: type({ userId: "string" }),
},
}),
buildStructural: () =>
createArkTypeJobTypes({
main: {
entry: true,
input: type({ id: "string" }),
output: type({ done: "boolean" }),
blockers: type({ input: { token: "string" } }).array(),
},
auth: {
entry: true,
input: type({ token: "string" }),
output: type({ userId: "string" }),
},
}),
},
external: {
buildWithExternalSlice: () => {
const notifications = createArkTypeJobTypes({
"notifications.send-notification": {
entry: true,
input: type({ userId: "string", message: "string" }),
output: type({ sentAt: "string" }),
},
});
return createArkTypeJobTypes(
{
"orders.place-order": {
entry: true,
input: type({ userId: "string" }),
continueWith: type({ typeName: "'orders.confirm-order'" }),
},
"orders.confirm-order": {
input: type({ orderId: "number" }),
output: type({ confirmedAt: "string" }),
blockers: type([{ typeName: "'notifications.send-notification'" }]),
},
},
notifications,
);
},
buildWithExternalSlices: () => {
const notifications = createArkTypeJobTypes({
"notifications.send-notification": {
entry: true,
input: type({ userId: "string", message: "string" }),
output: type({ sentAt: "string" }),
},
});
const payments = createArkTypeJobTypes({
"payments.charge": {
entry: true,
input: type({ amount: "number" }),
output: type({ receiptId: "string" }),
},
});
return createArkTypeJobTypes(
{
"orders.place-order": {
entry: true,
input: type({ userId: "string" }),
continueWith: type({ typeName: "'orders.confirm-order'" }),
},
"orders.confirm-order": {
input: type({ orderId: "number" }),
output: type({ confirmedAt: "string" }),
blockers: type([
{ typeName: "'notifications.send-notification'" },
{ typeName: "'payments.charge'" },
]),
},
},
[notifications, payments] as const,
);
},
},
};
for (const conformanceCase of validationAdapterConformanceCases) {
test(conformanceCase.title, async () => {
await conformanceCase.run(context);
});
}
});Examples
Validation adapters
- validation/zod ZodGitHubCustom validation adapter backed by Zod — covers nominal (by type name) and structural (by input shape) reference validation.
$ pnpm --filter example-validation-zod startsrc/zod-adapter.tssrc/index.ts - validation/valibot ValibotGitHubCustom validation adapter backed by Valibot — covers nominal (by type name) and structural (by input shape) reference validation.
$ pnpm --filter example-validation-valibot startsrc/valibot-adapter.tssrc/index.ts - validation/typebox TypeBoxGitHubCustom validation adapter backed by TypeBox — covers nominal (by type name) and structural (by input shape) reference validation.
$ pnpm --filter example-validation-typebox startsrc/typebox-adapter.tssrc/index.ts - validation/arktype ArkTypeGitHubCustom validation adapter backed by ArkType — covers nominal (by type name) and structural (by input shape) reference validation.
$ pnpm --filter example-validation-arktype startsrc/arktype-adapter.tssrc/index.ts
Codecs
- validation/codec-zod Zod codecsGitHubZod 4 codec adapter — carries a Date through a chain while storing it as an ISO string, so handlers and client reads see runtime types and the database stays JSON-safe.
$ pnpm --filter example-validation-codec-zod startsrc/zod-codec-adapter.tssrc/index.ts - validation/codec-superjson superjsonGitHubsuperjson codec adapter — one codec for every job type carries Date, Map, Set and bigint through a chain, with job types declared as plain TypeScript types.
$ pnpm --filter example-validation-codec-superjson startsrc/superjson-adapter.tssrc/index.ts