@bluelibs/runner 1.1.0 → 1.3.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 (72) hide show
  1. package/README.md +309 -114
  2. package/dist/DependencyProcessor.d.ts +2 -2
  3. package/dist/DependencyProcessor.js +3 -3
  4. package/dist/DependencyProcessor.js.map +1 -1
  5. package/dist/Store.d.ts +24 -1
  6. package/dist/Store.js +108 -34
  7. package/dist/Store.js.map +1 -1
  8. package/dist/TaskRunner.d.ts +3 -0
  9. package/dist/TaskRunner.js +3 -0
  10. package/dist/TaskRunner.js.map +1 -1
  11. package/dist/define.d.ts +2 -2
  12. package/dist/define.js +13 -9
  13. package/dist/define.js.map +1 -1
  14. package/dist/defs.d.ts +21 -10
  15. package/dist/globalEvents.d.ts +5 -1
  16. package/dist/globalEvents.js +3 -0
  17. package/dist/globalEvents.js.map +1 -1
  18. package/dist/globalResources.d.ts +5 -3
  19. package/dist/globalResources.js +4 -0
  20. package/dist/globalResources.js.map +1 -1
  21. package/dist/index.d.ts +11 -7
  22. package/dist/index.js +3 -3
  23. package/dist/index.js.map +1 -1
  24. package/dist/models/DependencyProcessor.d.ts +49 -0
  25. package/dist/models/DependencyProcessor.js +185 -0
  26. package/dist/models/DependencyProcessor.js.map +1 -0
  27. package/dist/models/EventManager.d.ts +18 -0
  28. package/dist/models/EventManager.js +99 -0
  29. package/dist/models/EventManager.js.map +1 -0
  30. package/dist/models/Logger.d.ts +33 -0
  31. package/dist/models/Logger.js +76 -0
  32. package/dist/models/Logger.js.map +1 -0
  33. package/dist/models/ResourceInitializer.d.ts +14 -0
  34. package/dist/models/ResourceInitializer.js +86 -0
  35. package/dist/models/ResourceInitializer.js.map +1 -0
  36. package/dist/models/Store.d.ts +91 -0
  37. package/dist/models/Store.js +312 -0
  38. package/dist/models/Store.js.map +1 -0
  39. package/dist/models/TaskRunner.d.ts +25 -0
  40. package/dist/models/TaskRunner.js +100 -0
  41. package/dist/models/TaskRunner.js.map +1 -0
  42. package/dist/models/index.d.ts +5 -0
  43. package/dist/models/index.js +22 -0
  44. package/dist/models/index.js.map +1 -0
  45. package/dist/run.d.ts +3 -3
  46. package/dist/run.js +12 -6
  47. package/dist/run.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/__tests__/index.ts +9 -4
  50. package/src/__tests__/models/EventManager.test.ts +385 -0
  51. package/src/__tests__/models/Logger.test.ts +140 -0
  52. package/src/__tests__/{ResourceInitializer.test.ts → models/ResourceInitializer.test.ts} +5 -4
  53. package/src/__tests__/{Store.test.ts → models/Store.test.ts} +4 -4
  54. package/src/__tests__/{TaskRunner.test.ts → models/TaskRunner.test.ts} +9 -7
  55. package/src/__tests__/run.hooks.test.ts +31 -0
  56. package/src/__tests__/run.middleware.test.ts +223 -0
  57. package/src/__tests__/run.overrides.test.ts +392 -0
  58. package/src/__tests__/run.test.ts +112 -131
  59. package/src/define.ts +18 -11
  60. package/src/defs.ts +23 -10
  61. package/src/globalEvents.ts +8 -2
  62. package/src/globalResources.ts +8 -3
  63. package/src/index.ts +3 -3
  64. package/src/{DependencyProcessor.ts → models/DependencyProcessor.ts} +23 -14
  65. package/src/{EventManager.ts → models/EventManager.ts} +56 -27
  66. package/src/models/Logger.ts +100 -0
  67. package/src/{ResourceInitializer.ts → models/ResourceInitializer.ts} +51 -6
  68. package/src/{Store.ts → models/Store.ts} +159 -47
  69. package/src/{TaskRunner.ts → models/TaskRunner.ts} +11 -5
  70. package/src/models/index.ts +5 -0
  71. package/src/run.ts +13 -7
  72. package/src/__tests__/EventManager.test.ts +0 -114
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResourceInitializer.js","sourceRoot":"","sources":["../../src/models/ResourceInitializer.ts"],"names":[],"mappings":";;;AAOA,kDAA+C;AAG/C,MAAa,mBAAmB;IAET;IACA;IAFrB,YACqB,KAAY,EACZ,YAA0B;QAD1B,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;IAC5C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CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;CACF;AAvGD,kDAuGC"}
@@ -0,0 +1,91 @@
1
+ import { DependencyMapType, DependencyValuesType, IEventDefinition, IResource, ITask, IResourceWithConfig, RegisterableItems, IMiddleware } from "../defs";
2
+ import { IDependentNode } from "../tools/findCircularDependencies";
3
+ import { EventManager } from "./EventManager";
4
+ export type ResourceStoreElementType<C = any, V = any, D extends DependencyMapType = {}> = {
5
+ resource: IResource<C, V, D>;
6
+ computedDependencies?: DependencyValuesType<D>;
7
+ config: C;
8
+ value: V;
9
+ isInitialized?: boolean;
10
+ };
11
+ export type TaskStoreElementType<Input = any, Output extends Promise<any> = any, D extends DependencyMapType = any> = {
12
+ task: ITask<Input, Output, D>;
13
+ computedDependencies: DependencyValuesType<D>;
14
+ isInitialized: boolean;
15
+ };
16
+ export type MiddlewareStoreElementType<TDeps extends DependencyMapType = any> = {
17
+ middleware: IMiddleware<TDeps>;
18
+ computedDependencies: DependencyValuesType<TDeps>;
19
+ };
20
+ export type EventStoreElementType = {
21
+ event: IEventDefinition;
22
+ };
23
+ /**
24
+ * Store class which is used to store all the resources, tasks, middleware and events.
25
+ */
26
+ export declare class Store {
27
+ #private;
28
+ protected readonly eventManager: EventManager;
29
+ root: ResourceStoreElementType;
30
+ tasks: Map<string, TaskStoreElementType>;
31
+ resources: Map<string, ResourceStoreElementType>;
32
+ events: Map<string, EventStoreElementType>;
33
+ middlewares: Map<string, MiddlewareStoreElementType>;
34
+ overrides: Map<string, IResource | IMiddleware | ITask | IResourceWithConfig>;
35
+ constructor(eventManager: EventManager);
36
+ get isLocked(): boolean;
37
+ lock(): void;
38
+ checkLock(): void;
39
+ /**
40
+ * Store the root before beginning registration
41
+ * @param root
42
+ * @param config
43
+ */
44
+ initializeStore(root: IResource<any>, config: any): void;
45
+ private runSanityChecks;
46
+ /**
47
+ * Beginning with the root, we perform registering to the container all the resources, tasks, middleware and events.
48
+ * @param element
49
+ * @param config
50
+ */
51
+ private computeRegistrationDeeply;
52
+ /**
53
+ * @param element
54
+ */
55
+ private storeOverridesDeeply;
56
+ /**
57
+ * middlewares are already stored in their final form and the check for them would be redundant
58
+ * @param id
59
+ */
60
+ protected checkIfIDExists(id: string): void | never;
61
+ /**
62
+ * Cleanup
63
+ */
64
+ dispose(): Promise<void>;
65
+ /**
66
+ * When this is called, all overrides should have been stored in the "overrides" store.
67
+ */
68
+ processOverrides(): void;
69
+ getGlobalMiddlewares(excludingIds: string[]): IMiddleware[];
70
+ /**
71
+ * If you want to register something to the store you can use this function.
72
+ * @param item
73
+ */
74
+ storeGenericItem<C>(item: RegisterableItems): void;
75
+ private storeMiddleware;
76
+ storeEvent<C>(item: IEventDefinition<void>): void;
77
+ private storeResourceWithConfig;
78
+ /**
79
+ * This is for storing a resource without a config.
80
+ * @param item
81
+ */
82
+ private storeResource;
83
+ storeEventsForAllTasks(): void;
84
+ /**
85
+ * This is for storing a resource without a config.
86
+ * @param item
87
+ */
88
+ private prepareResource;
89
+ private storeTask;
90
+ getDependentNodes(): IDependentNode[];
91
+ }
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Store = void 0;
4
+ const defs_1 = require("../defs");
5
+ const utils = require("../define");
6
+ const globalEvents_1 = require("../globalEvents");
7
+ const errors_1 = require("../errors");
8
+ const globalResources_1 = require("../globalResources");
9
+ /**
10
+ * Store class which is used to store all the resources, tasks, middleware and events.
11
+ */
12
+ class Store {
13
+ eventManager;
14
+ root;
15
+ tasks = new Map();
16
+ resources = new Map();
17
+ events = new Map();
18
+ middlewares = new Map();
19
+ overrides = new Map();
20
+ #isLocked = false;
21
+ #isInitialized = false;
22
+ constructor(eventManager) {
23
+ this.eventManager = eventManager;
24
+ }
25
+ get isLocked() {
26
+ return this.#isLocked;
27
+ }
28
+ lock() {
29
+ this.#isLocked = true;
30
+ this.eventManager.lock();
31
+ }
32
+ checkLock() {
33
+ if (this.#isLocked) {
34
+ throw new Error("Cannot modify the Store when it is locked.");
35
+ }
36
+ }
37
+ /**
38
+ * Store the root before beginning registration
39
+ * @param root
40
+ * @param config
41
+ */
42
+ initializeStore(root, config) {
43
+ if (this.#isInitialized) {
44
+ throw errors_1.Errors.storeAlreadyInitialized();
45
+ }
46
+ this.storeGenericItem(globalResources_1.globalResources.eventManager.with(this.eventManager));
47
+ this.storeGenericItem(globalResources_1.globalResources.store.with(this));
48
+ root.dependencies =
49
+ typeof root.dependencies === "function"
50
+ ? root.dependencies(config)
51
+ : root.dependencies;
52
+ this.root = {
53
+ resource: root,
54
+ computedDependencies: {},
55
+ config,
56
+ value: undefined,
57
+ isInitialized: false,
58
+ };
59
+ // register global events
60
+ globalEvents_1.globalEventsArray.forEach((event) => {
61
+ this.storeEvent(event);
62
+ });
63
+ this.computeRegistrationDeeply(root, config);
64
+ this.resources.set(root.id, this.root);
65
+ this.runSanityChecks();
66
+ for (const resource of this.resources.values()) {
67
+ this.storeOverridesDeeply(resource.resource);
68
+ }
69
+ this.#isInitialized = true;
70
+ }
71
+ runSanityChecks() {
72
+ for (const task of this.tasks.values()) {
73
+ task.task.middleware.forEach((middleware) => {
74
+ if (!this.middlewares.has(middleware.id)) {
75
+ throw errors_1.Errors.dependencyNotFound(`Middleware ${middleware.id} in Task ${task.task.id}`);
76
+ }
77
+ });
78
+ }
79
+ }
80
+ /**
81
+ * Beginning with the root, we perform registering to the container all the resources, tasks, middleware and events.
82
+ * @param element
83
+ * @param config
84
+ */
85
+ computeRegistrationDeeply(element, config) {
86
+ const items = typeof element.register === "function"
87
+ ? element.register(config)
88
+ : element.register;
89
+ for (const item of items) {
90
+ // will call registration if it detects another resource.
91
+ this.storeGenericItem(item);
92
+ }
93
+ }
94
+ /**
95
+ * @param element
96
+ */
97
+ storeOverridesDeeply(element) {
98
+ element.overrides.forEach((override) => {
99
+ // the one on top has priority of setting the last override.
100
+ if (utils.isResource(override)) {
101
+ this.storeOverridesDeeply(override);
102
+ }
103
+ if (utils.isResourceWithConfig(override)) {
104
+ this.storeOverridesDeeply(override.resource);
105
+ this.overrides.set(override.resource.id, override);
106
+ }
107
+ else {
108
+ this.overrides.set(override.id, override);
109
+ }
110
+ });
111
+ }
112
+ /**
113
+ * middlewares are already stored in their final form and the check for them would be redundant
114
+ * @param id
115
+ */
116
+ checkIfIDExists(id) {
117
+ if (this.tasks.has(id)) {
118
+ throw errors_1.Errors.duplicateRegistration("Task", id);
119
+ }
120
+ if (this.resources.has(id)) {
121
+ throw errors_1.Errors.duplicateRegistration("Resource", id);
122
+ }
123
+ if (this.events.has(id)) {
124
+ throw errors_1.Errors.duplicateRegistration("Event", id);
125
+ }
126
+ if (this.middlewares.has(id)) {
127
+ throw errors_1.Errors.duplicateRegistration("Middleware", id);
128
+ }
129
+ }
130
+ /**
131
+ * Cleanup
132
+ */
133
+ async dispose() {
134
+ for (const resource of this.resources.values()) {
135
+ if (resource.resource.dispose) {
136
+ await resource.resource.dispose(resource.value, resource.config, resource.computedDependencies);
137
+ }
138
+ }
139
+ }
140
+ /**
141
+ * When this is called, all overrides should have been stored in the "overrides" store.
142
+ */
143
+ processOverrides() {
144
+ // If we are trying to use override on something that wasn't previously registered, we throw an error.
145
+ for (const override of this.overrides.values()) {
146
+ let hasAnyItem = false;
147
+ if (utils.isTask(override)) {
148
+ hasAnyItem = this.tasks.has(override.id);
149
+ }
150
+ else if (utils.isResource(override)) {
151
+ hasAnyItem = this.resources.has(override.id);
152
+ }
153
+ else if (utils.isMiddleware(override)) {
154
+ hasAnyItem = this.middlewares.has(override.id);
155
+ }
156
+ else if (utils.isResourceWithConfig(override)) {
157
+ hasAnyItem = this.resources.has(override.resource.id);
158
+ }
159
+ if (!hasAnyItem) {
160
+ const id = utils.isResourceWithConfig(override)
161
+ ? override.resource.id
162
+ : override.id;
163
+ throw errors_1.Errors.dependencyNotFound(id);
164
+ }
165
+ }
166
+ for (const override of this.overrides.values()) {
167
+ if (utils.isTask(override)) {
168
+ this.storeTask(override, false);
169
+ }
170
+ else if (utils.isResource(override)) {
171
+ this.storeResource(override, false);
172
+ }
173
+ else if (utils.isMiddleware(override)) {
174
+ this.storeMiddleware(override, false);
175
+ }
176
+ else if (utils.isResourceWithConfig(override)) {
177
+ this.storeResourceWithConfig(override, false);
178
+ }
179
+ }
180
+ }
181
+ getGlobalMiddlewares(excludingIds) {
182
+ return Array.from(this.middlewares.values())
183
+ .filter((x) => x.middleware[defs_1.symbols.middlewareGlobal])
184
+ .filter((x) => !excludingIds.includes(x.middleware.id))
185
+ .map((x) => x.middleware);
186
+ }
187
+ /**
188
+ * If you want to register something to the store you can use this function.
189
+ * @param item
190
+ */
191
+ storeGenericItem(item) {
192
+ if (utils.isTask(item)) {
193
+ this.storeTask(item);
194
+ }
195
+ else if (utils.isResource(item)) {
196
+ // Registration a simple resource, which is interpreted as a resource with no configuration.
197
+ this.storeResource(item);
198
+ }
199
+ else if (utils.isEvent(item)) {
200
+ this.storeEvent(item);
201
+ }
202
+ else if (utils.isMiddleware(item)) {
203
+ this.storeMiddleware(item);
204
+ }
205
+ else if (utils.isResourceWithConfig(item)) {
206
+ this.storeResourceWithConfig(item);
207
+ }
208
+ else {
209
+ throw errors_1.Errors.unknownItemType(item);
210
+ }
211
+ }
212
+ storeMiddleware(item, check = true) {
213
+ check && this.checkIfIDExists(item.id);
214
+ item.dependencies =
215
+ typeof item.dependencies === "function"
216
+ ? item.dependencies()
217
+ : item.dependencies;
218
+ this.middlewares.set(item.id, {
219
+ middleware: item,
220
+ computedDependencies: {},
221
+ });
222
+ }
223
+ storeEvent(item) {
224
+ this.checkIfIDExists(item.id);
225
+ this.events.set(item.id, { event: item });
226
+ }
227
+ storeResourceWithConfig(item, check = true) {
228
+ check && this.checkIfIDExists(item.resource.id);
229
+ this.prepareResource(item.resource, item.config);
230
+ this.resources.set(item.resource.id, {
231
+ resource: item.resource,
232
+ config: item.config,
233
+ value: undefined,
234
+ isInitialized: false,
235
+ });
236
+ this.computeRegistrationDeeply(item.resource, item.config);
237
+ }
238
+ /**
239
+ * This is for storing a resource without a config.
240
+ * @param item
241
+ */
242
+ storeResource(item, check = true) {
243
+ check && this.checkIfIDExists(item.id);
244
+ this.prepareResource(item, {});
245
+ this.resources.set(item.id, {
246
+ resource: item,
247
+ config: {},
248
+ value: undefined,
249
+ isInitialized: false,
250
+ });
251
+ this.computeRegistrationDeeply(item, {});
252
+ }
253
+ storeEventsForAllTasks() {
254
+ for (const task of this.tasks.values()) {
255
+ this.storeEvent(task.task.events.beforeRun);
256
+ this.storeEvent(task.task.events.afterRun);
257
+ this.storeEvent(task.task.events.onError);
258
+ }
259
+ for (const resource of this.resources.values()) {
260
+ this.storeEvent(resource.resource.events.beforeInit);
261
+ this.storeEvent(resource.resource.events.afterInit);
262
+ this.storeEvent(resource.resource.events.onError);
263
+ }
264
+ }
265
+ /**
266
+ * This is for storing a resource without a config.
267
+ * @param item
268
+ */
269
+ prepareResource(item, config) {
270
+ item.dependencies =
271
+ typeof item.dependencies === "function"
272
+ ? item.dependencies(config)
273
+ : item.dependencies;
274
+ return item;
275
+ }
276
+ storeTask(item, check = true) {
277
+ check && this.checkIfIDExists(item.id);
278
+ item.dependencies =
279
+ typeof item.dependencies === "function"
280
+ ? item.dependencies()
281
+ : item.dependencies;
282
+ this.tasks.set(item.id, {
283
+ task: item,
284
+ computedDependencies: {},
285
+ isInitialized: false,
286
+ });
287
+ }
288
+ getDependentNodes() {
289
+ const depenedants = [];
290
+ for (const task of this.tasks.values()) {
291
+ depenedants.push({
292
+ id: task.task.id,
293
+ dependencies: task.task.dependencies,
294
+ });
295
+ }
296
+ for (const middleware of this.middlewares.values()) {
297
+ depenedants.push({
298
+ id: middleware.middleware.id,
299
+ dependencies: middleware.middleware.dependencies,
300
+ });
301
+ }
302
+ for (const resource of this.resources.values()) {
303
+ depenedants.push({
304
+ id: resource.resource.id,
305
+ dependencies: resource.resource.dependencies || {},
306
+ });
307
+ }
308
+ return depenedants;
309
+ }
310
+ }
311
+ exports.Store = Store;
312
+ //# sourceMappingURL=Store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Store.js","sourceRoot":"","sources":["../../src/models/Store.ts"],"names":[],"mappings":";;;AAAA,kCAWiB;AACjB,mCAAmC;AAEnC,kDAAoD;AACpD,sCAAmC;AACnC,wDAAqD;AAoCrD;;GAEG;AACH,MAAa,KAAK;IAce;IAb/B,IAAI,CAA4B;IACzB,KAAK,GAAsC,IAAI,GAAG,EAAE,CAAC;IACrD,SAAS,GAA0C,IAAI,GAAG,EAAE,CAAC;IAC7D,MAAM,GAAuC,IAAI,GAAG,EAAE,CAAC;IACvD,WAAW,GAA4C,IAAI,GAAG,EAAE,CAAC;IACjE,SAAS,GAGZ,IAAI,GAAG,EAAE,CAAC;IAEd,SAAS,GAAG,KAAK,CAAC;IAClB,cAAc,GAAG,KAAK,CAAC;IAEvB,YAA+B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAE7D,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,IAAoB,EAAE,MAAW;QAC/C,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,eAAM,CAAC,uBAAuB,EAAE,CAAC;QACzC,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,iCAAe,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QAC5E,IAAI,CAAC,gBAAgB,C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ACL,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;YAC/C,WAAW,CAAC,IAAI,CAAC;gBACf,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBACxB,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE;aACnD,CAAC,CAAC;QACL,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AA5VD,sBA4VC"}
@@ -0,0 +1,25 @@
1
+ import { DependencyMapType, DependencyValuesType, ITask } from "../defs";
2
+ import { EventManager } from "./EventManager";
3
+ import { Store } from "./Store";
4
+ export declare class TaskRunner {
5
+ protected readonly store: Store;
6
+ protected readonly eventManager: EventManager;
7
+ protected readonly runnerStore: Map<string, (input: any) => Promise<any>>;
8
+ constructor(store: Store, eventManager: EventManager);
9
+ /**
10
+ * Begins the execution of an task. These are registered tasks and all sanity checks have been performed at this stage to ensure consistency of the object.
11
+ * This function can throw only if any of the event listeners or run function throws
12
+ * @param task the task to be run
13
+ * @param input the input to be passed to the task
14
+ * @param taskDependencies optional dependencies to be passed to the task, if not provided, the dependencies will be the ones already computed from the store.
15
+ */
16
+ run<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>, input: TInput, taskDependencies?: DependencyValuesType<TDeps>): Promise<TOutput | undefined>;
17
+ /**
18
+ * Creates the function with the chain of middleware.
19
+ * @param task
20
+ * @param input
21
+ * @param taskDependencies
22
+ * @returns
23
+ */
24
+ protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>, taskDependencies: DependencyValuesType<{}>): (input: any) => Promise<TOutput>;
25
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskRunner = void 0;
4
+ const globalEvents_1 = require("../globalEvents");
5
+ class TaskRunner {
6
+ store;
7
+ eventManager;
8
+ runnerStore = new Map();
9
+ constructor(store, eventManager) {
10
+ this.store = store;
11
+ this.eventManager = eventManager;
12
+ }
13
+ /**
14
+ * Begins the execution of an task. These are registered tasks and all sanity checks have been performed at this stage to ensure consistency of the object.
15
+ * This function can throw only if any of the event listeners or run function throws
16
+ * @param task the task to be run
17
+ * @param input the input to be passed to the task
18
+ * @param taskDependencies optional dependencies to be passed to the task, if not provided, the dependencies will be the ones already computed from the store.
19
+ */
20
+ async run(task, input, taskDependencies) {
21
+ let runner = this.runnerStore.get(task.id);
22
+ if (!runner) {
23
+ const storeTask = this.store.tasks.get(task.id);
24
+ const deps = taskDependencies || storeTask.computedDependencies;
25
+ runner = this.createRunnerWithMiddleware(task, deps);
26
+ this.runnerStore.set(task.id, runner);
27
+ }
28
+ // begin by dispatching the event of creating it.
29
+ // then ensure the hooks are called
30
+ // then ensure the middleware are called
31
+ await this.eventManager.emit(task.events.beforeRun, { input });
32
+ await this.eventManager.emit(globalEvents_1.globalEvents.tasks.beforeRun, {
33
+ task,
34
+ input,
35
+ });
36
+ let error;
37
+ try {
38
+ // craft the next function starting from the first next function
39
+ const output = await runner(input);
40
+ await this.eventManager.emit(task.events.afterRun, { input, output });
41
+ await this.eventManager.emit(globalEvents_1.globalEvents.tasks.afterRun, {
42
+ task,
43
+ input,
44
+ output,
45
+ });
46
+ return output;
47
+ }
48
+ catch (e) {
49
+ let isSuppressed = false;
50
+ const suppress = () => (isSuppressed = true);
51
+ error = e;
52
+ // If you want to rewthrow the error, this should be done inside the onError event.
53
+ await this.eventManager.emit(task.events.onError, { error, suppress });
54
+ await this.eventManager.emit(globalEvents_1.globalEvents.tasks.onError, {
55
+ task,
56
+ error,
57
+ suppress,
58
+ });
59
+ if (!isSuppressed)
60
+ throw e;
61
+ }
62
+ }
63
+ /**
64
+ * Creates the function with the chain of middleware.
65
+ * @param task
66
+ * @param input
67
+ * @param taskDependencies
68
+ * @returns
69
+ */
70
+ createRunnerWithMiddleware(task, taskDependencies) {
71
+ // this is the final next()
72
+ let next = async (input) => {
73
+ return task.run.call(null, input, taskDependencies);
74
+ };
75
+ const existingMiddlewares = task.middleware;
76
+ const createdMiddlewares = [
77
+ ...this.store.getGlobalMiddlewares(existingMiddlewares.map((x) => x.id)),
78
+ ...existingMiddlewares,
79
+ ];
80
+ if (createdMiddlewares.length > 0) {
81
+ // we need to run the middleware in reverse order
82
+ // so we can chain the next function
83
+ for (let i = createdMiddlewares.length - 1; i >= 0; i--) {
84
+ const middleware = createdMiddlewares[i];
85
+ const storeMiddleware = this.store.middlewares.get(middleware.id); // we know it exists because at this stage all sanity checks have been done.
86
+ const nextFunction = next;
87
+ next = async (input) => {
88
+ return storeMiddleware.middleware.run({
89
+ taskDefinition: task,
90
+ input,
91
+ next: nextFunction,
92
+ }, storeMiddleware.computedDependencies);
93
+ };
94
+ }
95
+ }
96
+ return next;
97
+ }
98
+ }
99
+ exports.TaskRunner = TaskRunner;
100
+ //# sourceMappingURL=TaskRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/models/TaskRunner.ts"],"names":[],"mappings":";;;AAGA,kDAA+C;AAO/C,MAAa,UAAU;IAOA;IACA;IAPF,WAAW,GAAG,IAAI,GAAG,EAGrC,CAAC;IAEJ,YACqB,KAAY,EACZ,YAA0B;QAD1B,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ;;;;;;OAMG;IACI,KAAK,CAAC,GAAG,CAKd,IAAmC,EACnC,KAAa,EACb,gBAA8C;QAE9C,IAAI,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,C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AC,UAAU,CAAC,GAAG,CACnC;wBACE,cAAc,EAAE,IAAW;wBAC3B,KAAK;wBACL,IAAI,EAAE,YAAY;qBACnB,EACD,eAAe,CAAC,oBAAoB,CACrC,CAAC;gBACJ,CAAC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlID,gCAkIC"}
@@ -0,0 +1,5 @@
1
+ export * from "./DependencyProcessor";
2
+ export * from "./EventManager";
3
+ export * from "./Logger";
4
+ export * from "./Store";
5
+ export * from "./TaskRunner";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./DependencyProcessor"), exports);
18
+ __exportStar(require("./EventManager"), exports);
19
+ __exportStar(require("./Logger"), exports);
20
+ __exportStar(require("./Store"), exports);
21
+ __exportStar(require("./TaskRunner"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,iDAA+B;AAC/B,2CAAyB;AACzB,0CAAwB;AACxB,+CAA6B"}
package/dist/run.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { TaskRunner } from "./TaskRunner";
1
+ import { TaskRunner } from "./models/TaskRunner";
2
2
  import { DependencyMapType, ITaskDefinition, IResourceDefinintion, IEventDefinition, IMiddlewareDefinition, DependencyValuesType, IResource } from "./defs";
3
- import { EventManager } from "./EventManager";
4
- import { Store } from "./Store";
3
+ import { EventManager } from "./models/EventManager";
4
+ import { Store } from "./models/Store";
5
5
  export type ResourcesStoreElementType<C = any, V = any, D extends DependencyMapType = {}> = {
6
6
  resource: IResourceDefinintion<C, V, D>;
7
7
  computedDependencies?: DependencyValuesType<D>;
package/dist/run.js CHANGED
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.run = run;
4
- const TaskRunner_1 = require("./TaskRunner");
5
- const DependencyProcessor_1 = require("./DependencyProcessor");
6
- const EventManager_1 = require("./EventManager");
4
+ const TaskRunner_1 = require("./models/TaskRunner");
5
+ const DependencyProcessor_1 = require("./models/DependencyProcessor");
6
+ const EventManager_1 = require("./models/EventManager");
7
7
  const globalEvents_1 = require("./globalEvents");
8
- const Store_1 = require("./Store");
8
+ const Store_1 = require("./models/Store");
9
9
  const findCircularDependencies_1 = require("./tools/findCircularDependencies");
10
10
  const errors_1 = require("./errors");
11
11
  const globalResources_1 = require("./globalResources");
12
+ const Logger_1 = require("./models/Logger");
12
13
  async function run(resource, config) {
13
14
  const eventManager = new EventManager_1.EventManager();
14
15
  const store = new Store_1.Store(eventManager);
15
16
  const taskRunner = new TaskRunner_1.TaskRunner(store, eventManager);
16
17
  const processor = new DependencyProcessor_1.DependencyProcessor(store, eventManager, taskRunner);
18
+ const logger = new Logger_1.Logger(eventManager);
17
19
  // In the registration phase we register deeply all the resources, tasks, middleware and events
18
20
  store.initializeStore(resource, config);
21
+ store.storeGenericItem(globalResources_1.globalResources.logger.with(logger));
19
22
  store.storeGenericItem(globalResources_1.globalResources.taskRunner.with(taskRunner));
20
23
  // We verify that there isn't any circular dependencies before we begin computing the dependencies
21
24
  const dependentNodes = store.getDependentNodes();
@@ -23,11 +26,14 @@ async function run(resource, config) {
23
26
  if (circularDependencies.cycles.length > 0) {
24
27
  throw errors_1.Errors.circularDependencies(circularDependencies.cycles);
25
28
  }
26
- await processor.processHooks();
29
+ await store.processOverrides();
30
+ // a form of hooking, we store the events for all tasks
31
+ await store.storeEventsForAllTasks();
32
+ await processor.attachHooks();
33
+ await processor.computeAllDependencies();
27
34
  // Now we can safely compute dependencies without being afraid of an infinite loop.
28
35
  // The hooking part is done here.
29
36
  await eventManager.emit(globalEvents_1.globalEvents.beforeInit);
30
- await processor.computeAllDependencies();
31
37
  // leftovers that were registered but not depended upon, except root
32
38
  await processor.initializeUninitializedResources();
33
39
  // Now we can initialise the root resource
package/dist/run.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AA2DA,kBAwCC;AAnGD,6CAA0C;AAU1C,+DAA4D;AAC5D,iDAA8C;AAC9C,iDAA8C;AAC9C,mCAAgC;AAChC,+EAA4E;AAC5E,qCAAkC;AAClC,uDAAoD;AA2C7C,KAAK,UAAU,GAAG,CACvB,QAAyB,EACzB,MAAU;IAEV,MAAM,YAAY,GAAG,IAAI,2BAAY,EAAE,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,aAAK,CAAC,YAAY,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,IAAI,uBAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,IAAI,yCAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IAE3E,+FAA+F;IAC/F,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACxC,KAAK,CAAC,gBAAgB,CAAC,iCAAe,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAEpE,kGAAkG;IAClG,MAAM,cAAc,GAAG,KAAK,CAAC,i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