Typing emitter

This commit is contained in:
Adria Navarro 2024-10-24 13:07:13 +02:00
parent a8264aadc2
commit 47e16dd844
3 changed files with 32 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import * as internal from "./internal"
import * as external from "./external"
import { isExternalTableID } from "../../../integrations/utils"
import {
AutomationEventType,
Ctx,
DeleteRow,
DeleteRowRequest,
@ -64,9 +65,9 @@ export async function patch(
ctx.throw(404, "Row not found")
}
ctx.status = 200
ctx.eventEmitter &&
ctx.eventEmitter.emitRow({
eventName: `row:update`,
ctx.eventEmitter?.emitRow({
eventName: AutomationEventType.ROW_UPDATE,
appId,
row,
table,

View File

@ -1,12 +1,12 @@
import { rowEmission, tableEmission } from "./utils"
import mainEmitter from "./index"
import env from "../environment"
import { Table, Row, DocumentType, App } from "@budibase/types"
import { Table, Row, DocumentType, App, ContextEmitter } from "@budibase/types"
import { context } from "@budibase/backend-core"
const MAX_AUTOMATIONS_ALLOWED = 5
class AutomationEmitter {
class AutomationEmitter implements ContextEmitter {
chainCount: number
metadata: { automationChainCount: number }

View File

@ -1,5 +1,14 @@
import { Context, Request } from "koa"
import { User, Role, UserRoles, Account, ConfigType } from "../documents"
import {
User,
Role,
UserRoles,
Account,
ConfigType,
Row,
Table,
AutomationEventType,
} from "../documents"
import { FeatureFlag, License } from "../sdk"
import { Files } from "formidable"
@ -40,6 +49,7 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
extends Ctx<RequestBody, ResponseBody> {
user: ContextUser
roleId?: string
eventEmitter?: ContextEmitter
}
/**
@ -49,3 +59,12 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
export interface BBContext extends Ctx {
user?: ContextUser
}
export interface ContextEmitter {
emitRow: (params: {
eventName: AutomationEventType
appId: string
row: Row
table?: Table
}) => Promise<void>
}