@nocobase/plugin-workflow 0.7.0-alpha.2 → 0.7.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -77,7 +77,7 @@ function add(...args) {
77
77
  function minus(a, b) {
78
78
  return a - b;
79
79
  }
80
- function multipe(...args) {
80
+ function multiple(...args) {
81
81
  return args.reduce((result, a) => result * a, 1);
82
82
  }
83
83
  function divide(a, b) {
@@ -88,12 +88,12 @@ function mod(a, b) {
88
88
  }
89
89
  calculators.register('add', add);
90
90
  calculators.register('minus', minus);
91
- calculators.register('multipe', multipe);
91
+ calculators.register('multiple', multiple);
92
92
  calculators.register('divide', divide);
93
93
  calculators.register('mod', mod);
94
94
  calculators.register('+', add);
95
95
  calculators.register('-', minus);
96
- calculators.register('*', multipe);
96
+ calculators.register('*', multiple);
97
97
  calculators.register('/', divide);
98
98
  calculators.register('%', mod);
99
99
  function includes(a, b) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,QAAQ,EAAY,CAAC;AAEpD,eAAe,WAAW,CAAC;AA8C3B,cAAc;AACd,yCAAyC;AACzC,kDAAkD;AAClD,sDAAsD;AACtD,SAAS,GAAG,CAAC,MAAM,EAAE,IAA6B;IAChD,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,QAAQ;AACR,sDAAsD;AACtD,gEAAgE;AAChE,8CAA8C;AAC9C,MAAM,UAAU,SAAS,CAAC,OAAgB,EAA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AED,SAAS,WAAW,CAAC,CAAC,EAAE,CAAC;IACvB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACpC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC/C,WAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AACrD,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjD,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multipe(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multipe', multipe);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multipe);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators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AE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC/C,WAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AACrD,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjD,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multiple(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multiple', multiple);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multiple);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators\n"]}
@@ -2,7 +2,7 @@ import WorkflowModel from "../models/Workflow";
2
2
  export interface ModelChangeTriggerConfig {
3
3
  collection: string;
4
4
  mode: number;
5
- filter: any;
5
+ condition: any;
6
6
  }
7
7
  declare const _default: {
8
8
  name: string;
@@ -7,26 +7,35 @@ const MODE_BITMAP_EVENTS = new Map();
7
7
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
8
8
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
9
9
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
10
+ // async function, should return promise
11
+ function bindHandler(callback) {
12
+ const { condition, changed } = this.config;
13
+ return (data, options) => {
14
+ // NOTE: if no configured fields changed, do not trigger
15
+ if (changed && changed.length && changed.every(name => !data.changed(name))) {
16
+ return;
17
+ }
18
+ // NOTE: if no configured condition match, do not trigger
19
+ if (condition && condition.$and.length) {
20
+ // TODO: check all conditions in condition against data
21
+ // const calculation = toCalculation(condition);
22
+ }
23
+ return callback({ data: data.get() }, options);
24
+ };
25
+ }
10
26
  export default {
11
27
  name: 'model',
12
28
  on(callback) {
13
29
  const { database } = this.constructor;
14
- const { collection, mode, filter } = this.config;
30
+ const { collection, mode } = this.config;
15
31
  const Collection = database.getCollection(collection);
16
32
  if (!Collection) {
17
33
  return;
18
34
  }
19
- // async function, should return promise
20
- const handler = (data, options) => {
21
- if (filter) {
22
- // TODO: check all conditions in filter against data
23
- }
24
- return callback({ data: data.get() }, options);
25
- };
26
35
  // TODO: duplication when mode change should be considered
27
36
  for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
28
37
  if (mode & key) {
29
- Collection.model.addHook(event, this.getHookId(), handler);
38
+ Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));
30
39
  }
31
40
  }
32
41
  },
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/triggers/model.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AACrC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE5D,eAAe;IACb,IAAI,EAAE,OAAO;IACb,EAAE,CAAsB,QAAkB;QACxC,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,wCAAwC;QACxC,MAAM,OAAO,GAAG,CAAC,IAAS,EAAE,OAAO,EAAE,EAAE;YACrC,IAAI,MAAM,EAAE;gBACV,oDAAoD;aACrD;YACD,OAAO,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC;QACF,0DAA0D;QAC1D,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;aAC5D;SACF;IACH,CAAC;IACD,GAAG;QACD,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;SACF;IACH,CAAC;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n filter: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode, filter } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // async function, should return promise\n const handler = (data: any, options) => {\n if (filter) {\n // TODO: check all conditions in filter against data\n }\n return callback({ data: data.get() }, options);\n };\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), handler);\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/triggers/model.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AACrC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE5D,wCAAwC;AACxC,S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,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;SACF;IACH,CAAC;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n condition: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\n// async function, should return promise\nfunction bindHandler(this: WorkflowModel, callback: Function) {\n const { condition, changed } = this.config;\n return (data: any, options) => {\n // NOTE: if no configured fields changed, do not trigger\n if (changed && changed.length && changed.every(name => !data.changed(name))) {\n return;\n }\n // NOTE: if no configured condition match, do not trigger\n if (condition && condition.$and.length) {\n // TODO: check all conditions in condition against data\n // const calculation = toCalculation(condition);\n }\n\n return callback({ data: data.get() }, options);\n };\n}\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
@@ -81,7 +81,7 @@ function add(...args) {
81
81
  function minus(a, b) {
82
82
  return a - b;
83
83
  }
84
- function multipe(...args) {
84
+ function multiple(...args) {
85
85
  return args.reduce((result, a) => result * a, 1);
86
86
  }
87
87
  function divide(a, b) {
@@ -92,12 +92,12 @@ function mod(a, b) {
92
92
  }
93
93
  exports.calculators.register('add', add);
94
94
  exports.calculators.register('minus', minus);
95
- exports.calculators.register('multipe', multipe);
95
+ exports.calculators.register('multiple', multiple);
96
96
  exports.calculators.register('divide', divide);
97
97
  exports.calculators.register('mod', mod);
98
98
  exports.calculators.register('+', add);
99
99
  exports.calculators.register('-', minus);
100
- exports.calculators.register('*', multipe);
100
+ exports.calculators.register('*', multiple);
101
101
  exports.calculators.register('/', divide);
102
102
  exports.calculators.register('%', mod);
103
103
  function includes(a, b) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAC5C,2CAA2C;AAK9B,QAAA,WAAW,GAAG,IAAI,gBAAQ,EAAY,CAAC;AAEpD,kBAAe,mBAAW,CAAC;AA8C3B,cAAc;AACd,yCAAyC;AACzC,kDAAkD;AAClD,sDAAsD;AACtD,SAAS,GAAG,CAAC,MAAM,EAAE,IAA6B;IAChD,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,YAAW,EAAC,MAAM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,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multipe(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multipe', multipe);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multipe);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAC5C,2CAA2C;AAK9B,QAAA,WAAW,GAAG,IAAI,gBAAQ,EAAY,CAAC;AAEpD,kBAAe,mBAAW,CAAC;AA8C3B,cAAc;AACd,yCAAyC;AACzC,kDAAkD;AAClD,sDAAsD;AACtD,SAAS,GAAG,CAAC,MAAM,EAAE,IAA6B;IAChD,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAA,YAAW,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,QAAQ;AACR,sDAAsD;AACtD,gEAAgE;AAChE,8CAA8C;AAC9C,SAAgB,SAAS,CAAC,OAAgB,EAAE,OAAiB,EAAE,SAAyB;IACtF,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,cAAc;QACd,yBAAyB;QACzB,KAAK,UAAU;YACb,OAAO,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEtD,cAAc;QACd,+BAA+B;QAC/B,KAAK,QAAQ;YACX,OAAO,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAE9D,cAAc;QACd,wBAAwB;QACxB,KAAK,kBAAkB;YACrB,sDAAsD;YACtD,MAAM,GAAG,GAAG,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC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CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,mBAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,mBAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,mBAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC/C,mBAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AACrD,mBAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,mBAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjD,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,mBAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multiple(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multiple', multiple);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multiple);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators\n"]}
@@ -2,7 +2,7 @@ import WorkflowModel from "../models/Workflow";
2
2
  export interface ModelChangeTriggerConfig {
3
3
  collection: string;
4
4
  mode: number;
5
- filter: any;
5
+ condition: any;
6
6
  }
7
7
  declare const _default: {
8
8
  name: string;
@@ -9,26 +9,35 @@ const MODE_BITMAP_EVENTS = new Map();
9
9
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
10
10
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
11
11
  MODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');
12
+ // async function, should return promise
13
+ function bindHandler(callback) {
14
+ const { condition, changed } = this.config;
15
+ return (data, options) => {
16
+ // NOTE: if no configured fields changed, do not trigger
17
+ if (changed && changed.length && changed.every(name => !data.changed(name))) {
18
+ return;
19
+ }
20
+ // NOTE: if no configured condition match, do not trigger
21
+ if (condition && condition.$and.length) {
22
+ // TODO: check all conditions in condition against data
23
+ // const calculation = toCalculation(condition);
24
+ }
25
+ return callback({ data: data.get() }, options);
26
+ };
27
+ }
12
28
  exports.default = {
13
29
  name: 'model',
14
30
  on(callback) {
15
31
  const { database } = this.constructor;
16
- const { collection, mode, filter } = this.config;
32
+ const { collection, mode } = this.config;
17
33
  const Collection = database.getCollection(collection);
18
34
  if (!Collection) {
19
35
  return;
20
36
  }
21
- // async function, should return promise
22
- const handler = (data, options) => {
23
- if (filter) {
24
- // TODO: check all conditions in filter against data
25
- }
26
- return callback({ data: data.get() }, options);
27
- };
28
37
  // TODO: duplication when mode change should be considered
29
38
  for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
30
39
  if (mode & key) {
31
- Collection.model.addHook(event, this.getHookId(), handler);
40
+ Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));
32
41
  }
33
42
  }
34
43
  },
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/triggers/model.ts"],"names":[],"mappings":";;AASA,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AACrC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAE5D,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,EAAE,CAAsB,QAAkB;QACxC,MAAM,E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C;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n filter: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode, filter } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // async function, should return promise\n const handler = (data: any, options) => {\n if (filter) {\n // TODO: check all conditions in filter against data\n }\n return callback({ data: data.get() }, options);\n };\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), handler);\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/triggers/model.ts"],"names":[],"mappings":";;AASA,MAAM,WAAW,GAAG;IAClB,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAC;AACrC,kBAAkB,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAC1D,kBAAkB,CAAC,G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AAS,EAAE,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;aACrF;SACF;IACH,CAAC;IACD,GAAG;QACD,MAAM,EAAE,QAAQ,EAAE,GAAyB,IAAI,CAAC,WAAW,CAAC;QAC5D,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE;YACf,OAAO;SACR;QACD,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,EAAE;YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;SACF;IACH,CAAC;CACF,CAAA","sourcesContent":["import WorkflowModel from \"../models/Workflow\";\n\nexport interface ModelChangeTriggerConfig {\n collection: string;\n mode: number;\n // TODO: ICondition\n condition: any;\n}\n\nconst MODE_BITMAP = {\n CREATE: 1,\n UPDATE: 2,\n DESTROY: 4\n};\n\nconst MODE_BITMAP_EVENTS = new Map();\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');\nMODE_BITMAP_EVENTS.set(MODE_BITMAP.DESTROY, 'afterDestroy');\n\n// async function, should return promise\nfunction bindHandler(this: WorkflowModel, callback: Function) {\n const { condition, changed } = this.config;\n return (data: any, options) => {\n // NOTE: if no configured fields changed, do not trigger\n if (changed && changed.length && changed.every(name => !data.changed(name))) {\n return;\n }\n // NOTE: if no configured condition match, do not trigger\n if (condition && condition.$and.length) {\n // TODO: check all conditions in condition against data\n // const calculation = toCalculation(condition);\n }\n\n return callback({ data: data.get() }, options);\n };\n}\n\nexport default {\n name: 'model',\n on(this: WorkflowModel, callback: Function) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n // TODO: duplication when mode change should be considered\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));\n }\n }\n },\n off(this: WorkflowModel) {\n const { database } = <typeof WorkflowModel>this.constructor;\n const { collection, mode } = this.config;\n const Collection = database.getCollection(collection);\n if (!Collection) {\n return;\n }\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n Collection.model.removeHook(event, this.getHookId());\n }\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-workflow",
3
- "version": "0.7.0-alpha.2",
3
+ "version": "0.7.0-alpha.22",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -15,14 +15,14 @@
15
15
  "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
16
16
  },
17
17
  "dependencies": {
18
- "@nocobase/actions": "0.7.0-alpha.2",
19
- "@nocobase/database": "0.7.0-alpha.2",
20
- "@nocobase/server": "0.7.0-alpha.2",
21
- "@nocobase/utils": "0.7.0-alpha.2",
18
+ "@nocobase/actions": "0.7.0-alpha.22",
19
+ "@nocobase/database": "0.7.0-alpha.22",
20
+ "@nocobase/server": "0.7.0-alpha.22",
21
+ "@nocobase/utils": "0.7.0-alpha.22",
22
22
  "json-templates": "^4.2.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@nocobase/test": "0.7.0-alpha.2"
25
+ "@nocobase/test": "0.7.0-alpha.22"
26
26
  },
27
- "gitHead": "0e0e99ef79c0b25bb0b45ecaa477c049cb16afee"
27
+ "gitHead": "dc5e9c80ed57ffd9b2f652f68a9444bfb79647db"
28
28
  }