@nestjs-pipeline/job-context 0.2.0 → 0.4.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 +11 -2
- package/dist/constants/job-context.constants.js +3 -6
- package/dist/constants/job-context.constants.js.map +1 -1
- package/dist/decorators/as-system.decorator.d.ts +1 -1
- package/dist/decorators/as-system.decorator.d.ts.map +1 -1
- package/dist/decorators/as-system.decorator.js +5 -8
- package/dist/decorators/as-system.decorator.js.map +1 -1
- package/dist/decorators/in-job-context.decorator.js +5 -8
- package/dist/decorators/in-job-context.decorator.js.map +1 -1
- package/dist/errors/invalid-job-context.error.d.ts.map +1 -1
- package/dist/errors/invalid-job-context.error.js +1 -5
- package/dist/errors/invalid-job-context.error.js.map +1 -1
- package/dist/errors/missing-job-context.error.d.ts.map +1 -1
- package/dist/errors/missing-job-context.error.js +1 -5
- package/dist/errors/missing-job-context.error.js.map +1 -1
- package/dist/helpers/parse-job-context.d.ts +1 -1
- package/dist/helpers/parse-job-context.d.ts.map +1 -1
- package/dist/helpers/parse-job-context.js +12 -15
- package/dist/helpers/parse-job-context.js.map +1 -1
- package/dist/helpers/principal-reference.d.ts +1 -1
- package/dist/helpers/principal-reference.d.ts.map +1 -1
- package/dist/helpers/principal-reference.js +1 -4
- package/dist/helpers/principal-reference.js.map +1 -1
- package/dist/helpers/registration.d.ts +2 -2
- package/dist/helpers/registration.d.ts.map +1 -1
- package/dist/helpers/registration.js +5 -10
- package/dist/helpers/registration.js.map +1 -1
- package/dist/helpers/with-job-context.d.ts +1 -1
- package/dist/helpers/with-job-context.d.ts.map +1 -1
- package/dist/helpers/with-job-context.js +8 -11
- package/dist/helpers/with-job-context.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -15
- package/dist/index.js.map +1 -1
- package/dist/interfaces/context-source.interface.js +1 -2
- package/dist/interfaces/context-source.interface.js.map +1 -1
- package/dist/interfaces/job-context-options.interface.d.ts +7 -3
- package/dist/interfaces/job-context-options.interface.d.ts.map +1 -1
- package/dist/interfaces/job-context-options.interface.js +1 -2
- package/dist/interfaces/job-context-options.interface.js.map +1 -1
- package/dist/interfaces/job-context.interface.d.ts +1 -1
- package/dist/interfaces/job-context.interface.d.ts.map +1 -1
- package/dist/interfaces/job-context.interface.js +1 -2
- package/dist/interfaces/job-context.interface.js.map +1 -1
- package/dist/interfaces/job-principal.interface.d.ts +1 -1
- package/dist/interfaces/job-principal.interface.d.ts.map +1 -1
- package/dist/interfaces/job-principal.interface.js +1 -2
- package/dist/interfaces/job-principal.interface.js.map +1 -1
- package/dist/interfaces/principal-reference.interface.js +1 -2
- package/dist/interfaces/principal-reference.interface.js.map +1 -1
- package/dist/job-context.module.d.ts +4 -3
- package/dist/job-context.module.d.ts.map +1 -1
- package/dist/job-context.module.js +27 -23
- package/dist/job-context.module.js.map +1 -1
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -21,7 +21,10 @@ so pipelines a job dispatches get the same tenant and correlation id.
|
|
|
21
21
|
pnpm add @nestjs-pipeline/job-context @nestjs/common
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Requires Node.js 22 or later.
|
|
24
|
+
Requires Node.js 22.12 or later and `@nestjs/common` `^12.1.0`.
|
|
25
|
+
|
|
26
|
+
Published as an ES module; a CommonJS application loads it with `require()`. Coming from
|
|
27
|
+
0.3.x, see [Upgrading from 0.3.x](https://github.com/aristoteliss/nestjs-pipeline#upgrading-from-03x).
|
|
25
28
|
|
|
26
29
|
## Setup
|
|
27
30
|
|
|
@@ -76,6 +79,12 @@ export class SessionJobPrincipal implements IJobPrincipal<Capability> {
|
|
|
76
79
|
export class JobsModule {}
|
|
77
80
|
```
|
|
78
81
|
|
|
82
|
+
`tenants` is a list, or a function that returns one. A function is called once, when the
|
|
83
|
+
application builds the module's providers, so the list can come from configuration read
|
|
84
|
+
at startup (`tenants: () => config().tenants`) instead of when the module file is
|
|
85
|
+
imported. An empty list throws: a list in `forRoot`, a function when the application
|
|
86
|
+
starts.
|
|
87
|
+
|
|
79
88
|
`capture` reads the current principal when a job is enqueued; only its `id`, `type` and
|
|
80
89
|
`sessionId` are kept. `restore` runs when the job does, inside the job's tenant and
|
|
81
90
|
correlation id: it must re-check the principal against current state, bind it the way a
|
|
@@ -196,7 +205,7 @@ The tenant must be one of the configured tenants.
|
|
|
196
205
|
| `withJobContext(data)` | function | Copies `data` and adds the current `jobContext` |
|
|
197
206
|
| `InJobContext(options?)` | decorator | Runs a job method in its payload's context; `path` defaults to `'data.jobContext'` |
|
|
198
207
|
| `AsSystem(options)` | decorator | Runs system work once per tenant as the declared principal and grants |
|
|
199
|
-
| `JobContextModule.forRoot(options)` | module | Registers `principal` (a class), `tenants
|
|
208
|
+
| `JobContextModule.forRoot(options)` | module | Registers `principal` (a class), `tenants` (a list, or a function called at startup), `sources` and optional `imports` |
|
|
200
209
|
| `ContextSource`, `CorrelationSource`, `JobContextSources` | type | `{ current, run }`; the correlation source adds `create()` and `accepts(id)`; and the `{ tenantId, correlationId }` pair `sources` takes |
|
|
201
210
|
| `IJobPrincipal<TGrant>` | interface | Application port: `capture()` and `restore(principal, work, grants?)` |
|
|
202
211
|
| `PrincipalReference` | type | `{ id, type, sessionId? }` |
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.JOB_SOURCES = exports.JOB_TENANTS = exports.JOB_PRINCIPAL = void 0;
|
|
5
2
|
/** Injection token of the application's `IJobPrincipal`. */
|
|
6
|
-
|
|
3
|
+
export const JOB_PRINCIPAL = Symbol('JOB_PRINCIPAL');
|
|
7
4
|
/** Injection token of the configured tenant list. */
|
|
8
|
-
|
|
5
|
+
export const JOB_TENANTS = Symbol('JOB_TENANTS');
|
|
9
6
|
/** Injection token of the tenant and correlation id sources. */
|
|
10
|
-
|
|
7
|
+
export const JOB_SOURCES = Symbol('JOB_SOURCES');
|
|
11
8
|
//# sourceMappingURL=job-context.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context.constants.js","sourceRoot":"","sources":["../../src/constants/job-context.constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-context.constants.js","sourceRoot":"","sources":["../../src/constants/job-context.constants.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAErD,qDAAqD;AACrD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAEjD,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrincipalReference } from '../interfaces/principal-reference.interface';
|
|
1
|
+
import type { PrincipalReference } from '../interfaces/principal-reference.interface.js';
|
|
2
2
|
/** Options of {@link AsSystem}. */
|
|
3
3
|
export interface AsSystemOptions<TGrant = unknown> {
|
|
4
4
|
/** The service principal the work acts as. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"as-system.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/as-system.decorator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"as-system.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/as-system.decorator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAEzF,mCAAmC;AACnC,MAAM,WAAW,eAAe,CAAC,MAAM,GAAG,OAAO;IAC/C,8CAA8C;IAC9C,SAAS,EAAE,kBAAkB,CAAC;IAC9B,+EAA+E;IAC/E,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAC7B,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,GAC/B,eAAe,CA2CjB"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const principal_reference_1 = require("../helpers/principal-reference");
|
|
6
|
-
const registration_1 = require("../helpers/registration");
|
|
2
|
+
import { toReference } from '../helpers/principal-reference.js';
|
|
3
|
+
import { activeRegistration } from '../helpers/registration.js';
|
|
7
4
|
/**
|
|
8
5
|
* Runs system-started work, such as a cron job, once per configured tenant.
|
|
9
6
|
* Each run has its own tenant, a new correlation id, and the declared service
|
|
@@ -26,13 +23,13 @@ const registration_1 = require("../helpers/registration");
|
|
|
26
23
|
* }
|
|
27
24
|
* ```
|
|
28
25
|
*/
|
|
29
|
-
function AsSystem(options) {
|
|
30
|
-
const reference =
|
|
26
|
+
export function AsSystem(options) {
|
|
27
|
+
const reference = toReference(options.principal);
|
|
31
28
|
const grants = [...options.grants];
|
|
32
29
|
return (_target, _propertyKey, descriptor) => {
|
|
33
30
|
const original = descriptor.value;
|
|
34
31
|
descriptor.value = async function (...args) {
|
|
35
|
-
const { principal, tenants, sources } =
|
|
32
|
+
const { principal, tenants, sources } = activeRegistration();
|
|
36
33
|
const failures = [];
|
|
37
34
|
const failed = [];
|
|
38
35
|
for (const tenant of tenants) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"as-system.decorator.js","sourceRoot":"","sources":["../../src/decorators/as-system.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"as-system.decorator.js","sourceRoot":"","sources":["../../src/decorators/as-system.decorator.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAWhE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAgC;IAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,UAA8B,EAAE,EAAE;QAC/D,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAwC,CAAC;QAErE,UAAU,CAAC,KAAK,GAAG,KAAK,WAEtB,GAAG,IAAe;YAElB,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;YAC7D,MAAM,QAAQ,GAAc,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CACtC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAC7D,SAAS,CAAC,OAAO,CACf,SAAS,EACT,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EACtC,MAAM,CACP,CACF,CACF,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,IAAI,cAAc,CACtB,QAAQ,EACR,kCAAkC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACtD,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE;YAC9C,KAAK,EAAE,QAAQ,CAAC,IAAI;YACpB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const parse_job_context_1 = require("../helpers/parse-job-context");
|
|
6
|
-
const registration_1 = require("../helpers/registration");
|
|
2
|
+
import { parseJobContext } from '../helpers/parse-job-context.js';
|
|
3
|
+
import { activeRegistration } from '../helpers/registration.js';
|
|
7
4
|
function readPath(value, segments) {
|
|
8
5
|
let current = value;
|
|
9
6
|
for (const segment of segments) {
|
|
@@ -34,13 +31,13 @@ function readPath(value, segments) {
|
|
|
34
31
|
* }
|
|
35
32
|
* ```
|
|
36
33
|
*/
|
|
37
|
-
function InJobContext(options = {}) {
|
|
34
|
+
export function InJobContext(options = {}) {
|
|
38
35
|
const segments = (options.path ?? 'data.jobContext').split('.');
|
|
39
36
|
return (_target, _propertyKey, descriptor) => {
|
|
40
37
|
const original = descriptor.value;
|
|
41
38
|
descriptor.value = async function (...args) {
|
|
42
|
-
const { principal, tenants, sources } =
|
|
43
|
-
const context =
|
|
39
|
+
const { principal, tenants, sources } = activeRegistration();
|
|
40
|
+
const context = parseJobContext(readPath(args[0], segments), tenants, sources.correlationId.accepts);
|
|
44
41
|
return sources.tenantId.run(context.tenantId, () => sources.correlationId.run(context.correlationId, () => principal.restore(context.principal, async () => original.apply(this, args))));
|
|
45
42
|
};
|
|
46
43
|
Object.defineProperty(descriptor.value, 'name', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-job-context.decorator.js","sourceRoot":"","sources":["../../src/decorators/in-job-context.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"in-job-context.decorator.js","sourceRoot":"","sources":["../../src/decorators/in-job-context.decorator.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAYhE,SAAS,QAAQ,CAAC,KAAc,EAAE,QAA2B;IAC3D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QACtE,OAAO,GAAI,OAAmC,CAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAO,GAAwB,EAAE;IAEjC,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,iBAAiB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAEhE,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,UAA8B,EAAE,EAAE;QAC/D,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAwC,CAAC;QAErE,UAAU,CAAC,KAAK,GAAG,KAAK,WAA0B,GAAG,IAAe;YAClE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAG,eAAe,CAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAC3B,OAAO,EACP,OAAO,CAAC,aAAa,CAAC,OAAO,CAC9B,CAAC;YACF,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,CACjD,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,EAAE,CACpD,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,CAC9C,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAC3B,CACF,CACF,CAAC;QACJ,CAAC,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE;YAC9C,KAAK,EAAE,QAAQ,CAAC,IAAI;YACpB,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalid-job-context.error.d.ts","sourceRoot":"","sources":["../../src/errors/invalid-job-context.error.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"invalid-job-context.error.d.ts","sourceRoot":"","sources":["../../src/errors/invalid-job-context.error.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAnC,YAAqB,MAAM,EAAE,MAAM,EAGlC;CACF"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.InvalidJobContextError = void 0;
|
|
5
2
|
/**
|
|
6
3
|
* Raised when a job payload's context is malformed, names an unconfigured
|
|
7
4
|
* tenant, or carries fields a principal reference must not have, such as
|
|
@@ -12,7 +9,7 @@ exports.InvalidJobContextError = void 0;
|
|
|
12
9
|
* throw new InvalidJobContextError('tenantId is not a configured tenant');
|
|
13
10
|
* ```
|
|
14
11
|
*/
|
|
15
|
-
class InvalidJobContextError extends Error {
|
|
12
|
+
export class InvalidJobContextError extends Error {
|
|
16
13
|
reason;
|
|
17
14
|
constructor(reason) {
|
|
18
15
|
super(`Invalid job context: ${reason}.`);
|
|
@@ -20,5 +17,4 @@ class InvalidJobContextError extends Error {
|
|
|
20
17
|
this.name = InvalidJobContextError.name;
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.InvalidJobContextError = InvalidJobContextError;
|
|
24
20
|
//# sourceMappingURL=invalid-job-context.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invalid-job-context.error.js","sourceRoot":"","sources":["../../src/errors/invalid-job-context.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"invalid-job-context.error.js","sourceRoot":"","sources":["../../src/errors/invalid-job-context.error.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE;;;;;;;;;GASG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC1B,MAAM;IAA3B,YAAqB,MAAc;QACjC,KAAK,CAAC,wBAAwB,MAAM,GAAG,CAAC,CAAC;sBADtB,MAAM;QAEzB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing-job-context.error.d.ts","sourceRoot":"","sources":["../../src/errors/missing-job-context.error.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"missing-job-context.error.d.ts","sourceRoot":"","sources":["../../src/errors/missing-job-context.error.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAApC,YAAqB,OAAO,EAAE,MAAM,EAKnC;CACF"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.MissingJobContextError = void 0;
|
|
5
2
|
/**
|
|
6
3
|
* Raised when a job would run, or be enqueued, without part of its execution
|
|
7
4
|
* context. A job never falls back to a default tenant or an anonymous principal.
|
|
@@ -11,7 +8,7 @@ exports.MissingJobContextError = void 0;
|
|
|
11
8
|
* throw new MissingJobContextError('principal');
|
|
12
9
|
* ```
|
|
13
10
|
*/
|
|
14
|
-
class MissingJobContextError extends Error {
|
|
11
|
+
export class MissingJobContextError extends Error {
|
|
15
12
|
missing;
|
|
16
13
|
constructor(missing) {
|
|
17
14
|
super(`Missing job context: ${missing}. A job never runs without it and never falls back to a default.`);
|
|
@@ -19,5 +16,4 @@ class MissingJobContextError extends Error {
|
|
|
19
16
|
this.name = MissingJobContextError.name;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
exports.MissingJobContextError = MissingJobContextError;
|
|
23
19
|
//# sourceMappingURL=missing-job-context.error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"missing-job-context.error.js","sourceRoot":"","sources":["../../src/errors/missing-job-context.error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"missing-job-context.error.js","sourceRoot":"","sources":["../../src/errors/missing-job-context.error.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE;;;;;;;;GAQG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC1B,OAAO;IAA5B,YAAqB,OAAe;QAClC,KAAK,CACH,wBAAwB,OAAO,kEAAkE,CAClG,CAAC;uBAHiB,OAAO;QAI1B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAC1C,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JobContext } from '../interfaces/job-context.interface';
|
|
1
|
+
import type { JobContext } from '../interfaces/job-context.interface.js';
|
|
2
2
|
/**
|
|
3
3
|
* Validates a job payload's context before anything runs with it. Every field
|
|
4
4
|
* is checked, unknown fields are refused, the tenant must be configured, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-job-context.d.ts","sourceRoot":"","sources":["../../src/helpers/parse-job-context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"parse-job-context.d.ts","sourceRoot":"","sources":["../../src/helpers/parse-job-context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AAyBzE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,GAC5C,UAAU,CAmCZ"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const missing_job_context_error_1 = require("../errors/missing-job-context.error");
|
|
7
|
-
const principal_reference_1 = require("./principal-reference");
|
|
2
|
+
import { InvalidJobContextError } from '../errors/invalid-job-context.error.js';
|
|
3
|
+
import { MissingJobContextError } from '../errors/missing-job-context.error.js';
|
|
4
|
+
import { toReference } from './principal-reference.js';
|
|
8
5
|
const CONTEXT_FIELDS = new Set(['tenantId', 'correlationId', 'principal']);
|
|
9
6
|
const PRINCIPAL_FIELDS = new Set(['id', 'type', 'sessionId']);
|
|
10
7
|
function isRecord(value) {
|
|
@@ -16,7 +13,7 @@ function isText(value) {
|
|
|
16
13
|
function assertFields(value, allowed, name) {
|
|
17
14
|
const extra = Object.keys(value).find((key) => !allowed.has(key));
|
|
18
15
|
if (extra !== undefined) {
|
|
19
|
-
throw new
|
|
16
|
+
throw new InvalidJobContextError(`${name} carries the field "${extra}"`);
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
@@ -36,36 +33,36 @@ function assertFields(value, allowed, name) {
|
|
|
36
33
|
* const context = parseJobContext(job.data.jobContext, ['tenant_a'], sources.correlationId.accepts);
|
|
37
34
|
* ```
|
|
38
35
|
*/
|
|
39
|
-
function parseJobContext(value, tenants, acceptsCorrelationId) {
|
|
36
|
+
export function parseJobContext(value, tenants, acceptsCorrelationId) {
|
|
40
37
|
if (value === undefined) {
|
|
41
|
-
throw new
|
|
38
|
+
throw new MissingJobContextError('the payload has no jobContext');
|
|
42
39
|
}
|
|
43
40
|
if (!isRecord(value)) {
|
|
44
|
-
throw new
|
|
41
|
+
throw new InvalidJobContextError('jobContext is not an object');
|
|
45
42
|
}
|
|
46
43
|
assertFields(value, CONTEXT_FIELDS, 'jobContext');
|
|
47
44
|
const { tenantId, correlationId, principal } = value;
|
|
48
45
|
if (typeof tenantId !== 'string' || !tenants.includes(tenantId)) {
|
|
49
|
-
throw new
|
|
46
|
+
throw new InvalidJobContextError('tenantId is not a configured tenant');
|
|
50
47
|
}
|
|
51
48
|
if (typeof correlationId !== 'string' ||
|
|
52
49
|
!acceptsCorrelationId(correlationId)) {
|
|
53
|
-
throw new
|
|
50
|
+
throw new InvalidJobContextError('correlationId is malformed');
|
|
54
51
|
}
|
|
55
52
|
if (!isRecord(principal)) {
|
|
56
|
-
throw new
|
|
53
|
+
throw new InvalidJobContextError('principal is not an object');
|
|
57
54
|
}
|
|
58
55
|
assertFields(principal, PRINCIPAL_FIELDS, 'principal');
|
|
59
56
|
const { id, type, sessionId } = principal;
|
|
60
57
|
if (!isText(id) ||
|
|
61
58
|
!isText(type) ||
|
|
62
59
|
(sessionId !== undefined && !isText(sessionId))) {
|
|
63
|
-
throw new
|
|
60
|
+
throw new InvalidJobContextError('principal is malformed');
|
|
64
61
|
}
|
|
65
62
|
return {
|
|
66
63
|
tenantId,
|
|
67
64
|
correlationId,
|
|
68
|
-
principal:
|
|
65
|
+
principal: toReference({ id, type, sessionId }),
|
|
69
66
|
};
|
|
70
67
|
}
|
|
71
68
|
//# sourceMappingURL=parse-job-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-job-context.js","sourceRoot":"","sources":["../../src/helpers/parse-job-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-job-context.js","sourceRoot":"","sources":["../../src/helpers/parse-job-context.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC;AAC3E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAE9D,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAC1D,CAAC;AAED,SAAS,YAAY,CACnB,KAA8B,EAC9B,OAA4B,EAC5B,IAAY;IAEZ,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAClE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,sBAAsB,CAAC,GAAG,IAAI,uBAAuB,KAAK,GAAG,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,OAA0B,EAC1B,oBAA6C;IAE7C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,sBAAsB,CAAC,+BAA+B,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,sBAAsB,CAAC,6BAA6B,CAAC,CAAC;IAClE,CAAC;IACD,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACrD,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,sBAAsB,CAAC,qCAAqC,CAAC,CAAC;IAC1E,CAAC;IACD,IACE,OAAO,aAAa,KAAK,QAAQ;QACjC,CAAC,oBAAoB,CAAC,aAAa,CAAC,EACpC,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC,4BAA4B,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,sBAAsB,CAAC,4BAA4B,CAAC,CAAC;IACjE,CAAC;IACD,YAAY,CAAC,SAAS,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC;IACvD,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IAC1C,IACE,CAAC,MAAM,CAAC,EAAE,CAAC;QACX,CAAC,MAAM,CAAC,IAAI,CAAC;QACb,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,EAC/C,CAAC;QACD,MAAM,IAAI,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO;QACL,QAAQ;QACR,aAAa;QACb,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrincipalReference } from '../interfaces/principal-reference.interface';
|
|
1
|
+
import type { PrincipalReference } from '../interfaces/principal-reference.interface.js';
|
|
2
2
|
/**
|
|
3
3
|
* Copies only the identity fields of `principal`, so grants or session data an
|
|
4
4
|
* application object also holds never reach a payload or a restore call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal-reference.d.ts","sourceRoot":"","sources":["../../src/helpers/principal-reference.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"principal-reference.d.ts","sourceRoot":"","sources":["../../src/helpers/principal-reference.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AAEzF;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,kBAAkB,GAAG,kBAAkB,CAG7E"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.toReference = toReference;
|
|
5
2
|
/**
|
|
6
3
|
* Copies only the identity fields of `principal`, so grants or session data an
|
|
7
4
|
* application object also holds never reach a payload or a restore call.
|
|
@@ -11,7 +8,7 @@ exports.toReference = toReference;
|
|
|
11
8
|
* toReference({ id: 'u-1', type: 'user', sid: 's-1', grants: [] }); // { id: 'u-1', type: 'user' }
|
|
12
9
|
* ```
|
|
13
10
|
*/
|
|
14
|
-
function toReference(principal) {
|
|
11
|
+
export function toReference(principal) {
|
|
15
12
|
const { id, type, sessionId } = principal;
|
|
16
13
|
return sessionId === undefined ? { id, type } : { id, type, sessionId };
|
|
17
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal-reference.js","sourceRoot":"","sources":["../../src/helpers/principal-reference.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"principal-reference.js","sourceRoot":"","sources":["../../src/helpers/principal-reference.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAItE;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,SAA6B;IACvD,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IAC1C,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JobContextSources } from '../interfaces/context-source.interface';
|
|
2
|
-
import type { IJobPrincipal } from '../interfaces/job-principal.interface';
|
|
1
|
+
import type { JobContextSources } from '../interfaces/context-source.interface.js';
|
|
2
|
+
import type { IJobPrincipal } from '../interfaces/job-principal.interface.js';
|
|
3
3
|
/** What `JobContextModule` registers for the decorators, which run outside DI. */
|
|
4
4
|
export interface Registration {
|
|
5
5
|
readonly principal: IJobPrincipal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/helpers/registration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"registration.d.ts","sourceRoot":"","sources":["../../src/helpers/registration.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAE9E,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AAID;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAEzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,IAAI,YAAY,CAKjD"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
exports.register = register;
|
|
5
|
-
exports.unregister = unregister;
|
|
6
|
-
exports.activeRegistration = activeRegistration;
|
|
7
|
-
const missing_job_context_error_1 = require("../errors/missing-job-context.error");
|
|
2
|
+
import { MissingJobContextError } from '../errors/missing-job-context.error.js';
|
|
8
3
|
let active;
|
|
9
4
|
/**
|
|
10
5
|
* Makes `registration` the one the decorators and `withJobContext` use.
|
|
@@ -14,7 +9,7 @@ let active;
|
|
|
14
9
|
* register({ principal, tenants: ['tenant_a'], sources });
|
|
15
10
|
* ```
|
|
16
11
|
*/
|
|
17
|
-
function register(registration) {
|
|
12
|
+
export function register(registration) {
|
|
18
13
|
active = registration;
|
|
19
14
|
}
|
|
20
15
|
/**
|
|
@@ -26,7 +21,7 @@ function register(registration) {
|
|
|
26
21
|
* unregister(registration);
|
|
27
22
|
* ```
|
|
28
23
|
*/
|
|
29
|
-
function unregister(registration) {
|
|
24
|
+
export function unregister(registration) {
|
|
30
25
|
if (active === registration)
|
|
31
26
|
active = undefined;
|
|
32
27
|
}
|
|
@@ -40,9 +35,9 @@ function unregister(registration) {
|
|
|
40
35
|
* const { principal, tenants, sources } = activeRegistration();
|
|
41
36
|
* ```
|
|
42
37
|
*/
|
|
43
|
-
function activeRegistration() {
|
|
38
|
+
export function activeRegistration() {
|
|
44
39
|
if (active === undefined) {
|
|
45
|
-
throw new
|
|
40
|
+
throw new MissingJobContextError('a running JobContextModule');
|
|
46
41
|
}
|
|
47
42
|
return active;
|
|
48
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/helpers/registration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registration.js","sourceRoot":"","sources":["../../src/helpers/registration.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAWhF,IAAI,MAAgC,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,YAA0B;IACjD,MAAM,GAAG,YAAY,CAAC;AACxB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,YAA0B;IACnD,IAAI,MAAM,KAAK,YAAY;QAAE,MAAM,GAAG,SAAS,CAAC;AAClD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,sBAAsB,CAAC,4BAA4B,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WithJobContext } from '../interfaces/job-context.interface';
|
|
1
|
+
import type { WithJobContext } from '../interfaces/job-context.interface.js';
|
|
2
2
|
/**
|
|
3
3
|
* Stamps the current execution context onto a job payload: the tenant and
|
|
4
4
|
* correlation id of the registered sources (a new one from the correlation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-job-context.d.ts","sourceRoot":"","sources":["../../src/helpers/with-job-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"with-job-context.d.ts","sourceRoot":"","sources":["../../src/helpers/with-job-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAI7E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,IAAI,EAAE,CAAC,GACN,cAAc,CAAC,CAAC,CAAC,CAwBnB"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const principal_reference_1 = require("./principal-reference");
|
|
7
|
-
const registration_1 = require("./registration");
|
|
2
|
+
import { MissingJobContextError } from '../errors/missing-job-context.error.js';
|
|
3
|
+
import { toReference } from './principal-reference.js';
|
|
4
|
+
import { activeRegistration } from './registration.js';
|
|
8
5
|
/**
|
|
9
6
|
* Stamps the current execution context onto a job payload: the tenant and
|
|
10
7
|
* correlation id of the registered sources (a new one from the correlation
|
|
@@ -23,26 +20,26 @@ const registration_1 = require("./registration");
|
|
|
23
20
|
* await queue.add('send', withJobContext({ userId, email }));
|
|
24
21
|
* ```
|
|
25
22
|
*/
|
|
26
|
-
function withJobContext(data) {
|
|
23
|
+
export function withJobContext(data) {
|
|
27
24
|
const prototype = data !== null && typeof data === 'object'
|
|
28
25
|
? Object.getPrototypeOf(data)
|
|
29
26
|
: undefined;
|
|
30
27
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
31
28
|
throw new TypeError('withJobContext(data) requires a plain object payload. Wrap arrays and class instances in a plain object first.');
|
|
32
29
|
}
|
|
33
|
-
const { principal, sources } =
|
|
30
|
+
const { principal, sources } = activeRegistration();
|
|
34
31
|
const tenantId = sources.tenantId.current();
|
|
35
32
|
if (tenantId === undefined)
|
|
36
|
-
throw new
|
|
33
|
+
throw new MissingJobContextError('tenant');
|
|
37
34
|
const captured = principal.capture();
|
|
38
35
|
if (captured === undefined)
|
|
39
|
-
throw new
|
|
36
|
+
throw new MissingJobContextError('principal');
|
|
40
37
|
return {
|
|
41
38
|
...data,
|
|
42
39
|
jobContext: {
|
|
43
40
|
tenantId,
|
|
44
41
|
correlationId: sources.correlationId.current() ?? sources.correlationId.create(),
|
|
45
|
-
principal:
|
|
42
|
+
principal: toReference(captured),
|
|
46
43
|
},
|
|
47
44
|
};
|
|
48
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-job-context.js","sourceRoot":"","sources":["../../src/helpers/with-job-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"with-job-context.js","sourceRoot":"","sources":["../../src/helpers/with-job-context.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAO;IAEP,MAAM,SAAS,GACb,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QACvC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC;QAC7B,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACzD,MAAM,IAAI,SAAS,CACjB,gHAAgH,CACjH,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,CAAC;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5C,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,IAAI,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACrC,IAAI,QAAQ,KAAK,SAAS;QAAE,MAAM,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC1E,OAAO;QACL,GAAG,IAAI;QACP,UAAU,EAAE;YACV,QAAQ;YACR,aAAa,EACX,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE;YACnE,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC;SACjC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { AsSystem, type AsSystemOptions, } from './decorators/as-system.decorator';
|
|
2
|
-
export { InJobContext, type InJobContextOptions, } from './decorators/in-job-context.decorator';
|
|
3
|
-
export { InvalidJobContextError } from './errors/invalid-job-context.error';
|
|
4
|
-
export { MissingJobContextError } from './errors/missing-job-context.error';
|
|
5
|
-
export { withJobContext } from './helpers/with-job-context';
|
|
6
|
-
export type { ContextSource, CorrelationSource, JobContextSources, } from './interfaces/context-source.interface';
|
|
7
|
-
export type { JobContext, WithJobContext, } from './interfaces/job-context.interface';
|
|
8
|
-
export type { JobContextOptions } from './interfaces/job-context-options.interface';
|
|
9
|
-
export type { IJobPrincipal } from './interfaces/job-principal.interface';
|
|
10
|
-
export type { PrincipalReference } from './interfaces/principal-reference.interface';
|
|
11
|
-
export { JobContextModule } from './job-context.module';
|
|
1
|
+
export { AsSystem, type AsSystemOptions, } from './decorators/as-system.decorator.js';
|
|
2
|
+
export { InJobContext, type InJobContextOptions, } from './decorators/in-job-context.decorator.js';
|
|
3
|
+
export { InvalidJobContextError } from './errors/invalid-job-context.error.js';
|
|
4
|
+
export { MissingJobContextError } from './errors/missing-job-context.error.js';
|
|
5
|
+
export { withJobContext } from './helpers/with-job-context.js';
|
|
6
|
+
export type { ContextSource, CorrelationSource, JobContextSources, } from './interfaces/context-source.interface.js';
|
|
7
|
+
export type { JobContext, WithJobContext, } from './interfaces/job-context.interface.js';
|
|
8
|
+
export type { JobContextOptions } from './interfaces/job-context-options.interface.js';
|
|
9
|
+
export type { IJobPrincipal } from './interfaces/job-principal.interface.js';
|
|
10
|
+
export type { PrincipalReference } from './interfaces/principal-reference.interface.js';
|
|
11
|
+
export { JobContextModule } from './job-context.module.js';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,GACrB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,GACrB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,KAAK,mBAAmB,GACzB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,0CAA0C,CAAC;AAClD,YAAY,EACV,UAAU,EACV,cAAc,GACf,MAAM,uCAAuC,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,YAAY,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var invalid_job_context_error_1 = require("./errors/invalid-job-context.error");
|
|
10
|
-
Object.defineProperty(exports, "InvalidJobContextError", { enumerable: true, get: function () { return invalid_job_context_error_1.InvalidJobContextError; } });
|
|
11
|
-
var missing_job_context_error_1 = require("./errors/missing-job-context.error");
|
|
12
|
-
Object.defineProperty(exports, "MissingJobContextError", { enumerable: true, get: function () { return missing_job_context_error_1.MissingJobContextError; } });
|
|
13
|
-
var with_job_context_1 = require("./helpers/with-job-context");
|
|
14
|
-
Object.defineProperty(exports, "withJobContext", { enumerable: true, get: function () { return with_job_context_1.withJobContext; } });
|
|
15
|
-
var job_context_module_1 = require("./job-context.module");
|
|
16
|
-
Object.defineProperty(exports, "JobContextModule", { enumerable: true, get: function () { return job_context_module_1.JobContextModule; } });
|
|
2
|
+
export { AsSystem, } from './decorators/as-system.decorator.js';
|
|
3
|
+
export { InJobContext, } from './decorators/in-job-context.decorator.js';
|
|
4
|
+
export { InvalidJobContextError } from './errors/invalid-job-context.error.js';
|
|
5
|
+
export { MissingJobContextError } from './errors/missing-job-context.error.js';
|
|
6
|
+
export { withJobContext } from './helpers/with-job-context.js';
|
|
7
|
+
export { JobContextModule } from './job-context.module.js';
|
|
17
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,OAAO,EACL,QAAQ,GAET,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,YAAY,GAEb,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAa/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-source.interface.js","sourceRoot":"","sources":["../../src/interfaces/context-source.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context-source.interface.js","sourceRoot":"","sources":["../../src/interfaces/context-source.interface.ts"],"names":[],"mappings":"AAAA,sEAAsE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
-
import type { JobContextSources } from './context-source.interface';
|
|
3
|
-
import type { IJobPrincipal } from './job-principal.interface';
|
|
2
|
+
import type { JobContextSources } from './context-source.interface.js';
|
|
3
|
+
import type { IJobPrincipal } from './job-principal.interface.js';
|
|
4
4
|
/** Options of `JobContextModule.forRoot`. */
|
|
5
5
|
export interface JobContextOptions {
|
|
6
6
|
/** The application's principal port, instantiated through dependency injection. */
|
|
@@ -8,8 +8,12 @@ export interface JobContextOptions {
|
|
|
8
8
|
/**
|
|
9
9
|
* Tenants a job may run in. A payload naming another tenant is refused, and
|
|
10
10
|
* `@AsSystem` work runs once per tenant, in this order. Must not be empty.
|
|
11
|
+
*
|
|
12
|
+
* A function is called once, when the application builds the module's
|
|
13
|
+
* providers, so the list can come from configuration read at startup
|
|
14
|
+
* instead of when the module file is imported.
|
|
11
15
|
*/
|
|
12
|
-
tenants: readonly string[];
|
|
16
|
+
tenants: readonly string[] | (() => readonly string[]);
|
|
13
17
|
/**
|
|
14
18
|
* Where the tenant and correlation id are read when a job is enqueued and
|
|
15
19
|
* restored when it runs, such as `tenantSource` of `@nestjs-pipeline/tenant`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-context-options.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"job-context-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-context-options.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/B;;;;;;;OAOG;IACH,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,MAAM,SAAS,MAAM,EAAE,CAAC,CAAC;IACvD;;;;OAIG;IACH,OAAO,EAAE,iBAAiB,CAAC;IAC3B,2DAA2D;IAC3D,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;CACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-context-options.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-context-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-context-options.interface.ts"],"names":[],"mappings":"AAAA,sEAAsE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrincipalReference } from './principal-reference.interface';
|
|
1
|
+
import type { PrincipalReference } from './principal-reference.interface.js';
|
|
2
2
|
/** Execution context a job payload carries from the request that enqueued it. */
|
|
3
3
|
export interface JobContext {
|
|
4
4
|
readonly tenantId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-context.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"job-context.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-context.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,kBAAkB,CAAC;CACxC;AAED,iDAAiD;AACjD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;IAClE,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-context.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-context.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-context.interface.ts"],"names":[],"mappings":"AAAA,sEAAsE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrincipalReference } from './principal-reference.interface';
|
|
1
|
+
import type { PrincipalReference } from './principal-reference.interface.js';
|
|
2
2
|
/**
|
|
3
3
|
* Application port that reads the current principal when a job is enqueued and
|
|
4
4
|
* binds it again when the job runs. The application implements it over its own
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-principal.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-principal.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"job-principal.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/job-principal.interface.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,MAAM,GAAG,OAAO;IAC7C;;;OAGG;IACH,OAAO,IAAI,kBAAkB,GAAG,SAAS,CAAC;IAE1C;;;;;;;;;OASG;IACH,OAAO,CAAC,CAAC,EACP,SAAS,EAAE,kBAAkB,EAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GACzB,OAAO,CAAC,CAAC,CAAC,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-principal.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-principal.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-principal.interface.js","sourceRoot":"","sources":["../../src/interfaces/job-principal.interface.ts"],"names":[],"mappings":"AAAA,sEAAsE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principal-reference.interface.js","sourceRoot":"","sources":["../../src/interfaces/principal-reference.interface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"principal-reference.interface.js","sourceRoot":"","sources":["../../src/interfaces/principal-reference.interface.ts"],"names":[],"mappings":"AAAA,sEAAsE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
-
import type { JobContextOptions } from './interfaces/job-context-options.interface';
|
|
2
|
+
import type { JobContextOptions } from './interfaces/job-context-options.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* Connects `withJobContext`, `@InJobContext` and `@AsSystem` to the
|
|
5
5
|
* application's principal port, tenant list, and tenant and correlation id
|
|
@@ -26,13 +26,14 @@ export declare class JobContextModule {
|
|
|
26
26
|
/**
|
|
27
27
|
* Builds the module for `options`.
|
|
28
28
|
*
|
|
29
|
-
* @throws {TypeError} When `options.tenants` is empty.
|
|
29
|
+
* @throws {TypeError} When `options.tenants` is an empty list. A tenant
|
|
30
|
+
* function that returns an empty list throws when the application starts.
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
32
33
|
* ```ts
|
|
33
34
|
* JobContextModule.forRoot({
|
|
34
35
|
* principal: SessionJobPrincipal,
|
|
35
|
-
* tenants:
|
|
36
|
+
* tenants: () => persistenceConfig().tenants,
|
|
36
37
|
* sources: { tenantId: tenantSource, correlationId: correlationSource },
|
|
37
38
|
* });
|
|
38
39
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context.module.d.ts","sourceRoot":"","sources":["../src/job-context.module.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"job-context.module.d.ts","sourceRoot":"","sources":["../src/job-context.module.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,gBAAgB,CAAC;AAYxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AAyBvF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAcxD;CACF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* Copyright (C) 2026-present Aristotelis — see repository license. */
|
|
3
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
4
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -13,11 +12,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
14
13
|
};
|
|
15
14
|
var JobContextModule_1;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const job_context_constants_1 = require("./constants/job-context.constants");
|
|
20
|
-
const registration_1 = require("./helpers/registration");
|
|
15
|
+
import { Inject, Injectable, Module, } from '@nestjs/common';
|
|
16
|
+
import { JOB_PRINCIPAL, JOB_SOURCES, JOB_TENANTS, } from './constants/job-context.constants.js';
|
|
17
|
+
import { register, unregister, } from './helpers/registration.js';
|
|
21
18
|
/**
|
|
22
19
|
* Registers the principal port, tenants and sources when it is constructed, before any
|
|
23
20
|
* lifecycle hook can start a worker, and removes them at shutdown.
|
|
@@ -26,17 +23,17 @@ let JobContextRegistration = class JobContextRegistration {
|
|
|
26
23
|
registration;
|
|
27
24
|
constructor(principal, tenants, sources) {
|
|
28
25
|
this.registration = { principal, tenants, sources };
|
|
29
|
-
|
|
26
|
+
register(this.registration);
|
|
30
27
|
}
|
|
31
28
|
onApplicationShutdown() {
|
|
32
|
-
|
|
29
|
+
unregister(this.registration);
|
|
33
30
|
}
|
|
34
31
|
};
|
|
35
32
|
JobContextRegistration = __decorate([
|
|
36
|
-
|
|
37
|
-
__param(0,
|
|
38
|
-
__param(1,
|
|
39
|
-
__param(2,
|
|
33
|
+
Injectable(),
|
|
34
|
+
__param(0, Inject(JOB_PRINCIPAL)),
|
|
35
|
+
__param(1, Inject(JOB_TENANTS)),
|
|
36
|
+
__param(2, Inject(JOB_SOURCES)),
|
|
40
37
|
__metadata("design:paramtypes", [Object, Array, Object])
|
|
41
38
|
], JobContextRegistration);
|
|
42
39
|
/**
|
|
@@ -65,35 +62,42 @@ let JobContextModule = JobContextModule_1 = class JobContextModule {
|
|
|
65
62
|
/**
|
|
66
63
|
* Builds the module for `options`.
|
|
67
64
|
*
|
|
68
|
-
* @throws {TypeError} When `options.tenants` is empty.
|
|
65
|
+
* @throws {TypeError} When `options.tenants` is an empty list. A tenant
|
|
66
|
+
* function that returns an empty list throws when the application starts.
|
|
69
67
|
*
|
|
70
68
|
* @example
|
|
71
69
|
* ```ts
|
|
72
70
|
* JobContextModule.forRoot({
|
|
73
71
|
* principal: SessionJobPrincipal,
|
|
74
|
-
* tenants:
|
|
72
|
+
* tenants: () => persistenceConfig().tenants,
|
|
75
73
|
* sources: { tenantId: tenantSource, correlationId: correlationSource },
|
|
76
74
|
* });
|
|
77
75
|
* ```
|
|
78
76
|
*/
|
|
79
77
|
static forRoot(options) {
|
|
80
|
-
|
|
81
|
-
throw new TypeError('JobContextModule needs at least one tenant.');
|
|
82
|
-
}
|
|
78
|
+
const { tenants } = options;
|
|
83
79
|
return {
|
|
84
80
|
module: JobContextModule_1,
|
|
85
81
|
imports: options.imports ?? [],
|
|
86
82
|
providers: [
|
|
87
|
-
{ provide:
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
{ provide: JOB_PRINCIPAL, useClass: options.principal },
|
|
84
|
+
typeof tenants === 'function'
|
|
85
|
+
? { provide: JOB_TENANTS, useFactory: () => toTenantList(tenants()) }
|
|
86
|
+
: { provide: JOB_TENANTS, useValue: toTenantList(tenants) },
|
|
87
|
+
{ provide: JOB_SOURCES, useValue: options.sources },
|
|
90
88
|
JobContextRegistration,
|
|
91
89
|
],
|
|
92
90
|
};
|
|
93
91
|
}
|
|
94
92
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(0, common_1.Module)({})
|
|
93
|
+
JobContextModule = JobContextModule_1 = __decorate([
|
|
94
|
+
Module({})
|
|
98
95
|
], JobContextModule);
|
|
96
|
+
export { JobContextModule };
|
|
97
|
+
function toTenantList(tenants) {
|
|
98
|
+
if (tenants.length === 0) {
|
|
99
|
+
throw new TypeError('JobContextModule needs at least one tenant.');
|
|
100
|
+
}
|
|
101
|
+
return [...tenants];
|
|
102
|
+
}
|
|
99
103
|
//# sourceMappingURL=job-context.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-context.module.js","sourceRoot":"","sources":["../src/job-context.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-context.module.js","sourceRoot":"","sources":["../src/job-context.module.ts"],"names":[],"mappings":"AAAA,sEAAsE;;;;;;;;;;;;;;AAEtE,OAAO,EAEL,MAAM,EACN,UAAU,EACV,MAAM,GAEP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,GACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEL,QAAQ,EACR,UAAU,GACX,MAAM,2BAA2B,CAAC;AAKnC;;;GAGG;AACH,IACM,sBAAsB,GAD5B,MACM,sBAAsB;IACT,YAAY,CAAe;IAE5C,YACyB,SAAwB,EAC1B,OAA0B,EAC1B,OAA0B;QAE/C,IAAI,CAAC,YAAY,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QACpD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9B,CAAC;IAED,qBAAqB;QACnB,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AAfK,sBAAsB;IAD3B,UAAU,EAAE;IAKR,WAAA,MAAM,CAAC,aAAa,CAAC,CAAA;IACrB,WAAA,MAAM,CAAC,WAAW,CAAC,CAAA;IACnB,WAAA,MAAM,CAAC,WAAW,CAAC,CAAA;;GANlB,sBAAsB,CAe3B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B;;;;;;;;;;;;;;OAcG;IACI,AAAP,MAAM,CAAC,OAAO,CAAC,OAA0B;QACvC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC5B,OAAO;YACL,MAAM,oBAAkB;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;YAC9B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,CAAC,SAAS,EAAE;gBACvD,OAAO,OAAO,KAAK,UAAU;oBAC3B,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,EAAE;oBACrE,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE;gBAC7D,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE;gBACnD,sBAAsB;aACvB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA/BY,gBAAgB;IAD5B,MAAM,CAAC,EAAE,CAAC;GACE,gBAAgB,CA+B5B;;AAED,SAAS,YAAY,CAAC,OAA0B;IAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs-pipeline/job-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Carries the tenant, correlation id and principal of a request into the queue jobs it enqueues, and gives system-started work an explicit context",
|
|
5
5
|
"author": "Aristotelis",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"engines": {
|
|
8
|
-
"node": ">=22.
|
|
9
|
+
"node": ">=22.12.0"
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -26,6 +27,13 @@
|
|
|
26
27
|
"authorization",
|
|
27
28
|
"correlation-id"
|
|
28
29
|
],
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
29
37
|
"main": "dist/index.js",
|
|
30
38
|
"types": "dist/index.d.ts",
|
|
31
39
|
"files": [
|
|
@@ -37,13 +45,13 @@
|
|
|
37
45
|
"access": "public"
|
|
38
46
|
},
|
|
39
47
|
"peerDependencies": {
|
|
40
|
-
"@nestjs/common": "^
|
|
48
|
+
"@nestjs/common": "^12.1.0"
|
|
41
49
|
},
|
|
42
50
|
"devDependencies": {
|
|
43
|
-
"@nestjs/common": "^
|
|
44
|
-
"@vitest/coverage-v8": "^
|
|
51
|
+
"@nestjs/common": "^12.1.1",
|
|
52
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
45
53
|
"reflect-metadata": "^0.2.2",
|
|
46
|
-
"vitest": "^
|
|
54
|
+
"vitest": "^5.0.2"
|
|
47
55
|
},
|
|
48
56
|
"scripts": {
|
|
49
57
|
"build": "tsc -p tsconfig.build.json",
|