@ddd-ts-kit/scheduling 0.9.0 → 0.11.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 +73 -7
- package/dist/index.d.ts +25 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/job-runner.d.ts.map +1 -1
- package/dist/job-runner.js +1 -13
- package/dist/job-runner.js.map +1 -1
- package/dist/metric-names.d.ts +2 -0
- package/dist/metric-names.d.ts.map +1 -1
- package/dist/metric-names.js +2 -0
- package/dist/metric-names.js.map +1 -1
- package/dist/process/no-timeout-job-error.d.ts +6 -0
- package/dist/process/no-timeout-job-error.d.ts.map +1 -0
- package/dist/process/no-timeout-job-error.js +9 -0
- package/dist/process/no-timeout-job-error.js.map +1 -0
- package/dist/process/stored-process-runner.d.ts +24 -0
- package/dist/process/stored-process-runner.d.ts.map +1 -0
- package/dist/process/stored-process-runner.js +89 -0
- package/dist/process/stored-process-runner.js.map +1 -0
- package/dist/queue/background-job-definition.d.ts +9 -0
- package/dist/queue/background-job-definition.d.ts.map +1 -0
- package/dist/queue/background-job-definition.js +2 -0
- package/dist/queue/background-job-definition.js.map +1 -0
- package/dist/queue/background-job-observer.d.ts +4 -0
- package/dist/queue/background-job-observer.d.ts.map +1 -0
- package/dist/queue/background-job-observer.js +2 -0
- package/dist/queue/background-job-observer.js.map +1 -0
- package/dist/queue/background-job-outcome.d.ts +9 -0
- package/dist/queue/background-job-outcome.d.ts.map +1 -0
- package/dist/queue/background-job-outcome.js +2 -0
- package/dist/queue/background-job-outcome.js.map +1 -0
- package/dist/queue/background-job-recorder.d.ts +19 -0
- package/dist/queue/background-job-recorder.d.ts.map +1 -0
- package/dist/queue/background-job-recorder.js +87 -0
- package/dist/queue/background-job-recorder.js.map +1 -0
- package/dist/queue/background-job-run.d.ts +15 -0
- package/dist/queue/background-job-run.d.ts.map +1 -0
- package/dist/queue/background-job-run.js +2 -0
- package/dist/queue/background-job-run.js.map +1 -0
- package/dist/queue/claimed-job-runner.d.ts +44 -0
- package/dist/queue/claimed-job-runner.d.ts.map +1 -0
- package/dist/queue/claimed-job-runner.js +178 -0
- package/dist/queue/claimed-job-runner.js.map +1 -0
- package/dist/queue/errors/attempts-exhausted-error.d.ts +6 -0
- package/dist/queue/errors/attempts-exhausted-error.d.ts.map +1 -0
- package/dist/queue/errors/attempts-exhausted-error.js +9 -0
- package/dist/queue/errors/attempts-exhausted-error.js.map +1 -0
- package/dist/queue/errors/invalid-enqueue-error.d.ts +8 -0
- package/dist/queue/errors/invalid-enqueue-error.d.ts.map +1 -0
- package/dist/queue/errors/invalid-enqueue-error.js +15 -0
- package/dist/queue/errors/invalid-enqueue-error.js.map +1 -0
- package/dist/queue/errors/job-interrupted-error.d.ts +6 -0
- package/dist/queue/errors/job-interrupted-error.d.ts.map +1 -0
- package/dist/queue/errors/job-interrupted-error.js +9 -0
- package/dist/queue/errors/job-interrupted-error.js.map +1 -0
- package/dist/queue/errors/unknown-background-job-error.d.ts +6 -0
- package/dist/queue/errors/unknown-background-job-error.d.ts.map +1 -0
- package/dist/queue/errors/unknown-background-job-error.js +9 -0
- package/dist/queue/errors/unknown-background-job-error.js.map +1 -0
- package/dist/queue/queue-state.d.ts +12 -0
- package/dist/queue/queue-state.d.ts.map +1 -0
- package/dist/queue/queue-state.js +2 -0
- package/dist/queue/queue-state.js.map +1 -0
- package/dist/queue/queue-worker-options.d.ts +29 -0
- package/dist/queue/queue-worker-options.d.ts.map +1 -0
- package/dist/queue/queue-worker-options.js +2 -0
- package/dist/queue/queue-worker-options.js.map +1 -0
- package/dist/queue/queue-worker.d.ts +52 -0
- package/dist/queue/queue-worker.d.ts.map +1 -0
- package/dist/queue/queue-worker.js +194 -0
- package/dist/queue/queue-worker.js.map +1 -0
- package/dist/queue/registered-background-job.d.ts +11 -0
- package/dist/queue/registered-background-job.d.ts.map +1 -0
- package/dist/queue/registered-background-job.js +17 -0
- package/dist/queue/registered-background-job.js.map +1 -0
- package/dist/queue/report-failed-background-jobs.d.ts +11 -0
- package/dist/queue/report-failed-background-jobs.d.ts.map +1 -0
- package/dist/queue/report-failed-background-jobs.js +22 -0
- package/dist/queue/report-failed-background-jobs.js.map +1 -0
- package/dist/queue/running-job.d.ts +14 -0
- package/dist/queue/running-job.d.ts.map +1 -0
- package/dist/queue/running-job.js +2 -0
- package/dist/queue/running-job.js.map +1 -0
- package/dist/queue/store/claim-request.d.ts +8 -0
- package/dist/queue/store/claim-request.d.ts.map +1 -0
- package/dist/queue/store/claim-request.js +2 -0
- package/dist/queue/store/claim-request.js.map +1 -0
- package/dist/queue/store/claimed-job.d.ts +15 -0
- package/dist/queue/store/claimed-job.d.ts.map +1 -0
- package/dist/queue/store/claimed-job.js +2 -0
- package/dist/queue/store/claimed-job.js.map +1 -0
- package/dist/queue/store/in-memory-job-store.d.ts +40 -0
- package/dist/queue/store/in-memory-job-store.d.ts.map +1 -0
- package/dist/queue/store/in-memory-job-store.js +185 -0
- package/dist/queue/store/in-memory-job-store.js.map +1 -0
- package/dist/queue/store/job-failure.d.ts +8 -0
- package/dist/queue/store/job-failure.d.ts.map +1 -0
- package/dist/queue/store/job-failure.js +2 -0
- package/dist/queue/store/job-failure.js.map +1 -0
- package/dist/queue/store/job-lease.d.ts +9 -0
- package/dist/queue/store/job-lease.d.ts.map +1 -0
- package/dist/queue/store/job-lease.js +2 -0
- package/dist/queue/store/job-lease.js.map +1 -0
- package/dist/queue/store/job-store-stats.d.ts +7 -0
- package/dist/queue/store/job-store-stats.d.ts.map +1 -0
- package/dist/queue/store/job-store-stats.js +2 -0
- package/dist/queue/store/job-store-stats.js.map +1 -0
- package/dist/queue/store/job-store.d.ts +53 -0
- package/dist/queue/store/job-store.d.ts.map +1 -0
- package/dist/queue/store/job-store.js +12 -0
- package/dist/queue/store/job-store.js.map +1 -0
- package/dist/queue/store/job-update.d.ts +7 -0
- package/dist/queue/store/job-update.d.ts.map +1 -0
- package/dist/queue/store/job-update.js +2 -0
- package/dist/queue/store/job-update.js.map +1 -0
- package/dist/queue/store/new-job.d.ts +17 -0
- package/dist/queue/store/new-job.d.ts.map +1 -0
- package/dist/queue/store/new-job.js +2 -0
- package/dist/queue/store/new-job.js.map +1 -0
- package/dist/queue/store/plain-json.d.ts +3 -0
- package/dist/queue/store/plain-json.d.ts.map +1 -0
- package/dist/queue/store/plain-json.js +5 -0
- package/dist/queue/store/plain-json.js.map +1 -0
- package/dist/queue/store/queued-job-of.d.ts +5 -0
- package/dist/queue/store/queued-job-of.d.ts.map +1 -0
- package/dist/queue/store/queued-job-of.js +18 -0
- package/dist/queue/store/queued-job-of.js.map +1 -0
- package/dist/queue/store/stored-job.d.ts +22 -0
- package/dist/queue/store/stored-job.d.ts.map +1 -0
- package/dist/queue/store/stored-job.js +2 -0
- package/dist/queue/store/stored-job.js.map +1 -0
- package/dist/queue/store/tenant-key-of.d.ts +8 -0
- package/dist/queue/store/tenant-key-of.d.ts.map +1 -0
- package/dist/queue/store/tenant-key-of.js +9 -0
- package/dist/queue/store/tenant-key-of.js.map +1 -0
- package/dist/queue/stored-job-queue.d.ts +27 -0
- package/dist/queue/stored-job-queue.d.ts.map +1 -0
- package/dist/queue/stored-job-queue.js +78 -0
- package/dist/queue/stored-job-queue.js.map +1 -0
- package/dist/unless-aborted.d.ts +3 -0
- package/dist/unless-aborted.d.ts.map +1 -0
- package/dist/unless-aborted.js +14 -0
- package/dist/unless-aborted.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who may still report on a claimed job: the claim of that attempt. A worker whose lease expired
|
|
3
|
+
* and whose job was claimed again holds an older attempt, and the store ignores it.
|
|
4
|
+
*/
|
|
5
|
+
export interface JobLease {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly attempt: number;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=job-lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-lease.d.ts","sourceRoot":"","sources":["../../../src/queue/store/job-lease.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-lease.js","sourceRoot":"","sources":["../../../src/queue/store/job-lease.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-store-stats.d.ts","sourceRoot":"","sources":["../../../src/queue/store/job-store-stats.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-store-stats.js","sourceRoot":"","sources":["../../../src/queue/store/job-store-stats.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { EnqueuedJob, QueuedJob } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { ClaimRequest } from './claim-request.js';
|
|
3
|
+
import type { ClaimedJob } from './claimed-job.js';
|
|
4
|
+
import type { JobFailure } from './job-failure.js';
|
|
5
|
+
import type { JobLease } from './job-lease.js';
|
|
6
|
+
import type { JobStoreStats } from './job-store-stats.js';
|
|
7
|
+
import type { JobUpdate } from './job-update.js';
|
|
8
|
+
import type { NewJob } from './new-job.js';
|
|
9
|
+
/**
|
|
10
|
+
* Where background jobs wait between `enqueue` and their run, and what a worker reports of them.
|
|
11
|
+
*
|
|
12
|
+
* A claim is a lease: a job claimed and not heard of before its lease ends is claimed again,
|
|
13
|
+
* which is how the jobs of a worker that died come back. Every report names the attempt it
|
|
14
|
+
* holds (`JobLease`): once the job was claimed again, or cancelled, the store answers false and
|
|
15
|
+
* the worker stops. Every write answers false when it changed nothing.
|
|
16
|
+
*/
|
|
17
|
+
export declare abstract class JobStore {
|
|
18
|
+
static readonly tokenKey = "scheduling.JobStore";
|
|
19
|
+
/**
|
|
20
|
+
* Adds the job, in the transaction of the caller when the store is transactional. A job of the
|
|
21
|
+
* same name, tenant and idempotency key already kept is answered instead, `duplicate: true`.
|
|
22
|
+
* A store that writes after the commit checks the key before: two jobs of one key staged
|
|
23
|
+
* before either committed both answer their own id, and only the first is kept.
|
|
24
|
+
*/
|
|
25
|
+
abstract add(job: NewJob): Promise<EnqueuedJob>;
|
|
26
|
+
/**
|
|
27
|
+
* Claims up to `limit` jobs of the queue that are due (waiting with `runAt` passed, or running
|
|
28
|
+
* with an expired lease), the earliest first, and counts the attempt. Two concurrent claims
|
|
29
|
+
* never return the same job.
|
|
30
|
+
*/
|
|
31
|
+
abstract claim(request: ClaimRequest): Promise<ClaimedJob[]>;
|
|
32
|
+
/** Extends the lease while the run goes on. False: the job was cancelled or claimed again. */
|
|
33
|
+
abstract heartbeat(lease: JobLease, leaseUntil: Date): Promise<boolean>;
|
|
34
|
+
/** Stores the progress or the checkpoint of the run, and extends the lease. */
|
|
35
|
+
abstract update(lease: JobLease, update: JobUpdate, leaseUntil: Date): Promise<boolean>;
|
|
36
|
+
abstract complete(lease: JobLease, at: Date): Promise<boolean>;
|
|
37
|
+
/** Schedules the next attempt, or declares the job dead when `retryAt` is null. */
|
|
38
|
+
abstract fail(lease: JobLease, failure: JobFailure): Promise<boolean>;
|
|
39
|
+
/** Gives a job back without counting the attempt: the worker stops before the run could end. */
|
|
40
|
+
abstract release(lease: JobLease, runAt: Date): Promise<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* A waiting or running job is cancelled: a running one learns it at its next heartbeat. In
|
|
43
|
+
* the transaction of the caller, or once it committed for a store that cannot share it.
|
|
44
|
+
*/
|
|
45
|
+
abstract cancel(id: string, at: Date): Promise<boolean>;
|
|
46
|
+
abstract find(id: string): Promise<QueuedJob | undefined>;
|
|
47
|
+
/** Puts dead jobs back with a fresh attempt budget. Answers how many. */
|
|
48
|
+
abstract retryDead(ids: readonly string[], now: Date): Promise<number>;
|
|
49
|
+
/** Housekeeping: drops the jobs that succeeded or were cancelled before `before`. Dead jobs stay. */
|
|
50
|
+
abstract purgeFinished(before: Date): Promise<number>;
|
|
51
|
+
abstract stats(queue: string): Promise<JobStoreStats>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=job-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-store.d.ts","sourceRoot":"","sources":["../../../src/queue/store/job-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C;;;;;;;GAOG;AACH,8BAAsB,QAAQ;IAC5B,MAAM,CAAC,QAAQ,CAAC,QAAQ,yBAAyB;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEhD;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,U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0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where background jobs wait between `enqueue` and their run, and what a worker reports of them.
|
|
3
|
+
*
|
|
4
|
+
* A claim is a lease: a job claimed and not heard of before its lease ends is claimed again,
|
|
5
|
+
* which is how the jobs of a worker that died come back. Every report names the attempt it
|
|
6
|
+
* holds (`JobLease`): once the job was claimed again, or cancelled, the store answers false and
|
|
7
|
+
* the worker stops. Every write answers false when it changed nothing.
|
|
8
|
+
*/
|
|
9
|
+
export class JobStore {
|
|
10
|
+
static tokenKey = 'scheduling.JobStore';
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=job-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-store.js","sourceRoot":"","sources":["../../../src/queue/store/job-store.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,MAAM,OAAgB,QAAQ;IAC5B,MAAM,CAAU,QAAQ,GAAG,qBAAqB,CAAC;CA8ClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-update.d.ts","sourceRoot":"","sources":["../../../src/queue/store/job-update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-update.js","sourceRoot":"","sources":["../../../src/queue/store/job-update.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EnqueuedBy } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/** A job as `enqueue` hands it to the store. */
|
|
3
|
+
export interface NewJob {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly queue: string;
|
|
7
|
+
/** Plain JSON. */
|
|
8
|
+
readonly payload: unknown;
|
|
9
|
+
/** Its `tenantId`, when present, scopes the idempotency key: two tenants never share one. */
|
|
10
|
+
readonly enqueuedBy: EnqueuedBy;
|
|
11
|
+
readonly enqueuedAt: Date;
|
|
12
|
+
readonly runAt: Date;
|
|
13
|
+
readonly idempotencyKey?: string;
|
|
14
|
+
/** What the job works on, answered by `find`. */
|
|
15
|
+
readonly subject?: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=new-job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-job.d.ts","sourceRoot":"","sources":["../../../src/queue/store/new-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,gDAAgD;AAChD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,kBAAkB;IAClB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6FAA6F;IAC7F,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,iDAAiD;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-job.js","sourceRoot":"","sources":["../../../src/queue/store/new-job.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-json.d.ts","sourceRoot":"","sources":["../../../src/queue/store/plain-json.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** A value as it comes back from JSON, the way every store of the queue hands it back: a date becomes its text. */
|
|
2
|
+
export function plainJson(value) {
|
|
3
|
+
return value === undefined ? undefined : JSON.parse(JSON.stringify(value));
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=plain-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-json.js","sourceRoot":"","sources":["../../../src/queue/store/plain-json.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QueuedJob } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { StoredJob } from './stored-job.js';
|
|
3
|
+
/** What a stored job shows of itself: never its payload, its checkpoint or its actor. */
|
|
4
|
+
export declare function queuedJobOf(job: StoredJob): QueuedJob;
|
|
5
|
+
//# sourceMappingURL=queued-job-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queued-job-of.d.ts","sourceRoot":"","sources":["../../../src/queue/store/queued-job-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,GAAG,EAAE,SAAS,GAAG,SAAS,CAerD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** What a stored job shows of itself: never its payload, its checkpoint or its actor. */
|
|
2
|
+
export function queuedJobOf(job) {
|
|
3
|
+
return {
|
|
4
|
+
id: job.id,
|
|
5
|
+
name: job.name,
|
|
6
|
+
queue: job.queue,
|
|
7
|
+
status: job.status,
|
|
8
|
+
attempts: job.attempts,
|
|
9
|
+
enqueuedAt: job.enqueuedAt,
|
|
10
|
+
runAt: job.runAt,
|
|
11
|
+
...(job.enqueuedBy.tenantId === undefined ? {} : { tenantId: job.enqueuedBy.tenantId }),
|
|
12
|
+
...(job.subject === undefined ? {} : { subject: job.subject }),
|
|
13
|
+
...(job.progress === undefined ? {} : { progress: job.progress }),
|
|
14
|
+
...(job.lastErrorCode === undefined ? {} : { lastErrorCode: job.lastErrorCode }),
|
|
15
|
+
...(job.finishedAt === undefined ? {} : { finishedAt: job.finishedAt }),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=queued-job-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queued-job-of.js","sourceRoot":"","sources":["../../../src/queue/store/queued-job-of.ts"],"names":[],"mappings":"AAGA,yFAAyF;AACzF,MAAM,UAAU,WAAW,CAAC,GAAc;IACxC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;QACvF,GAAG,CAAC,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;QAC9D,GAAG,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjE,GAAG,CAAC,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,CAAC,aAAa,EAAE,CAAC;QAChF,GAAG,CAAC,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC;KACxE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EnqueuedBy, JobProgress, QueuedJobStatus } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/** A job as the in-memory store keeps it. */
|
|
3
|
+
export interface StoredJob {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly queue: string;
|
|
7
|
+
readonly payload: unknown;
|
|
8
|
+
readonly enqueuedBy: EnqueuedBy;
|
|
9
|
+
readonly enqueuedAt: Date;
|
|
10
|
+
readonly idempotencyKey: string | undefined;
|
|
11
|
+
readonly subject: string | undefined;
|
|
12
|
+
readonly sequence: number;
|
|
13
|
+
status: QueuedJobStatus;
|
|
14
|
+
attempts: number;
|
|
15
|
+
runAt: Date;
|
|
16
|
+
leaseUntil: Date | undefined;
|
|
17
|
+
progress: JobProgress | undefined;
|
|
18
|
+
checkpoint: unknown;
|
|
19
|
+
lastErrorCode: string | undefined;
|
|
20
|
+
finishedAt: Date | undefined;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=stored-job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-job.d.ts","sourceRoot":"","sources":["../../../src/queue/store/stored-job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEnF,6CAA6C;AAC7C,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;IACZ,UAAU,EAAE,IAAI,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,WAAW,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,EAAE,IAAI,GAAG,SAAS,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-job.js","sourceRoot":"","sources":["../../../src/queue/store/stored-job.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EnqueuedBy } from '@ddd-ts-kit/kernel';
|
|
2
|
+
/**
|
|
3
|
+
* The tenant part of the idempotency key of a job, for a store that keeps it in a column of a
|
|
4
|
+
* unique index: the tenant, or the empty text for a job enqueued outside any tenant, because a
|
|
5
|
+
* null would make every such key distinct on PostgreSQL before 15.
|
|
6
|
+
*/
|
|
7
|
+
export declare function tenantKeyOf(enqueuedBy: EnqueuedBy): string;
|
|
8
|
+
//# sourceMappingURL=tenant-key-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-key-of.d.ts","sourceRoot":"","sources":["../../../src/queue/store/tenant-key-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tenant part of the idempotency key of a job, for a store that keeps it in a column of a
|
|
3
|
+
* unique index: the tenant, or the empty text for a job enqueued outside any tenant, because a
|
|
4
|
+
* null would make every such key distinct on PostgreSQL before 15.
|
|
5
|
+
*/
|
|
6
|
+
export function tenantKeyOf(enqueuedBy) {
|
|
7
|
+
return enqueuedBy.tenantId ?? '';
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=tenant-key-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-key-of.js","sourceRoot":"","sources":["../../../src/queue/store/tenant-key-of.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,UAAsB;IAChD,OAAO,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type BackgroundJobType, type Clock, type EnqueuedJob, type EnqueueOptions, type ExecutionScope, type IdGenerator, type JobQueue, type QueuedJob } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { JobStore } from './store/job-store.js';
|
|
3
|
+
export interface StoredJobQueueOptions {
|
|
4
|
+
readonly store: JobStore;
|
|
5
|
+
readonly clock: Clock;
|
|
6
|
+
readonly ids: IdGenerator;
|
|
7
|
+
/** Where the correlation, the actor and the tenant of the work that enqueues are read. */
|
|
8
|
+
readonly scope: ExecutionScope;
|
|
9
|
+
/** The `traceparent` of the active span, stored with the job: `captureTraceparent` of `@ddd-ts-kit/tracing`. */
|
|
10
|
+
readonly traceparent?: () => string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The `JobQueue` of the kernel on a `JobStore`: it names the job, captures what travels with it
|
|
14
|
+
* and adds it to the store, in the transaction of the caller when the store shares it. `find`
|
|
15
|
+
* and `cancel` reach the jobs of the tenant of the work in progress only (the tenants of its
|
|
16
|
+
* elevation), every job when the work has no tenant.
|
|
17
|
+
*/
|
|
18
|
+
export declare class StoredJobQueue implements JobQueue {
|
|
19
|
+
private readonly options;
|
|
20
|
+
constructor(options: StoredJobQueueOptions);
|
|
21
|
+
enqueue<Payload>(job: BackgroundJobType<Payload>, payload: NoInfer<Payload>, options?: EnqueueOptions): Promise<EnqueuedJob>;
|
|
22
|
+
cancel(id: string): Promise<boolean>;
|
|
23
|
+
find(id: string): Promise<QueuedJob | undefined>;
|
|
24
|
+
/** Outside of any execution scope (a script, a test), the job acts as itself, under a correlation of its own. */
|
|
25
|
+
private enqueuedBy;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=stored-job-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-job-queue.d.ts","sourceRoot":"","sources":["../../src/queue/stored-job-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,KAAK,EAEV,KAAK,WAAW,EAChB,KAAK,cAAc,EAEnB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,0FAA0F;IAC1F,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,gHAAgH;IAChH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CACjD;AAED;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,QAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,EAAE,qBAAqB,EAAI;IAEzD,OAAO,CAAC,OAAO,EACnB,GAAG,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC/B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAgBtB;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMzC;IAEK,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAIrD;IAED,iHAAiH;IACjH,OAAO,CAAC,UAAU;CAanB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { isJobName, parseDuration, systemActor, } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { InvalidEnqueueError } from './errors/invalid-enqueue-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* The `JobQueue` of the kernel on a `JobStore`: it names the job, captures what travels with it
|
|
5
|
+
* and adds it to the store, in the transaction of the caller when the store shares it. `find`
|
|
6
|
+
* and `cancel` reach the jobs of the tenant of the work in progress only (the tenants of its
|
|
7
|
+
* elevation), every job when the work has no tenant.
|
|
8
|
+
*/
|
|
9
|
+
export class StoredJobQueue {
|
|
10
|
+
options;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
async enqueue(job, payload, options = {}) {
|
|
15
|
+
const name = nameOf(job);
|
|
16
|
+
const enqueuedAt = this.options.clock.now();
|
|
17
|
+
const { idempotencyKey, subject } = options;
|
|
18
|
+
return this.options.store.add({
|
|
19
|
+
id: this.options.ids.next(),
|
|
20
|
+
name,
|
|
21
|
+
queue: queueOf(name),
|
|
22
|
+
payload,
|
|
23
|
+
enqueuedBy: this.enqueuedBy(name),
|
|
24
|
+
enqueuedAt,
|
|
25
|
+
runAt: runAtOf(options, enqueuedAt),
|
|
26
|
+
...(idempotencyKey === undefined ? {} : { idempotencyKey }),
|
|
27
|
+
...(subject === undefined ? {} : { subject }),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async cancel(id) {
|
|
31
|
+
if ((await this.find(id)) === undefined) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return this.options.store.cancel(id, this.options.clock.now());
|
|
35
|
+
}
|
|
36
|
+
async find(id) {
|
|
37
|
+
const job = await this.options.store.find(id);
|
|
38
|
+
return job !== undefined && isInReach(job, this.options.scope.current()) ? job : undefined;
|
|
39
|
+
}
|
|
40
|
+
/** Outside of any execution scope (a script, a test), the job acts as itself, under a correlation of its own. */
|
|
41
|
+
enqueuedBy(name) {
|
|
42
|
+
const context = this.options.scope.current();
|
|
43
|
+
const traceparent = this.options.traceparent?.();
|
|
44
|
+
const traced = traceparent === undefined ? {} : { traceparent };
|
|
45
|
+
if (context === undefined) {
|
|
46
|
+
return { correlationId: this.options.ids.next(), actor: systemActor(name), ...traced };
|
|
47
|
+
}
|
|
48
|
+
const { correlationId, actor, tenantId } = context;
|
|
49
|
+
return { correlationId, actor, ...(tenantId === undefined ? {} : { tenantId }), ...traced };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function isInReach(job, context) {
|
|
53
|
+
const elevated = context?.elevation?.tenants;
|
|
54
|
+
if (elevated !== undefined) {
|
|
55
|
+
return elevated === 'all' || (job.tenantId !== undefined && elevated.includes(job.tenantId));
|
|
56
|
+
}
|
|
57
|
+
return context?.tenantId === undefined || job.tenantId === context.tenantId;
|
|
58
|
+
}
|
|
59
|
+
function nameOf(job) {
|
|
60
|
+
if (!isJobName(job.jobName)) {
|
|
61
|
+
throw InvalidEnqueueError.unnamed(job.jobName);
|
|
62
|
+
}
|
|
63
|
+
return job.jobName;
|
|
64
|
+
}
|
|
65
|
+
/** The queue of a job is its context: the first part of its name. */
|
|
66
|
+
function queueOf(name) {
|
|
67
|
+
return name.split('.', 1).join('');
|
|
68
|
+
}
|
|
69
|
+
function runAtOf({ delay, runAt }, now) {
|
|
70
|
+
if (delay !== undefined && runAt !== undefined) {
|
|
71
|
+
throw InvalidEnqueueError.twoInstants();
|
|
72
|
+
}
|
|
73
|
+
if (delay !== undefined) {
|
|
74
|
+
return new Date(now.getTime() + parseDuration(delay));
|
|
75
|
+
}
|
|
76
|
+
return runAt ?? now;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=stored-job-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored-job-queue.js","sourceRoot":"","sources":["../../src/queue/stored-job-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,WAAW,GAWZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAaxE;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACI,OAAO;IAApC,YAA6B,OAA8B;uBAA9B,OAAO;IAA0B,CAAC;IAE/D,KAAK,CAAC,OAAO,CACX,GAA+B,EAC/B,OAAyB,EACzB,OAAO,GAAmB,EAAE;QAE5B,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5C,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAE5C,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAA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jD,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC;AAED,qEAAqE;AACrE,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAkB,EAAE,GAAS;IAC1D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/C,MAAM,mBAAmB,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,KAAK,IAAI,GAAG,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unless-aborted.d.ts","sourceRoot":"","sources":["../src/unless-aborted.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAYrF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A job that ignores its signal is left behind: the run ends when the signal is aborted, with its reason. */
|
|
2
|
+
export function unlessAborted(signal, work) {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
signal.addEventListener('abort', () => {
|
|
5
|
+
reject(reasonOf(signal));
|
|
6
|
+
}, { once: true });
|
|
7
|
+
work.then(resolve, reject);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function reasonOf(signal) {
|
|
11
|
+
const reason = signal.reason;
|
|
12
|
+
return reason instanceof Error ? reason : new Error('The run was aborted.');
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=unless-aborted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unless-aborted.js","sourceRoot":"","sources":["../src/unless-aborted.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,MAAM,UAAU,aAAa,CAAC,MAAmB,EAAE,IAAmB;IACpE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,gBAAgB,CACrB,OAAO,EACP,GAAG,EAAE;YACH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3B,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,MAAmB;IACnC,MAAM,MAAM,GAAY,MAAM,CAAC,MAAM,CAAC;IAEtC,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;AAC9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/scheduling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Scheduled jobs that only trigger use cases: interval and cron schedules, one run across instances, no overlap, each run in its own execution scope.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ddd-ts-kit/kernel": "0.
|
|
33
|
+
"@ddd-ts-kit/kernel": "0.11.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@ddd-ts-kit/testing": "0.
|
|
36
|
+
"@ddd-ts-kit/testing": "0.11.0"
|
|
37
37
|
}
|
|
38
38
|
}
|