@nocobase/plugin-workflow 0.7.0-alpha.34 → 0.7.0-alpha.57
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.
- package/lib/actions/index.js +31 -32
- package/lib/actions/nodes.js +310 -182
- package/lib/actions/workflows.js +260 -157
- package/lib/calculators/index.js +142 -90
- package/lib/collections/executions.js +40 -43
- package/lib/collections/flow_nodes.js +60 -65
- package/lib/collections/jobs.js +45 -47
- package/lib/collections/workflows.js +78 -87
- package/lib/constants.js +22 -17
- package/lib/index.js +71 -22
- package/lib/instructions/calculation.js +34 -29
- package/lib/instructions/condition.js +94 -87
- package/lib/instructions/create.js +43 -26
- package/lib/instructions/destroy.js +42 -25
- package/lib/instructions/index.js +46 -25
- package/lib/instructions/parallel.js +99 -84
- package/lib/instructions/prompt.js +21 -13
- package/lib/instructions/query.js +47 -29
- package/lib/instructions/update.js +44 -25
- package/lib/models/Execution.js +401 -248
- package/lib/models/FlowNode.js +18 -5
- package/lib/models/Job.js +18 -5
- package/lib/models/Workflow.js +132 -88
- package/lib/server.js +93 -66
- package/lib/triggers/collection.js +113 -51
- package/lib/triggers/index.js +25 -11
- package/package.json +7 -12
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.js +0 -14
- package/esm/actions/index.js.map +0 -1
- package/esm/actions/nodes.d.ts +0 -4
- package/esm/actions/nodes.js +0 -187
- package/esm/actions/nodes.js.map +0 -1
- package/esm/actions/workflows.d.ts +0 -3
- package/esm/actions/workflows.js +0 -163
- package/esm/actions/workflows.js.map +0 -1
- package/esm/calculators/index.d.ts +0 -38
- package/esm/calculators/index.js +0 -128
- package/esm/calculators/index.js.map +0 -1
- package/esm/collections/executions.d.ts +0 -3
- package/esm/collections/executions.js +0 -43
- package/esm/collections/executions.js.map +0 -1
- package/esm/collections/flow_nodes.d.ts +0 -3
- package/esm/collections/flow_nodes.js +0 -65
- package/esm/collections/flow_nodes.js.map +0 -1
- package/esm/collections/jobs.d.ts +0 -3
- package/esm/collections/jobs.js +0 -47
- package/esm/collections/jobs.js.map +0 -1
- package/esm/collections/workflows.d.ts +0 -3
- package/esm/collections/workflows.js +0 -87
- package/esm/collections/workflows.js.map +0 -1
- package/esm/constants.d.ts +0 -17
- package/esm/constants.js +0 -18
- package/esm/constants.js.map +0 -1
- package/esm/index.d.ts +0 -5
- package/esm/index.js +0 -6
- package/esm/index.js.map +0 -1
- package/esm/instructions/calculation.d.ts +0 -8
- package/esm/instructions/calculation.js +0 -55
- package/esm/instructions/calculation.js.map +0 -1
- package/esm/instructions/condition.d.ts +0 -5
- package/esm/instructions/condition.js +0 -99
- package/esm/instructions/condition.js.map +0 -1
- package/esm/instructions/create.d.ts +0 -8
- package/esm/instructions/create.js +0 -26
- package/esm/instructions/create.js.map +0 -1
- package/esm/instructions/destroy.d.ts +0 -8
- package/esm/instructions/destroy.js +0 -25
- package/esm/instructions/destroy.js.map +0 -1
- package/esm/instructions/index.d.ts +0 -15
- package/esm/instructions/index.js +0 -20
- package/esm/instructions/index.js.map +0 -1
- package/esm/instructions/parallel.d.ts +0 -13
- package/esm/instructions/parallel.js +0 -88
- package/esm/instructions/parallel.js.map +0 -1
- package/esm/instructions/prompt.d.ts +0 -7
- package/esm/instructions/prompt.js +0 -13
- package/esm/instructions/prompt.js.map +0 -1
- package/esm/instructions/query.d.ts +0 -8
- package/esm/instructions/query.js +0 -29
- package/esm/instructions/query.js.map +0 -1
- package/esm/instructions/update.d.ts +0 -9
- package/esm/instructions/update.js +0 -25
- package/esm/instructions/update.js.map +0 -1
- package/esm/models/Execution.d.ts +0 -51
- package/esm/models/Execution.js +0 -256
- package/esm/models/Execution.js.map +0 -1
- package/esm/models/FlowNode.d.ts +0 -17
- package/esm/models/FlowNode.js +0 -4
- package/esm/models/FlowNode.js.map +0 -1
- package/esm/models/Job.d.ts +0 -15
- package/esm/models/Job.js +0 -4
- package/esm/models/Job.js.map +0 -1
- package/esm/models/Workflow.d.ts +0 -29
- package/esm/models/Workflow.js +0 -88
- package/esm/models/Workflow.js.map +0 -1
- package/esm/server.d.ts +0 -5
- package/esm/server.js +0 -62
- package/esm/server.js.map +0 -1
- package/esm/triggers/collection.d.ts +0 -12
- package/esm/triggers/collection.js +0 -61
- package/esm/triggers/collection.js.map +0 -1
- package/esm/triggers/index.d.ts +0 -9
- package/esm/triggers/index.js +0 -6
- package/esm/triggers/index.js.map +0 -1
- package/lib/actions/index.js.map +0 -1
- package/lib/actions/nodes.js.map +0 -1
- package/lib/actions/workflows.js.map +0 -1
- package/lib/calculators/index.js.map +0 -1
- package/lib/collections/executions.js.map +0 -1
- package/lib/collections/flow_nodes.js.map +0 -1
- package/lib/collections/jobs.js.map +0 -1
- package/lib/collections/workflows.js.map +0 -1
- package/lib/constants.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/instructions/calculation.js.map +0 -1
- package/lib/instructions/condition.js.map +0 -1
- package/lib/instructions/create.js.map +0 -1
- package/lib/instructions/destroy.js.map +0 -1
- package/lib/instructions/index.js.map +0 -1
- package/lib/instructions/parallel.js.map +0 -1
- package/lib/instructions/prompt.js.map +0 -1
- package/lib/instructions/query.js.map +0 -1
- package/lib/instructions/update.js.map +0 -1
- package/lib/models/Execution.js.map +0 -1
- package/lib/models/FlowNode.js.map +0 -1
- package/lib/models/Job.js.map +0 -1
- package/lib/models/Workflow.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/lib/triggers/collection.js.map +0 -1
- package/lib/triggers/index.js.map +0 -1
- package/tsconfig.build.json +0 -9
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FlowNode.js","sourceRoot":"","sources":["../../src/models/FlowNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAKrD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK;CAiB/C","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport WorkflowModel from './Workflow';\n\n\nexport default class FlowNodeModel extends Model {\n declare static readonly database: Database;\n\n declare id: number;\n declare title: string;\n declare branchIndex: null | number;\n declare type: string;\n declare config: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstream: FlowNodeModel;\n declare downstream: FlowNodeModel;\n\n declare workflow?: WorkflowModel;\n declare getWorkflow: BelongsToGetAssociationMixin<WorkflowModel>;\n}\n"]}
|
package/esm/models/Job.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
import { BelongsToGetAssociationMixin } from 'sequelize';
|
|
3
|
-
import FlowNodeModel from './FlowNode';
|
|
4
|
-
export default class JobModel extends Model {
|
|
5
|
-
id: number;
|
|
6
|
-
status: number;
|
|
7
|
-
result: any;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
updatedAt: Date;
|
|
10
|
-
upstreamId: number;
|
|
11
|
-
upstream: JobModel;
|
|
12
|
-
nodeId: number;
|
|
13
|
-
node?: FlowNodeModel;
|
|
14
|
-
getNode: BelongsToGetAssociationMixin<FlowNodeModel>;
|
|
15
|
-
}
|
package/esm/models/Job.js
DELETED
package/esm/models/Job.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../src/models/Job.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI3C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,KAAK;CAc1C","sourcesContent":["import { Model } from '@nocobase/database';\nimport { BelongsToGetAssociationMixin } from 'sequelize';\nimport FlowNodeModel from './FlowNode';\n\nexport default class JobModel extends Model {\n declare id: number;\n declare status: number;\n declare result: any;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare upstreamId: number;\n declare upstream: JobModel;\n\n declare nodeId: number;\n declare node?: FlowNodeModel;\n declare getNode: BelongsToGetAssociationMixin<FlowNodeModel>;\n}"]}
|
package/esm/models/Workflow.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Database, Model } from '@nocobase/database';
|
|
2
|
-
import { HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';
|
|
3
|
-
import ExecutionModel from './Execution';
|
|
4
|
-
import FlowNodeModel from './FlowNode';
|
|
5
|
-
export default class WorkflowModel extends Model {
|
|
6
|
-
static database: Database;
|
|
7
|
-
id: number;
|
|
8
|
-
title: string;
|
|
9
|
-
enabled: boolean;
|
|
10
|
-
description?: string;
|
|
11
|
-
type: string;
|
|
12
|
-
config: any;
|
|
13
|
-
useTransaction: boolean;
|
|
14
|
-
executed: boolean;
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
updatedAt: Date;
|
|
17
|
-
nodes: FlowNodeModel[];
|
|
18
|
-
getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;
|
|
19
|
-
createNode: HasManyCreateAssociationMixin<FlowNodeModel>;
|
|
20
|
-
executions: ExecutionModel[];
|
|
21
|
-
countExecutions: HasManyCountAssociationsMixin;
|
|
22
|
-
getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;
|
|
23
|
-
createExecution: HasManyCreateAssociationMixin<ExecutionModel>;
|
|
24
|
-
static mount(): Promise<void>;
|
|
25
|
-
getHookId(): string;
|
|
26
|
-
getTransaction(options: any): any;
|
|
27
|
-
toggle(enable?: boolean): Promise<void>;
|
|
28
|
-
trigger(context: Object, options: any): Promise<ExecutionModel>;
|
|
29
|
-
}
|
package/esm/models/Workflow.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Model } from '@nocobase/database';
|
|
11
|
-
import triggers from '../triggers';
|
|
12
|
-
import { EXECUTION_STATUS } from '../constants';
|
|
13
|
-
export default class WorkflowModel extends Model {
|
|
14
|
-
static mount() {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const collection = this.database.getCollection('workflows');
|
|
17
|
-
const workflows = yield collection.repository.find({
|
|
18
|
-
filter: { enabled: true },
|
|
19
|
-
});
|
|
20
|
-
workflows.forEach((workflow) => {
|
|
21
|
-
workflow.toggle();
|
|
22
|
-
});
|
|
23
|
-
this.addHook('afterCreate', (model) => model.toggle());
|
|
24
|
-
this.addHook('afterUpdate', (model) => model.toggle());
|
|
25
|
-
this.addHook('afterDestroy', (model) => model.toggle(false));
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
getHookId() {
|
|
29
|
-
return `workflow-${this.get('id')}`;
|
|
30
|
-
}
|
|
31
|
-
getTransaction(options) {
|
|
32
|
-
if (!this.useTransaction) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return options.transaction && !options.transaction.finished
|
|
36
|
-
? options.transaction
|
|
37
|
-
: this.constructor.database.sequelize.transaction();
|
|
38
|
-
}
|
|
39
|
-
toggle(enable) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const type = this.get('type');
|
|
42
|
-
const { on, off } = triggers.get(type);
|
|
43
|
-
if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {
|
|
44
|
-
on.call(this, this.trigger.bind(this));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
off.call(this);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
trigger(context, options) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
// `null` means not to trigger
|
|
54
|
-
if (context === null) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const transaction = yield this.getTransaction(options);
|
|
58
|
-
if (this.useTransaction) {
|
|
59
|
-
const existed = yield this.countExecutions({
|
|
60
|
-
where: {
|
|
61
|
-
transaction: transaction.id
|
|
62
|
-
},
|
|
63
|
-
transaction
|
|
64
|
-
});
|
|
65
|
-
if (existed) {
|
|
66
|
-
console.warn(`workflow ${this.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const execution = yield this.createExecution({
|
|
71
|
-
context,
|
|
72
|
-
status: EXECUTION_STATUS.STARTED,
|
|
73
|
-
useTransaction: this.useTransaction,
|
|
74
|
-
transaction: transaction.id
|
|
75
|
-
}, { transaction });
|
|
76
|
-
execution.workflow = this;
|
|
77
|
-
yield execution.start({ transaction });
|
|
78
|
-
if (!this.executed) {
|
|
79
|
-
yield this.update({ executed: true }, { transaction });
|
|
80
|
-
}
|
|
81
|
-
if (transaction && (!options.transaction || options.transaction.finished)) {
|
|
82
|
-
yield transaction.commit();
|
|
83
|
-
}
|
|
84
|
-
return execution;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=Workflow.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Workflow.js","sourceRoot":"","sources":["../../src/models/Workflow.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,KAAK;I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,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;aACxD;YAED,IAAI,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;gBACzE,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;aAC5B;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;KAAA;CACF","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { HasManyCountAssociationsMixin, HasManyCreateAssociationMixin, HasManyGetAssociationsMixin } from 'sequelize';\n\nimport triggers from '../triggers';\nimport { EXECUTION_STATUS } from '../constants';\nimport ExecutionModel from './Execution';\nimport FlowNodeModel from './FlowNode';\n\nexport default class WorkflowModel extends Model {\n declare static database: Database;\n\n declare id: number;\n declare title: string;\n declare enabled: boolean;\n declare description?: string;\n declare type: string;\n declare config: any;\n declare useTransaction: boolean;\n declare executed: boolean;\n\n declare createdAt: Date;\n declare updatedAt: Date;\n\n declare nodes: FlowNodeModel[];\n declare getNodes: HasManyGetAssociationsMixin<FlowNodeModel>;\n declare createNode: HasManyCreateAssociationMixin<FlowNodeModel>;\n\n declare executions: ExecutionModel[];\n declare countExecutions: HasManyCountAssociationsMixin;\n declare getExecutions: HasManyGetAssociationsMixin<ExecutionModel>;\n declare createExecution: HasManyCreateAssociationMixin<ExecutionModel>;\n\n static async mount() {\n const collection = this.database.getCollection('workflows');\n const workflows = await collection.repository.find({\n filter: { enabled: true },\n });\n\n workflows.forEach((workflow: WorkflowModel) => {\n workflow.toggle();\n });\n\n this.addHook('afterCreate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterUpdate', (model: WorkflowModel) => model.toggle());\n this.addHook('afterDestroy', (model: WorkflowModel) => model.toggle(false));\n }\n\n getHookId() {\n return `workflow-${this.get('id')}`;\n }\n\n getTransaction(options) {\n if (!this.useTransaction) {\n return undefined;\n }\n\n return options.transaction && !options.transaction.finished\n ? options.transaction\n : (<typeof WorkflowModel>this.constructor).database.sequelize.transaction();\n }\n\n async toggle(enable?: boolean) {\n const type = this.get('type');\n const { on, off } = triggers.get(type);\n if (typeof enable !== 'undefined' ? enable : this.get('enabled')) {\n on.call(this, this.trigger.bind(this));\n } else {\n off.call(this);\n }\n }\n\n async trigger(context: Object, options) {\n // `null` means not to trigger\n if (context === null) {\n return;\n }\n\n const transaction = await this.getTransaction(options);\n\n if (this.useTransaction) {\n const existed = await this.countExecutions({\n where: {\n transaction: transaction.id\n },\n transaction\n });\n\n if (existed) {\n console.warn(`workflow ${this.id} has already been triggered in same execution (${transaction.id}), and newly triggering will be skipped.`);\n return;\n }\n }\n\n const execution = await this.createExecution({\n context,\n status: EXECUTION_STATUS.STARTED,\n useTransaction: this.useTransaction,\n transaction: transaction.id\n }, { transaction });\n\n execution.workflow = this;\n\n await execution.start({ transaction });\n\n if (!this.executed) {\n await this.update({ executed: true }, { transaction });\n }\n\n if (transaction && (!options.transaction || options.transaction.finished)) {\n await transaction.commit();\n }\n\n return execution;\n }\n}\n"]}
|
package/esm/server.d.ts
DELETED
package/esm/server.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import { Plugin } from '@nocobase/server';
|
|
12
|
-
import WorkflowModel from './models/Workflow';
|
|
13
|
-
import ExecutionModel from './models/Execution';
|
|
14
|
-
import actions from './actions';
|
|
15
|
-
export default class WorkflowPlugin extends Plugin {
|
|
16
|
-
load(options = {}) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const { db } = this.app;
|
|
19
|
-
db.registerModels({
|
|
20
|
-
WorkflowModel,
|
|
21
|
-
ExecutionModel,
|
|
22
|
-
});
|
|
23
|
-
yield db.import({
|
|
24
|
-
directory: path.resolve(__dirname, 'collections'),
|
|
25
|
-
});
|
|
26
|
-
actions(this.app);
|
|
27
|
-
// [Life Cycle]:
|
|
28
|
-
// * load all workflows in db
|
|
29
|
-
// * add all hooks for enabled workflows
|
|
30
|
-
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
31
|
-
this.app.on('beforeStart', () => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const { model } = db.getCollection('workflows');
|
|
33
|
-
yield model.mount();
|
|
34
|
-
}));
|
|
35
|
-
// [Life Cycle]: initialize all necessary seed data
|
|
36
|
-
this.app.on('db.init', () => __awaiter(this, void 0, void 0, function* () { }));
|
|
37
|
-
// const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);
|
|
38
|
-
// Automation.addHook('afterCreate', async (model: AutomationModel) => {
|
|
39
|
-
// model.get('enabled') && await model.loadJobs();
|
|
40
|
-
// });
|
|
41
|
-
// Automation.addHook('afterUpdate', async (model: AutomationModel) => {
|
|
42
|
-
// if (!model.changed('enabled' as any)) {
|
|
43
|
-
// return;
|
|
44
|
-
// }
|
|
45
|
-
// model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();
|
|
46
|
-
// });
|
|
47
|
-
// Automation.addHook('beforeDestroy', async (model: AutomationModel) => {
|
|
48
|
-
// await model.cancelJobs();
|
|
49
|
-
// });
|
|
50
|
-
// AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {
|
|
51
|
-
// await model.bootstrap();
|
|
52
|
-
// });
|
|
53
|
-
// AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {
|
|
54
|
-
// await model.cancel();
|
|
55
|
-
// });
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
getName() {
|
|
59
|
-
return this.getPackageName(__dirname);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=server.js.map
|
package/esm/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,aAAa,MAAM,mBAAmB,CAAC;AAC9C,OAAO,cAAc,MAAM,oBAAoB,CAAC;AAChD,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,MAAM;IAC1C,IAAI,CAAC,OAAO,GAAG,EAAE;;YACrB,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC;YAExB,EAAE,CAAC,cAAc,CAAC;gBAChB,aAAa;gBACb,cAAc;aACf,CAAC,CAAC;YAEH,MAAM,EAAE,CAAC,MAAM,CAAC;gBACd,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAClD,CAAC,CAAC;YAEH,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAElB,gBAAgB;YAChB,+BAA+B;YAC/B,0CAA0C;YAC1C,wFAAwF;YACxF,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,GAAS,EAAE;gBACpC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gBAChD,MAAO,KAA8B,CAAC,KAAK,EAAE,CAAC;YAChD,CAAC,CAAA,CAAC,CAAC;YAEH,mDAAmD;YACnD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAS,EAAE,gDAAE,CAAC,CAAA,CAAC,CAAC;YAEvC,+FAA+F;YAE/F,wEAAwE;YACxE,oDAAoD;YACpD,MAAM;YAEN,wEAAwE;YACxE,4CAA4C;YAC5C,cAAc;YACd,MAAM;YACN,8EAA8E;YAC9E,MAAM;YAEN,0EAA0E;YAC1E,8BAA8B;YAC9B,MAAM;YAEN,8EAA8E;YAC9E,6BAA6B;YAC7B,MAAM;YAEN,gFAAgF;YAChF,0BAA0B;YAC1B,MAAM;QACR,CAAC;KAAA;IAED,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import path from 'path';\n\nimport { Plugin } from '@nocobase/server';\n\nimport WorkflowModel from './models/Workflow';\nimport ExecutionModel from './models/Execution';\nimport actions from './actions';\n\nexport default class WorkflowPlugin extends Plugin {\n async load(options = {}) {\n const { db } = this.app;\n\n db.registerModels({\n WorkflowModel,\n ExecutionModel,\n });\n\n await db.import({\n directory: path.resolve(__dirname, 'collections'),\n });\n\n actions(this.app);\n\n // [Life Cycle]:\n // * load all workflows in db\n // * add all hooks for enabled workflows\n // * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks\n this.app.on('beforeStart', async () => {\n const { model } = db.getCollection('workflows');\n await (model as typeof WorkflowModel).mount();\n });\n\n // [Life Cycle]: initialize all necessary seed data\n this.app.on('db.init', async () => {});\n\n // const [Automation, AutomationJob] = database.getModels(['automations', 'automations_jobs']);\n\n // Automation.addHook('afterCreate', async (model: AutomationModel) => {\n // model.get('enabled') && await model.loadJobs();\n // });\n\n // Automation.addHook('afterUpdate', async (model: AutomationModel) => {\n // if (!model.changed('enabled' as any)) {\n // return;\n // }\n // model.get('enabled') ? await model.loadJobs() : await model.cancelJobs();\n // });\n\n // Automation.addHook('beforeDestroy', async (model: AutomationModel) => {\n // await model.cancelJobs();\n // });\n\n // AutomationJob.addHook('afterCreate', async (model: AutomationJobModel) => {\n // await model.bootstrap();\n // });\n\n // AutomationJob.addHook('beforeDestroy', async (model: AutomationJobModel) => {\n // await model.cancel();\n // });\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import WorkflowModel from "../models/Workflow";
|
|
2
|
-
export interface ModelChangeTriggerConfig {
|
|
3
|
-
collection: string;
|
|
4
|
-
mode: number;
|
|
5
|
-
condition: any;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: {
|
|
8
|
-
name: string;
|
|
9
|
-
on(this: WorkflowModel, callback: Function): void;
|
|
10
|
-
off(this: WorkflowModel): void;
|
|
11
|
-
};
|
|
12
|
-
export default _default;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const MODE_BITMAP = {
|
|
2
|
-
CREATE: 1,
|
|
3
|
-
UPDATE: 2,
|
|
4
|
-
DESTROY: 4
|
|
5
|
-
};
|
|
6
|
-
const MODE_BITMAP_EVENTS = new Map();
|
|
7
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.CREATE, 'afterCreate');
|
|
8
|
-
MODE_BITMAP_EVENTS.set(MODE_BITMAP.UPDATE, 'afterUpdate');
|
|
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
|
-
}
|
|
26
|
-
export default {
|
|
27
|
-
name: 'collection',
|
|
28
|
-
on(callback) {
|
|
29
|
-
var _a;
|
|
30
|
-
const { database } = this.constructor;
|
|
31
|
-
const { collection, mode } = this.config;
|
|
32
|
-
const Collection = database.getCollection(collection);
|
|
33
|
-
if (!Collection) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
37
|
-
if (mode & key) {
|
|
38
|
-
if (!((_a = Collection.model.options.hooks[event]) === null || _a === void 0 ? void 0 : _a.find(item => item.name && item.name === this.getHookId()))) {
|
|
39
|
-
Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
Collection.model.removeHook(event, this.getHookId());
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
off() {
|
|
48
|
-
const { database } = this.constructor;
|
|
49
|
-
const { collection, mode } = this.config;
|
|
50
|
-
const Collection = database.getCollection(collection);
|
|
51
|
-
if (!Collection) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {
|
|
55
|
-
if (mode & key) {
|
|
56
|
-
Collection.model.removeHook(event, this.getHookId());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=collection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"collection.js","sourceRoot":"","sources":["../../src/triggers/collection.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,IAA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YACrD,IAAI,IAAI,GAAG,GAAG,EAAE;gBACd,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,0CAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA,EAAE;oBACrG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;iBACrF;aACF;iBAAM;gBACL,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;aACtD;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: 'collection',\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\n for (let [key, event] of MODE_BITMAP_EVENTS.entries()) {\n if (mode & key) {\n if (!Collection.model.options.hooks[event]?.find(item => item.name && item.name === this.getHookId())) {\n Collection.model.addHook(event, this.getHookId(), bindHandler.call(this, callback));\n }\n } else {\n Collection.model.removeHook(event, this.getHookId());\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/esm/triggers/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Registry } from '@nocobase/utils';
|
|
2
|
-
import WorkflowModel from '../models/Workflow';
|
|
3
|
-
export interface Trigger {
|
|
4
|
-
name: string;
|
|
5
|
-
on(this: WorkflowModel, callback: Function): void;
|
|
6
|
-
off(this: WorkflowModel): void;
|
|
7
|
-
}
|
|
8
|
-
export declare const triggers: Registry<Trigger>;
|
|
9
|
-
export default triggers;
|
package/esm/triggers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/triggers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,kBAAkB,MAAM,cAAc,CAAC;AAQ9C,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAW,CAAC;AAEhD,eAAe,QAAQ,CAAC;AAExB,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC","sourcesContent":["import { Registry } from '@nocobase/utils';\nimport WorkflowModel from '../models/Workflow';\nimport collectionlTrigger from './collection';\n\nexport interface Trigger {\n name: string;\n on(this: WorkflowModel, callback: Function): void;\n off(this: WorkflowModel): void;\n}\n\nexport const triggers = new Registry<Trigger>();\n\nexport default triggers;\n\ntriggers.register(collectionlTrigger.name, collectionlTrigger);\n"]}
|
package/lib/actions/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AACzC,+CAAiC;AAEjC,SAAS,IAAI,CAAC,IAAI,EAAE,GAAG;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iCAC3C,MAAM,KACT,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAC5B,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AAED,mBAAwB,GAAG;IACzB,GAAG,CAAC,OAAO,+CACN,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAC5B,IAAI,CAAC,iBAAiB,EAAE;QACzB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,GACC,IAAI,CAAC,YAAY,EAAE;QACpB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,EACF,CAAC;AACL,CAAC;AAXD,4BAWC","sourcesContent":["import * as workflows from './workflows';\nimport * as nodes from './nodes';\n\nfunction make(name, mod) {\n return Object.keys(mod).reduce((result, key) => ({\n ...result,\n [`${name}:${key}`]: mod[key]\n }), {})\n}\n\nexport default function(app) {\n app.actions({\n ...make('workflows', workflows),\n ...make('workflows.nodes', {\n create: nodes.create,\n destroy: nodes.destroy\n }),\n ...make('flow_nodes', {\n update: nodes.update\n })\n });\n}\n"]}
|
package/lib/actions/nodes.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/actions/nodes.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAA+B;AAC/B,+CAAmD;AAInD,SAAsB,MAAM,CAAC,OAAgB,EAAE,IAAI;;QACjD,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;QACvB,MAAM,UAAU,GAAG,eAAK,CAAC,uBAAuB,CAAC,OAAO,CAA+B,CAAC;QACxF,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAErH,OAAO,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAM,WAAW,EAAC,EAAE;YAChE,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,WAAW,CAAkB,CAAC;YAC/E,IAAI,QAAQ,CAAC,QAAQ,EAAE;gBACrB,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,gDAAgD,CAAC,CAAC;aACtE;YAED,MAAM,QAAQ,GAAG,MAAM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","sourcesContent":["import { Op } from 'sequelize';\nimport { Context, utils } from '@nocobase/actions';\nimport { MultipleRelationRepository } from '@nocobase/database';\nimport WorkflowModel from '../models/Workflow';\n\nexport async function create(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context) as MultipleRelationRepository;\n const { whitelist, blacklist, updateAssociationValues, values, associatedIndex: workflowId } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const workflow = await repository.getSourceModel(transaction) as WorkflowModel;\n if (workflow.executed) {\n context.throw(400, 'Node could not be created in executed workflow');\n }\n\n const instance = await repository.create({\n values,\n whitelist,\n blacklist,\n updateAssociationValues,\n context,\n transaction\n });\n\n if (!instance.upstreamId) {\n const previousHead = await repository.findOne({\n filter: {\n id: {\n $ne: instance.id\n },\n upstreamId: null\n },\n transaction\n });\n if (previousHead) {\n await previousHead.setUpstream(instance, { transaction });\n await instance.setDownstream(previousHead, { transaction });\n instance.set('downstream', previousHead);\n }\n return instance;\n }\n\n const upstream = await instance.getUpstream({ transaction });\n\n if (instance.branchIndex == null) {\n const downstream = await upstream.getDownstream({ transaction });\n\n if (downstream) {\n await downstream.setUpstream(instance, { transaction });\n await instance.setDownstream(downstream, { transaction });\n instance.set('downstream', downstream);\n }\n\n await upstream.update({\n downstreamId: instance.id\n }, { transaction });\n\n upstream.set('downstream', instance);\n } else {\n const [downstream] = await upstream.getBranches({\n where: {\n id: {\n [Op.ne]: instance.id\n },\n branchIndex: instance.branchIndex\n },\n transaction\n });\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.id,\n branchIndex: null\n }, { transaction });\n await instance.setDownstream(downstream, { transaction });\n instance.set('downstream', downstream);\n }\n }\n\n instance.set('upstream', upstream);\n });\n\n await next();\n}\n\nfunction searchBranchNodes(nodes, from): any[] {\n const branchHeads = nodes\n .filter((item: any) => item.upstreamId === from.id && item.branchIndex != null);\n return branchHeads.reduce((flatten: any[], head) => flatten.concat(searchBranchDownstreams(nodes, head)), []) as any[];\n}\n\nfunction searchBranchDownstreams(nodes, from) {\n let result = [];\n for (let search = from; search; search = search.downstream) {\n result = [...result, search, ...searchBranchNodes(nodes, search)];\n }\n return result;\n}\n\nexport async function destroy(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context) as MultipleRelationRepository;\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const workflow = await repository.getSourceModel(transaction) as WorkflowModel;\n if (workflow.executed) {\n context.throw(400, 'Nodes in executed workflow could not be deleted');\n }\n\n const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];\n const instance = await repository.findOne({\n filterByTk,\n fields: [...fields, 'workflowId'],\n appends: ['upstream', 'downstream'],\n transaction\n });\n const { upstream, downstream } = instance.get();\n\n if (upstream && upstream.downstreamId === instance.id) {\n await upstream.update({\n downstreamId: instance.downstreamId\n }, { transaction });\n }\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.upstreamId,\n branchIndex: instance.branchIndex\n }, { transaction });\n }\n\n const nodes = await repository.find({\n filter: {\n workflowId: instance.workflowId\n },\n fields,\n transaction\n });\n const nodesMap = new Map();\n // make map\n nodes.forEach(item => {\n nodesMap.set(item.id, item);\n });\n // overwrite\n nodesMap.set(instance.id, instance);\n // make linked list\n nodes.forEach(item => {\n if (item.upstreamId) {\n item.upstream = nodesMap.get(item.upstreamId);\n }\n if (item.downstreamId) {\n item.downstream = nodesMap.get(item.downstreamId);\n }\n });\n\n const branchNodes = searchBranchNodes(nodes, instance);\n\n await repository.destroy({\n filterByTk: [instance.id, ...branchNodes.map(item => item.id)],\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n\nexport async function update(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;\n context.body = await db.sequelize.transaction(async transaction => {\n // TODO(optimize): duplicated instance query\n const { workflow } = await repository.findOne({\n filterByTk,\n appends: ['workflow.executed'],\n transaction\n });\n if (workflow.executed) {\n context.throw(400, 'Nodes in executed workflow could not be reconfigured');\n }\n\n return repository.update({\n filterByTk,\n values,\n whitelist,\n blacklist,\n filter,\n updateAssociationValues,\n context,\n transaction\n });\n });\n\n await next();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/actions/workflows.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAEA,+CAAmD;AACnD,iDAAwC;AAIxC,SAAsB,MAAM,CAAC,OAAgB,EAAE,IAAI;;QACjD,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;QACvB,MAAM,UAAU,GAAG,eAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAE5G,OAAO,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAM,WAAW,EAAC,EAAE;YAChE,MAAM,MAAM,GAA6C,EAAE,CAAC;YAE5D,IAAI,MAAM,CAAC,OAAO,EAAE;gBAClB,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;gBACtB,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;aACxB;YAED,IAAI,MAAM,CAAC,OAAO,EAAE;gBAClB,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;gBACvB,MAAM,UAAU,CAAC,MAAM,CAAC;oBACtB,MAAM,EAAE;wBACN,GAAG,EAAE,MAAM,CAAC,GAAG;wBACf,EAAE,EAAE;4BACF,CAAC,aAAE,CAAC,EAAE,CAAC,EAAE,UAAU;yBACpB;qBACF;oBACD,MAAM,EAAE,MAAM;oBACd,OAAO;oBACP,WAAW;iBACZ,CAAC,CAAC;aACJ;YAED,MAAM,QAAQ,GAAG,MAAM,UAAU,C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,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;qBAChD,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;iBACrB;;;;;;;;;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AA3DD,8BA2DC","sourcesContent":["import parse from 'json-templates';\n\nimport { Context, utils } from '@nocobase/actions';\nimport { Op } from '@nocobase/database';\n\n\n\nexport async function update(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk, values, whitelist, blacklist, filter, updateAssociationValues } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const others: { enabled?: boolean, current?: boolean } = {};\n\n if (values.enabled) {\n values.current = true;\n others.enabled = false;\n }\n\n if (values.current) {\n others.current = false;\n await repository.update({\n filter: {\n key: values.key,\n id: {\n [Op.ne]: filterByTk\n }\n },\n values: others,\n context,\n transaction\n });\n }\n\n const instance = await repository.update({\n filterByTk,\n values,\n whitelist,\n blacklist,\n filter,\n updateAssociationValues,\n context,\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n\nfunction typeOf(value) {\n if (Array.isArray(value)) {\n return 'array';\n } else if (value instanceof Date) {\n return 'date';\n } else if (value === null) {\n return 'null';\n }\n\n return typeof value;\n}\n\nfunction migrateConfig(config, oldToNew) {\n function migrate(value) {\n switch (typeOf(value)) {\n case 'object':\n return Object.keys(value).reduce((result, key) => ({ ...result, [key]: migrate(value[key]) }), {});\n case 'array':\n return value.map(item => migrate(item));\n case 'string':\n return value\n .replace(\n /(\\{\\{\\$jobsMapByNodeId\\.)(\\d+)/,\n (_, prefix, id) => `${prefix}${oldToNew.get(Number.parseInt(id, 10)).id}`\n );\n default:\n return value;\n }\n }\n\n return migrate(config);\n}\n\nexport async function duplicate(context: Context, next) {\n const { db } = context;\n const repository = utils.getRepositoryFromParams(context);\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const origin = await repository.findOne({\n filterByTk,\n appends: ['nodes'],\n context,\n transaction\n });\n\n const instance = await repository.create({\n values: {\n key: origin.key,\n title: origin.title,\n description: origin.description,\n type: origin.type,\n config: origin.config\n },\n transaction\n });\n\n const originalNodesMap = new Map();\n origin.nodes.forEach((node) => {\n originalNodesMap.set(node.id, node);\n });\n\n const oldToNew = new Map();\n const newToOld = new Map();\n for await (const node of origin.nodes) {\n const newNode = await instance.createNode({\n type: node.type,\n config: node.config,\n title: node.title,\n branchIndex: node.branchIndex\n }, { transaction });\n // NOTE: keep original node references for later replacement\n oldToNew.set(node.id, newNode);\n newToOld.set(newNode.id, node);\n }\n\n for await (const [oldId, newNode] of oldToNew.entries()) {\n const oldNode = originalNodesMap.get(oldId);\n const newUpstream = oldNode.upstreamId ? oldToNew.get(oldNode.upstreamId) : null;\n const newDownstream = oldNode.downstreamId ? oldToNew.get(oldNode.downstreamId) : null;\n\n await newNode.update({\n upstreamId: newUpstream?.id ?? null,\n downstreamId: newDownstream?.id ?? null,\n config: migrateConfig(oldNode.config, oldToNew)\n }, { transaction });\n }\n\n return instance;\n });\n\n await next();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
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,g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C,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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executions.js","sourceRoot":"","sources":["../../src/collections/executions.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,OAAO;SACf;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,MAAM;YACb,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,YAAY,EAAE,IAAI;SACnB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,OAAO;SACf;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;SACZ;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'executions',\n model: 'ExecutionModel',\n title: '执行流程',\n fields: [\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'workflow',\n title: '所属工作流'\n },\n {\n type: 'boolean',\n name: 'useTransaction',\n title: '使用事务',\n defaultValue: false\n },\n {\n type: 'uuid',\n name: 'transaction',\n defaultValue: null\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'jobs',\n title: '流程记录'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'context',\n title: '上下文数据'\n },\n {\n interface: 'select',\n type: 'integer',\n name: 'status',\n title: '状态'\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flow_nodes.js","sourceRoot":"","sources":["../../src/collections/flow_nodes.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,YAAY;IAClB,0BAA0B;IAC1B,KAAK,EAAE,gBAAgB;IACvB,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,IAAI;SACZ;QACD,4BAA4B;QAC5B;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;SAClB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,YAAY;SACrB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,YAAY;YACpB,SAAS,EAAE,IAAI;YACf,UAAU,EAAE,YAAY;SACzB;QACD,mFAAmF;QACnF,mFAAmF;QACnF,6CAA6C;QAC7C;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,cAAc;SACtB;QACD,qBAAqB;QACrB,6CAA6C;QAC7C,iDAAiD;QACjD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,YAAY;SACrB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;YACX,YAAY,EAAE,EAAE;SACjB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'flow_nodes',\n // model: 'FlowNodeModel',\n title: 'Workflow Nodes',\n fields: [\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '名称'\n },\n // which workflow belongs to\n {\n interface: 'linkTo',\n name: 'workflow',\n type: 'belongsTo',\n },\n {\n interface: 'linkTo',\n name: 'upstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'linkTo',\n name: 'branches',\n type: 'hasMany',\n target: 'flow_nodes',\n sourceKey: 'id',\n foreignKey: 'upstreamId',\n },\n // only works when upstream node is branching type, such as condition and parallel.\n // put here because the design of flow-links model is not really necessary for now.\n // or it should be put into flow-links model.\n {\n interface: 'select',\n name: 'branchIndex',\n type: 'integer',\n title: 'branch index'\n },\n // Note: for reasons:\n // 1. redirect type node to solve cycle flow.\n // 2. recognize as real next node after branches.\n {\n interface: 'linkTo',\n name: 'downstream',\n type: 'belongsTo',\n target: 'flow_nodes'\n },\n {\n interface: 'select',\n type: 'string',\n name: 'type',\n title: '类型'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'config',\n title: '配置',\n defaultValue: {}\n }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.js","sourceRoot":"","sources":["../../src/collections/jobs.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,MAAM;SACd;QACD,gCAAgC;QAChC;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;SACd;QACD,qEAAqE;QACrE,IAAI;QACJ,uBAAuB;QACvB,mBAAmB;QACnB,0BAA0B;QAC1B,2BAA2B;QAC3B,IAAI;KACL;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'jobs',\n title: '流程记录',\n fields: [\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'execution',\n title: '所属流程'\n },\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'node',\n target: 'flow_nodes',\n title: '所属节点'\n },\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'upstream',\n target: 'jobs',\n title: '上游记录'\n },\n // pending / resolved / rejected\n {\n interface: 'status',\n type: 'integer',\n name: 'status',\n title: '处理状态'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'result',\n title: '处理结果'\n },\n // TODO: possibly need node snapshot in case if node has been changed\n // {\n // interface: 'json',\n // type: 'jsonb',\n // name: 'nodeSnapshot',\n // title: 'node snapshot'\n // }\n ]\n} as CollectionOptions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/collections/workflows.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,WAAW;IACjB,KAAK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AAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,WAAW;YACnB,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,KAAK;YAChB,mEAAmE;YACnE,WAAW,EAAE,KAAK;SACnB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'workflows',\n model: 'WorkflowModel',\n title: '自动化',\n fields: [\n {\n name: 'key',\n type: 'uid'\n },\n {\n interface: 'string',\n type: 'string',\n name: 'title',\n title: '工作流名称',\n required: true\n },\n {\n interface: 'boolean',\n type: 'boolean',\n name: 'enabled',\n title: '启用',\n defaultValue: false\n },\n {\n interface: 'textarea',\n type: 'text',\n name: 'description',\n title: '描述'\n },\n {\n interface: 'select',\n type: 'string',\n title: '触发方式',\n name: 'type',\n required: true\n },\n {\n interface: 'json',\n type: 'jsonb',\n title: '触发配置',\n name: 'config',\n required: true,\n defaultValue: {}\n },\n {\n interface: 'boolean',\n type: 'boolean',\n title: '使用事务',\n name: 'useTransaction',\n defaultValue: true\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'nodes',\n target: 'flow_nodes',\n title: '流程节点'\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'executions',\n target: 'executions',\n title: '触发执行'\n },\n {\n type: 'boolean',\n name: 'executed',\n defaultValue: false\n },\n {\n type: 'boolean',\n name: 'current',\n defaultValue: false\n },\n {\n type: 'hasMany',\n name: 'revisions',\n target: 'workflows',\n foreignKey: 'key',\n sourceKey: 'key',\n // NOTE: no constraints needed here because tricky self-referencing\n constraints: false\n }\n ]\n} as CollectionOptions;\n"]}
|
package/lib/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG;IAC9B,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEW,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;CACZ,CAAC","sourcesContent":["export const EXECUTION_STATUS = {\n STARTED: 0,\n RESOLVED: 1,\n REJECTED: -1,\n CANCELLED: -2\n};\n\nexport const JOB_STATUS = {\n PENDING: 0,\n RESOLVED: 1,\n REJECTED: -1,\n CANCELLED: -2\n};\n\nexport const BRANCH_INDEX = {\n DEFAULT: null,\n ON_TRUE: 1,\n ON_FALSE: 0\n};\n"]}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,gDAA8B;AAC9B,6CAA2B;AAC3B,iDAA+B;AAE/B,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export * from './constants';\nexport * from './calculators';\nexport * from './triggers';\nexport * from './instructions';\n\nexport { default } from './server';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculation.js","sourceRoot":"","sources":["../../src/instructions/calculation.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAE1C,gDAA2C;AAE3C,kBAAkB;AAClB,0BAA0B;AAC1B,gBAAgB;AAChB,QAAQ;AACR,6BAA6B;AAC7B,mBAAmB;AACnB,6BAA6B;AAC7B,iDAAiD;AACjD,UAAU;AACV,SAAS;AACT,QAAQ;AACR,0BAA0B;AAC1B,yCAAyC;AACzC,SAAS;AACT,QAAQ;AACR,yBAAyB;AACzB,mBAAmB;AACnB,6BAA6B;AAC7B,UAAU;AACV,SAAS;AACT,QAAQ;AACR,0BAA0B;AAC1B,iBAAiB;AACjB,QAAQ;AACR,MAAM;AACN,IAAI;AAEJ,kBAAe;IACP,GAAG,CAAsB,OAAO,EAAE,SAAS;;YAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;YAE1C,MAAM,MAAM,GAAG,WAAW;gBACxB,CAAC,CAAC,IAAA,uBAAS,EAAC;oBACV,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,SAAS,CAAC,cAAc,CAAC,WAAW,CAAC;iBAC/C,EAAE,OAAO,EAAE,SAAS,CAAC;gBACtB,CAAC,CAAC,IAAI,CAAC;YAET,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\nimport { calculate } from \"../calculators\";\n\n// @calculation: {\n// calculator: 'concat',\n// operands: [\n// {\n// type: 'calculation',\n// options: {\n// calculator: 'add',\n// operands: [{ value: 1 }, { value: 2 }]\n// }\n// },\n// {\n// type: 'constant',\n// value: '{{$context.data.title}}'\n// },\n// {\n// type: 'context',\n// options: {\n// path: 'data.title'\n// }\n// },\n// {\n// type: 'constant',\n// value: 1\n// }\n// ]\n// }\n\nexport default {\n async run(this: FlowNodeModel, prevJob, execution) {\n const { calculation } = this.config || {};\n\n const result = calculation\n ? calculate({\n type: '$calculation',\n options: execution.getParsedValue(calculation)\n }, prevJob, execution)\n : null;\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../src/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AAK,sBAAU,CAAC,QAAQ,EAAE;gBAC5C,qCAAqC;gBACrC,OAAO,SAAS,CAAC;aAClB;YAED,sDAAsD;YACtD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;KAAA;CACF,CAAC","sourcesContent":["import calculators, { calculate, Operand } from \"../calculators\";\nimport { JOB_STATUS } from \"../constants\";\n\ntype BaseCalculation = {\n not?: boolean;\n};\n\ntype SingleCalculation = BaseCalculation & {\n calculation: string;\n operands?: Operand[];\n};\n\ntype GroupCalculationOptions = {\n type: 'and' | 'or';\n calculations: Calculation[]\n};\n\ntype GroupCalculation = BaseCalculation & {\n group: GroupCalculationOptions\n};\n\n// TODO(type)\ntype Calculation = SingleCalculation | GroupCalculation;\n\n// @calculation: {\n// not: false,\n// group: {\n// type: 'and',\n// calculations: [\n// {\n// calculator: 'time.equal',\n// operands: [{ value: '{{$context.time}}' }, { value: '{{$fn.now}}' }]\n// },\n// {\n// calculator: 'value.equal',\n// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]\n// },\n// {\n// group: {\n// type: 'or',\n// calculations: [\n// {\n// calculator: 'value.equal',\n// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]\n// }\n// ]\n// }\n// }\n// ]\n// }\n// }\nfunction logicCalculate(calculation, input, execution) {\n if (!calculation) {\n return true;\n }\n\n const { not, group } = calculation;\n let result;\n if (group) {\n const method = group.type === 'and' ? 'every' : 'some';\n result = group.calculations[method](item => logicCalculate(item, input, execution));\n } else {\n const args = calculation.operands.map(operand => calculate(operand, input, execution));\n const fn = calculators.get(calculation.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${calculation.calculator}\"`);\n }\n result = fn(...args);\n }\n\n return not ? !result : result;\n}\n\n\nexport default {\n async run(this, prevJob, execution) {\n // TODO(optimize): loading of jobs could be reduced and turned into incrementally in execution\n // const jobs = await execution.getJobs();\n const { calculation, rejectOnFalse } = this.config || {};\n const result = logicCalculate(calculation, prevJob, execution);\n\n if (!result && rejectOnFalse) {\n return {\n status: JOB_STATUS.REJECTED,\n result\n };\n }\n\n const job = {\n status: JOB_STATUS.RESOLVED,\n result,\n // TODO(optimize): try unify the building of job\n nodeId: this.id,\n upstreamId: prevJob && prevJob.id || null\n };\n\n const branchNode = execution.nodes\n .find(item => item.upstream === this && Boolean(item.branchIndex) === result);\n\n if (!branchNode) {\n return job;\n }\n\n const savedJob = await execution.saveJob(job);\n\n return execution.run(branchNode, savedJob);\n },\n\n async resume(this, branchJob, execution) {\n if (branchJob.status === JOB_STATUS.RESOLVED) {\n // return to continue this.downstream\n return branchJob;\n }\n\n // pass control to upper scope by ending current scope\n return execution.end(this, branchJob);\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/instructions/create.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,8CAA8C;gBAC9C,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE;gBACpB,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.create({\n ...options,\n transaction: execution.tx\n });\n\n return {\n // NOTE: get() for non-proxied instance (#380)\n result: result.get(),\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/instructions/destroy.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,iCAC5B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.destroy({\n ...options,\n transaction: execution.tx\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instructions/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAK3C,sDAA8B;AAC9B,gEAAwC;AACxC,4DAAoC;AACpC,0DAAkC;AAClC,oDAA4B;AAC5B,sDAA8B;AAC9B,sDAA8B;AAC9B,wDAAgC;AA+BnB,QAAA,YAAY,GAAG,IAAI,gBAAQ,EAAe,CAAC;AAExD,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,aAAa,EAAE,qBAAW,CAAC,CAAC;AAClD,oBAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,mBAAS,CAAC,CAAC;AAC9C,oBAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,kBAAQ,CAAC,CAAC;AAC5C,oBAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAK,CAAC,CAAC;AACtC,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAM,CAAC,CAAC;AACxC,oBAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,iBAAO,CAAC,CAAC;AAE1C,kBAAe,oBAAY,CAAC","sourcesContent":["import { Registry } from '@nocobase/utils';\n\nimport ExecutionModel from '../models/Execution';\nimport FlowNodeModel from '../models/FlowNode';\n\nimport prompt from './prompt';\nimport calculation from './calculation';\nimport condition from './condition';\nimport parallel from './parallel';\nimport query from './query';\nimport create from './create';\nimport update from './update';\nimport destroy from './destroy';\n\nexport interface Job {\n status: number;\n result?: unknown;\n [key: string]: unknown;\n}\n\nexport type InstructionResult = Job | Promise<Job>;\n\n// what should a instruction do?\n// - base on input and context, do any calculations or system call (io), and produce a result or pending.\nexport interface Instruction {\n run(\n this: FlowNodeModel,\n // what should input to be?\n // - just use previously output result for convenience?\n input: any,\n // what should context to be?\n // - could be the workflow execution object (containing context data)\n execution: ExecutionModel\n ): InstructionResult;\n\n // for start node in main flow (or branch) to resume when manual sub branch triggered\n resume?(\n this: FlowNodeModel,\n input: any,\n execution: ExecutionModel\n ): InstructionResult\n}\n\nexport const instructions = new Registry<Instruction>();\n\ninstructions.register('prompt', prompt);\ninstructions.register('calculation', calculation);\ninstructions.register('condition', condition);\ninstructions.register('parallel', parallel);\ninstructions.register('query', query);\ninstructions.register('create', create);\ninstructions.register('update', update);\ninstructions.register('destroy', destroy);\n\nexport default instructions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sourceRoot":"","sources":["../../src/instructions/parallel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0C;AAK7B,QAAA,aAAa,GAAG;IAC3B,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,aAAa,GAAG;IACpB,CAAC,qBAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,sBAAU,CAAC,QAAQ,CAAC,EAAE;YAC3D,OAAO,sBAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,sBAAU,CAAC,QAAQ,CAAC,EAAE;YAC5D,OAAO,sBAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,OAAO,sBAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,CAAC,qBAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,sBAAU,CAAC,QAAQ,CAAC;YAC5D,CAAC,CAAC,sBAAU,CAAC,QAAQ;YACrB,CAAC,CAAC,CACA,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MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;aACvC,CAAC,CAAC;YAEH,IAAI,GAAG,CAAC,MAAM,KAAK,sBAAU,CAAC,OAAO,EAAE;gBACrC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC9C,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACjC;YAED,OAAO,GAAG,CAAC;QACb,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport ExecutionModel from \"../models/Execution\";\nimport FlowNodeModel from \"../models/FlowNode\";\nimport JobModel from \"../models/Job\";\n\nexport const PARALLEL_MODE = {\n ALL: 'all',\n ANY: 'any',\n RACE: 'race'\n} as const;\n\nconst StatusGetters = {\n [PARALLEL_MODE.ALL](result) {\n if (result.some(j => j && j.status === JOB_STATUS.REJECTED)) {\n return JOB_STATUS.REJECTED;\n }\n if (result.every(j => j && j.status === JOB_STATUS.RESOLVED)) {\n return JOB_STATUS.RESOLVED;\n }\n return JOB_STATUS.PENDING;\n },\n [PARALLEL_MODE.ANY](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.PENDING)\n ? JOB_STATUS.PENDING\n : JOB_STATUS.REJECTED\n )\n },\n [PARALLEL_MODE.RACE](result) {\n return result.some(j => j && j.status === JOB_STATUS.RESOLVED)\n ? JOB_STATUS.RESOLVED\n : (\n result.some(j => j && j.status === JOB_STATUS.REJECTED)\n ? JOB_STATUS.REJECTED\n : JOB_STATUS.PENDING\n )\n }\n};\n\nexport default {\n async run(this: FlowNodeModel, prevJob: JobModel, execution: ExecutionModel) {\n const branches = execution.nodes\n .filter(item => item.upstream === this && item.branchIndex !== null)\n .sort((a, b) => a.branchIndex - b.branchIndex);\n\n const job = await execution.saveJob({\n status: JOB_STATUS.PENDING,\n result: Array(branches.length).fill(null),\n nodeId: this.id,\n upstreamId: prevJob?.id ?? null\n });\n\n // NOTE:\n // use `reduce` but not `Promise.all` here to avoid racing manupulating db.\n // for users, this is almost equivalent to `Promise.all`,\n // because of the delay is not significant sensible.\n // another better aspect of this is, it could handle sequenced branches in future.\n await branches.reduce((promise: Promise<any>, branch) => promise.then(() => execution.run(branch, job)), Promise.resolve());\n\n return execution.end(this, job);\n },\n\n async resume(this, branchJob, execution: ExecutionModel) {\n const job = execution.findBranchParentJob(branchJob, this);\n\n const { result, status } = job;\n // if parallel has been done (resolved / rejected), do not care newly executed branch jobs.\n if (status !== JOB_STATUS.PENDING) {\n return null;\n }\n\n // find the index of the node which start the branch\n const jobNode = execution.nodesMap.get(branchJob.nodeId);\n const { branchIndex } = execution.findBranchStartNode(jobNode);\n const { mode = PARALLEL_MODE.ALL } = this.config || {};\n\n const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];\n job.set({\n result: newResult,\n status: StatusGetters[mode](newResult)\n });\n\n if (job.status === JOB_STATUS.PENDING) {\n await job.save({ transaction: execution.tx });\n return execution.end(this, job);\n }\n\n return job;\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/instructions/prompt.ts"],"names":[],"mappings":";;AAAA,4CAA0C;AAE1C,kBAAe;IACb,GAAG,CAAO,KAAK,EAAE,SAAS;QACxB,OAAO;YACL,MAAM,EAAE,sBAAU,CAAC,OAAO;SAC3B,CAAC;IACJ,CAAC;IAED,MAAM,CAAO,GAAG,EAAE,SAAS;QACzB,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,sBAAU,CAAC,QAAQ,CAAC,CAAC;QACvC,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\n\nexport default {\n run(this, input, execution) {\n return {\n status: JOB_STATUS.PENDING\n };\n },\n\n resume(this, job, execution) {\n job.set('status', JOB_STATUS.RESOLVED);\n return job;\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/instructions/query.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAG1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAS;;YAC7C,MAAM,EACJ,UAAU,EACV,QAAQ,EACR,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,kCAC/D,OAAO;gBACV,kFAAkF;gBAClF,mEAAmE;gBACnE,kEAAkE;gBAClE,GAAG,EAAE,IAAI,EACT,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAC","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution) {\n const {\n collection,\n multiple,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await (multiple ? repo.find : repo.findOne).call(repo, {\n ...options,\n // NOTE: `raw` to avoid getting undefined value from Proxied model instance (#380)\n // e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false\n // so the properties can not be get by json-templates(object-path)\n raw: true,\n transaction: execution.tx\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/instructions/update.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA0C;AAI1C,kBAAe;IACP,GAAG,CAAsB,KAAK,EAAE,SAAyB;;YAC7D,MAAM,EACJ,UAAU,EACV,QAAQ,GAAG,KAAK,EAChB,MAAM,GAAG,EAAE,EACZ,GAAG,IAAI,CAAC,MAAM,CAAC;YAEhB,MAAM,IAAI,GAA0B,IAAI,CAAC,WAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACzF,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,iCAC3B,OAAO,KACV,WAAW,EAAE,SAAS,CAAC,EAAE,IACzB,CAAC;YAEH,OAAO;gBACL,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;gBAC/C,MAAM,EAAE,sBAAU,CAAC,QAAQ;aAC5B,CAAC;QACJ,CAAC;KAAA;CACF,CAAA","sourcesContent":["import { JOB_STATUS } from \"../constants\";\nimport ExecutionModel from \"../models/Execution\";\nimport FlowNodeModel from \"../models/FlowNode\";\n\nexport default {\n async run(this: FlowNodeModel, input, execution: ExecutionModel) {\n const {\n collection,\n multiple = false,\n params = {}\n } = this.config;\n\n const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);\n const options = execution.getParsedValue(params);\n const result = await repo.update({\n ...options,\n transaction: execution.tx\n });\n\n return {\n result: multiple ? result : (result[0] || null),\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|