@ddd-ts-kit/nats 0.7.0 → 0.9.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 +3 -3
- package/dist/codec/decode.d.ts +1 -1
- package/dist/codec/decode.d.ts.map +1 -1
- package/dist/codec/decode.js +5 -1
- package/dist/codec/decode.js.map +1 -1
- package/dist/codec/encode.d.ts.map +1 -1
- package/dist/codec/encode.js +4 -1
- package/dist/codec/encode.js.map +1 -1
- package/dist/codec/headers.d.ts +1 -0
- package/dist/codec/headers.d.ts.map +1 -1
- package/dist/codec/headers.js +1 -0
- package/dist/codec/headers.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -168,9 +168,9 @@ A durable name holds neither dot nor wildcard: every character of the consumer n
|
|
|
168
168
|
the type outside `[A-Za-z0-9_-]` becomes `_`.
|
|
169
169
|
|
|
170
170
|
A message is the envelope as JSON (`id`, `type`, `version`, `occurredAt`, `payload`,
|
|
171
|
-
`traceparent`, `correlationId`) with the headers `Nats-Msg-Id` (the event id),
|
|
172
|
-
`x-event-type`, `x-event-version`, `traceparent` and `x-
|
|
173
|
-
consume it.
|
|
171
|
+
`traceparent`, `correlationId`, `tenantId`) with the headers `Nats-Msg-Id` (the event id),
|
|
172
|
+
`x-event-type`, `x-event-version`, `traceparent`, `x-correlation-id` and `x-tenant-id`. Any NATS
|
|
173
|
+
client can consume it.
|
|
174
174
|
|
|
175
175
|
Two consumers of one type have a durable consumer each and both receive every event. Two
|
|
176
176
|
instances of one consumer pull from the same durable consumer: each event goes to one of them.
|
package/dist/codec/decode.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IntegrationEvent } from '@ddd-ts-kit/kernel';
|
|
2
2
|
/** The envelope exactly as published, or `undefined` for a body that is not one (poison). */
|
|
3
3
|
export declare function decode(data: Uint8Array): IntegrationEvent | undefined;
|
|
4
4
|
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/codec/decode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/codec/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEvE,6FAA6F;AAC7F,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAiBrE"}
|
package/dist/codec/decode.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isTenantId } from '@ddd-ts-kit/kernel';
|
|
1
2
|
/** The envelope exactly as published, or `undefined` for a body that is not one (poison). */
|
|
2
3
|
export function decode(data) {
|
|
3
4
|
const body = parsed(data);
|
|
@@ -12,6 +13,7 @@ export function decode(data) {
|
|
|
12
13
|
payload: body.payload,
|
|
13
14
|
...(typeof body.traceparent === 'string' ? { traceparent: body.traceparent } : {}),
|
|
14
15
|
...(typeof body.correlationId === 'string' ? { correlationId: body.correlationId } : {}),
|
|
16
|
+
...(isTenantId(body.tenantId) ? { tenantId: body.tenantId } : {}),
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
function parsed(data) {
|
|
@@ -30,7 +32,9 @@ function isEnvelope(body) {
|
|
|
30
32
|
hasText(body, 'type') &&
|
|
31
33
|
hasText(body, 'occurredAt') &&
|
|
32
34
|
'version' in body &&
|
|
33
|
-
typeof body.version === 'number'
|
|
35
|
+
typeof body.version === 'number' &&
|
|
36
|
+
// A tenant outside the grammar could widen what the consumer reaches: the envelope is poison.
|
|
37
|
+
(!('tenantId' in body) || body.tenantId === undefined || isTenantId(body.tenantId)));
|
|
34
38
|
}
|
|
35
39
|
function hasText(body, field) {
|
|
36
40
|
const value = Reflect.get(body, field);
|
package/dist/codec/decode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/codec/decode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/codec/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyB,MAAM,oBAAoB,CAAC;AAEvE,6FAA6F;AAC7F,MAAM,UAAU,MAAM,CAAC,IAAgB;IACrC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE1B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,CAAC,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,GAAG,CAAC,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxF,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC;AAaD,SAAS,MAAM,CAAC,IAAgB;IAC9B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAa;IAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC;QACnB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC;QAC3B,SAAS,IAAI,IAAI;QACjB,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;QAChC,8FAA8F;QAC9F,CAAC,CAAC,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CACpF,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,KAAa;IAC1C,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEhD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/codec/encode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/codec/encode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQ3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW,CAmB3D"}
|
package/dist/codec/encode.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { headers as emptyHeaders } from '@nats-io/transport-node';
|
|
2
|
-
import { CORRELATION_HEADER, EVENT_TYPE_HEADER, EVENT_VERSION_HEADER, TRACEPARENT_HEADER } from './headers.js';
|
|
2
|
+
import { CORRELATION_HEADER, EVENT_TYPE_HEADER, EVENT_VERSION_HEADER, TENANT_HEADER, TRACEPARENT_HEADER, } from './headers.js';
|
|
3
3
|
/**
|
|
4
4
|
* The body is the whole envelope as JSON, so any NATS client can consume it. The headers
|
|
5
5
|
* repeat what the stream, a tracer or an operator needs without opening the body.
|
|
@@ -14,6 +14,9 @@ export function encode(event) {
|
|
|
14
14
|
if (event.correlationId !== undefined) {
|
|
15
15
|
headers.set(CORRELATION_HEADER, event.correlationId);
|
|
16
16
|
}
|
|
17
|
+
if (event.tenantId !== undefined) {
|
|
18
|
+
headers.set(TENANT_HEADER, event.tenantId);
|
|
19
|
+
}
|
|
17
20
|
return { data: JSON.stringify(event), messageId: event.id, headers };
|
|
18
21
|
}
|
|
19
22
|
//# sourceMappingURL=encode.js.map
|
package/dist/codec/encode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/codec/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/codec/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,KAAuB;IAC5C,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAE/B,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAEzD,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;IAED,IAAI,KAAK,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;AACvE,CAAC"}
|
package/dist/codec/headers.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const EVENT_TYPE_HEADER = "x-event-type";
|
|
|
4
4
|
export declare const EVENT_VERSION_HEADER = "x-event-version";
|
|
5
5
|
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
6
6
|
export declare const CORRELATION_HEADER = "x-correlation-id";
|
|
7
|
+
export declare const TENANT_HEADER = "x-tenant-id";
|
|
7
8
|
export declare const ATTEMPT_HEADER = "x-attempt";
|
|
8
9
|
export declare const ERROR_CODE_HEADER = "x-error-code";
|
|
9
10
|
export declare const DEAD_REASON_HEADER = "x-dead-reason";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/codec/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAChD,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AACrD,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAClD,6DAA6D;AAC7D,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/codec/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAC/C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AACtD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAChD,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AACrD,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAC3C,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAChD,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAClD,6DAA6D;AAC7D,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB,iBAAiB,CAAC"}
|
package/dist/codec/headers.js
CHANGED
|
@@ -4,6 +4,7 @@ export const EVENT_TYPE_HEADER = 'x-event-type';
|
|
|
4
4
|
export const EVENT_VERSION_HEADER = 'x-event-version';
|
|
5
5
|
export const TRACEPARENT_HEADER = 'traceparent';
|
|
6
6
|
export const CORRELATION_HEADER = 'x-correlation-id';
|
|
7
|
+
export const TENANT_HEADER = 'x-tenant-id';
|
|
7
8
|
export const ATTEMPT_HEADER = 'x-attempt';
|
|
8
9
|
export const ERROR_CODE_HEADER = 'x-error-code';
|
|
9
10
|
export const DEAD_REASON_HEADER = 'x-dead-reason';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/codec/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAClD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AACxC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/codec/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAAkB,CAAC;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAC3C,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAClD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AACxC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/nats",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "NATS JetStream provider for integration events: acknowledged publishing with message deduplication for the outbox relay, one durable consumer per consumer, explicit acknowledgement, bounded redelivery and a dead-letter subject.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ddd-ts-kit/events": "0.
|
|
30
|
-
"@ddd-ts-kit/kernel": "0.
|
|
29
|
+
"@ddd-ts-kit/events": "0.9.0",
|
|
30
|
+
"@ddd-ts-kit/kernel": "0.9.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@ddd-ts-kit/testing": "0.
|
|
33
|
+
"@ddd-ts-kit/testing": "0.9.0",
|
|
34
34
|
"@nats-io/jetstream": "^3.4.0",
|
|
35
35
|
"@nats-io/transport-node": "^3.4.0"
|
|
36
36
|
},
|