RuntimeOptions
Stable · since 0.1.0
Section titled “inspector semantics”
The options bag passed to createRuntime. Every field is optional; omitting the argument constructs a runtime with all defaults.
Import
Section titled “Import”import type { RuntimeOptions } from '@triggery/core';
Definition
Section titled “Definition”type RuntimeOptions = {
middleware?: readonly Middleware[];
maxCascadeDepth?: number;
inspectorBufferSize?: number;
inspector?: boolean | { dev?: boolean; prod?: boolean };
};Fields
Section titled “Fields”| Field | Type | Default | Description |
|---|---|---|---|
middleware | readonly Middleware[] | [] | Chain applied to every trigger in this runtime. Order matters for onFire / onSkip / onActionStart / onActionEnd / onError / onCascade. |
maxCascadeDepth | number | 3 | Maximum depth for action → fireEvent → … chains. Runs above this are skipped with 'overflow'. |
inspectorBufferSize | number | 50 | Ring-buffer size for the inspector. Ignored when the inspector is disabled. |
inspector | boolean | { dev?: boolean; prod?: boolean } | DEV true, PROD false (auto) | Per-run inspector switch. See below. |
inspector semantics
Section titled “inspector semantics”| Value | Effect |
|---|---|
undefined (default) | Auto — on when process.env.NODE_ENV !== 'production', off otherwise. |
true | Always on, regardless of environment. |
false | Always off — hot path drops the snapshot allocation entirely (~30-40% extra throughput). |
{ dev?, prod? } | Per-environment override. Unset fields fall back to the auto default. |
When disabled, runtime.subscribe callbacks never fire, runtime.getInspectorBuffer() returns [], and trigger.inspect() returns undefined. Devtools — @triggery/devtools-redux, @triggery/devtools-bridge, the React useInspectHistory hook — depend on the inspector being on.
Examples
Section titled “Examples”Defaults are fine for most apps
Section titled “Defaults are fine for most apps”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime (); // inspector auto, cascade=3, buffer=50, no middlewareTighten cascade depth
Section titled “Tighten cascade depth”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ maxCascadeDepth maxCascadeDepth?: number | undefinedMaximum cascade depth (action → fireEvent → ...). Default: 3. : 1 });
// Now `action → fireEvent → trigger` is allowed but `action → fireEvent → trigger → action → fireEvent → …` is not.Larger inspector buffer
Section titled “Larger inspector buffer”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ inspectorBufferSize inspectorBufferSize?: number | undefinedInspector ring buffer size (default: 50). Ignored when the inspector is disabled. : 500 });
// Helpful for long-running e2e tests that need to see runs from many minutes ago.Per-env inspector override
Section titled “Per-env inspector override”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';
// On in dev, also on in prod (e.g. for an opt-in beta where you want telemetry).
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ inspector inspector?: InspectorOption | undefinedEnable / disable the per-run inspector. See
{@link
InspectorOption
}
. : { dev dev?: boolean | undefined : true, prod prod?: boolean | undefined : true } });Hot-path benchmark mode
Section titled “Hot-path benchmark mode”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ inspector inspector?: InspectorOption | undefinedEnable / disable the per-run inspector. See
{@link
InspectorOption
}
. : false });
// `getInspectorBuffer()` returns a shared frozen `[]`; `subscribe` is a noop.Middleware chain
Section titled “Middleware chain”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime , type Middleware type Middleware = {
readonly name: string;
onFire?(ctx: FireContext): void | {
cancel: true;
reason: string;
};
onBeforeMatch?(ctx: MatchContext): void;
onSkip?(ctx: SkipContext): void;
onActionStart?(ctx: ActionContext): void;
onActionEnd?(ctx: ActionContext & {
durationMs: number;
result?: unknown;
}): void;
onError?(ctx: ActionContext & {
error: unknown;
}): void;
onCascade?(ctx: CascadeContext): void;
}
} from '@triggery/core';
const tracing const tracing: Middleware : Middleware type Middleware = {
readonly name: string;
onFire?(ctx: FireContext): void | {
cancel: true;
reason: string;
};
onBeforeMatch?(ctx: MatchContext): void;
onSkip?(ctx: SkipContext): void;
onActionStart?(ctx: ActionContext): void;
onActionEnd?(ctx: ActionContext & {
durationMs: number;
result?: unknown;
}): void;
onError?(ctx: ActionContext & {
error: unknown;
}): void;
onCascade?(ctx: CascadeContext): void;
}
= {
name name: string : 'tracing',
onFire onFire?(ctx: FireContext): void | {
cancel: true;
reason: string;
}
({ eventName eventName: string }) { console var console: Console .debug Console.debug(...data: any[]): voidThe **`console.debug()`** static method outputs a message to the console at the 'debug' log level.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static) ('[fire]', eventName eventName: string ); },
onActionEnd onActionEnd?(ctx: ActionContext & {
durationMs: number;
result?: unknown;
}): void
({ actionName actionName: string , durationMs durationMs: number }) {
console var console: Console .debug Console.debug(...data: any[]): voidThe **`console.debug()`** static method outputs a message to the console at the 'debug' log level.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static) (`[action] ${actionName actionName: string } ${durationMs durationMs: number .toFixed Number.toFixed(fractionDigits?: number): stringReturns a string representing a number in fixed-point notation. (2)}ms`);
},
};
const audit const audit: Middleware : Middleware type Middleware = {
readonly name: string;
onFire?(ctx: FireContext): void | {
cancel: true;
reason: string;
};
onBeforeMatch?(ctx: MatchContext): void;
onSkip?(ctx: SkipContext): void;
onActionStart?(ctx: ActionContext): void;
onActionEnd?(ctx: ActionContext & {
durationMs: number;
result?: unknown;
}): void;
onError?(ctx: ActionContext & {
error: unknown;
}): void;
onCascade?(ctx: CascadeContext): void;
}
= {
name name: string : 'audit',
onError onError?(ctx: ActionContext & {
error: unknown;
}): void
({ triggerId triggerId: string , actionName actionName: string , error error: unknown }) {
console var console: Console .error Console.error(...data: any[]): voidThe **`console.error()`** static method outputs a message to the console at the 'error' log level.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error_static) (`[${triggerId triggerId: string }] ${actionName actionName: string } failed`, error error: unknown );
},
};
const runtime const runtime: Runtime = createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ middleware middleware?: readonly Middleware[] | undefinedGlobal middleware applied to every trigger in this runtime. : [tracing const tracing: Middleware , audit const audit: Middleware ] });Related
Section titled “Related” createRuntime The constructor that consumes this type.
Middleware Hook shape of every middleware in the chain.
createInspector The ring-buffer implementation.
Cascade limits guide Why max-depth defaults to 3.