Typing emitter
This commit is contained in:
parent
a8264aadc2
commit
47e16dd844
|
@ -7,6 +7,7 @@ import * as internal from "./internal"
|
||||||
import * as external from "./external"
|
import * as external from "./external"
|
||||||
import { isExternalTableID } from "../../../integrations/utils"
|
import { isExternalTableID } from "../../../integrations/utils"
|
||||||
import {
|
import {
|
||||||
|
AutomationEventType,
|
||||||
Ctx,
|
Ctx,
|
||||||
DeleteRow,
|
DeleteRow,
|
||||||
DeleteRowRequest,
|
DeleteRowRequest,
|
||||||
|
@ -64,15 +65,15 @@ export async function patch(
|
||||||
ctx.throw(404, "Row not found")
|
ctx.throw(404, "Row not found")
|
||||||
}
|
}
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.eventEmitter &&
|
|
||||||
ctx.eventEmitter.emitRow({
|
ctx.eventEmitter?.emitRow({
|
||||||
eventName: `row:update`,
|
eventName: AutomationEventType.ROW_UPDATE,
|
||||||
appId,
|
appId,
|
||||||
row,
|
row,
|
||||||
table,
|
table,
|
||||||
oldRow,
|
oldRow,
|
||||||
user: sdk.users.getUserContextBindings(ctx.user),
|
user: sdk.users.getUserContextBindings(ctx.user),
|
||||||
})
|
})
|
||||||
ctx.message = `${table.name} updated successfully.`
|
ctx.message = `${table.name} updated successfully.`
|
||||||
ctx.body = row
|
ctx.body = row
|
||||||
gridSocket?.emitRowUpdate(ctx, row)
|
gridSocket?.emitRowUpdate(ctx, row)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { rowEmission, tableEmission } from "./utils"
|
import { rowEmission, tableEmission } from "./utils"
|
||||||
import mainEmitter from "./index"
|
import mainEmitter from "./index"
|
||||||
import env from "../environment"
|
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"
|
import { context } from "@budibase/backend-core"
|
||||||
|
|
||||||
const MAX_AUTOMATIONS_ALLOWED = 5
|
const MAX_AUTOMATIONS_ALLOWED = 5
|
||||||
|
|
||||||
class AutomationEmitter {
|
class AutomationEmitter implements ContextEmitter {
|
||||||
chainCount: number
|
chainCount: number
|
||||||
metadata: { automationChainCount: number }
|
metadata: { automationChainCount: number }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
import { Context, Request } from "koa"
|
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 { FeatureFlag, License } from "../sdk"
|
||||||
import { Files } from "formidable"
|
import { Files } from "formidable"
|
||||||
|
|
||||||
|
@ -40,6 +49,7 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
|
||||||
extends Ctx<RequestBody, ResponseBody> {
|
extends Ctx<RequestBody, ResponseBody> {
|
||||||
user: ContextUser
|
user: ContextUser
|
||||||
roleId?: string
|
roleId?: string
|
||||||
|
eventEmitter?: ContextEmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,3 +59,12 @@ export interface UserCtx<RequestBody = any, ResponseBody = any>
|
||||||
export interface BBContext extends Ctx {
|
export interface BBContext extends Ctx {
|
||||||
user?: ContextUser
|
user?: ContextUser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ContextEmitter {
|
||||||
|
emitRow: (params: {
|
||||||
|
eventName: AutomationEventType
|
||||||
|
appId: string
|
||||||
|
row: Row
|
||||||
|
table?: Table
|
||||||
|
}) => Promise<void>
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue