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

createInspector

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

Создаёт инспектор на кольцевом буфере, которым рантайм пользуется для записи снепшотов. Рантайм вызывает его за тебя, когда ты передаёшь inspectorBufferSize в createRuntime; напрямую createInspector нужен только при сборке кастомной инфраструктуры рантайма (например, моста devtools, которому нужен прямой доступ к record / subscribe).

Реализация не аллоцирует на горячем пути: O(1) record, фиксированный массив слотов, индекс с обёртыванием. getBuffer() материализует массив (newest-first) по требованию.

import { createInspector } from '@triggery/core';
function createInspector(bufferSize: number): InspectorImpl;
ПараметрТипОписание
bufferSizenumberСколько снепшотов хранить. Зажимается минимум до 1.

Объект InspectorImpl:

МетодСигнатураОписание
record(snapshot)(s: TriggerInspectSnapshot) => voidЗапушить снепшот. Обёртывается по буферу. Уведомляет подписчиков.
getBuffer()() => readonly TriggerInspectSnapshot[]Массив (newest-first) последних N записей.
getLastForTrigger(id)(triggerId: string) => Snapshot | undefinedСамый свежий снепшот по id триггера.
subscribe(fn)(fn) => () => voidСлушатель, вызываемый на каждый record. Возвращает unsubscribe.
clear()() => voidОчистить буфер и карту по триггерам.
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();