1
0
Fork 0
mirror of synced 2024-07-11 09:15:48 +12:00
budibase/packages/datastores/tests/diagnosticPlugin.js
Martin McKeaveney 7ae40de558 eslint tidy up
2020-02-25 15:46:04 +00:00

27 lines
791 B
JavaScript

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