Postboy Help

Infrastructure Messages Reference

Reference page for the infrastructure messages of @artstesh/postboy (applies to v3.5.x).

Since v3.5 these executors are the only way to mutate the bus. All are dispatched via postboy.exec(...), all declare their own static ID, and all flow through the Execute stage of the middleware pipeline — filter them out with canHandle if your middleware gates domain commands only (see Middleware).

Registration

ConnectMessage<T>

exec(new ConnectMessage(type: MessageType<T>, sub: Subject<T>, pipe?: (s: Subject<T>) => Observable<T>));

Registers a message subject (replaces the deprecated record/recordWithPipe). The optional pipe shapes the observable that sub hands out — e.g. s => s.pipe(auditTime(200)).

ConnectExecutor<E, T>

exec(new ConnectExecutor(type: MessageType<E>, exec: (e: E) => T));

Registers the handler function invoked by exec for this executor type (replaces recordExecutor).

ConnectHandler<E, R>

exec(new ConnectHandler(executor: new (...args: any[]) => E, handler: PostboyExecutionHandler<R, E>));

Registers a handler object whose handle(executor) is invoked for the type (replaces recordHandler).

DisconnectMessage

exec(new DisconnectMessage(messageId: string));

Unregisters a message type by its static ID: completes the subject (subscriber streams end), runs the registered completion callbacks, and also drops any executor handler registered under the same ID. Further fire/sub of the type throws.

Pipeline

AddMiddleware / RemoveMiddleware

exec(new AddMiddleware(middleware: PostboyMiddleware)); exec(new RemoveMiddleware(middleware: PostboyMiddleware));

Append to / remove from the middleware pipeline. Removal is by instance identity and calls the middleware's dispose(). The same instance added twice runs its hooks twice. See Middleware.

Locking

LockMessage<T> / UnlockMessage<T>

exec(new LockMessage(Type)); exec(new UnlockMessage(Type));

Adds the type's static ID to the lock set / removes it. A locked type's delivery via fire and fireCallback is silently skipped — no error, no notification to subscribers; registration and sub keep working, middleware hooks still run. Mute, not error. Never lock IDs you don't own: to their subscribers a locked type looks exactly like data loss.

Namespaces

AddNamespace

const registrator = exec(new AddNamespace(space: string));

Creates the namespace and returns its PostboyAbstractRegistrator — record messages and executors on it, then tear them all down at once. Executing it again with the same name returns the same registrator without recreating it.

EliminateNamespace

exec(new EliminateNamespace(space: string));

Tears the namespace down (down() on its registrator — a DisconnectMessage for every recorded ID) and removes it. Unknown names are ignored. The whole bus tear-down (postboy.dispose()) eliminates every namespace as well. See Namespaces.

Removal from ≤3.4

Removed service method

Message replacement

lock(Type)/unlock(Type)

LockMessage/UnlockMessage

addMiddleware(mw)/removeMiddleware(mw)

AddMiddleware/RemoveMiddleware

addNamespace(ns)

AddNamespace

eliminateNamespace(ns)

EliminateNamespace

unregister(Type)

DisconnectMessage(Type.ID)

record* (deprecated, still present)

ConnectMessage/ConnectExecutor/ConnectHandler

See Migrating middleware from 3.4 for the reasoning behind the removals and Versions for the version lines.

07 September 2026