@pogodisco/zephyr 1.3.13 → 1.3.15

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,13 +1,14 @@
1
1
  import { ActionRegistry, MergeActionRegistries } from "./types.js";
2
- export declare class ActionRegistryBuilder<R extends ActionRegistry = {}> {
2
+ export declare class ActionRegistryBuilder<R extends ActionRegistry = {}, Prefix extends string = ""> {
3
+ private prefix;
3
4
  private registry;
4
- constructor(initial?: R);
5
+ constructor(prefix: Prefix, initial?: R);
5
6
  /**
6
7
  * Accepts ANY function - sync or async, any parameter shape
7
8
  * F captures the complete function signature for full type inference
8
9
  */
9
- action<K extends string, F extends (...args: any[]) => any>(key: K, action: F): ActionRegistryBuilder<MergeActionRegistries<R, Record<K, F>>>;
10
- extend<Other extends ActionRegistry>(other: ActionRegistryBuilder<Other> | Other): ActionRegistryBuilder<MergeActionRegistries<R, Other>>;
10
+ action<K extends string, F extends (...args: any[]) => any>(key: K, action: F): ActionRegistryBuilder<MergeActionRegistries<R, Record<`${Prefix}${K}`, F>>, Prefix>;
11
+ extend<Other extends ActionRegistry>(other: ActionRegistryBuilder<Other, any> | Other): ActionRegistryBuilder<MergeActionRegistries<R, Other>, Prefix>;
11
12
  build(): R;
12
13
  }
13
- export declare function createActionRegistry<R extends ActionRegistry = {}>(initial?: R): ActionRegistryBuilder<R>;
14
+ export declare function createActionRegistry<R extends ActionRegistry = {}, Prefix extends string = "">(prefix: Prefix, initial?: R): ActionRegistryBuilder<R, Prefix>;
package/dist/registry.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export class ActionRegistryBuilder {
2
- constructor(initial) {
2
+ constructor(prefix, initial) {
3
+ this.prefix = prefix;
3
4
  this.registry = {};
4
5
  if (initial) {
5
6
  this.registry = { ...initial };
@@ -10,12 +11,21 @@ export class ActionRegistryBuilder {
10
11
  * F captures the complete function signature for full type inference
11
12
  */
12
13
  action(key, action) {
13
- this.registry[key] = action;
14
+ const fullKey = `${this.prefix}${key}`;
15
+ if (fullKey in this.registry) {
16
+ throw new Error(`Action "${fullKey}" already exists`);
17
+ }
18
+ this.registry[fullKey] = action;
14
19
  return this;
15
20
  }
16
21
  // Extend with another registry (with override)
17
22
  extend(other) {
18
23
  const otherRegistry = other instanceof ActionRegistryBuilder ? other.build() : other;
24
+ for (const key in otherRegistry) {
25
+ if (key in this.registry) {
26
+ throw new Error(`Action collision detected "${key}"`);
27
+ }
28
+ }
19
29
  Object.assign(this.registry, otherRegistry);
20
30
  return this;
21
31
  }
@@ -23,6 +33,9 @@ export class ActionRegistryBuilder {
23
33
  return this.registry;
24
34
  }
25
35
  }
26
- export function createActionRegistry(initial) {
27
- return new ActionRegistryBuilder(initial);
36
+ export function createActionRegistry(prefix, initial) {
37
+ if (!prefix || typeof prefix !== "string" || prefix?.trim() === "") {
38
+ throw new Error(`Registry prefix is required`);
39
+ }
40
+ return new ActionRegistryBuilder(prefix, initial);
28
41
  }
@@ -1,26 +1,33 @@
1
1
  import { ActionRegistry, WorkflowObserver } from "./types.js";
2
2
  import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
3
+ type ModuleDepsPublic<Use> = {
4
+ [K in keyof Use]: Use[K] extends Module<any, infer Ctx, infer Own, any> ? ModulePublic<Ctx, Own> : never;
5
+ };
6
+ type ModulePublic<Context extends Record<string, any>, Own extends ModuleShape> = {
7
+ own: Own;
8
+ __ctx: Context;
9
+ };
3
10
  type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
4
- type WorkflowFromDeps<Deps extends Record<string, any>> = {
5
- [K in keyof Deps]: Deps[K] extends Module<any, any, infer Own, infer SubDeps> ? Own[keyof Own] | WorkflowFromDeps<SubDeps> : never;
6
- }[keyof Deps];
7
11
  type ModuleShape = Record<string, AnyWorkflow>;
8
12
  type ContextFromDeps<Deps> = [keyof Deps] extends [never] ? {} : {
9
13
  [K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any> ? Ctx : never;
10
14
  }[keyof Deps];
11
- type FinalContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = Context & ContextFromDeps<Deps>;
12
- type ModuleMap<Reg extends ActionRegistry> = Record<string, Module<Reg, any, any, any>>;
15
+ type FinalContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap> = Context & ContextFromDeps<Deps>;
16
+ type ModuleMap = Record<string, Module<any, any, any, any>>;
13
17
  export type WorkflowInput<W> = W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
14
18
  export type WorkflowResults<W> = W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
15
19
  export type WorkflowOutput<W> = W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
16
- type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own extends ModuleShape = {}, Deps extends ModuleMap<Reg> = {}> = {
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
+ type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own extends ModuleShape = {}, Deps extends ModuleMap = {}> = {
17
24
  own: Own;
18
- deps: Deps;
25
+ deps: ModuleDepsPublic<Deps>;
19
26
  createRuntime: (config: {
20
27
  registry: Reg;
21
28
  context: FinalContext<Reg, Context, Deps>;
22
29
  }) => {
23
- run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(workflow: W, input: WorkflowInput<W>, obververs?: WorkflowObserver<Reg>[]) => Promise<{
30
+ run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(workflow: W, input: WorkflowInput<W>, observers?: WorkflowObserver<Reg>[]) => Promise<{
24
31
  results: WorkflowResults<W>;
25
32
  output: WorkflowOutput<W>;
26
33
  extras: Record<string, any>;
@@ -28,7 +35,7 @@ type Module<Reg extends ActionRegistry, Context extends Record<string, any>, Own
28
35
  getContext: () => FinalContext<Reg, Context, Deps>;
29
36
  };
30
37
  };
31
- export type ModuleContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap<Reg>> = {
38
+ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<string, any>, Deps extends ModuleMap> = {
32
39
  wf: ReturnType<typeof createWorkflow<Reg, Context>>;
33
40
  deps: Deps;
34
41
  context: Context;
@@ -38,11 +45,7 @@ export type ModuleContext<Reg extends ActionRegistry, Context extends Record<str
38
45
  context: Context;
39
46
  }) => T) => T;
40
47
  };
41
- export declare function createModule<Reg extends ActionRegistry, Context extends Record<string, any>, Use extends ModuleMap<Reg>, Own extends ModuleShape>(config: {
42
- use?: Use;
43
- define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
44
- }): Module<Reg, Context, Own, Use>;
45
- export declare function createModuleFactory<Reg extends ActionRegistry, Context extends Record<string, any>>(): <Use extends ModuleMap<Reg> = {}, Own extends ModuleShape = {}>(config: {
48
+ export declare function createModuleFactory<Reg extends ActionRegistry, Context extends Record<string, any>>(): <Use extends ModuleMap = {}, Own extends ModuleShape = {}>(config: {
46
49
  use?: Use;
47
50
  define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
48
51
  }) => Module<Reg, Context, Own, Use>;
@@ -1,6 +1,154 @@
1
+ // import { ActionRegistry, Simplify, WorkflowObserver } from "./types.js";
2
+ // import { createWorkflow, WorkflowDef } from "./workflow-composer.js";
3
+ // import { executeWorkflow } from "./workflow-executor.js";
4
+ //
5
+ // type AnyWorkflow = WorkflowDef<any, any, any, any, any>;
6
+ //
7
+ // type WorkflowFromDeps<Deps extends Record<string, any>> = {
8
+ // [K in keyof Deps]: Deps[K] extends Module<any, any, infer Own, infer SubDeps>
9
+ // ? Own[keyof Own] | WorkflowFromDeps<SubDeps>
10
+ // : never;
11
+ // }[keyof Deps];
12
+ // type ModuleShape = Record<string, AnyWorkflow>;
13
+ //
14
+ // type ContextFromDeps<Deps> = [keyof Deps] extends [never]
15
+ // ? {} // 👈 THIS is the fix
16
+ // : {
17
+ // [K in keyof Deps]: Deps[K] extends Module<any, infer Ctx, any, any>
18
+ // ? Ctx
19
+ // : never;
20
+ // }[keyof Deps];
21
+ //
22
+ // type FinalContext<
23
+ // Reg extends ActionRegistry,
24
+ // Context extends Record<string, any>,
25
+ // Deps extends ModuleMap<Reg>,
26
+ // > = Context & ContextFromDeps<Deps>;
27
+ //
28
+ // type ModuleMap<Reg extends ActionRegistry> = Record<
29
+ // string,
30
+ // Module<Reg, any, any, any>
31
+ // >;
32
+ //
33
+ // // type Module<Own extends ModuleShape = {}, Deps extends ModuleMap = {}> = Own & {
34
+ // // deps: Deps;
35
+ // // };
36
+ // export type WorkflowInput<W> =
37
+ // W extends WorkflowDef<any, infer I, any, any, any> ? I : never;
38
+ //
39
+ // export type WorkflowResults<W> =
40
+ // W extends WorkflowDef<any, any, infer R, any, any> ? R : never;
41
+ //
42
+ // export type WorkflowOutput<W> =
43
+ // W extends WorkflowDef<any, any, any, any, infer O> ? O : never;
44
+ // type Module<
45
+ // Reg extends ActionRegistry,
46
+ // Context extends Record<string, any>,
47
+ // Own extends ModuleShape = {},
48
+ // Deps extends ModuleMap<Reg> = {},
49
+ // > = {
50
+ // own: Own;
51
+ // deps: Deps;
52
+ // createRuntime: (config: {
53
+ // registry: Reg;
54
+ // context: FinalContext<Reg, Context, Deps>;
55
+ // }) => {
56
+ // run: <W extends Own[keyof Own] | WorkflowFromDeps<Deps>>(
57
+ // workflow: W,
58
+ // input: WorkflowInput<W>,
59
+ // obververs?: WorkflowObserver<Reg>[],
60
+ // ) => Promise<{
61
+ // results: WorkflowResults<W>;
62
+ // output: WorkflowOutput<W>;
63
+ // extras: Record<string, any>;
64
+ // }>;
65
+ // getContext: () => FinalContext<Reg, Context, Deps>;
66
+ // };
67
+ // };
68
+ //
69
+ // export type ModuleContext<
70
+ // Reg extends ActionRegistry,
71
+ // Context extends Record<string, any>,
72
+ // Deps extends ModuleMap<Reg>,
73
+ // > = {
74
+ // wf: ReturnType<typeof createWorkflow<Reg, Context>>;
75
+ //
76
+ // deps: Deps;
77
+ // context: Context;
78
+ //
79
+ // tools: <T>(
80
+ // factory: (ctx: {
81
+ // wf: ModuleContext<Reg, Context, Deps>["wf"];
82
+ // deps: Deps;
83
+ // context: Context;
84
+ // }) => T,
85
+ // ) => T;
86
+ // };
87
+ //
88
+ // function createModule<
89
+ // Reg extends ActionRegistry,
90
+ // Context extends Record<string, any>,
91
+ // Use extends ModuleMap<Reg>,
92
+ // Own extends ModuleShape,
93
+ // >(config: {
94
+ // use?: Use;
95
+ // define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
96
+ // }): Module<Reg, Context, Own, Use> {
97
+ // const wf = createWorkflow<Reg, Context>();
98
+ //
99
+ // const deps = (config.use ?? {}) as Use;
100
+ //
101
+ // const moduleCtx: ModuleContext<Reg, Context, Use> = {
102
+ // wf,
103
+ // deps,
104
+ // context: {} as Context,
105
+ //
106
+ // tools: (factory) =>
107
+ // factory({
108
+ // wf,
109
+ // deps,
110
+ // context: {} as Context,
111
+ // }),
112
+ // };
113
+ //
114
+ // const own = config.define(moduleCtx);
115
+ //
116
+ // return {
117
+ // own,
118
+ // deps,
119
+ // createRuntime({ registry, context }) {
120
+ // const runtimeCtx = { ...context } as FinalContext<Reg, Context, Use>;
121
+ // return {
122
+ // run: async (workflow, input, observers = []) => {
123
+ // return executeWorkflow(workflow, registry, input, context, observers);
124
+ // },
125
+ // getContext: () => ({ ...runtimeCtx }),
126
+ // };
127
+ // },
128
+ // };
129
+ // }
130
+ //
131
+ // export function createModuleFactory<
132
+ // Reg extends ActionRegistry,
133
+ // Context extends Record<string, any>,
134
+ // >() {
135
+ // return function <
136
+ // Use extends ModuleMap<Reg> = {},
137
+ // Own extends ModuleShape = {},
138
+ // >(config: {
139
+ // use?: Use;
140
+ // define: (ctx: ModuleContext<Reg, Context, Use>) => Own;
141
+ // }): Module<Reg, Context, Own, Use> {
142
+ // return createModule<Reg, Context, Use, Own>(config);
143
+ // };
144
+ // }
145
+ //
1
146
  import { createWorkflow } from "./workflow-composer.js";
2
147
  import { executeWorkflow } from "./workflow-executor.js";
3
- export function createModule(config) {
148
+ function toPublicDeps(deps) {
149
+ return deps;
150
+ }
151
+ function createModule(config) {
4
152
  const wf = createWorkflow();
5
153
  const deps = (config.use ?? {});
6
154
  const moduleCtx = {
@@ -16,7 +164,7 @@ export function createModule(config) {
16
164
  const own = config.define(moduleCtx);
17
165
  return {
18
166
  own,
19
- deps,
167
+ deps: toPublicDeps(deps),
20
168
  createRuntime({ registry, context }) {
21
169
  const runtimeCtx = { ...context };
22
170
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pogodisco/zephyr",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },