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