@exaudeus/workrail 1.10.0 → 1.12.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/dist/application/services/compiler/resolve-templates.d.ts +13 -0
- package/dist/application/services/compiler/resolve-templates.js +54 -0
- package/dist/application/services/compiler/template-registry.d.ts +19 -0
- package/dist/application/services/compiler/template-registry.js +27 -0
- package/dist/application/services/workflow-compiler.d.ts +1 -0
- package/dist/application/services/workflow-compiler.js +12 -1
- package/dist/manifest.json +22 -6
- package/dist/types/workflow-definition.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
2
|
+
import type { TemplateRegistry, TemplateResolveError, TemplateExpandError } from './template-registry.js';
|
|
3
|
+
import type { WorkflowStepDefinition, LoopStepDefinition } from '../../../types/workflow-definition.js';
|
|
4
|
+
export type ResolveTemplatesPassError = {
|
|
5
|
+
readonly code: 'TEMPLATE_RESOLVE_ERROR';
|
|
6
|
+
readonly stepId: string;
|
|
7
|
+
readonly cause: TemplateResolveError;
|
|
8
|
+
} | {
|
|
9
|
+
readonly code: 'TEMPLATE_EXPAND_ERROR';
|
|
10
|
+
readonly stepId: string;
|
|
11
|
+
readonly cause: TemplateExpandError;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveTemplatesPass(steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[], registry: TemplateRegistry): Result<readonly (WorkflowStepDefinition | LoopStepDefinition)[], ResolveTemplatesPassError>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveTemplatesPass = resolveTemplatesPass;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const workflow_definition_js_1 = require("../../../types/workflow-definition.js");
|
|
6
|
+
function resolveStepTemplate(step, registry) {
|
|
7
|
+
if (!step.templateCall)
|
|
8
|
+
return (0, neverthrow_1.ok)([step]);
|
|
9
|
+
const { templateId, args } = step.templateCall;
|
|
10
|
+
const expanderResult = registry.resolve(templateId);
|
|
11
|
+
if (expanderResult.isErr()) {
|
|
12
|
+
return (0, neverthrow_1.err)({
|
|
13
|
+
code: 'TEMPLATE_RESOLVE_ERROR',
|
|
14
|
+
stepId: step.id,
|
|
15
|
+
cause: expanderResult.error,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const expandResult = expanderResult.value(step.id, args ?? {});
|
|
19
|
+
if (expandResult.isErr()) {
|
|
20
|
+
return (0, neverthrow_1.err)({
|
|
21
|
+
code: 'TEMPLATE_EXPAND_ERROR',
|
|
22
|
+
stepId: step.id,
|
|
23
|
+
cause: expandResult.error,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return (0, neverthrow_1.ok)(expandResult.value);
|
|
27
|
+
}
|
|
28
|
+
function resolveTemplatesPass(steps, registry) {
|
|
29
|
+
const resolved = [];
|
|
30
|
+
for (const step of steps) {
|
|
31
|
+
if ((0, workflow_definition_js_1.isLoopStepDefinition)(step)) {
|
|
32
|
+
if (Array.isArray(step.body)) {
|
|
33
|
+
const bodyResolved = [];
|
|
34
|
+
for (const bodyStep of step.body) {
|
|
35
|
+
const res = resolveStepTemplate(bodyStep, registry);
|
|
36
|
+
if (res.isErr())
|
|
37
|
+
return (0, neverthrow_1.err)(res.error);
|
|
38
|
+
bodyResolved.push(...res.value);
|
|
39
|
+
}
|
|
40
|
+
resolved.push({ ...step, body: bodyResolved });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
resolved.push(step);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const res = resolveStepTemplate(step, registry);
|
|
48
|
+
if (res.isErr())
|
|
49
|
+
return (0, neverthrow_1.err)(res.error);
|
|
50
|
+
resolved.push(...res.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return (0, neverthrow_1.ok)(resolved);
|
|
54
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Result } from 'neverthrow';
|
|
2
|
+
import type { WorkflowStepDefinition } from '../../../types/workflow-definition.js';
|
|
3
|
+
export type TemplateExpander = (callerId: string, args: Readonly<Record<string, unknown>>) => Result<readonly WorkflowStepDefinition[], TemplateExpandError>;
|
|
4
|
+
export type TemplateExpandError = {
|
|
5
|
+
readonly code: 'TEMPLATE_EXPAND_FAILED';
|
|
6
|
+
readonly templateId: string;
|
|
7
|
+
readonly message: string;
|
|
8
|
+
};
|
|
9
|
+
export type TemplateResolveError = {
|
|
10
|
+
readonly code: 'UNKNOWN_TEMPLATE';
|
|
11
|
+
readonly templateId: string;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
};
|
|
14
|
+
export interface TemplateRegistry {
|
|
15
|
+
readonly resolve: (templateId: string) => Result<TemplateExpander, TemplateResolveError>;
|
|
16
|
+
readonly has: (templateId: string) => boolean;
|
|
17
|
+
readonly knownIds: () => readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export declare function createTemplateRegistry(): TemplateRegistry;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTemplateRegistry = createTemplateRegistry;
|
|
4
|
+
const neverthrow_1 = require("neverthrow");
|
|
5
|
+
const TEMPLATE_DEFINITIONS = new Map();
|
|
6
|
+
function createTemplateRegistry() {
|
|
7
|
+
const knownIds = [...TEMPLATE_DEFINITIONS.keys()];
|
|
8
|
+
return {
|
|
9
|
+
resolve(templateId) {
|
|
10
|
+
const expander = TEMPLATE_DEFINITIONS.get(templateId);
|
|
11
|
+
if (!expander) {
|
|
12
|
+
return (0, neverthrow_1.err)({
|
|
13
|
+
code: 'UNKNOWN_TEMPLATE',
|
|
14
|
+
templateId,
|
|
15
|
+
message: `Unknown template '${templateId}'. Known templates: ${knownIds.length > 0 ? knownIds.join(', ') : '(none)'}`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return (0, neverthrow_1.ok)(expander);
|
|
19
|
+
},
|
|
20
|
+
has(templateId) {
|
|
21
|
+
return TEMPLATE_DEFINITIONS.has(templateId);
|
|
22
|
+
},
|
|
23
|
+
knownIds() {
|
|
24
|
+
return knownIds;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -17,6 +17,7 @@ export interface CompiledWorkflow {
|
|
|
17
17
|
export declare class WorkflowCompiler {
|
|
18
18
|
private readonly refRegistry;
|
|
19
19
|
private readonly featureRegistry;
|
|
20
|
+
private readonly templateRegistry;
|
|
20
21
|
compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
|
|
21
22
|
private deriveConditionSource;
|
|
22
23
|
private resolveLoopBody;
|
|
@@ -17,13 +17,24 @@ const resolve_refs_1 = require("./compiler/resolve-refs");
|
|
|
17
17
|
const ref_registry_1 = require("./compiler/ref-registry");
|
|
18
18
|
const resolve_features_1 = require("./compiler/resolve-features");
|
|
19
19
|
const feature_registry_1 = require("./compiler/feature-registry");
|
|
20
|
+
const resolve_templates_1 = require("./compiler/resolve-templates");
|
|
21
|
+
const template_registry_1 = require("./compiler/template-registry");
|
|
20
22
|
let WorkflowCompiler = class WorkflowCompiler {
|
|
21
23
|
constructor() {
|
|
22
24
|
this.refRegistry = (0, ref_registry_1.createRefRegistry)();
|
|
23
25
|
this.featureRegistry = (0, feature_registry_1.createFeatureRegistry)();
|
|
26
|
+
this.templateRegistry = (0, template_registry_1.createTemplateRegistry)();
|
|
24
27
|
}
|
|
25
28
|
compile(workflow) {
|
|
26
|
-
const
|
|
29
|
+
const templatesResult = (0, resolve_templates_1.resolveTemplatesPass)(workflow.definition.steps, this.templateRegistry);
|
|
30
|
+
if (templatesResult.isErr()) {
|
|
31
|
+
const e = templatesResult.error;
|
|
32
|
+
const message = e.code === 'TEMPLATE_RESOLVE_ERROR'
|
|
33
|
+
? `Step '${e.stepId}': template error — ${e.cause.message}`
|
|
34
|
+
: `Step '${e.stepId}': template expansion error — ${e.cause.message}`;
|
|
35
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(message));
|
|
36
|
+
}
|
|
37
|
+
const featuresResult = (0, resolve_features_1.resolveFeaturesPass)(templatesResult.value, workflow.definition.features ?? [], this.featureRegistry);
|
|
27
38
|
if (featuresResult.isErr()) {
|
|
28
39
|
const e = featuresResult.error;
|
|
29
40
|
const message = e.code === 'FEATURE_RESOLVE_ERROR'
|
package/dist/manifest.json
CHANGED
|
@@ -41,6 +41,22 @@
|
|
|
41
41
|
"sha256": "9f9e2a44cec6dfd6d870a645b38e4faf52e17c9ef3654fd600ebcd9943f532c5",
|
|
42
42
|
"bytes": 4214
|
|
43
43
|
},
|
|
44
|
+
"application/services/compiler/resolve-templates.d.ts": {
|
|
45
|
+
"sha256": "623e4b9e7b65c1cbe8a6acee232ba3fa7b11c9394f22a77c7443a02681b0a0a8",
|
|
46
|
+
"bytes": 767
|
|
47
|
+
},
|
|
48
|
+
"application/services/compiler/resolve-templates.js": {
|
|
49
|
+
"sha256": "2d7bef8627cd933fa265d9faf9b0d6ced860bd66b39793af7ffa97956ba38a09",
|
|
50
|
+
"bytes": 1997
|
|
51
|
+
},
|
|
52
|
+
"application/services/compiler/template-registry.d.ts": {
|
|
53
|
+
"sha256": "16221e2671a95456abfd875fc7caceb40058f351a5a371e13acf53def2f77b24",
|
|
54
|
+
"bytes": 873
|
|
55
|
+
},
|
|
56
|
+
"application/services/compiler/template-registry.js": {
|
|
57
|
+
"sha256": "79ea2925e1d4a003a0b07a5f4c99cdc5fb8aa73e0b2be4e239435bf7bf1ffb13",
|
|
58
|
+
"bytes": 972
|
|
59
|
+
},
|
|
44
60
|
"application/services/enhanced-error-service.d.ts": {
|
|
45
61
|
"sha256": "b6fe8fad92717f0962f87aa9c0f88277bf28fe2b5e3cfd7875612ee57eb8c684",
|
|
46
62
|
"bytes": 601
|
|
@@ -82,12 +98,12 @@
|
|
|
82
98
|
"bytes": 31038
|
|
83
99
|
},
|
|
84
100
|
"application/services/workflow-compiler.d.ts": {
|
|
85
|
-
"sha256": "
|
|
86
|
-
"bytes":
|
|
101
|
+
"sha256": "d1371ca551a908a7f95078d20e02203d7b24525659d9160d50b06fd2708ca4a9",
|
|
102
|
+
"bytes": 1101
|
|
87
103
|
},
|
|
88
104
|
"application/services/workflow-compiler.js": {
|
|
89
|
-
"sha256": "
|
|
90
|
-
"bytes":
|
|
105
|
+
"sha256": "4fad72793de969fce4f269d154fc5743a329fc1e015e63b3c6e6ba12bcdeafc7",
|
|
106
|
+
"bytes": 8017
|
|
91
107
|
},
|
|
92
108
|
"application/services/workflow-interpreter.d.ts": {
|
|
93
109
|
"sha256": "56b5b5ad06d42096deba9f0abe7642c18a355a1e598749aab1730df4e9847674",
|
|
@@ -1098,8 +1114,8 @@
|
|
|
1098
1114
|
"bytes": 395
|
|
1099
1115
|
},
|
|
1100
1116
|
"types/workflow-definition.d.ts": {
|
|
1101
|
-
"sha256": "
|
|
1102
|
-
"bytes":
|
|
1117
|
+
"sha256": "13681513404db7396b07ded2c72fac53a9e42a76e5016c34f0fc77fc6591aa5a",
|
|
1118
|
+
"bytes": 3951
|
|
1103
1119
|
},
|
|
1104
1120
|
"types/workflow-definition.js": {
|
|
1105
1121
|
"sha256": "e269d62f27b7f37f870183d6b77800b7aa1e22dabc894374bab8f34db049a55b",
|
|
@@ -18,10 +18,15 @@ export interface WorkflowStepDefinition {
|
|
|
18
18
|
readonly validationCriteria?: ValidationCriteria;
|
|
19
19
|
readonly outputContract?: OutputContract;
|
|
20
20
|
readonly notesOptional?: boolean;
|
|
21
|
+
readonly templateCall?: TemplateCall;
|
|
21
22
|
readonly functionDefinitions?: readonly FunctionDefinition[];
|
|
22
23
|
readonly functionCalls?: readonly FunctionCall[];
|
|
23
24
|
readonly functionReferences?: readonly string[];
|
|
24
25
|
}
|
|
26
|
+
export interface TemplateCall {
|
|
27
|
+
readonly templateId: string;
|
|
28
|
+
readonly args?: Readonly<Record<string, unknown>>;
|
|
29
|
+
}
|
|
25
30
|
export interface LoopStepDefinition extends WorkflowStepDefinition {
|
|
26
31
|
readonly type: 'loop';
|
|
27
32
|
readonly loop: LoopConfigDefinition;
|