44 lines
897 B
JavaScript
44 lines
897 B
JavaScript
/**
|
|
* Ordered hop log from Zapier input through every module to the response.
|
|
* @module trace
|
|
*/
|
|
|
|
export class TraceBus {
|
|
constructor() {
|
|
this.events = [];
|
|
this.t0 = Date.now();
|
|
}
|
|
|
|
now() {
|
|
return Date.now() - this.t0;
|
|
}
|
|
|
|
/**
|
|
* @param {{
|
|
* module: string,
|
|
* hop: string,
|
|
* dir?: 'in'|'out'|'internal',
|
|
* address?: string,
|
|
* status?: 'ok'|'silent'|'error'|'retry'|'delay'|'skip',
|
|
* payload?: object,
|
|
* note?: string,
|
|
* durationMs?: number
|
|
* }} e
|
|
*/
|
|
emit(e) {
|
|
const ev = {
|
|
seq: this.events.length + 1,
|
|
tMs: this.now(),
|
|
module: e.module,
|
|
hop: e.hop,
|
|
dir: e.dir || 'internal',
|
|
address: e.address || '',
|
|
status: e.status || 'ok',
|
|
payload: e.payload ?? null,
|
|
note: e.note || '',
|
|
durationMs: e.durationMs ?? 0,
|
|
};
|
|
this.events.push(ev);
|
|
return ev;
|
|
}
|
|
}
|