@signaltree/events 7.3.1
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/angular.d.ts +1 -0
- package/angular.esm.js +547 -0
- package/factory.esm.js +178 -0
- package/idempotency.esm.js +701 -0
- package/index.d.ts +1 -0
- package/index.esm.js +167 -0
- package/nestjs.d.ts +1 -0
- package/nestjs.esm.js +944 -0
- package/package.json +110 -0
- package/src/angular/handlers.d.ts +132 -0
- package/src/angular/index.d.ts +12 -0
- package/src/angular/optimistic-updates.d.ts +117 -0
- package/src/angular/websocket.service.d.ts +158 -0
- package/src/angular.d.ts +7 -0
- package/src/core/error-classification.d.ts +100 -0
- package/src/core/factory.d.ts +114 -0
- package/src/core/idempotency.d.ts +209 -0
- package/src/core/registry.d.ts +147 -0
- package/src/core/types.d.ts +127 -0
- package/src/core/validation.d.ts +619 -0
- package/src/index.d.ts +56 -0
- package/src/nestjs/base.subscriber.d.ts +169 -0
- package/src/nestjs/decorators.d.ts +37 -0
- package/src/nestjs/dlq.service.d.ts +117 -0
- package/src/nestjs/event-bus.module.d.ts +117 -0
- package/src/nestjs/event-bus.service.d.ts +114 -0
- package/src/nestjs/index.d.ts +16 -0
- package/src/nestjs/tokens.d.ts +8 -0
- package/src/nestjs.d.ts +7 -0
- package/src/testing/assertions.d.ts +113 -0
- package/src/testing/factories.d.ts +106 -0
- package/src/testing/helpers.d.ts +104 -0
- package/src/testing/index.d.ts +13 -0
- package/src/testing/mock-event-bus.d.ts +144 -0
- package/src/testing.d.ts +7 -0
- package/testing.d.ts +1 -0
- package/testing.esm.js +743 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
import { z, ZodError, ZodObject, ZodRawShape } from 'zod';
|
|
2
|
+
import { BaseEvent } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Event validation using Zod schemas
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - Base schemas for common event fields
|
|
8
|
+
* - Factory function to create event schemas
|
|
9
|
+
* - Runtime validation with detailed errors
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Schema for event actor
|
|
13
|
+
*/
|
|
14
|
+
export declare const EventActorSchema: z.ZodObject<{
|
|
15
|
+
id: z.ZodString;
|
|
16
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
17
|
+
name: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
id: string;
|
|
20
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
21
|
+
name?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
id: string;
|
|
24
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Schema for event version
|
|
29
|
+
*/
|
|
30
|
+
export declare const EventVersionSchema: z.ZodObject<{
|
|
31
|
+
major: z.ZodNumber;
|
|
32
|
+
minor: z.ZodNumber;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
major: number;
|
|
35
|
+
minor: number;
|
|
36
|
+
}, {
|
|
37
|
+
major: number;
|
|
38
|
+
minor: number;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Schema for event metadata
|
|
42
|
+
*/
|
|
43
|
+
export declare const EventMetadataSchema: z.ZodObject<{
|
|
44
|
+
source: z.ZodString;
|
|
45
|
+
environment: z.ZodString;
|
|
46
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
47
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
49
|
+
source: z.ZodString;
|
|
50
|
+
environment: z.ZodString;
|
|
51
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
52
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
53
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
54
|
+
source: z.ZodString;
|
|
55
|
+
environment: z.ZodString;
|
|
56
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
57
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
59
|
+
/**
|
|
60
|
+
* Schema for aggregate info
|
|
61
|
+
*/
|
|
62
|
+
export declare const AggregateSchema: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
type: z.ZodString;
|
|
64
|
+
id: z.ZodString;
|
|
65
|
+
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
id: string;
|
|
67
|
+
type: string;
|
|
68
|
+
}, {
|
|
69
|
+
id: string;
|
|
70
|
+
type: string;
|
|
71
|
+
}>>;
|
|
72
|
+
/**
|
|
73
|
+
* Base event schema without data field
|
|
74
|
+
*/
|
|
75
|
+
export declare const BaseEventSchema: z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
type: z.ZodString;
|
|
78
|
+
version: z.ZodObject<{
|
|
79
|
+
major: z.ZodNumber;
|
|
80
|
+
minor: z.ZodNumber;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
major: number;
|
|
83
|
+
minor: number;
|
|
84
|
+
}, {
|
|
85
|
+
major: number;
|
|
86
|
+
minor: number;
|
|
87
|
+
}>;
|
|
88
|
+
timestamp: z.ZodString;
|
|
89
|
+
correlationId: z.ZodString;
|
|
90
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
91
|
+
actor: z.ZodObject<{
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
94
|
+
name: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
id: string;
|
|
97
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
98
|
+
name?: string | undefined;
|
|
99
|
+
}, {
|
|
100
|
+
id: string;
|
|
101
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
102
|
+
name?: string | undefined;
|
|
103
|
+
}>;
|
|
104
|
+
metadata: z.ZodObject<{
|
|
105
|
+
source: z.ZodString;
|
|
106
|
+
environment: z.ZodString;
|
|
107
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
108
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
110
|
+
source: z.ZodString;
|
|
111
|
+
environment: z.ZodString;
|
|
112
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
113
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
114
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
115
|
+
source: z.ZodString;
|
|
116
|
+
environment: z.ZodString;
|
|
117
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
118
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
120
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
121
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
122
|
+
type: z.ZodString;
|
|
123
|
+
id: z.ZodString;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
id: string;
|
|
126
|
+
type: string;
|
|
127
|
+
}, {
|
|
128
|
+
id: string;
|
|
129
|
+
type: string;
|
|
130
|
+
}>>;
|
|
131
|
+
}, "strip", z.ZodTypeAny, {
|
|
132
|
+
id: string;
|
|
133
|
+
type: string;
|
|
134
|
+
version: {
|
|
135
|
+
major: number;
|
|
136
|
+
minor: number;
|
|
137
|
+
};
|
|
138
|
+
timestamp: string;
|
|
139
|
+
correlationId: string;
|
|
140
|
+
actor: {
|
|
141
|
+
id: string;
|
|
142
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
143
|
+
name?: string | undefined;
|
|
144
|
+
};
|
|
145
|
+
metadata: {
|
|
146
|
+
source: string;
|
|
147
|
+
environment: string;
|
|
148
|
+
ip?: string | undefined;
|
|
149
|
+
userAgent?: string | undefined;
|
|
150
|
+
} & {
|
|
151
|
+
[k: string]: unknown;
|
|
152
|
+
};
|
|
153
|
+
causationId?: string | undefined;
|
|
154
|
+
priority?: "critical" | "high" | "normal" | "low" | "bulk" | undefined;
|
|
155
|
+
aggregate?: {
|
|
156
|
+
id: string;
|
|
157
|
+
type: string;
|
|
158
|
+
} | undefined;
|
|
159
|
+
}, {
|
|
160
|
+
id: string;
|
|
161
|
+
type: string;
|
|
162
|
+
version: {
|
|
163
|
+
major: number;
|
|
164
|
+
minor: number;
|
|
165
|
+
};
|
|
166
|
+
timestamp: string;
|
|
167
|
+
correlationId: string;
|
|
168
|
+
actor: {
|
|
169
|
+
id: string;
|
|
170
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
171
|
+
name?: string | undefined;
|
|
172
|
+
};
|
|
173
|
+
metadata: {
|
|
174
|
+
source: string;
|
|
175
|
+
environment: string;
|
|
176
|
+
ip?: string | undefined;
|
|
177
|
+
userAgent?: string | undefined;
|
|
178
|
+
} & {
|
|
179
|
+
[k: string]: unknown;
|
|
180
|
+
};
|
|
181
|
+
causationId?: string | undefined;
|
|
182
|
+
priority?: "critical" | "high" | "normal" | "low" | "bulk" | undefined;
|
|
183
|
+
aggregate?: {
|
|
184
|
+
id: string;
|
|
185
|
+
type: string;
|
|
186
|
+
} | undefined;
|
|
187
|
+
}>;
|
|
188
|
+
/**
|
|
189
|
+
* Create a typed event schema with Zod validation
|
|
190
|
+
*
|
|
191
|
+
* @param eventType - The event type string (e.g., 'TradeProposalCreated')
|
|
192
|
+
* @param dataSchema - Zod schema for the event's data field
|
|
193
|
+
* @returns Complete event schema
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const TradeProposalCreatedSchema = createEventSchema('TradeProposalCreated', {
|
|
198
|
+
* tradeId: z.string().uuid(),
|
|
199
|
+
* initiatorId: z.string().uuid(),
|
|
200
|
+
* recipientId: z.string().uuid(),
|
|
201
|
+
* vehicleOfferedId: z.string().uuid(),
|
|
202
|
+
* terms: z.object({
|
|
203
|
+
* cashDifference: z.number().optional(),
|
|
204
|
+
* }),
|
|
205
|
+
* });
|
|
206
|
+
*
|
|
207
|
+
* type TradeProposalCreated = z.infer<typeof TradeProposalCreatedSchema>;
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function createEventSchema<TType extends string, TDataShape extends ZodRawShape>(eventType: TType, dataSchema: TDataShape): z.ZodObject<{
|
|
211
|
+
id: z.ZodString;
|
|
212
|
+
version: z.ZodObject<{
|
|
213
|
+
major: z.ZodNumber;
|
|
214
|
+
minor: z.ZodNumber;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
major: number;
|
|
217
|
+
minor: number;
|
|
218
|
+
}, {
|
|
219
|
+
major: number;
|
|
220
|
+
minor: number;
|
|
221
|
+
}>;
|
|
222
|
+
timestamp: z.ZodString;
|
|
223
|
+
correlationId: z.ZodString;
|
|
224
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
225
|
+
actor: z.ZodObject<{
|
|
226
|
+
id: z.ZodString;
|
|
227
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
228
|
+
name: z.ZodOptional<z.ZodString>;
|
|
229
|
+
}, "strip", z.ZodTypeAny, {
|
|
230
|
+
id: string;
|
|
231
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
232
|
+
name?: string | undefined;
|
|
233
|
+
}, {
|
|
234
|
+
id: string;
|
|
235
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
236
|
+
name?: string | undefined;
|
|
237
|
+
}>;
|
|
238
|
+
metadata: z.ZodObject<{
|
|
239
|
+
source: z.ZodString;
|
|
240
|
+
environment: z.ZodString;
|
|
241
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
242
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
243
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
244
|
+
source: z.ZodString;
|
|
245
|
+
environment: z.ZodString;
|
|
246
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
247
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
248
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
249
|
+
source: z.ZodString;
|
|
250
|
+
environment: z.ZodString;
|
|
251
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
252
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
253
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
254
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
255
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
256
|
+
type: z.ZodString;
|
|
257
|
+
id: z.ZodString;
|
|
258
|
+
}, "strip", z.ZodTypeAny, {
|
|
259
|
+
id: string;
|
|
260
|
+
type: string;
|
|
261
|
+
}, {
|
|
262
|
+
id: string;
|
|
263
|
+
type: string;
|
|
264
|
+
}>>;
|
|
265
|
+
} & {
|
|
266
|
+
type: z.ZodLiteral<TType>;
|
|
267
|
+
data: z.ZodObject<TDataShape, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<TDataShape>, any> extends infer T ? { [k in keyof T]: T[k]; } : never, z.baseObjectInputType<TDataShape> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never>;
|
|
268
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
269
|
+
id: z.ZodString;
|
|
270
|
+
version: z.ZodObject<{
|
|
271
|
+
major: z.ZodNumber;
|
|
272
|
+
minor: z.ZodNumber;
|
|
273
|
+
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
major: number;
|
|
275
|
+
minor: number;
|
|
276
|
+
}, {
|
|
277
|
+
major: number;
|
|
278
|
+
minor: number;
|
|
279
|
+
}>;
|
|
280
|
+
timestamp: z.ZodString;
|
|
281
|
+
correlationId: z.ZodString;
|
|
282
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
283
|
+
actor: z.ZodObject<{
|
|
284
|
+
id: z.ZodString;
|
|
285
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
286
|
+
name: z.ZodOptional<z.ZodString>;
|
|
287
|
+
}, "strip", z.ZodTypeAny, {
|
|
288
|
+
id: string;
|
|
289
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
290
|
+
name?: string | undefined;
|
|
291
|
+
}, {
|
|
292
|
+
id: string;
|
|
293
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
294
|
+
name?: string | undefined;
|
|
295
|
+
}>;
|
|
296
|
+
metadata: z.ZodObject<{
|
|
297
|
+
source: z.ZodString;
|
|
298
|
+
environment: z.ZodString;
|
|
299
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
300
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
301
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
302
|
+
source: z.ZodString;
|
|
303
|
+
environment: z.ZodString;
|
|
304
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
305
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
306
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
307
|
+
source: z.ZodString;
|
|
308
|
+
environment: z.ZodString;
|
|
309
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
310
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
311
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
312
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
313
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
314
|
+
type: z.ZodString;
|
|
315
|
+
id: z.ZodString;
|
|
316
|
+
}, "strip", z.ZodTypeAny, {
|
|
317
|
+
id: string;
|
|
318
|
+
type: string;
|
|
319
|
+
}, {
|
|
320
|
+
id: string;
|
|
321
|
+
type: string;
|
|
322
|
+
}>>;
|
|
323
|
+
} & {
|
|
324
|
+
type: z.ZodLiteral<TType>;
|
|
325
|
+
data: z.ZodObject<TDataShape, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<TDataShape>, any> extends infer T_3 ? { [k in keyof T_3]: T_3[k]; } : never, z.baseObjectInputType<TDataShape> extends infer T_4 ? { [k_1 in keyof T_4]: T_4[k_1]; } : never>;
|
|
326
|
+
}>, any> extends infer T_2 ? { [k_2 in keyof T_2]: T_2[k_2]; } : never, z.baseObjectInputType<{
|
|
327
|
+
id: z.ZodString;
|
|
328
|
+
version: z.ZodObject<{
|
|
329
|
+
major: z.ZodNumber;
|
|
330
|
+
minor: z.ZodNumber;
|
|
331
|
+
}, "strip", z.ZodTypeAny, {
|
|
332
|
+
major: number;
|
|
333
|
+
minor: number;
|
|
334
|
+
}, {
|
|
335
|
+
major: number;
|
|
336
|
+
minor: number;
|
|
337
|
+
}>;
|
|
338
|
+
timestamp: z.ZodString;
|
|
339
|
+
correlationId: z.ZodString;
|
|
340
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
341
|
+
actor: z.ZodObject<{
|
|
342
|
+
id: z.ZodString;
|
|
343
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
344
|
+
name: z.ZodOptional<z.ZodString>;
|
|
345
|
+
}, "strip", z.ZodTypeAny, {
|
|
346
|
+
id: string;
|
|
347
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
348
|
+
name?: string | undefined;
|
|
349
|
+
}, {
|
|
350
|
+
id: string;
|
|
351
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
352
|
+
name?: string | undefined;
|
|
353
|
+
}>;
|
|
354
|
+
metadata: z.ZodObject<{
|
|
355
|
+
source: z.ZodString;
|
|
356
|
+
environment: z.ZodString;
|
|
357
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
358
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
359
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
360
|
+
source: z.ZodString;
|
|
361
|
+
environment: z.ZodString;
|
|
362
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
363
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
364
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
365
|
+
source: z.ZodString;
|
|
366
|
+
environment: z.ZodString;
|
|
367
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
368
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
369
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
370
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
371
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
372
|
+
type: z.ZodString;
|
|
373
|
+
id: z.ZodString;
|
|
374
|
+
}, "strip", z.ZodTypeAny, {
|
|
375
|
+
id: string;
|
|
376
|
+
type: string;
|
|
377
|
+
}, {
|
|
378
|
+
id: string;
|
|
379
|
+
type: string;
|
|
380
|
+
}>>;
|
|
381
|
+
} & {
|
|
382
|
+
type: z.ZodLiteral<TType>;
|
|
383
|
+
data: z.ZodObject<TDataShape, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<TDataShape>, any> extends infer T_6 ? { [k in keyof T_6]: T_6[k]; } : never, z.baseObjectInputType<TDataShape> extends infer T_7 ? { [k_1 in keyof T_7]: T_7[k_1]; } : never>;
|
|
384
|
+
}> extends infer T_5 ? { [k_3 in keyof T_5]: T_5[k_3]; } : never>;
|
|
385
|
+
/**
|
|
386
|
+
* Create event schema from existing Zod object
|
|
387
|
+
*/
|
|
388
|
+
export declare function createEventSchemaFromZod<TType extends string, TData extends ZodObject<ZodRawShape>>(eventType: TType, dataSchema: TData): z.ZodObject<{
|
|
389
|
+
id: z.ZodString;
|
|
390
|
+
version: z.ZodObject<{
|
|
391
|
+
major: z.ZodNumber;
|
|
392
|
+
minor: z.ZodNumber;
|
|
393
|
+
}, "strip", z.ZodTypeAny, {
|
|
394
|
+
major: number;
|
|
395
|
+
minor: number;
|
|
396
|
+
}, {
|
|
397
|
+
major: number;
|
|
398
|
+
minor: number;
|
|
399
|
+
}>;
|
|
400
|
+
timestamp: z.ZodString;
|
|
401
|
+
correlationId: z.ZodString;
|
|
402
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
403
|
+
actor: z.ZodObject<{
|
|
404
|
+
id: z.ZodString;
|
|
405
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
406
|
+
name: z.ZodOptional<z.ZodString>;
|
|
407
|
+
}, "strip", z.ZodTypeAny, {
|
|
408
|
+
id: string;
|
|
409
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
410
|
+
name?: string | undefined;
|
|
411
|
+
}, {
|
|
412
|
+
id: string;
|
|
413
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
414
|
+
name?: string | undefined;
|
|
415
|
+
}>;
|
|
416
|
+
metadata: z.ZodObject<{
|
|
417
|
+
source: z.ZodString;
|
|
418
|
+
environment: z.ZodString;
|
|
419
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
420
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
421
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
422
|
+
source: z.ZodString;
|
|
423
|
+
environment: z.ZodString;
|
|
424
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
425
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
426
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
427
|
+
source: z.ZodString;
|
|
428
|
+
environment: z.ZodString;
|
|
429
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
430
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
431
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
432
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
433
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
434
|
+
type: z.ZodString;
|
|
435
|
+
id: z.ZodString;
|
|
436
|
+
}, "strip", z.ZodTypeAny, {
|
|
437
|
+
id: string;
|
|
438
|
+
type: string;
|
|
439
|
+
}, {
|
|
440
|
+
id: string;
|
|
441
|
+
type: string;
|
|
442
|
+
}>>;
|
|
443
|
+
} & {
|
|
444
|
+
type: z.ZodLiteral<TType>;
|
|
445
|
+
data: TData;
|
|
446
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
447
|
+
id: z.ZodString;
|
|
448
|
+
version: z.ZodObject<{
|
|
449
|
+
major: z.ZodNumber;
|
|
450
|
+
minor: z.ZodNumber;
|
|
451
|
+
}, "strip", z.ZodTypeAny, {
|
|
452
|
+
major: number;
|
|
453
|
+
minor: number;
|
|
454
|
+
}, {
|
|
455
|
+
major: number;
|
|
456
|
+
minor: number;
|
|
457
|
+
}>;
|
|
458
|
+
timestamp: z.ZodString;
|
|
459
|
+
correlationId: z.ZodString;
|
|
460
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
461
|
+
actor: z.ZodObject<{
|
|
462
|
+
id: z.ZodString;
|
|
463
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
464
|
+
name: z.ZodOptional<z.ZodString>;
|
|
465
|
+
}, "strip", z.ZodTypeAny, {
|
|
466
|
+
id: string;
|
|
467
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
468
|
+
name?: string | undefined;
|
|
469
|
+
}, {
|
|
470
|
+
id: string;
|
|
471
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
472
|
+
name?: string | undefined;
|
|
473
|
+
}>;
|
|
474
|
+
metadata: z.ZodObject<{
|
|
475
|
+
source: z.ZodString;
|
|
476
|
+
environment: z.ZodString;
|
|
477
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
478
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
479
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
480
|
+
source: z.ZodString;
|
|
481
|
+
environment: z.ZodString;
|
|
482
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
483
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
484
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
485
|
+
source: z.ZodString;
|
|
486
|
+
environment: z.ZodString;
|
|
487
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
488
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
489
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
490
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
491
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
492
|
+
type: z.ZodString;
|
|
493
|
+
id: z.ZodString;
|
|
494
|
+
}, "strip", z.ZodTypeAny, {
|
|
495
|
+
id: string;
|
|
496
|
+
type: string;
|
|
497
|
+
}, {
|
|
498
|
+
id: string;
|
|
499
|
+
type: string;
|
|
500
|
+
}>>;
|
|
501
|
+
} & {
|
|
502
|
+
type: z.ZodLiteral<TType>;
|
|
503
|
+
data: TData;
|
|
504
|
+
}>, any> extends infer T ? { [k in keyof T]: T[k]; } : never, z.baseObjectInputType<{
|
|
505
|
+
id: z.ZodString;
|
|
506
|
+
version: z.ZodObject<{
|
|
507
|
+
major: z.ZodNumber;
|
|
508
|
+
minor: z.ZodNumber;
|
|
509
|
+
}, "strip", z.ZodTypeAny, {
|
|
510
|
+
major: number;
|
|
511
|
+
minor: number;
|
|
512
|
+
}, {
|
|
513
|
+
major: number;
|
|
514
|
+
minor: number;
|
|
515
|
+
}>;
|
|
516
|
+
timestamp: z.ZodString;
|
|
517
|
+
correlationId: z.ZodString;
|
|
518
|
+
causationId: z.ZodOptional<z.ZodString>;
|
|
519
|
+
actor: z.ZodObject<{
|
|
520
|
+
id: z.ZodString;
|
|
521
|
+
type: z.ZodEnum<["user", "system", "admin", "webhook"]>;
|
|
522
|
+
name: z.ZodOptional<z.ZodString>;
|
|
523
|
+
}, "strip", z.ZodTypeAny, {
|
|
524
|
+
id: string;
|
|
525
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
526
|
+
name?: string | undefined;
|
|
527
|
+
}, {
|
|
528
|
+
id: string;
|
|
529
|
+
type: "user" | "system" | "admin" | "webhook";
|
|
530
|
+
name?: string | undefined;
|
|
531
|
+
}>;
|
|
532
|
+
metadata: z.ZodObject<{
|
|
533
|
+
source: z.ZodString;
|
|
534
|
+
environment: z.ZodString;
|
|
535
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
536
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
537
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
538
|
+
source: z.ZodString;
|
|
539
|
+
environment: z.ZodString;
|
|
540
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
541
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
542
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
543
|
+
source: z.ZodString;
|
|
544
|
+
environment: z.ZodString;
|
|
545
|
+
ip: z.ZodOptional<z.ZodString>;
|
|
546
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
547
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
548
|
+
priority: z.ZodOptional<z.ZodEnum<["critical", "high", "normal", "low", "bulk"]>>;
|
|
549
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
550
|
+
type: z.ZodString;
|
|
551
|
+
id: z.ZodString;
|
|
552
|
+
}, "strip", z.ZodTypeAny, {
|
|
553
|
+
id: string;
|
|
554
|
+
type: string;
|
|
555
|
+
}, {
|
|
556
|
+
id: string;
|
|
557
|
+
type: string;
|
|
558
|
+
}>>;
|
|
559
|
+
} & {
|
|
560
|
+
type: z.ZodLiteral<TType>;
|
|
561
|
+
data: TData;
|
|
562
|
+
}> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never>;
|
|
563
|
+
/**
|
|
564
|
+
* Custom error class for event validation failures
|
|
565
|
+
*/
|
|
566
|
+
export declare class EventValidationError extends Error {
|
|
567
|
+
readonly zodError: ZodError;
|
|
568
|
+
readonly event: unknown;
|
|
569
|
+
constructor(message: string, zodError: ZodError, event: unknown);
|
|
570
|
+
/**
|
|
571
|
+
* Get formatted error messages
|
|
572
|
+
*/
|
|
573
|
+
get issues(): string[];
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Validate an event against a schema, throwing on failure
|
|
577
|
+
*
|
|
578
|
+
* @param schema - Zod schema to validate against
|
|
579
|
+
* @param event - Event to validate
|
|
580
|
+
* @returns Validated and typed event
|
|
581
|
+
* @throws EventValidationError if validation fails
|
|
582
|
+
*
|
|
583
|
+
* @example
|
|
584
|
+
* ```typescript
|
|
585
|
+
* try {
|
|
586
|
+
* const validEvent = validateEvent(TradeProposalCreatedSchema, rawEvent);
|
|
587
|
+
* // validEvent is typed as TradeProposalCreated
|
|
588
|
+
* } catch (error) {
|
|
589
|
+
* if (error instanceof EventValidationError) {
|
|
590
|
+
* console.error('Validation failed:', error.issues);
|
|
591
|
+
* }
|
|
592
|
+
* }
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
export declare function validateEvent<T extends z.ZodTypeAny>(schema: T, event: unknown): z.infer<T>;
|
|
596
|
+
/**
|
|
597
|
+
* Check if an event is valid without throwing
|
|
598
|
+
*
|
|
599
|
+
* @param schema - Zod schema to validate against
|
|
600
|
+
* @param event - Event to check
|
|
601
|
+
* @returns true if valid, false otherwise
|
|
602
|
+
*/
|
|
603
|
+
export declare function isValidEvent<T extends z.ZodTypeAny>(schema: T, event: unknown): event is z.infer<T>;
|
|
604
|
+
/**
|
|
605
|
+
* Parse an event, returning result with success/error
|
|
606
|
+
*
|
|
607
|
+
* @param schema - Zod schema to parse with
|
|
608
|
+
* @param event - Event to parse
|
|
609
|
+
* @returns SafeParseResult with data or error
|
|
610
|
+
*/
|
|
611
|
+
export declare function parseEvent<T extends z.ZodTypeAny>(schema: T, event: unknown): z.SafeParseReturnType<unknown, z.infer<T>>;
|
|
612
|
+
/**
|
|
613
|
+
* Validate base event structure (without specific data validation)
|
|
614
|
+
*/
|
|
615
|
+
export declare function validateBaseEvent(event: unknown): BaseEvent;
|
|
616
|
+
/**
|
|
617
|
+
* Check if value looks like a base event (duck typing)
|
|
618
|
+
*/
|
|
619
|
+
export declare function isBaseEventLike(value: unknown): value is BaseEvent;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @signaltree/events
|
|
3
|
+
*
|
|
4
|
+
* Event-driven architecture infrastructure for SignalTree applications.
|
|
5
|
+
* Provides a complete event bus system with validation, subscribers, and real-time sync.
|
|
6
|
+
*
|
|
7
|
+
* ## Subpaths
|
|
8
|
+
*
|
|
9
|
+
* - `@signaltree/events` - Core types, schemas, validation (framework-agnostic)
|
|
10
|
+
* - `@signaltree/events/nestjs` - NestJS integration (EventBusModule, BaseSubscriber)
|
|
11
|
+
* - `@signaltree/events/angular` - Angular integration (WebSocketService)
|
|
12
|
+
* - `@signaltree/events/testing` - Test utilities (MockEventBus, event factories)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Define your app events
|
|
17
|
+
* import { BaseEvent, createEventSchema, EventPriority } from '@signaltree/events';
|
|
18
|
+
* import { z } from 'zod';
|
|
19
|
+
*
|
|
20
|
+
* // Define event schema with Zod for runtime validation
|
|
21
|
+
* export const TradeProposalCreatedSchema = createEventSchema('TradeProposalCreated', {
|
|
22
|
+
* tradeId: z.string().uuid(),
|
|
23
|
+
* initiatorId: z.string().uuid(),
|
|
24
|
+
* recipientId: z.string().uuid(),
|
|
25
|
+
* vehicleOfferedId: z.string().uuid(),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* export type TradeProposalCreated = z.infer<typeof TradeProposalCreatedSchema>;
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // NestJS: Set up event bus
|
|
34
|
+
* import { EventBusModule } from '@signaltree/events/nestjs';
|
|
35
|
+
*
|
|
36
|
+
* @Module({
|
|
37
|
+
* imports: [
|
|
38
|
+
* EventBusModule.forRoot({
|
|
39
|
+
* redis: { host: 'localhost', port: 6379 },
|
|
40
|
+
* queues: ['critical', 'high', 'normal', 'low', 'bulk'],
|
|
41
|
+
* }),
|
|
42
|
+
* ],
|
|
43
|
+
* })
|
|
44
|
+
* export class AppModule {}
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @packageDocumentation
|
|
48
|
+
*/
|
|
49
|
+
export type { BaseEvent, EventMetadata, EventActor, EventPriority, EventVersion, } from './core/types';
|
|
50
|
+
export { EVENT_PRIORITIES, DEFAULT_EVENT_VERSION } from './core/types';
|
|
51
|
+
export { createEventSchema, BaseEventSchema, EventMetadataSchema, EventActorSchema, EventVersionSchema, validateEvent, isValidEvent, parseEvent, EventValidationError, } from './core/validation';
|
|
52
|
+
export { EventRegistry, createEventRegistry, type RegisteredEvent, type EventRegistryConfig, type EventCatalog, type EventCatalogEntry, } from './core/registry';
|
|
53
|
+
export { createEvent, createEventFactory, generateEventId, generateCorrelationId, type EventFactory, type EventFactoryConfig, type CreateEventOptions, } from './core/factory';
|
|
54
|
+
export { classifyError, isRetryableError, createErrorClassifier, defaultErrorClassifier, DEFAULT_RETRY_CONFIGS, type ErrorClassification, type RetryConfig, type ClassificationResult, type ErrorClassifier, type ErrorClassifierConfig, } from './core/error-classification';
|
|
55
|
+
export { InMemoryIdempotencyStore, createInMemoryIdempotencyStore, generateIdempotencyKey, generateCorrelationKey, type IdempotencyStore, type IdempotencyCheckResult, type IdempotencyCheckOptions, type ProcessedEventRecord, type InMemoryIdempotencyStoreConfig, } from './core/idempotency';
|
|
56
|
+
export { z } from 'zod';
|