@loopstack/core 0.1.2 → 0.3.0
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/CHANGELOG.md +22 -0
- package/dist/modules/common/common.module.js +9 -15
- package/dist/modules/common/common.module.js.map +1 -1
- package/dist/modules/common/errors/object-expression.error.d.ts +4 -0
- package/dist/modules/common/errors/object-expression.error.js +13 -0
- package/dist/modules/common/errors/object-expression.error.js.map +1 -0
- package/dist/modules/common/errors/template-expression.error.d.ts +4 -0
- package/dist/modules/common/errors/template-expression.error.js +13 -0
- package/dist/modules/common/errors/template-expression.error.js.map +1 -0
- package/dist/modules/common/services/context.service.d.ts +1 -0
- package/dist/modules/common/services/context.service.js +4 -0
- package/dist/modules/common/services/context.service.js.map +1 -1
- package/dist/modules/common/services/expression-handler/object-expression.handler.d.ts +20 -0
- package/dist/modules/common/services/expression-handler/object-expression.handler.js +125 -0
- package/dist/modules/common/services/expression-handler/object-expression.handler.js.map +1 -0
- package/dist/modules/common/services/expression-handler/template-expression.handler.d.ts +12 -0
- package/dist/modules/common/services/expression-handler/template-expression.handler.js +63 -0
- package/dist/modules/common/services/expression-handler/template-expression.handler.js.map +1 -0
- package/dist/modules/common/services/handlebars-helpers/date-formatter-handlebars-helper.service.d.ts +9 -0
- package/dist/modules/common/services/handlebars-helpers/date-formatter-handlebars-helper.service.js +124 -0
- package/dist/modules/common/services/handlebars-helpers/date-formatter-handlebars-helper.service.js.map +1 -0
- package/dist/modules/common/services/handlebars-helpers/index.d.ts +1 -0
- package/dist/modules/common/services/handlebars-helpers/index.js +18 -0
- package/dist/modules/common/services/handlebars-helpers/index.js.map +1 -0
- package/dist/modules/common/services/handlebars-processor.service.d.ts +12 -0
- package/dist/modules/common/services/handlebars-processor.service.js +70 -0
- package/dist/modules/common/services/handlebars-processor.service.js.map +1 -0
- package/dist/modules/common/services/index.d.ts +6 -5
- package/dist/modules/common/services/index.js +6 -5
- package/dist/modules/common/services/index.js.map +1 -1
- package/dist/modules/common/services/template.service.d.ts +16 -0
- package/dist/modules/common/services/template.service.js +64 -0
- package/dist/modules/common/services/template.service.js.map +1 -0
- package/dist/modules/common/services/variable-sanitizer.service.d.ts +9 -0
- package/dist/modules/common/services/variable-sanitizer.service.js +84 -0
- package/dist/modules/common/services/variable-sanitizer.service.js.map +1 -0
- package/dist/modules/configuration/configuration.module.js +2 -1
- package/dist/modules/configuration/configuration.module.js.map +1 -1
- package/dist/modules/configuration/services/configuration.service.d.ts +15 -14
- package/dist/modules/configuration/services/configuration.service.js +97 -107
- package/dist/modules/configuration/services/configuration.service.js.map +1 -1
- package/dist/modules/configuration/services/dynamic-schema-generator.service.js +3 -1
- package/dist/modules/configuration/services/dynamic-schema-generator.service.js.map +1 -1
- package/dist/modules/configuration/services/index.d.ts +1 -0
- package/dist/modules/configuration/services/index.js +1 -0
- package/dist/modules/configuration/services/index.js.map +1 -1
- package/dist/modules/configuration/services/schema-registry.service.d.ts +9 -0
- package/dist/modules/configuration/services/schema-registry.service.js +41 -0
- package/dist/modules/configuration/services/schema-registry.service.js.map +1 -0
- package/dist/modules/configuration/services/service-registry.service.js +1 -1
- package/dist/modules/configuration/services/service-registry.service.js.map +1 -1
- package/dist/modules/persistence/services/document.service.d.ts +6 -2
- package/dist/modules/persistence/services/document.service.js +29 -17
- package/dist/modules/persistence/services/document.service.js.map +1 -1
- package/dist/modules/persistence/services/namespace.service.js.map +1 -1
- package/dist/modules/persistence/services/workflow.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/index.d.ts +4 -1
- package/dist/modules/workflow-processor/services/index.js +4 -1
- package/dist/modules/workflow-processor/services/index.js.map +1 -1
- package/dist/modules/workflow-processor/services/pipeline-processor.service.d.ts +15 -8
- package/dist/modules/workflow-processor/services/pipeline-processor.service.js +163 -29
- package/dist/modules/workflow-processor/services/pipeline-processor.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/root-processor.service.d.ts +12 -0
- package/dist/modules/workflow-processor/services/root-processor.service.js +49 -0
- package/dist/modules/workflow-processor/services/root-processor.service.js.map +1 -0
- package/dist/modules/workflow-processor/services/service-execution.service.d.ts +12 -0
- package/dist/modules/workflow-processor/services/service-execution.service.js +53 -0
- package/dist/modules/workflow-processor/services/service-execution.service.js.map +1 -0
- package/dist/modules/workflow-processor/services/state-machine-config.service.d.ts +2 -17
- package/dist/modules/workflow-processor/services/state-machine-config.service.js +33 -17
- package/dist/modules/workflow-processor/services/state-machine-config.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/state-machine-processor.service.d.ts +11 -7
- package/dist/modules/workflow-processor/services/state-machine-processor.service.js +95 -30
- package/dist/modules/workflow-processor/services/state-machine-processor.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/template-expression-evaluator.service.d.ts +24 -4
- package/dist/modules/workflow-processor/services/template-expression-evaluator.service.js +90 -21
- package/dist/modules/workflow-processor/services/template-expression-evaluator.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/tool-execution.service.d.ts +8 -20
- package/dist/modules/workflow-processor/services/tool-execution.service.js +31 -55
- package/dist/modules/workflow-processor/services/tool-execution.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/workflow-context.service.d.ts +4 -0
- package/dist/modules/{common/services/template-engine.service.js → workflow-processor/services/workflow-context.service.js} +12 -15
- package/dist/modules/workflow-processor/services/workflow-context.service.js.map +1 -0
- package/dist/modules/workflow-processor/services/workflow-processor.service.d.ts +5 -26
- package/dist/modules/workflow-processor/services/workflow-processor.service.js +18 -184
- package/dist/modules/workflow-processor/services/workflow-processor.service.js.map +1 -1
- package/dist/modules/workflow-processor/services/workflow-state.service.d.ts +8 -0
- package/dist/modules/workflow-processor/services/workflow-state.service.js +49 -0
- package/dist/modules/workflow-processor/services/workflow-state.service.js.map +1 -0
- package/dist/modules/workflow-processor/tool-services/add-namespace.service.js +4 -4
- package/dist/modules/workflow-processor/tool-services/add-namespace.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/batch-create-documents.service.d.ts +6 -10
- package/dist/modules/workflow-processor/tool-services/batch-create-documents.service.js +39 -27
- package/dist/modules/workflow-processor/tool-services/batch-create-documents.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/create-document.service.d.ts +7 -142
- package/dist/modules/workflow-processor/tool-services/create-document.service.js +91 -35
- package/dist/modules/workflow-processor/tool-services/create-document.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/load-document.service.d.ts +26 -51
- package/dist/modules/workflow-processor/tool-services/load-document.service.js +59 -81
- package/dist/modules/workflow-processor/tool-services/load-document.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/mock.service.d.ts +11 -8
- package/dist/modules/workflow-processor/tool-services/mock.service.js +41 -9
- package/dist/modules/workflow-processor/tool-services/mock.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/set-context.service.d.ts +3 -0
- package/dist/modules/workflow-processor/tool-services/set-context.service.js +11 -5
- package/dist/modules/workflow-processor/tool-services/set-context.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/set-target-place.service.d.ts +1 -1
- package/dist/modules/workflow-processor/tool-services/set-target-place.service.js +6 -5
- package/dist/modules/workflow-processor/tool-services/set-target-place.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/transition-selector.service.js +2 -2
- package/dist/modules/workflow-processor/tool-services/transition-selector.service.js.map +1 -1
- package/dist/modules/workflow-processor/tool-services/update-document.service.d.ts +32 -62
- package/dist/modules/workflow-processor/tool-services/update-document.service.js +92 -7
- package/dist/modules/workflow-processor/tool-services/update-document.service.js.map +1 -1
- package/dist/modules/workflow-processor/validators/workflow-option.validator.d.ts +1 -1
- package/dist/modules/workflow-processor/validators/workflow-option.validator.js +3 -3
- package/dist/modules/workflow-processor/validators/workflow-option.validator.js.map +1 -1
- package/dist/modules/workflow-processor/workflow-processor.module.js +9 -2
- package/dist/modules/workflow-processor/workflow-processor.module.js.map +1 -1
- package/dist/utils/load-configuration.js +5 -3
- package/dist/utils/load-configuration.js.map +1 -1
- package/package.json +5 -3
- package/dist/modules/common/services/document-helper.service.d.ts +0 -212
- package/dist/modules/common/services/document-helper.service.js +0 -53
- package/dist/modules/common/services/document-helper.service.js.map +0 -1
- package/dist/modules/common/services/expression-evaluator.service.d.ts +0 -5
- package/dist/modules/common/services/expression-evaluator.service.js +0 -44
- package/dist/modules/common/services/expression-evaluator.service.js.map +0 -1
- package/dist/modules/common/services/schema-validator.service.d.ts +0 -7
- package/dist/modules/common/services/schema-validator.service.js +0 -41
- package/dist/modules/common/services/schema-validator.service.js.map +0 -1
- package/dist/modules/common/services/template-engine.service.d.ts +0 -5
- package/dist/modules/common/services/template-engine.service.js.map +0 -1
- package/dist/modules/common/services/value-parser.service.d.ts +0 -19
- package/dist/modules/common/services/value-parser.service.js +0 -68
- package/dist/modules/common/services/value-parser.service.js.map +0 -1
- package/dist/modules/configuration/commands/generate-schemas.command.d.ts +0 -8
- package/dist/modules/configuration/commands/generate-schemas.command.js +0 -34
- package/dist/modules/configuration/commands/generate-schemas.command.js.map +0 -1
- package/dist/modules/workflow-processor/services/tool-schema-validator.service.d.ts +0 -5
- package/dist/modules/workflow-processor/services/tool-schema-validator.service.js +0 -41
- package/dist/modules/workflow-processor/services/tool-schema-validator.service.js.map +0 -1
|
@@ -6,22 +6,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.WorkflowContextService = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
evaluate(value, variables) {
|
|
20
|
-
return this.isTemplate(value) ? this.render(value, variables) : value;
|
|
11
|
+
let WorkflowContextService = class WorkflowContextService {
|
|
12
|
+
setWorkflowContextUpdate(workflow, key, value) {
|
|
13
|
+
if (!workflow.contextVariables) {
|
|
14
|
+
workflow.contextVariables = {};
|
|
15
|
+
}
|
|
16
|
+
workflow.contextVariables[key] = value;
|
|
17
|
+
return workflow;
|
|
21
18
|
}
|
|
22
19
|
};
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
20
|
+
exports.WorkflowContextService = WorkflowContextService;
|
|
21
|
+
exports.WorkflowContextService = WorkflowContextService = __decorate([
|
|
25
22
|
(0, common_1.Injectable)()
|
|
26
|
-
],
|
|
27
|
-
//# sourceMappingURL=
|
|
23
|
+
], WorkflowContextService);
|
|
24
|
+
//# sourceMappingURL=workflow-context.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-context.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/services/workflow-context.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAIrC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,wBAAwB,CACtB,QAAwB,EACxB,GAAW,EACX,KAAU;QAEV,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;YAC/B,QAAQ,CAAC,gBAAgB,GAAG,EAAE,CAAC;QACjC,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AAbY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAalC"}
|
|
@@ -1,31 +1,10 @@
|
|
|
1
|
-
import { ContextService } from '../../common';
|
|
2
|
-
import { ValueParserService } from '../../common';
|
|
3
1
|
import { StateMachineProcessorService } from './state-machine-processor.service';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ContextInterface, WorkflowEntity, WorkflowFactoryType, WorkflowPipelineType, WorkflowStateMachineType, WorkflowToolType, WorkflowType } from '@loopstack/shared';
|
|
7
|
-
import { NamespaceProcessorService } from './namespace-processor.service';
|
|
8
|
-
import { ToolExecutionService } from './tool-execution.service';
|
|
2
|
+
import { ContextInterface, ConfigElement, WorkflowType } from '@loopstack/shared';
|
|
3
|
+
import { WorkflowStateService } from './workflow-state.service';
|
|
9
4
|
export declare class WorkflowProcessorService {
|
|
10
|
-
private
|
|
11
|
-
private loopConfigService;
|
|
12
|
-
private valueParserService;
|
|
5
|
+
private workflowConfigService;
|
|
13
6
|
private stateMachineProcessorService;
|
|
14
|
-
private workflowService;
|
|
15
|
-
private namespaceProcessorService;
|
|
16
|
-
private toolExecutionService;
|
|
17
7
|
private readonly logger;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
workflowExists(name: string): boolean;
|
|
21
|
-
createIndex(ltreeIndex: string, increment?: number): string;
|
|
22
|
-
runToolType(config: WorkflowToolType, context: ContextInterface): Promise<ContextInterface | undefined>;
|
|
23
|
-
runSequenceType(sequenceConfig: WorkflowPipelineType, context: ContextInterface): Promise<ContextInterface | undefined>;
|
|
24
|
-
prepareAllContexts(context: ContextInterface, factory: WorkflowFactoryType, items: string[]): Promise<ContextInterface[]>;
|
|
25
|
-
runFactoryType(factory: WorkflowFactoryType, context: ContextInterface): Promise<ContextInterface>;
|
|
26
|
-
runStateMachineType(config: WorkflowStateMachineType, context: ContextInterface): Promise<ContextInterface>;
|
|
27
|
-
processWorkflow(workflowConfig: WorkflowType, context: ContextInterface): Promise<ContextInterface | undefined>;
|
|
28
|
-
getWorkflow(workflowConfig: WorkflowType, context: ContextInterface): Promise<WorkflowEntity>;
|
|
29
|
-
processChild(name: string, context: ContextInterface): Promise<ContextInterface>;
|
|
30
|
-
start(entrypoint: string, context: ContextInterface): Promise<ContextInterface>;
|
|
8
|
+
constructor(workflowConfigService: WorkflowStateService, stateMachineProcessorService: StateMachineProcessorService);
|
|
9
|
+
runStateMachineType(configElement: ConfigElement<WorkflowType>, context: ContextInterface): Promise<ContextInterface>;
|
|
31
10
|
}
|
|
@@ -12,207 +12,41 @@ var WorkflowProcessorService_1;
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.WorkflowProcessorService = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
-
const common_2 = require("../../common");
|
|
16
|
-
const common_3 = require("../../common");
|
|
17
15
|
const state_machine_processor_service_1 = require("./state-machine-processor.service");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const namespace_processor_service_1 = require("./namespace-processor.service");
|
|
21
|
-
const tool_execution_service_1 = require("./tool-execution.service");
|
|
16
|
+
const shared_1 = require("@loopstack/shared");
|
|
17
|
+
const workflow_state_service_1 = require("./workflow-state.service");
|
|
22
18
|
let WorkflowProcessorService = WorkflowProcessorService_1 = class WorkflowProcessorService {
|
|
23
|
-
|
|
24
|
-
loopConfigService;
|
|
25
|
-
valueParserService;
|
|
19
|
+
workflowConfigService;
|
|
26
20
|
stateMachineProcessorService;
|
|
27
|
-
workflowService;
|
|
28
|
-
namespaceProcessorService;
|
|
29
|
-
toolExecutionService;
|
|
30
21
|
logger = new common_1.Logger(WorkflowProcessorService_1.name);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.contextService = contextService;
|
|
34
|
-
this.loopConfigService = loopConfigService;
|
|
35
|
-
this.valueParserService = valueParserService;
|
|
22
|
+
constructor(workflowConfigService, stateMachineProcessorService) {
|
|
23
|
+
this.workflowConfigService = workflowConfigService;
|
|
36
24
|
this.stateMachineProcessorService = stateMachineProcessorService;
|
|
37
|
-
this.workflowService = workflowService;
|
|
38
|
-
this.namespaceProcessorService = namespaceProcessorService;
|
|
39
|
-
this.toolExecutionService = toolExecutionService;
|
|
40
25
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
parts[parts.length - 1] += increment;
|
|
47
|
-
return parts.map((part) => part.toString().padStart(4, '0')).join('.');
|
|
48
|
-
}
|
|
49
|
-
async runToolType(config, context) {
|
|
50
|
-
const sequence = config.sequence;
|
|
51
|
-
if (!sequence) {
|
|
52
|
-
return context;
|
|
53
|
-
}
|
|
54
|
-
let workflow = await this.getWorkflow(config, context);
|
|
55
|
-
let lastContext = this.contextService.create(context);
|
|
56
|
-
for (let i = 0; i < sequence.length; i++) {
|
|
57
|
-
const handler = sequence[i];
|
|
58
|
-
const meta = {
|
|
59
|
-
transition: 'tool',
|
|
60
|
-
history: [],
|
|
61
|
-
payload: null,
|
|
62
|
-
};
|
|
63
|
-
const result = await this.toolExecutionService.applyTool(handler, workflow, context, meta);
|
|
64
|
-
workflow = this.toolExecutionService.commitServiceCallResult(workflow, 'default', handler.tool, handler.exportAs, result);
|
|
65
|
-
if (result?.persist) {
|
|
66
|
-
await this.workflowService.save(workflow);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
await this.workflowService.save(workflow);
|
|
70
|
-
return lastContext;
|
|
71
|
-
}
|
|
72
|
-
async runSequenceType(sequenceConfig, context) {
|
|
73
|
-
const sequence = sequenceConfig.sequence;
|
|
74
|
-
const index = `${context.index}.0`;
|
|
75
|
-
let lastContext = this.contextService.create(context);
|
|
76
|
-
for (let i = 0; i < sequence.length; i++) {
|
|
77
|
-
const item = sequence[i];
|
|
78
|
-
const workflowName = typeof item === 'object' ? item.name : item;
|
|
79
|
-
this.logger.debug(`Processing Sequence Item ${workflowName}`);
|
|
80
|
-
const evaluatedItem = this.valueParserService.evalWithContext(item, { context: lastContext });
|
|
81
|
-
if (evaluatedItem.condition === false) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
lastContext.index = this.createIndex(index, i + 1);
|
|
85
|
-
lastContext = await this.processChild(workflowName, lastContext);
|
|
86
|
-
if (this.stop) {
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return lastContext;
|
|
91
|
-
}
|
|
92
|
-
async prepareAllContexts(context, factory, items) {
|
|
93
|
-
const index = `${context.index}.0`;
|
|
94
|
-
const contexts = [];
|
|
95
|
-
for (let i = 0; i < items.length; i++) {
|
|
96
|
-
const item = items[i];
|
|
97
|
-
const label = factory.iterator.label
|
|
98
|
-
? this.valueParserService.evalWithContextAndItem(factory.iterator.label, {
|
|
99
|
-
context,
|
|
100
|
-
item,
|
|
101
|
-
index: i + 1,
|
|
102
|
-
})
|
|
103
|
-
: item.toString();
|
|
104
|
-
const metadata = factory.iterator.meta
|
|
105
|
-
? this.valueParserService.evalWithContextAndItem(factory.iterator.meta, {
|
|
106
|
-
context,
|
|
107
|
-
item,
|
|
108
|
-
index: i + 1,
|
|
109
|
-
})
|
|
110
|
-
: undefined;
|
|
111
|
-
const localContext = await this.namespaceProcessorService.createNamespace(context, {
|
|
112
|
-
label,
|
|
113
|
-
meta: metadata,
|
|
114
|
-
});
|
|
115
|
-
localContext.index = this.createIndex(index, i + 1);
|
|
116
|
-
contexts.push(localContext);
|
|
26
|
+
async runStateMachineType(configElement, context) {
|
|
27
|
+
const currentWorkflow = await this.workflowConfigService.getWorkflowState(configElement, context);
|
|
28
|
+
const workflow = await this.stateMachineProcessorService.processStateMachine(context, currentWorkflow, configElement);
|
|
29
|
+
if (workflow.status === shared_1.WorkflowState.Failed) {
|
|
30
|
+
context.error = true;
|
|
117
31
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
async runFactoryType(factory, context) {
|
|
121
|
-
const workflowName = factory.workflow;
|
|
122
|
-
if (!this.workflowExists(factory.workflow)) {
|
|
123
|
-
throw new Error(`Workflow ${workflowName} for factory does not exist.`);
|
|
124
|
-
}
|
|
125
|
-
const items = this.valueParserService.evalWithContext(factory.iterator.source, { context });
|
|
126
|
-
if (!Array.isArray(items)) {
|
|
127
|
-
throw new Error(`Iterator values in ${factory.iterator.source} must be array, got ${typeof items}`);
|
|
128
|
-
}
|
|
129
|
-
const preparedChildContexts = await this.prepareAllContexts(context, factory, items);
|
|
130
|
-
await this.namespaceProcessorService.cleanupNamespace(context, preparedChildContexts);
|
|
131
|
-
for (const childContext of preparedChildContexts) {
|
|
132
|
-
await this.processChild(workflowName, childContext);
|
|
133
|
-
if (this.stop) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return context;
|
|
138
|
-
}
|
|
139
|
-
async runStateMachineType(config, context) {
|
|
140
|
-
const currentWorkflow = await this.getWorkflow(config, context);
|
|
141
|
-
const workflow = await this.stateMachineProcessorService.processStateMachine(context, currentWorkflow, config);
|
|
142
|
-
if (workflow.place !== 'complete') {
|
|
143
|
-
this.stop = true;
|
|
32
|
+
if (context.error || workflow.place !== 'end') {
|
|
33
|
+
context.stop = true;
|
|
144
34
|
}
|
|
145
35
|
else {
|
|
146
|
-
if (workflow.
|
|
147
|
-
context.
|
|
148
|
-
...context.
|
|
149
|
-
...workflow.
|
|
36
|
+
if (workflow.contextVariables) {
|
|
37
|
+
context.variables = {
|
|
38
|
+
...context.variables,
|
|
39
|
+
...workflow.contextVariables,
|
|
150
40
|
};
|
|
151
41
|
}
|
|
152
42
|
}
|
|
153
43
|
return context;
|
|
154
44
|
}
|
|
155
|
-
async processWorkflow(workflowConfig, context) {
|
|
156
|
-
if (workflowConfig.namespace) {
|
|
157
|
-
context = await this.namespaceProcessorService.createNamespace(context, workflowConfig.namespace);
|
|
158
|
-
}
|
|
159
|
-
switch (workflowConfig.type) {
|
|
160
|
-
case 'tool':
|
|
161
|
-
return this.runToolType(workflowConfig, context);
|
|
162
|
-
case 'pipeline':
|
|
163
|
-
return this.runSequenceType(workflowConfig, context);
|
|
164
|
-
case 'factory':
|
|
165
|
-
return this.runFactoryType(workflowConfig, context);
|
|
166
|
-
case 'stateMachine':
|
|
167
|
-
return this.runStateMachineType(workflowConfig, context);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async getWorkflow(workflowConfig, context) {
|
|
171
|
-
const workflow = await this.workflowService
|
|
172
|
-
.createFindQuery(context.namespace?.id, {
|
|
173
|
-
name: workflowConfig.name,
|
|
174
|
-
labels: context.labels,
|
|
175
|
-
})
|
|
176
|
-
.getOne();
|
|
177
|
-
if (workflow) {
|
|
178
|
-
return workflow;
|
|
179
|
-
}
|
|
180
|
-
return this.workflowService.create({
|
|
181
|
-
createdBy: context.userId,
|
|
182
|
-
labels: context.labels,
|
|
183
|
-
namespace: context.namespace ?? undefined,
|
|
184
|
-
pipelineId: context.pipelineId,
|
|
185
|
-
name: workflowConfig.name,
|
|
186
|
-
title: workflowConfig.title ?? workflowConfig.name,
|
|
187
|
-
ui: workflowConfig.ui ?? null,
|
|
188
|
-
index: context.index,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
async processChild(name, context) {
|
|
192
|
-
const workflowConfig = this.loopConfigService.get('workflows', name);
|
|
193
|
-
if (!workflowConfig) {
|
|
194
|
-
throw new Error(`workflow with name "${name}" not found.`);
|
|
195
|
-
}
|
|
196
|
-
const newContext = await this.processWorkflow(workflowConfig, context);
|
|
197
|
-
if (newContext && newContext.namespace.id === context.namespace.id) {
|
|
198
|
-
return newContext;
|
|
199
|
-
}
|
|
200
|
-
return context;
|
|
201
|
-
}
|
|
202
|
-
start(entrypoint, context) {
|
|
203
|
-
this.stop = false;
|
|
204
|
-
return this.processChild(entrypoint, context);
|
|
205
|
-
}
|
|
206
45
|
};
|
|
207
46
|
exports.WorkflowProcessorService = WorkflowProcessorService;
|
|
208
47
|
exports.WorkflowProcessorService = WorkflowProcessorService = WorkflowProcessorService_1 = __decorate([
|
|
209
48
|
(0, common_1.Injectable)(),
|
|
210
|
-
__metadata("design:paramtypes", [
|
|
211
|
-
|
|
212
|
-
common_3.ValueParserService,
|
|
213
|
-
state_machine_processor_service_1.StateMachineProcessorService,
|
|
214
|
-
persistence_1.WorkflowService,
|
|
215
|
-
namespace_processor_service_1.NamespaceProcessorService,
|
|
216
|
-
tool_execution_service_1.ToolExecutionService])
|
|
49
|
+
__metadata("design:paramtypes", [workflow_state_service_1.WorkflowStateService,
|
|
50
|
+
state_machine_processor_service_1.StateMachineProcessorService])
|
|
217
51
|
], WorkflowProcessorService);
|
|
218
52
|
//# sourceMappingURL=workflow-processor.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-processor.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/services/workflow-processor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"workflow-processor.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/services/workflow-processor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,uFAAiF;AACjF,8CAK2B;AAC3B,qEAAgE;AAGzD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAIzB;IACA;IAJO,MAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAEpE,YACU,qBAA2C,EAC3C,4BAA0D;QAD1D,0BAAqB,GAArB,qBAAqB,CAAsB;QAC3C,iCAA4B,GAA5B,4BAA4B,CAA8B;IACjE,CAAC;IAEJ,KAAK,CAAC,mBAAmB,CACvB,aAA0C,EAC1C,OAAyB;QAGzB,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,gBAAgB,CACvE,aAAa,EACb,OAAO,CACR,CAAC;QAEF,MAAM,QAAQ,GACZ,MAAM,IAAI,CAAC,4BAA4B,CAAC,mBAAmB,CACzD,OAAO,EACP,eAAe,EACf,aAAa,CACd,CAAC;QAEJ,IAAI,QAAQ,CAAC,MAAM,KAAK,sBAAa,CAAC,MAAM,EAAE,CAAC;YAC7C,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;QACvB,CAAC;QAED,IAAI,OAAO,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;aAAM,CAAC;YAEN,IAAI,QAAQ,CAAC,gBAAgB,EAAE,CAAC;gBAC9B,OAAO,CAAC,SAAS,GAAG;oBAClB,GAAG,OAAO,CAAC,SAAS;oBACpB,GAAG,QAAQ,CAAC,gBAAgB;iBAC7B,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AA3CY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAKsB,6CAAoB;QACb,8DAA4B;GALzD,wBAAwB,CA2CpC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WorkflowService } from '../../persistence';
|
|
2
|
+
import { ConfigElement, ContextInterface, WorkflowEntity, WorkflowType } from '@loopstack/shared';
|
|
3
|
+
export declare class WorkflowStateService {
|
|
4
|
+
private workflowService;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(workflowService: WorkflowService);
|
|
7
|
+
getWorkflowState(configElement: ConfigElement<WorkflowType>, context: ContextInterface): Promise<WorkflowEntity>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var WorkflowStateService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.WorkflowStateService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const persistence_1 = require("../../persistence");
|
|
16
|
+
let WorkflowStateService = WorkflowStateService_1 = class WorkflowStateService {
|
|
17
|
+
workflowService;
|
|
18
|
+
logger = new common_1.Logger(WorkflowStateService_1.name);
|
|
19
|
+
constructor(workflowService) {
|
|
20
|
+
this.workflowService = workflowService;
|
|
21
|
+
}
|
|
22
|
+
async getWorkflowState(configElement, context) {
|
|
23
|
+
const workflow = await this.workflowService
|
|
24
|
+
.createFindQuery(context.namespace?.id, {
|
|
25
|
+
name: configElement.name,
|
|
26
|
+
labels: context.labels,
|
|
27
|
+
})
|
|
28
|
+
.getOne();
|
|
29
|
+
if (workflow) {
|
|
30
|
+
return workflow;
|
|
31
|
+
}
|
|
32
|
+
return this.workflowService.create({
|
|
33
|
+
createdBy: context.userId,
|
|
34
|
+
labels: context.labels,
|
|
35
|
+
namespace: context.namespace ?? undefined,
|
|
36
|
+
pipelineId: context.pipelineId,
|
|
37
|
+
name: configElement.name,
|
|
38
|
+
title: configElement.config.title ?? configElement.name,
|
|
39
|
+
ui: configElement.config.ui ?? null,
|
|
40
|
+
index: context.index,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.WorkflowStateService = WorkflowStateService;
|
|
45
|
+
exports.WorkflowStateService = WorkflowStateService = WorkflowStateService_1 = __decorate([
|
|
46
|
+
(0, common_1.Injectable)(),
|
|
47
|
+
__metadata("design:paramtypes", [persistence_1.WorkflowService])
|
|
48
|
+
], WorkflowStateService);
|
|
49
|
+
//# sourceMappingURL=workflow-state.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-state.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/services/workflow-state.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,mDAAoD;AAS7C,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAGX;IAFH,MAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEhE,YAAoB,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAExD,KAAK,CAAC,gBAAgB,CACpB,aAA0C,EAC1C,OAAyB;QAEzB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe;aACxC,eAAe,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,EAAE;YACtC,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;aACD,MAAM,EAAE,CAAC;QAEZ,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;YACjC,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,SAAS;YACzC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,IAAI,EAAE,aAAa,CAAC,IAAI;YACxB,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,IAAI,aAAa,CAAC,IAAI;YACvD,EAAE,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,IAAI;YACnC,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA/BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAI0B,6BAAe;GAHzC,oBAAoB,CA+BhC"}
|
|
@@ -41,12 +41,12 @@ let AddNamespaceService = AddNamespaceService_1 = class AddNamespaceService {
|
|
|
41
41
|
createdBy: context.userId,
|
|
42
42
|
parent: context.namespace,
|
|
43
43
|
});
|
|
44
|
-
if (!workflow.
|
|
45
|
-
workflow.
|
|
44
|
+
if (!workflow.contextVariables) {
|
|
45
|
+
workflow.contextVariables = {};
|
|
46
46
|
}
|
|
47
47
|
const contextLabels = context.labels;
|
|
48
|
-
const workflowLabels = workflow.
|
|
49
|
-
workflow.
|
|
48
|
+
const workflowLabels = workflow.contextVariables.labels ?? [];
|
|
49
|
+
workflow.contextVariables.labels = [
|
|
50
50
|
...contextLabels,
|
|
51
51
|
...workflowLabels,
|
|
52
52
|
namespace.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-namespace.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/tool-services/add-namespace.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6BAAwB;AACxB,8CAQ2B;AAC3B,mDAAsD;AAEtD,MAAM,MAAM,GAAG,OAAC;KACb,MAAM,CAAC;IACN,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,yBAAgB,CAAC,CAAC;IAC9C,IAAI,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACzB,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,MAAM,GAAG,6BAAoB,CAAC,MAAM,EAAE,CAAC;AAOtC,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAGV;IAFH,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAE/D,YAAoB,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAE5D,KAAK,CAAC,KAAK,CACT,KAA6B,EAC7B,QAAoC,EACpC,OAAyB;QAEzB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACpD,IAAI,EAAE,KAAK,CAAC,KAAK;YACjB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,KAAK,CAAC,IAAI;YACpB,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,MAAM,EAAE,OAAO,CAAC,SAAS;SAC1B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"add-namespace.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/tool-services/add-namespace.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6BAAwB;AACxB,8CAQ2B;AAC3B,mDAAsD;AAEtD,MAAM,MAAM,GAAG,OAAC;KACb,MAAM,CAAC;IACN,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,yBAAgB,CAAC,CAAC;IAC9C,IAAI,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;CACzB,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,MAAM,GAAG,6BAAoB,CAAC,MAAM,EAAE,CAAC;AAOtC,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAGV;IAFH,MAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAE/D,YAAoB,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAE5D,KAAK,CAAC,KAAK,CACT,KAA6B,EAC7B,QAAoC,EACpC,OAAyB;QAEzB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC;YACpD,IAAI,EAAE,KAAK,CAAC,KAAK;YACjB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,KAAK,CAAC,IAAI;YACpB,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,MAAM,EAAE,OAAO,CAAC,SAAS;SAC1B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;YAC/B,QAAQ,CAAC,gBAAgB,GAAG,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;QACrC,MAAM,cAAc,GAAG,QAAQ,CAAC,gBAAgB,CAAC,MAAM,IAAI,EAAE,CAAC;QAE9D,QAAQ,CAAC,gBAAgB,CAAC,MAAM,GAAG;YACjC,GAAG,aAAa;YAChB,GAAG,cAAc;YACjB,SAAS,CAAC,IAAI;SACf,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC;QAE9D,OAAO;YACL,OAAO,EAAE,IAAI;YACb,QAAQ;SACT,CAAC;IACJ,CAAC;CACF,CAAA;AA3CY,kDAAmB;8BAAnB,mBAAmB;IAL/B,IAAA,mBAAU,GAAE;IACZ,IAAA,gBAAO,EAAC;QACP,MAAM;QACN,MAAM;KACP,CAAC;qCAIuC,+BAAiB;GAH7C,mBAAmB,CA2C/B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ContextInterface, ServiceInterface, ServiceCallResult, TransitionMetadataInterface } from '@loopstack/shared';
|
|
2
|
-
import {
|
|
3
|
-
import { ConfigurationService } from '../../configuration';
|
|
2
|
+
import { ConfigurationService, SchemaRegistry } from '../../configuration';
|
|
4
3
|
import { z } from 'zod';
|
|
5
4
|
import { WorkflowEntity } from '@loopstack/shared';
|
|
6
5
|
import { DocumentService } from '../../persistence';
|
|
@@ -8,26 +7,23 @@ import { TemplateExpressionEvaluatorService } from '../services';
|
|
|
8
7
|
declare const schema: z.ZodObject<{
|
|
9
8
|
document: z.ZodString;
|
|
10
9
|
name: z.ZodOptional<z.ZodString>;
|
|
11
|
-
addSuffix: z.ZodOptional<z.ZodBoolean>;
|
|
12
10
|
items: z.ZodArray<z.ZodAny, "many">;
|
|
13
11
|
}, "strict", z.ZodTypeAny, {
|
|
14
|
-
document: string;
|
|
15
12
|
items: any[];
|
|
13
|
+
document: string;
|
|
16
14
|
name?: string | undefined;
|
|
17
|
-
addSuffix?: boolean | undefined;
|
|
18
15
|
}, {
|
|
19
|
-
document: string;
|
|
20
16
|
items: any[];
|
|
17
|
+
document: string;
|
|
21
18
|
name?: string | undefined;
|
|
22
|
-
addSuffix?: boolean | undefined;
|
|
23
19
|
}>;
|
|
24
20
|
export declare class BatchCreateDocumentsService implements ServiceInterface {
|
|
25
|
-
private actionHelperService;
|
|
26
21
|
private loopConfigService;
|
|
27
22
|
private documentService;
|
|
28
23
|
private templateExpressionEvaluatorService;
|
|
24
|
+
private schemaRegistry;
|
|
29
25
|
private readonly logger;
|
|
30
|
-
constructor(
|
|
31
|
-
apply(props: z.infer<typeof schema>, workflow: WorkflowEntity | undefined, context: ContextInterface,
|
|
26
|
+
constructor(loopConfigService: ConfigurationService, documentService: DocumentService, templateExpressionEvaluatorService: TemplateExpressionEvaluatorService, schemaRegistry: SchemaRegistry);
|
|
27
|
+
apply(props: z.infer<typeof schema>, workflow: WorkflowEntity | undefined, context: ContextInterface, transitionData: TransitionMetadataInterface, parentArguments: any): Promise<ServiceCallResult>;
|
|
32
28
|
}
|
|
33
29
|
export {};
|
|
@@ -13,7 +13,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.BatchCreateDocumentsService = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const shared_1 = require("@loopstack/shared");
|
|
16
|
-
const common_2 = require("../../common");
|
|
17
16
|
const configuration_1 = require("../../configuration");
|
|
18
17
|
const zod_1 = require("zod");
|
|
19
18
|
const persistence_1 = require("../../persistence");
|
|
@@ -22,57 +21,70 @@ const services_1 = require("../services");
|
|
|
22
21
|
const config = zod_1.z
|
|
23
22
|
.object({
|
|
24
23
|
document: zod_1.z.string(),
|
|
25
|
-
name: zod_1.z.
|
|
26
|
-
addSuffix: zod_1.z.union([shared_1.ExpressionString, zod_1.z.boolean()]).optional(),
|
|
24
|
+
name: zod_1.z.string().optional(),
|
|
27
25
|
items: zod_1.z.union([shared_1.ExpressionString, zod_1.z.array(zod_1.z.any())]),
|
|
28
26
|
})
|
|
29
27
|
.strict();
|
|
30
28
|
const schema = zod_1.z
|
|
31
29
|
.object({
|
|
32
30
|
document: zod_1.z.string(),
|
|
33
|
-
name:
|
|
34
|
-
addSuffix: zod_1.z.boolean().optional(),
|
|
31
|
+
name: zod_1.z.string().optional(),
|
|
35
32
|
items: zod_1.z.array(zod_1.z.any()),
|
|
36
33
|
})
|
|
37
34
|
.strict();
|
|
38
35
|
let BatchCreateDocumentsService = BatchCreateDocumentsService_1 = class BatchCreateDocumentsService {
|
|
39
|
-
actionHelperService;
|
|
40
36
|
loopConfigService;
|
|
41
37
|
documentService;
|
|
42
38
|
templateExpressionEvaluatorService;
|
|
39
|
+
schemaRegistry;
|
|
43
40
|
logger = new common_1.Logger(BatchCreateDocumentsService_1.name);
|
|
44
|
-
constructor(
|
|
45
|
-
this.actionHelperService = actionHelperService;
|
|
41
|
+
constructor(loopConfigService, documentService, templateExpressionEvaluatorService, schemaRegistry) {
|
|
46
42
|
this.loopConfigService = loopConfigService;
|
|
47
43
|
this.documentService = documentService;
|
|
48
44
|
this.templateExpressionEvaluatorService = templateExpressionEvaluatorService;
|
|
45
|
+
this.schemaRegistry = schemaRegistry;
|
|
49
46
|
}
|
|
50
|
-
async apply(props, workflow, context,
|
|
47
|
+
async apply(props, workflow, context, transitionData, parentArguments) {
|
|
51
48
|
if (!workflow) {
|
|
52
49
|
throw new Error('Workflow is undefined');
|
|
53
50
|
}
|
|
54
|
-
const template = this.loopConfigService.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const template = this.loopConfigService.resolveConfig('documents', props.document, context.includes);
|
|
52
|
+
const documentSkeleton = this.templateExpressionEvaluatorService.parse((0, lodash_1.omit)(template.config, ['content']), {
|
|
53
|
+
arguments: parentArguments,
|
|
54
|
+
context,
|
|
55
|
+
workflow,
|
|
56
|
+
transition: transitionData,
|
|
57
|
+
}, {
|
|
58
|
+
schema: shared_1.DocumentSchema,
|
|
59
|
+
});
|
|
60
|
+
const zodSchema = this.schemaRegistry.getZodSchema(`${template.name}.content`);
|
|
59
61
|
const documents = [];
|
|
60
62
|
for (let index = 0; index < props.items.length; index++) {
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
63
|
-
throw
|
|
64
|
-
}
|
|
65
|
-
if (props.addSuffix) {
|
|
66
|
-
documentData.name += `-${index + 1}`;
|
|
63
|
+
const itemDocumentData = (0, lodash_1.merge)({}, documentSkeleton, props.items[index]);
|
|
64
|
+
if (!zodSchema && itemDocumentData.content) {
|
|
65
|
+
throw Error(`Document creates with content no schema defined.`);
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const parsedDocumentContent = itemDocumentData.content
|
|
68
|
+
? this.templateExpressionEvaluatorService.parse(itemDocumentData.content, {
|
|
69
|
+
arguments: parentArguments,
|
|
70
|
+
context,
|
|
71
|
+
workflow,
|
|
72
|
+
transition: transitionData,
|
|
73
|
+
}, {
|
|
74
|
+
schema: zodSchema,
|
|
75
|
+
})
|
|
76
|
+
: null;
|
|
77
|
+
const documentData = {
|
|
78
|
+
...itemDocumentData,
|
|
79
|
+
content: parsedDocumentContent,
|
|
80
|
+
};
|
|
81
|
+
documents.push(this.documentService.create(workflow, context, transitionData, documentData));
|
|
82
|
+
this.logger.debug(`Created document "${documentData.name}".`);
|
|
71
83
|
}
|
|
72
84
|
return {
|
|
73
85
|
success: true,
|
|
74
|
-
workflow,
|
|
75
86
|
persist: true,
|
|
87
|
+
workflow,
|
|
76
88
|
data: documents,
|
|
77
89
|
};
|
|
78
90
|
}
|
|
@@ -84,9 +96,9 @@ exports.BatchCreateDocumentsService = BatchCreateDocumentsService = BatchCreateD
|
|
|
84
96
|
config,
|
|
85
97
|
schema,
|
|
86
98
|
}),
|
|
87
|
-
__metadata("design:paramtypes", [
|
|
88
|
-
configuration_1.ConfigurationService,
|
|
99
|
+
__metadata("design:paramtypes", [configuration_1.ConfigurationService,
|
|
89
100
|
persistence_1.DocumentService,
|
|
90
|
-
services_1.TemplateExpressionEvaluatorService
|
|
101
|
+
services_1.TemplateExpressionEvaluatorService,
|
|
102
|
+
configuration_1.SchemaRegistry])
|
|
91
103
|
], BatchCreateDocumentsService);
|
|
92
104
|
//# sourceMappingURL=batch-create-documents.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch-create-documents.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/tool-services/batch-create-documents.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,
|
|
1
|
+
{"version":3,"file":"batch-create-documents.service.js","sourceRoot":"","sources":["../../../../src/modules/workflow-processor/tool-services/batch-create-documents.service.ts"],"names":[],"mappings":"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"}
|