@zudojs/adapters
Boundary layer between Zudojs and external platforms. Provides adapter contracts, a registry, capabilities, and transport abstractions so your application code never touches platform-specific APIs.
INSTALLATION
WHAT IT DOES
@zudojs/adapters is the boundary between your Zudojs application and the outside world. It defines:
- → A base Adapter interface that all adapters implement
- → An AdapterRegistry for registering, discovering, and managing adapters
- → A Capabilities system so runtime code can adapt behavior based on platform support
- → Transport-specific interfaces for HTTP, messaging, storage, queue, runtime, WebSocket, CLI, and scheduler
- → Lifecycle contracts with health checks and operation options
WHERE IT SITS
Adapters sit below the transport layer. Transport packages use adapters to interact with platforms. Application code never directly calls platform APIs.
DEPENDENCIES
| Package | Version | Purpose |
|---|---|---|
| @zudojs/errors | 1.2.0 | Adapter error hierarchy (AdapterError, AdapterNotFoundError, AdapterConfigurationError, etc.) |
workspace:*, always — including on main. They are never hand-pinned to an exact version. At publish time pnpm rewrites each workspace:* to the exact version of that package in the same release, so a published tarball carries real ranges. Releases go out through publish-all.sh, which runs pnpm -r publish — it rewrites the ranges and publishes in dependency order. Plain npm publish does not understand the workspace: protocol and would ship a literal workspace:* to the registry.
CORE API — ADAPTER INTERFACE
Interface: Adapter
Every adapter in the Zudojs ecosystem implements this contract:
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Unique identifier. Normalized to lowercase for lookup. |
| version | string | No | Semantic version of the adapter. |
| capabilities | AdapterCapabilities | Yes | What the adapter supports. Runtime queries this to adapt behavior. |
| metadata | AdapterMetadata | No | Identification, versioning, and compatibility info. |
Lifecycle Methods
| Method | When Called | Purpose |
|---|---|---|
| initialize() | During app bootstrap | Prepare external resources. Connect to databases, validate config. |
| start() | After initialization | Begin active processing. Listen for requests, consume messages. |
| stop() | During graceful shutdown | Cease active processing. Stop accepting new work. |
| dispose() | After stopping | Release all resources. Close connections, clear timers. |
Example: Custom Adapter
ADAPTER REGISTRY
The AdapterRegistry manages adapter registration, lookup, and removal. Names are normalized to lowercase for case-insensitive lookup.
Methods
| Method | Signature | Returns |
|---|---|---|
| register() | register(adapter: Adapter): void | void. Throws AdapterAlreadyRegisteredError on duplicate, AdapterConfigurationError on a blank or reserved name. |
| get() | get<T>(name: string): T | undefined | Adapter or undefined |
| has() | has(name: string): boolean | true if registered |
| remove() | remove(name: string): boolean | true if removed, false if not found |
| getAll() | getAll(): readonly Adapter[] | Frozen array of all adapters |
| getNames() | getNames(): readonly string[] | Frozen array of adapter names |
| size | get size(): number | Number of registered adapters |
| clear() | clear(): void | Removes all adapters |
register() refuses the names __proto__, constructor and prototype with an AdapterConfigurationError. The check runs after normalization, so "__PROTO__" is refused too. They survive the registry's own Map, but any consumer that keys a plain object by adapter name — a health report, a metrics bag, a JSON dump — loses or corrupts the entry, so they are refused at the door. Rename the adapter; nothing else about registration changed.
Example: Using the Registry
CAPABILITIES
Adapters declare what they support through AdapterCapabilities. Runtime code queries capabilities to decide behavior.
| Capability | Type | Description |
|---|---|---|
| http | boolean | Supports HTTP request/response handling |
| websocket | boolean | Supports WebSocket connections |
| streaming | boolean | Supports streaming responses |
| filesystem | boolean | Supports file system access |
| tcp | boolean | Supports raw TCP connections |
| udp | boolean | Supports UDP datagrams |
| backgroundTasks | boolean | Supports background task execution |
| longRunning | boolean | Supports long-running processes |
| edgeRuntime | boolean | Runs on edge (Cloudflare, Vercel Edge) |
| serverless | boolean | Runs in serverless (Lambda, etc.) |
| gracefulShutdown | boolean | Supports graceful shutdown |
| abortSignal | boolean | Supports request cancellation via AbortSignal |
Example: Querying Capabilities
METADATA
Adapter metadata provides identification, versioning, and compatibility information for diagnostics and tooling.
LIFECYCLE CONTRACTS
AdapterHealth
Health Factory Functions
LifecycleAdapter
AdapterRegistry.healthAll({ timeout, signal, retry }) runs every health() hook and returns an AdapterHealthReport, { status, adapters } (the worst status; failing, timed-out or aborted checks are unhealthy). AdapterRegistry.configure(name, options) calls the adapter's configure() and throws AdapterConfigurationError if it has none.
AdapterOperationOptions
| Option | Default | Meaning |
|---|---|---|
| signal | none | Cancels the operation. An aborted signal also stops any remaining retries at once. |
| timeout | none | Milliseconds allowed for each try, not for the whole retry sequence. |
| retry.attempts | 1 |
The total number of tries, including the first one. 3 means one call plus at most two retries. Anything below 1, fractional, or non-finite is clamped to a single try. |
| retry.delay | 0 |
Milliseconds to pause between tries. Ended early by signal. |
Until v1.2.0 retry was part of the contract with nothing reading it: a caller asking for three attempts got one, silently. It is now honoured by healthAll(). A check is re-run only while it reports unhealthy — a healthy or degraded result is accepted and returned immediately. Omit retry and the behaviour is exactly what it was: one try.
attempts: 1 is a single try and no retry at all, not "one retry". If you previously wrote attempts: 3 expecting four calls, you now get three — and before v1.2.0 you got one.
TRANSPORT ADAPTERS
HTTP ADAPTER
Translates platform-specific HTTP requests/responses into Zudojs's normalized shapes.
@zudojs/http (v1.2.0), @zudojs/security (v1.1.0)
MESSAGING ADAPTER
Connects Zudojs message bus to external providers (RabbitMQ, Kafka, Redis Streams, NATS, AWS SQS, Google Pub/Sub).
@zudojs/messaging (v1.0.2), @zudojs/events (v1.1.0)
STORAGE ADAPTER
Bridges Zudojs storage to external providers (AWS S3, Cloudflare R2, Google Cloud Storage, Azure Blob).
@zudojs/storage (v1.1.1), @zudojs/cache (v1.1.0)
QUEUE ADAPTER
Connects Zudojs queue abstractions to external providers (BullMQ, RabbitMQ, AWS SQS, Redis, Kafka).
@zudojs/queue (v1.2.0)
WEBSOCKET ADAPTER
RUNTIME ADAPTER
Provides platform-specific runtime services (Node.js, Bun, Deno, AWS Lambda, Cloudflare Workers).
CLI ADAPTER
SCHEDULER ADAPTER
ERROR HIERARCHY
All error types are defined in @zudojs/errors and re-exported by this package.
| Error | When Thrown |
|---|---|
| AdapterError | Base error for all adapter issues |
| AdapterNotFoundError | Requested adapter not in registry |
| AdapterAlreadyRegisteredError | Duplicate adapter registration |
| AdapterNotSupportedError | Capability not supported by adapter |
| AdapterCapabilityMissingError | Required capability missing |
| AdapterConnectionError | Connection failure |
| AdapterOperationError | Operation failure |
| AdapterTimeoutError | Operation timed out |
| AdapterDisposeError | Disposal failure |
| AdapterInitializationError | Initialization failure |
| AdapterConfigurationError | Invalid configuration |
Error Handling Pattern
TESTING UTILITIES
Import from @zudojs/adapters/testing for mock adapters and test helpers.
createMockAdapter()
createMockAdapterRegistry()
Full Test Example
FULL INTEGRATION EXAMPLE
Complete example: register adapters, query capabilities, use with the runtime.
CONNECTIONS TO OTHER PACKAGES
| Package | Version | Relationship | How They Connect |
|---|---|---|---|
| @zudojs/http | 1.3.0 | Transport | HTTP adapter provides request/response shapes that @zudojs/http consumes |
| @zudojs/messaging | 1.1.0 | Transport | Message adapter bridges external message providers to the internal message bus |
| @zudojs/storage | 1.1.2 | Transport | Storage adapter provides the implementation for storage abstractions |
| @zudojs/queue | 1.3.0 | Transport | Queue adapter provides the implementation for background job processing |
| @zudojs/scheduler | 1.1.2 | Transport | Scheduler adapter provides the implementation for job scheduling |
| @zudojs/lifecycle | 1.2.0 | Dependency | Lifecycle contracts integrate with the lifecycle state machine |
| @zudojs/runtime | 1.2.1 | Consumer | Runtime manages adapter lifecycle (initialize, start, stop, dispose) |
| @zudojs/errors | 1.2.0 | Dependency | All adapter error types defined in @zudojs/errors |
| @zudojs/database | 1.2.1 | Consumer | Database clients use storage adapter interface for connection management |
VERSION COMPATIBILITY
workspace:*, always — including on main. They are never hand-pinned to an exact version. At publish time pnpm rewrites each workspace:* to the exact version of that package in the same release, so a published tarball carries real ranges. Releases go out through publish-all.sh, which runs pnpm -r publish — it rewrites the ranges and publishes in dependency order. Plain npm publish does not understand the workspace: protocol and would ship a literal workspace:* to the registry.
| Package | adapters v1.2.0 works with | Stability |
|---|---|---|
| @zudojs/errors | v1.2.0 | STABLE |
| @zudojs/constants | v1.1.1 | STABLE |
| @zudojs/types | v1.1.1 | STABLE |
| @zudojs/lifecycle | v1.2.0 | STABLE |
| @zudojs/http | v1.3.0 (peer) | PEER |
| @zudojs/messaging | v1.1.0 | STABLE |
| @zudojs/storage | v1.1.2 | STABLE |
| @zudojs/queue | v1.3.0 | STABLE |
| @zudojs/scheduler | v1.1.2 | STABLE |
| @zudojs/runtime | v1.2.1 | STABLE |
IMPROVEMENTS & RECOMMENDATIONS
1. Add AdapterFactory Pattern
Create factory functions that encapsulate adapter creation with validation:
2. Add AdapterMiddleware Support
Allow wrapping adapter operations with middleware for logging, metrics, and retry logic.
3. Add AdapterHealthChecker
A utility that periodically checks adapter health and emits events when status changes.
4. Add Adapter Connection Pool
For adapters that maintain connections (HTTP, storage), add connection pooling with configurable limits.
5. Add Adapter Metrics Collection
Automatic metrics for adapter operations: request duration, error rates, connection counts.
QUICK REFERENCE
COMPLETE EXPORT INDEX
Every name @zudojs/adapters exports from its package root at v1.2.0 — 56 in total, generated from the package’s own entry point rather than written by hand. The sections above explain the ones you reach for most; this is the exhaustive list, so nothing shipped is undocumented. Names not covered above are typically internal helpers and supporting types.
Show all 56 exports
AdapterAlreadyRegisteredError AdapterCapabilityMissingError AdapterConfigurationError AdapterConnectionError AdapterDisposeError AdapterError AdapterInitializationError AdapterNotFoundError AdapterNotSupportedError AdapterOperationError AdapterRegistry AdapterTimeoutError MockAdapterRegistrycreateAdapterError createDegradedHealth createHealthyHealth createMockAdapter createMockAdapterRegistry createMockHealth createUnhealthyHealth isAdapterErrorAdapter AdapterCapabilities AdapterErrorOptions AdapterHealth AdapterHealthReport AdapterMetadata AdapterOperationOptions CLIAdapter CLIOptions CLIResult HTTPAdapter HTTPListenOptions HTTPRequestAdapter HTTPRequestLike HTTPResponseAdapter HTTPResponseLike HTTPServerAdapter LifecycleAdapter MessageAdapter MockAdapter MockAdapterHealth QueueAdapter QueueStats RuntimeAdapter ScheduledJob ScheduledTask SchedulerAdapter StorageAdapter Subscription WebSocketAdapter WebSocketSessionAdapterCapabilityName AdapterHealthStatus MessageHandlerWebSocketReadyState