@pogodisco/zephyr 1.5.17 → 1.5.19
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/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/workflow-module.d.ts +15 -17
- package/dist/workflow-module.d.ts.map +1 -1
- package/dist/workflow-module.js +489 -143
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Module } from "./workflow-module.js";
|
|
2
2
|
export declare function generateWorkflowId(name: string): string;
|
|
3
|
-
export declare function exposeAll<Name extends string, M extends Module<any, any, any, any
|
|
4
|
-
export declare function exposeAllAs<Name extends string, M extends Module<any, any, any, any
|
|
3
|
+
export declare function exposeAll<Name extends string, M extends Module<any, any, any, any>>(name: Name, mod: M): Record<`${Name}.${keyof M["workflows"] & string}`, `${Name}.${keyof M["workflows"] & string}`>;
|
|
4
|
+
export declare function exposeAllAs<Name extends string, M extends Module<any, any, any, any>>(name: Name, mod: M): Record<keyof M["workflows"] & string, `${Name}.${keyof M["workflows"] & string}`>;
|
|
5
5
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,UAI9C;AAED,wBAAgB,SAAS,CACvB,IAAI,SAAS,MAAM,EACnB,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,UAI9C;AAED,wBAAgB,SAAS,CACvB,IAAI,SAAS,MAAM,EACnB,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACpC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,kGAWnB;AAED,wBAAgB,WAAW,CACzB,IAAI,SAAS,MAAM,EACnB,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACpC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,qFAUnB"}
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import { ActionRegistry, ServiceRegistry, Executor, Simplify, WorkflowObserver } from "./types.js";
|
|
2
2
|
import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
|
|
3
3
|
type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (x: infer I) => any ? I : never;
|
|
4
|
-
|
|
4
|
+
type EnsureWorkflowShape<T> = {
|
|
5
5
|
[K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any> ? T[K] : never;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never ? {} : Simplify<EnsureWorkflowShape<UnionToIntersection<{
|
|
8
8
|
[D in keyof Deps & string]: {
|
|
9
|
-
[K in keyof Deps[D]["
|
|
9
|
+
[K in keyof Deps[D]["workflows"] & string as `${D}.${K}`]: Deps[D]["workflows"][K];
|
|
10
10
|
};
|
|
11
11
|
}[keyof Deps & string]>>>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
]
|
|
20
|
-
[K in keyof Deps]: Deps[K] extends Module<any, infer S, any, infer SubDeps, any> ? S & ServicesFromDepsRecursive<SubDeps> : never;
|
|
12
|
+
type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
|
|
13
|
+
type ModuleShape = Record<string, AnyWorkflow>;
|
|
14
|
+
type ModuleMap = Record<string, Module<any, any, any, any>>;
|
|
15
|
+
type FinalServices<S extends ServiceRegistry, Deps extends ModuleMap> = S & ServicesFromDepsRecursive<Deps>;
|
|
16
|
+
type ServicesFromDepsRecursive<Deps extends ModuleMap> = [keyof Deps] extends [
|
|
17
|
+
never
|
|
18
|
+
] ? {} : UnionToIntersection<{
|
|
19
|
+
[K in keyof Deps]: Deps[K] extends Module<any, infer S, any, infer SubDeps> ? S & ServicesFromDepsRecursive<SubDeps> : never;
|
|
21
20
|
}[keyof Deps]>;
|
|
22
21
|
export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
|
|
23
22
|
export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
|
|
24
23
|
export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
|
|
25
|
-
export type Module<Reg extends ActionRegistry, S extends ServiceRegistry, Own extends ModuleShape, Deps extends ModuleMap, Public extends ModuleShape> = {
|
|
24
|
+
export type Module<Reg extends ActionRegistry, S extends ServiceRegistry, Own extends ModuleShape, Deps extends ModuleMap, Public extends ModuleShape = Own> = {
|
|
26
25
|
workflows: Own;
|
|
27
|
-
__public: Public;
|
|
28
26
|
__getExecutor: () => Executor;
|
|
29
27
|
createRuntime: (config: {
|
|
30
28
|
services: FinalServices<S, Deps>;
|
|
@@ -36,14 +34,14 @@ export type Module<Reg extends ActionRegistry, S extends ServiceRegistry, Own ex
|
|
|
36
34
|
getServices: () => FinalServices<S, Deps>;
|
|
37
35
|
};
|
|
38
36
|
};
|
|
39
|
-
|
|
37
|
+
type ModuleContext<Reg extends ActionRegistry, WFReg extends Record<string, WorkflowDef<any, any, any, any, any>>, S extends ServiceRegistry> = {
|
|
40
38
|
wf: ReturnType<typeof createWorkflow<Reg, WFReg, S>>;
|
|
41
39
|
services: S;
|
|
42
40
|
};
|
|
43
|
-
|
|
41
|
+
type ExposedWorkflows<Own extends ModuleShape, Use extends ModuleMap, Expose extends Record<string, keyof DepWorkflows<Use>> | undefined> = Own & (Expose extends Record<string, keyof DepWorkflows<Use>> ? {
|
|
44
42
|
[K in keyof Expose]: DepWorkflows<Use>[Expose[K]];
|
|
45
43
|
} : {});
|
|
46
|
-
export declare function createModuleFactory<S extends ServiceRegistry>(): <Reg extends ActionRegistry, Use extends ModuleMap, Own extends ModuleShape, Expose extends Record<string, keyof DepWorkflows<Use>> | undefined = undefined>(config: {
|
|
44
|
+
export declare function createModuleFactory<S extends ServiceRegistry>(): <Reg extends ActionRegistry = Record<string, any>, Use extends ModuleMap = {}, Own extends ModuleShape = {}, Expose extends Record<string, keyof DepWorkflows<Use>> | undefined = undefined>(config: {
|
|
47
45
|
actionRegistry: Reg;
|
|
48
46
|
use?: Use;
|
|
49
47
|
expose?: Expose;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-module.d.ts","sourceRoot":"","sources":["../src/workflow-module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-module.d.ts","sourceRoot":"","sources":["../src/workflow-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EAGd,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAEhC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,GAAG,GAAG,KAAK,CAAC,SAAS,CAC5E,CAAC,EAAE,MAAM,CAAC,KACP,GAAG,GACJ,CAAC,GACD,KAAK,CAAC;AAKV,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAC3B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,EAAE,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B,MAAM,EAAE,CACN,GAAG,EAAE,aAAa,CAAC,OAAO,MAAM,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KACnE,GAAG,CAAC;CACV,KAAG,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAGjE"}
|
package/dist/workflow-module.js
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
+
import { createWorkflow, } from "./workflow-composer.js";
|
|
2
|
+
import { executeWorkflow } from "./workflow-executor.js";
|
|
3
|
+
function createModule(config) {
|
|
4
|
+
const deps = (config.use ?? {});
|
|
5
|
+
const wf = createWorkflow();
|
|
6
|
+
const own = config.define({
|
|
7
|
+
wf,
|
|
8
|
+
services: {},
|
|
9
|
+
});
|
|
10
|
+
// function buildWorkflowMap(): WorkflowRegistry<Own, Use> {
|
|
11
|
+
// const depWFs = Object.fromEntries(
|
|
12
|
+
// Object.entries(deps).flatMap(([name, mod]) =>
|
|
13
|
+
// Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
|
|
14
|
+
// ),
|
|
15
|
+
// );
|
|
16
|
+
//
|
|
17
|
+
// const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
18
|
+
//
|
|
19
|
+
// const publicMap = own;
|
|
20
|
+
// return { internal, publicMap };
|
|
21
|
+
// }
|
|
22
|
+
function buildWorkflowMap() {
|
|
23
|
+
const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([name, mod]) => Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf])));
|
|
24
|
+
// const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
25
|
+
// const exposed = Object.fromEntries(
|
|
26
|
+
// Object.entries(config.expose ?? {}).map(([alias, key]) => [
|
|
27
|
+
// alias,
|
|
28
|
+
// internal[key], // reuse already resolved workflow
|
|
29
|
+
// ]),
|
|
30
|
+
// );
|
|
31
|
+
//
|
|
32
|
+
const internalBase = { ...own, ...depWFs };
|
|
33
|
+
const exposed = {};
|
|
34
|
+
if (config.expose) {
|
|
35
|
+
for (const alias in config.expose) {
|
|
36
|
+
const key = config.expose[alias];
|
|
37
|
+
exposed[alias] = internalBase[key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const internal = {
|
|
41
|
+
...internalBase,
|
|
42
|
+
...exposed,
|
|
43
|
+
};
|
|
44
|
+
// if (config.expose) {
|
|
45
|
+
// for (const alias in config.expose) {
|
|
46
|
+
// const key = config.expose[alias];
|
|
47
|
+
// exposed[alias] = internal[key];
|
|
48
|
+
// }
|
|
49
|
+
// }
|
|
50
|
+
const publicMap = { ...own, ...exposed };
|
|
51
|
+
return { internal, publicMap };
|
|
52
|
+
}
|
|
53
|
+
const { internal, publicMap } = buildWorkflowMap();
|
|
54
|
+
const depsExecutors = Object.fromEntries(Object.entries(deps).map(([name, mod]) => [name, mod.__getExecutor()]));
|
|
55
|
+
const executor = {
|
|
56
|
+
run(wfId, input, services, observers = []) {
|
|
57
|
+
if (!(wfId in publicMap)) {
|
|
58
|
+
throw new Error(`Workflow not in public: ${wfId}`);
|
|
59
|
+
}
|
|
60
|
+
const workflow = internal[wfId];
|
|
61
|
+
if (!workflow) {
|
|
62
|
+
throw new Error(`Workflow not found: ${String(wfId)}`);
|
|
63
|
+
}
|
|
64
|
+
return executeWorkflow({
|
|
65
|
+
workflow,
|
|
66
|
+
actionRegistry: config.actionRegistry,
|
|
67
|
+
depsExecutors,
|
|
68
|
+
input,
|
|
69
|
+
services,
|
|
70
|
+
observers,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
workflows: own,
|
|
76
|
+
__getExecutor: () => executor,
|
|
77
|
+
createRuntime({ services }) {
|
|
78
|
+
let runtimeActions = config.actionRegistry;
|
|
79
|
+
// const runtimeService = createServiceRegisty(services)
|
|
80
|
+
return {
|
|
81
|
+
run: async (
|
|
82
|
+
// run: async <K extends keyof WorkflowRegistry<Own, Use>>(
|
|
83
|
+
workflowId, input,
|
|
84
|
+
// input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
|
|
85
|
+
// input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
|
|
86
|
+
observers = []) => {
|
|
87
|
+
return executor.run(workflowId, input, services, observers);
|
|
88
|
+
},
|
|
89
|
+
// make it same, practically nothing changes but naming, and what context holds
|
|
90
|
+
getServices: () => ({ ...services }),
|
|
91
|
+
setActionRegistry(reg) {
|
|
92
|
+
runtimeActions = reg;
|
|
93
|
+
// ⚠️ optional: if you REALLY want override, you'd need:
|
|
94
|
+
// executor.actions = reg
|
|
95
|
+
// but better keep actions immutable
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/* ------------------------------------------------ */
|
|
102
|
+
/* FACTORY (FIXED) */
|
|
103
|
+
/* ------------------------------------------------ */
|
|
104
|
+
export function createModuleFactory() {
|
|
105
|
+
return function (config) {
|
|
106
|
+
return createModule(config);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//
|
|
110
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1
111
|
// import {
|
|
2
112
|
// ActionRegistry,
|
|
3
113
|
// ServiceRegistry,
|
|
@@ -21,6 +131,366 @@
|
|
|
21
131
|
// /* WORKFLOW REGISTRY TYPES */
|
|
22
132
|
// /* ------------------------------------------------ */
|
|
23
133
|
//
|
|
134
|
+
// export type EnsureWorkflowShape<T> = {
|
|
135
|
+
// [K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any>
|
|
136
|
+
// ? T[K]
|
|
137
|
+
// : never;
|
|
138
|
+
// };
|
|
139
|
+
//
|
|
140
|
+
// // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
141
|
+
// // ? {}
|
|
142
|
+
// // : Simplify<
|
|
143
|
+
// // EnsureWorkflowShape<
|
|
144
|
+
// // UnionToIntersection<
|
|
145
|
+
// // {
|
|
146
|
+
// // [D in keyof Deps & string]: {
|
|
147
|
+
// // [K in keyof Deps[D]["__public"] &
|
|
148
|
+
// // string as `${D}.${K}`]: Deps[D]["__public"][K];
|
|
149
|
+
// // };
|
|
150
|
+
// // }[keyof Deps & string]
|
|
151
|
+
// // >
|
|
152
|
+
// // >
|
|
153
|
+
// // >;
|
|
154
|
+
//
|
|
155
|
+
// // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
156
|
+
// // ? {}
|
|
157
|
+
// // : Simplify<
|
|
158
|
+
// // EnsureWorkflowShape<
|
|
159
|
+
// // UnionToIntersection<
|
|
160
|
+
// // {
|
|
161
|
+
// // [D in keyof Deps & string]: {
|
|
162
|
+
// // [K in keyof Deps[D]["__public"] &
|
|
163
|
+
// // string as `${D}.${K}`]: Deps[D]["__public"][K];
|
|
164
|
+
// // };
|
|
165
|
+
// // }[keyof Deps & string]
|
|
166
|
+
// // >
|
|
167
|
+
// // >
|
|
168
|
+
// // >;
|
|
169
|
+
// // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
170
|
+
// // ? {}
|
|
171
|
+
// // : Simplify<{
|
|
172
|
+
// // [D in keyof Deps as `${D & string}.${keyof Deps[D]["__public"] & string}`]: Deps[D]["__public"][keyof Deps[D]["__public"]];
|
|
173
|
+
// // }>;
|
|
174
|
+
// //
|
|
175
|
+
//
|
|
176
|
+
// // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
177
|
+
// // ? {}
|
|
178
|
+
// // : Simplify<
|
|
179
|
+
// // // Just create the object directly without intersection
|
|
180
|
+
// // Omit<
|
|
181
|
+
// // {
|
|
182
|
+
// // [D in keyof Deps & string]: {
|
|
183
|
+
// // [K in keyof Deps[D]["__public"] &
|
|
184
|
+
// // string as `${D}.${K}`]: Deps[D]["__public"][K];
|
|
185
|
+
// // };
|
|
186
|
+
// // }[keyof Deps & string],
|
|
187
|
+
// // never
|
|
188
|
+
// // >
|
|
189
|
+
// // >;
|
|
190
|
+
//
|
|
191
|
+
// // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
192
|
+
// // ? {}
|
|
193
|
+
// // : Simplify<
|
|
194
|
+
// // EnsureWorkflowShape<
|
|
195
|
+
// // {
|
|
196
|
+
// // [D in keyof Deps & string]: {
|
|
197
|
+
// // [K in keyof Deps[D]["__public"] &
|
|
198
|
+
// // string as `${D}.${K}`]: Deps[D]["__public"][K];
|
|
199
|
+
// // };
|
|
200
|
+
// // }[keyof Deps & string]
|
|
201
|
+
// // >
|
|
202
|
+
// // >;
|
|
203
|
+
//
|
|
204
|
+
// export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
|
|
205
|
+
// ? {}
|
|
206
|
+
// : Simplify<
|
|
207
|
+
// EnsureWorkflowShape<
|
|
208
|
+
// // Just use Omit + intersection - it's the same as UnionToIntersection but TypeScript handles it better
|
|
209
|
+
// {
|
|
210
|
+
// [D in keyof Deps & string]: {
|
|
211
|
+
// [K in keyof Deps[D]["__public"] &
|
|
212
|
+
// string as `${D}.${K}`]: Deps[D]["__public"][K];
|
|
213
|
+
// };
|
|
214
|
+
// }[keyof Deps & string] extends infer U
|
|
215
|
+
// ? Omit<U, never>
|
|
216
|
+
// : never
|
|
217
|
+
// >
|
|
218
|
+
// >;
|
|
219
|
+
// export type WorkflowRegistry<
|
|
220
|
+
// Own extends ModuleShape,
|
|
221
|
+
// Deps extends ModuleMap,
|
|
222
|
+
// > = Own & DepWorkflows<Deps>;
|
|
223
|
+
//
|
|
224
|
+
// /* ------------------------------------------------ */
|
|
225
|
+
// /* MODULE TYPES */
|
|
226
|
+
// /* ------------------------------------------------ */
|
|
227
|
+
//
|
|
228
|
+
// export type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
|
|
229
|
+
// export type ModuleShape = Record<string, AnyWorkflow>;
|
|
230
|
+
// export type ModuleMap = Record<string, Module<any, any, any, any, any>>;
|
|
231
|
+
//
|
|
232
|
+
// export type FinalServices<
|
|
233
|
+
// S extends ServiceRegistry,
|
|
234
|
+
// Deps extends ModuleMap,
|
|
235
|
+
// > = S & ServicesFromDepsRecursive<Deps>;
|
|
236
|
+
//
|
|
237
|
+
// export type ServicesFromDepsRecursive<Deps extends ModuleMap> = [
|
|
238
|
+
// keyof Deps,
|
|
239
|
+
// ] extends [never]
|
|
240
|
+
// ? {} // no deps
|
|
241
|
+
// : UnionToIntersection<
|
|
242
|
+
// {
|
|
243
|
+
// [K in keyof Deps]: Deps[K] extends Module<
|
|
244
|
+
// any,
|
|
245
|
+
// infer S,
|
|
246
|
+
// any,
|
|
247
|
+
// infer SubDeps,
|
|
248
|
+
// any
|
|
249
|
+
// >
|
|
250
|
+
// ? S & ServicesFromDepsRecursive<SubDeps>
|
|
251
|
+
// : never;
|
|
252
|
+
// }[keyof Deps]
|
|
253
|
+
// >;
|
|
254
|
+
//
|
|
255
|
+
// /* ------------------------------------------------ */
|
|
256
|
+
// /* WORKFLOW IO TYPES */
|
|
257
|
+
// /* ------------------------------------------------ */
|
|
258
|
+
//
|
|
259
|
+
// export type WorkflowInput<W> =
|
|
260
|
+
// W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
|
|
261
|
+
//
|
|
262
|
+
// export type WorkflowResults<W> =
|
|
263
|
+
// W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
|
|
264
|
+
//
|
|
265
|
+
// export type WorkflowOutput<W> =
|
|
266
|
+
// W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
|
|
267
|
+
//
|
|
268
|
+
// /* ------------------------------------------------ */
|
|
269
|
+
// /* MODULE RUNTIME */
|
|
270
|
+
// /* ------------------------------------------------ */
|
|
271
|
+
//
|
|
272
|
+
// export type Module<
|
|
273
|
+
// Reg extends ActionRegistry,
|
|
274
|
+
// S extends ServiceRegistry,
|
|
275
|
+
// Own extends ModuleShape,
|
|
276
|
+
// Deps extends ModuleMap,
|
|
277
|
+
// Public extends ModuleShape,
|
|
278
|
+
// > = {
|
|
279
|
+
// workflows: Own;
|
|
280
|
+
//
|
|
281
|
+
// __public: Public;
|
|
282
|
+
// __getExecutor: () => Executor;
|
|
283
|
+
//
|
|
284
|
+
// createRuntime: (config: { services: FinalServices<S, Deps> }) => {
|
|
285
|
+
// run: <K extends keyof Public>(
|
|
286
|
+
// workflow: K,
|
|
287
|
+
// input: WorkflowInput<Public[K]>,
|
|
288
|
+
// observers?: WorkflowObserver<Reg>[],
|
|
289
|
+
// ) => Promise<{
|
|
290
|
+
// output: WorkflowOutput<Public[K]>;
|
|
291
|
+
// extras: Record<string, any>;
|
|
292
|
+
// }>;
|
|
293
|
+
//
|
|
294
|
+
// getServices: () => FinalServices<S, Deps>;
|
|
295
|
+
// };
|
|
296
|
+
// };
|
|
297
|
+
//
|
|
298
|
+
// /* ------------------------------------------------ */
|
|
299
|
+
// /* MODULE CONTEXT (FIXED) */
|
|
300
|
+
// /* ------------------------------------------------ */
|
|
301
|
+
//
|
|
302
|
+
// export type ModuleContext<
|
|
303
|
+
// Reg extends ActionRegistry,
|
|
304
|
+
// WFReg extends Record<string, WorkflowDef<any, any, any, any, any>>,
|
|
305
|
+
// S extends ServiceRegistry,
|
|
306
|
+
// > = {
|
|
307
|
+
// wf: ReturnType<typeof createWorkflow<Reg, WFReg, S>>;
|
|
308
|
+
// services: S;
|
|
309
|
+
// };
|
|
310
|
+
//
|
|
311
|
+
// export type ExposedWorkflows<
|
|
312
|
+
// Own extends ModuleShape,
|
|
313
|
+
// Use extends ModuleMap,
|
|
314
|
+
// Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
|
|
315
|
+
// > = Own &
|
|
316
|
+
// (Expose extends Record<string, keyof DepWorkflows<Use>>
|
|
317
|
+
// ? {
|
|
318
|
+
// [K in keyof Expose]: DepWorkflows<Use>[Expose[K]];
|
|
319
|
+
// }
|
|
320
|
+
// : {});
|
|
321
|
+
// function createModule<
|
|
322
|
+
// Reg extends ActionRegistry,
|
|
323
|
+
// S extends ServiceRegistry,
|
|
324
|
+
// Use extends ModuleMap,
|
|
325
|
+
// Own extends ModuleShape,
|
|
326
|
+
// Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
|
|
327
|
+
// >(config: {
|
|
328
|
+
// actionRegistry: Reg;
|
|
329
|
+
// use?: Use;
|
|
330
|
+
// expose?: Expose;
|
|
331
|
+
// define: (ctx: ModuleContext<Reg, DepWorkflows<Use>, S>) => Own;
|
|
332
|
+
// }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose> & ModuleShape> {
|
|
333
|
+
// const deps = (config.use ?? {}) as Use;
|
|
334
|
+
//
|
|
335
|
+
// type WFReg = DepWorkflows<Use>;
|
|
336
|
+
//
|
|
337
|
+
// const wf = createWorkflow<Reg, WFReg, S>();
|
|
338
|
+
//
|
|
339
|
+
// const own = config.define({
|
|
340
|
+
// wf,
|
|
341
|
+
// services: {} as S,
|
|
342
|
+
// });
|
|
343
|
+
//
|
|
344
|
+
// function mergePublic<
|
|
345
|
+
// Own extends ModuleShape,
|
|
346
|
+
// Use extends ModuleMap,
|
|
347
|
+
// Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
|
|
348
|
+
// >(
|
|
349
|
+
// own: Own,
|
|
350
|
+
// exposed: Record<string, AnyWorkflow>,
|
|
351
|
+
// ): ExposedWorkflows<Own, Use, Expose> {
|
|
352
|
+
// return { ...own, ...exposed } as any;
|
|
353
|
+
// }
|
|
354
|
+
//
|
|
355
|
+
// function buildWorkflowMap() {
|
|
356
|
+
// const depWFs = Object.fromEntries(
|
|
357
|
+
// Object.entries(deps).flatMap(([name, mod]) =>
|
|
358
|
+
// Object.entries(mod.__public).map(([k, wf]) => [`${name}.${k}`, wf]),
|
|
359
|
+
// ),
|
|
360
|
+
// );
|
|
361
|
+
//
|
|
362
|
+
// const internalBase = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
363
|
+
//
|
|
364
|
+
// const exposed = {} as Record<string, AnyWorkflow>;
|
|
365
|
+
//
|
|
366
|
+
// if (config.expose) {
|
|
367
|
+
// for (const alias in config.expose) {
|
|
368
|
+
// const key = config.expose[alias];
|
|
369
|
+
// exposed[alias] = internalBase[key];
|
|
370
|
+
// }
|
|
371
|
+
// }
|
|
372
|
+
// const internal = {
|
|
373
|
+
// ...internalBase,
|
|
374
|
+
// ...exposed,
|
|
375
|
+
// } as WorkflowRegistry<Own, Use> & typeof exposed;
|
|
376
|
+
//
|
|
377
|
+
// // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
|
|
378
|
+
// // Own,
|
|
379
|
+
// // Use,
|
|
380
|
+
// // Expose
|
|
381
|
+
// // >;
|
|
382
|
+
//
|
|
383
|
+
// const publicMap = mergePublic<Own, Use, Expose>(own, exposed);
|
|
384
|
+
// return { internal, publicMap };
|
|
385
|
+
// }
|
|
386
|
+
//
|
|
387
|
+
// const { internal, publicMap } = buildWorkflowMap();
|
|
388
|
+
//
|
|
389
|
+
// const depsExecutors = Object.fromEntries(
|
|
390
|
+
// Object.entries(deps).map(([name, mod]) => [name, mod.__getExecutor()]),
|
|
391
|
+
// );
|
|
392
|
+
//
|
|
393
|
+
// const executor: Executor = {
|
|
394
|
+
// run(wfId, input, services, observers = []) {
|
|
395
|
+
// if (!(wfId in publicMap)) {
|
|
396
|
+
// throw new Error(`Workflow not in public: ${wfId}`);
|
|
397
|
+
// }
|
|
398
|
+
//
|
|
399
|
+
// const workflow = internal[wfId];
|
|
400
|
+
//
|
|
401
|
+
// if (!workflow) {
|
|
402
|
+
// throw new Error(`Workflow not found: ${String(wfId)}`);
|
|
403
|
+
// }
|
|
404
|
+
//
|
|
405
|
+
// return executeWorkflow({
|
|
406
|
+
// workflow,
|
|
407
|
+
// actionRegistry: config.actionRegistry,
|
|
408
|
+
// depsExecutors,
|
|
409
|
+
// input,
|
|
410
|
+
// services,
|
|
411
|
+
// observers,
|
|
412
|
+
// });
|
|
413
|
+
// },
|
|
414
|
+
// };
|
|
415
|
+
//
|
|
416
|
+
// return {
|
|
417
|
+
// workflows: own,
|
|
418
|
+
// __public: publicMap,
|
|
419
|
+
// __getExecutor: () => executor,
|
|
420
|
+
//
|
|
421
|
+
// createRuntime({ services }) {
|
|
422
|
+
// let runtimeActions = config.actionRegistry;
|
|
423
|
+
//
|
|
424
|
+
// return {
|
|
425
|
+
// run: async <K extends keyof typeof publicMap>(
|
|
426
|
+
// workflowId: K,
|
|
427
|
+
// input: WorkflowInput<(typeof publicMap)[K]>,
|
|
428
|
+
//
|
|
429
|
+
// observers: WorkflowObserver<Reg>[] = [],
|
|
430
|
+
// ) => {
|
|
431
|
+
// return executor.run(workflowId as string, input, services, observers);
|
|
432
|
+
// },
|
|
433
|
+
//
|
|
434
|
+
// getServices: () => ({ ...services }) as FinalServices<S, Use>,
|
|
435
|
+
//
|
|
436
|
+
// setActionRegistry(reg: Reg) {
|
|
437
|
+
// runtimeActions = reg;
|
|
438
|
+
// },
|
|
439
|
+
// };
|
|
440
|
+
// },
|
|
441
|
+
// };
|
|
442
|
+
// }
|
|
443
|
+
//
|
|
444
|
+
// /* ------------------------------------------------ */
|
|
445
|
+
// /* FACTORY (FIXED) */
|
|
446
|
+
// /* ------------------------------------------------ */
|
|
447
|
+
//
|
|
448
|
+
// export function createModuleFactory<S extends ServiceRegistry>() {
|
|
449
|
+
// return function <
|
|
450
|
+
// Reg extends ActionRegistry,
|
|
451
|
+
// Use extends ModuleMap,
|
|
452
|
+
// Own extends ModuleShape,
|
|
453
|
+
// Expose extends Record<string, keyof DepWorkflows<Use>> | undefined =
|
|
454
|
+
// undefined,
|
|
455
|
+
// >(config: {
|
|
456
|
+
// actionRegistry: Reg;
|
|
457
|
+
// use?: Use;
|
|
458
|
+
// expose?: Expose;
|
|
459
|
+
// define: (
|
|
460
|
+
// ctx: ModuleContext<typeof config.actionRegistry, DepWorkflows<Use>, S>,
|
|
461
|
+
// ) => Own;
|
|
462
|
+
// }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>> {
|
|
463
|
+
// return createModule<Reg, S, Use, Own, Expose>(config);
|
|
464
|
+
// };
|
|
465
|
+
// }
|
|
466
|
+
// ////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
467
|
+
//
|
|
468
|
+
//
|
|
469
|
+
// import {
|
|
470
|
+
// ActionRegistry,
|
|
471
|
+
// ServiceRegistry,
|
|
472
|
+
// Executor,
|
|
473
|
+
// Simplify,
|
|
474
|
+
// WorkflowObserver,
|
|
475
|
+
// } from "./types.js";
|
|
476
|
+
// import {
|
|
477
|
+
// createWorkflow,
|
|
478
|
+
// StepDef,
|
|
479
|
+
// WorkflowBuilder,
|
|
480
|
+
// WorkflowDef,
|
|
481
|
+
// } from "./workflow-composer.js";
|
|
482
|
+
// import { executeWorkflow } from "./workflow-executor.js";
|
|
483
|
+
//
|
|
484
|
+
// type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (
|
|
485
|
+
// x: infer I,
|
|
486
|
+
// ) => any
|
|
487
|
+
// ? I
|
|
488
|
+
// : never;
|
|
489
|
+
//
|
|
490
|
+
// /* ------------------------------------------------ */
|
|
491
|
+
// /* WORKFLOW REGISTRY TYPES */
|
|
492
|
+
// /* ------------------------------------------------ */
|
|
493
|
+
//
|
|
24
494
|
// type EnsureWorkflowShape<T> = {
|
|
25
495
|
// [K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any>
|
|
26
496
|
// ? T[K]
|
|
@@ -95,20 +565,17 @@
|
|
|
95
565
|
// S extends ServiceRegistry,
|
|
96
566
|
// Own extends ModuleShape,
|
|
97
567
|
// Deps extends ModuleMap,
|
|
98
|
-
// Public extends ModuleShape = Own,
|
|
99
568
|
// > = {
|
|
100
569
|
// workflows: Own;
|
|
101
570
|
// __getExecutor: () => Executor;
|
|
102
571
|
//
|
|
103
572
|
// createRuntime: (config: { services: FinalServices<S, Deps> }) => {
|
|
104
|
-
// run: <K extends keyof
|
|
105
|
-
// // run: <K extends keyof WorkflowRegistry<Own, Deps>>(
|
|
573
|
+
// run: <K extends keyof Own>(
|
|
106
574
|
// workflow: K,
|
|
107
|
-
// input: WorkflowInput<
|
|
575
|
+
// input: WorkflowInput<Own[K]>,
|
|
108
576
|
// observers?: WorkflowObserver<Reg>[],
|
|
109
577
|
// ) => Promise<{
|
|
110
|
-
//
|
|
111
|
-
// output: WorkflowOutput<Public[K]>;
|
|
578
|
+
// output: WorkflowOutput<Own[K]>;
|
|
112
579
|
// extras: Record<string, any>;
|
|
113
580
|
// }>;
|
|
114
581
|
//
|
|
@@ -139,6 +606,7 @@
|
|
|
139
606
|
// [K in keyof Expose]: DepWorkflows<Use>[Expose[K]];
|
|
140
607
|
// }
|
|
141
608
|
// : {});
|
|
609
|
+
//
|
|
142
610
|
// function createModule<
|
|
143
611
|
// Reg extends ActionRegistry,
|
|
144
612
|
// S extends ServiceRegistry,
|
|
@@ -150,7 +618,7 @@
|
|
|
150
618
|
// use?: Use;
|
|
151
619
|
// expose?: Expose;
|
|
152
620
|
// define: (ctx: ModuleContext<Reg, DepWorkflows<Use>, S>) => Own;
|
|
153
|
-
// }): Module<Reg, S,
|
|
621
|
+
// }): Module<Reg, S, ExposedWorkflows<Own, Use, Expose>, Use> {
|
|
154
622
|
// const deps = (config.use ?? {}) as Use;
|
|
155
623
|
//
|
|
156
624
|
// const wf = createWorkflow<Reg, DepWorkflows<Use>, S>();
|
|
@@ -160,61 +628,37 @@
|
|
|
160
628
|
// services: {} as S,
|
|
161
629
|
// });
|
|
162
630
|
//
|
|
163
|
-
// // function buildWorkflowMap(): WorkflowRegistry<Own, Use> {
|
|
164
|
-
// // const depWFs = Object.fromEntries(
|
|
165
|
-
// // Object.entries(deps).flatMap(([name, mod]) =>
|
|
166
|
-
// // Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
|
|
167
|
-
// // ),
|
|
168
|
-
// // );
|
|
169
|
-
// //
|
|
170
|
-
// // const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
171
|
-
// //
|
|
172
|
-
// // const publicMap = own;
|
|
173
|
-
// // return { internal, publicMap };
|
|
174
|
-
// // }
|
|
175
|
-
//
|
|
176
631
|
// function buildWorkflowMap() {
|
|
632
|
+
// // Get all workflows from dependencies (prefixed)
|
|
177
633
|
// const depWFs = Object.fromEntries(
|
|
178
634
|
// Object.entries(deps).flatMap(([name, mod]) =>
|
|
179
635
|
// Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
|
|
180
636
|
// ),
|
|
181
637
|
// );
|
|
182
638
|
//
|
|
183
|
-
// // const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
184
|
-
//
|
|
185
|
-
// // const exposed = Object.fromEntries(
|
|
186
|
-
// // Object.entries(config.expose ?? {}).map(([alias, key]) => [
|
|
187
|
-
// // alias,
|
|
188
|
-
// // internal[key], // reuse already resolved workflow
|
|
189
|
-
// // ]),
|
|
190
|
-
// // );
|
|
191
|
-
// //
|
|
192
639
|
// const internalBase = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
|
|
193
640
|
//
|
|
641
|
+
// // Build exposed workflows by looking up from internalBase
|
|
194
642
|
// const exposed = {} as Record<string, AnyWorkflow>;
|
|
195
|
-
//
|
|
196
643
|
// if (config.expose) {
|
|
197
644
|
// for (const alias in config.expose) {
|
|
198
|
-
// const key = config.expose[alias];
|
|
645
|
+
// const key = config.expose[alias] as string;
|
|
199
646
|
// exposed[alias] = internalBase[key];
|
|
200
647
|
// }
|
|
201
648
|
// }
|
|
202
|
-
// const internal = {
|
|
203
|
-
// ...internalBase,
|
|
204
|
-
// ...exposed,
|
|
205
|
-
// } as WorkflowRegistry<Own, Use> & typeof exposed;
|
|
206
|
-
// // if (config.expose) {
|
|
207
|
-
// // for (const alias in config.expose) {
|
|
208
|
-
// // const key = config.expose[alias];
|
|
209
|
-
// // exposed[alias] = internal[key];
|
|
210
|
-
// // }
|
|
211
|
-
// // }
|
|
212
649
|
//
|
|
650
|
+
// // Merge exposed into public workflows
|
|
213
651
|
// const publicMap = { ...own, ...exposed } as ExposedWorkflows<
|
|
214
652
|
// Own,
|
|
215
653
|
// Use,
|
|
216
654
|
// Expose
|
|
217
655
|
// >;
|
|
656
|
+
//
|
|
657
|
+
// const internal = {
|
|
658
|
+
// ...internalBase,
|
|
659
|
+
// ...exposed,
|
|
660
|
+
// } as WorkflowRegistry<Own, Use> & typeof exposed;
|
|
661
|
+
//
|
|
218
662
|
// return { internal, publicMap };
|
|
219
663
|
// }
|
|
220
664
|
//
|
|
@@ -248,33 +692,20 @@
|
|
|
248
692
|
// };
|
|
249
693
|
//
|
|
250
694
|
// return {
|
|
251
|
-
// workflows:
|
|
695
|
+
// workflows: publicMap, // ← KEY CHANGE: return publicMap (with exposed merged) as workflows
|
|
252
696
|
// __getExecutor: () => executor,
|
|
253
697
|
//
|
|
254
698
|
// createRuntime({ services }) {
|
|
255
|
-
// let runtimeActions = config.actionRegistry;
|
|
256
|
-
//
|
|
257
|
-
// // const runtimeService = createServiceRegisty(services)
|
|
258
699
|
// return {
|
|
259
700
|
// run: async <K extends keyof typeof publicMap>(
|
|
260
|
-
// // run: async <K extends keyof WorkflowRegistry<Own, Use>>(
|
|
261
701
|
// workflowId: K,
|
|
262
702
|
// input: WorkflowInput<(typeof publicMap)[K]>,
|
|
263
|
-
// // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
|
|
264
|
-
// // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
|
|
265
703
|
// observers: WorkflowObserver<Reg>[] = [],
|
|
266
704
|
// ) => {
|
|
267
705
|
// return executor.run(workflowId as string, input, services, observers);
|
|
268
706
|
// },
|
|
269
|
-
// // make it same, practically nothing changes but naming, and what context holds
|
|
270
|
-
// getServices: () => ({ ...services }) as FinalServices<S, Use>,
|
|
271
707
|
//
|
|
272
|
-
//
|
|
273
|
-
// runtimeActions = reg;
|
|
274
|
-
// // ⚠️ optional: if you REALLY want override, you'd need:
|
|
275
|
-
// // executor.actions = reg
|
|
276
|
-
// // but better keep actions immutable
|
|
277
|
-
// },
|
|
708
|
+
// getServices: () => ({ ...services }) as FinalServices<S, Use>,
|
|
278
709
|
// };
|
|
279
710
|
// },
|
|
280
711
|
// };
|
|
@@ -284,10 +715,7 @@
|
|
|
284
715
|
// /* FACTORY (FIXED) */
|
|
285
716
|
// /* ------------------------------------------------ */
|
|
286
717
|
//
|
|
287
|
-
// export function createModuleFactory<
|
|
288
|
-
// // Reg extends ActionRegistry,
|
|
289
|
-
// S extends ServiceRegistry,
|
|
290
|
-
// >() {
|
|
718
|
+
// export function createModuleFactory<S extends ServiceRegistry>() {
|
|
291
719
|
// return function <
|
|
292
720
|
// Reg extends ActionRegistry = Record<string, any>,
|
|
293
721
|
// Use extends ModuleMap = {},
|
|
@@ -301,89 +729,7 @@
|
|
|
301
729
|
// define: (
|
|
302
730
|
// ctx: ModuleContext<typeof config.actionRegistry, DepWorkflows<Use>, S>,
|
|
303
731
|
// ) => Own;
|
|
304
|
-
// }): Module<Reg, S,
|
|
732
|
+
// }): Module<Reg, S, ExposedWorkflows<Own, Use, Expose>, Use> {
|
|
305
733
|
// return createModule<Reg, S, Use, Own, Expose>(config);
|
|
306
734
|
// };
|
|
307
735
|
// }
|
|
308
|
-
//
|
|
309
|
-
import { createWorkflow, } from "./workflow-composer.js";
|
|
310
|
-
import { executeWorkflow } from "./workflow-executor.js";
|
|
311
|
-
function createModule(config) {
|
|
312
|
-
const deps = (config.use ?? {});
|
|
313
|
-
const wf = createWorkflow();
|
|
314
|
-
const own = config.define({
|
|
315
|
-
wf,
|
|
316
|
-
services: {},
|
|
317
|
-
});
|
|
318
|
-
function mergePublic(own, exposed) {
|
|
319
|
-
return { ...own, ...exposed };
|
|
320
|
-
}
|
|
321
|
-
function buildWorkflowMap() {
|
|
322
|
-
const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([name, mod]) => Object.entries(mod.__public).map(([k, wf]) => [`${name}.${k}`, wf])));
|
|
323
|
-
const internalBase = { ...own, ...depWFs };
|
|
324
|
-
const exposed = {};
|
|
325
|
-
if (config.expose) {
|
|
326
|
-
for (const alias in config.expose) {
|
|
327
|
-
const key = config.expose[alias];
|
|
328
|
-
exposed[alias] = internalBase[key];
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const internal = {
|
|
332
|
-
...internalBase,
|
|
333
|
-
...exposed,
|
|
334
|
-
};
|
|
335
|
-
// const publicMap = { ...own, ...exposed } as ExposedWorkflows<
|
|
336
|
-
// Own,
|
|
337
|
-
// Use,
|
|
338
|
-
// Expose
|
|
339
|
-
// >;
|
|
340
|
-
const publicMap = mergePublic(own, exposed);
|
|
341
|
-
return { internal, publicMap };
|
|
342
|
-
}
|
|
343
|
-
const { internal, publicMap } = buildWorkflowMap();
|
|
344
|
-
const depsExecutors = Object.fromEntries(Object.entries(deps).map(([name, mod]) => [name, mod.__getExecutor()]));
|
|
345
|
-
const executor = {
|
|
346
|
-
run(wfId, input, services, observers = []) {
|
|
347
|
-
if (!(wfId in publicMap)) {
|
|
348
|
-
throw new Error(`Workflow not in public: ${wfId}`);
|
|
349
|
-
}
|
|
350
|
-
const workflow = internal[wfId];
|
|
351
|
-
if (!workflow) {
|
|
352
|
-
throw new Error(`Workflow not found: ${String(wfId)}`);
|
|
353
|
-
}
|
|
354
|
-
return executeWorkflow({
|
|
355
|
-
workflow,
|
|
356
|
-
actionRegistry: config.actionRegistry,
|
|
357
|
-
depsExecutors,
|
|
358
|
-
input,
|
|
359
|
-
services,
|
|
360
|
-
observers,
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
};
|
|
364
|
-
return {
|
|
365
|
-
workflows: own,
|
|
366
|
-
__public: publicMap,
|
|
367
|
-
__getExecutor: () => executor,
|
|
368
|
-
createRuntime({ services }) {
|
|
369
|
-
let runtimeActions = config.actionRegistry;
|
|
370
|
-
return {
|
|
371
|
-
run: async (workflowId, input, observers = []) => {
|
|
372
|
-
return executor.run(workflowId, input, services, observers);
|
|
373
|
-
},
|
|
374
|
-
getServices: () => ({ ...services }),
|
|
375
|
-
setActionRegistry(reg) {
|
|
376
|
-
runtimeActions = reg;
|
|
377
|
-
},
|
|
378
|
-
};
|
|
379
|
-
},
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
/* ------------------------------------------------ */
|
|
383
|
-
/* FACTORY (FIXED) */
|
|
384
|
-
/* ------------------------------------------------ */
|
|
385
|
-
export function createModuleFactory() {
|
|
386
|
-
return function (config) {
|
|
387
|
-
return createModule(config);
|
|
388
|
-
};
|
|
389
|
-
}
|