budibase/packages/server/src/events/BudibaseEmitter.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import { EventEmitter } from "events"
import { rowEmission, tableEmission } from "./utils"
import { Table, Row, User } from "@budibase/types"
2020-05-24 23:54:08 +02:00
/**
* keeping event emitter in one central location as it might be used for things other than
* automations (what it was for originally) - having a central emitter will be useful in the
* future.
*/
2020-05-31 18:12:52 +02:00
/**
* Extending the standard emitter to some syntactic sugar and standardisation to the emitted event.
* This is specifically quite important for template strings used in automations.
*/
class BudibaseEmitter extends EventEmitter {
2024-10-22 13:03:16 +02:00
emitRow({
eventName,
appId,
row,
table,
oldRow,
user,
}: {
eventName: string
appId: string
row: Row
table?: Table
oldRow?: Row
user: User
}) {
rowEmission({ emitter: this, eventName, appId, row, table, oldRow, user })
}
emitTable(eventName: string, appId: string, table?: Table) {
tableEmission({ emitter: this, eventName, appId, table })
}
2022-11-26 16:10:41 +01:00
emitPort(portNumber?: number | string) {
this.emit("internal:port", portNumber)
}
}
export default BudibaseEmitter