@crossdelta/cloudevents 0.5.4 → 0.5.6
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 +24 -6
- package/dist/domain/discovery.js +18 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Type-safe event-driven microservices with [NATS](https://nats.io) and [Zod](http
|
|
|
11
11
|
└──────────────┘ │ │ └──────────────┘
|
|
12
12
|
└──────────────┘
|
|
13
13
|
│ │
|
|
14
|
-
│
|
|
14
|
+
│ publish(...) │ handleEvent(...)
|
|
15
15
|
▼ ▼
|
|
16
16
|
┌──────────────┐ ┌──────────────┐
|
|
17
17
|
│ { orderId, │ │ Zod schema │
|
|
@@ -286,14 +286,32 @@ export const OrdersCreatedContract = createContract({
|
|
|
286
286
|
```typescript
|
|
287
287
|
interface ChannelConfig {
|
|
288
288
|
stream: string // JetStream stream name (e.g., 'ORDERS')
|
|
289
|
-
subject?: string // NATS subject (
|
|
289
|
+
subject?: string // NATS subject (optional override)
|
|
290
290
|
}
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
**Subject
|
|
294
|
-
-
|
|
295
|
-
-
|
|
296
|
-
-
|
|
293
|
+
**Subject Routing (CRITICAL):**
|
|
294
|
+
- **Without `subject`**: Domain is auto-pluralized: `customer.created` → subject `customers.created`
|
|
295
|
+
- **With `subject`**: Uses exact subject specified (no auto-pluralization)
|
|
296
|
+
- **Why pluralize**: Stream subjects are plural (`customers.*`), event types are singular (`customer.created`)
|
|
297
|
+
|
|
298
|
+
**Examples:**
|
|
299
|
+
```typescript
|
|
300
|
+
// Auto-pluralized subject
|
|
301
|
+
createContract({
|
|
302
|
+
type: 'order.created', // Event type: singular
|
|
303
|
+
channel: { stream: 'ORDERS' }, // Subject: orders.created (plural)
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
// Custom subject (no auto-pluralization)
|
|
307
|
+
createContract({
|
|
308
|
+
type: 'order.created',
|
|
309
|
+
channel: {
|
|
310
|
+
stream: 'ORDERS',
|
|
311
|
+
subject: 'orders.v1.created' // Exact subject, no auto-pluralization
|
|
312
|
+
},
|
|
313
|
+
})
|
|
314
|
+
```
|
|
297
315
|
|
|
298
316
|
### Multiple Events, Same Stream
|
|
299
317
|
|
package/dist/domain/discovery.js
CHANGED
|
@@ -53,11 +53,24 @@ const loadHandlers = async (filePath, filter) => {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
logger?.warn(`
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
// Comprehensive error logging for debugging
|
|
57
|
+
logger?.warn(`Failed to load ${filePath}`);
|
|
58
|
+
logger?.warn(`Error type: ${typeof error}`);
|
|
59
|
+
logger?.warn(`Error constructor: ${error?.constructor?.name}`);
|
|
60
|
+
if (error instanceof Error) {
|
|
61
|
+
logger?.warn(`Error message: ${error.message}`);
|
|
62
|
+
if (error.stack) {
|
|
63
|
+
logger?.warn(`Stack trace:\n${error.stack}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
logger?.warn(`Error value: ${String(error)}`);
|
|
68
|
+
try {
|
|
69
|
+
logger?.warn(`Error JSON: ${JSON.stringify(error, null, 2)}`);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
logger?.warn('(Error is not JSON-serializable)');
|
|
73
|
+
}
|
|
61
74
|
}
|
|
62
75
|
return [];
|
|
63
76
|
}
|