@bluelibs/runner 3.3.2 → 3.4.0

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 (75) hide show
  1. package/README.md +437 -33
  2. package/dist/define.d.ts +5 -5
  3. package/dist/define.js +22 -2
  4. package/dist/define.js.map +1 -1
  5. package/dist/defs.d.ts +55 -21
  6. package/dist/defs.js.map +1 -1
  7. package/dist/defs.returnTag.d.ts +36 -0
  8. package/dist/defs.returnTag.js +4 -0
  9. package/dist/defs.returnTag.js.map +1 -0
  10. package/dist/errors.d.ts +60 -10
  11. package/dist/errors.js +103 -12
  12. package/dist/errors.js.map +1 -1
  13. package/dist/globals/globalMiddleware.d.ts +4 -4
  14. package/dist/globals/globalResources.d.ts +28 -10
  15. package/dist/globals/middleware/cache.middleware.d.ts +9 -9
  16. package/dist/globals/resources/queue.resource.d.ts +5 -2
  17. package/dist/index.d.ts +33 -14
  18. package/dist/index.js +2 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/models/DependencyProcessor.js +4 -4
  21. package/dist/models/DependencyProcessor.js.map +1 -1
  22. package/dist/models/EventManager.js +10 -1
  23. package/dist/models/EventManager.js.map +1 -1
  24. package/dist/models/Logger.d.ts +8 -0
  25. package/dist/models/Logger.js +24 -0
  26. package/dist/models/Logger.js.map +1 -1
  27. package/dist/models/OverrideManager.js +1 -1
  28. package/dist/models/OverrideManager.js.map +1 -1
  29. package/dist/models/ResourceInitializer.d.ts +2 -2
  30. package/dist/models/ResourceInitializer.js.map +1 -1
  31. package/dist/models/Store.d.ts +2 -2
  32. package/dist/models/Store.js +1 -1
  33. package/dist/models/Store.js.map +1 -1
  34. package/dist/models/StoreConstants.d.ts +6 -3
  35. package/dist/models/StoreRegistry.d.ts +2 -2
  36. package/dist/models/StoreRegistry.js +1 -1
  37. package/dist/models/StoreRegistry.js.map +1 -1
  38. package/dist/models/StoreTypes.d.ts +1 -1
  39. package/dist/models/StoreValidator.js +5 -5
  40. package/dist/models/StoreValidator.js.map +1 -1
  41. package/dist/models/TaskRunner.js +10 -0
  42. package/dist/models/TaskRunner.js.map +1 -1
  43. package/dist/run.d.ts +3 -3
  44. package/dist/run.js +1 -1
  45. package/dist/run.js.map +1 -1
  46. package/dist/t1.d.ts +1 -0
  47. package/dist/t1.js +13 -0
  48. package/dist/t1.js.map +1 -0
  49. package/dist/testing.d.ts +1 -1
  50. package/package.json +2 -2
  51. package/src/__tests__/errors.test.ts +92 -11
  52. package/src/__tests__/models/EventManager.test.ts +0 -1
  53. package/src/__tests__/models/Logger.test.ts +82 -5
  54. package/src/__tests__/recursion/c.resource.ts +1 -1
  55. package/src/__tests__/run.overrides.test.ts +3 -3
  56. package/src/__tests__/typesafety.test.ts +112 -9
  57. package/src/__tests__/validation-edge-cases.test.ts +111 -0
  58. package/src/__tests__/validation-interface.test.ts +428 -0
  59. package/src/define.ts +47 -15
  60. package/src/defs.returnTag.ts +91 -0
  61. package/src/defs.ts +84 -27
  62. package/src/errors.ts +95 -23
  63. package/src/index.ts +1 -0
  64. package/src/models/DependencyProcessor.ts +9 -5
  65. package/src/models/EventManager.ts +12 -3
  66. package/src/models/Logger.ts +28 -0
  67. package/src/models/OverrideManager.ts +2 -7
  68. package/src/models/ResourceInitializer.ts +8 -3
  69. package/src/models/Store.ts +3 -3
  70. package/src/models/StoreRegistry.ts +2 -2
  71. package/src/models/StoreTypes.ts +1 -1
  72. package/src/models/StoreValidator.ts +6 -6
  73. package/src/models/TaskRunner.ts +10 -1
  74. package/src/run.ts +8 -5
  75. package/src/testing.ts +1 -1
package/dist/defs.d.ts CHANGED
@@ -14,6 +14,19 @@
14
14
  * - Safe overrides and strong typing around config and register mechanics
15
15
  */
16
16
  import { MiddlewareEverywhereOptions } from "./define";
17
+ import { EnsureResponseSatisfiesContracts, HasContracts } from "./defs.returnTag";
18
+ /**
19
+ * Generic validation schema interface that can be implemented by any validation library.
20
+ * Compatible with Zod, Yup, Joi, and other validation libraries.
21
+ */
22
+ export interface IValidationSchema<T = any> {
23
+ /**
24
+ * Parse and validate the input data.
25
+ * Should throw an error if validation fails.
26
+ * Can transform the data if the schema supports transformations.
27
+ */
28
+ parse(input: unknown): T;
29
+ }
17
30
  export { ICacheInstance } from "./globals/middleware/cache.middleware";
18
31
  export * from "./models/StoreTypes";
19
32
  /**
@@ -39,16 +52,16 @@ export declare const symbolDispose: unique symbol;
39
52
  export declare const symbolStore: unique symbol;
40
53
  /** @internal Brand used by index() resources */
41
54
  export declare const symbolIndexResource: unique symbol;
42
- export interface ITagDefinition<TConfig = void> {
55
+ export interface ITagDefinition<TConfig = void, TEnforceContract = void> {
43
56
  id: string | symbol;
44
57
  }
45
58
  /**
46
59
  * A configured instance of a tag as produced by `ITag.with()`.
47
60
  */
48
- export interface ITagWithConfig<TConfig = void> {
61
+ export interface ITagWithConfig<TConfig = void, TEnforceContract = void> {
49
62
  id: string | symbol;
50
63
  /** The tag definition used to produce this configured instance. */
51
- tag: ITag<TConfig>;
64
+ tag: ITag<TConfig, TEnforceContract>;
52
65
  /** The configuration captured for this tag instance. */
53
66
  config: TConfig;
54
67
  }
@@ -56,16 +69,16 @@ export interface ITagWithConfig<TConfig = void> {
56
69
  * A tag definition (builder). Use `.with(config)` to obtain configured instances,
57
70
  * and `.extract(tags)` to find either a configured instance or the bare tag in a list.
58
71
  */
59
- export interface ITag<TConfig = void> extends ITagDefinition<TConfig> {
72
+ export interface ITag<TConfig = void, TEnforceContract = void> extends ITagDefinition<TConfig, TEnforceContract> {
60
73
  /**
61
74
  * Creates a configured instance of the tag.
62
75
  */
63
- with(config: TConfig): ITagWithConfig<TConfig>;
76
+ with(config: TConfig): ITagWithConfig<TConfig, TEnforceContract>;
64
77
  /**
65
78
  * Extracts either a configured instance or the bare tag from a list of tags
66
79
  * or from a taggable object (`{ meta: { tags?: [] } }`).
67
80
  */
68
- extract(target: TagType[] | ITaggable): ExtractedTagResult<TConfig> | null;
81
+ extract(target: TagType[] | ITaggable): ExtractedTagResult<TConfig, TEnforceContract> | null;
69
82
  [symbolFilePath]: string;
70
83
  }
71
84
  /**
@@ -73,16 +86,16 @@ export interface ITag<TConfig = void> extends ITagDefinition<TConfig> {
73
86
  * mirroring the same principle used for resources in `RegisterableItems`.
74
87
  * Required-config tags must appear as configured instances.
75
88
  */
76
- export type TagType = string | ITag<void> | ITag<{
89
+ export type TagType = string | ITag<void, any> | ITag<{
77
90
  [K in any]?: any;
78
- }> | ITagWithConfig<any>;
91
+ }, any> | ITagWithConfig<any, any>;
79
92
  /**
80
93
  * Conditional result type for `ITag.extract`:
81
94
  * - For void config → just the identifier
82
95
  * - For optional object config → identifier with optional config
83
96
  * - For required config → identifier with required config
84
97
  */
85
- export type ExtractedTagResult<TConfig> = {} extends TConfig ? {
98
+ export type ExtractedTagResult<TConfig, TEnforceContract> = {} extends TConfig ? {
86
99
  id: string | symbol;
87
100
  config?: TConfig;
88
101
  } : {
@@ -123,7 +136,7 @@ export interface IMiddlewareMeta extends IMeta {
123
136
  export type DependencyMapType = Record<string, ITask<any, any, any, any> | IResource<any, any, any> | IEventDefinition<any>>;
124
137
  type ExtractTaskInput<T> = T extends ITask<infer I, any, infer D> ? I : never;
125
138
  type ExtractTaskOutput<T> = T extends ITask<any, infer O, infer D> ? O : never;
126
- type ExtractResourceValue<T> = T extends IResource<any, infer V, infer D> ? V : never;
139
+ type ExtractResourceValue<T> = T extends IResource<any, infer V, infer D> ? V extends Promise<infer U> ? U : V : never;
127
140
  type ExtractEventParams<T> = T extends IEvent<infer P> ? P : never;
128
141
  /**
129
142
  * Task dependencies transform into callable functions: call with the task input
@@ -162,7 +175,8 @@ export type RegisterableItems<T = any> = IResourceWithConfig<any> | IResource<vo
162
175
  export type MiddlewareAttachments = IMiddleware<void> | IMiddleware<{
163
176
  [K in any]?: any;
164
177
  }> | IMiddlewareConfigured<any>;
165
- export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined> {
178
+ export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined, // Adding a generic to track 'on' type,
179
+ TMeta extends ITaskMeta = any> {
166
180
  /**
167
181
  * Stable identifier. If omitted, an anonymous id is generated from file path
168
182
  * (see README: Anonymous IDs).
@@ -185,12 +199,17 @@ export interface ITaskDefinition<TInput = any, TOutput extends Promise<any> = an
185
199
  */
186
200
  listenerOrder?: number;
187
201
  /** Optional metadata used for docs, filtering and tooling. */
188
- meta?: ITaskMeta;
202
+ meta?: TMeta;
203
+ /**
204
+ * Optional validation schema for runtime input validation.
205
+ * When provided, task input will be validated before execution.
206
+ */
207
+ inputSchema?: IValidationSchema<TInput>;
189
208
  /**
190
209
  * The task body. If `on` is set, the input is an `IEventEmission`. Otherwise,
191
210
  * it's the declared input type.
192
211
  */
193
- run: (input: TOn extends undefined ? TInput : IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => TOutput;
212
+ run: (input: TOn extends undefined ? TInput : IEventEmission<TOn extends "*" ? any : ExtractEventParams<TOn>>, dependencies: DependencyValuesType<TDependencies>) => HasContracts<TMeta> extends true ? EnsureResponseSatisfiesContracts<TMeta, TOutput> : TOutput;
194
213
  }
195
214
  export type BeforeRunEventPayload<TInput> = {
196
215
  input: TInput;
@@ -217,7 +236,7 @@ export type AfterInitEventPayload<TConfig, TValue> = {
217
236
  /**
218
237
  * This is the response after the definition has been prepared. TODO: better naming?
219
238
  */
220
- 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> {
239
+ export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDependencies extends DependencyMapType = {}, TOn extends "*" | IEventDefinition<any> | undefined = undefined, TMeta extends ITaskMeta = any> extends ITaskDefinition<TInput, TOutput, TDependencies, TOn, TMeta> {
221
240
  id: string | symbol;
222
241
  dependencies: TDependencies | (() => TDependencies);
223
242
  computedDependencies?: DependencyValuesType<TDependencies>;
@@ -233,7 +252,7 @@ export interface ITask<TInput = any, TOutput extends Promise<any> = any, TDepend
233
252
  [symbolFilePath]: string;
234
253
  [symbolTask]: true;
235
254
  }
236
- export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any> {
255
+ export interface IResourceDefinition<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = {}, TContext = any, THooks = any, TRegisterableItems = any, TMeta extends IResourceMeta = any> {
237
256
  /** Stable identifier. Omit to get an anonymous id. */
238
257
  id?: string | symbol;
239
258
  /** Static or lazy dependency map. Receives `config` when provided. */
@@ -246,7 +265,7 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
246
265
  /**
247
266
  * Initialize and return the resource value. Called once during boot.
248
267
  */
249
- init?: (this: any, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<TValue>;
268
+ init?: (this: any, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => HasContracts<TMeta> extends true ? EnsureResponseSatisfiesContracts<TMeta, TValue> : TValue;
250
269
  /**
251
270
  * Clean-up function for the resource. This is called when the resource is no longer needed.
252
271
  *
@@ -255,8 +274,13 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
255
274
  * @param dependencies The dependencies it needed
256
275
  * @returns Promise<void>
257
276
  */
258
- dispose?: (this: any, value: TValue, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
259
- meta?: IResourceMeta;
277
+ dispose?: (this: any, value: TValue extends Promise<infer U> ? U : TValue, config: TConfig, dependencies: DependencyValuesType<TDependencies>, context: TContext) => Promise<void>;
278
+ meta?: TMeta;
279
+ /**
280
+ * Optional validation schema for runtime config validation.
281
+ * When provided, resource config will be validated when .with() is called.
282
+ */
283
+ configSchema?: IValidationSchema<TConfig>;
260
284
  /**
261
285
  * Safe overrides to swap behavior while preserving identities. See
262
286
  * README: Overrides.
@@ -278,7 +302,7 @@ export interface IResourceDefinition<TConfig = any, TValue = unknown, TDependenc
278
302
  */
279
303
  [symbolIndexResource]?: boolean;
280
304
  }
281
- export interface IResource<TConfig = void, TValue = any, TDependencies extends DependencyMapType = any, TContext = any> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext> {
305
+ export interface IResource<TConfig = void, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any, TContext = any, TMeta extends IResourceMeta = any> extends IResourceDefinition<TConfig, TValue, TDependencies, TContext, any, any, TMeta> {
282
306
  id: string | symbol;
283
307
  with(config: TConfig): IResourceWithConfig<TConfig, TValue, TDependencies>;
284
308
  register: Array<RegisterableItems> | ((config: TConfig) => Array<RegisterableItems>);
@@ -296,7 +320,7 @@ export interface IResource<TConfig = void, TValue = any, TDependencies extends D
296
320
  [symbolIndexResource]: boolean;
297
321
  [symbolResource]: true;
298
322
  }
299
- export interface IResourceWithConfig<TConfig = any, TValue = any, TDependencies extends DependencyMapType = any> {
323
+ export interface IResourceWithConfig<TConfig = any, TValue extends Promise<any> = Promise<any>, TDependencies extends DependencyMapType = any> {
300
324
  /** The id of the underlying resource. */
301
325
  id: string;
302
326
  /** The underlying resource definition. */
@@ -309,6 +333,11 @@ export interface IEventDefinition<TPayload = void> {
309
333
  /** Stable identifier. Omit to get an anonymous id. */
310
334
  id?: string | symbol;
311
335
  meta?: IEventMeta;
336
+ /**
337
+ * Optional validation schema for runtime payload validation.
338
+ * When provided, event payload will be validated when emitted.
339
+ */
340
+ payloadSchema?: IValidationSchema<TPayload>;
312
341
  }
313
342
  export interface IEvent<TPayload = any> extends IEventDefinition<TPayload> {
314
343
  id: string | symbol;
@@ -357,6 +386,11 @@ export interface IMiddlewareDefinition<TConfig = any, TDependencies extends Depe
357
386
  id?: string | symbol;
358
387
  /** Static or lazy dependency map. */
359
388
  dependencies?: TDependencies | ((config: TConfig) => TDependencies);
389
+ /**
390
+ * Optional validation schema for runtime config validation.
391
+ * When provided, middleware config will be validated when .with() is called.
392
+ */
393
+ configSchema?: IValidationSchema<TConfig>;
360
394
  /**
361
395
  * The middleware body, called with task/resource execution input.
362
396
  */
@@ -396,7 +430,7 @@ export interface IMiddlewareExecutionInput<TTaskInput = any, TResourceConfig = a
396
430
  };
397
431
  /** Resource hook: present when wrapping init/dispose. */
398
432
  resource?: {
399
- definition: IResource<TResourceConfig>;
433
+ definition: IResource<TResourceConfig, any, any, any, any>;
400
434
  config: TResourceConfig;
401
435
  };
402
436
  next: (taskInputOrResourceConfig?: TTaskInput | TResourceConfig) => Promise<any>;
package/dist/defs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;AAMH,sDAAoC;AACpC;;;;;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,CA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agWithConfig } from "./defs";
2
+ import { IMeta } from "./defs";
3
+ type NonVoid<T> = [T] extends [void] ? never : T;
4
+ type ExtractReturnFromTag<T> = T extends ITagWithConfig<any, infer R> ? NonVoid<R> : T extends ITag<any, infer R> ? NonVoid<R> : never;
5
+ type IsTuple<T extends readonly unknown[]> = number extends T["length"] ? false : true;
6
+ type FilterContracts<TTags extends readonly unknown[], Acc extends readonly unknown[] = []> = TTags extends readonly [infer H, ...infer R] ? ExtractReturnFromTag<H> extends never ? FilterContracts<R, Acc> : FilterContracts<R, [...Acc, ExtractReturnFromTag<H>]> : Acc;
7
+ export type ExtractContractsFromTags<TTags extends readonly unknown[]> = IsTuple<TTags> extends true ? FilterContracts<TTags> : Array<ExtractReturnFromTag<TTags[number]>>;
8
+ export type ExtractTagsWithNonVoidReturnTypeFromMeta<TMeta extends IMeta> = TMeta extends {
9
+ tags?: infer TTags;
10
+ } ? TTags extends readonly unknown[] ? ExtractContractsFromTags<TTags> : [] : [];
11
+ export type HasContracts<T extends IMeta> = ExtractTagsWithNonVoidReturnTypeFromMeta<T> extends never[] ? false : true;
12
+ type UnionToIntersection<U> = (U extends any ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
13
+ type ContractsUnion<TMeta extends IMeta> = ExtractTagsWithNonVoidReturnTypeFromMeta<TMeta> extends readonly (infer U)[] ? U : never;
14
+ type ContractsIntersection<TMeta extends IMeta> = UnionToIntersection<ContractsUnion<TMeta>>;
15
+ /**
16
+ * Pretty-print helper to expand intersections for better IDE display.
17
+ */
18
+ type Simplify<T> = {
19
+ [K in keyof T]: T[K];
20
+ } & {};
21
+ /**
22
+ * Verbose compile-time error surfaced when a value does not satisfy
23
+ * the intersection of all tag-enforced contracts.
24
+ *
25
+ * Intersected with `never` in call sites when desired to ensure assignment
26
+ * fails while still surfacing a readable shape in tooltips.
27
+ */
28
+ export type ContractViolationError<TMeta extends IMeta, TActual> = {
29
+ message: "Value does not satisfy all tag contracts";
30
+ expected: Simplify<ContractsIntersection<TMeta>>;
31
+ received: TActual;
32
+ };
33
+ export type EnsureResponseSatisfiesContracts<TMeta extends IMeta, TResponse> = [
34
+ ContractsUnion<TMeta>
35
+ ] extends [never] ? TResponse : TResponse extends Promise<infer U> ? Promise<U extends ContractsIntersection<TMeta> ? U : ContractViolationError<TMeta, U>> : TResponse extends ContractsIntersection<TMeta> ? TResponse : ContractViolationError<TMeta, TResponse>;
36
+ export {};
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // HasContracts<Meta> → true if contracts present, else false
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=defs.returnTag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defs.returnTag.js","sourceRoot":"","sources":["../src/defs.returnTag.ts"],"names":[],"mappings":";AAAA,6DAA6D"}
package/dist/errors.d.ts CHANGED
@@ -1,10 +1,60 @@
1
- export declare const Errors: {
2
- duplicateRegistration: (type: string, id: string | symbol) => Error;
3
- dependencyNotFound: (key: string | symbol) => Error;
4
- unknownItemType: (item: any) => Error;
5
- circularDependencies: (cycles: string[]) => Error;
6
- eventNotFound: (id: string | symbol) => Error;
7
- middlewareAlreadyGlobal: (id: string | symbol) => Error;
8
- locked: (what: string | symbol) => Error;
9
- storeAlreadyInitialized: () => Error;
10
- };
1
+ /**
2
+ * Base error class for all BlueLibs Runner errors
3
+ */
4
+ export declare class RuntimeError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ /**
8
+ * Error thrown when attempting to register a component with a duplicate ID
9
+ */
10
+ export declare class DuplicateRegistrationError extends RuntimeError {
11
+ constructor(type: string, id: string | symbol);
12
+ }
13
+ /**
14
+ * Error thrown when a dependency is not found in the registry
15
+ */
16
+ export declare class DependencyNotFoundError extends RuntimeError {
17
+ constructor(key: string | symbol);
18
+ }
19
+ /**
20
+ * Error thrown when an unknown item type is encountered
21
+ */
22
+ export declare class UnknownItemTypeError extends RuntimeError {
23
+ constructor(item: any);
24
+ }
25
+ /**
26
+ * Error thrown when circular dependencies are detected
27
+ */
28
+ export declare class CircularDependenciesError extends RuntimeError {
29
+ constructor(cycles: string[]);
30
+ }
31
+ /**
32
+ * Error thrown when an event is not found in the registry
33
+ */
34
+ export declare class EventNotFoundError extends RuntimeError {
35
+ constructor(id: string | symbol);
36
+ }
37
+ /**
38
+ * Error thrown when attempting to make a middleware global when it's already global
39
+ */
40
+ export declare class MiddlewareAlreadyGlobalError extends RuntimeError {
41
+ constructor(id: string | symbol);
42
+ }
43
+ /**
44
+ * Error thrown when attempting to modify a locked component
45
+ */
46
+ export declare class LockedError extends RuntimeError {
47
+ constructor(what: string | symbol);
48
+ }
49
+ /**
50
+ * Error thrown when attempting to initialize a store that's already initialized
51
+ */
52
+ export declare class StoreAlreadyInitializedError extends RuntimeError {
53
+ constructor();
54
+ }
55
+ /**
56
+ * Error thrown when validation fails for task input, resource config, middleware config, or event payload
57
+ */
58
+ export declare class ValidationError extends RuntimeError {
59
+ constructor(type: string, id: string | symbol, originalError: Error | string);
60
+ }
package/dist/errors.js CHANGED
@@ -1,15 +1,106 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Errors = void 0;
4
- exports.Errors = {
5
- duplicateRegistration: (type, id) => new Error(`${type} "${id.toString()}" already registered`),
6
- dependencyNotFound: (key) => new Error(`Dependency ${key.toString()} not found. Did you forget to register it through a resource?`),
7
- unknownItemType: (item) => new Error(`Unknown item type: ${item}`),
8
- circularDependencies: (cycles) => new Error(`Circular dependencies detected: ${cycles.join(", ")}`),
9
- eventNotFound: (id) => new Error(`Event "${id.toString()}" not found. Did you forget to register it?`),
10
- middlewareAlreadyGlobal: (id) => new Error("Cannot call .everywhere() on an already global middleware: " +
11
- id.toString),
12
- locked: (what) => new Error(`Cannot modify the ${what.toString()} when it is locked.`),
13
- storeAlreadyInitialized: () => new Error("Store already initialized. Cannot reinitialize."),
14
- };
3
+ exports.ValidationError = exports.StoreAlreadyInitializedError = exports.LockedError = exports.MiddlewareAlreadyGlobalError = exports.EventNotFoundError = exports.CircularDependenciesError = exports.UnknownItemTypeError = exports.DependencyNotFoundError = exports.DuplicateRegistrationError = exports.RuntimeError = void 0;
4
+ /**
5
+ * Base error class for all BlueLibs Runner errors
6
+ */
7
+ class RuntimeError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = "RuntimeError";
11
+ }
12
+ }
13
+ exports.RuntimeError = RuntimeError;
14
+ /**
15
+ * Error thrown when attempting to register a component with a duplicate ID
16
+ */
17
+ class DuplicateRegistrationError extends RuntimeError {
18
+ constructor(type, id) {
19
+ super(`${type} "${id.toString()}" already registered`);
20
+ this.name = "DuplicateRegistrationError";
21
+ }
22
+ }
23
+ exports.DuplicateRegistrationError = DuplicateRegistrationError;
24
+ /**
25
+ * Error thrown when a dependency is not found in the registry
26
+ */
27
+ class DependencyNotFoundError extends RuntimeError {
28
+ constructor(key) {
29
+ super(`Dependency ${key.toString()} not found. Did you forget to register it through a resource?`);
30
+ this.name = "DependencyNotFoundError";
31
+ }
32
+ }
33
+ exports.DependencyNotFoundError = DependencyNotFoundError;
34
+ /**
35
+ * Error thrown when an unknown item type is encountered
36
+ */
37
+ class UnknownItemTypeError extends RuntimeError {
38
+ constructor(item) {
39
+ super(`Unknown item type: ${item}`);
40
+ this.name = "UnknownItemTypeError";
41
+ }
42
+ }
43
+ exports.UnknownItemTypeError = UnknownItemTypeError;
44
+ /**
45
+ * Error thrown when circular dependencies are detected
46
+ */
47
+ class CircularDependenciesError extends RuntimeError {
48
+ constructor(cycles) {
49
+ super(`Circular dependencies detected: ${cycles.join(", ")}`);
50
+ this.name = "CircularDependenciesError";
51
+ }
52
+ }
53
+ exports.CircularDependenciesError = CircularDependenciesError;
54
+ /**
55
+ * Error thrown when an event is not found in the registry
56
+ */
57
+ class EventNotFoundError extends RuntimeError {
58
+ constructor(id) {
59
+ super(`Event "${id.toString()}" not found. Did you forget to register it?`);
60
+ this.name = "EventNotFoundError";
61
+ }
62
+ }
63
+ exports.EventNotFoundError = EventNotFoundError;
64
+ /**
65
+ * Error thrown when attempting to make a middleware global when it's already global
66
+ */
67
+ class MiddlewareAlreadyGlobalError extends RuntimeError {
68
+ constructor(id) {
69
+ super("Cannot call .everywhere() on an already global middleware: " +
70
+ id.toString());
71
+ this.name = "MiddlewareAlreadyGlobalError";
72
+ }
73
+ }
74
+ exports.MiddlewareAlreadyGlobalError = MiddlewareAlreadyGlobalError;
75
+ /**
76
+ * Error thrown when attempting to modify a locked component
77
+ */
78
+ class LockedError extends RuntimeError {
79
+ constructor(what) {
80
+ super(`Cannot modify the ${what.toString()} when it is locked.`);
81
+ this.name = "LockedError";
82
+ }
83
+ }
84
+ exports.LockedError = LockedError;
85
+ /**
86
+ * Error thrown when attempting to initialize a store that's already initialized
87
+ */
88
+ class StoreAlreadyInitializedError extends RuntimeError {
89
+ constructor() {
90
+ super("Store already initialized. Cannot reinitialize.");
91
+ this.name = "StoreAlreadyInitializedError";
92
+ }
93
+ }
94
+ exports.StoreAlreadyInitializedError = StoreAlreadyInitializedError;
95
+ /**
96
+ * Error thrown when validation fails for task input, resource config, middleware config, or event payload
97
+ */
98
+ class ValidationError extends RuntimeError {
99
+ constructor(type, id, originalError) {
100
+ const errorMessage = originalError instanceof Error ? originalError.message : String(originalError);
101
+ super(`${type} validation failed for ${id.toString()}: ${errorMessage}`);
102
+ this.name = "ValidationError";
103
+ }
104
+ }
105
+ exports.ValidationError = ValidationError;
15
106
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEa,QAAA,MAAM,GAAG;IACpB,qBAAqB,EAAE,CAAC,IAAY,EAAE,EAAmB,EAAE,EAAE,CAC3D,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC,QAAQ,EAAE,sBAAsB,CAAC;IAE5D,kBAAkB,EAAE,CAAC,GAAoB,EAAE,EAAE,CAC3C,IAAI,KAAK,CACP,cAAc,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AAC,iDAAiD,CAAC,CAAC;QACzD,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AALD,oEAKC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,IAAY,EAAE,EAAmB,EAAE,aAA6B;QAC1E,MAAM,YAAY,GAAG,aAAa,YAAY,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACpG,KAAK,CAAC,GAAG,IAAI,0BAA0B,EAAE,CAAC,QAAQ,EAAE,KAAK,YAAY,EAAE,CAAC,CAAC;QACzE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAND,0CAMC"}
@@ -11,14 +11,14 @@ export declare const globalMiddlewares: {
11
11
  cache: import("../defs").IResource<{
12
12
  defaultOptions?: any;
13
13
  async?: boolean;
14
- }, {
14
+ }, Promise<{
15
15
  map: Map<string | symbol, import("./middleware/cache.middleware").ICacheInstance>;
16
16
  cacheFactoryTask: (...args: [] | [any]) => Promise<import("./middleware/cache.middleware").ICacheInstance>;
17
17
  async: boolean | undefined;
18
18
  defaultOptions: any;
19
- }, {
20
- cacheFactoryTask: import("../defs").ITask<any, Promise<import("./middleware/cache.middleware").ICacheInstance>, any, undefined>;
21
- }, any>;
19
+ }>, {
20
+ cacheFactoryTask: import("../defs").ITask<any, Promise<import("./middleware/cache.middleware").ICacheInstance>, any, undefined, any>;
21
+ }, any, any>;
22
22
  }>;
23
23
  timeout: import("../defs").IMiddleware<import("./middleware/timeout.middleware").TimeoutMiddlewareConfig, import("../defs").DependencyMapType>;
24
24
  };
@@ -3,25 +3,43 @@ import { Logger } from "../models/Logger";
3
3
  import { Store } from "../models/Store";
4
4
  import { TaskRunner } from "../models/TaskRunner";
5
5
  export declare const globalResources: {
6
- store: import("../defs").IResource<Store, Store, {}, any>;
7
- eventManager: import("../defs").IResource<EventManager, EventManager, {}, any>;
8
- taskRunner: import("../defs").IResource<TaskRunner, TaskRunner, {}, any>;
9
- logger: import("../defs").IResource<Logger, Logger, {}, any>;
6
+ store: import("../defs").IResource<Store, Promise<Store>, {}, any, {
7
+ title: string;
8
+ description: string;
9
+ tags: string[];
10
+ }>;
11
+ eventManager: import("../defs").IResource<EventManager, Promise<EventManager>, {}, any, {
12
+ title: string;
13
+ description: string;
14
+ tags: string[];
15
+ }>;
16
+ taskRunner: import("../defs").IResource<TaskRunner, Promise<TaskRunner>, {}, any, {
17
+ title: string;
18
+ description: string;
19
+ tags: string[];
20
+ }>;
21
+ logger: import("../defs").IResource<Logger, Promise<Logger>, {}, any, {
22
+ title: string;
23
+ description: string;
24
+ }>;
10
25
  cache: import("../defs").IResource<{
11
26
  defaultOptions?: any;
12
27
  async?: boolean;
13
- }, {
28
+ }, Promise<{
14
29
  map: Map<string | symbol, import("./middleware/cache.middleware").ICacheInstance>;
15
30
  cacheFactoryTask: (...args: [] | [any]) => Promise<import("./middleware/cache.middleware").ICacheInstance>;
16
31
  async: boolean | undefined;
17
32
  defaultOptions: any;
18
- }, {
19
- cacheFactoryTask: import("../defs").ITask<any, Promise<import("./middleware/cache.middleware").ICacheInstance>, any, undefined>;
20
- }, any>;
21
- queue: import("../defs").IResource<void, {
33
+ }>, {
34
+ cacheFactoryTask: import("../defs").ITask<any, Promise<import("./middleware/cache.middleware").ICacheInstance>, any, undefined, any>;
35
+ }, any, any>;
36
+ queue: import("../defs").IResource<void, Promise<{
22
37
  map: Map<string | symbol, import("..").Queue>;
23
38
  run: <T>(id: string, task: (signal: AbortSignal) => Promise<T>) => Promise<T>;
24
- }, {}, {
39
+ }>, {}, {
25
40
  map: Map<string | symbol, import("..").Queue>;
41
+ }, {
42
+ title: string;
43
+ description: string;
26
44
  }>;
27
45
  };
@@ -4,7 +4,7 @@ export interface ICacheInstance {
4
4
  get(key: string): any;
5
5
  clear(): void;
6
6
  }
7
- export declare const cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined>;
7
+ export declare const cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined, any>;
8
8
  type CacheResourceConfig = {
9
9
  defaultOptions?: any;
10
10
  /**
@@ -13,22 +13,22 @@ type CacheResourceConfig = {
13
13
  */
14
14
  async?: boolean;
15
15
  };
16
- export declare const cacheResource: IResource<CacheResourceConfig, {
16
+ export declare const cacheResource: IResource<CacheResourceConfig, Promise<{
17
17
  map: Map<string | symbol, ICacheInstance>;
18
18
  cacheFactoryTask: (...args: [] | [any]) => Promise<ICacheInstance>;
19
19
  async: boolean | undefined;
20
20
  defaultOptions: any;
21
- }, {
22
- cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined>;
23
- }, any>;
21
+ }>, {
22
+ cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined, any>;
23
+ }, any, any>;
24
24
  export declare const cacheMiddleware: import("../../defs").IMiddleware<any, {
25
- cache: IResource<CacheResourceConfig, {
25
+ cache: IResource<CacheResourceConfig, Promise<{
26
26
  map: Map<string | symbol, ICacheInstance>;
27
27
  cacheFactoryTask: (...args: [] | [any]) => Promise<ICacheInstance>;
28
28
  async: boolean | undefined;
29
29
  defaultOptions: any;
30
- }, {
31
- cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined>;
32
- }, any>;
30
+ }>, {
31
+ cacheFactoryTask: ITask<any, Promise<ICacheInstance>, any, undefined, any>;
32
+ }, any, any>;
33
33
  }>;
34
34
  export {};
@@ -1,7 +1,10 @@
1
1
  import { Queue } from "../../models/Queue";
2
- export declare const queueResource: import("../../defs").IResource<void, {
2
+ export declare const queueResource: import("../../defs").IResource<void, Promise<{
3
3
  map: Map<string | symbol, Queue>;
4
4
  run: <T>(id: string, task: (signal: AbortSignal) => Promise<T>) => Promise<T>;
5
- }, {}, {
5
+ }>, {}, {
6
6
  map: Map<string | symbol, Queue>;
7
+ }, {
8
+ title: string;
9
+ description: string;
7
10
  }>;