@bluelibs/runner 3.3.2 → 3.4.1
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 +491 -74
- package/dist/define.d.ts +5 -5
- package/dist/define.js +22 -2
- package/dist/define.js.map +1 -1
- package/dist/defs.d.ts +55 -21
- package/dist/defs.js.map +1 -1
- package/dist/defs.returnTag.d.ts +36 -0
- package/dist/defs.returnTag.js +4 -0
- package/dist/defs.returnTag.js.map +1 -0
- package/dist/errors.d.ts +60 -10
- package/dist/errors.js +103 -12
- package/dist/errors.js.map +1 -1
- package/dist/globals/globalMiddleware.d.ts +4 -4
- package/dist/globals/globalResources.d.ts +28 -10
- package/dist/globals/middleware/cache.middleware.d.ts +9 -9
- package/dist/globals/resources/queue.resource.d.ts +5 -2
- package/dist/index.d.ts +33 -14
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/models/DependencyProcessor.js +4 -4
- package/dist/models/DependencyProcessor.js.map +1 -1
- package/dist/models/EventManager.js +10 -1
- package/dist/models/EventManager.js.map +1 -1
- package/dist/models/Logger.d.ts +8 -0
- package/dist/models/Logger.js +24 -0
- package/dist/models/Logger.js.map +1 -1
- package/dist/models/OverrideManager.js +1 -1
- package/dist/models/OverrideManager.js.map +1 -1
- package/dist/models/ResourceInitializer.d.ts +2 -2
- package/dist/models/ResourceInitializer.js.map +1 -1
- package/dist/models/Store.d.ts +5 -3
- package/dist/models/Store.js +7 -1
- package/dist/models/Store.js.map +1 -1
- package/dist/models/StoreConstants.d.ts +6 -3
- package/dist/models/StoreRegistry.d.ts +5 -3
- package/dist/models/StoreRegistry.js +17 -1
- package/dist/models/StoreRegistry.js.map +1 -1
- package/dist/models/StoreTypes.d.ts +1 -1
- package/dist/models/StoreValidator.js +5 -5
- package/dist/models/StoreValidator.js.map +1 -1
- package/dist/models/TaskRunner.js +10 -0
- package/dist/models/TaskRunner.js.map +1 -1
- package/dist/run.d.ts +3 -3
- package/dist/run.js +1 -1
- package/dist/run.js.map +1 -1
- package/dist/t1.d.ts +1 -0
- package/dist/t1.js +13 -0
- package/dist/t1.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/package.json +2 -2
- package/src/__tests__/errors.test.ts +92 -11
- package/src/__tests__/models/EventManager.test.ts +0 -1
- package/src/__tests__/models/Logger.test.ts +82 -5
- package/src/__tests__/models/Store.test.ts +57 -0
- package/src/__tests__/recursion/c.resource.ts +1 -1
- package/src/__tests__/run.overrides.test.ts +3 -3
- package/src/__tests__/typesafety.test.ts +112 -9
- package/src/__tests__/validation-edge-cases.test.ts +111 -0
- package/src/__tests__/validation-interface.test.ts +428 -0
- package/src/define.ts +47 -15
- package/src/defs.returnTag.ts +91 -0
- package/src/defs.ts +84 -27
- package/src/errors.ts +95 -23
- package/src/index.ts +1 -0
- package/src/models/DependencyProcessor.ts +9 -5
- package/src/models/EventManager.ts +12 -3
- package/src/models/Logger.ts +28 -0
- package/src/models/OverrideManager.ts +2 -7
- package/src/models/ResourceInitializer.ts +8 -3
- package/src/models/Store.ts +12 -3
- package/src/models/StoreRegistry.ts +27 -2
- package/src/models/StoreTypes.ts +1 -1
- package/src/models/StoreValidator.ts +6 -6
- package/src/models/TaskRunner.ts +10 -1
- package/src/run.ts +8 -5
- package/src/testing.ts +1 -1
|
@@ -15,23 +15,23 @@ class StoreValidator {
|
|
|
15
15
|
}
|
|
16
16
|
checkIfIDExists(id) {
|
|
17
17
|
if (this.tasks.has(id)) {
|
|
18
|
-
throw errors_1.
|
|
18
|
+
throw new errors_1.DuplicateRegistrationError("Task", id);
|
|
19
19
|
}
|
|
20
20
|
if (this.resources.has(id)) {
|
|
21
|
-
throw errors_1.
|
|
21
|
+
throw new errors_1.DuplicateRegistrationError("Resource", id);
|
|
22
22
|
}
|
|
23
23
|
if (this.events.has(id)) {
|
|
24
|
-
throw errors_1.
|
|
24
|
+
throw new errors_1.DuplicateRegistrationError("Event", id);
|
|
25
25
|
}
|
|
26
26
|
if (this.middlewares.has(id)) {
|
|
27
|
-
throw errors_1.
|
|
27
|
+
throw new errors_1.DuplicateRegistrationError("Middleware", id);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
runSanityChecks() {
|
|
31
31
|
for (const task of this.tasks.values()) {
|
|
32
32
|
task.task.middleware.forEach((middleware) => {
|
|
33
33
|
if (!this.middlewares.has(middleware.id)) {
|
|
34
|
-
throw errors_1.
|
|
34
|
+
throw new errors_1.DependencyNotFoundError(`Middleware ${middleware.id.toString()} in Task ${task.task.id.toString()}`);
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreValidator.js","sourceRoot":"","sources":["../../src/models/StoreValidator.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"StoreValidator.js","sourceRoot":"","sources":["../../src/models/StoreValidator.ts"],"names":[],"mappings":";;;AAAA,sCAAgF;AAQhF,MAAa,cAAc;IAEf;IACA;IACA;IACA;IAJV,YACU,KAAiD,EACjD,SAAyD,EACzD,MAAmD,EACnD,WAA6D;QAH7D,UAAK,GAAL,KAAK,CAA4C;QACjD,cAAS,GAAT,SAAS,CAAgD;QACzD,WAAM,GAAN,MAAM,CAA6C;QACnD,gBAAW,GAAX,WAAW,CAAkD;IACpE,CAAC;IAEJ,eAAe,CAAC,EAAmB;QACjC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,mCAA0B,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,mCAA0B,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,mCAA0B,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,mCAA0B,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,eAAe;QACb,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;gBAC1C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;oBACzC,MAAM,IAAI,gCAAuB,CAC/B,cAAc,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC5E,CAAC;gBACJ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAlCD,wCAkCC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TaskRunner = void 0;
|
|
4
4
|
const globalEvents_1 = require("../globals/globalEvents");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
5
6
|
class TaskRunner {
|
|
6
7
|
store;
|
|
7
8
|
eventManager;
|
|
@@ -98,6 +99,15 @@ class TaskRunner {
|
|
|
98
99
|
const storeTask = this.store.tasks.get(task.id);
|
|
99
100
|
// this is the final next()
|
|
100
101
|
let next = async (input) => {
|
|
102
|
+
// Validate input with schema if provided
|
|
103
|
+
if (task.inputSchema) {
|
|
104
|
+
try {
|
|
105
|
+
input = task.inputSchema.parse(input);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw new errors_1.ValidationError("Task input", task.id, error instanceof Error ? error : new Error(String(error)));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
101
111
|
return task.run.call(null, input, storeTask?.computedDependencies);
|
|
102
112
|
};
|
|
103
113
|
const existingMiddlewares = task.middleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/models/TaskRunner.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TaskRunner.js","sourceRoot":"","sources":["../../src/models/TaskRunner.ts"],"names":[],"mappings":";;;AAEA,0DAAuD;AAIvD,sCAA4C;AAE5C,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;;;;;OAKG;IACI,KAAK,CAAC,GAAG,CAKd,IAAmC,EACnC,KAAa;QAEb,IAAI,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,CAAC,0BAA0B,CAAyB,IAAI,CAAC,CAAC;YAEvE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;QAED,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC;QAE9C,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1E,CAAC;QAED,IACE,CAAC,qBAAqB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
1
1
|
import { DependencyMapType, ITaskDefinition, IResourceDefinition, IEventDefinition, IMiddlewareDefinition, DependencyValuesType, IResource } from "./defs";
|
|
2
|
-
export type ResourcesStoreElementType<C = any, V = any, D extends DependencyMapType = {}> = {
|
|
2
|
+
export type ResourcesStoreElementType<C = any, V extends Promise<any> = any, D extends DependencyMapType = {}> = {
|
|
3
3
|
resource: IResourceDefinition<C, V, D>;
|
|
4
4
|
computedDependencies?: DependencyValuesType<D>;
|
|
5
5
|
config: C;
|
|
@@ -21,7 +21,7 @@ export type RunnerState = {
|
|
|
21
21
|
events: Record<string, EventStoreElementType>;
|
|
22
22
|
middleware: Record<string, MiddlewareStoreElementType>;
|
|
23
23
|
};
|
|
24
|
-
export declare function run<C, V>(resource: IResource<C, V
|
|
25
|
-
value: V;
|
|
24
|
+
export declare function run<C, V>(resource: IResource<C, V extends Promise<any> ? V : Promise<any>>, config?: C): Promise<{
|
|
25
|
+
value: V extends Promise<infer U> ? U : V;
|
|
26
26
|
dispose: () => Promise<void>;
|
|
27
27
|
}>;
|
package/dist/run.js
CHANGED
|
@@ -25,7 +25,7 @@ async function run(resource, config) {
|
|
|
25
25
|
const dependentNodes = store.getDependentNodes();
|
|
26
26
|
const circularDependencies = (0, findCircularDependencies_1.findCircularDependencies)(dependentNodes);
|
|
27
27
|
if (circularDependencies.cycles.length > 0) {
|
|
28
|
-
throw errors_1.
|
|
28
|
+
throw new errors_1.CircularDependenciesError(circularDependencies.cycles);
|
|
29
29
|
}
|
|
30
30
|
// the overrides that were registered now will override the other registered resources
|
|
31
31
|
await store.processOverrides();
|
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,kBA6DC;AAnHD,oDAAiD;AAUjD,sEAAmE;AACnE,wDAAqD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AClC,MAAM,SAAS,CAAC,sBAAsB,EAAE,CAAC;IAEzC,6DAA6D;IAC7D,MAAM,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAE1D,mFAAmF;IACnF,iCAAiC;IACjC,MAAM,YAAY,CAAC,IAAI,CAAC,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;QACL,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;QACvB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE;KAC/B,CAAC;AACJ,CAAC"}
|
package/dist/t1.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/t1.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const define_1 = require("./define");
|
|
4
|
+
const tag = (0, define_1.defineTag)({ id: "usertag" });
|
|
5
|
+
const tag2 = (0, define_1.defineTag)({ id: "usertag2" });
|
|
6
|
+
const tag3 = (0, define_1.defineTag)({ id: "usertag3" });
|
|
7
|
+
// Preserve as a const tuple for type extraction
|
|
8
|
+
const tags = [tag.with({ value: 123 }), tag2];
|
|
9
|
+
// Build runtime meta by spreading the tuple (meta.tags becomes an array)
|
|
10
|
+
const meta = {
|
|
11
|
+
tags: ["string", tag2, tag3, tag.with({ value: 123 })],
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=t1.js.map
|
package/dist/t1.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"t1.js","sourceRoot":"","sources":["../src/t1.ts"],"names":[],"mappings":";;AAAA,qCAAqC;AAgBrC,MAAM,GAAG,GAAG,IAAA,kBAAS,EAA2B,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;AACnE,MAAM,IAAI,GAAG,IAAA,kBAAS,EAAe,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AACzD,MAAM,IAAI,GAAG,IAAA,kBAAS,EAAa,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AAEvD,gDAAgD;AAChD,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,CAAU,CAAC;AAEvD,yEAAyE;AACzE,MAAM,IAAI,GAAG;IACX,IAAI,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;CACvC,CAAC"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { EventManager, Logger, Store, TaskRunner } from "./models";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function createTestResource(root: RegisterableItems, options?: {
|
|
9
9
|
overrides?: Array<IResource | ITask | IMiddleware | IResourceWithConfig>;
|
|
10
|
-
}): IResource<void, ReturnType<typeof buildTestFacade
|
|
10
|
+
}): IResource<void, Promise<ReturnType<typeof buildTestFacade>>>;
|
|
11
11
|
declare function buildTestFacade(deps: {
|
|
12
12
|
taskRunner: TaskRunner;
|
|
13
13
|
store: Store;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluelibs/runner",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "BlueLibs Runner",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"coverage": "jest --verbose --coverage",
|
|
16
16
|
"test:clean": "jest --clearCache",
|
|
17
17
|
"testonly": "npm test",
|
|
18
|
-
"test:ci": "
|
|
18
|
+
"test:ci": "jest --verbose --coverage --ci --maxWorkers=2 --reporters=default --reporters=jest-junit",
|
|
19
19
|
"prepublishOnly": "npm run build",
|
|
20
20
|
"typedoc": "typedoc --options typedoc.json",
|
|
21
21
|
"benchmark": "jest --testMatch=\"**/__tests__/benchmark/benchmark.test.ts\" --testTimeout 10000"
|
|
@@ -5,7 +5,20 @@ import {
|
|
|
5
5
|
defineMiddleware,
|
|
6
6
|
} from "../define";
|
|
7
7
|
import { run } from "../run";
|
|
8
|
-
import { Errors } from "
|
|
8
|
+
import { Errors } from "..";
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
RuntimeError,
|
|
12
|
+
DuplicateRegistrationError,
|
|
13
|
+
DependencyNotFoundError,
|
|
14
|
+
UnknownItemTypeError,
|
|
15
|
+
CircularDependenciesError,
|
|
16
|
+
EventNotFoundError,
|
|
17
|
+
MiddlewareAlreadyGlobalError,
|
|
18
|
+
LockedError,
|
|
19
|
+
StoreAlreadyInitializedError,
|
|
20
|
+
ValidationError,
|
|
21
|
+
} = Errors;
|
|
9
22
|
|
|
10
23
|
describe("Errors", () => {
|
|
11
24
|
it("should throw duplicateRegistration error", async () => {
|
|
@@ -18,7 +31,7 @@ describe("Errors", () => {
|
|
|
18
31
|
});
|
|
19
32
|
|
|
20
33
|
await expect(run(app)).rejects.toThrow(
|
|
21
|
-
|
|
34
|
+
new DuplicateRegistrationError("Task", "test.task").message
|
|
22
35
|
);
|
|
23
36
|
});
|
|
24
37
|
|
|
@@ -38,7 +51,9 @@ describe("Errors", () => {
|
|
|
38
51
|
},
|
|
39
52
|
});
|
|
40
53
|
|
|
41
|
-
await expect(run(app)).rejects.toThrow(
|
|
54
|
+
await expect(run(app)).rejects.toThrow(
|
|
55
|
+
new UnknownItemTypeError({}).message
|
|
56
|
+
);
|
|
42
57
|
});
|
|
43
58
|
|
|
44
59
|
it("should throw unknown item type error at resource level", async () => {
|
|
@@ -52,7 +67,9 @@ describe("Errors", () => {
|
|
|
52
67
|
async init(_, {}) {},
|
|
53
68
|
});
|
|
54
69
|
|
|
55
|
-
await expect(run(app)).rejects.toThrow(
|
|
70
|
+
await expect(run(app)).rejects.toThrow(
|
|
71
|
+
new UnknownItemTypeError({}).message
|
|
72
|
+
);
|
|
56
73
|
});
|
|
57
74
|
|
|
58
75
|
it("should throw circularDependencies error", async () => {
|
|
@@ -91,7 +108,7 @@ describe("Errors", () => {
|
|
|
91
108
|
});
|
|
92
109
|
|
|
93
110
|
await expect(run(app)).rejects.toThrow(
|
|
94
|
-
|
|
111
|
+
new EventNotFoundError("non.existent.event").message
|
|
95
112
|
);
|
|
96
113
|
});
|
|
97
114
|
|
|
@@ -148,7 +165,7 @@ describe("Errors", () => {
|
|
|
148
165
|
});
|
|
149
166
|
|
|
150
167
|
await expect(run(app)).rejects.toThrow(
|
|
151
|
-
|
|
168
|
+
new DuplicateRegistrationError("Resource", "res1").message
|
|
152
169
|
);
|
|
153
170
|
});
|
|
154
171
|
|
|
@@ -169,7 +186,7 @@ describe("Errors", () => {
|
|
|
169
186
|
});
|
|
170
187
|
|
|
171
188
|
await expect(run(app)).rejects.toThrow(
|
|
172
|
-
|
|
189
|
+
new DuplicateRegistrationError("Middleware", "middlewarex").message
|
|
173
190
|
);
|
|
174
191
|
});
|
|
175
192
|
|
|
@@ -187,7 +204,7 @@ describe("Errors", () => {
|
|
|
187
204
|
});
|
|
188
205
|
|
|
189
206
|
await expect(run(app)).rejects.toThrow(
|
|
190
|
-
|
|
207
|
+
new DuplicateRegistrationError("Event", "ev1").message
|
|
191
208
|
);
|
|
192
209
|
});
|
|
193
210
|
|
|
@@ -216,7 +233,7 @@ describe("Errors", () => {
|
|
|
216
233
|
});
|
|
217
234
|
|
|
218
235
|
await expect(run(app)).rejects.toThrow(
|
|
219
|
-
|
|
236
|
+
new DependencyNotFoundError("Task test.off.the.grid").message
|
|
220
237
|
);
|
|
221
238
|
});
|
|
222
239
|
|
|
@@ -244,7 +261,7 @@ describe("Errors", () => {
|
|
|
244
261
|
});
|
|
245
262
|
|
|
246
263
|
await expect(run(app)).rejects.toThrow(
|
|
247
|
-
|
|
264
|
+
new DependencyNotFoundError("Resource test.off.the.grid").message
|
|
248
265
|
);
|
|
249
266
|
});
|
|
250
267
|
|
|
@@ -254,7 +271,71 @@ describe("Errors", () => {
|
|
|
254
271
|
run: async () => {},
|
|
255
272
|
}).everywhere();
|
|
256
273
|
expect(() => first.everywhere()).toThrow(
|
|
257
|
-
|
|
274
|
+
new MiddlewareAlreadyGlobalError("x").message
|
|
258
275
|
);
|
|
259
276
|
});
|
|
277
|
+
|
|
278
|
+
describe("Error Classes", () => {
|
|
279
|
+
it("should have correct error names and inheritance", () => {
|
|
280
|
+
// Test base RuntimeError
|
|
281
|
+
const baseError = new RuntimeError("test");
|
|
282
|
+
expect(baseError.name).toBe("RuntimeError");
|
|
283
|
+
expect(baseError).toBeInstanceOf(Error);
|
|
284
|
+
expect(baseError).toBeInstanceOf(RuntimeError);
|
|
285
|
+
|
|
286
|
+
// Test DuplicateRegistrationError
|
|
287
|
+
const dupError = new DuplicateRegistrationError("Task", "test");
|
|
288
|
+
expect(dupError.name).toBe("DuplicateRegistrationError");
|
|
289
|
+
expect(dupError).toBeInstanceOf(Error);
|
|
290
|
+
expect(dupError).toBeInstanceOf(RuntimeError);
|
|
291
|
+
expect(dupError).toBeInstanceOf(DuplicateRegistrationError);
|
|
292
|
+
|
|
293
|
+
// Test DependencyNotFoundError
|
|
294
|
+
const depError = new DependencyNotFoundError("test");
|
|
295
|
+
expect(depError.name).toBe("DependencyNotFoundError");
|
|
296
|
+
expect(depError).toBeInstanceOf(RuntimeError);
|
|
297
|
+
|
|
298
|
+
// Test UnknownItemTypeError
|
|
299
|
+
const unknownError = new UnknownItemTypeError("test");
|
|
300
|
+
expect(unknownError.name).toBe("UnknownItemTypeError");
|
|
301
|
+
expect(unknownError).toBeInstanceOf(RuntimeError);
|
|
302
|
+
|
|
303
|
+
// Test CircularDependenciesError
|
|
304
|
+
const circularError = new CircularDependenciesError(["a", "b"]);
|
|
305
|
+
expect(circularError.name).toBe("CircularDependenciesError");
|
|
306
|
+
expect(circularError).toBeInstanceOf(RuntimeError);
|
|
307
|
+
|
|
308
|
+
// Test EventNotFoundError
|
|
309
|
+
const eventError = new EventNotFoundError("test");
|
|
310
|
+
expect(eventError.name).toBe("EventNotFoundError");
|
|
311
|
+
expect(eventError).toBeInstanceOf(RuntimeError);
|
|
312
|
+
|
|
313
|
+
// Test MiddlewareAlreadyGlobalError
|
|
314
|
+
const middlewareError = new MiddlewareAlreadyGlobalError("test");
|
|
315
|
+
expect(middlewareError.name).toBe("MiddlewareAlreadyGlobalError");
|
|
316
|
+
expect(middlewareError).toBeInstanceOf(RuntimeError);
|
|
317
|
+
|
|
318
|
+
// Test LockedError
|
|
319
|
+
const lockedError = new LockedError("test");
|
|
320
|
+
expect(lockedError.name).toBe("LockedError");
|
|
321
|
+
expect(lockedError).toBeInstanceOf(RuntimeError);
|
|
322
|
+
|
|
323
|
+
// Test StoreAlreadyInitializedError
|
|
324
|
+
const storeError = new StoreAlreadyInitializedError();
|
|
325
|
+
expect(storeError.name).toBe("StoreAlreadyInitializedError");
|
|
326
|
+
expect(storeError).toBeInstanceOf(RuntimeError);
|
|
327
|
+
|
|
328
|
+
// Test ValidationError with Error object
|
|
329
|
+
const validationErrorWithError = new ValidationError("Task input", "test-task", new Error("Required field missing"));
|
|
330
|
+
expect(validationErrorWithError.name).toBe("ValidationError");
|
|
331
|
+
expect(validationErrorWithError.message).toBe("Task input validation failed for test-task: Required field missing");
|
|
332
|
+
expect(validationErrorWithError).toBeInstanceOf(RuntimeError);
|
|
333
|
+
|
|
334
|
+
// Test ValidationError with string
|
|
335
|
+
const validationErrorWithString = new ValidationError("Resource config", Symbol("test-resource"), "Invalid configuration");
|
|
336
|
+
expect(validationErrorWithString.name).toBe("ValidationError");
|
|
337
|
+
expect(validationErrorWithString.message).toBe("Resource config validation failed for Symbol(test-resource): Invalid configuration");
|
|
338
|
+
expect(validationErrorWithString).toBeInstanceOf(RuntimeError);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
260
341
|
});
|
|
@@ -5,12 +5,25 @@ import { globalEvents } from "../../globals/globalEvents";
|
|
|
5
5
|
describe("Logger", () => {
|
|
6
6
|
let logger: Logger;
|
|
7
7
|
let mockEventManager: jest.Mocked<EventManager>;
|
|
8
|
+
let originalEnv: any;
|
|
8
9
|
|
|
9
10
|
beforeEach(() => {
|
|
11
|
+
// Save original environment
|
|
12
|
+
originalEnv = { ...process.env };
|
|
13
|
+
|
|
14
|
+
// Clear environment variables that might affect tests
|
|
15
|
+
delete process.env.RUNNER_DISABLE_LOGS;
|
|
16
|
+
delete process.env.RUNNER_LOG_LEVEL;
|
|
17
|
+
|
|
10
18
|
mockEventManager = new EventManager() as jest.Mocked<EventManager>;
|
|
11
19
|
logger = new Logger(mockEventManager);
|
|
12
20
|
});
|
|
13
21
|
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
// Restore original environment
|
|
24
|
+
process.env = originalEnv;
|
|
25
|
+
});
|
|
26
|
+
|
|
14
27
|
describe("log method", () => {
|
|
15
28
|
it("should emit a log event with correct data", async () => {
|
|
16
29
|
const testData = "Test log message";
|
|
@@ -318,7 +331,7 @@ describe("Logger", () => {
|
|
|
318
331
|
it("should use bound context in log calls", async () => {
|
|
319
332
|
const boundContext = { source: "testSource", userId: "123" };
|
|
320
333
|
const loggerWithContext = new Logger(mockEventManager, boundContext);
|
|
321
|
-
|
|
334
|
+
|
|
322
335
|
mockEventManager.emit = jest.fn().mockResolvedValue(undefined);
|
|
323
336
|
mockEventManager.hasListeners = jest.fn().mockReturnValue(true);
|
|
324
337
|
|
|
@@ -388,6 +401,70 @@ describe("Logger", () => {
|
|
|
388
401
|
});
|
|
389
402
|
});
|
|
390
403
|
|
|
404
|
+
describe("default print threshold", () => {
|
|
405
|
+
it("should default to 'info' level when no environment variables are set", () => {
|
|
406
|
+
const logger = new Logger(mockEventManager);
|
|
407
|
+
expect(logger.printThreshold).toBe("info");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("should respect RUNNER_DISABLE_LOGS=true to disable logging", () => {
|
|
411
|
+
process.env.RUNNER_DISABLE_LOGS = "true";
|
|
412
|
+
const logger = new Logger(mockEventManager);
|
|
413
|
+
expect(logger.printThreshold).toBeNull();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("should respect RUNNER_DISABLE_LOGS=1 to disable logging", () => {
|
|
417
|
+
process.env.RUNNER_DISABLE_LOGS = "1";
|
|
418
|
+
const logger = new Logger(mockEventManager);
|
|
419
|
+
expect(logger.printThreshold).toBeNull();
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("should respect RUNNER_LOG_LEVEL environment variable", () => {
|
|
423
|
+
process.env.RUNNER_LOG_LEVEL = "error";
|
|
424
|
+
const logger = new Logger(mockEventManager);
|
|
425
|
+
expect(logger.printThreshold).toBe("error");
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("should ignore invalid RUNNER_LOG_LEVEL and use default", () => {
|
|
429
|
+
process.env.RUNNER_LOG_LEVEL = "invalid_level";
|
|
430
|
+
const logger = new Logger(mockEventManager);
|
|
431
|
+
expect(logger.printThreshold).toBe("info");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
it("should prioritize RUNNER_DISABLE_LOGS over RUNNER_LOG_LEVEL", () => {
|
|
435
|
+
process.env.RUNNER_DISABLE_LOGS = "true";
|
|
436
|
+
process.env.RUNNER_LOG_LEVEL = "debug";
|
|
437
|
+
const logger = new Logger(mockEventManager);
|
|
438
|
+
expect(logger.printThreshold).toBeNull();
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it("should print info level logs by default", () => {
|
|
442
|
+
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
|
|
443
|
+
|
|
444
|
+
const logger = new Logger(mockEventManager);
|
|
445
|
+
logger.log("info", "This should be printed by default");
|
|
446
|
+
|
|
447
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
448
|
+
expect.stringContaining("This should be printed by default")
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
consoleLogSpy.mockRestore();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("should not print debug level logs by default", () => {
|
|
455
|
+
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
|
|
456
|
+
|
|
457
|
+
const logger = new Logger(mockEventManager);
|
|
458
|
+
logger.log("debug", "This should not be printed by default");
|
|
459
|
+
|
|
460
|
+
expect(consoleLogSpy).not.toHaveBeenCalledWith(
|
|
461
|
+
expect.stringContaining("This should not be printed by default")
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
consoleLogSpy.mockRestore();
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
391
468
|
it("should auto-print logs based on autoPrintLogsAfter option", () => {
|
|
392
469
|
const autoPrintLevel: LogLevels = "warn";
|
|
393
470
|
logger.setPrintThreshold(autoPrintLevel);
|
|
@@ -429,14 +506,14 @@ describe("Logger", () => {
|
|
|
429
506
|
|
|
430
507
|
it("should disable auto-printing when setPrintThreshold is set to null", () => {
|
|
431
508
|
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
|
|
432
|
-
|
|
509
|
+
|
|
433
510
|
// Set to null to disable auto-printing
|
|
434
511
|
logger.setPrintThreshold(null);
|
|
435
|
-
|
|
512
|
+
|
|
436
513
|
logger.log("error", "Should not be printed");
|
|
437
|
-
|
|
514
|
+
|
|
438
515
|
expect(consoleLogSpy).not.toHaveBeenCalled();
|
|
439
|
-
|
|
516
|
+
|
|
440
517
|
consoleLogSpy.mockRestore();
|
|
441
518
|
});
|
|
442
519
|
});
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
defineTask,
|
|
6
6
|
defineMiddleware,
|
|
7
7
|
defineEvent,
|
|
8
|
+
defineTag,
|
|
8
9
|
} from "../../define";
|
|
9
10
|
import { Logger } from "../../models";
|
|
10
11
|
|
|
@@ -167,4 +168,60 @@ describe("Store", () => {
|
|
|
167
168
|
const result = store.getDependentNodes();
|
|
168
169
|
expect(Array.isArray(result)).toBe(true);
|
|
169
170
|
});
|
|
171
|
+
|
|
172
|
+
it("should call getTasksWithTag method", () => {
|
|
173
|
+
const tag = defineTag({
|
|
174
|
+
id: "tags.test",
|
|
175
|
+
});
|
|
176
|
+
const taskTest = defineTask({
|
|
177
|
+
meta: {
|
|
178
|
+
tags: [tag, "test"],
|
|
179
|
+
},
|
|
180
|
+
async run() {
|
|
181
|
+
return "OK";
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
const unfindableTask = defineTask({
|
|
185
|
+
run: async () => 1,
|
|
186
|
+
});
|
|
187
|
+
const rootResource = defineResource({
|
|
188
|
+
id: "root",
|
|
189
|
+
register: [taskTest, unfindableTask],
|
|
190
|
+
init: async () => "Root Value",
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
store.initializeStore(rootResource, {});
|
|
194
|
+
const result = store.getTasksWithTag(tag);
|
|
195
|
+
expect(Array.isArray(result)).toBe(true);
|
|
196
|
+
expect(result).toHaveLength(1);
|
|
197
|
+
const result2 = store.getTasksWithTag("test");
|
|
198
|
+
expect(result2).toHaveLength(1);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("should call getResourcesWithTag method", () => {
|
|
202
|
+
const tag = defineTag({
|
|
203
|
+
id: "tags.test",
|
|
204
|
+
});
|
|
205
|
+
const resourceTest = defineResource({
|
|
206
|
+
meta: {
|
|
207
|
+
tags: [tag, "test"],
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const unfindableResource = defineResource({
|
|
212
|
+
init: async () => 1,
|
|
213
|
+
});
|
|
214
|
+
const rootResource = defineResource({
|
|
215
|
+
id: "root",
|
|
216
|
+
register: [resourceTest, unfindableResource],
|
|
217
|
+
init: async () => "Root Value",
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
store.initializeStore(rootResource, {});
|
|
221
|
+
const result = store.getResourcesWithTag(tag);
|
|
222
|
+
expect(Array.isArray(result)).toBe(true);
|
|
223
|
+
expect(result).toHaveLength(1);
|
|
224
|
+
const result2 = store.getResourcesWithTag("test");
|
|
225
|
+
expect(result2).toHaveLength(1);
|
|
226
|
+
});
|
|
170
227
|
});
|
|
@@ -15,4 +15,4 @@ export const cResource = defineResource({
|
|
|
15
15
|
const result: string = await aTask(); // Still benefits of autocompletion
|
|
16
16
|
return `C depends on ${result}`;
|
|
17
17
|
},
|
|
18
|
-
}) as IResource<void, string
|
|
18
|
+
}) as IResource<void, Promise<string>>; // This is the key change.
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
defineMiddleware,
|
|
7
7
|
defineOverride,
|
|
8
8
|
} from "../define";
|
|
9
|
-
import {
|
|
9
|
+
import { DependencyNotFoundError } from "../errors";
|
|
10
10
|
import { run } from "../run";
|
|
11
11
|
|
|
12
12
|
describe("run.overrides", () => {
|
|
@@ -230,7 +230,7 @@ describe("run.overrides", () => {
|
|
|
230
230
|
});
|
|
231
231
|
|
|
232
232
|
await expect(run(app)).rejects.toThrowError(
|
|
233
|
-
|
|
233
|
+
new DependencyNotFoundError("task2").message
|
|
234
234
|
);
|
|
235
235
|
});
|
|
236
236
|
|
|
@@ -256,7 +256,7 @@ describe("run.overrides", () => {
|
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
await expect(run(app)).rejects.toThrowError(
|
|
259
|
-
|
|
259
|
+
new DependencyNotFoundError("override2").message
|
|
260
260
|
);
|
|
261
261
|
});
|
|
262
262
|
|