API Reference

Type-safe worker process library for Node.js. Define your message contracts with TypeScript and get full type inference for payloads and responses.

Core

Types

Configuration

Serialization

Drivers

Other

Interfaces

IBaseMessage- Base message with transaction ID for request/response pairingIChildProcessDriverOptions- Options for child process driver spawnIChildProcessStartupData- Startup data specific to child_process driver. Extends the base StartupData with child_process-specific fields.IConnection- Active connection interfaceIConnectionOptions- Connection optionsIDetachCapability- Detach capability mixin. Channels that support detaching expose this to indicate whether the worker is running detached from the parent.IDriverChannel- Communication channel returned by driver spawn. The channel provides a unified interface for sending messages, handling events, and managing the connection lifecycle.IDriverMessage- Message structure for driver communication. All messages sent through the driver layer follow this structure, enabling type-safe messaging with transaction tracking.ILogger- Logger interface - must implement all log level methodsIMessageDef- Message definition shape - each message has a payload and optional resultIMiddlewareContext- Context passed to middleware functionsIReconnectCapability- Reconnect capability mixin. Channels that support reconnection implement this interface to allow disconnecting while keeping the worker alive.IServerChannel- Server channel interface for worker-side communication.IServerDriver- Driver interface for server-side usage. This is a minimal interface that drivers must satisfy for use with startWorkerServer. Both ChildProcessDriver and WorkerThreadsDriver satisfy this interface.IServerOptions- Options for creating a server channelITypedMessage- Message with type discriminatorITypedResult- Result message with type discriminatorIWorkerClient- Base worker client interface for type-safe messaging. The availability of certain methods depends on the driver's capabilities: - `disconnect()` / `reconnect()`: Only available with child_process driver - `pid`: Returns number for child_process, undefined for worker_threadsIWorkerOptions- Worker options for spawningIWorkerServer- Active worker serverIWorkerServerOptions- Server configuration optionsIWorkerThreadsDriverOptions- Options for worker threads driver spawnIWorkerThreadsResourceLimits- Resource limits for worker threadsIWorkerThreadsStartupData- Startup data specific to worker_threads driver. Extends the base StartupData with worker_threads-specific fields.

Types

TAllMessages- Union of all message types in the definition.TAllResults- Union of all result types in the definition.TAnyMessage- Union of all message types (requests and responses). Use this for middleware, transaction ID generators, and other functions that handle any message type.TBuiltInTimeoutKey- Built-in timeout keys for worker lifecycle eventsTChildProcessDriverType- Type of the ChildProcessDriverTDriverOptionsFor- Driver-specific options mappingTLogLevel- Log level enumTMaybePromise- Utility type for values that may be promisesTMessageDefs- Collection of message definitionsTMessageHandler- Handler function type for message processingTMessageOf- Extract the full message type for a given key.TMessageResult- Map a message type to its corresponding result type.TMessageTypeTMiddlewareDirection- Direction for middleware contextTPayloadOf- Extract the payload type for a given message key.TResponseFunction- Function to send a response back to the hostTResponseFunction- Function to send a response back to the hostTResultOf- Extract the full result type for a given key.TResultPayloadOf- Extract the result type for a given message key.TShutdownReasonTTimeoutConfig- Timeout configuration allowing per-message-type timeouts. Built-in keys: - `WORKER_STARTUP`: Time to wait for worker to start (default: 10s) - `SERVER_CONNECT`: Time for server to wait for host connection (default: 30s) - `WORKER_MESSAGE`: Default timeout for all messages (default: 5min) You can also specify timeouts for specific message types by their key name. Message-specific timeouts take precedence over WORKER_MESSAGE.TTransactionIdGenerator- Transaction ID generator function type. Receives a message and returns a unique transaction ID string.TUnexpectedShutdownConfigTUnexpectedShutdownStrategyTWorkerHandler- Handler function type for worker messagesTWorkerHandlers- Collection of handlers for different message typesTWorkerThreadsDriverType- Type of the WorkerThreadsDriver