@pogodisco/zephyr 1.5.7 → 1.5.9

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.
@@ -6,7 +6,7 @@ type EnsureWorkflowShape<T> = {
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]["workflows"] & string as `${D}.${K}`]: Deps[D]["workflows"][K];
9
+ [K in keyof Deps[D]["__public"] & string as `${D}.${K}`]: Deps[D]["__public"][K];
10
10
  };
11
11
  }[keyof Deps & string]>>>;
12
12
  type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
@@ -23,6 +23,7 @@ export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, a
23
23
  export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
24
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
+ __public: Public;
26
27
  __getExecutor: () => Executor;
27
28
  createRuntime: (config: {
28
29
  services: FinalServices<S, Deps>;
@@ -5,7 +5,12 @@
5
5
  // Simplify,
6
6
  // WorkflowObserver,
7
7
  // } from "./types.js";
8
- // import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
8
+ // import {
9
+ // createWorkflow,
10
+ // StepDef,
11
+ // WorkflowBuilder,
12
+ // WorkflowDef,
13
+ // } from "./workflow-composer.js";
9
14
  // import { executeWorkflow } from "./workflow-executor.js";
10
15
  // type UnionToIntersection<U> = (U extends any ? (x: U) => any : never) extends (
11
16
  // x: infer I,
@@ -15,10 +20,6 @@
15
20
  // /* ------------------------------------------------ */
16
21
  // /* WORKFLOW REGISTRY TYPES */
17
22
  // /* ------------------------------------------------ */
18
- // type EnsureWorkflowRecord<T> =
19
- // T extends Record<string, WorkflowDef<any, any, any, any, any>>
20
- // ? T
21
- // : Record<string, WorkflowDef<any, any, any, any, any>>;
22
23
  //
23
24
  // type EnsureWorkflowShape<T> = {
24
25
  // [K in keyof T]: T[K] extends WorkflowDef<any, any, any, any, any>
@@ -52,27 +53,9 @@
52
53
  // type ModuleShape = Record<string, AnyWorkflow>;
53
54
  // type ModuleMap = Record<string, Module<any, any, any, any>>;
54
55
  //
55
- // // type ContextFromDeps<Deps> = [keyof Deps] extends [never]
56
- // // ? {}
57
- // // : {
58
- // // [K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any>
59
- // // ? Ctx
60
- // // : never;
61
- // // }[keyof Deps];
62
- //
63
56
  // type FinalServices<S extends ServiceRegistry, Deps extends ModuleMap> = S &
64
57
  // ServicesFromDepsRecursive<Deps>;
65
58
  //
66
- // // type ContextFromDeps<Deps> = [keyof Deps] extends [never]
67
- // // ? {}
68
- // // : UnionToIntersection<
69
- // // {
70
- // // [K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any>
71
- // // ? Ctx
72
- // // : never;
73
- // // }[keyof Deps]
74
- // // >;
75
- //
76
59
  // type ServicesFromDepsRecursive<Deps extends ModuleMap> = [keyof Deps] extends [
77
60
  // never,
78
61
  // ]
@@ -107,23 +90,25 @@
107
90
  // /* MODULE RUNTIME */
108
91
  // /* ------------------------------------------------ */
109
92
  //
110
- // type Module<
93
+ // export type Module<
111
94
  // Reg extends ActionRegistry,
112
95
  // S extends ServiceRegistry,
113
96
  // Own extends ModuleShape,
114
97
  // Deps extends ModuleMap,
98
+ // Public extends ModuleShape = Own,
115
99
  // > = {
116
100
  // workflows: Own;
117
101
  // __getExecutor: () => Executor;
118
102
  //
119
103
  // createRuntime: (config: { services: FinalServices<S, Deps> }) => {
120
- // run: <K extends keyof WorkflowRegistry<Own, Deps>>(
104
+ // run: <K extends keyof Public>(
105
+ // // run: <K extends keyof WorkflowRegistry<Own, Deps>>(
121
106
  // workflow: K,
122
- // input: WorkflowInput<WorkflowRegistry<Own, Deps>[K]>,
107
+ // input: WorkflowInput<Public[K]>,
123
108
  // observers?: WorkflowObserver<Reg>[],
124
109
  // ) => Promise<{
125
110
  // // results: WorkflowResults<WorkflowRegistry<Own, Deps>[K]>;
126
- // output: WorkflowOutput<WorkflowRegistry<Own, Deps>[K]>;
111
+ // output: WorkflowOutput<Public[K]>;
127
112
  // extras: Record<string, any>;
128
113
  // }>;
129
114
  //
@@ -144,16 +129,28 @@
144
129
  // services: S;
145
130
  // };
146
131
  //
132
+ // type ExposedWorkflows<
133
+ // Own extends ModuleShape,
134
+ // Use extends ModuleMap,
135
+ // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
136
+ // > = Own &
137
+ // (Expose extends Record<string, keyof DepWorkflows<Use>>
138
+ // ? {
139
+ // [K in keyof Expose]: DepWorkflows<Use>[Expose[K]];
140
+ // }
141
+ // : {});
147
142
  // function createModule<
148
143
  // Reg extends ActionRegistry,
149
144
  // S extends ServiceRegistry,
150
145
  // Use extends ModuleMap,
151
146
  // Own extends ModuleShape,
147
+ // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined,
152
148
  // >(config: {
153
149
  // actionRegistry: Reg;
154
150
  // use?: Use;
151
+ // expose?: Expose;
155
152
  // define: (ctx: ModuleContext<Reg, DepWorkflows<Use>, S>) => Own;
156
- // }): Module<Reg, S, Own, Use> {
153
+ // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>> {
157
154
  // const deps = (config.use ?? {}) as Use;
158
155
  //
159
156
  // const wf = createWorkflow<Reg, DepWorkflows<Use>, S>();
@@ -163,17 +160,65 @@
163
160
  // services: {} as S,
164
161
  // });
165
162
  //
166
- // function buildWorkflowMap(): WorkflowRegistry<Own, Use> {
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
+ // function buildWorkflowMap() {
167
177
  // const depWFs = Object.fromEntries(
168
178
  // Object.entries(deps).flatMap(([name, mod]) =>
169
179
  // Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
170
180
  // ),
171
181
  // );
172
182
  //
173
- // return { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
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
+ // const internalBase = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
193
+ //
194
+ // const exposed = {} as Record<string, AnyWorkflow>;
195
+ //
196
+ // if (config.expose) {
197
+ // for (const alias in config.expose) {
198
+ // const key = config.expose[alias];
199
+ // exposed[alias] = internalBase[key];
200
+ // }
201
+ // }
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
+ //
213
+ // const publicMap = { ...own, ...exposed } as ExposedWorkflows<
214
+ // Own,
215
+ // Use,
216
+ // Expose
217
+ // >;
218
+ // return { internal, publicMap };
174
219
  // }
175
220
  //
176
- // const workflowMap = buildWorkflowMap();
221
+ // const { internal, publicMap } = buildWorkflowMap();
177
222
  //
178
223
  // const depsExecutors = Object.fromEntries(
179
224
  // Object.entries(deps).map(([name, mod]) => [name, mod.__getExecutor()]),
@@ -181,7 +226,11 @@
181
226
  //
182
227
  // const executor: Executor = {
183
228
  // run(wfId, input, services, observers = []) {
184
- // const workflow = workflowMap[wfId];
229
+ // if (!(wfId in publicMap)) {
230
+ // throw new Error(`Workflow not in public: ${wfId}`);
231
+ // }
232
+ //
233
+ // const workflow = internal[wfId];
185
234
  //
186
235
  // if (!workflow) {
187
236
  // throw new Error(`Workflow not found: ${String(wfId)}`);
@@ -207,9 +256,12 @@
207
256
  //
208
257
  // // const runtimeService = createServiceRegisty(services)
209
258
  // return {
210
- // run: async <K extends keyof WorkflowRegistry<Own, Use>>(
259
+ // run: async <K extends keyof typeof publicMap>(
260
+ // // run: async <K extends keyof WorkflowRegistry<Own, Use>>(
211
261
  // workflowId: K,
212
- // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
262
+ // input: WorkflowInput<(typeof publicMap)[K]>,
263
+ // // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
264
+ // // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
213
265
  // observers: WorkflowObserver<Reg>[] = [],
214
266
  // ) => {
215
267
  // return executor.run(workflowId as string, input, services, observers);
@@ -240,48 +292,31 @@
240
292
  // Reg extends ActionRegistry = Record<string, any>,
241
293
  // Use extends ModuleMap = {},
242
294
  // Own extends ModuleShape = {},
295
+ // Expose extends Record<string, keyof DepWorkflows<Use>> | undefined =
296
+ // undefined,
243
297
  // >(config: {
244
298
  // actionRegistry: Reg;
245
299
  // use?: Use;
300
+ // expose?: Expose;
246
301
  // define: (
247
302
  // ctx: ModuleContext<typeof config.actionRegistry, DepWorkflows<Use>, S>,
248
303
  // ) => Own;
249
- // }): Module<Reg, S, Own, Use> {
250
- // return createModule<Reg, S, Use, Own>(config);
304
+ // }): Module<Reg, S, Own, Use, ExposedWorkflows<Own, Use, Expose>> {
305
+ // return createModule<Reg, S, Use, Own, Expose>(config);
251
306
  // };
252
307
  // }
308
+ //
253
309
  import { createWorkflow, } from "./workflow-composer.js";
254
310
  import { executeWorkflow } from "./workflow-executor.js";
255
311
  function createModule(config) {
256
312
  const deps = (config.use ?? {});
257
313
  const wf = createWorkflow();
258
- // const macro = createMacro<Reg, S, DepWorkflows<Use>>();
259
314
  const own = config.define({
260
315
  wf,
261
316
  services: {},
262
317
  });
263
- // function buildWorkflowMap(): WorkflowRegistry<Own, Use> {
264
- // const depWFs = Object.fromEntries(
265
- // Object.entries(deps).flatMap(([name, mod]) =>
266
- // Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf]),
267
- // ),
268
- // );
269
- //
270
- // const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
271
- //
272
- // const publicMap = own;
273
- // return { internal, publicMap };
274
- // }
275
318
  function buildWorkflowMap() {
276
- const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([name, mod]) => Object.entries(mod.workflows).map(([k, wf]) => [`${name}.${k}`, wf])));
277
- // const internal = { ...own, ...depWFs } as WorkflowRegistry<Own, Use>;
278
- // const exposed = Object.fromEntries(
279
- // Object.entries(config.expose ?? {}).map(([alias, key]) => [
280
- // alias,
281
- // internal[key], // reuse already resolved workflow
282
- // ]),
283
- // );
284
- //
319
+ const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([name, mod]) => Object.entries(mod.__public).map(([k, wf]) => [`${name}.${k}`, wf])));
285
320
  const internalBase = { ...own, ...depWFs };
286
321
  const exposed = {};
287
322
  if (config.expose) {
@@ -294,12 +329,6 @@ function createModule(config) {
294
329
  ...internalBase,
295
330
  ...exposed,
296
331
  };
297
- // if (config.expose) {
298
- // for (const alias in config.expose) {
299
- // const key = config.expose[alias];
300
- // exposed[alias] = internal[key];
301
- // }
302
- // }
303
332
  const publicMap = { ...own, ...exposed };
304
333
  return { internal, publicMap };
305
334
  }
@@ -326,26 +355,17 @@ function createModule(config) {
326
355
  };
327
356
  return {
328
357
  workflows: own,
358
+ __public: publicMap,
329
359
  __getExecutor: () => executor,
330
360
  createRuntime({ services }) {
331
361
  let runtimeActions = config.actionRegistry;
332
- // const runtimeService = createServiceRegisty(services)
333
362
  return {
334
- run: async (
335
- // run: async <K extends keyof WorkflowRegistry<Own, Use>>(
336
- workflowId, input,
337
- // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
338
- // input: WorkflowInput<WorkflowRegistry<Own, Use>[K]>,
339
- observers = []) => {
363
+ run: async (workflowId, input, observers = []) => {
340
364
  return executor.run(workflowId, input, services, observers);
341
365
  },
342
- // make it same, practically nothing changes but naming, and what context holds
343
366
  getServices: () => ({ ...services }),
344
367
  setActionRegistry(reg) {
345
368
  runtimeActions = reg;
346
- // ⚠️ optional: if you REALLY want override, you'd need:
347
- // executor.actions = reg
348
- // but better keep actions immutable
349
369
  },
350
370
  };
351
371
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },