@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 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
- publishNatsRawEvent(...) │ handleEvent(...)
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 (defaults to event type)
289
+ subject?: string // NATS subject (optional override)
290
290
  }
291
291
  ```
292
292
 
293
- **Subject Defaulting:**
294
- - If `subject` is **not provided**, it defaults to the event `type`
295
- - This follows the convention: `orders.created` subject `orders.created`
296
- - Override when needed: `subject: 'orders.v1.created'`
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
 
@@ -53,11 +53,24 @@ const loadHandlers = async (filePath, filter) => {
53
53
  });
54
54
  }
55
55
  catch (error) {
56
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
57
- const errorStack = error instanceof Error ? error.stack : undefined;
58
- logger?.warn(`Failed to load ${filePath}: ${errorMessage}`);
59
- if (errorStack) {
60
- logger?.warn(errorStack);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/cloudevents",
3
- "version": "0.5.4",
3
+ "version": "0.5.6",
4
4
  "description": "CloudEvents toolkit for TypeScript - Zod validation, handler discovery, NATS JetStream",
5
5
  "author": "crossdelta",
6
6
  "license": "MIT",