@bluelibs/runner 2.1.0 → 2.2.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
CHANGED
|
@@ -280,7 +280,7 @@ const app = resource({
|
|
|
280
280
|
|
|
281
281
|
### wildcard events
|
|
282
282
|
|
|
283
|
-
You can listen to all events by using the wildcard `*`.
|
|
283
|
+
You can listen to all events by using the wildcard `*`. However you need to **manually check** if your dependencies have been computed. For example we dispatch events like 'global.beforeInit' before anything is initialized.
|
|
284
284
|
|
|
285
285
|
```ts
|
|
286
286
|
import { task, resource, run, event, global } from "@bluelibs/runner";
|
|
@@ -23,5 +23,5 @@ export declare class TaskRunner {
|
|
|
23
23
|
* @param taskDependencies
|
|
24
24
|
* @returns
|
|
25
25
|
*/
|
|
26
|
-
protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps
|
|
26
|
+
protected createRunnerWithMiddleware<TInput, TOutput extends Promise<any>, TDeps extends DependencyMapType>(task: ITask<TInput, TOutput, TDeps>): (input: any) => Promise<TOutput>;
|
|
27
27
|
}
|
|
@@ -22,9 +22,7 @@ class TaskRunner {
|
|
|
22
22
|
async run(task, input, taskDependencies) {
|
|
23
23
|
let runner = this.runnerStore.get(task.id);
|
|
24
24
|
if (!runner) {
|
|
25
|
-
|
|
26
|
-
const deps = taskDependencies || storeTask.computedDependencies;
|
|
27
|
-
runner = this.createRunnerWithMiddleware(task, deps);
|
|
25
|
+
runner = this.createRunnerWithMiddleware(task);
|
|
28
26
|
this.runnerStore.set(task.id, runner);
|
|
29
27
|
}
|
|
30
28
|
const isGlobalEventListener = task.on === "*";
|
|
@@ -81,14 +79,15 @@ class TaskRunner {
|
|
|
81
79
|
* @param taskDependencies
|
|
82
80
|
* @returns
|
|
83
81
|
*/
|
|
84
|
-
createRunnerWithMiddleware(task
|
|
82
|
+
createRunnerWithMiddleware(task) {
|
|
83
|
+
const storeTask = this.store.tasks.get(task.id);
|
|
85
84
|
// this is the final next()
|
|
86
85
|
let next = async (input) => {
|
|
87
86
|
this.logger.debug({
|
|
88
87
|
message: `Running task ${task.id}`,
|
|
89
88
|
input,
|
|
90
89
|
}, task.id);
|
|
91
|
-
return task.run.call(null, input,
|
|
90
|
+
return task.run.call(null, input, storeTask?.computedDependencies);
|
|
92
91
|
};
|
|
93
92
|
const existingMiddlewares = task.middleware;
|
|
94
93
|
const createdMiddlewares = [
|
|
@@ -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,
|
|
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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Event = defineEvent<{ message: string }>({ id: "test.event" });
|
|
345
345
|
const eventHandler = jest.fn();
|
|
346
346
|
let isReady = false;
|
|
347
|
+
let matched = false;
|
|
347
348
|
|
|
349
|
+
const dummyResource = defineResource({
|
|
350
|
+
id: "dummy",
|
|
351
|
+
init: async () => "dummy",
|
|
352
|
+
});
|
|
348
353
|
const task = defineTask({
|
|
349
354
|
id: "app",
|
|
350
355
|
on: "*",
|
|
351
|
-
|
|
352
|
-
|
|
356
|
+
dependencies: { dummyResource },
|
|
357
|
+
async run(event, { dummyResource }) {
|
|
358
|
+
if (dummyResource === "dummy") {
|
|
359
|
+
matched = true;
|
|
360
|
+
}
|
|
353
361
|
isReady && eventHandler();
|
|
354
362
|
},
|
|
355
363
|
});
|
|
356
364
|
|
|
357
365
|
const app = defineResource({
|
|
358
366
|
id: "app.resource",
|
|
359
|
-
register: [testEvent, task],
|
|
367
|
+
register: [testEvent, task, dummyResource],
|
|
360
368
|
dependencies: { task, testEvent },
|
|
361
369
|
async init(_, deps) {
|
|
362
370
|
isReady = true;
|
|
@@ -366,6 +374,7 @@ describe("run", () => {
|
|
|
366
374
|
|
|
367
375
|
await run(app);
|
|
368
376
|
expect(eventHandler).toHaveBeenCalled();
|
|
377
|
+
expect(matched).toBe(true);
|
|
369
378
|
});
|
|
370
379
|
});
|
|
371
380
|
|
package/src/models/TaskRunner.ts
CHANGED
|
@@ -39,13 +39,7 @@ export class TaskRunner {
|
|
|
39
39
|
): Promise<TOutput | undefined> {
|
|
40
40
|
let runner = this.runnerStore.get(task.id);
|
|
41
41
|
if (!runner) {
|
|
42
|
-
|
|
43
|
-
const deps = taskDependencies || storeTask.computedDependencies;
|
|
44
|
-
|
|
45
|
-
runner = this.createRunnerWithMiddleware<TInput, TOutput, TDeps>(
|
|
46
|
-
task,
|
|
47
|
-
deps
|
|
48
|
-
);
|
|
42
|
+
runner = this.createRunnerWithMiddleware<TInput, TOutput, TDeps>(task);
|
|
49
43
|
|
|
50
44
|
this.runnerStore.set(task.id, runner);
|
|
51
45
|
}
|
|
@@ -140,10 +134,8 @@ export class TaskRunner {
|
|
|
140
134
|
TInput,
|
|
141
135
|
TOutput extends Promise<any>,
|
|
142
136
|
TDeps extends DependencyMapType
|
|
143
|
-
>(
|
|
144
|
-
|
|
145
|
-
taskDependencies: DependencyValuesType<{}>
|
|
146
|
-
) {
|
|
137
|
+
>(task: ITask<TInput, TOutput, TDeps>) {
|
|
138
|
+
const storeTask = this.store.tasks.get(task.id);
|
|
147
139
|
// this is the final next()
|
|
148
140
|
let next = async (input) => {
|
|
149
141
|
this.logger.debug(
|
|
@@ -154,7 +146,7 @@ export class TaskRunner {
|
|
|
154
146
|
task.id
|
|
155
147
|
);
|
|
156
148
|
|
|
157
|
-
return task.run.call(null, input,
|
|
149
|
+
return task.run.call(null, input, storeTask?.computedDependencies as any);
|
|
158
150
|
};
|
|
159
151
|
|
|
160
152
|
const existingMiddlewares = task.middleware;
|