@crossdelta/cloudevents 0.4.1 → 0.4.21
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 +12 -12
- package/dist/domain/discovery.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,24 +29,24 @@ bun add @crossdelta/cloudevents zod@4
|
|
|
29
29
|
|
|
30
30
|
## Quick Start
|
|
31
31
|
|
|
32
|
-
**1. Create an event handler** (`src/events/
|
|
32
|
+
**1. Create an event handler** (`src/events/orders-created.event.ts`):
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
35
|
import { handleEvent } from '@crossdelta/cloudevents'
|
|
36
36
|
import { z } from 'zod'
|
|
37
37
|
|
|
38
38
|
// Export schema for mock generation
|
|
39
|
-
export const
|
|
39
|
+
export const OrdersCreatedSchema = z.object({
|
|
40
40
|
orderId: z.string(),
|
|
41
41
|
total: z.number(),
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
// Export type for use in use-cases
|
|
45
|
-
export type
|
|
45
|
+
export type OrdersCreatedEvent = z.infer<typeof OrdersCreatedSchema>
|
|
46
46
|
|
|
47
47
|
export default handleEvent(
|
|
48
48
|
{
|
|
49
|
-
schema:
|
|
49
|
+
schema: OrdersCreatedSchema,
|
|
50
50
|
type: 'orders.created',
|
|
51
51
|
},
|
|
52
52
|
async (data) => {
|
|
@@ -251,20 +251,20 @@ await consumeJetStreamEvents({
|
|
|
251
251
|
When multiple services consume the same event, use `createContract` to create shared event contracts:
|
|
252
252
|
|
|
253
253
|
```typescript
|
|
254
|
-
// packages/contracts/src/
|
|
254
|
+
// packages/contracts/src/events/orders-created.ts
|
|
255
255
|
import { createContract } from '@crossdelta/cloudevents'
|
|
256
256
|
import { z } from 'zod'
|
|
257
257
|
|
|
258
|
-
export const
|
|
258
|
+
export const OrdersCreatedSchema = z.object({
|
|
259
259
|
orderId: z.string(),
|
|
260
260
|
total: z.number(),
|
|
261
261
|
})
|
|
262
262
|
|
|
263
|
-
export type
|
|
263
|
+
export type OrdersCreatedData = z.infer<typeof OrdersCreatedSchema>
|
|
264
264
|
|
|
265
|
-
export const
|
|
265
|
+
export const OrdersCreatedContract = createContract({
|
|
266
266
|
type: 'orders.created',
|
|
267
|
-
schema:
|
|
267
|
+
schema: OrdersCreatedSchema,
|
|
268
268
|
})
|
|
269
269
|
```
|
|
270
270
|
|
|
@@ -272,12 +272,12 @@ Then import and use in handlers:
|
|
|
272
272
|
|
|
273
273
|
```typescript
|
|
274
274
|
import { handleEvent } from '@crossdelta/cloudevents'
|
|
275
|
-
import {
|
|
275
|
+
import { OrdersCreatedContract } from '@my-org/contracts'
|
|
276
276
|
|
|
277
277
|
export default handleEvent(
|
|
278
|
-
|
|
278
|
+
OrdersCreatedContract,
|
|
279
279
|
async (data) => {
|
|
280
|
-
// data is typed as
|
|
280
|
+
// data is typed as OrdersCreatedData
|
|
281
281
|
console.log(data.orderId)
|
|
282
282
|
},
|
|
283
283
|
)
|
package/dist/domain/discovery.js
CHANGED
|
@@ -53,7 +53,12 @@ const loadHandlers = async (filePath, filter) => {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
|
-
|
|
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);
|
|
61
|
+
}
|
|
57
62
|
return [];
|
|
58
63
|
}
|
|
59
64
|
};
|