alepha 0.10.2 → 0.10.4

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/topic.d.ts CHANGED
@@ -79,10 +79,10 @@ type UnSubscribeFn = () => Promise<void>;
79
79
  * name: "user-activity",
80
80
  * schema: {
81
81
  * payload: t.object({
82
- * userId: t.string(),
82
+ * userId: t.text(),
83
83
  * action: t.enum(["login", "logout", "purchase"]),
84
84
  * timestamp: t.number(),
85
- * metadata: t.optional(t.record(t.string(), t.any()))
85
+ * metadata: t.optional(t.record(t.text(), t.any()))
86
86
  * })
87
87
  * },
88
88
  * handler: async (message) => {
@@ -121,10 +121,10 @@ type UnSubscribeFn = () => Promise<void>;
121
121
  * description: "Real-time chat messages for all rooms",
122
122
  * schema: {
123
123
  * payload: t.object({
124
- * messageId: t.string(),
125
- * roomId: t.string(),
126
- * userId: t.string(),
127
- * content: t.string(),
124
+ * messageId: t.text(),
125
+ * roomId: t.text(),
126
+ * userId: t.text(),
127
+ * content: t.text(),
128
128
  * timestamp: t.number(),
129
129
  * messageType: t.enum(["text", "image", "file"])
130
130
  * })
@@ -169,70 +169,6 @@ type UnSubscribeFn = () => Promise<void>;
169
169
  * ```
170
170
  *
171
171
  * @example
172
- * **Event filtering and waiting for specific messages:**
173
- * ```ts
174
- * class OrderService {
175
- * orderEvents = $topic({
176
- * name: "order-events",
177
- * schema: {
178
- * payload: t.object({
179
- * orderId: t.string(),
180
- * status: t.union([
181
- * t.literal("created"),
182
- * t.literal("paid"),
183
- * t.literal("shipped"),
184
- * t.literal("delivered"),
185
- * t.literal("cancelled")
186
- * ]),
187
- * timestamp: t.number(),
188
- * data: t.optional(t.record(t.string(), t.any()))
189
- * })
190
- * }
191
- * });
192
- *
193
- * async processOrder(orderId: string) {
194
- * // Publish order created event
195
- * await this.orderEvents.publish({
196
- * orderId,
197
- * status: "created",
198
- * timestamp: Date.now()
199
- * });
200
- *
201
- * // Wait for payment confirmation with timeout
202
- * try {
203
- * const paymentEvent = await this.orderEvents.wait({
204
- * timeout: [5, "minutes"],
205
- * filter: (message) =>
206
- * message.payload.orderId === orderId &&
207
- * message.payload.status === "paid"
208
- * });
209
- *
210
- * console.log(`Order ${orderId} was paid at ${paymentEvent.payload.timestamp}`);
211
- *
212
- * // Continue with shipping...
213
- * await this.initiateShipping(orderId);
214
- *
215
- * } catch (error) {
216
- * if (error instanceof TopicTimeoutError) {
217
- * console.log(`Payment timeout for order ${orderId}`);
218
- * await this.cancelOrder(orderId);
219
- * }
220
- * }
221
- * }
222
- *
223
- * async setupOrderTracking() {
224
- * // Subscribe only to shipping events
225
- * await this.orderEvents.subscribe(async (message) => {
226
- * if (message.payload.status === "shipped") {
227
- * await this.updateTrackingInfo(message.payload.orderId, message.payload.data);
228
- * await this.notifyCustomer(message.payload.orderId, "Your order has shipped!");
229
- * }
230
- * });
231
- * }
232
- * }
233
- * ```
234
- *
235
- * @example
236
172
  * **Redis-backed topic for distributed systems:**
237
173
  * ```ts
238
174
  * class DistributedEventSystem {
@@ -241,11 +177,11 @@ type UnSubscribeFn = () => Promise<void>;
241
177
  * provider: RedisTopicProvider, // Use Redis for cross-service communication
242
178
  * schema: {
243
179
  * payload: t.object({
244
- * eventType: t.string(),
245
- * serviceId: t.string(),
246
- * data: t.record(t.string(), t.any()),
180
+ * eventType: t.text(),
181
+ * serviceId: t.text(),
182
+ * data: t.record(t.text(), t.any()),
247
183
  * timestamp: t.number(),
248
- * correlationId: t.optional(t.string())
184
+ * correlationId: t.optional(t.text())
249
185
  * })
250
186
  * },
251
187
  * handler: async (message) => {
@@ -380,15 +316,15 @@ interface TopicDescriptorOptions<T extends TopicMessageSchema> {
380
316
  * ```ts
381
317
  * {
382
318
  * payload: t.object({
383
- * eventId: t.string(),
319
+ * eventId: t.text(),
384
320
  * eventType: t.enum(["created", "updated"]),
385
- * data: t.record(t.string(), t.any()),
321
+ * data: t.record(t.text(), t.any()),
386
322
  * timestamp: t.number(),
387
- * userId: t.optional(t.string())
323
+ * userId: t.optional(t.text())
388
324
  * }),
389
325
  * headers: t.optional(t.object({
390
- * source: t.string(),
391
- * correlationId: t.string()
326
+ * source: t.text(),
327
+ * correlationId: t.text()
392
328
  * }))
393
329
  * }
394
330
  * ```
@@ -524,10 +460,10 @@ type TopicHandler<T extends TopicMessageSchema = TopicMessageSchema> = (message:
524
460
  * name: "user-activity",
525
461
  * schema: {
526
462
  * payload: t.object({
527
- * userId: t.string(),
463
+ * userId: t.text(),
528
464
  * action: t.enum(["login", "logout", "purchase"]),
529
465
  * timestamp: t.number(),
530
- * metadata: t.optional(t.record(t.string(), t.any()))
466
+ * metadata: t.optional(t.record(t.text(), t.any()))
531
467
  * })
532
468
  * }
533
469
  * });
@@ -563,77 +499,6 @@ type TopicHandler<T extends TopicMessageSchema = TopicMessageSchema> = (message:
563
499
  * ```
564
500
  *
565
501
  * @example
566
- * **Multiple specialized subscribers for different concerns:**
567
- * ```ts
568
- * class OrderEventHandlers {
569
- * orderEvents = $topic({
570
- * name: "order-events",
571
- * schema: {
572
- * payload: t.object({
573
- * orderId: t.string(),
574
- * customerId: t.string(),
575
- * status: t.union([
576
- * t.literal("created"),
577
- * t.literal("paid"),
578
- * t.literal("shipped"),
579
- * t.literal("delivered")
580
- * ]),
581
- * data: t.optional(t.record(t.string(), t.any()))
582
- * })
583
- * }
584
- * });
585
- *
586
- * // Analytics subscriber
587
- * analyticsSubscriber = $subscriber({
588
- * topic: this.orderEvents,
589
- * handler: async (message) => {
590
- * await this.analytics.track('order_status_changed', {
591
- * orderId: message.payload.orderId,
592
- * customerId: message.payload.customerId,
593
- * status: message.payload.status,
594
- * timestamp: Date.now()
595
- * });
596
- * }
597
- * });
598
- *
599
- * // Email notification subscriber
600
- * emailSubscriber = $subscriber({
601
- * topic: this.orderEvents,
602
- * handler: async (message) => {
603
- * const { customerId, orderId, status } = message.payload;
604
- *
605
- * const templates = {
606
- * 'paid': 'order-confirmation',
607
- * 'shipped': 'order-shipped',
608
- * 'delivered': 'order-delivered'
609
- * };
610
- *
611
- * const template = templates[status];
612
- * if (template) {
613
- * await this.emailService.send({
614
- * customerId,
615
- * template,
616
- * data: { orderId, status }
617
- * });
618
- * }
619
- * }
620
- * });
621
- *
622
- * // Inventory management subscriber
623
- * inventorySubscriber = $subscriber({
624
- * topic: this.orderEvents,
625
- * handler: async (message) => {
626
- * if (message.payload.status === 'paid') {
627
- * await this.inventoryService.reserveItems(message.payload.orderId);
628
- * } else if (message.payload.status === 'delivered') {
629
- * await this.inventoryService.confirmDelivery(message.payload.orderId);
630
- * }
631
- * }
632
- * });
633
- * }
634
- * ```
635
- *
636
- * @example
637
502
  * **Subscriber with advanced error handling and filtering:**
638
503
  * ```ts
639
504
  * class NotificationSubscriber {
@@ -641,11 +506,11 @@ type TopicHandler<T extends TopicMessageSchema = TopicMessageSchema> = (message:
641
506
  * name: "system-events",
642
507
  * schema: {
643
508
  * payload: t.object({
644
- * eventType: t.string(),
509
+ * eventType: t.text(),
645
510
  * severity: t.enum(["info", "warning", "error"]),
646
- * serviceId: t.string(),
647
- * message: t.string(),
648
- * data: t.optional(t.record(t.string(), t.any()))
511
+ * serviceId: t.text(),
512
+ * message: t.text(),
513
+ * data: t.optional(t.record(t.text(), t.any()))
649
514
  * })
650
515
  * }
651
516
  * });
@@ -714,12 +579,12 @@ type TopicHandler<T extends TopicMessageSchema = TopicMessageSchema> = (message:
714
579
  * name: "user-metrics",
715
580
  * schema: {
716
581
  * payload: t.object({
717
- * userId: t.string(),
718
- * sessionId: t.string(),
719
- * eventType: t.string(),
582
+ * userId: t.text(),
583
+ * sessionId: t.text(),
584
+ * eventType: t.text(),
720
585
  * timestamp: t.number(),
721
586
  * duration: t.optional(t.number()),
722
- * metadata: t.optional(t.record(t.string(), t.any()))
587
+ * metadata: t.optional(t.record(t.text(), t.any()))
723
588
  * })
724
589
  * }
725
590
  * });
@@ -794,7 +659,7 @@ interface SubscriberDescriptorOptions<T extends TopicMessageSchema> {
794
659
  * userEvents = $topic({
795
660
  * name: "user-activity",
796
661
  * schema: {
797
- * payload: t.object({ userId: t.string(), action: t.string() })
662
+ * payload: t.object({ userId: t.text(), action: t.text() })
798
663
  * }
799
664
  * });
800
665
  *