Skip to content

oracular / createRecord

Function: createRecord() ​

ts
function createRecord(
   state, 
   event, 
   opts
): EventRecord;

Defined in: recorder.ts:83

A recorder record for an event: the event itself and, for every intent, what the engine decides right after it. Call it with the state observe returned for that event, then append JSON.stringify(record) as one line of the log (NDJSON). The record holds the event's name and at, never its props.

Each decision is what evaluate reports at event.at with the state's own reveal options: p, lower, shouldReveal, suppressedUntil, the signals with the largest impact, and the effective weight of every signal. Pure: the install id comes from the app, never from here. See the Shadow mode guide for the whole workflow.

Parameters ​

ParameterTypeDescription
stateEngineStateThe state after observe(state, event). Not mutated.
eventIntentEventThe event just observed. Only name and at are recorded.
optsRecordOptionsinstallId (generated and stored by the app), mode ('shadow' while reveals are computed but not shown, 'live' once they are), and top (default 3).

Returns ​

EventRecord

A plain, JSON-serializable EventRecord.

Throws ​

TypeError when state is not an engine state, the event is malformed, opts is not an object, has an unknown key, an empty installId or a mode other than 'shadow' or 'live'.

Throws ​

RangeError when opts.top is negative or fractional.

Example ​

ts
const recording = { installId: localStorage.getItem('oracular.install')!, mode: 'shadow' } as const;

const event = { name: 'pricing.viewed', at: Date.now() };
state = observe(state, event);
appendLine(JSON.stringify(createRecord(state, event, recording)));

Released under the MIT License.