diff --git a/packages/core/database/src/repository.ts b/packages/core/database/src/repository.ts index 402edd5bd..d68175ebc 100644 --- a/packages/core/database/src/repository.ts +++ b/packages/core/database/src/repository.ts @@ -88,6 +88,7 @@ export type Values = any; export interface CountOptions extends Omit, Transactionable { filter?: Filter; + context?: any; } export interface FilterByTk { diff --git a/packages/plugins/workflow/src/server/Plugin.ts b/packages/plugins/workflow/src/server/Plugin.ts index 1335a5fad..9c5074448 100644 --- a/packages/plugins/workflow/src/server/Plugin.ts +++ b/packages/plugins/workflow/src/server/Plugin.ts @@ -128,7 +128,7 @@ export default class WorkflowPlugin extends Plugin { } } - async trigger(workflow: WorkflowModel, context: Object, options: Transactionable = {}): Promise { + async trigger(workflow: WorkflowModel, context: Object, options: Transactionable & { context?: any } = {}): Promise { // `null` means not to trigger if (context === null) { return null; @@ -186,7 +186,7 @@ export default class WorkflowPlugin extends Plugin { execution.workflow = workflow; - const processor = this.createProcessor(execution, { transaction }); + const processor = this.createProcessor(execution, { transaction, _context: options.context }); await processor.start(); diff --git a/packages/plugins/workflow/src/server/Processor.ts b/packages/plugins/workflow/src/server/Processor.ts index a64008069..2e1b5b547 100644 --- a/packages/plugins/workflow/src/server/Processor.ts +++ b/packages/plugins/workflow/src/server/Processor.ts @@ -13,6 +13,8 @@ import { EXECUTION_STATUS, JOB_STATUS } from './constants'; export interface ProcessorOptions extends Transactionable { + // TODO(temp): pass request context here for $isVar and other operators + _context?: any; plugin: Plugin } @@ -33,7 +35,7 @@ export default class Processor { jobsMap = new Map(); jobsMapByNodeId: { [key: number]: any } = {}; - constructor(public execution: ExecutionModel, private options: ProcessorOptions) { + constructor(public execution: ExecutionModel, public options: ProcessorOptions) { } // make dual linked nodes list then cache diff --git a/packages/plugins/workflow/src/server/instructions/create.ts b/packages/plugins/workflow/src/server/instructions/create.ts index c9a25dfec..4704ec614 100644 --- a/packages/plugins/workflow/src/server/instructions/create.ts +++ b/packages/plugins/workflow/src/server/instructions/create.ts @@ -12,6 +12,7 @@ export default { const options = processor.getParsedValue(params); const result = await repo.create({ ...options, + context: processor.options._context, transaction: processor.transaction }); diff --git a/packages/plugins/workflow/src/server/instructions/destroy.ts b/packages/plugins/workflow/src/server/instructions/destroy.ts index c94ddab9d..310bd8ba8 100644 --- a/packages/plugins/workflow/src/server/instructions/destroy.ts +++ b/packages/plugins/workflow/src/server/instructions/destroy.ts @@ -12,6 +12,7 @@ export default { const options = processor.getParsedValue(params); const result = await repo.destroy({ ...options, + context: processor.options._context, transaction: processor.transaction }); diff --git a/packages/plugins/workflow/src/server/instructions/query.ts b/packages/plugins/workflow/src/server/instructions/query.ts index 9001427b8..280cbcab4 100644 --- a/packages/plugins/workflow/src/server/instructions/query.ts +++ b/packages/plugins/workflow/src/server/instructions/query.ts @@ -14,6 +14,7 @@ export default { const options = processor.getParsedValue(params); const result = await (multiple ? repo.find : repo.findOne).call(repo, { ...options, + context: processor.options._context, transaction: processor.transaction }); diff --git a/packages/plugins/workflow/src/server/instructions/update.ts b/packages/plugins/workflow/src/server/instructions/update.ts index e0d2fede6..cac6de677 100644 --- a/packages/plugins/workflow/src/server/instructions/update.ts +++ b/packages/plugins/workflow/src/server/instructions/update.ts @@ -14,6 +14,7 @@ export default { const options = processor.getParsedValue(params); const result = await repo.update({ ...options, + context: processor.options._context, transaction: processor.transaction }); diff --git a/packages/plugins/workflow/src/server/triggers/collection.ts b/packages/plugins/workflow/src/server/triggers/collection.ts index f98eeda3b..e482a4db8 100644 --- a/packages/plugins/workflow/src/server/triggers/collection.ts +++ b/packages/plugins/workflow/src/server/triggers/collection.ts @@ -39,7 +39,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M // TODO: change to map filter format to calculation format // const calculation = toCalculation(condition); const { repository, model } = (data.constructor).database.getCollection(collection); - const { transaction } = options; + const { transaction, context } = options; const count = await repository.count({ filter: { $and: [ @@ -47,6 +47,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M { [model.primaryKeyAttribute]: data[model.primaryKeyAttribute] } ] }, + context, transaction }); @@ -56,6 +57,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M } return this.plugin.trigger(workflow, { data: data.get() }, { + context: options.context, transaction: options.transaction }); }