@nocobase/plugin-workflow 0.7.0-alpha.6 → 0.7.0-alpha.60
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.d.ts +3 -1
- package/lib/actions/index.js +33 -26
- package/{esm/actions/flow_nodes.d.ts → lib/actions/nodes.d.ts} +1 -0
- package/lib/actions/nodes.js +321 -0
- package/lib/actions/workflows.d.ts +3 -0
- package/lib/actions/workflows.js +271 -0
- package/lib/calculators/index.js +143 -91
- package/lib/collections/executions.js +40 -38
- package/lib/collections/flow_nodes.js +60 -72
- package/lib/collections/jobs.js +45 -47
- package/lib/collections/workflows.js +70 -63
- 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.d.ts +1 -1
- package/lib/instructions/create.js +43 -25
- 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 +46 -25
- package/lib/instructions/update.d.ts +2 -1
- package/lib/instructions/update.js +44 -25
- package/lib/models/Execution.d.ts +3 -2
- package/lib/models/Execution.js +400 -241
- package/lib/models/FlowNode.js +18 -5
- package/lib/models/Job.js +18 -5
- package/lib/models/Workflow.d.ts +4 -5
- package/lib/models/Workflow.js +94 -72
- package/lib/server.d.ts +7 -2
- package/lib/server.js +114 -65
- package/lib/triggers/collection.d.ts +16 -0
- package/lib/triggers/collection.js +162 -0
- package/lib/triggers/index.d.ts +3 -6
- package/lib/triggers/index.js +14 -11
- package/package.json +7 -12
- package/esm/actions/flow_nodes.js +0 -139
- package/esm/actions/flow_nodes.js.map +0 -1
- package/esm/actions/index.d.ts +0 -1
- package/esm/actions/index.js +0 -8
- package/esm/actions/index.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 -38
- package/esm/collections/executions.js.map +0 -1
- package/esm/collections/flow_nodes.d.ts +0 -3
- package/esm/collections/flow_nodes.js +0 -72
- 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 -63
- 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 -25
- 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 -25
- package/esm/instructions/query.js.map +0 -1
- package/esm/instructions/update.d.ts +0 -8
- package/esm/instructions/update.js +0 -25
- package/esm/instructions/update.js.map +0 -1
- package/esm/models/Execution.d.ts +0 -50
- package/esm/models/Execution.js +0 -250
- 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 -27
- package/esm/models/Workflow.js +0 -72
- 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/index.d.ts +0 -9
- package/esm/triggers/index.js +0 -6
- package/esm/triggers/index.js.map +0 -1
- package/esm/triggers/model.d.ts +0 -12
- package/esm/triggers/model.js +0 -47
- package/esm/triggers/model.js.map +0 -1
- package/lib/actions/flow_nodes.d.ts +0 -3
- package/lib/actions/flow_nodes.js +0 -163
- package/lib/actions/flow_nodes.js.map +0 -1
- package/lib/actions/index.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/index.js.map +0 -1
- package/lib/triggers/model.d.ts +0 -12
- package/lib/triggers/model.js +0 -49
- package/lib/triggers/model.js.map +0 -1
- package/tsconfig.build.json +0 -9
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'workflows',
|
|
3
|
-
model: 'WorkflowModel',
|
|
4
|
-
title: '自动化',
|
|
5
|
-
fields: [
|
|
6
|
-
{
|
|
7
|
-
interface: 'string',
|
|
8
|
-
type: 'string',
|
|
9
|
-
name: 'title',
|
|
10
|
-
title: '自动化名称',
|
|
11
|
-
required: true
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
interface: 'boolean',
|
|
15
|
-
type: 'boolean',
|
|
16
|
-
name: 'enabled',
|
|
17
|
-
title: '启用'
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
interface: 'textarea',
|
|
21
|
-
type: 'text',
|
|
22
|
-
name: 'description',
|
|
23
|
-
title: '描述'
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
interface: 'select',
|
|
27
|
-
type: 'string',
|
|
28
|
-
title: '触发方式',
|
|
29
|
-
name: 'type',
|
|
30
|
-
required: true
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
interface: 'json',
|
|
34
|
-
type: 'jsonb',
|
|
35
|
-
title: '触发配置',
|
|
36
|
-
name: 'config',
|
|
37
|
-
required: true,
|
|
38
|
-
defaultValue: {}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
interface: 'boolean',
|
|
42
|
-
type: 'boolean',
|
|
43
|
-
title: '使用事务',
|
|
44
|
-
name: 'useTransaction',
|
|
45
|
-
defaultValue: true
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
interface: 'linkTo',
|
|
49
|
-
type: 'hasMany',
|
|
50
|
-
name: 'nodes',
|
|
51
|
-
target: 'flow_nodes',
|
|
52
|
-
title: '流程节点'
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
interface: 'linkTo',
|
|
56
|
-
type: 'hasMany',
|
|
57
|
-
name: 'executions',
|
|
58
|
-
target: 'executions',
|
|
59
|
-
title: '触发执行'
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=workflows.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/collections/workflows.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,eAAe;IACtB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,IAAI;SACZ;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI;SACf;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,YAAY,EAAE,EAAE;SACjB;QACD;YACE,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,gBAAgB;YACtB,YAAY,EAAE,IAAI;SACnB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,YAAY;YACpB,KAAK,EAAE,MAAM;SACd;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'workflows',\n model: 'WorkflowModel',\n title: '自动化',\n fields: [\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 },\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} as CollectionOptions;\n"]}
|
package/esm/constants.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const EXECUTION_STATUS: {
|
|
2
|
-
STARTED: number;
|
|
3
|
-
RESOLVED: number;
|
|
4
|
-
REJECTED: number;
|
|
5
|
-
CANCELLED: number;
|
|
6
|
-
};
|
|
7
|
-
export declare const JOB_STATUS: {
|
|
8
|
-
PENDING: number;
|
|
9
|
-
RESOLVED: number;
|
|
10
|
-
REJECTED: number;
|
|
11
|
-
CANCELLED: number;
|
|
12
|
-
};
|
|
13
|
-
export declare const BRANCH_INDEX: {
|
|
14
|
-
DEFAULT: any;
|
|
15
|
-
ON_TRUE: number;
|
|
16
|
-
ON_FALSE: number;
|
|
17
|
-
};
|
package/esm/constants.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const EXECUTION_STATUS = {
|
|
2
|
-
STARTED: 0,
|
|
3
|
-
RESOLVED: 1,
|
|
4
|
-
REJECTED: -1,
|
|
5
|
-
CANCELLED: -2
|
|
6
|
-
};
|
|
7
|
-
export const JOB_STATUS = {
|
|
8
|
-
PENDING: 0,
|
|
9
|
-
RESOLVED: 1,
|
|
10
|
-
REJECTED: -1,
|
|
11
|
-
CANCELLED: -2
|
|
12
|
-
};
|
|
13
|
-
export const BRANCH_INDEX = {
|
|
14
|
-
DEFAULT: null,
|
|
15
|
-
ON_TRUE: 1,
|
|
16
|
-
ON_FALSE: 0
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=constants.js.map
|
package/esm/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC,CAAC;IACZ,SAAS,EAAE,CAAC,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,MAAM,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/esm/index.d.ts
DELETED
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export * from './constants';\nexport * from './calculators';\nexport * from './triggers';\nexport * from './instructions';\n\nexport { default } from './server';\n"]}
|
|
@@ -1,55 +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 { JOB_STATUS } from "../constants";
|
|
11
|
-
import { calculate } from "../calculators";
|
|
12
|
-
// @calculation: {
|
|
13
|
-
// calculator: 'concat',
|
|
14
|
-
// operands: [
|
|
15
|
-
// {
|
|
16
|
-
// type: 'calculation',
|
|
17
|
-
// options: {
|
|
18
|
-
// calculator: 'add',
|
|
19
|
-
// operands: [{ value: 1 }, { value: 2 }]
|
|
20
|
-
// }
|
|
21
|
-
// },
|
|
22
|
-
// {
|
|
23
|
-
// type: 'constant',
|
|
24
|
-
// value: '{{$context.data.title}}'
|
|
25
|
-
// },
|
|
26
|
-
// {
|
|
27
|
-
// type: 'context',
|
|
28
|
-
// options: {
|
|
29
|
-
// path: 'data.title'
|
|
30
|
-
// }
|
|
31
|
-
// },
|
|
32
|
-
// {
|
|
33
|
-
// type: 'constant',
|
|
34
|
-
// value: 1
|
|
35
|
-
// }
|
|
36
|
-
// ]
|
|
37
|
-
// }
|
|
38
|
-
export default {
|
|
39
|
-
run(prevJob, execution) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const { calculation } = this.config || {};
|
|
42
|
-
const result = calculation
|
|
43
|
-
? calculate({
|
|
44
|
-
type: '$calculation',
|
|
45
|
-
options: execution.getParsedValue(calculation)
|
|
46
|
-
}, prevJob, execution)
|
|
47
|
-
: null;
|
|
48
|
-
return {
|
|
49
|
-
result,
|
|
50
|
-
status: JOB_STATUS.RESOLVED
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=calculation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculation.js","sourceRoot":"","sources":["../../src/instructions/calculation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;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,eAAe;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,SAAS,CAAC;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,UAAU,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,99 +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 calculators, { calculate } from "../calculators";
|
|
11
|
-
import { JOB_STATUS } from "../constants";
|
|
12
|
-
// @calculation: {
|
|
13
|
-
// not: false,
|
|
14
|
-
// group: {
|
|
15
|
-
// type: 'and',
|
|
16
|
-
// calculations: [
|
|
17
|
-
// {
|
|
18
|
-
// calculator: 'time.equal',
|
|
19
|
-
// operands: [{ value: '{{$context.time}}' }, { value: '{{$fn.now}}' }]
|
|
20
|
-
// },
|
|
21
|
-
// {
|
|
22
|
-
// calculator: 'value.equal',
|
|
23
|
-
// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]
|
|
24
|
-
// },
|
|
25
|
-
// {
|
|
26
|
-
// group: {
|
|
27
|
-
// type: 'or',
|
|
28
|
-
// calculations: [
|
|
29
|
-
// {
|
|
30
|
-
// calculator: 'value.equal',
|
|
31
|
-
// operands: [{ value: '{{$jobsMapByNodeId.213}}' }, { value: 1 }]
|
|
32
|
-
// }
|
|
33
|
-
// ]
|
|
34
|
-
// }
|
|
35
|
-
// }
|
|
36
|
-
// ]
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
function logicCalculate(calculation, input, execution) {
|
|
40
|
-
if (!calculation) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
const { not, group } = calculation;
|
|
44
|
-
let result;
|
|
45
|
-
if (group) {
|
|
46
|
-
const method = group.type === 'and' ? 'every' : 'some';
|
|
47
|
-
result = group.calculations[method](item => logicCalculate(item, input, execution));
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const args = calculation.operands.map(operand => calculate(operand, input, execution));
|
|
51
|
-
const fn = calculators.get(calculation.calculator);
|
|
52
|
-
if (!fn) {
|
|
53
|
-
throw new Error(`no calculator function registered for "${calculation.calculator}"`);
|
|
54
|
-
}
|
|
55
|
-
result = fn(...args);
|
|
56
|
-
}
|
|
57
|
-
return not ? !result : result;
|
|
58
|
-
}
|
|
59
|
-
export default {
|
|
60
|
-
run(prevJob, execution) {
|
|
61
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
// TODO(optimize): loading of jobs could be reduced and turned into incrementally in execution
|
|
63
|
-
// const jobs = await execution.getJobs();
|
|
64
|
-
const { calculation, rejectOnFalse } = this.config || {};
|
|
65
|
-
const result = logicCalculate(calculation, prevJob, execution);
|
|
66
|
-
if (!result && rejectOnFalse) {
|
|
67
|
-
return {
|
|
68
|
-
status: JOB_STATUS.REJECTED,
|
|
69
|
-
result
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
const job = {
|
|
73
|
-
status: JOB_STATUS.RESOLVED,
|
|
74
|
-
result,
|
|
75
|
-
// TODO(optimize): try unify the building of job
|
|
76
|
-
nodeId: this.id,
|
|
77
|
-
upstreamId: prevJob && prevJob.id || null
|
|
78
|
-
};
|
|
79
|
-
const branchNode = execution.nodes
|
|
80
|
-
.find(item => item.upstream === this && Boolean(item.branchIndex) === result);
|
|
81
|
-
if (!branchNode) {
|
|
82
|
-
return job;
|
|
83
|
-
}
|
|
84
|
-
const savedJob = yield execution.saveJob(job);
|
|
85
|
-
return execution.run(branchNode, savedJob);
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
resume(branchJob, execution) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
if (branchJob.status === JOB_STATUS.RESOLVED) {
|
|
91
|
-
// return to continue this.downstream
|
|
92
|
-
return branchJob;
|
|
93
|
-
}
|
|
94
|
-
// pass control to upper scope by ending current scope
|
|
95
|
-
return execution.end(this, branchJob);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=condition.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../src/instructions/condition.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,WAAW,EAAE,EAAE,SAAS,EAAW,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAuB1C,kBAAk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AAG,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,25 +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 { JOB_STATUS } from "../constants";
|
|
11
|
-
export default {
|
|
12
|
-
run(input, execution) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const { collection, params = {} } = this.config;
|
|
15
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
16
|
-
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield repo.create(Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
18
|
-
return {
|
|
19
|
-
result,
|
|
20
|
-
status: JOB_STATUS.RESOLVED
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/instructions/create.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;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,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,UAAU,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.transaction\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1,25 +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 { JOB_STATUS } from "../constants";
|
|
11
|
-
export default {
|
|
12
|
-
run(input, execution) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const { collection, params = {} } = this.config;
|
|
15
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
16
|
-
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield repo.destroy(Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
18
|
-
return {
|
|
19
|
-
result,
|
|
20
|
-
status: JOB_STATUS.RESOLVED
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=destroy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"destroy.js","sourceRoot":"","sources":["../../src/instructions/destroy.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,eAAe;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,WAAW,IAClC,CAAC;YAEH,OAAO;gBACL,MAAM;gBACN,MAAM,EAAE,UAAU,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.transaction\n });\n\n return {\n result,\n status: JOB_STATUS.RESOLVED\n };\n }\n}\n"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Registry } from '@nocobase/utils';
|
|
2
|
-
import ExecutionModel from '../models/Execution';
|
|
3
|
-
import FlowNodeModel from '../models/FlowNode';
|
|
4
|
-
export interface Job {
|
|
5
|
-
status: number;
|
|
6
|
-
result?: unknown;
|
|
7
|
-
[key: string]: unknown;
|
|
8
|
-
}
|
|
9
|
-
export declare type InstructionResult = Job | Promise<Job>;
|
|
10
|
-
export interface Instruction {
|
|
11
|
-
run(this: FlowNodeModel, input: any, execution: ExecutionModel): InstructionResult;
|
|
12
|
-
resume?(this: FlowNodeModel, input: any, execution: ExecutionModel): InstructionResult;
|
|
13
|
-
}
|
|
14
|
-
export declare const instructions: Registry<Instruction>;
|
|
15
|
-
export default instructions;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Registry } from '@nocobase/utils';
|
|
2
|
-
import prompt from './prompt';
|
|
3
|
-
import calculation from './calculation';
|
|
4
|
-
import condition from './condition';
|
|
5
|
-
import parallel from './parallel';
|
|
6
|
-
import query from './query';
|
|
7
|
-
import create from './create';
|
|
8
|
-
import update from './update';
|
|
9
|
-
import destroy from './destroy';
|
|
10
|
-
export const instructions = new Registry();
|
|
11
|
-
instructions.register('prompt', prompt);
|
|
12
|
-
instructions.register('calculation', calculation);
|
|
13
|
-
instructions.register('condition', condition);
|
|
14
|
-
instructions.register('parallel', parallel);
|
|
15
|
-
instructions.register('query', query);
|
|
16
|
-
instructions.register('create', create);
|
|
17
|
-
instructions.register('update', update);
|
|
18
|
-
instructions.register('destroy', destroy);
|
|
19
|
-
export default instructions;
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instructions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,OAAO,MAAM,WAAW,CAAC;AA+BhC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,QAAQ,EAAe,CAAC;AAExD,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxC,YAAY,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAClD,YAAY,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAC9C,YAAY,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC5C,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtC,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxC,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxC,YAAY,CAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAE1C,eAAe,YAAY,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,13 +0,0 @@
|
|
|
1
|
-
import ExecutionModel from "../models/Execution";
|
|
2
|
-
import FlowNodeModel from "../models/FlowNode";
|
|
3
|
-
import JobModel from "../models/Job";
|
|
4
|
-
export declare const PARALLEL_MODE: {
|
|
5
|
-
readonly ALL: "all";
|
|
6
|
-
readonly ANY: "any";
|
|
7
|
-
readonly RACE: "race";
|
|
8
|
-
};
|
|
9
|
-
declare const _default: {
|
|
10
|
-
run(this: FlowNodeModel, prevJob: JobModel, execution: ExecutionModel): Promise<any>;
|
|
11
|
-
resume(this: any, branchJob: any, execution: ExecutionModel): Promise<any>;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
@@ -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 { JOB_STATUS } from "../constants";
|
|
11
|
-
export const PARALLEL_MODE = {
|
|
12
|
-
ALL: 'all',
|
|
13
|
-
ANY: 'any',
|
|
14
|
-
RACE: 'race'
|
|
15
|
-
};
|
|
16
|
-
const StatusGetters = {
|
|
17
|
-
[PARALLEL_MODE.ALL](result) {
|
|
18
|
-
if (result.some(j => j && j.status === JOB_STATUS.REJECTED)) {
|
|
19
|
-
return JOB_STATUS.REJECTED;
|
|
20
|
-
}
|
|
21
|
-
if (result.every(j => j && j.status === JOB_STATUS.RESOLVED)) {
|
|
22
|
-
return JOB_STATUS.RESOLVED;
|
|
23
|
-
}
|
|
24
|
-
return JOB_STATUS.PENDING;
|
|
25
|
-
},
|
|
26
|
-
[PARALLEL_MODE.ANY](result) {
|
|
27
|
-
return result.some(j => j && j.status === JOB_STATUS.RESOLVED)
|
|
28
|
-
? JOB_STATUS.RESOLVED
|
|
29
|
-
: (result.some(j => j && j.status === JOB_STATUS.PENDING)
|
|
30
|
-
? JOB_STATUS.PENDING
|
|
31
|
-
: JOB_STATUS.REJECTED);
|
|
32
|
-
},
|
|
33
|
-
[PARALLEL_MODE.RACE](result) {
|
|
34
|
-
return result.some(j => j && j.status === JOB_STATUS.RESOLVED)
|
|
35
|
-
? JOB_STATUS.RESOLVED
|
|
36
|
-
: (result.some(j => j && j.status === JOB_STATUS.REJECTED)
|
|
37
|
-
? JOB_STATUS.REJECTED
|
|
38
|
-
: JOB_STATUS.PENDING);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
export default {
|
|
42
|
-
run(prevJob, execution) {
|
|
43
|
-
var _a;
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const branches = execution.nodes
|
|
46
|
-
.filter(item => item.upstream === this && item.branchIndex !== null)
|
|
47
|
-
.sort((a, b) => a.branchIndex - b.branchIndex);
|
|
48
|
-
const job = yield execution.saveJob({
|
|
49
|
-
status: JOB_STATUS.PENDING,
|
|
50
|
-
result: Array(branches.length).fill(null),
|
|
51
|
-
nodeId: this.id,
|
|
52
|
-
upstreamId: (_a = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _a !== void 0 ? _a : null
|
|
53
|
-
});
|
|
54
|
-
// NOTE:
|
|
55
|
-
// use `reduce` but not `Promise.all` here to avoid racing manupulating db.
|
|
56
|
-
// for users, this is almost equivalent to `Promise.all`,
|
|
57
|
-
// because of the delay is not significant sensible.
|
|
58
|
-
// another better aspect of this is, it could handle sequenced branches in future.
|
|
59
|
-
yield branches.reduce((promise, branch) => promise.then(() => execution.run(branch, job)), Promise.resolve());
|
|
60
|
-
return execution.end(this, job);
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
resume(branchJob, execution) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const job = execution.findBranchParentJob(branchJob, this);
|
|
66
|
-
const { result, status } = job;
|
|
67
|
-
// if parallel has been done (resolved / rejected), do not care newly executed branch jobs.
|
|
68
|
-
if (status !== JOB_STATUS.PENDING) {
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
// find the index of the node which start the branch
|
|
72
|
-
const jobNode = execution.nodesMap.get(branchJob.nodeId);
|
|
73
|
-
const { branchIndex } = execution.findBranchStartNode(jobNode);
|
|
74
|
-
const { mode = PARALLEL_MODE.ALL } = this.config || {};
|
|
75
|
-
const newResult = [...result.slice(0, branchIndex), branchJob.get(), ...result.slice(branchIndex + 1)];
|
|
76
|
-
job.set({
|
|
77
|
-
result: newResult,
|
|
78
|
-
status: StatusGetters[mode](newResult)
|
|
79
|
-
});
|
|
80
|
-
if (job.status === JOB_STATUS.PENDING) {
|
|
81
|
-
yield job.save({ transaction: execution.transaction });
|
|
82
|
-
return execution.end(this, job);
|
|
83
|
-
}
|
|
84
|
-
return job;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=parallel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.js","sourceRoot":"","sources":["../../src/instructions/parallel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,MAAM,aAAa,GAAG;IACpB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC3D,OAAO,UAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC5D,OAAO,UAAU,CAAC,QAAQ,CAAC;SAC5B;QACD,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM;QACxB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,QAAQ,CAAC;YAC5D,CAAC,CAAC,UAAU,CAAC,QAAQ;YACrB,CAAC,CAAC,CACA,MAAM,CAAC,IAAI,CAAC,CAA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CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;aACvC,CAAC,CAAC;YAEH,IAAI,GAAG,CAAC,MAAM,KAAK,UAAU,CAAC,OAAO,EAAE;gBACrC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;gBACvD,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.transaction });\n return execution.end(this, job);\n }\n\n return job;\n }\n};\n"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { JOB_STATUS } from "../constants";
|
|
2
|
-
export default {
|
|
3
|
-
run(input, execution) {
|
|
4
|
-
return {
|
|
5
|
-
status: JOB_STATUS.PENDING
|
|
6
|
-
};
|
|
7
|
-
},
|
|
8
|
-
resume(job, execution) {
|
|
9
|
-
job.set('status', JOB_STATUS.RESOLVED);
|
|
10
|
-
return job;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=prompt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/instructions/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,eAAe;IACb,GAAG,CAAO,KAAK,EAAE,SAAS;QACxB,OAAO;YACL,MAAM,EAAE,UAAU,CAAC,OAAO;SAC3B,CAAC;IACJ,CAAC;IAED,MAAM,CAAO,GAAG,EAAE,SAAS;QACzB,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,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,25 +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 { JOB_STATUS } from "../constants";
|
|
11
|
-
export default {
|
|
12
|
-
run(input, execution) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
const { collection, multiple, params = {} } = this.config;
|
|
15
|
-
const repo = this.constructor.database.getRepository(collection);
|
|
16
|
-
const options = execution.getParsedValue(params);
|
|
17
|
-
const result = yield (multiple ? repo.find : repo.findOne).call(repo, Object.assign(Object.assign({}, options), { transaction: execution.transaction }));
|
|
18
|
-
return {
|
|
19
|
-
result,
|
|
20
|
-
status: JOB_STATUS.RESOLVED
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=query.js.map
|