1
0
Fork 0
mirror of synced 2024-07-30 02:26:11 +12:00
budibase/packages/datastores/tests/diagnosticPlugin.js

27 lines
791 B
JavaScript
Raw Normal View History

import { eventsList } from "@budibase/core"
import { filter, union, has, map } from "lodash/fp"
2019-06-08 01:18:10 +12:00
const allEventsOfType = type => filter(e => e.endsWith(`:${type}`))(eventsList)
2019-06-08 01:18:10 +12:00
const hasRecord = has("record")
2019-06-08 01:18:10 +12:00
export const register = (app, logTimeElapsed, eventNamespaces = []) => {
const onCompleteEvents =
eventNamespaces.length === 0
? allEventsOfType("onComplete")
: map(e => `${e}:onComplete`)(eventNamespaces)
2019-06-08 01:18:10 +12:00
const onErrorEvents =
eventNamespaces.length === 0
? allEventsOfType("onError")
: map(e => `${e}:onError`)(eventNamespaces)
2019-06-08 01:18:10 +12:00
for (let ev of union(onCompleteEvents)(onErrorEvents)) {
app.subscribe(ev, (_, ctx) => {
const info = hasRecord(ctx) ? ctx.record.type() : ""
2019-06-08 01:18:10 +12:00
logTimeElapsed(ev, ctx.elapsed, info)
})
}
}