@tsed/bullmq 8.0.0-rc.5 → 8.0.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/lib/esm/BullMQModule.js +16 -27
- package/lib/esm/BullMQModule.js.map +1 -1
- package/lib/esm/decorators/JobController.js +2 -2
- package/lib/esm/decorators/JobController.js.map +1 -1
- package/lib/esm/dispatchers/JobDispatcher.js +6 -17
- package/lib/esm/dispatchers/JobDispatcher.js.map +1 -1
- package/lib/esm/utils/createQueueProvider.js +8 -11
- package/lib/esm/utils/createQueueProvider.js.map +1 -1
- package/lib/esm/utils/createWorkerProvider.js +9 -10
- package/lib/esm/utils/createWorkerProvider.js.map +1 -1
- package/lib/types/BullMQModule.d.ts +4 -7
- package/lib/types/dispatchers/JobDispatcher.d.ts +0 -3
- package/lib/types/utils/createQueueProvider.d.ts +1 -2
- package/lib/types/utils/createWorkerProvider.d.ts +1 -2
- package/package.json +8 -11
- package/vitest.config.mts +9 -4
package/lib/esm/BullMQModule.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DIContext, InjectorService, Module, runInContext } from "@tsed/di";
|
|
1
|
+
import { constant, DIContext, inject, injectable, injectMany, injector, logger, ProviderType, runInContext } from "@tsed/di";
|
|
3
2
|
import { getComputedType } from "@tsed/schema";
|
|
4
3
|
import { v4 } from "uuid";
|
|
5
4
|
import { BullMQTypes } from "./constants/BullMQTypes.js";
|
|
@@ -10,22 +9,19 @@ import { createWorkerProvider } from "./utils/createWorkerProvider.js";
|
|
|
10
9
|
import { getFallbackJobToken, getJobToken } from "./utils/getJobToken.js";
|
|
11
10
|
import { mapQueueOptions } from "./utils/mapQueueOptions.js";
|
|
12
11
|
import { mapWorkerOptions } from "./utils/mapWorkerOptions.js";
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
this.
|
|
16
|
-
this.dispatcher = dispatcher;
|
|
12
|
+
export class BullMQModule {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.dispatcher = inject(JobDispatcher);
|
|
17
15
|
this.onProcess = async (job) => {
|
|
18
16
|
const jobService = this.getJob(job.name, job.queueName);
|
|
19
17
|
if (!jobService) {
|
|
20
|
-
|
|
18
|
+
logger().warn({
|
|
21
19
|
event: "BULLMQ_JOB_NOT_FOUND",
|
|
22
20
|
message: `Job ${job.name} ${job.queueName} not found`
|
|
23
21
|
});
|
|
24
22
|
return;
|
|
25
23
|
}
|
|
26
24
|
const $ctx = new DIContext({
|
|
27
|
-
injector: this.injector,
|
|
28
|
-
logger: this.injector.logger,
|
|
29
25
|
id: job.id || v4().split("-").join(""),
|
|
30
26
|
additionalProps: {
|
|
31
27
|
logType: "bullmq",
|
|
@@ -69,19 +65,19 @@ let BullMQModule = class BullMQModule {
|
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
67
|
get config() {
|
|
72
|
-
return
|
|
68
|
+
return constant("bullmq");
|
|
73
69
|
}
|
|
74
|
-
$
|
|
70
|
+
$onInit() {
|
|
75
71
|
if (this.isEnabled()) {
|
|
76
|
-
|
|
72
|
+
injectMany(BullMQTypes.CRON).map((job) => this.dispatcher.dispatch(getComputedType(job)));
|
|
77
73
|
}
|
|
78
74
|
}
|
|
79
75
|
async $onDestroy() {
|
|
80
76
|
if (!this.isEnabled()) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
|
-
await Promise.all(
|
|
84
|
-
await Promise.all(
|
|
79
|
+
await Promise.all(injectMany(BullMQTypes.QUEUE).map((queue) => queue.close()));
|
|
80
|
+
await Promise.all(injectMany(BullMQTypes.WORKER).map((worker) => worker.close()));
|
|
85
81
|
}
|
|
86
82
|
isEnabled() {
|
|
87
83
|
return !!this.config;
|
|
@@ -92,13 +88,13 @@ let BullMQModule = class BullMQModule {
|
|
|
92
88
|
buildQueues(queues) {
|
|
93
89
|
queues.forEach((queue) => {
|
|
94
90
|
const opts = mapQueueOptions(queue, this.config);
|
|
95
|
-
createQueueProvider(
|
|
91
|
+
createQueueProvider(queue, opts);
|
|
96
92
|
});
|
|
97
93
|
}
|
|
98
94
|
buildWorkers(workers) {
|
|
99
95
|
workers.forEach((worker) => {
|
|
100
96
|
const opts = mapWorkerOptions(worker, this.config);
|
|
101
|
-
createWorkerProvider(
|
|
97
|
+
createWorkerProvider(worker, this.onProcess, opts);
|
|
102
98
|
});
|
|
103
99
|
}
|
|
104
100
|
/**
|
|
@@ -106,22 +102,15 @@ let BullMQModule = class BullMQModule {
|
|
|
106
102
|
* @private
|
|
107
103
|
*/
|
|
108
104
|
getUniqQueueNames() {
|
|
109
|
-
return new Set(
|
|
105
|
+
return new Set(injector()
|
|
110
106
|
.getProviders([BullMQTypes.JOB, BullMQTypes.CRON, BullMQTypes.FALLBACK_JOB])
|
|
111
107
|
.map((provider) => provider.store.get(BULLMQ)?.queue)
|
|
112
108
|
.concat(this.config.queues)
|
|
113
109
|
.filter(Boolean));
|
|
114
110
|
}
|
|
115
111
|
getJob(name, queueName) {
|
|
116
|
-
return (
|
|
117
|
-
this.injector.get(getFallbackJobToken(queueName)) ||
|
|
118
|
-
this.injector.get(getFallbackJobToken()));
|
|
112
|
+
return inject(getJobToken(queueName, name)) || inject(getFallbackJobToken(queueName)) || inject(getFallbackJobToken());
|
|
119
113
|
}
|
|
120
|
-
}
|
|
121
|
-
BullMQModule
|
|
122
|
-
Module(),
|
|
123
|
-
__metadata("design:paramtypes", [InjectorService,
|
|
124
|
-
JobDispatcher])
|
|
125
|
-
], BullMQModule);
|
|
126
|
-
export { BullMQModule };
|
|
114
|
+
}
|
|
115
|
+
injectable(BullMQModule).type(ProviderType.MODULE);
|
|
127
116
|
//# sourceMappingURL=BullMQModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BullMQModule.js","sourceRoot":"","sources":["../../src/BullMQModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BullMQModule.js","sourceRoot":"","sources":["../../src/BullMQModule.ts"],"names":[],"m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obToken(queue, name),
|
|
13
13
|
type: opts.repeat ? BullMQTypes.CRON : BullMQTypes.JOB
|
|
14
14
|
}));
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export function FallbackJobController(queue) {
|
|
|
17
17
|
return useDecorators(StoreMerge(BULLMQ, {
|
|
18
18
|
queue
|
|
19
19
|
}), Injectable({
|
|
20
|
-
|
|
20
|
+
token: getFallbackJobToken(queue),
|
|
21
21
|
type: BullMQTypes.FALLBACK_JOB
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JobController.js","sourceRoot":"","sources":["../../../src/decorators/JobController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEzE,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAgB,SAAS,EAAE,OAAoB,EAAE;IAC3F,OAAO,aAAa,CAClB,UAAU,CAAC,MAAM,EAAE;QACjB,IAAI;QACJ,KAAK;QACL,IAAI;KACL,CAAC,EACF,UAAU,CAAC;QACT,
|
|
1
|
+
{"version":3,"file":"JobController.js","sourceRoot":"","sources":["../../../src/decorators/JobController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAC,mBAAmB,EAAE,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAEzE,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAgB,SAAS,EAAE,OAAoB,EAAE;IAC3F,OAAO,aAAa,CAClB,UAAU,CAAC,MAAM,EAAE;QACjB,IAAI;QACJ,KAAK;QACL,IAAI;KACL,CAAC,EACF,UAAU,CAAC;QACT,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC;QAC/B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG;KACvD,CAAC,CACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,aAAa,CAClB,UAAU,CAAC,MAAM,EAAE;QACjB,KAAK;KACN,CAAC,EACF,UAAU,CAAC;QACT,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;QACjC,IAAI,EAAE,WAAW,CAAC,YAAY;KAC/B,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import { Store } from "@tsed/core";
|
|
3
|
-
import {
|
|
2
|
+
import { inject, injectable } from "@tsed/di";
|
|
4
3
|
import { BULLMQ } from "../constants/constants.js";
|
|
5
4
|
import { getJobToken } from "../utils/getJobToken.js";
|
|
6
5
|
import { getQueueToken } from "../utils/getQueueToken.js";
|
|
7
|
-
|
|
8
|
-
constructor(injector) {
|
|
9
|
-
this.injector = injector;
|
|
10
|
-
}
|
|
6
|
+
export class JobDispatcher {
|
|
11
7
|
async dispatch(job, payload, options = {}) {
|
|
12
8
|
const { queueName, jobName, defaultJobOptions } = await this.resolveDispatchArgs(job, payload);
|
|
13
|
-
const queue =
|
|
9
|
+
const queue = inject(getQueueToken(queueName));
|
|
14
10
|
if (!queue) {
|
|
15
11
|
throw new Error(`Queue(${queueName}) not defined`);
|
|
16
12
|
}
|
|
@@ -47,10 +43,7 @@ let JobDispatcher = class JobDispatcher {
|
|
|
47
43
|
};
|
|
48
44
|
}
|
|
49
45
|
async retrieveJobOptionsFromClassBasedJob(store, payload) {
|
|
50
|
-
const job =
|
|
51
|
-
if (!job) {
|
|
52
|
-
return store.opts;
|
|
53
|
-
}
|
|
46
|
+
const job = inject(getJobToken(store.queue, store.name));
|
|
54
47
|
const jobId = await job.jobId?.(payload);
|
|
55
48
|
if (jobId === undefined) {
|
|
56
49
|
return store.opts;
|
|
@@ -60,10 +53,6 @@ let JobDispatcher = class JobDispatcher {
|
|
|
60
53
|
jobId
|
|
61
54
|
};
|
|
62
55
|
}
|
|
63
|
-
}
|
|
64
|
-
JobDispatcher
|
|
65
|
-
Injectable(),
|
|
66
|
-
__metadata("design:paramtypes", [InjectorService])
|
|
67
|
-
], JobDispatcher);
|
|
68
|
-
export { JobDispatcher };
|
|
56
|
+
}
|
|
57
|
+
injectable(JobDispatcher);
|
|
69
58
|
//# sourceMappingURL=JobDispatcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JobDispatcher.js","sourceRoot":"","sources":["../../../src/dispatchers/JobDispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JobDispatcher.js","sourceRoot":"","sources":["../../../src/dispatchers/JobDispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAO,MAAM,YAAY,CAAC;AAChD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAC,MAAM,EAAC,MAAM,2BAA2B,CAAC;AAEjD,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAGxD,MAAM,OAAO,aAAa;IAQjB,KAAK,CAAC,QAAQ,CAAC,GAAyC,EAAE,OAAgB,EAAE,UAAuB,EAAE;QAC1G,MAAM,EAAC,SAAS,EAA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CAAC,KAAe,EAAE,OAAgB;QACjF,MAAM,GAAG,GAAG,MAAM,CAAa,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC;QAED,OAAO;YACL,GAAG,KAAK,CAAC,IAAI;YACb,KAAK;SACN,CAAC;IACJ,CAAC;CACF;AAED,UAAU,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import { inject, injectable } from "@tsed/di";
|
|
1
2
|
import { Queue } from "bullmq";
|
|
2
|
-
import { BullMQTypes } from "../constants/BullMQTypes.js";
|
|
3
3
|
import { getQueueToken } from "./getQueueToken.js";
|
|
4
|
-
export function createQueueProvider(
|
|
4
|
+
export function createQueueProvider(queue, opts) {
|
|
5
5
|
const token = getQueueToken(queue);
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
.invoke(token);
|
|
6
|
+
injectable(token)
|
|
7
|
+
.factory(() => new Queue(queue, opts))
|
|
8
|
+
.hooks({
|
|
9
|
+
$onDestroy: (queue) => queue.close()
|
|
10
|
+
});
|
|
11
|
+
return inject(token);
|
|
15
12
|
}
|
|
16
13
|
//# sourceMappingURL=createQueueProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueueProvider.js","sourceRoot":"","sources":["../../../src/utils/createQueueProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createQueueProvider.js","sourceRoot":"","sources":["../../../src/utils/createQueueProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,KAAK,EAAe,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,IAAkB;IACnE,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEnC,UAAU,CAAC,KAAK,CAAC;SACd,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SACrC,KAAK,CAAC;QACL,UAAU,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE;KAC5C,CAAC,CAAC;IAEL,OAAO,MAAM,CAAQ,KAAK,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { inject, injectable } from "@tsed/di";
|
|
1
2
|
import { Worker } from "bullmq";
|
|
2
3
|
import { BullMQTypes } from "../constants/BullMQTypes.js";
|
|
3
4
|
import { getWorkerToken } from "./getWorkerToken.js";
|
|
4
|
-
export function createWorkerProvider(
|
|
5
|
+
export function createWorkerProvider(worker, process, opts) {
|
|
5
6
|
const token = getWorkerToken(worker);
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
.invoke(token);
|
|
7
|
+
injectable(token)
|
|
8
|
+
.type(BullMQTypes.WORKER)
|
|
9
|
+
.value(new Worker(worker, process, opts))
|
|
10
|
+
.hooks({
|
|
11
|
+
$onDestroy: (worker) => worker.close()
|
|
12
|
+
});
|
|
13
|
+
return inject(token);
|
|
15
14
|
}
|
|
16
15
|
//# sourceMappingURL=createWorkerProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createWorkerProvider.js","sourceRoot":"","sources":["../../../src/utils/createWorkerProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createWorkerProvider.js","sourceRoot":"","sources":["../../../src/utils/createWorkerProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAM,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAEnD,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,OAA0B,EAAE,IAAmB;IAClG,MAAM,KAAK,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAErC,UAAU,CAAC,KAAK,CAAC;SACd,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;SACxB,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;SACxC,KAAK,CAAC;QACL,UAAU,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;KAC/C,CAAC,CAAC;IAEL,OAAO,MAAM,CAAS,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BeforeInit } from "@tsed/platform-http";
|
|
1
|
+
import { OnDestroy, type OnInit } from "@tsed/di";
|
|
3
2
|
import { BullMQConfig } from "./config/config.js";
|
|
4
|
-
|
|
5
|
-
export declare class BullMQModule implements BeforeInit, OnDestroy {
|
|
6
|
-
private readonly injector;
|
|
3
|
+
export declare class BullMQModule implements OnInit, OnDestroy {
|
|
7
4
|
private readonly dispatcher;
|
|
8
|
-
constructor(
|
|
5
|
+
constructor();
|
|
9
6
|
get config(): BullMQConfig;
|
|
10
|
-
$
|
|
7
|
+
$onInit(): void;
|
|
11
8
|
$onDestroy(): Promise<void>;
|
|
12
9
|
isEnabled(): boolean;
|
|
13
10
|
isWorkerEnabled(): boolean | undefined;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Type } from "@tsed/core";
|
|
2
|
-
import { InjectorService } from "@tsed/di";
|
|
3
2
|
import { Job as BullMQJob, JobsOptions } from "bullmq";
|
|
4
3
|
import { JobMethods } from "../contracts/index.js";
|
|
5
4
|
import type { JobDispatcherOptions } from "./JobDispatcherOptions.js";
|
|
6
5
|
export declare class JobDispatcher {
|
|
7
|
-
private readonly injector;
|
|
8
|
-
constructor(injector: InjectorService);
|
|
9
6
|
dispatch<T extends JobMethods>(job: Type<T>, payload?: Parameters<T["handle"]>[0], options?: JobsOptions): Promise<BullMQJob>;
|
|
10
7
|
dispatch<P = unknown>(job: JobDispatcherOptions, payload?: P, options?: JobsOptions): Promise<BullMQJob>;
|
|
11
8
|
dispatch<P = unknown>(job: string, payload?: P, options?: JobsOptions): Promise<BullMQJob>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { InjectorService } from "@tsed/di";
|
|
2
1
|
import { Queue, QueueOptions } from "bullmq";
|
|
3
|
-
export declare function createQueueProvider(
|
|
2
|
+
export declare function createQueueProvider(queue: string, opts: QueueOptions): Queue<any, any, string>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { InjectorService } from "@tsed/di";
|
|
2
1
|
import { Job, Worker, WorkerOptions } from "bullmq";
|
|
3
|
-
export declare function createWorkerProvider(
|
|
2
|
+
export declare function createWorkerProvider(worker: string, process: (job: Job) => any, opts: WorkerOptions): Worker<any, any, string>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/bullmq",
|
|
3
3
|
"description": "BullMQ integration for Ts.ED",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.0.0
|
|
5
|
+
"version": "8.0.0",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Ts.ED",
|
|
8
8
|
"BullMQ"
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"tslib": "2.7.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/barrels": "8.0.0
|
|
33
|
-
"@tsed/core": "8.0.0
|
|
34
|
-
"@tsed/di": "8.0.0
|
|
35
|
-
"@tsed/platform-http": "8.0.0
|
|
36
|
-
"@tsed/schema": "8.0.0
|
|
37
|
-
"@tsed/typescript": "8.0.0
|
|
32
|
+
"@tsed/barrels": "8.0.0",
|
|
33
|
+
"@tsed/core": "8.0.0",
|
|
34
|
+
"@tsed/di": "8.0.0",
|
|
35
|
+
"@tsed/platform-http": "8.0.0",
|
|
36
|
+
"@tsed/schema": "8.0.0",
|
|
37
|
+
"@tsed/typescript": "8.0.0",
|
|
38
38
|
"bullmq": "^4.12.3 || ^5.1.1",
|
|
39
39
|
"eslint": "9.12.0",
|
|
40
40
|
"ts-mockito": "^2.6.1",
|
|
@@ -50,8 +50,5 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/third-parties/bullmq",
|
|
52
52
|
"author": "Romain Lenzotti",
|
|
53
|
-
"license": "MIT"
|
|
54
|
-
"publishConfig": {
|
|
55
|
-
"tag": "rc"
|
|
56
|
-
}
|
|
53
|
+
"license": "MIT"
|
|
57
54
|
}
|
package/vitest.config.mts
CHANGED
|
@@ -9,11 +9,16 @@ export default defineConfig(
|
|
|
9
9
|
...presets.test,
|
|
10
10
|
coverage: {
|
|
11
11
|
...presets.test.coverage,
|
|
12
|
+
exclude: [
|
|
13
|
+
...presets.test.coverage.exclude,
|
|
14
|
+
"**/contracts/**/*",
|
|
15
|
+
"**/config/**/*"
|
|
16
|
+
],
|
|
12
17
|
thresholds: {
|
|
13
|
-
statements:
|
|
14
|
-
branches:
|
|
15
|
-
functions:
|
|
16
|
-
lines:
|
|
18
|
+
statements: 100,
|
|
19
|
+
branches: 98.38,
|
|
20
|
+
functions: 100,
|
|
21
|
+
lines: 100
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
}
|