rhythmjs

Search documentation

Search guides, the tutorial and every package.

On this page

Rhythm#

new Rhythm<TInput, TStartup>(options?)#
Create a pipeline. TStartup declares the shape of context. Options include name and type.
use<TExtra>(middleware)#
Append a middleware step. Returns the same instance with an extended context type.
context#
Plain object of startup values, typed TStartup. Assign before serving; each run starts from { ...context, ...input }. Registered modules inherit their parent's values and may add their own, which never reach the parent.
register(child, exportValue?)#
Register a child Rhythm module and optional context exports. The parent's input and startup shape must satisfy the child's input type. The child runs in place: if it ends the chain without calling next(), the parent stops there. Accepts Rhythm instances only; controllers mount via use() instead.
parent#
The module this one was registered into with register(), or added to with use(child.middleware()). Undefined for a root.
sources#
Read-only list of what the module and everything under it was built from, in order: the sources of tagged middleware (routers, clis, any extension) with registered modules expanded in place. Read it lazily, once the app is assembled.
run(input): Promise<TContext>#
Dispatch one input, returning the final context.
callback(): (input) => Promise<TContext>#
Get a cached reusable handler for the current middleware stack.
middleware(): Middleware<TContext>#
Get flat middleware that shares its caller’s context and supports fallthrough. It is tagged with this module as its source.

Core exports#

compose(middleware[])#
Return a dispatcher accepting a context and optional final next handler.
withSource(fn, source)#
From @rhythmjs/rhythm/source. Tag a middleware with the object it was built from and return it. use() records the tag in the module's sources.
sourceOf(fn)#
From @rhythmjs/rhythm/source. Read the tag back, or undefined for an untagged function.
Middleware<TContext>#
A (ctx, next) function returning void or Promise<void>.
NextFn<TContext>#
Continue with optional extra context fields; resolves to readonly context.
DeepReadonly<T>#
Recursively readonly types, except callable and RhythmMutable-branded values.
OmitHashKeys<T>#
Remove keys beginning with # from an object type.
RhythmMutable#
A unique symbol used to opt objects out of DeepReadonly.
RhythmOptions#
Optional name and type labels, plus additional unknown option fields.