@pogodisco/zephyr 1.3.15 → 1.3.16

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.
@@ -1,5 +1,15 @@
1
1
  import { ActionRegistry, WorkflowObserver } from "./types.js";
2
2
  import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
3
+ type ModuleWFRegistry<Own extends ModuleShape, Deps extends ModuleMap> = OwnWFs<Own> & DepsWFs<Deps>;
4
+ type OwnWFs<Own extends ModuleShape> = {
5
+ [K in keyof Own & string]: Own[K];
6
+ };
7
+ type NamespacedDepWFs<DepName extends string, M extends Module<any, any, any, any>> = {
8
+ [K in keyof M["own"] & string as `${DepName}.${K}`]: M["own"][K];
9
+ };
10
+ type DepsWFs<Deps extends ModuleMap> = {
11
+ [DepName in keyof Deps & string]: NamespacedDepWFs<DepName, Deps[DepName]>;
12
+ }[keyof Deps & string];
3
13
  type ModuleDepsPublic<Use> = {
4
14
  [K in keyof Use]: Use[K] extends Module<any, infer Ctx, infer Own, any> ? ModulePublic<Ctx, Own> : never;
5
15
  };
@@ -17,9 +27,6 @@ type ModuleMap = Record<string, Module<any, any, any, any>>;
17
27
  export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
18
28
  export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
19
29
  export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
20
- type WorkflowFromDeps<Deps> = {
21
- [K in keyof Deps]: Deps[K] extends Module<any, any, infer Own, any> ? Own[keyof Own] : never;
22
- }[keyof Deps];
23
30
  type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own extends ModuleShape = {}, Deps extends ModuleMap = {}> = {
24
31
  own: Own;
25
32
  deps: ModuleDepsPublic<Deps>;
@@ -27,9 +34,9 @@ type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own
27
34
  registry: Reg;
28
35
  context: FinalContext<Reg, Context, Deps>;
29
36
  }) => {
30
- run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(workflow: W, input: WorkflowInput<W>, observers?: WorkflowObserver<Reg>[]) => Promise<{
31
- results: WorkflowResults<W>;
32
- output: WorkflowOutput<W>;
37
+ run: <K extends keyof ModuleWFRegistry<Own, Deps>>(workflow: K, input: WorkflowInput<ModuleWFRegistry<Own, Deps>[K]>, observers?: WorkflowObserver<Reg>[]) => Promise<{
38
+ results: WorkflowResults<ModuleWFRegistry<Own, Deps>[K]>;
39
+ output: WorkflowOutput<ModuleWFRegistry<Own, Deps>[K]>;
33
40
  extras: Record<string, any>;
34
41
  }>;
35
42
  getContext: () => FinalContext<Reg, Context, Deps>;
@@ -149,29 +149,32 @@ function toPublicDeps(deps) {
149
149
  return deps;
150
150
  }
151
151
  function createModule(config) {
152
- const wf = createWorkflow();
153
152
  const deps = (config.use ?? {});
154
- const moduleCtx = {
155
- wf,
153
+ const own = config.define({
154
+ wf: createWorkflow(),
156
155
  deps,
157
156
  context: {},
158
157
  tools: (factory) => factory({
159
- wf,
158
+ wf: createWorkflow(),
160
159
  deps,
161
160
  context: {},
162
161
  }),
163
- };
164
- const own = config.define(moduleCtx);
162
+ });
163
+ function mergeWFs() {
164
+ const depWFs = Object.fromEntries(Object.entries(deps).flatMap(([depName, depModule]) => Object.entries(depModule.own).map(([k, wf]) => [`${depName}.${k}`, wf])));
165
+ return { ...own, ...depWFs };
166
+ }
165
167
  return {
166
168
  own,
167
169
  deps: toPublicDeps(deps),
168
170
  createRuntime({ registry, context }) {
169
- const runtimeCtx = { ...context };
171
+ const workflowRegistry = mergeWFs();
170
172
  return {
171
- run: async (workflow, input, observers = []) => {
172
- return executeWorkflow(workflow, registry, input, context, observers);
173
+ run: async (workflowId, input, observers = []) => {
174
+ const wfObj = workflowRegistry[workflowId]; // <-- concrete WorkflowDef
175
+ return executeWorkflow(wfObj, registry, input, context, observers);
173
176
  },
174
- getContext: () => ({ ...runtimeCtx }),
177
+ getContext: () => ({ ...context }),
175
178
  };
176
179
  },
177
180
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },