@bluelibs/runner 1.4.0 → 1.5.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.
- package/README.md +32 -6
- package/dist/defs.d.ts +10 -0
- package/dist/models/DependencyProcessor.d.ts +3 -3
- package/dist/models/DependencyProcessor.js +15 -12
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/models/EventManager.d.ts +1 -1
- package/dist/models/EventManager.js +2 -2
- package/dist/models/EventManager.js.map +1 -1
- package/dist/models/Logger.d.ts +7 -7
- package/dist/models/Logger.js +15 -15
- package/dist/models/Logger.js.map +1 -1
- package/dist/models/ResourceInitializer.js +6 -6
- package/dist/models/ResourceInitializer.js.map +1 -1
- package/dist/models/TaskRunner.js +6 -6
- package/dist/models/TaskRunner.js.map +1 -1
- package/dist/run.js +3 -2
- package/dist/run.js.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/models/EventManager.test.ts +21 -21
- package/src/__tests__/models/Logger.test.ts +6 -4
- package/src/__tests__/models/ResourceInitializer.test.ts +56 -21
- package/src/defs.ts +10 -0
- package/src/models/DependencyProcessor.ts +33 -12
- package/src/models/EventManager.ts +3 -2
- package/src/models/Logger.ts +16 -16
- package/src/models/ResourceInitializer.ts +48 -23
- package/src/models/TaskRunner.ts +37 -17
- package/src/run.ts +3 -2
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# BlueLibs Runner
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://
|
|
4
|
+
<a href="https://github.com/bluelibs/runner/actions/workflows/ci.yml"><img src="https://github.com/bluelibs/runner/actions/workflows/ci.yml/badge.svg?branch=main" alt="Build Status" /></a>
|
|
5
5
|
<a href="https://coveralls.io/github/bluelibs/runner?branch=main"><img src="https://coveralls.io/repos/github/bluelibs/runner/badge.svg?branch=main" alt="Coverage Status" /></a>
|
|
6
6
|
<a href="https://bluelibs.github.io/runner/" target="_blank"><img src="https://img.shields.io/badge/read-typedocs-blue" alt="Docs" /></a>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
+
- [View the documentation page here](https://bluelibs.github.io/runner/).
|
|
10
|
+
- [Google Notebook LM Podcast](https://notebooklm.google.com/notebook/59bd49fa-346b-4cfb-bb4b-b59857c3b9b4/audio)
|
|
11
|
+
- [Continue GPT Conversation](https://chatgpt.com/share/670392f8-7188-800b-9b4b-e49b437d77f7)
|
|
12
|
+
|
|
9
13
|
BlueLibs Runner is a framework that provides a functional approach to building applications, whether small or large-scale. Its core concepts include Tasks, Resources, Events, and Middleware. Tasks represent the units of logic, while resources are singletons that provide shared services across the application. Events facilitate communication between different parts of the system, and Middleware allows interception and modification of task execution. The framework emphasizes an async-first philosophy, ensuring that all operations are executed asynchronously for smoother application flow.
|
|
10
14
|
|
|
11
15
|
## Building Blocks
|
|
@@ -216,8 +220,9 @@ The dependencies get injected as follows:
|
|
|
216
220
|
|
|
217
221
|
## Events
|
|
218
222
|
|
|
219
|
-
|
|
220
|
-
|
|
223
|
+
Events are triggered when specific actions occur in your app, like a user registration or a new comment. When you catch these events, you also receive the emitted data along with the source of the event. Knowing the source of the event without explicitly specifying it can be very helpful in large applications.
|
|
224
|
+
|
|
225
|
+
You can listen for these events using tasks and resources, and similarly, emit them from tasks and resources through dependencies.
|
|
221
226
|
|
|
222
227
|
```ts
|
|
223
228
|
import { task, run, event } from "@bluelibs/runner";
|
|
@@ -255,6 +260,7 @@ const helloTask = task({
|
|
|
255
260
|
on: afterRegisterEvent,
|
|
256
261
|
listenerPriority: 0, // this is the order in which the task will be executed when `on` is present
|
|
257
262
|
run(event) {
|
|
263
|
+
event.source; // id which middleware, task, resource triggered it
|
|
258
264
|
console.log("User has been registered!");
|
|
259
265
|
},
|
|
260
266
|
});
|
|
@@ -813,11 +819,31 @@ run(app);
|
|
|
813
819
|
|
|
814
820
|
### Inter-communication between resources
|
|
815
821
|
|
|
816
|
-
|
|
822
|
+
When registering resources with specific configuration, the initialization order usually doesn’t matter. However, there are cases where it becomes crucial. For instance, consider a security service that allows the injection of a custom hashing function to transition from MD5 to SHA-256.
|
|
823
|
+
|
|
824
|
+
In such cases, your resource should provide a method for other resources to update it. A straightforward approach is to expose a configuration option that lets you set a custom hasher, like so:
|
|
817
825
|
|
|
818
|
-
|
|
826
|
+
```ts
|
|
827
|
+
type SecurityResourceConfig = {
|
|
828
|
+
hasher: (str: string) => string;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const securityResource = resource({
|
|
832
|
+
id: "app.security",
|
|
833
|
+
async init(config: SecurityResourceConfig) {
|
|
834
|
+
return {
|
|
835
|
+
hash: (input: string) => config.hasher(input),
|
|
836
|
+
};
|
|
837
|
+
},
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
const app = resource({
|
|
841
|
+
id: "app",
|
|
842
|
+
register: [securityResource.with({ hasher: (input) => md5(input) })],
|
|
843
|
+
});
|
|
844
|
+
```
|
|
819
845
|
|
|
820
|
-
|
|
846
|
+
However, other resources might need to modify this dynamically as extensions. This is where hooks become valuable.
|
|
821
847
|
|
|
822
848
|
```ts
|
|
823
849
|
import { resource, run, event } from "@bluelibs/runner";
|
package/dist/defs.d.ts
CHANGED
|
@@ -125,8 +125,18 @@ export interface IResourceWithConfig<TConfig = any, TValue = any, TDependencies
|
|
|
125
125
|
}
|
|
126
126
|
export interface IEvent<TPayload = any> {
|
|
127
127
|
id: string;
|
|
128
|
+
/**
|
|
129
|
+
* The data that the event carries. It can be anything.
|
|
130
|
+
*/
|
|
128
131
|
data: TPayload;
|
|
132
|
+
/**
|
|
133
|
+
* The timestamp when the event was created.
|
|
134
|
+
*/
|
|
129
135
|
timestamp: Date;
|
|
136
|
+
/**
|
|
137
|
+
* The source of the event. This can be useful for debugging.
|
|
138
|
+
*/
|
|
139
|
+
source: string;
|
|
130
140
|
}
|
|
131
141
|
export type EventHandlerType<T = any> = (event: IEvent<T>) => any | Promise<any>;
|
|
132
142
|
export interface IEventDefinition<TPayload = void> {
|
|
@@ -38,14 +38,14 @@ export declare class DependencyProcessor {
|
|
|
38
38
|
* @param deps
|
|
39
39
|
*/
|
|
40
40
|
attachHooksToResource(resourceStoreElement: ResourceStoreElementType<any, any, {}>): void;
|
|
41
|
-
extractDependencies<T extends DependencyMapType>(map: T): Promise<DependencyValuesType<T>>;
|
|
42
|
-
extractDependency(object: any): Promise<any>;
|
|
41
|
+
extractDependencies<T extends DependencyMapType>(map: T, source: string): Promise<DependencyValuesType<T>>;
|
|
42
|
+
extractDependency(object: any, source: string): Promise<any>;
|
|
43
43
|
/**
|
|
44
44
|
* Converts the event into a running functions with real inputs
|
|
45
45
|
* @param object
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
extractEventDependency(object: IEventDefinition<Record<string, any
|
|
48
|
+
extractEventDependency(object: IEventDefinition<Record<string, any>>, source: string): (input: any) => Promise<void>;
|
|
49
49
|
extractTaskDependency(object: ITask<any, any, {}>): Promise<(input: any) => Promise<any>>;
|
|
50
50
|
extractResourceDependency(object: IResource<any, any, any>): Promise<any>;
|
|
51
51
|
}
|
|
@@ -28,7 +28,7 @@ class DependencyProcessor {
|
|
|
28
28
|
async computeAllDependencies() {
|
|
29
29
|
for (const middleware of this.store.middlewares.values()) {
|
|
30
30
|
const deps = middleware.middleware.dependencies;
|
|
31
|
-
middleware.computedDependencies = await this.extractDependencies(deps);
|
|
31
|
+
middleware.computedDependencies = await this.extractDependencies(deps, middleware.middleware.id);
|
|
32
32
|
}
|
|
33
33
|
for (const task of this.store.tasks.values()) {
|
|
34
34
|
await this.computeTaskDependencies(task);
|
|
@@ -42,7 +42,7 @@ class DependencyProcessor {
|
|
|
42
42
|
}
|
|
43
43
|
async computeTaskDependencies(task) {
|
|
44
44
|
const deps = task.task.dependencies;
|
|
45
|
-
task.computedDependencies = await this.extractDependencies(deps);
|
|
45
|
+
task.computedDependencies = await this.extractDependencies(deps, task.task.id);
|
|
46
46
|
let eventDefinition = task.task.on;
|
|
47
47
|
if (eventDefinition) {
|
|
48
48
|
if (this.store.events.get(eventDefinition.id) === undefined) {
|
|
@@ -77,7 +77,7 @@ class DependencyProcessor {
|
|
|
77
77
|
*/
|
|
78
78
|
async processResourceDependencies(resource) {
|
|
79
79
|
const deps = resource.resource.dependencies;
|
|
80
|
-
resource.computedDependencies = await this.extractDependencies(deps);
|
|
80
|
+
resource.computedDependencies = await this.extractDependencies(deps, resource.resource.id);
|
|
81
81
|
}
|
|
82
82
|
async initializeRoot() {
|
|
83
83
|
const storeResource = this.store.root;
|
|
@@ -131,14 +131,14 @@ class DependencyProcessor {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
async extractDependencies(map) {
|
|
134
|
+
async extractDependencies(map, source) {
|
|
135
135
|
const object = {};
|
|
136
136
|
for (const key in map) {
|
|
137
|
-
object[key] = await this.extractDependency(map[key]);
|
|
137
|
+
object[key] = await this.extractDependency(map[key], source);
|
|
138
138
|
}
|
|
139
139
|
return object;
|
|
140
140
|
}
|
|
141
|
-
async extractDependency(object) {
|
|
141
|
+
async extractDependency(object, source) {
|
|
142
142
|
if (utils.isResource(object)) {
|
|
143
143
|
return this.extractResourceDependency(object);
|
|
144
144
|
}
|
|
@@ -146,7 +146,7 @@ class DependencyProcessor {
|
|
|
146
146
|
return this.extractTaskDependency(object);
|
|
147
147
|
}
|
|
148
148
|
else if (utils.isEvent(object)) {
|
|
149
|
-
return this.extractEventDependency(object);
|
|
149
|
+
return this.extractEventDependency(object, source);
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
152
|
throw errors_1.Errors.unknownItemType(object);
|
|
@@ -157,10 +157,13 @@ class DependencyProcessor {
|
|
|
157
157
|
* @param object
|
|
158
158
|
* @returns
|
|
159
159
|
*/
|
|
160
|
-
extractEventDependency(object) {
|
|
160
|
+
extractEventDependency(object, source) {
|
|
161
161
|
return async (input) => {
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
// runs it in background.
|
|
163
|
+
this.logger.debug({
|
|
164
|
+
message: `Event ${object.id} was emitted from ${source}`,
|
|
165
|
+
});
|
|
166
|
+
return this.eventManager.emit(object, input, source);
|
|
164
167
|
};
|
|
165
168
|
}
|
|
166
169
|
async extractTaskDependency(object) {
|
|
@@ -172,7 +175,7 @@ class DependencyProcessor {
|
|
|
172
175
|
storeTask.isInitialized = true;
|
|
173
176
|
// it's sanitised
|
|
174
177
|
const dependencies = object.dependencies;
|
|
175
|
-
storeTask.computedDependencies = await this.extractDependencies(dependencies);
|
|
178
|
+
storeTask.computedDependencies = await this.extractDependencies(dependencies, storeTask.task.id);
|
|
176
179
|
}
|
|
177
180
|
return (input) => {
|
|
178
181
|
return this.taskRunner.run(storeTask.task, input, storeTask.computedDependencies);
|
|
@@ -193,7 +196,7 @@ class DependencyProcessor {
|
|
|
193
196
|
storeResource.isInitialized = true;
|
|
194
197
|
// check if it has an initialisation function that provides the value
|
|
195
198
|
if (resource.init) {
|
|
196
|
-
storeResource.value = await this.resourceInitializer.initializeResource(resource, config, await this.extractDependencies(resource.dependencies || {}));
|
|
199
|
+
storeResource.value = await this.resourceInitializer.initializeResource(resource, config, await this.extractDependencies(resource.dependencies || {}, resource.id));
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
202
|
return storeResource.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyProcessor.js","sourceRoot":"","sources":["../../src/models/DependencyProcessor.ts"],"names":[],"mappings":";;;AASA,mCAAmC;AAEnC,+DAA4D;AAE5D,sCAAmC;AAGnC;;;;GAIG;AACH,MAAa,mBAAmB;IAIT;IACA;IACA;IACA;IANF,mBAAmB,CAAsB;IAE5D,YACqB,KAAY,EACZ,YAA0B,EAC1B,UAAsB,EACtB,MAAc;QAHd,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;QACtB,WAAM,GAAN,MAAM,CAAQ;QAEjC,IAAI,CAAC,mBAAmB,GA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,EAAE,GAAG,aAAa,CAAC;QAC3C,IAAI,aAAa,CAAC,aAAa,EAAE,CAAC;YAChC,OAAO,aAAa,CAAC,KAAK,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,qCAAqC;YACrC,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC;YAEnC,qEAAqE;YACrE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAClB,aAAa,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CACrE,QAAQ,EACR,MAAM,EACN,MAAM,IAAI,CAAC,mBAAmB,CAC5B,QAAQ,CAAC,YAAY,IAAI,EAAE,EAC3B,QAAQ,CAAC,EAAE,CACZ,CACF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;CACF;AA9RD,kDA8RC"}
|
|
@@ -11,7 +11,7 @@ export declare class EventManager {
|
|
|
11
11
|
lock(): void;
|
|
12
12
|
checkLock(): void;
|
|
13
13
|
private mergeSortedListeners;
|
|
14
|
-
emit<TInput>(eventDefinition: IEventDefinition<TInput>,
|
|
14
|
+
emit<TInput>(eventDefinition: IEventDefinition<TInput>, data: TInput, source: string): Promise<void>;
|
|
15
15
|
private insertListener;
|
|
16
16
|
addListener<T>(event: IEventDefinition | Array<IEventDefinition>, handler: EventHandlerType<T>, options?: IEventHandlerOptions<T>): void;
|
|
17
17
|
addGlobalListener(handler: EventHandlerType, options?: IEventHandlerOptions): void;
|
|
@@ -35,14 +35,14 @@ class EventManager {
|
|
|
35
35
|
result.push(b[j++]);
|
|
36
36
|
return result;
|
|
37
37
|
}
|
|
38
|
-
async emit(eventDefinition,
|
|
39
|
-
const data = args[0];
|
|
38
|
+
async emit(eventDefinition, data, source) {
|
|
40
39
|
const eventListeners = this.listeners.get(eventDefinition.id) || [];
|
|
41
40
|
const allListeners = this.mergeSortedListeners(eventListeners, this.globalListeners);
|
|
42
41
|
const event = {
|
|
43
42
|
id: eventDefinition.id,
|
|
44
43
|
data,
|
|
45
44
|
timestamp: new Date(),
|
|
45
|
+
source,
|
|
46
46
|
};
|
|
47
47
|
for (const listener of allListeners) {
|
|
48
48
|
if (!listener.filter || listener.filter(event)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventManager.js","sourceRoot":"","sources":["../../src/models/EventManager.ts"],"names":[],"mappings":";;;AACA,sCAAmC;AAGnC,MAAM,sBAAsB,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAa5C,MAAa,YAAY;IACf,SAAS,GAAoC,IAAI,GAAG,EAAE,CAAC;IACvD,eAAe,GAAuB,EAAE,CAAC;IACjD,SAAS,GAAG,KAAK,CAAC;IAElB,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,eAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAEO,oBAAoB,CAC1B,CAAqB,EACrB,CAAqB;QAErB,MAAM,MAAM,GAAuB,EAAE,CAAC;QACtC,IAAI,CAAC,GAAG,CAAC,EACP,CAAC,GAAG,CAAC,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACtB,CAAC;QACH,C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,GAAqB;YACpC,OAAO;YACP,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;YACzB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;QACF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;CACF;AArHD,oCAqHC"}
|
package/dist/models/Logger.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { EventManager } from "./EventManager";
|
|
|
2
2
|
export type LogLevels = "trace" | "debug" | "info" | "warn" | "error" | "critical";
|
|
3
3
|
export interface ILog {
|
|
4
4
|
level: string;
|
|
5
|
-
|
|
5
|
+
source?: string;
|
|
6
6
|
data: any;
|
|
7
7
|
timestamp: Date;
|
|
8
8
|
}
|
|
@@ -29,10 +29,10 @@ export declare class Logger {
|
|
|
29
29
|
*/
|
|
30
30
|
setPrintThreshold(level: LogLevels | null): void;
|
|
31
31
|
print(log: ILog): void;
|
|
32
|
-
info(data: any,
|
|
33
|
-
error(data: any,
|
|
34
|
-
warn(data: any,
|
|
35
|
-
debug(data: any,
|
|
36
|
-
trace(data: any,
|
|
37
|
-
critical(data: any,
|
|
32
|
+
info(data: any, source?: string): Promise<void>;
|
|
33
|
+
error(data: any, source?: string): Promise<void>;
|
|
34
|
+
warn(data: any, source?: string): Promise<void>;
|
|
35
|
+
debug(data: any, source?: string): Promise<void>;
|
|
36
|
+
trace(data: any, source?: string): Promise<void>;
|
|
37
|
+
critical(data: any, source?: string): Promise<void>;
|
|
38
38
|
}
|
package/dist/models/Logger.js
CHANGED
|
@@ -24,14 +24,14 @@ class Logger {
|
|
|
24
24
|
const log = {
|
|
25
25
|
level,
|
|
26
26
|
data,
|
|
27
|
-
|
|
27
|
+
source: source,
|
|
28
28
|
timestamp: new Date(),
|
|
29
29
|
};
|
|
30
30
|
if (this.printThreshold &&
|
|
31
31
|
this.severity[level] >= this.severity[this.printThreshold]) {
|
|
32
32
|
this.print(log);
|
|
33
33
|
}
|
|
34
|
-
await this.eventManager.emit(globalEvents_1.globalEvents.log, log);
|
|
34
|
+
await this.eventManager.emit(globalEvents_1.globalEvents.log, log, source || "unknown");
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Will print logs after that, use `null` to disable autoprinting.
|
|
@@ -42,7 +42,7 @@ class Logger {
|
|
|
42
42
|
}
|
|
43
43
|
print(log) {
|
|
44
44
|
// Extract the relevant information from the log
|
|
45
|
-
const { level, context, data, timestamp } = log;
|
|
45
|
+
const { level, source: context, data, timestamp } = log;
|
|
46
46
|
// Format the timestamp to a more readable format
|
|
47
47
|
const formattedTimestamp = timestamp.toISOString();
|
|
48
48
|
// Format the log level for better visibility
|
|
@@ -65,23 +65,23 @@ class Logger {
|
|
|
65
65
|
// Print the log message
|
|
66
66
|
console.log(logMessage);
|
|
67
67
|
}
|
|
68
|
-
async info(data,
|
|
69
|
-
await this.log("info", data,
|
|
68
|
+
async info(data, source) {
|
|
69
|
+
await this.log("info", data, source);
|
|
70
70
|
}
|
|
71
|
-
async error(data,
|
|
72
|
-
await this.log("error", data,
|
|
71
|
+
async error(data, source) {
|
|
72
|
+
await this.log("error", data, source);
|
|
73
73
|
}
|
|
74
|
-
async warn(data,
|
|
75
|
-
await this.log("warn", data,
|
|
74
|
+
async warn(data, source) {
|
|
75
|
+
await this.log("warn", data, source);
|
|
76
76
|
}
|
|
77
|
-
async debug(data,
|
|
78
|
-
await this.log("debug", data,
|
|
77
|
+
async debug(data, source) {
|
|
78
|
+
await this.log("debug", data, source);
|
|
79
79
|
}
|
|
80
|
-
async trace(data,
|
|
81
|
-
await this.log("trace", data,
|
|
80
|
+
async trace(data, source) {
|
|
81
|
+
await this.log("trace", data, source);
|
|
82
82
|
}
|
|
83
|
-
async critical(data,
|
|
84
|
-
await this.log("critical", data,
|
|
83
|
+
async critical(data, source) {
|
|
84
|
+
await this.log("critical", data, source);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
exports.Logger = Logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/models/Logger.ts"],"names":[],"mappings":";;;AAAA,kDAA+C;AAkB/C,MAAa,MAAM;IAYK;IAXtB,cAAc,GAAqB,IAAI,CAAC;IAEjC,QAAQ,GAAG;QAChB,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;KACZ,CAAC;IAEF,YAAsB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAEpD;;;OAGG;IACI,KAAK,CAAC,GAAG,CACd,KAAgB,EAChB,IAAS,EACT,MAAe;QAEf,MAAM,GAAG,GAAS;YAChB,KAAK;YACL,IAAI;YACJ,
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/models/Logger.ts"],"names":[],"mappings":";;;AAAA,kDAA+C;AAkB/C,MAAa,MAAM;IAYK;IAXtB,cAAc,GAAqB,IAAI,CAAC;IAEjC,QAAQ,GAAG;QAChB,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;KACZ,CAAC;IAEF,YAAsB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAEpD;;;OAGG;IACI,KAAK,CAAC,GAAG,CACd,KAAgB,EAChB,IAAS,EACT,MAAe;QAEf,MAAM,GAAG,GAAS;YAChB,KAAK;YACL,IAAI;YACJ,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;QAEF,IACE,IAAI,CAAC,cAAc;YACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,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M,OAAO,EAAE,CAAC;QAElF,wBAAwB;QACxB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,IAAS,EAAE,MAAe;QAC1C,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,IAAS,EAAE,MAAe;QAC3C,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,IAAS,EAAE,MAAe;QAC1C,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,IAAS,EAAE,MAAe;QAC3C,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,IAAS,EAAE,MAAe;QAC3C,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAS,EAAE,MAAe;QAC9C,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AArGD,wBAqGC"}
|
|
@@ -19,8 +19,8 @@ class ResourceInitializer {
|
|
|
19
19
|
await this.eventManager.emit(globalEvents_1.globalEvents.resources.beforeInit, {
|
|
20
20
|
config,
|
|
21
21
|
resource,
|
|
22
|
-
});
|
|
23
|
-
await this.eventManager.emit(resource.events.beforeInit, { config });
|
|
22
|
+
}, resource.id);
|
|
23
|
+
await this.eventManager.emit(resource.events.beforeInit, { config }, resource.id);
|
|
24
24
|
let error, value;
|
|
25
25
|
try {
|
|
26
26
|
if (resource.init) {
|
|
@@ -29,12 +29,12 @@ class ResourceInitializer {
|
|
|
29
29
|
await this.eventManager.emit(resource.events.afterInit, {
|
|
30
30
|
config,
|
|
31
31
|
value,
|
|
32
|
-
});
|
|
32
|
+
}, resource.id);
|
|
33
33
|
await this.eventManager.emit(globalEvents_1.globalEvents.resources.afterInit, {
|
|
34
34
|
config,
|
|
35
35
|
resource,
|
|
36
36
|
value,
|
|
37
|
-
});
|
|
37
|
+
}, resource.id);
|
|
38
38
|
this.logger.debug(`Resource ${resource.id} initialized`);
|
|
39
39
|
return value;
|
|
40
40
|
}
|
|
@@ -46,12 +46,12 @@ class ResourceInitializer {
|
|
|
46
46
|
await this.eventManager.emit(resource.events.onError, {
|
|
47
47
|
error,
|
|
48
48
|
suppress,
|
|
49
|
-
});
|
|
49
|
+
}, resource.id);
|
|
50
50
|
await this.eventManager.emit(globalEvents_1.globalEvents.resources.onError, {
|
|
51
51
|
error,
|
|
52
52
|
resource,
|
|
53
53
|
suppress,
|
|
54
|
-
});
|
|
54
|
+
}, resource.id);
|
|
55
55
|
if (!isSuppressed)
|
|
56
56
|
throw e;
|
|
57
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceInitializer.js","sourceRoot":"","sources":["../../src/models/ResourceInitializer.ts"],"names":[],"mappings":";;;AAOA,kDAA+C;AAI/C,MAAa,mBAAmB;IAET;IACA;IACA;IAHrB,YACqB,KAAY,EACZ,YAA0B,EAC1B,MAAc;QAFd,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAQ;IAChC,CAAC;IAEJ;;;OAGG;IACI,KAAK,CAAC,kBAAkB,CAK7B,QAA2C,EAC3C,MAAe,EACf,YAAyC;QAEzC,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"ResourceInitializer.js","sourceRoot":"","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,CAAC,EAAE,EAAE,CAAC;YACxD,MAAM,UAAU,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YACzC,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAChD,UAAU,CAAC,EAAE,CACgB,CAAC,CAAC,4EAA4E;YAE7G,MAAM,YAAY,GAAG,IAAI,CAAC;YAC1B,IAAI,GAAG,KAAK,EAAE,MAAS,EAAE,EAAE;gBACzB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,CACnC;oBACE,kBAAkB,EAAE,QAAe;oBACnC,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,YAAY;iBACnB,EACD,eAAe,CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;CACF;AAhID,kDAgIC"}
|
|
@@ -30,21 +30,21 @@ class TaskRunner {
|
|
|
30
30
|
// begin by dispatching the event of creating it.
|
|
31
31
|
// then ensure the hooks are called
|
|
32
32
|
// then ensure the middleware are called
|
|
33
|
-
await this.eventManager.emit(task.events.beforeRun, { input });
|
|
33
|
+
await this.eventManager.emit(task.events.beforeRun, { input }, task.id);
|
|
34
34
|
await this.eventManager.emit(globalEvents_1.globalEvents.tasks.beforeRun, {
|
|
35
35
|
task,
|
|
36
36
|
input,
|
|
37
|
-
});
|
|
37
|
+
}, task.id);
|
|
38
38
|
let error;
|
|
39
39
|
try {
|
|
40
40
|
// craft the next function starting from the first next function
|
|
41
41
|
const output = await runner(input);
|
|
42
|
-
await this.eventManager.emit(task.events.afterRun, { input, output });
|
|
42
|
+
await this.eventManager.emit(task.events.afterRun, { input, output }, task.id);
|
|
43
43
|
await this.eventManager.emit(globalEvents_1.globalEvents.tasks.afterRun, {
|
|
44
44
|
task,
|
|
45
45
|
input,
|
|
46
46
|
output,
|
|
47
|
-
});
|
|
47
|
+
}, task.id);
|
|
48
48
|
return output;
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
@@ -52,12 +52,12 @@ class TaskRunner {
|
|
|
52
52
|
const suppress = () => (isSuppressed = true);
|
|
53
53
|
error = e;
|
|
54
54
|
// If you want to rewthrow the error, this should be done inside the onError event.
|
|
55
|
-
await this.eventManager.emit(task.events.onError, { error, suppress });
|
|
55
|
+
await this.eventManager.emit(task.events.onError, { error, suppress }, task.id);
|
|
56
56
|
await this.eventManager.emit(globalEvents_1.globalEvents.tasks.onError, {
|
|
57
57
|
task,
|
|
58
58
|
error,
|
|
59
59
|
suppress,
|
|
60
|
-
});
|
|
60
|
+
}, task.id);
|
|
61
61
|
if (!isSuppressed)
|
|
62
62
|
throw e;
|
|
63
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/models/TaskRunner.ts"],"names":[],"mappings":";;;AAGA,kDAA+C;AAQ/C,MAAa,UAAU;IAOA;IACA;IACA;IARF,WAAW,GAAG,IAAI,GAAG,EAGrC,CAAC;IAEJ,YACqB,KAAY,EACZ,YAA0B,EAC1B,MAAc;QAFd,UAAK,GAAL,KAAK,CAAO;QACZ,iBAAY,GAAZ,YAAY,CAAc;QAC1B,WAAM,GAAN,MAAM,CAAQ;IAChC,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,CAAyB,CAAC;YACxE,MAAM,IAAI,GAAG,gBAAgB,IAAI,SAAS,CAAC,oBAAoB,CAAC;YAEhE,MAAM,GAAG,IAAI,CAAC,0BAA0B,CACtC,IAAI,E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AK;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;AA5JD,gCA4JC"}
|
package/dist/run.js
CHANGED
|
@@ -33,13 +33,14 @@ async function run(resource, config) {
|
|
|
33
33
|
await store.storeEventsForAllTasks();
|
|
34
34
|
await processor.attachHooks();
|
|
35
35
|
await processor.computeAllDependencies();
|
|
36
|
+
// After this stage, logger print policy could have been set.
|
|
36
37
|
await logger.debug("All elements have been initalized..");
|
|
37
38
|
// Now we can safely compute dependencies without being afraid of an infinite loop.
|
|
38
39
|
// The hooking part is done here.
|
|
39
|
-
await eventManager.emit(globalEvents_1.globalEvents.beforeInit);
|
|
40
|
+
await eventManager.emit(globalEvents_1.globalEvents.beforeInit, null, resource.id);
|
|
40
41
|
// Now we can initialise the root resource
|
|
41
42
|
await processor.initializeRoot();
|
|
42
|
-
await eventManager.emit(globalEvents_1.globalEvents.afterInit);
|
|
43
|
+
await eventManager.emit(globalEvents_1.globalEvents.afterInit, null, resource.id);
|
|
43
44
|
await logger.debug("System initialized and operational.");
|
|
44
45
|
// disallow manipulation or attaching more
|
|
45
46
|
store.lock();
|
package/dist/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAsDA,
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAsDA,kBAuDC;AA7GD,oDAAiD;AAUjD,sEAAmE;AACnE,wDAAqD;AACrD,iDAA8C;AAC9C,0CAAuC;AACvC,+EAA4E;AAC5E,qCAAkC;AAClC,uDAAoD;AACpD,4CAAyC;AAqClC,KAAK,UAAU,GAAG,CACvB,QAAyB,EACzB,MAAU;IAEV,MAAM,YAAY,GAAG,IAAI,2BAAY,EAAE,CAAC;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2BAAY,CAAC,UAAU,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEpE,0CAA0C;IAC1C,MAAM,SAAS,CAAC,cAAc,EAAE,CAAC;IAEjC,MAAM,YAAY,CAAC,IAAI,CAAC,2BAAY,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnE,MAAM,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAE1D,0CAA0C;IAC1C,KAAK,CAAC,IAAI,EAAE,CAAC;IAEb,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluelibs/runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "BlueLibs Runner",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"testonly": "npm test",
|
|
19
19
|
"test:ci": "npm run coverage -- --ci --maxWorkers=2 --reporters=default --reporters=jest-junit",
|
|
20
20
|
"prepublishOnly": "npm run build",
|
|
21
|
-
"typedoc": "typedoc",
|
|
21
|
+
"typedoc": "typedoc --options typedoc.json",
|
|
22
22
|
"benchmark": "jest --testMatch=\"**/__tests__/benchmark/benchmark.test.ts\" --testTimeout 10000"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"source-map-support": "^0.5.13",
|
|
40
40
|
"ts-jest": "^29.0.0",
|
|
41
41
|
"typedoc": "^0.26.7",
|
|
42
|
+
"typedoc-material-theme": "^1.1.0",
|
|
42
43
|
"typescript": "^5.6.2"
|
|
43
44
|
},
|
|
44
45
|
"typings": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@ describe("EventManager", () => {
|
|
|
15
15
|
const handler = jest.fn();
|
|
16
16
|
eventManager.addListener(eventDefinition, handler);
|
|
17
17
|
|
|
18
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
18
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
19
19
|
|
|
20
20
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
21
21
|
expect(handler).toHaveBeenCalledWith(
|
|
@@ -61,7 +61,7 @@ describe("EventManager", () => {
|
|
|
61
61
|
{ order: 3 }
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
64
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
65
65
|
|
|
66
66
|
expect(results).toEqual([0, 1, 2, 3]);
|
|
67
67
|
});
|
|
@@ -72,10 +72,10 @@ describe("EventManager", () => {
|
|
|
72
72
|
|
|
73
73
|
eventManager.addListener(eventDefinition, handler, { filter });
|
|
74
74
|
|
|
75
|
-
await eventManager.emit(eventDefinition, "blocked");
|
|
75
|
+
await eventManager.emit(eventDefinition, "blocked", "test");
|
|
76
76
|
expect(handler).not.toHaveBeenCalled();
|
|
77
77
|
|
|
78
|
-
await eventManager.emit(eventDefinition, "allowed");
|
|
78
|
+
await eventManager.emit(eventDefinition, "allowed", "test");
|
|
79
79
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
80
80
|
expect(handler).toHaveBeenCalledWith(
|
|
81
81
|
expect.objectContaining({
|
|
@@ -89,7 +89,7 @@ describe("EventManager", () => {
|
|
|
89
89
|
|
|
90
90
|
eventManager.addGlobalListener(handler);
|
|
91
91
|
|
|
92
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
92
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
93
93
|
|
|
94
94
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
95
95
|
expect(handler).toHaveBeenCalledWith(
|
|
@@ -133,7 +133,7 @@ describe("EventManager", () => {
|
|
|
133
133
|
{ order: 3 }
|
|
134
134
|
);
|
|
135
135
|
|
|
136
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
136
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
137
137
|
|
|
138
138
|
expect(results).toEqual([
|
|
139
139
|
"globalListener1",
|
|
@@ -169,8 +169,8 @@ describe("EventManager", () => {
|
|
|
169
169
|
eventManager.addListener(eventDef1, handler1);
|
|
170
170
|
eventManager.addListener(eventDef2, handler2);
|
|
171
171
|
|
|
172
|
-
await eventManager.emit(eventDef1, "data1");
|
|
173
|
-
await eventManager.emit(eventDef2, "data2");
|
|
172
|
+
await eventManager.emit(eventDef1, "data1", "test");
|
|
173
|
+
await eventManager.emit(eventDef2, "data2", "test");
|
|
174
174
|
|
|
175
175
|
expect(handler1).toHaveBeenCalledTimes(1);
|
|
176
176
|
expect(handler1).toHaveBeenCalledWith(
|
|
@@ -196,7 +196,7 @@ describe("EventManager", () => {
|
|
|
196
196
|
eventManager.addListener(eventDefinition, handler1);
|
|
197
197
|
eventManager.addListener(eventDefinition, handler2);
|
|
198
198
|
|
|
199
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
199
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
200
200
|
|
|
201
201
|
expect(handler1).toHaveBeenCalledTimes(1);
|
|
202
202
|
expect(handler2).toHaveBeenCalledTimes(1);
|
|
@@ -210,8 +210,8 @@ describe("EventManager", () => {
|
|
|
210
210
|
|
|
211
211
|
eventManager.addListener([eventDef1, eventDef2], handler);
|
|
212
212
|
|
|
213
|
-
await eventManager.emit(eventDef1, "data1");
|
|
214
|
-
await eventManager.emit(eventDef2, "data2");
|
|
213
|
+
await eventManager.emit(eventDef1, "data1", "test");
|
|
214
|
+
await eventManager.emit(eventDef2, "data2", "test");
|
|
215
215
|
|
|
216
216
|
expect(handler).toHaveBeenCalledTimes(2);
|
|
217
217
|
expect(handler).toHaveBeenNthCalledWith(
|
|
@@ -240,7 +240,7 @@ describe("EventManager", () => {
|
|
|
240
240
|
eventManager.addListener(eventDef1, handler1);
|
|
241
241
|
eventManager.addListener(eventDef2, handler2);
|
|
242
242
|
|
|
243
|
-
await eventManager.emit(eventDef1, "data1");
|
|
243
|
+
await eventManager.emit(eventDef1, "data1", "test");
|
|
244
244
|
|
|
245
245
|
expect(handler1).toHaveBeenCalledTimes(1);
|
|
246
246
|
expect(handler2).not.toHaveBeenCalled();
|
|
@@ -266,7 +266,7 @@ describe("EventManager", () => {
|
|
|
266
266
|
{ order: 0 }
|
|
267
267
|
);
|
|
268
268
|
|
|
269
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
269
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
270
270
|
|
|
271
271
|
expect(results).toEqual([0, 1]);
|
|
272
272
|
});
|
|
@@ -279,7 +279,7 @@ describe("EventManager", () => {
|
|
|
279
279
|
eventManager.addListener(eventDefinition, handler);
|
|
280
280
|
|
|
281
281
|
await expect(
|
|
282
|
-
eventManager.emit(eventDefinition, "testData")
|
|
282
|
+
eventManager.emit(eventDefinition, "testData", "test")
|
|
283
283
|
).rejects.toThrow("Handler error");
|
|
284
284
|
});
|
|
285
285
|
|
|
@@ -293,7 +293,7 @@ describe("EventManager", () => {
|
|
|
293
293
|
eventManager.addListener(eventDefinition, handler2);
|
|
294
294
|
|
|
295
295
|
await expect(
|
|
296
|
-
eventManager.emit(eventDefinition, "testData")
|
|
296
|
+
eventManager.emit(eventDefinition, "testData", "test")
|
|
297
297
|
).rejects.toThrow("Handler error");
|
|
298
298
|
|
|
299
299
|
// The second handler should have been called despite the error in the first
|
|
@@ -316,7 +316,7 @@ describe("EventManager", () => {
|
|
|
316
316
|
eventManager.lock();
|
|
317
317
|
|
|
318
318
|
await expect(
|
|
319
|
-
eventManager.emit(eventDefinition, "testData")
|
|
319
|
+
eventManager.emit(eventDefinition, "testData", "test")
|
|
320
320
|
).resolves.toBeUndefined();
|
|
321
321
|
|
|
322
322
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
@@ -340,7 +340,7 @@ describe("EventManager", () => {
|
|
|
340
340
|
{ order: 1 }
|
|
341
341
|
);
|
|
342
342
|
|
|
343
|
-
await eventManager.emit(eventDefinition, "testData");
|
|
343
|
+
await eventManager.emit(eventDefinition, "testData", "test");
|
|
344
344
|
|
|
345
345
|
// According to the merge logic, event listeners come before global listeners when orders are equal
|
|
346
346
|
expect(results).toEqual(["eventListener", "globalListener"]);
|
|
@@ -352,16 +352,16 @@ describe("EventManager", () => {
|
|
|
352
352
|
|
|
353
353
|
eventManager.addGlobalListener(handler, { filter });
|
|
354
354
|
|
|
355
|
-
await eventManager.emit(eventDefinition, "blocked");
|
|
355
|
+
await eventManager.emit(eventDefinition, "blocked", "test");
|
|
356
356
|
expect(handler).not.toHaveBeenCalled();
|
|
357
357
|
|
|
358
|
-
await eventManager.emit(eventDefinition, "allowed");
|
|
358
|
+
await eventManager.emit(eventDefinition, "allowed", "test");
|
|
359
359
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
360
360
|
});
|
|
361
361
|
|
|
362
362
|
it("should handle emitting with no listeners", async () => {
|
|
363
363
|
await expect(
|
|
364
|
-
eventManager.emit(eventDefinition, "testData")
|
|
364
|
+
eventManager.emit(eventDefinition, "testData", "test")
|
|
365
365
|
).resolves.toBeUndefined();
|
|
366
366
|
});
|
|
367
367
|
|
|
@@ -372,7 +372,7 @@ describe("EventManager", () => {
|
|
|
372
372
|
|
|
373
373
|
eventManager.addListener(voidEventDefinition, handler);
|
|
374
374
|
|
|
375
|
-
await eventManager.emit(voidEventDefinition);
|
|
375
|
+
await eventManager.emit(voidEventDefinition, undefined, "test");
|
|
376
376
|
|
|
377
377
|
expect(handler).toHaveBeenCalledTimes(1);
|
|
378
378
|
expect(handler).toHaveBeenCalledWith(
|
|
@@ -26,7 +26,8 @@ describe("Logger", () => {
|
|
|
26
26
|
level: testLevel,
|
|
27
27
|
data: testData,
|
|
28
28
|
timestamp: expect.any(Date),
|
|
29
|
-
})
|
|
29
|
+
}),
|
|
30
|
+
"unknown"
|
|
30
31
|
);
|
|
31
32
|
});
|
|
32
33
|
|
|
@@ -43,7 +44,7 @@ describe("Logger", () => {
|
|
|
43
44
|
mockEventManager.emit = jest.fn();
|
|
44
45
|
|
|
45
46
|
for (const level of levels) {
|
|
46
|
-
await logger.log(level, `Test ${level} message
|
|
47
|
+
await logger.log(level, `Test ${level} message`, "testSource");
|
|
47
48
|
|
|
48
49
|
expect(mockEventManager.emit).toHaveBeenCalledWith(
|
|
49
50
|
globalEvents.log,
|
|
@@ -51,7 +52,8 @@ describe("Logger", () => {
|
|
|
51
52
|
level,
|
|
52
53
|
data: `Test ${level} message`,
|
|
53
54
|
timestamp: expect.any(Date),
|
|
54
|
-
})
|
|
55
|
+
}),
|
|
56
|
+
"testSource"
|
|
55
57
|
);
|
|
56
58
|
}
|
|
57
59
|
});
|
|
@@ -71,7 +73,7 @@ describe("Logger", () => {
|
|
|
71
73
|
it("should print log messages correctly", async () => {
|
|
72
74
|
const testLog: ILog = {
|
|
73
75
|
level: "info",
|
|
74
|
-
|
|
76
|
+
source: "test",
|
|
75
77
|
data: "Test log message",
|
|
76
78
|
timestamp: new Date("2023-01-01T00:00:00Z"),
|
|
77
79
|
};
|
|
@@ -3,6 +3,8 @@ import { Store } from "../../models/Store";
|
|
|
3
3
|
import { EventManager } from "../../models/EventManager";
|
|
4
4
|
import { defineResource } from "../../define";
|
|
5
5
|
import { Logger } from "../../models";
|
|
6
|
+
import { globalResources } from "../../globalResources";
|
|
7
|
+
import { globalEvents } from "../../globalEvents";
|
|
6
8
|
|
|
7
9
|
describe("ResourceInitializer", () => {
|
|
8
10
|
let store: Store;
|
|
@@ -39,13 +41,30 @@ describe("ResourceInitializer", () => {
|
|
|
39
41
|
mockConfig,
|
|
40
42
|
mockDependencies
|
|
41
43
|
);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
|
|
45
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
46
|
+
globalEvents.resources.beforeInit,
|
|
47
|
+
{
|
|
48
|
+
config: mockConfig,
|
|
49
|
+
resource: mockResource,
|
|
50
|
+
},
|
|
51
|
+
"testResource"
|
|
52
|
+
);
|
|
53
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
54
|
+
mockResource.events.beforeInit,
|
|
55
|
+
{
|
|
56
|
+
config: mockConfig,
|
|
57
|
+
},
|
|
58
|
+
"testResource"
|
|
59
|
+
);
|
|
60
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
61
|
+
mockResource.events.afterInit,
|
|
62
|
+
{
|
|
63
|
+
config: mockConfig,
|
|
64
|
+
value: "initialized value",
|
|
65
|
+
},
|
|
66
|
+
"testResource"
|
|
67
|
+
);
|
|
49
68
|
});
|
|
50
69
|
|
|
51
70
|
it("should handle errors and emit onError event", async () => {
|
|
@@ -74,13 +93,21 @@ describe("ResourceInitializer", () => {
|
|
|
74
93
|
mockConfig,
|
|
75
94
|
mockDependencies
|
|
76
95
|
);
|
|
77
|
-
expect(emitSpy).toHaveBeenCalledWith(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
97
|
+
mockResource.events.beforeInit,
|
|
98
|
+
{
|
|
99
|
+
config: mockConfig,
|
|
100
|
+
},
|
|
101
|
+
"testResource"
|
|
102
|
+
);
|
|
103
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
104
|
+
mockResource.events.onError,
|
|
105
|
+
{
|
|
106
|
+
error: mockError,
|
|
107
|
+
suppress: expect.any(Function),
|
|
108
|
+
},
|
|
109
|
+
"testResource"
|
|
110
|
+
);
|
|
84
111
|
});
|
|
85
112
|
|
|
86
113
|
it("should handle resources without init function", async () => {
|
|
@@ -100,12 +127,20 @@ describe("ResourceInitializer", () => {
|
|
|
100
127
|
);
|
|
101
128
|
|
|
102
129
|
expect(result).toBeUndefined();
|
|
103
|
-
expect(emitSpy).toHaveBeenCalledWith(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
130
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
131
|
+
mockResource.events.beforeInit,
|
|
132
|
+
{
|
|
133
|
+
config: mockConfig,
|
|
134
|
+
},
|
|
135
|
+
"testResource"
|
|
136
|
+
);
|
|
137
|
+
expect(emitSpy).toHaveBeenCalledWith(
|
|
138
|
+
mockResource.events.afterInit,
|
|
139
|
+
{
|
|
140
|
+
config: mockConfig,
|
|
141
|
+
value: undefined,
|
|
142
|
+
},
|
|
143
|
+
"testResource"
|
|
144
|
+
);
|
|
110
145
|
});
|
|
111
146
|
});
|
package/src/defs.ts
CHANGED
|
@@ -209,8 +209,18 @@ export interface IResourceWithConfig<
|
|
|
209
209
|
|
|
210
210
|
export interface IEvent<TPayload = any> {
|
|
211
211
|
id: string;
|
|
212
|
+
/**
|
|
213
|
+
* The data that the event carries. It can be anything.
|
|
214
|
+
*/
|
|
212
215
|
data: TPayload;
|
|
216
|
+
/**
|
|
217
|
+
* The timestamp when the event was created.
|
|
218
|
+
*/
|
|
213
219
|
timestamp: Date;
|
|
220
|
+
/**
|
|
221
|
+
* The source of the event. This can be useful for debugging.
|
|
222
|
+
*/
|
|
223
|
+
source: string;
|
|
214
224
|
}
|
|
215
225
|
|
|
216
226
|
export type EventHandlerType<T = any> = (
|
|
@@ -41,7 +41,10 @@ export class DependencyProcessor {
|
|
|
41
41
|
async computeAllDependencies() {
|
|
42
42
|
for (const middleware of this.store.middlewares.values()) {
|
|
43
43
|
const deps = middleware.middleware.dependencies as DependencyMapType;
|
|
44
|
-
middleware.computedDependencies = await this.extractDependencies(
|
|
44
|
+
middleware.computedDependencies = await this.extractDependencies(
|
|
45
|
+
deps,
|
|
46
|
+
middleware.middleware.id
|
|
47
|
+
);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
for (const task of this.store.tasks.values()) {
|
|
@@ -61,7 +64,10 @@ export class DependencyProcessor {
|
|
|
61
64
|
task: TaskStoreElementType<any, any, any>
|
|
62
65
|
) {
|
|
63
66
|
const deps = task.task.dependencies as DependencyMapType;
|
|
64
|
-
task.computedDependencies = await this.extractDependencies(
|
|
67
|
+
task.computedDependencies = await this.extractDependencies(
|
|
68
|
+
deps,
|
|
69
|
+
task.task.id
|
|
70
|
+
);
|
|
65
71
|
|
|
66
72
|
let eventDefinition = task.task.on;
|
|
67
73
|
if (eventDefinition) {
|
|
@@ -117,7 +123,10 @@ export class DependencyProcessor {
|
|
|
117
123
|
resource: ResourceStoreElementType<any, any, {}>
|
|
118
124
|
) {
|
|
119
125
|
const deps = resource.resource.dependencies as DependencyMapType;
|
|
120
|
-
resource.computedDependencies = await this.extractDependencies(
|
|
126
|
+
resource.computedDependencies = await this.extractDependencies(
|
|
127
|
+
deps,
|
|
128
|
+
resource.resource.id
|
|
129
|
+
);
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
public async initializeRoot() {
|
|
@@ -197,24 +206,25 @@ export class DependencyProcessor {
|
|
|
197
206
|
}
|
|
198
207
|
|
|
199
208
|
async extractDependencies<T extends DependencyMapType>(
|
|
200
|
-
map: T
|
|
209
|
+
map: T,
|
|
210
|
+
source: string
|
|
201
211
|
): Promise<DependencyValuesType<T>> {
|
|
202
212
|
const object = {} as DependencyValuesType<T>;
|
|
203
213
|
|
|
204
214
|
for (const key in map) {
|
|
205
|
-
object[key] = await this.extractDependency(map[key]);
|
|
215
|
+
object[key] = await this.extractDependency(map[key], source);
|
|
206
216
|
}
|
|
207
217
|
|
|
208
218
|
return object;
|
|
209
219
|
}
|
|
210
220
|
|
|
211
|
-
async extractDependency(object) {
|
|
221
|
+
async extractDependency(object, source: string) {
|
|
212
222
|
if (utils.isResource(object)) {
|
|
213
223
|
return this.extractResourceDependency(object);
|
|
214
224
|
} else if (utils.isTask(object)) {
|
|
215
225
|
return this.extractTaskDependency(object);
|
|
216
226
|
} else if (utils.isEvent(object)) {
|
|
217
|
-
return this.extractEventDependency(object);
|
|
227
|
+
return this.extractEventDependency(object, source);
|
|
218
228
|
} else {
|
|
219
229
|
throw Errors.unknownItemType(object);
|
|
220
230
|
}
|
|
@@ -225,10 +235,17 @@ export class DependencyProcessor {
|
|
|
225
235
|
* @param object
|
|
226
236
|
* @returns
|
|
227
237
|
*/
|
|
228
|
-
extractEventDependency(
|
|
238
|
+
extractEventDependency(
|
|
239
|
+
object: IEventDefinition<Record<string, any>>,
|
|
240
|
+
source: string
|
|
241
|
+
) {
|
|
229
242
|
return async (input) => {
|
|
230
|
-
|
|
231
|
-
|
|
243
|
+
// runs it in background.
|
|
244
|
+
this.logger.debug({
|
|
245
|
+
message: `Event ${object.id} was emitted from ${source}`,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return this.eventManager.emit(object, input, source);
|
|
232
249
|
};
|
|
233
250
|
}
|
|
234
251
|
|
|
@@ -245,7 +262,8 @@ export class DependencyProcessor {
|
|
|
245
262
|
const dependencies = object.dependencies as DependencyMapType;
|
|
246
263
|
|
|
247
264
|
storeTask.computedDependencies = await this.extractDependencies(
|
|
248
|
-
dependencies
|
|
265
|
+
dependencies,
|
|
266
|
+
storeTask.task.id
|
|
249
267
|
);
|
|
250
268
|
}
|
|
251
269
|
|
|
@@ -277,7 +295,10 @@ export class DependencyProcessor {
|
|
|
277
295
|
storeResource.value = await this.resourceInitializer.initializeResource(
|
|
278
296
|
resource,
|
|
279
297
|
config,
|
|
280
|
-
await this.extractDependencies(
|
|
298
|
+
await this.extractDependencies(
|
|
299
|
+
resource.dependencies || {},
|
|
300
|
+
resource.id
|
|
301
|
+
)
|
|
281
302
|
);
|
|
282
303
|
}
|
|
283
304
|
}
|
|
@@ -55,9 +55,9 @@ export class EventManager {
|
|
|
55
55
|
|
|
56
56
|
async emit<TInput>(
|
|
57
57
|
eventDefinition: IEventDefinition<TInput>,
|
|
58
|
-
|
|
58
|
+
data: TInput,
|
|
59
|
+
source: string
|
|
59
60
|
): Promise<void> {
|
|
60
|
-
const data = args[0];
|
|
61
61
|
const eventListeners = this.listeners.get(eventDefinition.id) || [];
|
|
62
62
|
const allListeners = this.mergeSortedListeners(
|
|
63
63
|
eventListeners,
|
|
@@ -68,6 +68,7 @@ export class EventManager {
|
|
|
68
68
|
id: eventDefinition.id,
|
|
69
69
|
data,
|
|
70
70
|
timestamp: new Date(),
|
|
71
|
+
source,
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
for (const listener of allListeners) {
|
package/src/models/Logger.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type LogLevels =
|
|
|
11
11
|
|
|
12
12
|
export interface ILog {
|
|
13
13
|
level: string;
|
|
14
|
-
|
|
14
|
+
source?: string;
|
|
15
15
|
data: any;
|
|
16
16
|
timestamp: Date;
|
|
17
17
|
}
|
|
@@ -42,7 +42,7 @@ export class Logger {
|
|
|
42
42
|
const log: ILog = {
|
|
43
43
|
level,
|
|
44
44
|
data,
|
|
45
|
-
|
|
45
|
+
source: source,
|
|
46
46
|
timestamp: new Date(),
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ export class Logger {
|
|
|
53
53
|
this.print(log);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
await this.eventManager.emit(globalEvents.log, log);
|
|
56
|
+
await this.eventManager.emit(globalEvents.log, log, source || "unknown");
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -66,7 +66,7 @@ export class Logger {
|
|
|
66
66
|
|
|
67
67
|
public print(log: ILog) {
|
|
68
68
|
// Extract the relevant information from the log
|
|
69
|
-
const { level, context, data, timestamp } = log;
|
|
69
|
+
const { level, source: context, data, timestamp } = log;
|
|
70
70
|
|
|
71
71
|
// Format the timestamp to a more readable format
|
|
72
72
|
const formattedTimestamp = timestamp.toISOString();
|
|
@@ -94,27 +94,27 @@ export class Logger {
|
|
|
94
94
|
console.log(logMessage);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
public async info(data: any,
|
|
98
|
-
await this.log("info", data,
|
|
97
|
+
public async info(data: any, source?: string) {
|
|
98
|
+
await this.log("info", data, source);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
public async error(data: any,
|
|
102
|
-
await this.log("error", data,
|
|
101
|
+
public async error(data: any, source?: string) {
|
|
102
|
+
await this.log("error", data, source);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
public async warn(data: any,
|
|
106
|
-
await this.log("warn", data,
|
|
105
|
+
public async warn(data: any, source?: string) {
|
|
106
|
+
await this.log("warn", data, source);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
public async debug(data: any,
|
|
110
|
-
await this.log("debug", data,
|
|
109
|
+
public async debug(data: any, source?: string) {
|
|
110
|
+
await this.log("debug", data, source);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
public async trace(data: any,
|
|
114
|
-
await this.log("trace", data,
|
|
113
|
+
public async trace(data: any, source?: string) {
|
|
114
|
+
await this.log("trace", data, source);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
public async critical(data: any,
|
|
118
|
-
await this.log("critical", data,
|
|
117
|
+
public async critical(data: any, source?: string) {
|
|
118
|
+
await this.log("critical", data, source);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -29,11 +29,20 @@ export class ResourceInitializer {
|
|
|
29
29
|
config: TConfig,
|
|
30
30
|
dependencies: DependencyValuesType<TDeps>
|
|
31
31
|
): Promise<TValue | undefined> {
|
|
32
|
-
await this.eventManager.emit(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
await this.eventManager.emit(
|
|
33
|
+
globalEvents.resources.beforeInit,
|
|
34
|
+
{
|
|
35
|
+
config,
|
|
36
|
+
resource,
|
|
37
|
+
},
|
|
38
|
+
resource.id
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
await this.eventManager.emit(
|
|
42
|
+
resource.events.beforeInit,
|
|
43
|
+
{ config },
|
|
44
|
+
resource.id
|
|
45
|
+
);
|
|
37
46
|
|
|
38
47
|
let error, value;
|
|
39
48
|
try {
|
|
@@ -41,15 +50,23 @@ export class ResourceInitializer {
|
|
|
41
50
|
value = await this.initWithMiddleware(resource, config, dependencies);
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
await this.eventManager.emit(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
resource
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
await this.eventManager.emit(
|
|
54
|
+
resource.events.afterInit,
|
|
55
|
+
{
|
|
56
|
+
config,
|
|
57
|
+
value,
|
|
58
|
+
},
|
|
59
|
+
resource.id
|
|
60
|
+
);
|
|
61
|
+
await this.eventManager.emit(
|
|
62
|
+
globalEvents.resources.afterInit,
|
|
63
|
+
{
|
|
64
|
+
config,
|
|
65
|
+
resource,
|
|
66
|
+
value,
|
|
67
|
+
},
|
|
68
|
+
resource.id
|
|
69
|
+
);
|
|
53
70
|
|
|
54
71
|
this.logger.debug(`Resource ${resource.id} initialized`);
|
|
55
72
|
|
|
@@ -60,15 +77,23 @@ export class ResourceInitializer {
|
|
|
60
77
|
const suppress = () => (isSuppressed = true);
|
|
61
78
|
|
|
62
79
|
// If you want to rewthrow the error, this should be done inside the onError event.
|
|
63
|
-
await this.eventManager.emit(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
resource
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
await this.eventManager.emit(
|
|
81
|
+
resource.events.onError,
|
|
82
|
+
{
|
|
83
|
+
error,
|
|
84
|
+
suppress,
|
|
85
|
+
},
|
|
86
|
+
resource.id
|
|
87
|
+
);
|
|
88
|
+
await this.eventManager.emit(
|
|
89
|
+
globalEvents.resources.onError,
|
|
90
|
+
{
|
|
91
|
+
error,
|
|
92
|
+
resource,
|
|
93
|
+
suppress,
|
|
94
|
+
},
|
|
95
|
+
resource.id
|
|
96
|
+
);
|
|
72
97
|
|
|
73
98
|
if (!isSuppressed) throw e;
|
|
74
99
|
}
|
package/src/models/TaskRunner.ts
CHANGED
|
@@ -53,23 +53,35 @@ export class TaskRunner {
|
|
|
53
53
|
// begin by dispatching the event of creating it.
|
|
54
54
|
// then ensure the hooks are called
|
|
55
55
|
// then ensure the middleware are called
|
|
56
|
-
await this.eventManager.emit(task.events.beforeRun, { input });
|
|
57
|
-
await this.eventManager.emit(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
await this.eventManager.emit(task.events.beforeRun, { input }, task.id);
|
|
57
|
+
await this.eventManager.emit(
|
|
58
|
+
globalEvents.tasks.beforeRun,
|
|
59
|
+
{
|
|
60
|
+
task,
|
|
61
|
+
input,
|
|
62
|
+
},
|
|
63
|
+
task.id
|
|
64
|
+
);
|
|
61
65
|
|
|
62
66
|
let error;
|
|
63
67
|
try {
|
|
64
68
|
// craft the next function starting from the first next function
|
|
65
69
|
const output = await runner(input);
|
|
66
70
|
|
|
67
|
-
await this.eventManager.emit(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
await this.eventManager.emit(
|
|
72
|
+
task.events.afterRun,
|
|
73
|
+
{ input, output },
|
|
74
|
+
task.id
|
|
75
|
+
);
|
|
76
|
+
await this.eventManager.emit(
|
|
77
|
+
globalEvents.tasks.afterRun,
|
|
78
|
+
{
|
|
79
|
+
task,
|
|
80
|
+
input,
|
|
81
|
+
output,
|
|
82
|
+
},
|
|
83
|
+
task.id
|
|
84
|
+
);
|
|
73
85
|
|
|
74
86
|
return output;
|
|
75
87
|
} catch (e) {
|
|
@@ -78,12 +90,20 @@ export class TaskRunner {
|
|
|
78
90
|
error = e;
|
|
79
91
|
|
|
80
92
|
// If you want to rewthrow the error, this should be done inside the onError event.
|
|
81
|
-
await this.eventManager.emit(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
await this.eventManager.emit(
|
|
94
|
+
task.events.onError,
|
|
95
|
+
{ error, suppress },
|
|
96
|
+
task.id
|
|
97
|
+
);
|
|
98
|
+
await this.eventManager.emit(
|
|
99
|
+
globalEvents.tasks.onError,
|
|
100
|
+
{
|
|
101
|
+
task,
|
|
102
|
+
error,
|
|
103
|
+
suppress,
|
|
104
|
+
},
|
|
105
|
+
task.id
|
|
106
|
+
);
|
|
87
107
|
|
|
88
108
|
if (!isSuppressed) throw e;
|
|
89
109
|
}
|
package/src/run.ts
CHANGED
|
@@ -90,16 +90,17 @@ export async function run<C, V>(
|
|
|
90
90
|
await processor.attachHooks();
|
|
91
91
|
await processor.computeAllDependencies();
|
|
92
92
|
|
|
93
|
+
// After this stage, logger print policy could have been set.
|
|
93
94
|
await logger.debug("All elements have been initalized..");
|
|
94
95
|
|
|
95
96
|
// Now we can safely compute dependencies without being afraid of an infinite loop.
|
|
96
97
|
// The hooking part is done here.
|
|
97
|
-
await eventManager.emit(globalEvents.beforeInit);
|
|
98
|
+
await eventManager.emit(globalEvents.beforeInit, null, resource.id);
|
|
98
99
|
|
|
99
100
|
// Now we can initialise the root resource
|
|
100
101
|
await processor.initializeRoot();
|
|
101
102
|
|
|
102
|
-
await eventManager.emit(globalEvents.afterInit);
|
|
103
|
+
await eventManager.emit(globalEvents.afterInit, null, resource.id);
|
|
103
104
|
await logger.debug("System initialized and operational.");
|
|
104
105
|
|
|
105
106
|
// disallow manipulation or attaching more
|