@bluelibs/runner 3.2.0 → 3.3.1

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.
Files changed (95) hide show
  1. package/README.md +482 -34
  2. package/dist/cli/extract-docs.d.ts +2 -0
  3. package/dist/cli/extract-docs.js +88 -0
  4. package/dist/cli/extract-docs.js.map +1 -0
  5. package/dist/define.d.ts +21 -1
  6. package/dist/define.js +95 -23
  7. package/dist/define.js.map +1 -1
  8. package/dist/defs/core.d.ts +144 -0
  9. package/dist/defs/core.js +6 -0
  10. package/dist/defs/core.js.map +1 -0
  11. package/dist/defs/symbols.d.ts +42 -0
  12. package/dist/defs/symbols.js +45 -0
  13. package/dist/defs/symbols.js.map +1 -0
  14. package/dist/defs/tags.d.ts +70 -0
  15. package/dist/defs/tags.js +6 -0
  16. package/dist/defs/tags.js.map +1 -0
  17. package/dist/defs.d.ts +168 -16
  18. package/dist/defs.js +41 -14
  19. package/dist/defs.js.map +1 -1
  20. package/dist/docs/introspect.d.ts +7 -0
  21. package/dist/docs/introspect.js +199 -0
  22. package/dist/docs/introspect.js.map +1 -0
  23. package/dist/docs/markdown.d.ts +2 -0
  24. package/dist/docs/markdown.js +148 -0
  25. package/dist/docs/markdown.js.map +1 -0
  26. package/dist/docs/model.d.ts +62 -0
  27. package/dist/docs/model.js +33 -0
  28. package/dist/docs/model.js.map +1 -0
  29. package/dist/express/docsRouter.d.ts +12 -0
  30. package/dist/express/docsRouter.js +54 -0
  31. package/dist/express/docsRouter.js.map +1 -0
  32. package/dist/globals/globalMiddleware.d.ts +1 -0
  33. package/dist/globals/globalMiddleware.js +2 -0
  34. package/dist/globals/globalMiddleware.js.map +1 -1
  35. package/dist/globals/middleware/timeout.middleware.d.ts +8 -0
  36. package/dist/globals/middleware/timeout.middleware.js +35 -0
  37. package/dist/globals/middleware/timeout.middleware.js.map +1 -0
  38. package/dist/index.d.ts +4 -2
  39. package/dist/index.js +5 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/models/DependencyProcessor.js +2 -2
  42. package/dist/models/DependencyProcessor.js.map +1 -1
  43. package/dist/models/Store.d.ts +1 -1
  44. package/dist/models/StoreConstants.d.ts +1 -1
  45. package/dist/models/StoreConstants.js +2 -1
  46. package/dist/models/StoreConstants.js.map +1 -1
  47. package/dist/models/TaskRunner.d.ts +2 -3
  48. package/dist/models/TaskRunner.js +1 -2
  49. package/dist/models/TaskRunner.js.map +1 -1
  50. package/dist/testing.d.ts +24 -0
  51. package/dist/testing.js +41 -0
  52. package/dist/testing.js.map +1 -0
  53. package/dist/types/dependencies.d.ts +47 -18
  54. package/dist/types/event.d.ts +49 -0
  55. package/dist/types/event.js +4 -0
  56. package/dist/types/event.js.map +1 -0
  57. package/dist/types/index.d.ts +4 -10
  58. package/dist/types/index.js +8 -7
  59. package/dist/types/index.js.map +1 -1
  60. package/dist/types/metadata.d.ts +75 -0
  61. package/dist/types/metadata.js +3 -0
  62. package/dist/types/metadata.js.map +1 -0
  63. package/dist/types/middleware.d.ts +43 -18
  64. package/dist/types/middleware.js +0 -3
  65. package/dist/types/middleware.js.map +1 -1
  66. package/dist/types/resource.d.ts +96 -0
  67. package/dist/types/resource.js +3 -0
  68. package/dist/types/resource.js.map +1 -0
  69. package/dist/types/symbols.d.ts +17 -0
  70. package/dist/types/symbols.js +18 -3
  71. package/dist/types/symbols.js.map +1 -1
  72. package/dist/types/task.d.ts +68 -0
  73. package/dist/types/task.js +3 -0
  74. package/dist/types/task.js.map +1 -0
  75. package/package.json +4 -4
  76. package/src/__tests__/benchmark/task-benchmark.test.ts +132 -0
  77. package/src/__tests__/createTestResource.test.ts +139 -0
  78. package/src/__tests__/globals/timeout.middleware.test.ts +88 -0
  79. package/src/__tests__/models/EventManager.test.ts +39 -6
  80. package/src/__tests__/models/Semaphore.test.ts +1 -1
  81. package/src/__tests__/override.test.ts +104 -0
  82. package/src/__tests__/run.overrides.test.ts +50 -21
  83. package/src/__tests__/run.test.ts +19 -0
  84. package/src/__tests__/tags.test.ts +396 -0
  85. package/src/__tests__/tools/getCallerFile.test.ts +9 -11
  86. package/src/__tests__/typesafety.test.ts +109 -1
  87. package/src/define.ts +128 -24
  88. package/src/defs.ts +174 -22
  89. package/src/globals/globalMiddleware.ts +2 -0
  90. package/src/globals/middleware/timeout.middleware.ts +46 -0
  91. package/src/index.ts +6 -0
  92. package/src/models/DependencyProcessor.ts +2 -10
  93. package/src/models/StoreConstants.ts +2 -1
  94. package/src/models/TaskRunner.ts +1 -3
  95. package/src/testing.ts +66 -0
package/dist/define.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { ITask, ITaskDefinition, IResource, IResourceWithConfig, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyMapType, DependencyValuesType, IMiddleware, IEvent, RegisterableItems } from "./defs";
1
+ /**
2
+ * Factory functions for defining tasks, resources, events and middleware.
3
+ *
4
+ * These helpers create strongly-typed definitions while also wiring internal
5
+ * metadata: anonymous IDs, file path tags (for better debugging), lifecycle
6
+ * events, and global middleware flags. See README for high-level concepts.
7
+ */
8
+ import { ITask, ITaskDefinition, IResource, IResourceWithConfig, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyMapType, DependencyValuesType, IMiddleware, IEvent, RegisterableItems, ITag, ITagDefinition } from "./defs";
2
9
  export declare function defineTask<Input = undefined, Output extends Promise<any> = any, Deps extends DependencyMapType = any, TOn extends "*" | IEventDefinition | undefined = undefined>(taskConfig: ITaskDefinition<Input, Output, Deps, TOn>): ITask<Input, Output, Deps, TOn>;
3
10
  export declare function defineResource<TConfig = void, TValue = any, TDeps extends DependencyMapType = {}, TPrivate = any>(constConfig: IResourceDefinition<TConfig, TValue, TDeps, TPrivate>): IResource<TConfig, TValue, TDeps, TPrivate>;
4
11
  /**
@@ -27,3 +34,16 @@ export declare function isResource(definition: any): definition is IResource;
27
34
  export declare function isResourceWithConfig(definition: any): definition is IResourceWithConfig;
28
35
  export declare function isEvent(definition: any): definition is IEvent;
29
36
  export declare function isMiddleware(definition: any): definition is IMiddleware;
37
+ /**
38
+ * Override helper that preserves the original `id` and returns the same type.
39
+ * You can override any property except `id`.
40
+ */
41
+ export declare function defineOverride<T extends ITask<any, any, any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
42
+ export declare function defineOverride<T extends IResource<any, any, any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
43
+ export declare function defineOverride<T extends IMiddleware<any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
44
+ /**
45
+ * Creates a tag definition.
46
+ * - `.with(config)` to create configured instances
47
+ * - `.extract(tags)` to extract this tag from a list of tags
48
+ */
49
+ export declare function defineTag<TConfig = void>(definition: ITagDefinition<TConfig>): ITag<TConfig>;
package/dist/define.js CHANGED
@@ -10,17 +10,32 @@ exports.isResource = isResource;
10
10
  exports.isResourceWithConfig = isResourceWithConfig;
11
11
  exports.isEvent = isEvent;
12
12
  exports.isMiddleware = isMiddleware;
13
+ exports.defineOverride = defineOverride;
14
+ exports.defineTag = defineTag;
15
+ /**
16
+ * Factory functions for defining tasks, resources, events and middleware.
17
+ *
18
+ * These helpers create strongly-typed definitions while also wiring internal
19
+ * metadata: anonymous IDs, file path tags (for better debugging), lifecycle
20
+ * events, and global middleware flags. See README for high-level concepts.
21
+ */
13
22
  const defs_1 = require("./defs");
14
23
  const errors_1 = require("./errors");
15
24
  const getCallerFile_1 = require("./tools/getCallerFile");
16
25
  // Helper function to get the caller file
17
26
  function defineTask(taskConfig) {
27
+ /**
28
+ * Creates a task definition.
29
+ * - Generates an anonymous id based on file path when `id` is omitted
30
+ * - Wires lifecycle events: beforeRun, afterRun, onError
31
+ * - Carries through dependencies and middleware as declared
32
+ */
18
33
  const filePath = (0, getCallerFile_1.getCallerFile)();
19
34
  const isAnonymous = !Boolean(taskConfig.id);
20
35
  const id = taskConfig.id || (0, getCallerFile_1.generateCallerIdFromFile)(filePath, "task");
21
36
  return {
22
- [defs_1.symbols.task]: true,
23
- [defs_1.symbols.filePath]: filePath,
37
+ [defs_1.symbolTask]: true,
38
+ [defs_1.symbolFilePath]: filePath,
24
39
  id,
25
40
  dependencies: taskConfig.dependencies || {},
26
41
  middleware: taskConfig.middleware || [],
@@ -34,7 +49,7 @@ function defineTask(taskConfig) {
34
49
  ? Symbol(`anonymous-task.events.beforeRun`)
35
50
  : `${id}.events.beforeRun`,
36
51
  }),
37
- [defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
52
+ [defs_1.symbolFilePath]: (0, getCallerFile_1.getCallerFile)(),
38
53
  },
39
54
  afterRun: {
40
55
  ...defineEvent({
@@ -42,7 +57,7 @@ function defineTask(taskConfig) {
42
57
  ? Symbol(`anonymous-task.events.afterRun`)
43
58
  : `${id}.events.afterRun`,
44
59
  }),
45
- [defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
60
+ [defs_1.symbolFilePath]: (0, getCallerFile_1.getCallerFile)(),
46
61
  },
47
62
  onError: {
48
63
  ...defineEvent({
@@ -50,7 +65,7 @@ function defineTask(taskConfig) {
50
65
  ? Symbol(`anonymous-task.events.onError`)
51
66
  : `${id}.events.onError`,
52
67
  }),
53
- [defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
68
+ [defs_1.symbolFilePath]: (0, getCallerFile_1.getCallerFile)(),
54
69
  },
55
70
  },
56
71
  meta: taskConfig.meta || {},
@@ -58,6 +73,12 @@ function defineTask(taskConfig) {
58
73
  };
59
74
  }
60
75
  function defineResource(constConfig) {
76
+ /**
77
+ * Creates a resource definition.
78
+ * - Generates anonymous id when omitted (resource or index flavor)
79
+ * - Wires lifecycle events: beforeInit, afterInit, onError
80
+ * - Exposes `.with(config)` for config‑bound registration
81
+ */
61
82
  // The symbolFilePath might already come from defineIndex() for example
62
83
  const filePath = constConfig[defs_1.symbolFilePath] || (0, getCallerFile_1.getCallerFile)();
63
84
  const isIndexResource = constConfig[defs_1.symbolIndexResource] || false;
@@ -65,8 +86,9 @@ function defineResource(constConfig) {
65
86
  const id = constConfig.id ||
66
87
  (0, getCallerFile_1.generateCallerIdFromFile)(filePath, isIndexResource ? "index" : "resource");
67
88
  return {
68
- [defs_1.symbols.resource]: true,
69
- [defs_1.symbols.filePath]: filePath,
89
+ [defs_1.symbolResource]: true,
90
+ [defs_1.symbolFilePath]: filePath,
91
+ [defs_1.symbolIndexResource]: isIndexResource,
70
92
  id,
71
93
  dependencies: constConfig.dependencies,
72
94
  dispose: constConfig.dispose,
@@ -76,7 +98,7 @@ function defineResource(constConfig) {
76
98
  context: constConfig.context,
77
99
  with: function (config) {
78
100
  return {
79
- [defs_1.symbols.resourceWithConfig]: true,
101
+ [defs_1.symbolResourceWithConfig]: true,
80
102
  id: this.id,
81
103
  resource: this,
82
104
  config,
@@ -89,7 +111,7 @@ function defineResource(constConfig) {
89
111
  ? Symbol(`anonymous-resource.events.beforeInit`)
90
112
  : `${id}.events.beforeInit`,
91
113
  }),
92
- [defs_1.symbols.filePath]: filePath,
114
+ [defs_1.symbolFilePath]: filePath,
93
115
  },
94
116
  afterInit: {
95
117
  ...defineEvent({
@@ -97,7 +119,7 @@ function defineResource(constConfig) {
97
119
  ? Symbol(`anonymous-resource.events.afterInit`)
98
120
  : `${id}.events.afterInit`,
99
121
  }),
100
- [defs_1.symbols.filePath]: filePath,
122
+ [defs_1.symbolFilePath]: filePath,
101
123
  },
102
124
  onError: {
103
125
  ...defineEvent({
@@ -105,7 +127,7 @@ function defineResource(constConfig) {
105
127
  ? Symbol(`anonymous-resource.events.onError`)
106
128
  : `${id}.events.onError`,
107
129
  }),
108
- [defs_1.symbols.filePath]: filePath,
130
+ [defs_1.symbolFilePath]: filePath,
109
131
  },
110
132
  },
111
133
  meta: constConfig.meta || {},
@@ -119,6 +141,7 @@ function defineResource(constConfig) {
119
141
  * access them naturally: `deps.services.myTask()` or `deps.services.myResource`.
120
142
  */
121
143
  function defineIndex(items) {
144
+ // Build dependency map from given items; unwrap `.with()` to the base resource
122
145
  const dependencies = {};
123
146
  const register = [];
124
147
  for (const key of Object.keys(items)) {
@@ -138,25 +161,35 @@ function defineIndex(items) {
138
161
  async init(_, deps) {
139
162
  return deps;
140
163
  },
141
- [defs_1.symbols.filePath]: callerFilePath,
142
- [defs_1.symbols.indexResource]: true,
164
+ [defs_1.symbolFilePath]: callerFilePath,
165
+ [defs_1.symbolIndexResource]: true,
143
166
  });
144
167
  }
145
168
  function defineEvent(config) {
169
+ /**
170
+ * Creates an event definition. Anonymous ids are generated from file path
171
+ * when omitted. The returned object is branded for runtime checks.
172
+ */
146
173
  const callerFilePath = (0, getCallerFile_1.getCallerFile)();
147
174
  const eventConfig = config || {};
148
175
  return {
149
176
  ...eventConfig,
150
177
  id: eventConfig.id || (0, getCallerFile_1.generateCallerIdFromFile)(callerFilePath, "event"),
151
- [defs_1.symbols.filePath]: callerFilePath,
178
+ [defs_1.symbolFilePath]: callerFilePath,
152
179
  [defs_1.symbolEvent]: true, // This is a workaround
153
180
  };
154
181
  }
155
182
  function defineMiddleware(middlewareDef) {
183
+ /**
184
+ * Creates a middleware definition with:
185
+ * - Anonymous id generation when omitted
186
+ * - `.with(config)` to create configured instances
187
+ * - `.everywhere()` to mark as global (optionally scoping to tasks/resources)
188
+ */
156
189
  const filePath = (0, getCallerFile_1.getCallerFile)();
157
190
  const object = {
158
- [defs_1.symbols.filePath]: filePath,
159
- [defs_1.symbols.middleware]: true,
191
+ [defs_1.symbolFilePath]: filePath,
192
+ [defs_1.symbolMiddleware]: true,
160
193
  config: {},
161
194
  id: middlewareDef.id || (0, getCallerFile_1.generateCallerIdFromFile)(filePath, "middleware"),
162
195
  ...middlewareDef,
@@ -178,8 +211,8 @@ function defineMiddleware(middlewareDef) {
178
211
  const { tasks = true, resources = true } = options;
179
212
  return {
180
213
  ...object,
181
- [defs_1.symbols.middlewareEverywhereTasks]: tasks,
182
- [defs_1.symbols.middlewareEverywhereResources]: resources,
214
+ [defs_1.symbolMiddlewareEverywhereTasks]: tasks,
215
+ [defs_1.symbolMiddlewareEverywhereResources]: resources,
183
216
  everywhere() {
184
217
  throw errors_1.Errors.middlewareAlreadyGlobal(object.id);
185
218
  },
@@ -188,18 +221,57 @@ function defineMiddleware(middlewareDef) {
188
221
  };
189
222
  }
190
223
  function isTask(definition) {
191
- return definition && definition[defs_1.symbols.task];
224
+ return definition && definition[defs_1.symbolTask];
192
225
  }
193
226
  function isResource(definition) {
194
- return definition && definition[defs_1.symbols.resource];
227
+ return definition && definition[defs_1.symbolResource];
195
228
  }
196
229
  function isResourceWithConfig(definition) {
197
- return definition && definition[defs_1.symbols.resourceWithConfig];
230
+ return definition && definition[defs_1.symbolResourceWithConfig];
198
231
  }
199
232
  function isEvent(definition) {
200
- return definition && definition[defs_1.symbols.event];
233
+ return definition && definition[defs_1.symbolEvent];
201
234
  }
202
235
  function isMiddleware(definition) {
203
- return definition && definition[defs_1.symbols.middleware];
236
+ return definition && definition[defs_1.symbolMiddleware];
237
+ }
238
+ function defineOverride(base, patch) {
239
+ const { id: _ignored, ...rest } = (patch || {});
240
+ // Ensure we never change the id, and merge overrides last
241
+ return {
242
+ ...base,
243
+ ...rest,
244
+ id: base.id,
245
+ };
246
+ }
247
+ /**
248
+ * Creates a tag definition.
249
+ * - `.with(config)` to create configured instances
250
+ * - `.extract(tags)` to extract this tag from a list of tags
251
+ */
252
+ function defineTag(definition) {
253
+ const id = definition.id;
254
+ return {
255
+ id,
256
+ with(tagConfig) {
257
+ return {
258
+ id,
259
+ tag: this,
260
+ config: tagConfig,
261
+ };
262
+ },
263
+ extract(target) {
264
+ const tags = Array.isArray(target) ? target : target?.meta?.tags || [];
265
+ for (const candidate of tags) {
266
+ if (typeof candidate === "string")
267
+ continue;
268
+ // Configured instance
269
+ if (candidate.id === id) {
270
+ return candidate;
271
+ }
272
+ }
273
+ return null;
274
+ },
275
+ };
204
276
  }
205
277
  //# sourceMappingURL=define.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;AAwBA,gCAiD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GAAG,IAAI,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAQ,CAAC;IACvD,0DAA0D;IAC1D,OAAO;QACL,GAAI,IAAY;QAChB,GAAG,IAAI;QACP,EAAE,EAAG,IAAY,CAAC,EAAE;KACd,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS,CACvB,UAAmC;IAEnC,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;IAEzB,OAAO;QACL,EAAE;QACF,IAAI,CAAC,SAAkB;YACrB,OAAO;gBACL,EAAE;gBACF,GAAG,EAAE,IAAI;gBACT,MAAM,EAAE,SAAgB;aACE,CAAC;QAC/B,CAAC;QACD,OAAO,CAAC,MAA6B;YACnC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;YACvE,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;gBAC7B,IAAI,OAAO,SAAS,KAAK,QAAQ;oBAAE,SAAS;gBAC5C,sBAAsB;gBACtB,IAAI,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;oBACxB,OAAO,SAAoC,CAAC;gBAC9C,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACe,CAAC;AACrB,CAAC"}
@@ -0,0 +1,144 @@
1
+ import { IEventMeta, IMiddlewareMeta, IResourceMeta, ITaskMeta } from "./tags";
2
+ import { symbolEvent, symbolMiddleware, symbolMiddlewareConfigured, symbolMiddlewareEverywhereResources, symbolMiddlewareEverywhereTasks } from "./symbols";
3
+ export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> extends ITaskDefinition<TInput, TOutput, TDependencies, TOn> {
4
+ id: string | symbol;
5
+ dependencies: TDependencies | (() => TDependencies);
6
+ computedDependencies?: DependencyValuesType<TDependencies>;
7
+ middleware: MiddlewareAttachments[];
8
+ events: {
9
+ beforeRun: IEvent<BeforeRunEventPayload<TInput>>;
10
+ afterRun: IEvent<AfterRunEventPayload<TInput, TOutput>>;
11
+ onError: IEvent<OnErrorEventPayload>;
12
+ };
13
+ }
14
+ export type DependencyMapType = Record<string, ITask<any, any, any, any> | IResource<any, any, any> | IEventDefinition<any>>;
15
+ type ExtractTaskInput<T> = T extends ITask<infer I, any, any, any> ? I : never;
16
+ type ExtractTaskOutput<T> = T extends ITask<any, infer O, any, any> ? O : never;
17
+ type ExtractResourceValue<T> = T extends IResource<any, infer V, any> ? V : never;
18
+ type ExtractEventParams<T> = T extends IEvent<infer P> ? P : never;
19
+ type TaskDependency<I, O> = (...args: I extends null | void ? [] : [I]) => O;
20
+ type ResourceDependency<V> = V;
21
+ type EventDependency<P> = P extends void ? (() => Promise<void>) & ((input?: Record<string, never>) => Promise<void>) : (input: P) => Promise<void>;
22
+ export type DependencyValueType<T> = T extends ITask<any, any, any, any> ? TaskDependency<ExtractTaskInput<T>, ExtractTaskOutput<T>> : T extends IResource<any, any, any> ? ResourceDependency<ExtractResourceValue<T>> : T extends IEventDefinition<any> ? EventDependency<ExtractEventParams<T>> : never;
23
+ export type DependencyValuesType<T extends DependencyMapType> = {
24
+ [K in keyof T]: DependencyValueType<T[K]>;
25
+ };
26
+ export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<void, any, any, any> | IResource<{
27
+ [K in any]?: any;
28
+ }, any, any, any> | ITask<any, any, any, any> | IMiddleware<any> | IEvent<any>;
29
+ export type MiddlewareAttachments = IMiddleware<void> | IMiddleware<{
30
+ [K in any]?: any;
31
+ }> | IMiddlewareConfigured<any>;
32
+ export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> {
33
+ id?: string | symbol;
34
+ dependencies?: TDependencies | (() => TDependencies);
35
+ middleware?: MiddlewareAttachments[];
36
+ on?: TOn;
37
+ listenerOrder?: number;
38
+ meta?: ITaskMeta;
39
+ run: (input: TOn extends undefined ? TInput : IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => TOutput;
40
+ }
41
+ export type BeforeRunEventPayload<TInput> = {
42
+ input: TInput;
43
+ };
44
+ export type AfterRunEventPayload<TInput, TOutput> = {
45
+ input: TInput;
46
+ output: TOutput extends Promise<infer U> ? U : TOutput;
47
+ setOutput(newOutput: TOutput extends Promise<infer U> ? U : TOutput): void;
48
+ };
49
+ export type OnErrorEventPayload = {
50
+ error: any;
51
+ suppress(): void;
52
+ };
53
+ export type BeforeInitEventPayload<TConfig> = {
54
+ config: TConfig;
55
+ };
56
+ export type AfterInitEventPayload<TConfig, TValue> = {
57
+ config: TConfig;
58
+ value: TValue;
59
+ };
60
+ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependencies extends DependencyMapType = {}, TContext = any> {
61
+ id?: string | symbol;
62
+ dependencies?: TDependencies | ((config: TConfig) => TDependencies);
63
+ register?: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
64
+ init?: (this: any, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<TValue>;
65
+ dispose?: (this: any, value: TValue, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
66
+ meta?: IResourceMeta;
67
+ overrides?: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
68
+ middleware?: MiddlewareAttachments[];
69
+ context?: () => TContext;
70
+ [symbolFilePath]?: string;
71
+ [symbolIndexResource]?: boolean;
72
+ }
73
+ import { symbolFilePath, symbolIndexResource } from "./symbols";
74
+ export interface IResource<TConfig = void, TValue = any, TDependencies extends DependencyMapType = any, TContext = any> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext> {
75
+ id: string | symbol;
76
+ with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
77
+ register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
78
+ events: {
79
+ beforeInit: IEvent<BeforeInitEventPayload<TConfig>>;
80
+ afterInit: IEvent<AfterInitEventPayload<TConfig, TValue>>;
81
+ onError: IEvent<OnErrorEventPayload>;
82
+ };
83
+ overrides: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
84
+ middleware: MiddlewareAttachments[];
85
+ }
86
+ export interface IResourceWithConfig<TConfig = any, TValue = any, TDependencies extends DependencyMapType = any> {
87
+ id: string;
88
+ resource: IResource<TConfig, TValue, TDependencies>;
89
+ config: TConfig;
90
+ }
91
+ export type EventHandlerType<T = any> = (event: IEventEmission<T>) => any | Promise<any>;
92
+ export interface IEventDefinition<TPayload = void> {
93
+ id?: string | symbol;
94
+ meta?: IEventMeta;
95
+ }
96
+ export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
97
+ id: string | symbol;
98
+ [symbolEvent]: true;
99
+ }
100
+ export interface IMiddlewareDefinition<TConfig = any, TDependencies extends DependencyMapType = any> {
101
+ id?: string | symbol;
102
+ dependencies?: TDependencies | ((config: TConfig) => TDependencies);
103
+ run: (input: IMiddlewareExecutionInput, dependencies: DependencyValuesType<TDependencies>, config: TConfig) => Promise<any>;
104
+ meta?: IMiddlewareMeta;
105
+ }
106
+ export interface IMiddleware<TConfig = any, TDependencies extends DependencyMapType = any> extends IMiddlewareDefinition<TConfig, TDependencies> {
107
+ [symbolMiddleware]: true;
108
+ [symbolMiddlewareConfigured]?: boolean;
109
+ [symbolMiddlewareEverywhereTasks]?: boolean;
110
+ [symbolMiddlewareEverywhereResources]?: boolean;
111
+ id: string | symbol;
112
+ dependencies: TDependencies | (() => TDependencies);
113
+ everywhere(config?: import("../define").MiddlewareEverywhereOptions): IMiddleware<TConfig, TDependencies>;
114
+ config: TConfig;
115
+ with: (config: TConfig) => IMiddlewareConfigured<TConfig, TDependencies>;
116
+ }
117
+ export interface IMiddlewareConfigured<TConfig = any, TDependencies extends DependencyMapType = any> extends IMiddleware<TConfig, TDependencies> {
118
+ [symbolMiddlewareConfigured]: true;
119
+ }
120
+ export interface IMiddlewareDefinitionConfigured<C extends Record<string, any> = {}> {
121
+ middleware: IMiddleware<C>;
122
+ config?: C;
123
+ }
124
+ export interface IMiddlewareExecutionInput<TTaskInput = any, TResourceConfig = any> {
125
+ task?: {
126
+ definition: ITask<TTaskInput>;
127
+ input: TTaskInput;
128
+ };
129
+ resource?: {
130
+ definition: IResource<TResourceConfig>;
131
+ config: TResourceConfig;
132
+ };
133
+ next: (taskInputOrResourceConfig?: TTaskInput | TResourceConfig) => Promise<any>;
134
+ }
135
+ export interface IEventEmission<TPayload = any> {
136
+ id: string | symbol;
137
+ data: TPayload;
138
+ timestamp: Date;
139
+ source: string | symbol;
140
+ meta: IEventMeta;
141
+ stopPropagation(): void;
142
+ isPropagationStopped(): boolean;
143
+ }
144
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const symbols_1 = require("./symbols");
4
+ // symbol imports referenced above
5
+ const symbols_2 = require("./symbols");
6
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/defs/core.ts"],"names":[],"mappings":";;AACA,uCASmB;AAyInB,kCAAkC;AAClC,uCAAgE"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Internal brand symbols used to tag created objects at runtime and help with
3
+ * type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
4
+ * helpers instead of touching these directly.
5
+ * @internal
6
+ */
7
+ export declare const symbolTask: unique symbol;
8
+ export declare const symbolResource: unique symbol;
9
+ export declare const symbolResourceWithConfig: unique symbol;
10
+ export declare const symbolEvent: unique symbol;
11
+ export declare const symbolMiddleware: unique symbol;
12
+ export declare const symbolMiddlewareConfigured: unique symbol;
13
+ export declare const symbolMiddlewareGlobal: unique symbol;
14
+ export declare const symbolMiddlewareEverywhereTasks: unique symbol;
15
+ export declare const symbolMiddlewareEverywhereResources: unique symbol;
16
+ /** @internal Path to aid anonymous id generation and error messages */
17
+ export declare const symbolFilePath: unique symbol;
18
+ /** @internal Marks disposable instances */
19
+ export declare const symbolDispose: unique symbol;
20
+ /** @internal Link to internal Store */
21
+ export declare const symbolStore: unique symbol;
22
+ /** @internal Brand used by index() resources */
23
+ export declare const symbolIndexResource: unique symbol;
24
+ /**
25
+ * Convenience bag of internal symbols. Intended for framework internals;
26
+ * consumers should not rely on this shape.
27
+ * @internal
28
+ */
29
+ export declare const symbols: {
30
+ task: symbol;
31
+ resource: symbol;
32
+ resourceWithConfig: symbol;
33
+ indexResource: symbol;
34
+ event: symbol;
35
+ middleware: symbol;
36
+ middlewareEverywhereTasks: symbol;
37
+ middlewareEverywhereResources: symbol;
38
+ filePath: symbol;
39
+ dispose: symbol;
40
+ store: symbol;
41
+ };
42
+ export type SymbolsBag = typeof symbols;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.symbols = exports.symbolIndexResource = exports.symbolStore = exports.symbolDispose = exports.symbolFilePath = exports.symbolMiddlewareEverywhereResources = exports.symbolMiddlewareEverywhereTasks = exports.symbolMiddlewareGlobal = exports.symbolMiddlewareConfigured = exports.symbolMiddleware = exports.symbolEvent = exports.symbolResourceWithConfig = exports.symbolResource = exports.symbolTask = void 0;
4
+ /**
5
+ * Internal brand symbols used to tag created objects at runtime and help with
6
+ * type‑narrowing. Prefer the `isTask`/`isResource`/`isEvent`/`isMiddleware`
7
+ * helpers instead of touching these directly.
8
+ * @internal
9
+ */
10
+ exports.symbolTask = Symbol("runner.task");
11
+ exports.symbolResource = Symbol("runner.resource");
12
+ exports.symbolResourceWithConfig = Symbol("runner.resourceWithConfig");
13
+ exports.symbolEvent = Symbol("runner.event");
14
+ exports.symbolMiddleware = Symbol("runner.middleware");
15
+ exports.symbolMiddlewareConfigured = Symbol("runner.middlewareConfigured");
16
+ exports.symbolMiddlewareGlobal = Symbol("runner.middlewareGlobal");
17
+ exports.symbolMiddlewareEverywhereTasks = Symbol("runner.middlewareGlobalTasks");
18
+ exports.symbolMiddlewareEverywhereResources = Symbol("runner.middlewareGlobalResources");
19
+ /** @internal Path to aid anonymous id generation and error messages */
20
+ exports.symbolFilePath = Symbol("runner.filePath");
21
+ /** @internal Marks disposable instances */
22
+ exports.symbolDispose = Symbol("runner.dispose");
23
+ /** @internal Link to internal Store */
24
+ exports.symbolStore = Symbol("runner.store");
25
+ /** @internal Brand used by index() resources */
26
+ exports.symbolIndexResource = Symbol("runner.indexResource");
27
+ /**
28
+ * Convenience bag of internal symbols. Intended for framework internals;
29
+ * consumers should not rely on this shape.
30
+ * @internal
31
+ */
32
+ exports.symbols = {
33
+ task: exports.symbolTask,
34
+ resource: exports.symbolResource,
35
+ resourceWithConfig: exports.symbolResourceWithConfig,
36
+ indexResource: exports.symbolIndexResource,
37
+ event: exports.symbolEvent,
38
+ middleware: exports.symbolMiddleware,
39
+ middlewareEverywhereTasks: exports.symbolMiddlewareEverywhereTasks,
40
+ middlewareEverywhereResources: exports.symbolMiddlewareEverywhereResources,
41
+ filePath: exports.symbolFilePath,
42
+ dispose: exports.symbolDispose,
43
+ store: exports.symbolStore,
44
+ };
45
+ //# sourceMappingURL=symbols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/defs/symbols.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,UAAU,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAClD,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1D,QAAA,wBAAwB,GAAkB,MAAM,CAC3D,2BAA2B,CAC5B,CAAC;AACW,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AACpD,QAAA,gBAAgB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC9D,QAAA,0BAA0B,GAAkB,MAAM,CAC7D,6BAA6B,CAC9B,CAAC;AACW,QAAA,sBAAsB,GAAkB,MAAM,CACzD,yBAAyB,CAC1B,CAAC;AACW,QAAA,+BAA+B,GAAkB,MAAM,CAClE,8BAA8B,CAC/B,CAAC;AACW,QAAA,mCAAmC,GAAkB,MAAM,CACtE,kCAAkC,CACnC,CAAC;AAEF,uEAAuE;AAC1D,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACvE,2CAA2C;AAC9B,QAAA,aAAa,GAAkB,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACrE,uCAAuC;AAC1B,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAEjE,gDAAgD;AACnC,QAAA,mBAAmB,GAAkB,MAAM,CACtD,sBAAsB,CACvB,CAAC;AAEF;;;;GAIG;AACU,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,kBAAU;IAChB,QAAQ,EAAE,sBAAc;IACxB,kBAAkB,EAAE,gCAAwB;IAC5C,aAAa,EAAE,2BAAmB;IAClC,KAAK,EAAE,mBAAW;IAClB,UAAU,EAAE,wBAAgB;IAC5B,yBAAyB,EAAE,uCAA+B;IAC1D,6BAA6B,EAAE,2CAAmC;IAClE,QAAQ,EAAE,sBAAc;IACxB,OAAO,EAAE,qBAAa;IACtB,KAAK,EAAE,mBAAW;CACnB,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Tag system and metadata types.
3
+ */
4
+ export interface ITagDefinition<TConfig = void> {
5
+ id: string | symbol;
6
+ }
7
+ /**
8
+ * A configured instance of a tag as produced by `ITag.with()`.
9
+ */
10
+ export interface ITagWithConfig<TConfig = void> {
11
+ id: string | symbol;
12
+ /** The tag definition used to produce this configured instance. */
13
+ tag: ITag<TConfig>;
14
+ /** The configuration captured for this tag instance. */
15
+ config: TConfig;
16
+ }
17
+ /**
18
+ * A tag definition (builder). Use `.with(config)` to obtain configured instances,
19
+ * and `.extract(tags)` to find either a configured instance or the bare tag in a list.
20
+ */
21
+ export interface ITag<TConfig = void> extends ITagDefinition<TConfig> {
22
+ /** Creates a configured instance of the tag. */
23
+ with(config: TConfig): ITagWithConfig<TConfig>;
24
+ /**
25
+ * Extracts either a configured instance or the bare tag from a list of tags
26
+ * or from a taggable object (`{ meta: { tags?: [] } }`).
27
+ */
28
+ extract(target: TagType[] | ITaggable): ExtractedTagResult<TConfig> | null;
29
+ }
30
+ /**
31
+ * Restrict bare tags to those whose config can be omitted (void or optional object),
32
+ * mirroring the same principle used for resources in `RegisterableItems`.
33
+ * Required-config tags must appear as configured instances.
34
+ */
35
+ export type TagType = string | ITag<void> | ITag<{
36
+ [K in any]?: any;
37
+ }> | ITagWithConfig<any>;
38
+ /**
39
+ * Conditional result type for `ITag.extract`:
40
+ * - For void config → just the identifier
41
+ * - For optional object config → identifier with optional config
42
+ * - For required config → identifier with required config
43
+ */
44
+ export type ExtractedTagResult<TConfig> = {} extends TConfig ? {
45
+ id: string | symbol;
46
+ config?: TConfig;
47
+ } : {
48
+ id: string | symbol;
49
+ config: TConfig;
50
+ };
51
+ /** Any object that can carry tags via metadata. */
52
+ export interface ITaggable {
53
+ meta?: {
54
+ tags?: TagType[];
55
+ };
56
+ }
57
+ /** Common metadata you can attach to tasks/resources/events/middleware. */
58
+ export interface IMeta {
59
+ title?: string;
60
+ description?: string;
61
+ tags?: TagType[];
62
+ }
63
+ export interface ITaskMeta extends IMeta {
64
+ }
65
+ export interface IResourceMeta extends IMeta {
66
+ }
67
+ export interface IEventMeta extends IMeta {
68
+ }
69
+ export interface IMiddlewareMeta extends IMeta {
70
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Tag system and metadata types.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../src/defs/tags.ts"],"names":[],"mappings":";AAAA;;GAEG"}