Skip to content

Runtime Validation

For production APIs accepting external input, you can add runtime validation using any schema library (Zod, Valibot, TypeBox, etc.). The core is minimal — schema-specific adapters are implemented in user-land.

Both defineJobTypes (compile-time only) and createJobTypeRegistry (runtime validation) provide the same compile-time type safety. Runtime validation adds protection against invalid external data.

See complete adapter examples: Zod, Valibot, TypeBox, ArkType.

Queuert’s runtime validation follows an adapter pattern. The core provides createJobTypeRegistry, which accepts raw validation functions. Schema-specific adapters (Zod, Valibot, TypeBox, ArkType) are implemented in user-land, wrapping their respective schema libraries into the registry interface.

Each adapter:

  1. Accepts schema definitions in the library’s native format
  2. Infers TJobTypeDefinitions from the schemas (providing the same compile-time safety as defineJobTypes)
  3. Calls createJobTypeRegistry with validation functions that delegate to the schema library

defineJobTypes is a lightweight type-only helper. It provides compile-time type inference with zero runtime cost — no validation functions are executed. Use it when your inputs come from trusted internal code.

createJobTypeRegistry adds runtime validation on top of compile-time types. It accepts validation functions for entry checks, input/output parsing, continuation validation, and blocker validation. Use it when your job inputs originate from external sources (APIs, webhooks, user input) where compile-time guarantees alone are insufficient.

The registry validates at each boundary:

Job Type DefinitionRegistry MethodPurpose
(all)getTypeNamesReturns known type names (for merge/routing)
entry?: booleanvalidateEntryValidates job type can start a chain
input: unknownparseInputParses and validates job input
output?: unknownparseOutputParses and validates job output
continueWith?: ReferencevalidateContinueWithValidates continuation target
blockers?: Reference[]validateBlockersValidates blocker references

All validation errors throw JobTypeValidationError with:

  • code: Error type ('invalid_input', 'invalid_output', 'invalid_continuation', 'invalid_blockers', 'not_entry_point')
  • typeName: The job type that failed validation
  • message: Human-readable error message
  • details: Additional context (original error, input value, etc.)