Skip to content
GitHubXDiscord

createInspector

Stable · since 0.1.0

Constructs the ring-buffer inspector the runtime uses to record snapshots. The runtime calls this for you when you pass inspectorBufferSize to createRuntime; you only need createInspector directly when building custom runtime infrastructure (e.g. a devtools bridge that wants direct access to record / subscribe).

The implementation is allocation-free on the hot path: O(1) record, fixed slot array, wrap-around index. getBuffer() materializes a newest-first array on demand.

import { createInspector } from '@triggery/core';
function createInspector(bufferSize: number): InspectorImpl;
ParamTypeDescription
bufferSizenumberNumber of snapshots to keep. Clamped to a minimum of 1.

An InspectorImpl object:

MethodSignatureDescription
record(snapshot)(s: TriggerInspectSnapshot) => voidPush a snapshot. Wraps around the buffer. Notifies subscribers.
getBuffer()() => readonly TriggerInspectSnapshot[]Newest-first array of the last N records.
getLastForTrigger(id)(triggerId: string) => Snapshot | undefinedMost recent snapshot per trigger id.
subscribe(fn)(fn) => () => voidListener fired on every record. Returns an unsubscribe.
clear()() => voidEmpty the buffer and the per-trigger map.
import { createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
, type TriggerInspectSnapshot
type TriggerInspectSnapshot = {
    readonly triggerId: string;
    readonly runId: string;
    readonly eventName: string;
    readonly status: "fired" | "skipped" | "errored" | "aborted";
    readonly reason?: string;
    readonly durationMs: number;
    readonly executedActions: readonly string[];
    readonly snapshotKeys: readonly string[];
}
} from '@triggery/core';
const inspectorconst inspector: InspectorImpl = createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
(200);
inspectorconst inspector: InspectorImpl.subscribefunction subscribe(listener: (snapshot: TriggerInspectSnapshot) => void): () => void((snapshotsnapshot: TriggerInspectSnapshot: TriggerInspectSnapshot
type TriggerInspectSnapshot = {
    readonly triggerId: string;
    readonly runId: string;
    readonly eventName: string;
    readonly status: "fired" | "skipped" | "errored" | "aborted";
    readonly reason?: string;
    readonly durationMs: number;
    readonly executedActions: readonly string[];
    readonly snapshotKeys: readonly string[];
}
) => {
globalThismodule globalThis.postMessagefunction postMessage(message: any, targetOrigin: string, transfer?: Transferable[]): void (+1 overload)
The **`window.postMessage()`** method safely enables cross-origin communication between Window objects; _e.g.,_ between a page and a pop-up that it spawned, or between a page and an iframe embedded within it. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/postMessage)
(
{ sourcesource: string: 'triggery-bridge', snapshotsnapshot: TriggerInspectSnapshot }, '*', ); }); // Feed it manually — the example assumes you wired up your own dispatch // recording. The runtime created via `createRuntime` calls `record` for you. inspectorconst inspector: InspectorImpl.recordfunction record(snapshot: TriggerInspectSnapshot): void({ triggerIdtriggerId: string: 'demo', runIdrunId: string: '1', eventNameeventName: string: 'ping', statusstatus: "fired" | "skipped" | "errored" | "aborted": 'fired', durationMsdurationMs: number: 0.2, executedActionsexecutedActions: readonly string[]: ['log'], snapshotKeyssnapshotKeys: readonly string[]: [], });
import { createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
} from '@triggery/core';
const inspectorconst inspector: InspectorImpl = createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
(50);
const latestconst latest: TriggerInspectSnapshot | undefined = inspectorconst inspector: InspectorImpl.getLastForTriggerfunction getLastForTrigger(triggerId: string): TriggerInspectSnapshot | undefined('chat:new-message'); consolevar console: Console.logConsole.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
(latestconst latest: TriggerInspectSnapshot | undefined?.statusstatus: "fired" | "skipped" | "errored" | "aborted" | undefined);
import { createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
} from '@triggery/core';
const inspectorconst inspector: InspectorImpl = createInspectorfunction createInspector(bufferSize: number): InspectorImpl
Ring-buffer inspector. `record` is O(1) — writes into a fixed-size slot array with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer` materializes a newest-first array on demand (rare relative to fires).
(50);
const unsubscribeconst unsubscribe: () => void = inspectorconst inspector: InspectorImpl.subscribefunction subscribe(listener: (snapshot: TriggerInspectSnapshot) => void): () => void(snapshotsnapshot: TriggerInspectSnapshot => { consolevar console: Console.logConsole.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
(snapshotsnapshot: TriggerInspectSnapshot.triggerIdtriggerId: string, snapshotsnapshot: TriggerInspectSnapshot.statusstatus: "fired" | "skipped" | "errored" | "aborted");
}); // Later, when the panel unmounts: unsubscribeconst unsubscribe: () => void();