@pogodisco/zephyr 1.5.18 → 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.
@@ -21,14 +21,14 @@ type ServicesFromDepsRecursive<Deps extends ModuleMap> = [keyof Deps] extends [
21
21
  export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
22
22
  export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
23
23
  export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
24
- export type Module<Reg extends ActionRegistry, S extends ServiceRegistry, Own extends ModuleShape, Deps extends ModuleMap> = {
24
+ export type Module<Reg extends ActionRegistry, S extends ServiceRegistry, Own extends ModuleShape, Deps extends ModuleMap, Public extends ModuleShape = Own> = {
25
25
  workflows: Own;
26
26
  __getExecutor: () => Executor;
27
27
  createRuntime: (config: {
28
28
  services: FinalServices<S, Deps>;
29
29
  }) => {
30
- run: <K extends keyof Own>(workflow: K, input: WorkflowInput<Own[K]>, observers?: WorkflowObserver<Reg>[]) => Promise<{
31
- output: WorkflowOutput<Own[K]>;
30
+ run: <K extends keyof Public>(workflow: K, input: WorkflowInput<Public[K]>, observers?: WorkflowObserver<Reg>[]) => Promise<{
31
+ output: WorkflowOutput<Public[K]>;
32
32
  extras: Record<string, any>;
33
33
  }>;
34
34
  getServices: () => FinalServices<S, Deps>;
@@ -46,6 +46,6 @@ export declare function createModuleFactory<S extends ServiceRegistry>(): <Reg e
46
46
  use?: Use;
47
47
  expose?: Expose;
48
48
  define: (ctx: ModuleContext<typeof config.actionRegistry, DepWorkflows<Use>, S>) => Own;
49
- }) => Module<Reg, S, ExposedWorkflows<Own, Use, Expose>, Use>;
49
+ }) => Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>>;
50
50
  export {};
51
51
  //# sourceMappingURL=workflow-module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-module.d.ts","sour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CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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"}
@@ -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,44 +131,112 @@
21
131
  // /* WORKFLOW REGISTRY TYPES */
22
132
  // /* ------------------------------------------------ */
23
133
  //
24
- // type EnsureWorkflowShape<T> = {
134
+ // export type EnsureWorkflowShape<T> = {
25
135
  // [K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any>
26
136
  // ? T[K]
27
137
  // : never;
28
138
  // };
29
139
  //
30
- // type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
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
31
205
  // ? {}
32
206
  // : Simplify<
33
207
  // EnsureWorkflowShape<
34
- // UnionToIntersection<
35
- // {
36
- // [D in keyof Deps & string]: {
37
- // [K in keyof Deps[D]["workflows"] &
38
- // string as `${D}.${K}`]: Deps[D]["workflows"][K];
39
- // };
40
- // }[keyof Deps & string]
41
- // >
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
42
217
  // >
43
218
  // >;
44
- //
45
- // type WorkflowRegistry<Own extends ModuleShape, Deps extends ModuleMap> = Own &
46
- // DepWorkflows<Deps>;
219
+ // export type WorkflowRegistry<
220
+ // Own extends ModuleShape,
221
+ // Deps extends ModuleMap,
222
+ // > = Own & DepWorkflows<Deps>;
47
223
  //
48
224
  // /* ------------------------------------------------ */
49
225
  // /* MODULE TYPES */
50
226
  // /* ------------------------------------------------ */
51
227
  //
52
- // type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
53
- // type ModuleShape = Record<string, AnyWorkflow>;
54
- // type ModuleMap = Record<string, Module<any, any, any, any>>;
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>>;
55
231
  //
56
- // type FinalServices<S extends ServiceRegistry, Deps extends ModuleMap> = S &
57
- // ServicesFromDepsRecursive<Deps>;
232
+ // export type FinalServices<
233
+ // S extends ServiceRegistry,
234
+ // Deps extends ModuleMap,
235
+ // > = S & ServicesFromDepsRecursive<Deps>;
58
236
  //
59
- // type ServicesFromDepsRecursive<Deps extends ModuleMap> = [keyof Deps] extends [
60
- // never,
61
- // ]
237
+ // export type ServicesFromDepsRecursive<Deps extends ModuleMap> = [
238
+ // keyof Deps,
239
+ // ] extends [never]
62
240
  // ? {} // no deps
63
241
  // : UnionToIntersection<
64
242
  // {
@@ -66,7 +244,8 @@
66
244
  // any,
67
245
  // infer S,
68
246
  // any,
69
- // infer SubDeps
247
+ // infer SubDeps,
248
+ // any
70
249
  // >
71
250
  // ? S & ServicesFromDepsRecursive<SubDeps>
72
251
  // : never;
@@ -95,19 +274,19 @@
95
274
  // S extends ServiceRegistry,
96
275
  // Own extends ModuleShape,
97
276
  // Deps extends ModuleMap,
98
- // Public extends ModuleShape = Own,
277
+ // Public extends ModuleShape,
99
278
  // > = {
100
279
  // workflows: Own;
280
+ //
281
+ // __public: Public;
101
282
  // __getExecutor: () => Executor;
102
283
  //
103
284
  // createRuntime: (config: { services: FinalServices<S, Deps> }) => {
104
285
  // run: <K extends keyof Public>(
105
- // // run: <K extends keyof WorkflowRegistry<Own, Deps>>(
106
286
  // workflow: K,
107
287
  // input: WorkflowInput<Public[K]>,
108
288
  // observers?: WorkflowObserver<Reg>[],
109
289
  // ) => Promise<{
110
- // // results: WorkflowResults<WorkflowRegistry<Own, Deps>[K]>;
111
290
  // output: WorkflowOutput<Public[K]>;
112
291
  // extras: Record<string, any>;
113
292
  // }>;
@@ -120,7 +299,7 @@
120
299
  // /* MODULE CONTEXT (FIXED) */
121
300
  // /* ------------------------------------------------ */
122
301
  //
123
- // type ModuleContext<
302
+ // export type ModuleContext<
124
303
  // Reg extends ActionRegistry,
125
304
  // WFReg extends Record<string, WorkflowDef<any, any, any, any, any>>,
126
305
  // S extends ServiceRegistry,
@@ -129,7 +308,7 @@
129
308
  // services: S;
130
309
  // };
131
310
  //
132
- // type ExposedWorkflows<
311
+ // export type ExposedWorkflows<
133
312
  // Own extends ModuleShape,
134
313
  // Use extends ModuleMap,
135
314
  // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
@@ -150,45 +329,36 @@
150
329
  // use?: Use;
151
330
  // expose?: Expose;
152
331
  // define: (ctx: ModuleContext<Reg, DepWorkflows<Use>, S>) => Own;
153
- // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>> {
332
+ // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose> & ModuleShape> {
154
333
  // const deps = (config.use ?? {}) as Use;
155
334
  //
156
- // const wf = createWorkflow<Reg, DepWorkflows<Use>, S>();
335
+ // type WFReg = DepWorkflows<Use>;
336
+ //
337
+ // const wf = createWorkflow<Reg, WFReg, S>();
157
338
  //
158
339
  // const own = config.define({
159
340
  // wf,
160
341
  // services: {} as S,
161
342
  // });
162
343
  //
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
- // // }
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
+ // }
175
354
  //
176
355
  // function buildWorkflowMap() {
177
356
  // const depWFs = Object.fromEntries(
178
357
  // Object.entries(deps).flatMap(([name, mod]) =>
179
- // Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
358
+ // Object.entries(mod.__public).map(([k, wf]) => [`${name}.${k}`, wf]),
180
359
  // ),
181
360
  // );
182
361
  //
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
362
  // const internalBase = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
193
363
  //
194
364
  // const exposed = {} as Record<string, AnyWorkflow>;
@@ -203,18 +373,14 @@
203
373
  // ...internalBase,
204
374
  // ...exposed,
205
375
  // } 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
376
  //
213
- // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
214
- // Own,
215
- // Use,
216
- // Expose
217
- // >;
377
+ // // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
378
+ // // Own,
379
+ // // Use,
380
+ // // Expose
381
+ // // >;
382
+ //
383
+ // const publicMap = mergePublic<Own, Use, Expose>(own, exposed);
218
384
  // return { internal, publicMap };
219
385
  // }
220
386
  //
@@ -249,31 +415,26 @@
249
415
  //
250
416
  // return {
251
417
  // workflows: own,
418
+ // __public: publicMap,
252
419
  // __getExecutor: () => executor,
253
420
  //
254
421
  // createRuntime({ services }) {
255
422
  // let runtimeActions = config.actionRegistry;
256
423
  //
257
- // // const runtimeService = createServiceRegisty(services)
258
424
  // return {
259
425
  // run: async <K extends keyof typeof publicMap>(
260
- // // run: async <K extends keyof WorkflowRegistry<Own, Use>>(
261
426
  // workflowId: K,
262
427
  // input: WorkflowInput<(typeof publicMap)[K]>,
263
- // // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
264
- // // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
428
+ //
265
429
  // observers: WorkflowObserver<Reg>[] = [],
266
430
  // ) => {
267
431
  // return executor.run(workflowId as string, input, services, observers);
268
432
  // },
269
- // // make it same, practically nothing changes but naming, and what context holds
433
+ //
270
434
  // getServices: () => ({ ...services }) as FinalServices<S, Use>,
271
435
  //
272
436
  // setActionRegistry(reg: Reg) {
273
437
  // runtimeActions = reg;
274
- // // ⚠️ optional: if you REALLY want override, you'd need:
275
- // // executor.actions = reg
276
- // // but better keep actions immutable
277
438
  // },
278
439
  // };
279
440
  // },
@@ -284,14 +445,11 @@
284
445
  // /* FACTORY (FIXED) */
285
446
  // /* ------------------------------------------------ */
286
447
  //
287
- // export function createModuleFactory<
288
- // // Reg extends ActionRegistry,
289
- // S extends ServiceRegistry,
290
- // >() {
448
+ // export function createModuleFactory<S extends ServiceRegistry>() {
291
449
  // return function <
292
- // Reg extends ActionRegistry = Record<string, any>,
293
- // Use extends ModuleMap = {},
294
- // Own extends ModuleShape = {},
450
+ // Reg extends ActionRegistry,
451
+ // Use extends ModuleMap,
452
+ // Own extends ModuleShape,
295
453
  // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined =
296
454
  // undefined,
297
455
  // >(config: {
@@ -305,8 +463,9 @@
305
463
  // return createModule<Reg, S, Use, Own, Expose>(config);
306
464
  // };
307
465
  // }
466
+ // ////////////////////////////////////////////////////////////////////////////////////////////////////
467
+ //
308
468
  //
309
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
310
469
  // import {
311
470
  // ActionRegistry,
312
471
  // ServiceRegistry,
@@ -321,121 +480,55 @@
321
480
  // WorkflowDef,
322
481
  // } from "./workflow-composer.js";
323
482
  // import { executeWorkflow } from "./workflow-executor.js";
483
+ //
324
484
  // type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (
325
485
  // x: infer I,
326
486
  // ) => any
327
487
  // ? I
328
488
  // : never;
489
+ //
329
490
  // /* ------------------------------------------------ */
330
491
  // /* WORKFLOW REGISTRY TYPES */
331
492
  // /* ------------------------------------------------ */
332
493
  //
333
- // export type EnsureWorkflowShape<T> = {
494
+ // type EnsureWorkflowShape<T> = {
334
495
  // [K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any>
335
496
  // ? T[K]
336
497
  // : never;
337
498
  // };
338
499
  //
339
- // // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
340
- // // ? {}
341
- // // : Simplify<
342
- // // EnsureWorkflowShape<
343
- // // UnionToIntersection<
344
- // // {
345
- // // [D in keyof Deps & string]: {
346
- // // [K in keyof Deps[D]["__public"] &
347
- // // string as `${D}.${K}`]: Deps[D]["__public"][K];
348
- // // };
349
- // // }[keyof Deps & string]
350
- // // >
351
- // // >
352
- // // >;
353
- //
354
- // // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
355
- // // ? {}
356
- // // : Simplify<
357
- // // EnsureWorkflowShape<
358
- // // UnionToIntersection<
359
- // // {
360
- // // [D in keyof Deps & string]: {
361
- // // [K in keyof Deps[D]["__public"] &
362
- // // string as `${D}.${K}`]: Deps[D]["__public"][K];
363
- // // };
364
- // // }[keyof Deps & string]
365
- // // >
366
- // // >
367
- // // >;
368
- // // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
369
- // // ? {}
370
- // // : Simplify<{
371
- // // [D in keyof Deps as `${D & string}.${keyof Deps[D]["__public"] & string}`]: Deps[D]["__public"][keyof Deps[D]["__public"]];
372
- // // }>;
373
- // //
374
- //
375
- // // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
376
- // // ? {}
377
- // // : Simplify<
378
- // // // Just create the object directly without intersection
379
- // // Omit<
380
- // // {
381
- // // [D in keyof Deps & string]: {
382
- // // [K in keyof Deps[D]["__public"] &
383
- // // string as `${D}.${K}`]: Deps[D]["__public"][K];
384
- // // };
385
- // // }[keyof Deps & string],
386
- // // never
387
- // // >
388
- // // >;
389
- //
390
- // // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
391
- // // ? {}
392
- // // : Simplify<
393
- // // EnsureWorkflowShape<
394
- // // {
395
- // // [D in keyof Deps & string]: {
396
- // // [K in keyof Deps[D]["__public"] &
397
- // // string as `${D}.${K}`]: Deps[D]["__public"][K];
398
- // // };
399
- // // }[keyof Deps & string]
400
- // // >
401
- // // >;
402
- //
403
- // export type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
500
+ // type DepWorkflows<Deps extends ModuleMap> = keyof Deps extends never
404
501
  // ? {}
405
502
  // : Simplify<
406
503
  // EnsureWorkflowShape<
407
- // // Just use Omit + intersection - it's the same as UnionToIntersection but TypeScript handles it better
408
- // {
409
- // [D in keyof Deps & string]: {
410
- // [K in keyof Deps[D]["__public"] &
411
- // string as `${D}.${K}`]: Deps[D]["__public"][K];
412
- // };
413
- // }[keyof Deps & string] extends infer U
414
- // ? Omit<U, never>
415
- // : never
504
+ // UnionToIntersection<
505
+ // {
506
+ // [D in keyof Deps & string]: {
507
+ // [K in keyof Deps[D]["workflows"] &
508
+ // string as `${D}.${K}`]: Deps[D]["workflows"][K];
509
+ // };
510
+ // }[keyof Deps & string]
511
+ // >
416
512
  // >
417
513
  // >;
418
- // export type WorkflowRegistry<
419
- // Own extends ModuleShape,
420
- // Deps extends ModuleMap,
421
- // > = Own & DepWorkflows<Deps>;
514
+ //
515
+ // type WorkflowRegistry<Own extends ModuleShape, Deps extends ModuleMap> = Own &
516
+ // DepWorkflows<Deps>;
422
517
  //
423
518
  // /* ------------------------------------------------ */
424
519
  // /* MODULE TYPES */
425
520
  // /* ------------------------------------------------ */
426
521
  //
427
- // export type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
428
- // export type ModuleShape = Record<string, AnyWorkflow>;
429
- // export type ModuleMap = Record<string, Module<any, any, any, any, any>>;
522
+ // type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
523
+ // type ModuleShape = Record<string, AnyWorkflow>;
524
+ // type ModuleMap = Record<string, Module<any, any, any, any>>;
430
525
  //
431
- // export type FinalServices<
432
- // S extends ServiceRegistry,
433
- // Deps extends ModuleMap,
434
- // > = S & ServicesFromDepsRecursive<Deps>;
526
+ // type FinalServices<S extends ServiceRegistry, Deps extends ModuleMap> = S &
527
+ // ServicesFromDepsRecursive<Deps>;
435
528
  //
436
- // export type ServicesFromDepsRecursive<Deps extends ModuleMap> = [
437
- // keyof Deps,
438
- // ] extends [never]
529
+ // type ServicesFromDepsRecursive<Deps extends ModuleMap> = [keyof Deps] extends [
530
+ // never,
531
+ // ]
439
532
  // ? {} // no deps
440
533
  // : UnionToIntersection<
441
534
  // {
@@ -443,8 +536,7 @@
443
536
  // any,
444
537
  // infer S,
445
538
  // any,
446
- // infer SubDeps,
447
- // any
539
+ // infer SubDeps
448
540
  // >
449
541
  // ? S & ServicesFromDepsRecursive<SubDeps>
450
542
  // : never;
@@ -473,20 +565,17 @@
473
565
  // S extends ServiceRegistry,
474
566
  // Own extends ModuleShape,
475
567
  // Deps extends ModuleMap,
476
- // Public extends ModuleShape,
477
568
  // > = {
478
569
  // workflows: Own;
479
- //
480
- // __public: Public;
481
570
  // __getExecutor: () => Executor;
482
571
  //
483
572
  // createRuntime: (config: { services: FinalServices<S, Deps> }) => {
484
- // run: <K extends keyof Public>(
573
+ // run: <K extends keyof Own>(
485
574
  // workflow: K,
486
- // input: WorkflowInput<Public[K]>,
575
+ // input: WorkflowInput<Own[K]>,
487
576
  // observers?: WorkflowObserver<Reg>[],
488
577
  // ) => Promise<{
489
- // output: WorkflowOutput<Public[K]>;
578
+ // output: WorkflowOutput<Own[K]>;
490
579
  // extras: Record<string, any>;
491
580
  // }>;
492
581
  //
@@ -498,7 +587,7 @@
498
587
  // /* MODULE CONTEXT (FIXED) */
499
588
  // /* ------------------------------------------------ */
500
589
  //
501
- // export type ModuleContext<
590
+ // type ModuleContext<
502
591
  // Reg extends ActionRegistry,
503
592
  // WFReg extends Record<string, WorkflowDef<any, any, any, any, any>>,
504
593
  // S extends ServiceRegistry,
@@ -507,7 +596,7 @@
507
596
  // services: S;
508
597
  // };
509
598
  //
510
- // export type ExposedWorkflows<
599
+ // type ExposedWorkflows<
511
600
  // Own extends ModuleShape,
512
601
  // Use extends ModuleMap,
513
602
  // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
@@ -517,6 +606,7 @@
517
606
  // [K in keyof Expose]: DepWorkflows<Use>[Expose[K]];
518
607
  // }
519
608
  // : {});
609
+ //
520
610
  // function createModule<
521
611
  // Reg extends ActionRegistry,
522
612
  // S extends ServiceRegistry,
@@ -528,58 +618,47 @@
528
618
  // use?: Use;
529
619
  // expose?: Expose;
530
620
  // define: (ctx: ModuleContext<Reg, DepWorkflows<Use>, S>) => Own;
531
- // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose> & ModuleShape> {
621
+ // }): Module<Reg, S, ExposedWorkflows<Own, Use, Expose>, Use> {
532
622
  // const deps = (config.use ?? {}) as Use;
533
623
  //
534
- // type WFReg = DepWorkflows<Use>;
535
- //
536
- // const wf = createWorkflow<Reg, WFReg, S>();
624
+ // const wf = createWorkflow<Reg, DepWorkflows<Use>, S>();
537
625
  //
538
626
  // const own = config.define({
539
627
  // wf,
540
628
  // services: {} as S,
541
629
  // });
542
630
  //
543
- // function mergePublic<
544
- // Own extends ModuleShape,
545
- // Use extends ModuleMap,
546
- // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
547
- // >(
548
- // own: Own,
549
- // exposed: Record<string, AnyWorkflow>,
550
- // ): ExposedWorkflows<Own, Use, Expose> {
551
- // return { ...own, ...exposed } as any;
552
- // }
553
- //
554
631
  // function buildWorkflowMap() {
632
+ // // Get all workflows from dependencies (prefixed)
555
633
  // const depWFs = Object.fromEntries(
556
634
  // Object.entries(deps).flatMap(([name, mod]) =>
557
- // Object.entries(mod.__public).map(([k, wf]) => [`${name}.${k}`, wf]),
635
+ // Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
558
636
  // ),
559
637
  // );
560
638
  //
561
639
  // const internalBase = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
562
640
  //
641
+ // // Build exposed workflows by looking up from internalBase
563
642
  // const exposed = {} as Record<string, AnyWorkflow>;
564
- //
565
643
  // if (config.expose) {
566
644
  // for (const alias in config.expose) {
567
- // const key = config.expose[alias];
645
+ // const key = config.expose[alias] as string;
568
646
  // exposed[alias] = internalBase[key];
569
647
  // }
570
648
  // }
649
+ //
650
+ // // Merge exposed into public workflows
651
+ // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
652
+ // Own,
653
+ // Use,
654
+ // Expose
655
+ // >;
656
+ //
571
657
  // const internal = {
572
658
  // ...internalBase,
573
659
  // ...exposed,
574
660
  // } as WorkflowRegistry<Own, Use> & typeof exposed;
575
661
  //
576
- // // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
577
- // // Own,
578
- // // Use,
579
- // // Expose
580
- // // >;
581
- //
582
- // const publicMap = mergePublic<Own, Use, Expose>(own, exposed);
583
662
  // return { internal, publicMap };
584
663
  // }
585
664
  //
@@ -613,28 +692,20 @@
613
692
  // };
614
693
  //
615
694
  // return {
616
- // workflows: own,
617
- // __public: publicMap,
695
+ // workflows: publicMap, // ← KEY CHANGE: return publicMap (with exposed merged) as workflows
618
696
  // __getExecutor: () => executor,
619
697
  //
620
698
  // createRuntime({ services }) {
621
- // let runtimeActions = config.actionRegistry;
622
- //
623
699
  // return {
624
700
  // run: async <K extends keyof typeof publicMap>(
625
701
  // workflowId: K,
626
702
  // input: WorkflowInput<(typeof publicMap)[K]>,
627
- //
628
703
  // observers: WorkflowObserver<Reg>[] = [],
629
704
  // ) => {
630
705
  // return executor.run(workflowId as string, input, services, observers);
631
706
  // },
632
707
  //
633
708
  // getServices: () => ({ ...services }) as FinalServices<S, Use>,
634
- //
635
- // setActionRegistry(reg: Reg) {
636
- // runtimeActions = reg;
637
- // },
638
709
  // };
639
710
  // },
640
711
  // };
@@ -646,9 +717,9 @@
646
717
  //
647
718
  // export function createModuleFactory<S extends ServiceRegistry>() {
648
719
  // return function <
649
- // Reg extends ActionRegistry,
650
- // Use extends ModuleMap,
651
- // Own extends ModuleShape,
720
+ // Reg extends ActionRegistry = Record<string, any>,
721
+ // Use extends ModuleMap = {},
722
+ // Own extends ModuleShape = {},
652
723
  // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined =
653
724
  // undefined,
654
725
  // >(config: {
@@ -658,81 +729,7 @@
658
729
  // define: (
659
730
  // ctx: ModuleContext<typeof config.actionRegistry, DepWorkflows<Use>, S>,
660
731
  // ) => Own;
661
- // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>> {
732
+ // }): Module<Reg, S, ExposedWorkflows<Own, Use, Expose>, Use> {
662
733
  // return createModule<Reg, S, Use, Own, Expose>(config);
663
734
  // };
664
735
  // }
665
- // ////////////////////////////////////////////////////////////////////////////////////////////////////
666
- //
667
- //
668
- import { createWorkflow, } from "./workflow-composer.js";
669
- import { executeWorkflow } from "./workflow-executor.js";
670
- function createModule(config) {
671
- const deps = (config.use ?? {});
672
- const wf = createWorkflow();
673
- const own = config.define({
674
- wf,
675
- services: {},
676
- });
677
- function buildWorkflowMap() {
678
- // Get all workflows from dependencies (prefixed)
679
- const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([name, mod]) => Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf])));
680
- const internalBase = { ...own, ...depWFs };
681
- // Build exposed workflows by looking up from internalBase
682
- const exposed = {};
683
- if (config.expose) {
684
- for (const alias in config.expose) {
685
- const key = config.expose[alias];
686
- exposed[alias] = internalBase[key];
687
- }
688
- }
689
- // Merge exposed into public workflows
690
- const publicMap = { ...own, ...exposed };
691
- const internal = {
692
- ...internalBase,
693
- ...exposed,
694
- };
695
- return { internal, publicMap };
696
- }
697
- const { internal, publicMap } = buildWorkflowMap();
698
- const depsExecutors = Object.fromEntries(Object.entries(deps).map(([name, mod]) => [name, mod.__getExecutor()]));
699
- const executor = {
700
- run(wfId, input, services, observers = []) {
701
- if (!(wfId in publicMap)) {
702
- throw new Error(`Workflow not in public: ${wfId}`);
703
- }
704
- const workflow = internal[wfId];
705
- if (!workflow) {
706
- throw new Error(`Workflow not found: ${String(wfId)}`);
707
- }
708
- return executeWorkflow({
709
- workflow,
710
- actionRegistry: config.actionRegistry,
711
- depsExecutors,
712
- input,
713
- services,
714
- observers,
715
- });
716
- },
717
- };
718
- return {
719
- workflows: publicMap, // ← KEY CHANGE: return publicMap (with exposed merged) as workflows
720
- __getExecutor: () => executor,
721
- createRuntime({ services }) {
722
- return {
723
- run: async (workflowId, input, observers = []) => {
724
- return executor.run(workflowId, input, services, observers);
725
- },
726
- getServices: () => ({ ...services }),
727
- };
728
- },
729
- };
730
- }
731
- /* ------------------------------------------------ */
732
- /* FACTORY (FIXED) */
733
- /* ------------------------------------------------ */
734
- export function createModuleFactory() {
735
- return function (config) {
736
- return createModule(config);
737
- };
738
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.5.18",
3
+ "version": "1.5.19",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },