@bluelibs/runner 3.4.1 → 3.4.3
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.
- package/README.md +77 -281
- package/dist/define.d.ts +68 -4
- package/dist/define.js +121 -51
- package/dist/define.js.map +1 -1
- package/dist/globals/globalMiddleware.d.ts +3 -3
- package/dist/globals/middleware/requireContext.middleware.d.ts +1 -1
- package/dist/globals/middleware/retry.middleware.d.ts +1 -1
- package/dist/globals/middleware/timeout.middleware.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/models/StoreConstants.d.ts +1 -1
- package/dist/tools/getCallerFile.js +16 -6
- package/dist/tools/getCallerFile.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/globalEvents.test.ts +1 -1
- package/src/__tests__/run.anonymous.test.ts +27 -0
- package/src/__tests__/run.middleware.test.ts +71 -0
- package/src/__tests__/tools/getCallerFile.test.ts +20 -5
- package/src/define.ts +145 -57
- package/src/tools/getCallerFile.ts +18 -7
package/dist/define.d.ts
CHANGED
|
@@ -6,6 +6,23 @@
|
|
|
6
6
|
* events, and global middleware flags. See README for high-level concepts.
|
|
7
7
|
*/
|
|
8
8
|
import { ITask, ITaskDefinition, IResource, IResourceWithConfig, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyMapType, DependencyValuesType, IMiddleware, IEvent, RegisterableItems, ITag, ITagDefinition, ITaskMeta, IResourceMeta } from "./defs";
|
|
9
|
+
/**
|
|
10
|
+
* Define a task.
|
|
11
|
+
* Generates a strongly-typed task object with id, lifecycle events, dependencies,
|
|
12
|
+
* middleware, and metadata.
|
|
13
|
+
*
|
|
14
|
+
* - If `id` is omitted, an anonymous, file-based id is generated.
|
|
15
|
+
* - Wires lifecycle events: `beforeRun`, `afterRun`, `onError`.
|
|
16
|
+
* - Carries through dependencies, middleware, input schema, and metadata.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam Input - Input type accepted by the task's `run` function.
|
|
19
|
+
* @typeParam Output - Promise type returned by the `run` function.
|
|
20
|
+
* @typeParam Deps - Dependency map type this task requires.
|
|
21
|
+
* @typeParam TOn - Event type or "*" this task listens to.
|
|
22
|
+
* @typeParam TMeta - Arbitrary metadata type carried by the task.
|
|
23
|
+
* @param taskConfig - The task definition config.
|
|
24
|
+
* @returns A branded task definition usable by the runner.
|
|
25
|
+
*/
|
|
9
26
|
export declare function defineTask<Input = undefined, Output extends Promise<any> = any, Deps extends DependencyMapType = any, TOn extends "*" | IEventDefinition | undefined = undefined, TMeta extends ITaskMeta = any>(taskConfig: ITaskDefinition<Input, Output, Deps, TOn, TMeta>): ITask<Input, Output, Deps, TOn, TMeta>;
|
|
10
27
|
export declare function defineResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDeps extends DependencyMapType = {}, TPrivate = any, TMeta extends IResourceMeta = any>(constConfig: IResourceDefinition<TConfig, TValue, TDeps, TPrivate, any, any, TMeta>): IResource<TConfig, TValue, TDeps, TPrivate, TMeta>;
|
|
11
28
|
/**
|
|
@@ -28,22 +45,69 @@ export type MiddlewareEverywhereOptions = {
|
|
|
28
45
|
*/
|
|
29
46
|
resources?: boolean;
|
|
30
47
|
};
|
|
31
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Define a middleware.
|
|
50
|
+
* Creates a middleware definition with anonymous id generation, `.with(config)`,
|
|
51
|
+
* and `.everywhere()` helpers.
|
|
52
|
+
*
|
|
53
|
+
* - `.with(config)` merges config (optionally validated via `configSchema`).
|
|
54
|
+
* - `.everywhere()` marks the middleware global (optionally scoping to tasks/resources).
|
|
55
|
+
*
|
|
56
|
+
* @typeParam TConfig - Configuration type accepted by the middleware.
|
|
57
|
+
* @typeParam TDependencies - Dependency map type required by the middleware.
|
|
58
|
+
* @param middlewareDef - The middleware definition config.
|
|
59
|
+
* @returns A branded middleware definition usable by the runner.
|
|
60
|
+
*/
|
|
61
|
+
export declare function defineMiddleware<TConfig extends Record<string, any> = any, TDependencies extends DependencyMapType = any>(middlewareDef: IMiddlewareDefinition<TConfig, TDependencies>): IMiddleware<TConfig, TDependencies>;
|
|
62
|
+
/**
|
|
63
|
+
* Type guard: checks if a definition is a Task.
|
|
64
|
+
* @param definition - Any value to test.
|
|
65
|
+
* @returns True when `definition` is a branded Task.
|
|
66
|
+
*/
|
|
32
67
|
export declare function isTask(definition: any): definition is ITask;
|
|
68
|
+
/**
|
|
69
|
+
* Type guard: checks if a definition is a Resource.
|
|
70
|
+
* @param definition - Any value to test.
|
|
71
|
+
* @returns True when `definition` is a branded Resource.
|
|
72
|
+
*/
|
|
33
73
|
export declare function isResource(definition: any): definition is IResource;
|
|
74
|
+
/**
|
|
75
|
+
* Type guard: checks if a definition is a Resource that carries config via `.with()`.
|
|
76
|
+
* @param definition - Any value to test.
|
|
77
|
+
* @returns True when `definition` is a branded ResourceWithConfig.
|
|
78
|
+
*/
|
|
34
79
|
export declare function isResourceWithConfig(definition: any): definition is IResourceWithConfig;
|
|
80
|
+
/**
|
|
81
|
+
* Type guard: checks if a definition is an Event.
|
|
82
|
+
* @param definition - Any value to test.
|
|
83
|
+
* @returns True when `definition` is a branded Event.
|
|
84
|
+
*/
|
|
35
85
|
export declare function isEvent(definition: any): definition is IEvent;
|
|
86
|
+
/**
|
|
87
|
+
* Type guard: checks if a definition is a Middleware.
|
|
88
|
+
* @param definition - Any value to test.
|
|
89
|
+
* @returns True when `definition` is a branded Middleware.
|
|
90
|
+
*/
|
|
36
91
|
export declare function isMiddleware(definition: any): definition is IMiddleware;
|
|
37
92
|
/**
|
|
38
93
|
* Override helper that preserves the original `id` and returns the same type.
|
|
39
|
-
* You can override any property except `id`.
|
|
94
|
+
* You can override any property except `id`. The override is shallow-merged over the base.
|
|
95
|
+
*
|
|
96
|
+
* @param base - The base definition to override.
|
|
97
|
+
* @param patch - Properties to override (except `id`).
|
|
98
|
+
* @returns A definition of the same kind with overrides applied.
|
|
40
99
|
*/
|
|
41
100
|
export declare function defineOverride<T extends ITask<any, any, any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
|
|
42
101
|
export declare function defineOverride<T extends IResource<any, any, any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
|
|
43
102
|
export declare function defineOverride<T extends IMiddleware<any, any>>(base: T, patch: Omit<Partial<T>, "id">): T;
|
|
44
103
|
/**
|
|
45
|
-
*
|
|
104
|
+
* Create a tag definition.
|
|
46
105
|
* - `.with(config)` to create configured instances
|
|
47
|
-
* - `.extract(tags)` to extract this tag from a list of tags
|
|
106
|
+
* - `.extract(tags)` to extract this tag from a list of tags or a taggable's meta
|
|
107
|
+
*
|
|
108
|
+
* @typeParam TConfig - Configuration type carried by configured tags.
|
|
109
|
+
* @typeParam TEnforceContract - Optional helper type to enforce a contract when tags are used.
|
|
110
|
+
* @param definition - The tag definition (id).
|
|
111
|
+
* @returns A tag object with helpers to configure and extract.
|
|
48
112
|
*/
|
|
49
113
|
export declare function defineTag<TConfig = void, TEnforceContract = void>(definition: ITagDefinition<TConfig, TEnforceContract>): ITag<TConfig, TEnforceContract>;
|
package/dist/define.js
CHANGED
|
@@ -23,13 +23,24 @@ const defs_1 = require("./defs");
|
|
|
23
23
|
const errors_1 = require("./errors");
|
|
24
24
|
const getCallerFile_1 = require("./tools/getCallerFile");
|
|
25
25
|
// Helper function to get the caller file
|
|
26
|
+
/**
|
|
27
|
+
* Define a task.
|
|
28
|
+
* Generates a strongly-typed task object with id, lifecycle events, dependencies,
|
|
29
|
+
* middleware, and metadata.
|
|
30
|
+
*
|
|
31
|
+
* - If `id` is omitted, an anonymous, file-based id is generated.
|
|
32
|
+
* - Wires lifecycle events: `beforeRun`, `afterRun`, `onError`.
|
|
33
|
+
* - Carries through dependencies, middleware, input schema, and metadata.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam Input - Input type accepted by the task's `run` function.
|
|
36
|
+
* @typeParam Output - Promise type returned by the `run` function.
|
|
37
|
+
* @typeParam Deps - Dependency map type this task requires.
|
|
38
|
+
* @typeParam TOn - Event type or "*" this task listens to.
|
|
39
|
+
* @typeParam TMeta - Arbitrary metadata type carried by the task.
|
|
40
|
+
* @param taskConfig - The task definition config.
|
|
41
|
+
* @returns A branded task definition usable by the runner.
|
|
42
|
+
*/
|
|
26
43
|
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
|
-
*/
|
|
33
44
|
const filePath = (0, getCallerFile_1.getCallerFile)();
|
|
34
45
|
const isAnonymous = !Boolean(taskConfig.id);
|
|
35
46
|
const id = taskConfig.id || (0, getCallerFile_1.generateCallerIdFromFile)(filePath, "task");
|
|
@@ -75,10 +86,21 @@ function defineTask(taskConfig) {
|
|
|
75
86
|
}
|
|
76
87
|
function defineResource(constConfig) {
|
|
77
88
|
/**
|
|
78
|
-
*
|
|
79
|
-
* -
|
|
80
|
-
*
|
|
81
|
-
*
|
|
89
|
+
* Define a resource.
|
|
90
|
+
* Produces a strongly-typed resource with id, lifecycle events, registration hooks,
|
|
91
|
+
* and optional config schema.
|
|
92
|
+
*
|
|
93
|
+
* - If `id` is omitted, an anonymous, file-based id is generated (resource or index flavored).
|
|
94
|
+
* - Wires lifecycle events: `beforeInit`, `afterInit`, `onError`.
|
|
95
|
+
* - Provides `.with(config)` for config-bound registration with optional runtime validation.
|
|
96
|
+
*
|
|
97
|
+
* @typeParam TConfig - Configuration type accepted by the resource.
|
|
98
|
+
* @typeParam TValue - Promise type resolved by the resource `init`.
|
|
99
|
+
* @typeParam TDeps - Dependency map type this resource requires.
|
|
100
|
+
* @typeParam TPrivate - Private context type exposed to middleware during init.
|
|
101
|
+
* @typeParam TMeta - Arbitrary metadata type carried by the resource.
|
|
102
|
+
* @param constConfig - The resource definition config.
|
|
103
|
+
* @returns A branded resource definition usable by the runner.
|
|
82
104
|
*/
|
|
83
105
|
// The symbolFilePath might already come from defineIndex() for example
|
|
84
106
|
const filePath = constConfig[defs_1.symbolFilePath] || (0, getCallerFile_1.getCallerFile)();
|
|
@@ -178,8 +200,13 @@ function defineIndex(items) {
|
|
|
178
200
|
}
|
|
179
201
|
function defineEvent(config) {
|
|
180
202
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
203
|
+
* Define an event.
|
|
204
|
+
* Generates a branded event definition with a stable id (anonymous if omitted)
|
|
205
|
+
* and file path metadata for better debugging.
|
|
206
|
+
*
|
|
207
|
+
* @typeParam TPayload - Payload type carried by the event.
|
|
208
|
+
* @param config - Optional event definition (id, etc.).
|
|
209
|
+
* @returns A branded event definition.
|
|
183
210
|
*/
|
|
184
211
|
const callerFilePath = (0, getCallerFile_1.getCallerFile)();
|
|
185
212
|
const eventConfig = config || {};
|
|
@@ -190,15 +217,22 @@ function defineEvent(config) {
|
|
|
190
217
|
[defs_1.symbolEvent]: true, // This is a workaround
|
|
191
218
|
};
|
|
192
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Define a middleware.
|
|
222
|
+
* Creates a middleware definition with anonymous id generation, `.with(config)`,
|
|
223
|
+
* and `.everywhere()` helpers.
|
|
224
|
+
*
|
|
225
|
+
* - `.with(config)` merges config (optionally validated via `configSchema`).
|
|
226
|
+
* - `.everywhere()` marks the middleware global (optionally scoping to tasks/resources).
|
|
227
|
+
*
|
|
228
|
+
* @typeParam TConfig - Configuration type accepted by the middleware.
|
|
229
|
+
* @typeParam TDependencies - Dependency map type required by the middleware.
|
|
230
|
+
* @param middlewareDef - The middleware definition config.
|
|
231
|
+
* @returns A branded middleware definition usable by the runner.
|
|
232
|
+
*/
|
|
193
233
|
function defineMiddleware(middlewareDef) {
|
|
194
|
-
/**
|
|
195
|
-
* Creates a middleware definition with:
|
|
196
|
-
* - Anonymous id generation when omitted
|
|
197
|
-
* - `.with(config)` to create configured instances
|
|
198
|
-
* - `.everywhere()` to mark as global (optionally scoping to tasks/resources)
|
|
199
|
-
*/
|
|
200
234
|
const filePath = (0, getCallerFile_1.getCallerFile)();
|
|
201
|
-
const
|
|
235
|
+
const base = {
|
|
202
236
|
[defs_1.symbolFilePath]: filePath,
|
|
203
237
|
[defs_1.symbolMiddleware]: true,
|
|
204
238
|
config: {},
|
|
@@ -206,52 +240,83 @@ function defineMiddleware(middlewareDef) {
|
|
|
206
240
|
...middlewareDef,
|
|
207
241
|
dependencies: middlewareDef.dependencies || {},
|
|
208
242
|
};
|
|
209
|
-
return
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
243
|
+
// Wrap an object to ensure we always return chainable helpers
|
|
244
|
+
const wrap = (obj) => {
|
|
245
|
+
return {
|
|
246
|
+
...obj,
|
|
247
|
+
with: (config) => {
|
|
248
|
+
// Validate config with schema if provided (fail fast)
|
|
249
|
+
if (obj.configSchema) {
|
|
250
|
+
try {
|
|
251
|
+
config = obj.configSchema.parse(config);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
throw new errors_1.ValidationError("Middleware config", obj.id, error instanceof Error ? error : new Error(String(error)));
|
|
255
|
+
}
|
|
216
256
|
}
|
|
217
|
-
|
|
218
|
-
|
|
257
|
+
return wrap({
|
|
258
|
+
...obj,
|
|
259
|
+
[defs_1.symbolMiddlewareConfigured]: true,
|
|
260
|
+
config: {
|
|
261
|
+
...obj.config,
|
|
262
|
+
...config,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
},
|
|
266
|
+
everywhere(options = {}) {
|
|
267
|
+
const { tasks = true, resources = true } = options;
|
|
268
|
+
// If already global, prevent calling again
|
|
269
|
+
if (obj[defs_1.symbolMiddlewareEverywhereTasks] ||
|
|
270
|
+
obj[defs_1.symbolMiddlewareEverywhereResources]) {
|
|
271
|
+
throw new errors_1.MiddlewareAlreadyGlobalError(obj.id);
|
|
219
272
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
everywhere(options = {}) {
|
|
231
|
-
const { tasks = true, resources = true } = options;
|
|
232
|
-
return {
|
|
233
|
-
...object,
|
|
234
|
-
[defs_1.symbolMiddlewareEverywhereTasks]: tasks,
|
|
235
|
-
[defs_1.symbolMiddlewareEverywhereResources]: resources,
|
|
236
|
-
everywhere() {
|
|
237
|
-
throw new errors_1.MiddlewareAlreadyGlobalError(object.id);
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
},
|
|
273
|
+
return wrap({
|
|
274
|
+
...obj,
|
|
275
|
+
[defs_1.symbolMiddlewareEverywhereTasks]: tasks,
|
|
276
|
+
[defs_1.symbolMiddlewareEverywhereResources]: resources,
|
|
277
|
+
});
|
|
278
|
+
},
|
|
279
|
+
};
|
|
241
280
|
};
|
|
281
|
+
return wrap(base);
|
|
242
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Type guard: checks if a definition is a Task.
|
|
285
|
+
* @param definition - Any value to test.
|
|
286
|
+
* @returns True when `definition` is a branded Task.
|
|
287
|
+
*/
|
|
243
288
|
function isTask(definition) {
|
|
244
289
|
return definition && definition[defs_1.symbolTask];
|
|
245
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Type guard: checks if a definition is a Resource.
|
|
293
|
+
* @param definition - Any value to test.
|
|
294
|
+
* @returns True when `definition` is a branded Resource.
|
|
295
|
+
*/
|
|
246
296
|
function isResource(definition) {
|
|
247
297
|
return definition && definition[defs_1.symbolResource];
|
|
248
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Type guard: checks if a definition is a Resource that carries config via `.with()`.
|
|
301
|
+
* @param definition - Any value to test.
|
|
302
|
+
* @returns True when `definition` is a branded ResourceWithConfig.
|
|
303
|
+
*/
|
|
249
304
|
function isResourceWithConfig(definition) {
|
|
250
305
|
return definition && definition[defs_1.symbolResourceWithConfig];
|
|
251
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Type guard: checks if a definition is an Event.
|
|
309
|
+
* @param definition - Any value to test.
|
|
310
|
+
* @returns True when `definition` is a branded Event.
|
|
311
|
+
*/
|
|
252
312
|
function isEvent(definition) {
|
|
253
313
|
return definition && definition[defs_1.symbolEvent];
|
|
254
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Type guard: checks if a definition is a Middleware.
|
|
317
|
+
* @param definition - Any value to test.
|
|
318
|
+
* @returns True when `definition` is a branded Middleware.
|
|
319
|
+
*/
|
|
255
320
|
function isMiddleware(definition) {
|
|
256
321
|
return definition && definition[defs_1.symbolMiddleware];
|
|
257
322
|
}
|
|
@@ -265,9 +330,14 @@ function defineOverride(base, patch) {
|
|
|
265
330
|
};
|
|
266
331
|
}
|
|
267
332
|
/**
|
|
268
|
-
*
|
|
333
|
+
* Create a tag definition.
|
|
269
334
|
* - `.with(config)` to create configured instances
|
|
270
|
-
* - `.extract(tags)` to extract this tag from a list of tags
|
|
335
|
+
* - `.extract(tags)` to extract this tag from a list of tags or a taggable's meta
|
|
336
|
+
*
|
|
337
|
+
* @typeParam TConfig - Configuration type carried by configured tags.
|
|
338
|
+
* @typeParam TEnforceContract - Optional helper type to enforce a contract when tags are used.
|
|
339
|
+
* @param definition - The tag definition (id).
|
|
340
|
+
* @returns A tag object with helpers to configure and extract.
|
|
271
341
|
*/
|
|
272
342
|
function defineTag(definition) {
|
|
273
343
|
const id = definition.id;
|
package/dist/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;AA4DA,gCAmDC;AAED,wCAyGC;AAQD,kCAiCC;AAED,kCAoBC;AA0BD,4CAkEC;AAOD,wBAEC;AAOD,gCAEC;AAOD,oDAIC;AAOD,0BAEC;AAOD,oCAEC;AAsBD,wCAWC;AAYD,8BA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,EAAE;KACd,CAAC;AACX,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,SAAS,CACvB,UAAqD;IAErD,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"}
|
|
@@ -5,8 +5,8 @@ import { Context } from "../context";
|
|
|
5
5
|
export declare const globalMiddlewares: {
|
|
6
6
|
requireContext: import("../defs").IMiddleware<{
|
|
7
7
|
context: Context<any>;
|
|
8
|
-
},
|
|
9
|
-
retry: import("../defs").IMiddleware<import("./middleware/retry.middleware").RetryMiddlewareConfig,
|
|
8
|
+
}, any>;
|
|
9
|
+
retry: import("../defs").IMiddleware<import("./middleware/retry.middleware").RetryMiddlewareConfig, any>;
|
|
10
10
|
cache: import("../defs").IMiddleware<any, {
|
|
11
11
|
cache: import("../defs").IResource<{
|
|
12
12
|
defaultOptions?: any;
|
|
@@ -20,5 +20,5 @@ export declare const globalMiddlewares: {
|
|
|
20
20
|
cacheFactoryTask: import("../defs").ITask<any, Promise<import("./middleware/cache.middleware").ICacheInstance>, any, undefined, any>;
|
|
21
21
|
}, any, any>;
|
|
22
22
|
}>;
|
|
23
|
-
timeout: import("../defs").IMiddleware<import("./middleware/timeout.middleware").TimeoutMiddlewareConfig,
|
|
23
|
+
timeout: import("../defs").IMiddleware<import("./middleware/timeout.middleware").TimeoutMiddlewareConfig, any>;
|
|
24
24
|
};
|
|
@@ -2,5 +2,5 @@ import { Context } from "../../context";
|
|
|
2
2
|
type RequireContextMiddlewareConfig = {
|
|
3
3
|
context: Context<any>;
|
|
4
4
|
};
|
|
5
|
-
export declare const requireContextMiddleware: import("../../defs").IMiddleware<RequireContextMiddlewareConfig,
|
|
5
|
+
export declare const requireContextMiddleware: import("../../defs").IMiddleware<RequireContextMiddlewareConfig, any>;
|
|
6
6
|
export {};
|
|
@@ -17,4 +17,4 @@ export interface RetryMiddlewareConfig {
|
|
|
17
17
|
*/
|
|
18
18
|
delayStrategy?: (attempt: number, error: Error) => number;
|
|
19
19
|
}
|
|
20
|
-
export declare const retryMiddleware: import("../../defs").IMiddleware<RetryMiddlewareConfig,
|
|
20
|
+
export declare const retryMiddleware: import("../../defs").IMiddleware<RetryMiddlewareConfig, any>;
|
|
@@ -5,4 +5,4 @@ export interface TimeoutMiddlewareConfig {
|
|
|
5
5
|
*/
|
|
6
6
|
ttl: number;
|
|
7
7
|
}
|
|
8
|
-
export declare const timeoutMiddleware: import("../../defs").IMiddleware<TimeoutMiddlewareConfig,
|
|
8
|
+
export declare const timeoutMiddleware: import("../../defs").IMiddleware<TimeoutMiddlewareConfig, any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ declare const globals: {
|
|
|
85
85
|
middlewares: {
|
|
86
86
|
requireContext: import("./defs").IMiddleware<{
|
|
87
87
|
context: import("./context").Context<any>;
|
|
88
|
-
},
|
|
89
|
-
retry: import("./defs").IMiddleware<import("./globals/middleware/retry.middleware").RetryMiddlewareConfig,
|
|
88
|
+
}, any>;
|
|
89
|
+
retry: import("./defs").IMiddleware<import("./globals/middleware/retry.middleware").RetryMiddlewareConfig, any>;
|
|
90
90
|
cache: import("./defs").IMiddleware<any, {
|
|
91
91
|
cache: import("./defs").IResource<{
|
|
92
92
|
defaultOptions?: any;
|
|
@@ -100,7 +100,7 @@ declare const globals: {
|
|
|
100
100
|
cacheFactoryTask: import("./defs").ITask<any, Promise<import("./defs").ICacheInstance>, any, undefined, any>;
|
|
101
101
|
}, any, any>;
|
|
102
102
|
}>;
|
|
103
|
-
timeout: import("./defs").IMiddleware<import("./globals/middleware/timeout.middleware").TimeoutMiddlewareConfig,
|
|
103
|
+
timeout: import("./defs").IMiddleware<import("./globals/middleware/timeout.middleware").TimeoutMiddlewareConfig, any>;
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
export { globals };
|
|
@@ -11,4 +11,4 @@ export declare function getBuiltInResources(eventManager: EventManager, store: S
|
|
|
11
11
|
}> | import("../defs").IResourceWithConfig<EventManager, Promise<EventManager>, {}> | import("../defs").IResourceWithConfig<Store, Promise<Store>, {}>)[];
|
|
12
12
|
export declare function getBuiltInMiddlewares(): (import("../defs").IMiddleware<{
|
|
13
13
|
context: import("../context").Context<any>;
|
|
14
|
-
},
|
|
14
|
+
}, any> | import("../defs").IMiddleware<import("../globals/middleware/retry.middleware").RetryMiddlewareConfig, any> | import("../defs").IMiddleware<import("../globals/middleware/timeout.middleware").TimeoutMiddlewareConfig, any>)[];
|
|
@@ -36,16 +36,26 @@ function getCallerFile() {
|
|
|
36
36
|
* @returns
|
|
37
37
|
*/
|
|
38
38
|
function generateCallerIdFromFile(filePath, suffix = "", fallbackParts = 4) {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
const
|
|
39
|
+
// Normalize paths for consistency across platforms
|
|
40
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
41
|
+
const cwdNormalized = process.cwd().replace(/\\/g, "/");
|
|
42
|
+
const parts = normalizedPath.split("/");
|
|
42
43
|
const nodeModulesIndex = parts.lastIndexOf("node_modules");
|
|
43
|
-
const breakIndex = Math.max(srcIndex, nodeModulesIndex);
|
|
44
44
|
let relevantParts;
|
|
45
|
-
if (
|
|
46
|
-
|
|
45
|
+
if (nodeModulesIndex !== -1) {
|
|
46
|
+
// If inside node_modules, generate id relative to the package path
|
|
47
|
+
relevantParts = parts.slice(nodeModulesIndex + 1);
|
|
48
|
+
}
|
|
49
|
+
else if (normalizedPath === cwdNormalized ||
|
|
50
|
+
normalizedPath.startsWith(cwdNormalized + "/")) {
|
|
51
|
+
// Prefer generating id relative to the workspace root (process.cwd())
|
|
52
|
+
const relativeToCwd = normalizedPath
|
|
53
|
+
.slice(cwdNormalized.length)
|
|
54
|
+
.replace(/^\//, "");
|
|
55
|
+
relevantParts = relativeToCwd.length > 0 ? relativeToCwd.split("/") : [""];
|
|
47
56
|
}
|
|
48
57
|
else {
|
|
58
|
+
// Fallback: use the last N parts if path is outside cwd and not in node_modules
|
|
49
59
|
relevantParts = parts.slice(-fallbackParts);
|
|
50
60
|
}
|
|
51
61
|
if (relevantParts.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCallerFile.js","sourceRoot":"","sources":["../../src/tools/getCallerFile.ts"],"names":[],"mappings":";;AAAA,sCAgCC;AASD,
|
|
1
|
+
{"version":3,"file":"getCallerFile.js","sourceRoot":"","sources":["../../src/tools/getCallerFile.ts"],"names":[],"mappings":";;AAAA,sCAgCC;AASD,4DAsDC;AA/FD,SAAgB,aAAa;IAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IAE7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,UAAU,CAAC;QACf,IAAI,WAAW,CAAC;QAEhB,8BAA8B;QAC9B,KAAK,CAAC,iBAAiB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;QAEhD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAqC,CAAC;QAExD,+BAA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M,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,GAAG,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -536,7 +536,7 @@ describe("Global Events", () => {
|
|
|
536
536
|
|
|
537
537
|
// Verify the simple event handler was executed
|
|
538
538
|
expect(eventHandlerExecutions).toContain(
|
|
539
|
-
"simple-handler:Symbol(__tests__.globalEvents.test.event)"
|
|
539
|
+
"simple-handler:Symbol(src.__tests__.globalEvents.test.event)"
|
|
540
540
|
);
|
|
541
541
|
});
|
|
542
542
|
});
|
|
@@ -314,6 +314,33 @@ describe("Anonymous Components", () => {
|
|
|
314
314
|
|
|
315
315
|
await run(app);
|
|
316
316
|
});
|
|
317
|
+
|
|
318
|
+
it("should allow two anonymous resources to co-exist and be distinct", async () => {
|
|
319
|
+
const resourceA = defineResource({
|
|
320
|
+
init: async () => "A",
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const resourceB = defineResource({
|
|
324
|
+
init: async () => "B",
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// Both ids should be symbols and different
|
|
328
|
+
expect(typeof resourceA.id).toBe("symbol");
|
|
329
|
+
expect(typeof resourceB.id).toBe("symbol");
|
|
330
|
+
expect(resourceA.id).not.toBe(resourceB.id);
|
|
331
|
+
|
|
332
|
+
const app = defineResource({
|
|
333
|
+
id: "app",
|
|
334
|
+
register: [resourceA, resourceB],
|
|
335
|
+
dependencies: { resourceA, resourceB },
|
|
336
|
+
async init(_, { resourceA, resourceB }) {
|
|
337
|
+
expect(resourceA).toBe("A");
|
|
338
|
+
expect(resourceB).toBe("B");
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
await run(app);
|
|
343
|
+
});
|
|
317
344
|
});
|
|
318
345
|
|
|
319
346
|
describe("Anonymous Events", () => {
|
|
@@ -400,6 +400,77 @@ describe("Configurable Middleware (.with)", () => {
|
|
|
400
400
|
|
|
401
401
|
await run(app);
|
|
402
402
|
});
|
|
403
|
+
|
|
404
|
+
it("should allow configured middleware to be global for tasks", async () => {
|
|
405
|
+
const calls: string[] = [];
|
|
406
|
+
const validate = defineMiddleware<{ schema: string }>({
|
|
407
|
+
id: "validate.global.tasks",
|
|
408
|
+
run: async ({ next }, _deps, config) => {
|
|
409
|
+
calls.push(`global:${config.schema}`);
|
|
410
|
+
return next();
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
const task = defineTask({
|
|
415
|
+
id: "task.global",
|
|
416
|
+
run: async () => "ok",
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
const app = defineResource({
|
|
420
|
+
id: "app.global.tasks",
|
|
421
|
+
register: [
|
|
422
|
+
validate
|
|
423
|
+
.with({ schema: "user" })
|
|
424
|
+
.everywhere({ tasks: true, resources: false }),
|
|
425
|
+
task,
|
|
426
|
+
],
|
|
427
|
+
dependencies: { task },
|
|
428
|
+
async init(_, { task }) {
|
|
429
|
+
const result = await task();
|
|
430
|
+
expect(result).toBe("ok");
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
await run(app);
|
|
435
|
+
expect(calls).toContain("global:user");
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("should allow configured middleware to be global for resources", async () => {
|
|
439
|
+
const calls: string[] = [];
|
|
440
|
+
const m = defineMiddleware<{ flag: string }>({
|
|
441
|
+
id: "validate.global.resources",
|
|
442
|
+
run: async ({ next, resource }, _deps, config) => {
|
|
443
|
+
if (resource) {
|
|
444
|
+
calls.push(`${String(resource.definition.id)}:${config.flag}`);
|
|
445
|
+
}
|
|
446
|
+
return next();
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const sub = defineResource({
|
|
451
|
+
id: "res.sub",
|
|
452
|
+
async init() {
|
|
453
|
+
return "Sub";
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
const app = defineResource({
|
|
458
|
+
id: "res.app",
|
|
459
|
+
register: [
|
|
460
|
+
m.with({ flag: "X" }).everywhere({ tasks: false, resources: true }),
|
|
461
|
+
sub,
|
|
462
|
+
],
|
|
463
|
+
dependencies: { sub },
|
|
464
|
+
async init(_, { sub }) {
|
|
465
|
+
return sub;
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const result = await run(app);
|
|
470
|
+
expect(String(result.value)).toBe("Sub");
|
|
471
|
+
expect(calls).toContain("res.app:X");
|
|
472
|
+
expect(calls).toContain("res.sub:X");
|
|
473
|
+
});
|
|
403
474
|
});
|
|
404
475
|
|
|
405
476
|
describe("Middleware.everywhere()", () => {
|