Перейти к содержимому
GitHubXDiscord

RuntimeOptions

Стабильный · с 0.1.0

Bag опций, передаваемый в createRuntime. Все поля необязательные; без аргументов создаётся рантайм со всеми дефолтами.

import type { RuntimeOptions } from '@triggery/core';
type RuntimeOptions = {
  middleware?:          readonly Middleware[];
  maxCascadeDepth?:     number;
  inspectorBufferSize?: number;
  inspector?:           boolean | { dev?: boolean; prod?: boolean };
};
ПолеТипПо умолчаниюОписание
middlewarereadonly Middleware[][]Цепочка, применяемая к каждому триггеру в этом рантайме. Порядок важен для onFire / onSkip / onActionStart / onActionEnd / onError / onCascade.
maxCascadeDepthnumber3Максимальная глубина цепочек action → fireEvent → …. Запуски выше этой границы пропускаются с 'overflow'.
inspectorBufferSizenumber50Размер кольцевого буфера инспектора. Игнорируется, когда инспектор выключен.
inspectorboolean | { dev?: boolean; prod?: boolean }DEV true, PROD false (авто)Переключатель инспектора по средам. См. ниже.
ЗначениеЭффект
undefined (по умолчанию)Авто — включён при process.env.NODE_ENV !== 'production', иначе выключен.
trueВсегда включён, вне зависимости от среды.
falseВсегда выключен — горячий путь не аллоцирует снепшот вообще (~30–40% дополнительной пропускной способности).
{ dev?, prod? }Переопределение по средам. Неустановленные поля падают на авто-дефолт.

Когда выключен, обратные вызовы runtime.subscribe не вызываются, runtime.getInspectorBuffer() возвращает [], а trigger.inspect()undefined. Devtools — @triggery/devtools-redux, @triggery/devtools-bridge, хук useInspectHistory для React — зависят от включённого инспектора.

import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';

const runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime(); // inspector auto, cascade=3, buffer=50, no middleware
import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';

const runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ maxCascadeDepthmaxCascadeDepth?: number | undefined
Maximum cascade depth (action → fireEvent → ...). Default: 3.
: 1 });
// Now `action → fireEvent → trigger` is allowed but `action → fireEvent → trigger → action → fireEvent → …` is not.
import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';

const runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ inspectorBufferSizeinspectorBufferSize?: number | undefined
Inspector 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.
import { createRuntimefunction 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 runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ inspectorinspector?: InspectorOption | undefined
Enable / disable the per-run inspector. See {@link InspectorOption } .
: { devdev?: boolean | undefined: true, prodprod?: boolean | undefined: true } });
import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime } from '@triggery/core';

const runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ inspectorinspector?: InspectorOption | undefined
Enable / disable the per-run inspector. See {@link InspectorOption } .
: false });
// `getInspectorBuffer()` returns a shared frozen `[]`; `subscribe` is a noop.
import { createRuntimefunction 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 tracingconst 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;
}
= {
namename: string: 'tracing', onFire
onFire?(ctx: FireContext): void | {
    cancel: true;
    reason: string;
}
({ eventNameeventName: string }) { consolevar console: Console.debugConsole.debug(...data: any[]): void
The **`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]', eventNameeventName: string); },
onActionEnd
onActionEnd?(ctx: ActionContext & {
    durationMs: number;
    result?: unknown;
}): void
({ actionNameactionName: string, durationMsdurationMs: number }) {
consolevar console: Console.debugConsole.debug(...data: any[]): void
The **`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] ${actionNameactionName: string} ${durationMsdurationMs: number.toFixedNumber.toFixed(fractionDigits?: number): string
Returns a string representing a number in fixed-point notation.
@paramfractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
(2)}ms`);
}, }; const auditconst 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;
}
= {
namename: string: 'audit', onError
onError?(ctx: ActionContext & {
    error: unknown;
}): void
({ triggerIdtriggerId: string, actionNameactionName: string, errorerror: unknown }) {
consolevar console: Console.errorConsole.error(...data: any[]): void
The **`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)
(`[${triggerIdtriggerId: string}] ${actionNameactionName: string} failed`, errorerror: unknown);
}, }; const runtimeconst runtime: Runtime = createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ middlewaremiddleware?: readonly Middleware[] | undefined
Global middleware applied to every trigger in this runtime.
: [tracingconst tracing: Middleware, auditconst audit: Middleware] });