@beignet/provider-event-bus-memory 0.0.51 → 0.0.53
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/CHANGELOG.md +10 -0
- package/README.md +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +21 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @beignet/provider-event-bus-memory
|
|
2
2
|
|
|
3
|
+
## 0.0.53
|
|
4
|
+
|
|
5
|
+
## 0.0.52
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- b39bb6e: Clarify that Beignet applications require Node.js 22.12 or newer and can use
|
|
10
|
+
npm, pnpm, Yarn, or Bun for package management and framework commands.
|
|
11
|
+
- ac76ab9: Reject event payloads with `EventTransportError` when they are not canonical JSON or change when validated again after transport, before publishing or recording them durably. Direct memory and recording-bus publication must be awaited while validation completes.
|
|
12
|
+
|
|
3
13
|
## 0.0.51
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# @beignet/provider-event-bus-memory
|
|
2
2
|
|
|
3
|
-
> **Runtime:** Beignet requires Node.js 22.12 or newer. Bun
|
|
4
|
-
> supported for Beignet commands.
|
|
3
|
+
> **Runtime:** Beignet requires Node.js 22.12 or newer. Bun is optional.
|
|
5
4
|
|
|
6
5
|
> [!CAUTION]
|
|
7
6
|
> Beignet is experimental alpha software. The `0.0.x` package line is for early
|
|
@@ -159,7 +158,8 @@ export async function stopOrderListeners() {
|
|
|
159
158
|
|
|
160
159
|
### `publish<E>(event, payload, options?): Promise<void> | void`
|
|
161
160
|
|
|
162
|
-
Publish a domain event with a typed payload.
|
|
161
|
+
Publish a domain event with a typed payload. Await the result so payload
|
|
162
|
+
validation and the configured delivery mode complete before continuing.
|
|
163
163
|
|
|
164
164
|
```typescript
|
|
165
165
|
await eventBus.publish(UserRegistered, {
|
|
@@ -250,9 +250,13 @@ describe("User Registration", () => {
|
|
|
250
250
|
- **Memory-only**: No persistence - events are lost if the process crashes
|
|
251
251
|
- **Order**: Handlers are called in the order they were subscribed
|
|
252
252
|
- **Multiple handlers**: Multiple handlers can subscribe to the same event
|
|
253
|
-
- **
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
- **Transport-stable payloads**: Direct publication, `publishEvent(...)`, and
|
|
254
|
+
use-case helpers reject non-JSON output and transforms whose canonical JSON
|
|
255
|
+
changes when validated again. This keeps local behavior aligned with
|
|
256
|
+
serialized providers.
|
|
257
|
+
- **Canonical helper delivery**: Producer helpers preserve parsed and
|
|
258
|
+
transport-stable payload state through in-process delivery, so registered
|
|
259
|
+
listeners do not repeat validation unnecessarily.
|
|
256
260
|
- **Error handling**: Handler errors reject `publish(...)` unless
|
|
257
261
|
`onHandlerError` is configured
|
|
258
262
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAGL,KAAK,6BAA6B,EACnC,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,6BAA6B,CAAC;IAEhD;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAElC;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,OAAO,KACb,IAAI,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,6BACf,SAAQ,IAAI,CAAC,qBAAqB,EAAE,iBAAiB,CAAC;IACtD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,qBAA0B,GAClC,YAAY,CAmHd;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,6BAAkC;;kBAiB5C"}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* await subscription.unsubscribe();
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
+
import { prepareEventPayloadForTransport, } from "@beignet/core/events";
|
|
29
30
|
import { createProvider, createProviderInstrumentation, } from "@beignet/core/providers";
|
|
30
31
|
import { captureTraceCarrier, parseTraceCarrier } from "@beignet/core/tracing";
|
|
31
32
|
/**
|
|
@@ -75,7 +76,9 @@ export function createMemoryEventBus(options = {}) {
|
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
return {
|
|
78
|
-
publish(event, payload, publishOptions) {
|
|
79
|
+
async publish(event, payload, publishOptions) {
|
|
80
|
+
const prepared = await prepareEventPayloadForTransport(event, payload, publishOptions);
|
|
81
|
+
const canonicalPayload = prepared.payload;
|
|
79
82
|
instrumentation.record({
|
|
80
83
|
type: "eventBus",
|
|
81
84
|
eventName: event.name,
|
|
@@ -84,32 +87,23 @@ export function createMemoryEventBus(options = {}) {
|
|
|
84
87
|
if (!subs || subs.size === 0)
|
|
85
88
|
return;
|
|
86
89
|
const subscribers = [...subs];
|
|
87
|
-
const trace = parseTraceCarrier(publishOptions
|
|
90
|
+
const trace = parseTraceCarrier(prepared.publishOptions.trace) ??
|
|
88
91
|
captureTraceCarrier(options.instrumentation);
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (trace)
|
|
95
|
-
deliveryOptions.trace = trace;
|
|
96
|
-
else
|
|
97
|
-
delete deliveryOptions.trace;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
else if (trace) {
|
|
101
|
-
deliveryOptions = { trace };
|
|
102
|
-
}
|
|
92
|
+
const deliveryOptions = { ...prepared.publishOptions };
|
|
93
|
+
if (trace)
|
|
94
|
+
deliveryOptions.trace = trace;
|
|
95
|
+
else
|
|
96
|
+
delete deliveryOptions.trace;
|
|
103
97
|
if (delivery === "fire-and-forget") {
|
|
104
98
|
for (const handler of subscribers) {
|
|
105
99
|
try {
|
|
106
|
-
const result = handler(
|
|
100
|
+
const result = handler(canonicalPayload, deliveryOptions);
|
|
107
101
|
Promise.resolve(result).catch((error) => {
|
|
108
|
-
reportHandlerError(error, event.name,
|
|
102
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
109
103
|
});
|
|
110
104
|
}
|
|
111
105
|
catch (error) {
|
|
112
|
-
reportHandlerError(error, event.name,
|
|
106
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
113
107
|
}
|
|
114
108
|
}
|
|
115
109
|
return;
|
|
@@ -117,10 +111,10 @@ export function createMemoryEventBus(options = {}) {
|
|
|
117
111
|
return (async () => {
|
|
118
112
|
for (const handler of subscribers) {
|
|
119
113
|
try {
|
|
120
|
-
await handler(
|
|
114
|
+
await handler(canonicalPayload, deliveryOptions);
|
|
121
115
|
}
|
|
122
116
|
catch (error) {
|
|
123
|
-
reportHandlerError(error, event.name,
|
|
117
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
124
118
|
if (!onHandlerError)
|
|
125
119
|
throw error;
|
|
126
120
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAEL,+BAA+B,GAChC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,6BAA6B,GAE9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAkE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAiC,EAAE;IAEnC,MAAM,cAAc,GAAG,OAAO,EAAE,cAAc,CAAC;IAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,gBAAgB,CAAC;IACtD,MAAM,eAAe,GAAG,6BAA6B,CACnD,OAAO,CAAC,eAAe,EACvB;QACE,YAAY,EAAE,kBAAkB;QAChC,OAAO,EAAE,UAAU;KACpB,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAKrB,CAAC;IAEJ,MAAM,kBAAkB,GAAG,CACzB,KAAc,EACd,SAAiB,EACjB,OAAgB,EAChB,EAAE;QACF,IAAI,CAAC;YACH,cAAc,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,wFAAwF;QAC1F,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc;YAC1C,MAAM,QAAQ,GAAG,MAAM,+BAA+B,CACpD,KAAK,EACL,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AAG,kBAAkB,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;IAElE,OAAO,cAAc,CAAC;QACpB,IAAI;QACJ,KAAK,CAAC,EAAE,KAAK,EAAE;YACb,OAAO;gBACL,KAAK,EAAE;oBACL,QAAQ,EAAE,oBAAoB,CAAC;wBAC7B,GAAG,eAAe;wBAClB,eAAe,EAAE,KAAK;qBACvB,CAAC;iBACmC;aACxC,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@beignet/provider-event-bus-memory",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "In-memory event bus provider for Beignet - implements EventBusPort for single-process applications",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@beignet/core": "*",
|
|
60
60
|
"@beignet/devtools": "*",
|
|
61
|
-
"@types/bun": "^1.
|
|
61
|
+
"@types/bun": "^1.4.0",
|
|
62
62
|
"@types/node": "^22.0.0",
|
|
63
63
|
"typescript": "^5.3.0",
|
|
64
64
|
"zod": "^4.0.0"
|
package/src/index.ts
CHANGED
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
import
|
|
30
|
+
import {
|
|
31
|
+
type EventPublishOptions,
|
|
32
|
+
prepareEventPayloadForTransport,
|
|
33
|
+
} from "@beignet/core/events";
|
|
31
34
|
import type { EventBusPort } from "@beignet/core/ports";
|
|
32
35
|
import {
|
|
33
36
|
createProvider,
|
|
@@ -163,7 +166,14 @@ export function createMemoryEventBus(
|
|
|
163
166
|
};
|
|
164
167
|
|
|
165
168
|
return {
|
|
166
|
-
publish(event, payload, publishOptions) {
|
|
169
|
+
async publish(event, payload, publishOptions) {
|
|
170
|
+
const prepared = await prepareEventPayloadForTransport(
|
|
171
|
+
event,
|
|
172
|
+
payload,
|
|
173
|
+
publishOptions,
|
|
174
|
+
);
|
|
175
|
+
const canonicalPayload = prepared.payload;
|
|
176
|
+
|
|
167
177
|
instrumentation.record({
|
|
168
178
|
type: "eventBus",
|
|
169
179
|
eventName: event.name,
|
|
@@ -174,31 +184,21 @@ export function createMemoryEventBus(
|
|
|
174
184
|
|
|
175
185
|
const subscribers = [...subs];
|
|
176
186
|
const trace =
|
|
177
|
-
parseTraceCarrier(publishOptions
|
|
187
|
+
parseTraceCarrier(prepared.publishOptions.trace) ??
|
|
178
188
|
captureTraceCarrier(options.instrumentation);
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
(key) => key !== "trace",
|
|
183
|
-
);
|
|
184
|
-
if (trace || hasNonTraceMetadata) {
|
|
185
|
-
deliveryOptions = { ...publishOptions };
|
|
186
|
-
if (trace) deliveryOptions.trace = trace;
|
|
187
|
-
else delete deliveryOptions.trace;
|
|
188
|
-
}
|
|
189
|
-
} else if (trace) {
|
|
190
|
-
deliveryOptions = { trace };
|
|
191
|
-
}
|
|
189
|
+
const deliveryOptions = { ...prepared.publishOptions };
|
|
190
|
+
if (trace) deliveryOptions.trace = trace;
|
|
191
|
+
else delete deliveryOptions.trace;
|
|
192
192
|
|
|
193
193
|
if (delivery === "fire-and-forget") {
|
|
194
194
|
for (const handler of subscribers) {
|
|
195
195
|
try {
|
|
196
|
-
const result = handler(
|
|
196
|
+
const result = handler(canonicalPayload, deliveryOptions);
|
|
197
197
|
Promise.resolve(result).catch((error: unknown) => {
|
|
198
|
-
reportHandlerError(error, event.name,
|
|
198
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
199
199
|
});
|
|
200
200
|
} catch (error) {
|
|
201
|
-
reportHandlerError(error, event.name,
|
|
201
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -208,9 +208,9 @@ export function createMemoryEventBus(
|
|
|
208
208
|
return (async () => {
|
|
209
209
|
for (const handler of subscribers) {
|
|
210
210
|
try {
|
|
211
|
-
await handler(
|
|
211
|
+
await handler(canonicalPayload, deliveryOptions);
|
|
212
212
|
} catch (error) {
|
|
213
|
-
reportHandlerError(error, event.name,
|
|
213
|
+
reportHandlerError(error, event.name, canonicalPayload);
|
|
214
214
|
if (!onHandlerError) throw error;
|
|
215
215
|
}
|
|
216
216
|
}
|