Initial import of verae-zapier-simulator from zapier monorepo
This commit is contained in:
commit
bb8833dc2e
10 changed files with 1651 additions and 0 deletions
44
src/trace.js
Normal file
44
src/trace.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue