@beignet/provider-event-bus-memory 0.0.36 → 0.0.38
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 +18 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +24 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @beignet/provider-event-bus-memory
|
|
2
2
|
|
|
3
|
+
## 0.0.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 443b9a1: Clarify post-commit delivery, listener ordering, cooperative job timeouts, stateless upload completion, and stable idempotency-key responsibilities.
|
|
8
|
+
- d23b0b3: Continue versioned W3C trace context through outbox, event bus, BullMQ, and
|
|
9
|
+
Inngest boundaries without making telemetry metadata part of delivery success.
|
|
10
|
+
|
|
11
|
+
## 0.0.37
|
|
12
|
+
|
|
3
13
|
## 0.0.36
|
|
4
14
|
|
|
5
15
|
## 0.0.35
|
package/README.md
CHANGED
|
@@ -60,12 +60,12 @@ unsubscribe();
|
|
|
60
60
|
```typescript
|
|
61
61
|
import { createNextServer, createNextServerLoader } from "@beignet/next";
|
|
62
62
|
import { createMemoryEventBusProvider } from "@beignet/provider-event-bus-memory";
|
|
63
|
-
import {
|
|
63
|
+
import { initialPorts } from "@/infra/port-wiring";
|
|
64
64
|
import { routes } from "@/server/routes";
|
|
65
65
|
|
|
66
66
|
export const getServer = createNextServerLoader(() =>
|
|
67
67
|
createNextServer({
|
|
68
|
-
ports:
|
|
68
|
+
ports: initialPorts,
|
|
69
69
|
providers: [createMemoryEventBusProvider()],
|
|
70
70
|
context: ({ ports }) => ({
|
|
71
71
|
ports,
|
|
@@ -143,7 +143,7 @@ const placeOrder = useCase
|
|
|
143
143
|
|
|
144
144
|
## EventBus port API
|
|
145
145
|
|
|
146
|
-
### `publish<E>(event
|
|
146
|
+
### `publish<E>(event, payload, options?): Promise<void> | void`
|
|
147
147
|
|
|
148
148
|
Publish a domain event with a typed payload.
|
|
149
149
|
|
|
@@ -161,13 +161,18 @@ in-process delivery. Fire-and-forget delivery reports handler errors through
|
|
|
161
161
|
`onHandlerError` when provided, but it still does not retry or dead-letter
|
|
162
162
|
failed work.
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
The optional third `{ trace }` argument is transport metadata used by Beignet
|
|
165
|
+
listeners. When `instrumentation` exposes a tracing port, the bus captures the
|
|
166
|
+
active context automatically. Existing two-argument calls are unchanged.
|
|
167
|
+
|
|
168
|
+
### `subscribe<E>(event, handler): () => void`
|
|
165
169
|
|
|
166
170
|
Subscribe to a domain event. Returns an unsubscribe function.
|
|
167
171
|
|
|
168
172
|
```typescript
|
|
169
|
-
const unsubscribe = eventBus.subscribe(UserRegistered, (payload) => {
|
|
173
|
+
const unsubscribe = eventBus.subscribe(UserRegistered, (payload, options) => {
|
|
170
174
|
console.log(`New user: ${payload.email}`);
|
|
175
|
+
console.log(options?.trace?.traceparent);
|
|
171
176
|
});
|
|
172
177
|
|
|
173
178
|
// Later, when you want to stop listening:
|
|
@@ -183,12 +188,12 @@ import type { EventBusPort } from "@beignet/core/ports";
|
|
|
183
188
|
import { definePorts } from "@beignet/core/ports";
|
|
184
189
|
|
|
185
190
|
// Type-safe ports definition
|
|
186
|
-
const
|
|
191
|
+
const initialPorts = definePorts({
|
|
187
192
|
eventBus: createMemoryEventBus() as EventBusPort,
|
|
188
193
|
// ... other ports
|
|
189
194
|
});
|
|
190
195
|
|
|
191
|
-
type AppPorts = typeof
|
|
196
|
+
type AppPorts = typeof initialPorts;
|
|
192
197
|
```
|
|
193
198
|
|
|
194
199
|
## Testing
|
|
@@ -227,6 +232,12 @@ describe("User Registration", () => {
|
|
|
227
232
|
- **Error handling**: Handler errors reject `publish(...)` unless
|
|
228
233
|
`onHandlerError` is configured
|
|
229
234
|
|
|
235
|
+
In awaited mode, an unhandled failure stops delivery to later handlers. A
|
|
236
|
+
transport-level retry may then rerun handlers that already succeeded. With
|
|
237
|
+
`onHandlerError`, delivery continues but the failed handler is not retried
|
|
238
|
+
independently. Use separate idempotent jobs or outbox messages when each side
|
|
239
|
+
effect needs its own durable retry lifecycle.
|
|
240
|
+
|
|
230
241
|
## Local and tests
|
|
231
242
|
|
|
232
243
|
Use this provider for local development, deterministic use-case tests, and
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,qBAA0B,GAClC,YAAY,CAoGd;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,6BAAkC;;kBAiB5C"}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
import { createProvider, createProviderInstrumentation, } from "@beignet/core/providers";
|
|
29
|
+
import { captureTraceCarrier, parseTraceCarrier } from "@beignet/core/tracing";
|
|
29
30
|
/**
|
|
30
31
|
* Create an in-memory event bus implementation.
|
|
31
32
|
*
|
|
@@ -71,7 +72,7 @@ export function createMemoryEventBus(options = {}) {
|
|
|
71
72
|
}
|
|
72
73
|
};
|
|
73
74
|
return {
|
|
74
|
-
publish(event, payload) {
|
|
75
|
+
publish(event, payload, publishOptions) {
|
|
75
76
|
instrumentation.record({
|
|
76
77
|
type: "eventBus",
|
|
77
78
|
eventName: event.name,
|
|
@@ -80,10 +81,13 @@ export function createMemoryEventBus(options = {}) {
|
|
|
80
81
|
if (!subs || subs.size === 0)
|
|
81
82
|
return;
|
|
82
83
|
const subscribers = [...subs];
|
|
84
|
+
const trace = parseTraceCarrier(publishOptions?.trace) ??
|
|
85
|
+
captureTraceCarrier(options.instrumentation);
|
|
86
|
+
const deliveryOptions = trace ? { trace } : undefined;
|
|
83
87
|
if (delivery === "fire-and-forget") {
|
|
84
88
|
for (const handler of subscribers) {
|
|
85
89
|
try {
|
|
86
|
-
const result = handler(payload);
|
|
90
|
+
const result = handler(payload, deliveryOptions);
|
|
87
91
|
Promise.resolve(result).catch((error) => {
|
|
88
92
|
reportHandlerError(error, event.name, payload);
|
|
89
93
|
});
|
|
@@ -97,7 +101,7 @@ export function createMemoryEventBus(options = {}) {
|
|
|
97
101
|
return (async () => {
|
|
98
102
|
for (const handler of subscribers) {
|
|
99
103
|
try {
|
|
100
|
-
await handler(payload);
|
|
104
|
+
await handler(payload, deliveryOptions);
|
|
101
105
|
}
|
|
102
106
|
catch (error) {
|
|
103
107
|
reportHandlerError(error, event.name, payload);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EACL,cAAc,EACd,6BAA6B,GAE9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAkE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;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,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc;YACpC,eAAe,CAAC,MAAM,CAAC;gBACrB,IA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26
|
* ```
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
import type { EventPublishOptions } from "@beignet/core/events";
|
|
29
30
|
import type { EventBusPort } from "@beignet/core/ports";
|
|
30
31
|
import {
|
|
31
32
|
createProvider,
|
|
32
33
|
createProviderInstrumentation,
|
|
33
34
|
type ProviderInstrumentationTarget,
|
|
34
35
|
} from "@beignet/core/providers";
|
|
36
|
+
import { captureTraceCarrier, parseTraceCarrier } from "@beignet/core/tracing";
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* Delivery mode for the in-memory event bus.
|
|
@@ -140,7 +142,9 @@ export function createMemoryEventBus(
|
|
|
140
142
|
|
|
141
143
|
const handlers = new Map<
|
|
142
144
|
string,
|
|
143
|
-
Set<
|
|
145
|
+
Set<
|
|
146
|
+
(payload: unknown, options?: EventPublishOptions) => void | Promise<void>
|
|
147
|
+
>
|
|
144
148
|
>();
|
|
145
149
|
|
|
146
150
|
const reportHandlerError = (
|
|
@@ -156,7 +160,7 @@ export function createMemoryEventBus(
|
|
|
156
160
|
};
|
|
157
161
|
|
|
158
162
|
return {
|
|
159
|
-
publish(event, payload) {
|
|
163
|
+
publish(event, payload, publishOptions) {
|
|
160
164
|
instrumentation.record({
|
|
161
165
|
type: "eventBus",
|
|
162
166
|
eventName: event.name,
|
|
@@ -166,11 +170,15 @@ export function createMemoryEventBus(
|
|
|
166
170
|
if (!subs || subs.size === 0) return;
|
|
167
171
|
|
|
168
172
|
const subscribers = [...subs];
|
|
173
|
+
const trace =
|
|
174
|
+
parseTraceCarrier(publishOptions?.trace) ??
|
|
175
|
+
captureTraceCarrier(options.instrumentation);
|
|
176
|
+
const deliveryOptions = trace ? { trace } : undefined;
|
|
169
177
|
|
|
170
178
|
if (delivery === "fire-and-forget") {
|
|
171
179
|
for (const handler of subscribers) {
|
|
172
180
|
try {
|
|
173
|
-
const result = handler(payload);
|
|
181
|
+
const result = handler(payload, deliveryOptions);
|
|
174
182
|
Promise.resolve(result).catch((error: unknown) => {
|
|
175
183
|
reportHandlerError(error, event.name, payload);
|
|
176
184
|
});
|
|
@@ -185,7 +193,7 @@ export function createMemoryEventBus(
|
|
|
185
193
|
return (async () => {
|
|
186
194
|
for (const handler of subscribers) {
|
|
187
195
|
try {
|
|
188
|
-
await handler(payload);
|
|
196
|
+
await handler(payload, deliveryOptions);
|
|
189
197
|
} catch (error) {
|
|
190
198
|
reportHandlerError(error, event.name, payload);
|
|
191
199
|
if (!onHandlerError) throw error;
|
|
@@ -201,10 +209,20 @@ export function createMemoryEventBus(
|
|
|
201
209
|
handlers.set(event.name, subs);
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
subs.add(
|
|
212
|
+
subs.add(
|
|
213
|
+
handler as unknown as (
|
|
214
|
+
payload: unknown,
|
|
215
|
+
options?: EventPublishOptions,
|
|
216
|
+
) => void | Promise<void>,
|
|
217
|
+
);
|
|
205
218
|
|
|
206
219
|
return () => {
|
|
207
|
-
subs.delete(
|
|
220
|
+
subs.delete(
|
|
221
|
+
handler as unknown as (
|
|
222
|
+
payload: unknown,
|
|
223
|
+
options?: EventPublishOptions,
|
|
224
|
+
) => void | Promise<void>,
|
|
225
|
+
);
|
|
208
226
|
if (subs.size === 0) {
|
|
209
227
|
handlers.delete(event.name);
|
|
210
228
|
}
|