@prosody-events/prosody 0.4.0 → 0.5.0

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.
Files changed (6) hide show
  1. package/README.md +346 -239
  2. package/bindings.d.ts +430 -174
  3. package/bindings.js +211 -83
  4. package/index.d.ts +231 -34
  5. package/index.js +699 -246
  6. package/package.json +21 -21
package/bindings.d.ts CHANGED
@@ -31,6 +31,45 @@ export declare class AdminClient {
31
31
  deleteTopic(name: string): Promise<void>
32
32
  }
33
33
 
34
+ /** A Kafka excise record received from a consumer. */
35
+ export declare class ExciseMessage {
36
+ /** The Kafka topic this record was consumed from. */
37
+ get topic(): string
38
+ /** The partition number within the topic. */
39
+ get partition(): number
40
+ /** The offset of this record within its partition. */
41
+ get offset(): bigint
42
+ /** The timestamp when the record was produced. */
43
+ get timestamp(): Date
44
+ /** The key that this record excises. */
45
+ get key(): string
46
+ }
47
+
48
+ /** A Kafka message received from a consumer. */
49
+ export declare class Message {
50
+ /** The Kafka topic this message was consumed from. */
51
+ get topic(): string
52
+ /** The partition number within the topic. */
53
+ get partition(): number
54
+ /** The offset of this message within its partition. */
55
+ get offset(): bigint
56
+ /** The timestamp when the message was produced. */
57
+ get timestamp(): Date
58
+ /** The message key used for partitioning. */
59
+ get key(): string
60
+ /**
61
+ * The payload as the raw JSON text read from the wire.
62
+ *
63
+ * Borrowed from the wrapped message and copied once into a JavaScript
64
+ * string; no intermediate Rust buffer is allocated. The typed layer parses
65
+ * it lazily, so a handler that reads only metadata never pays for a parse.
66
+ *
67
+ * @throws Error if the payload is not valid UTF-8, which valid JSON always
68
+ * is.
69
+ */
70
+ get payload(): string
71
+ }
72
+
34
73
  /**
35
74
  * A native client wrapper for the Prosody high-level client.
36
75
  * Provides methods for sending messages, subscribing to topics, and managing
@@ -43,7 +82,7 @@ export declare class NativeClient {
43
82
  * @param config - The configuration for the client
44
83
  * @throws Error if the client creation fails
45
84
  */
46
- constructor(config: Configuration)
85
+ static create(config: Configuration): Promise<NativeClient>
47
86
  /**
48
87
  * Gets the current state of the consumer.
49
88
  *
@@ -51,19 +90,37 @@ export declare class NativeClient {
51
90
  * @throws Error if the operation fails
52
91
  */
53
92
  consumerState(): Promise<ConsumerState>
93
+ /** Builds a read-only view of a published value collection. */
94
+ publishedValue(subsystem: string, name: string, cacheMs?: number | undefined | null, cacheDisabled?: boolean | undefined | null): Promise<NativePublishedValue>
95
+ /** Builds a read-only view of a published map collection. */
96
+ publishedMap(subsystem: string, name: string, cacheMs?: number | undefined | null, cacheDisabled?: boolean | undefined | null): Promise<NativePublishedMap>
97
+ /** Builds a read-only view of a published deque collection. */
98
+ publishedDeque(subsystem: string, name: string, cacheMs?: number | undefined | null, cacheDisabled?: boolean | undefined | null): Promise<NativePublishedDeque>
54
99
  /**
55
100
  * Sends a message to a specified topic.
56
101
  *
102
+ * The payload crosses as its JSON text and is forwarded to Kafka verbatim;
103
+ * Rust never parses it. The caller supplies the event metadata, read off
104
+ * the payload object before it was serialized, so the boundary costs no
105
+ * JSON re-parse.
106
+ *
57
107
  * @param topic - The topic to send the message to
58
108
  * @param key - The key of the message
59
- * @param payload - The payload of the message (must be JSON-serializable)
109
+ * @param payload - The payload as JSON text
110
+ * @param metadata - The event metadata read off the payload object
60
111
  * @param otelContext - The OpenTelemetry context for tracing
61
112
  * @param maybeAbort - Optional promise that resolves when the operation
62
113
  * should be aborted @returns A promise that resolves when the message
63
114
  * has been sent @throws Error if the send operation fails or is
64
115
  * aborted
65
116
  */
66
- send(topic: string, key: string, payload: any, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<void>
117
+ send(topic: string, key: string, payload: string, metadata: EventMetadata, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<void>
118
+ /** Sends an excise record to a specified topic. */
119
+ excise(topic: string, key: string, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<void>
120
+ /** Sends one request and returns one outcome per subsystem. */
121
+ request(request: NativeRequest, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<Array<NativeSubsystemOutcome>>
122
+ /** Sends one excise request and returns one outcome per subsystem. */
123
+ requestExcise(request: NativeExciseRequest, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<Array<NativeSubsystemOutcome>>
67
124
  /**
68
125
  * Subscribes to receive messages using the provided event handler.
69
126
  *
@@ -71,7 +128,7 @@ export declare class NativeClient {
71
128
  * timers @returns A promise that resolves when the subscription is
72
129
  * established @throws Error if the subscription fails
73
130
  */
74
- subscribe(eventHandler: { onMessage: (err: null | Error, args: [NativeContext, Message, Record<string, string>]) => Promise<void>; onTimer: (err: null | Error, args: [NativeContext, Timer, Record<string, string>]) => Promise<void>; isPermanent: (args: [Error]) => boolean }): Promise<void>
131
+ subscribe(eventHandler: { onMessage: (err: null | Error, args: [NativeContext, Message, Record<string, string>]) => Promise<string>; onExcise: (err: null | Error, args: [NativeContext, ExciseMessage, Record<string, string>]) => Promise<string>; onTimer: (err: null | Error, args: [NativeContext, Timer, Record<string, string>]) => Promise<string>; isPermanent: (args: [Error]) => boolean }): Promise<void>
75
132
  /**
76
133
  * Gets the number of partitions assigned to the consumer.
77
134
  *
@@ -93,6 +150,13 @@ export declare class NativeClient {
93
150
  * complete @throws Error if the unsubscribe operation fails
94
151
  */
95
152
  unsubscribe(): Promise<void>
153
+ /**
154
+ * Shuts down the client and all its services.
155
+ *
156
+ * @returns A promise that resolves when shutdown is complete
157
+ * @throws Error if shutdown fails
158
+ */
159
+ shutdown(): Promise<void>
96
160
  /**
97
161
  * Gets the source system identifier configured for the client.
98
162
  *
@@ -171,7 +235,7 @@ export declare class NativeContext {
171
235
  * @throws Error (permanent) if the name is unregistered or its registered
172
236
  * identity mismatches.
173
237
  */
174
- valueState(name: string): NativeValueState
238
+ valueState(name: string): NativeJsonValueState
175
239
  /**
176
240
  * Vends the state handle for the named JSON map collection.
177
241
  *
@@ -184,7 +248,7 @@ export declare class NativeContext {
184
248
  * @throws Error (permanent) if the name is unregistered or its registered
185
249
  * identity mismatches.
186
250
  */
187
- mapState(name: string): NativeMapState
251
+ mapState(name: string): NativeJsonMapState
188
252
  /**
189
253
  * Vends the state handle for the named JSON deque collection.
190
254
  *
@@ -197,7 +261,7 @@ export declare class NativeContext {
197
261
  * @throws Error (permanent) if the name is unregistered or its registered
198
262
  * identity mismatches.
199
263
  */
200
- dequeState(name: string): NativeDequeState
264
+ dequeState(name: string): NativeJsonDequeState
201
265
  /**
202
266
  * Vends the state handle for the named Kafka-message value collection.
203
267
  *
@@ -209,7 +273,7 @@ export declare class NativeContext {
209
273
  * @throws Error (permanent) if the name is unregistered or its registered
210
274
  * identity mismatches.
211
275
  */
212
- messageValueState(name: string): NativeValueState
276
+ messageValueState(name: string): NativeMessageValueState
213
277
  /**
214
278
  * Vends the state handle for the named Kafka-message map collection.
215
279
  *
@@ -221,7 +285,7 @@ export declare class NativeContext {
221
285
  * @throws Error (permanent) if the name is unregistered or its registered
222
286
  * identity mismatches.
223
287
  */
224
- messageMapState(name: string): NativeMapState
288
+ messageMapState(name: string): NativeMessageMapState
225
289
  /**
226
290
  * Vends the state handle for the named Kafka-message deque collection.
227
291
  *
@@ -233,11 +297,19 @@ export declare class NativeContext {
233
297
  * @throws Error (permanent) if the name is unregistered or its registered
234
298
  * identity mismatches.
235
299
  */
236
- messageDequeState(name: string): NativeDequeState
300
+ messageDequeState(name: string): NativeMessageDequeState
301
+ }
302
+
303
+ /** Demand-driven cursor with one element type. */
304
+ export declare class NativeJsonDequeCursor {
305
+ /** Pulls the next ready chunk. */
306
+ nextChunk(otelContext: Record<string, string>): Promise<Array<string> | null>
307
+ /** Closes the cursor. */
308
+ close(): Promise<void>
237
309
  }
238
310
 
239
- /** Erased deque state handle, vended per event. */
240
- export declare class NativeDequeState {
311
+ /** JSON deque state handle for one event. */
312
+ export declare class NativeJsonDequeState {
241
313
  /**
242
314
  * The number of live elements.
243
315
  *
@@ -263,7 +335,7 @@ export declare class NativeDequeState {
263
335
  * @returns The element, or null past the end.
264
336
  * @throws Error carrying the category on `cause` if the read fails.
265
337
  */
266
- get(index: number, otelContext: Record<string, string>): Promise<any | Message | null>
338
+ get(index: number, otelContext: Record<string, string>): Promise<string | null>
267
339
  /**
268
340
  * Reads the front endpoint SLOT without a length round trip — exactly
269
341
  * `get(0)`.
@@ -276,7 +348,7 @@ export declare class NativeDequeState {
276
348
  * @returns The front element, or null when the endpoint slot is empty.
277
349
  * @throws Error carrying the category on `cause` if the read fails.
278
350
  */
279
- peekFront(otelContext: Record<string, string>): Promise<any | Message | null>
351
+ peekFront(otelContext: Record<string, string>): Promise<string | null>
280
352
  /**
281
353
  * Reads the back endpoint SLOT without a length round trip — exactly
282
354
  * `get(len − 1)`.
@@ -289,31 +361,29 @@ export declare class NativeDequeState {
289
361
  * @returns The back element, or null when the endpoint slot is empty.
290
362
  * @throws Error carrying the category on `cause` if the read fails.
291
363
  */
292
- peekBack(otelContext: Record<string, string>): Promise<any | Message | null>
364
+ peekBack(otelContext: Record<string, string>): Promise<string | null>
293
365
  /**
294
- * Appends an element at the back.
366
+ * Appends a JSON document at the back.
295
367
  *
296
368
  * JSON null is not a storable element and is rejected with a transient
297
- * error. An item-shape mismatch is a caller mistake and is likewise
298
- * transient (it retries and stays visible, never discarded).
369
+ * error.
299
370
  *
300
- * @param item The value (JSON) or message to append.
371
+ * @param json The document's JSON text.
301
372
  * @param otelContext The OpenTelemetry context for tracing.
302
373
  * @throws Error carrying the category on `cause` if the write fails.
303
374
  */
304
- pushBack(item: any, otelContext: Record<string, string>): Promise<void>
375
+ pushBack(json: string, otelContext: Record<string, string>): Promise<void>
305
376
  /**
306
- * Prepends an element at the front.
377
+ * Prepends a JSON document at the front.
307
378
  *
308
379
  * JSON null is not a storable element and is rejected with a transient
309
- * error. An item-shape mismatch is a caller mistake and is likewise
310
- * transient (it retries and stays visible, never discarded).
380
+ * error.
311
381
  *
312
- * @param item The value (JSON) or message to prepend.
382
+ * @param json The document's JSON text.
313
383
  * @param otelContext The OpenTelemetry context for tracing.
314
384
  * @throws Error carrying the category on `cause` if the write fails.
315
385
  */
316
- pushFront(item: any, otelContext: Record<string, string>): Promise<void>
386
+ pushFront(json: string, otelContext: Record<string, string>): Promise<void>
317
387
  /**
318
388
  * Removes and returns the front element.
319
389
  *
@@ -321,7 +391,7 @@ export declare class NativeDequeState {
321
391
  * @returns The removed front element, or null when empty.
322
392
  * @throws Error carrying the category on `cause` if the operation fails.
323
393
  */
324
- popFront(otelContext: Record<string, string>): Promise<any | Message | null>
394
+ popFront(otelContext: Record<string, string>): Promise<string | null>
325
395
  /**
326
396
  * Removes and returns the back element.
327
397
  *
@@ -329,7 +399,7 @@ export declare class NativeDequeState {
329
399
  * @returns The removed back element, or null when empty.
330
400
  * @throws Error carrying the category on `cause` if the operation fails.
331
401
  */
332
- popBack(otelContext: Record<string, string>): Promise<any | Message | null>
402
+ popBack(otelContext: Record<string, string>): Promise<string | null>
333
403
  /**
334
404
  * Removes every element.
335
405
  *
@@ -349,24 +419,23 @@ export declare class NativeDequeState {
349
419
  * @returns A cursor over the deque elements.
350
420
  * @throws Error if the direction token is invalid.
351
421
  */
352
- scan(direction: string, otelContext: Record<string, string>): NativeStateCursor
353
- /**
354
- * Durably commits the buffered operations mid-handler.
355
- *
356
- * @param otelContext The OpenTelemetry context for tracing.
357
- * @throws Error carrying the category on `cause` if the commit fails.
358
- */
422
+ scan(direction: string, otelContext: Record<string, string>): NativeJsonDequeCursor
423
+ /** Durably commits the buffered operations. */
359
424
  commit(otelContext: Record<string, string>): Promise<void>
360
- /**
361
- * Discards the buffered uncommitted operations.
362
- *
363
- * @param otelContext The OpenTelemetry context for tracing.
364
- */
425
+ /** Discards the buffered operations. */
365
426
  rollback(otelContext: Record<string, string>): Promise<void>
366
427
  }
367
428
 
368
- /** Erased ordered-map state handle, keyed by `String`, vended per event. */
369
- export declare class NativeMapState {
429
+ /** Demand-driven cursor with one element type. */
430
+ export declare class NativeJsonMapCursor {
431
+ /** Pulls the next ready chunk. */
432
+ nextChunk(otelContext: Record<string, string>): Promise<Array<[string, string]> | null>
433
+ /** Closes the cursor. */
434
+ close(): Promise<void>
435
+ }
436
+
437
+ /** JSON ordered-map state handle for one event. */
438
+ export declare class NativeJsonMapState {
370
439
  /**
371
440
  * Reads the value for `key`.
372
441
  *
@@ -375,7 +444,7 @@ export declare class NativeMapState {
375
444
  * @returns The value, or null when the key is absent.
376
445
  * @throws Error carrying the category on `cause` if the read fails.
377
446
  */
378
- get(key: string, otelContext: Record<string, string>): Promise<any | Message | null>
447
+ get(key: string, otelContext: Record<string, string>): Promise<string | null>
379
448
  /**
380
449
  * Reads several keys in a single call.
381
450
  *
@@ -390,7 +459,7 @@ export declare class NativeMapState {
390
459
  * @returns One result per input key; null for a key that is absent.
391
460
  * @throws Error carrying the category on `cause` if the read fails.
392
461
  */
393
- getMany(keys: Array<string>, otelContext: Record<string, string>): Promise<Array<any | Message | undefined | null>>
462
+ getMany(keys: Array<string>, otelContext: Record<string, string>): Promise<Array<string | undefined | null>>
394
463
  /**
395
464
  * Reports whether a stored cell exists for `key`.
396
465
  *
@@ -408,18 +477,17 @@ export declare class NativeMapState {
408
477
  */
409
478
  contains(key: string, otelContext: Record<string, string>): Promise<boolean>
410
479
  /**
411
- * Inserts or overwrites `key`.
480
+ * Inserts or overwrites `key` with a JSON document.
412
481
  *
413
482
  * JSON null is rejected with a transient error naming `delete` as the way
414
- * to remove an entry. An item-shape mismatch is a caller mistake and is
415
- * likewise transient (it retries and stays visible, never discarded).
483
+ * to remove an entry.
416
484
  *
417
485
  * @param key The map key.
418
- * @param item The value (JSON) or message to store.
486
+ * @param json The document's JSON text.
419
487
  * @param otelContext The OpenTelemetry context for tracing.
420
488
  * @throws Error carrying the category on `cause` if the write fails.
421
489
  */
422
- set(key: string, item: any, otelContext: Record<string, string>): Promise<void>
490
+ set(key: string, json: string, otelContext: Record<string, string>): Promise<void>
423
491
  /**
424
492
  * Removes `key`.
425
493
  *
@@ -447,7 +515,7 @@ export declare class NativeMapState {
447
515
  * @returns A cursor over the map entries.
448
516
  * @throws Error if the direction token is invalid.
449
517
  */
450
- scan(direction: string, otelContext: Record<string, string>): NativeStateCursor
518
+ scan(direction: string, otelContext: Record<string, string>): NativeJsonMapCursor
451
519
  /**
452
520
  * Opens a demand-driven cursor over the live KEYS in key order.
453
521
  *
@@ -462,63 +530,15 @@ export declare class NativeMapState {
462
530
  * @returns A cursor over the map keys.
463
531
  * @throws Error if the direction token is invalid.
464
532
  */
465
- keys(direction: string, otelContext: Record<string, string>): NativeStateCursor
466
- /**
467
- * Durably commits the buffered operations mid-handler.
468
- *
469
- * @param otelContext The OpenTelemetry context for tracing.
470
- * @throws Error carrying the category on `cause` if the commit fails.
471
- */
533
+ keys(direction: string, otelContext: Record<string, string>): NativeMapKeyCursor
534
+ /** Durably commits the buffered operations. */
472
535
  commit(otelContext: Record<string, string>): Promise<void>
473
- /**
474
- * Discards the buffered uncommitted operations.
475
- *
476
- * @param otelContext The OpenTelemetry context for tracing.
477
- */
536
+ /** Discards the buffered operations. */
478
537
  rollback(otelContext: Record<string, string>): Promise<void>
479
538
  }
480
539
 
481
- /**
482
- * Demand-driven scan cursor over a map or deque collection.
483
- *
484
- * Pulling is lazy: each `next_chunk()` restores the JavaScript context without
485
- * creating a binding span, awaits one stream item, and asks core to drain only
486
- * the immediately-ready tail. Chunking,
487
- * exhaustion, error ordering, serialization, close-idempotence, and
488
- * use-after-close behavior are core-owned; this layer only transports.
489
- */
490
- export declare class NativeStateCursor {
491
- /**
492
- * Pulls the next immediately-ready chunk of scanned items.
493
- *
494
- * Awaits the first item, then drains up to 255 more items only while they
495
- * are immediately ready. This amortizes N-API overhead without waiting to
496
- * fill a chunk.
497
- *
498
- * @param otelContext The OpenTelemetry context for tracing.
499
- * @returns The next non-empty vector of items, or null when exhausted.
500
- * @throws Error carrying the category on `cause` if the pull fails or the
501
- * cursor was closed.
502
- */
503
- nextChunk(otelContext: Record<string, string>): Promise<Array<any | [string, any] | Message | [string, Message]> | null>
504
- /**
505
- * Closes the cursor, releasing the underlying stream.
506
- *
507
- * Idempotent; a subsequent `next_chunk()` errors. No span — pure teardown.
508
- *
509
- * @returns A promise that resolves when the cursor is closed.
510
- */
511
- close(): Promise<void>
512
- }
513
-
514
- /**
515
- * Erased single-value state handle, vended per event.
516
- *
517
- * Wraps the boxed erased value handle plus the propagator used to open each
518
- * operation's span. Values cross as JSON; message collections cross as the
519
- * `Message` object.
520
- */
521
- export declare class NativeValueState {
540
+ /** JSON single-value state handle for one event. */
541
+ export declare class NativeJsonValueState {
522
542
  /**
523
543
  * Reads the current value.
524
544
  *
@@ -526,20 +546,18 @@ export declare class NativeValueState {
526
546
  * @returns The current value, or null when absent/cleared.
527
547
  * @throws Error carrying the category on `cause` if the read fails.
528
548
  */
529
- get(otelContext: Record<string, string>): Promise<any | Message | null>
549
+ get(otelContext: Record<string, string>): Promise<string | null>
530
550
  /**
531
- * Buffers a write of the value.
551
+ * Buffers a write of a JSON document.
532
552
  *
533
553
  * JSON null is rejected with a transient error naming `clear` as the way
534
- * to delete. A message-shaped payload cannot be stored in a JSON
535
- * collection (and vice versa); such a mismatch is a caller mistake and is
536
- * likewise transient (it retries and stays visible, never discarded).
554
+ * to delete.
537
555
  *
538
- * @param item The value (JSON) or message to write.
556
+ * @param json The document's JSON text.
539
557
  * @param otelContext The OpenTelemetry context for tracing.
540
558
  * @throws Error carrying the category on `cause` if the write fails.
541
559
  */
542
- set(item: any, otelContext: Record<string, string>): Promise<void>
560
+ set(json: string, otelContext: Record<string, string>): Promise<void>
543
561
  /**
544
562
  * Buffers a clear of the value.
545
563
  *
@@ -547,23 +565,140 @@ export declare class NativeValueState {
547
565
  * @throws Error carrying the category on `cause` if the clear fails.
548
566
  */
549
567
  clear(otelContext: Record<string, string>): Promise<void>
550
- /**
551
- * Durably commits the buffered operations mid-handler.
552
- *
553
- * @param otelContext The OpenTelemetry context for tracing.
554
- * @throws Error carrying the category on `cause` if the commit fails.
555
- */
568
+ /** Durably commits the buffered operations. */
556
569
  commit(otelContext: Record<string, string>): Promise<void>
557
- /**
558
- * Discards the buffered uncommitted operations.
559
- *
560
- * Infallible: rolling back a terminated session is a no-op.
561
- *
562
- * @param otelContext The OpenTelemetry context for tracing.
563
- */
570
+ /** Discards the buffered operations. */
564
571
  rollback(otelContext: Record<string, string>): Promise<void>
565
572
  }
566
573
 
574
+ /** Demand-driven cursor with one element type. */
575
+ export declare class NativeMapKeyCursor {
576
+ /** Pulls the next ready chunk. */
577
+ nextChunk(otelContext: Record<string, string>): Promise<Array<string> | null>
578
+ /** Closes the cursor. */
579
+ close(): Promise<void>
580
+ }
581
+
582
+ /** Demand-driven cursor with one element type. */
583
+ export declare class NativeMessageDequeCursor {
584
+ /** Pulls the next ready chunk. */
585
+ nextChunk(otelContext: Record<string, string>): Promise<Array<Message> | null>
586
+ /** Closes the cursor. */
587
+ close(): Promise<void>
588
+ }
589
+
590
+ /** Kafka-message deque state handle for one event. */
591
+ export declare class NativeMessageDequeState {
592
+ /** Returns the number of live elements. */
593
+ len(otelContext: Record<string, string>): Promise<number>
594
+ /** Reports whether the deque has no live elements. */
595
+ isEmpty(otelContext: Record<string, string>): Promise<boolean>
596
+ /** Reads one element by its position from the front. */
597
+ get(index: number, otelContext: Record<string, string>): Promise<Message | null>
598
+ /** Reads the front endpoint. */
599
+ peekFront(otelContext: Record<string, string>): Promise<Message | null>
600
+ /** Reads the back endpoint. */
601
+ peekBack(otelContext: Record<string, string>): Promise<Message | null>
602
+ /** Appends a Kafka message. */
603
+ pushBack(message: Message, otelContext: Record<string, string>): Promise<void>
604
+ /** Prepends a Kafka message. */
605
+ pushFront(message: Message, otelContext: Record<string, string>): Promise<void>
606
+ /** Removes and returns the front element. */
607
+ popFront(otelContext: Record<string, string>): Promise<Message | null>
608
+ /** Removes and returns the back element. */
609
+ popBack(otelContext: Record<string, string>): Promise<Message | null>
610
+ /** Removes every element. */
611
+ clear(otelContext: Record<string, string>): Promise<void>
612
+ /** Opens a cursor over the live elements. */
613
+ scan(direction: string, otelContext: Record<string, string>): NativeMessageDequeCursor
614
+ /** Durably commits the buffered operations. */
615
+ commit(otelContext: Record<string, string>): Promise<void>
616
+ /** Discards the buffered operations. */
617
+ rollback(otelContext: Record<string, string>): Promise<void>
618
+ }
619
+
620
+ /** Demand-driven cursor with one element type. */
621
+ export declare class NativeMessageMapCursor {
622
+ /** Pulls the next ready chunk. */
623
+ nextChunk(otelContext: Record<string, string>): Promise<Array<[string, Message]> | null>
624
+ /** Closes the cursor. */
625
+ close(): Promise<void>
626
+ }
627
+
628
+ /** Kafka-message ordered-map state handle for one event. */
629
+ export declare class NativeMessageMapState {
630
+ /** Reads the value for `key`. */
631
+ get(key: string, otelContext: Record<string, string>): Promise<Message | null>
632
+ /** Reads several keys in one operation. */
633
+ getMany(keys: Array<string>, otelContext: Record<string, string>): Promise<Array<Message | undefined | null>>
634
+ /** Reports whether `key` has a stored cell. */
635
+ contains(key: string, otelContext: Record<string, string>): Promise<boolean>
636
+ /** Inserts or overwrites `key` with a Kafka message. */
637
+ set(key: string, message: Message, otelContext: Record<string, string>): Promise<void>
638
+ /** Removes `key`. */
639
+ remove(key: string, otelContext: Record<string, string>): Promise<void>
640
+ /** Removes every entry. */
641
+ clear(otelContext: Record<string, string>): Promise<void>
642
+ /** Opens a cursor over entries in key order. */
643
+ scan(direction: string, otelContext: Record<string, string>): NativeMessageMapCursor
644
+ /** Opens a cursor over keys in key order. */
645
+ keys(direction: string, otelContext: Record<string, string>): NativeMapKeyCursor
646
+ /** Durably commits the buffered operations. */
647
+ commit(otelContext: Record<string, string>): Promise<void>
648
+ /** Discards the buffered operations. */
649
+ rollback(otelContext: Record<string, string>): Promise<void>
650
+ }
651
+
652
+ /** Kafka-message single-value state handle for one event. */
653
+ export declare class NativeMessageValueState {
654
+ /** Reads the current value. */
655
+ get(otelContext: Record<string, string>): Promise<Message | null>
656
+ /** Buffers a write of a Kafka message. */
657
+ set(message: Message, otelContext: Record<string, string>): Promise<void>
658
+ /** Buffers a clear of the value. */
659
+ clear(otelContext: Record<string, string>): Promise<void>
660
+ /** Durably commits the buffered operations. */
661
+ commit(otelContext: Record<string, string>): Promise<void>
662
+ /** Discards the buffered operations. */
663
+ rollback(otelContext: Record<string, string>): Promise<void>
664
+ }
665
+
666
+ /** A read-only published deque collection. */
667
+ export declare class NativePublishedDeque {
668
+ /** Reads one front-relative element. */
669
+ get(key: string, index: number, otelContext: Record<string, string>): Promise<string | null>
670
+ /** Returns the committed deque length. */
671
+ length(key: string, otelContext: Record<string, string>): Promise<number>
672
+ /** Reports whether the committed deque is empty. */
673
+ isEmpty(key: string, otelContext: Record<string, string>): Promise<boolean>
674
+ /** Reads the committed front element. */
675
+ peekFront(key: string, otelContext: Record<string, string>): Promise<string | null>
676
+ /** Reads the committed back element. */
677
+ peekBack(key: string, otelContext: Record<string, string>): Promise<string | null>
678
+ /** Opens an ordered element cursor. */
679
+ scan(key: string, direction: string, otelContext: Record<string, string>): Promise<NativeJsonDequeCursor>
680
+ }
681
+
682
+ /** A read-only published map collection. */
683
+ export declare class NativePublishedMap {
684
+ /** Reads one committed map entry. */
685
+ get(key: string, mapKey: string, otelContext: Record<string, string>): Promise<string | null>
686
+ /** Reads entries aligned with the supplied map keys. */
687
+ getMany(key: string, mapKeys: Array<string>, otelContext: Record<string, string>): Promise<Array<string | undefined | null>>
688
+ /** Reports whether a committed map entry exists. */
689
+ contains(key: string, mapKey: string, otelContext: Record<string, string>): Promise<boolean>
690
+ /** Opens an ordered entry cursor. */
691
+ scan(key: string, direction: string, otelContext: Record<string, string>): Promise<NativeJsonMapCursor>
692
+ /** Opens an ordered key cursor. */
693
+ keys(key: string, direction: string, otelContext: Record<string, string>): Promise<NativeMapKeyCursor>
694
+ }
695
+
696
+ /** A read-only published value collection. */
697
+ export declare class NativePublishedValue {
698
+ /** Reads the committed value for a partition key. */
699
+ get(key: string, otelContext: Record<string, string>): Promise<string | null>
700
+ }
701
+
567
702
  /** Configuration options for the Prosody client. */
568
703
  export interface Configuration {
569
704
  /** Kafka servers for initial connection. */
@@ -635,7 +770,7 @@ export interface Configuration {
635
770
  slabSizeMs?: number
636
771
  /** Cassandra contact nodes (hostnames or IPs). */
637
772
  cassandraNodes?: string | Array<string>
638
- /** Cassandra keyspace to use for storing timer data. */
773
+ /** Cassandra keyspace used for persistent Prosody data. */
639
774
  cassandraKeyspace?: string
640
775
  /** Preferred Cassandra datacenter for query routing. */
641
776
  cassandraDatacenter?: string
@@ -646,8 +781,8 @@ export interface Configuration {
646
781
  /** Password for authenticating with Cassandra. */
647
782
  cassandraPassword?: string
648
783
  /**
649
- * Retention period for failed/unprocessed timer data in Cassandra in
650
- * seconds.
784
+ * Retention period for persistent timer and deferral data in Cassandra,
785
+ * in seconds.
651
786
  */
652
787
  cassandraRetentionSeconds?: number
653
788
  /**
@@ -709,29 +844,33 @@ export interface Configuration {
709
844
  */
710
845
  deferMaxDelayMs?: number
711
846
  /**
712
- * Failure rate threshold for enabling deferral (0.0 to 1.0).
847
+ * Failure rate threshold for disabling deferral (0.0 to 1.0).
713
848
  * When exceeded within the failure window, deferral is disabled.
714
849
  */
715
850
  deferFailureThreshold?: number
716
851
  /** Sliding window duration (in milliseconds) for failure rate tracking. */
717
852
  deferFailureWindowMs?: number
718
- /**
719
- * Cache size for the deferred-retry message loader.
720
- * Controls capacity for the loader cache.
721
- */
722
- deferCacheSize?: number
723
853
  /**
724
854
  * Maximum deferred store cache entries per Cassandra defer store.
725
855
  * Env: `PROSODY_DEFER_STORE_CACHE_SIZE`. Default: 8192.
726
856
  */
727
857
  deferStoreCacheSize?: number
728
- /** Timeout for Kafka seek operations in milliseconds. */
729
- deferSeekTimeoutMs?: number
858
+ /**
859
+ * Capacity of the shared Kafka message loader cache.
860
+ * Env: `PROSODY_LOADER_CACHE_SIZE`. Default: 1024.
861
+ */
862
+ loaderCacheSize?: number
863
+ /**
864
+ * Timeout for Kafka loader seek operations in milliseconds.
865
+ * Env: `PROSODY_LOADER_SEEK_TIMEOUT`. Default: 30 seconds.
866
+ */
867
+ loaderSeekTimeoutMs?: number
730
868
  /**
731
869
  * Messages to read sequentially before seeking.
732
870
  * If next offset is within this threshold, reads rather than seeks.
871
+ * Env: `PROSODY_LOADER_DISCARD_THRESHOLD`. Default: 100.
733
872
  */
734
- deferDiscardThreshold?: number
873
+ loaderDiscardThreshold?: number
735
874
  /**
736
875
  * Fixed timeout duration for handler execution in milliseconds.
737
876
  * If unset, defaults to 80% of stall threshold.
@@ -774,11 +913,22 @@ export interface Configuration {
774
913
  */
775
914
  stateCacheDir?: string
776
915
  /**
777
- * Capacity of the in-memory keyed-state cache, in bytes. Falls back to
778
- * `PROSODY_STATE_CACHE_SIZE_BYTES`,
779
- * then to the storage-engine default. Must be a positive safe integer.
916
+ * Capacity of the owning keyed-state cache. Accepts a human-readable size.
917
+ * Uses `PROSODY_STATE_OWNED_CACHE_SIZE` when omitted. Otherwise, the
918
+ * storage engine selects its default.
780
919
  */
781
- stateCacheSizeBytes?: number
920
+ stateOwnedCacheSize?: string
921
+ /**
922
+ * Capacity of the published-state read-through cache. Uses
923
+ * `PROSODY_STATE_READ_CACHE_SIZE` when omitted. It then uses the owning
924
+ * cache size when set, or 1 MiB when both sizes are unset.
925
+ */
926
+ stateReadCacheSize?: string
927
+ /**
928
+ * Default cache policy for published-state reads. Uses
929
+ * `PROSODY_STATE_READ_CACHE_TTL` when omitted, then 5 seconds.
930
+ */
931
+ stateReadCache?: ReadCacheConfiguration
782
932
  /**
783
933
  * Delay in whole seconds between staging a provisional cell and the
784
934
  * keyed-state recovery sweep. Every registered TTL must strictly exceed
@@ -788,21 +938,75 @@ export interface Configuration {
788
938
  * non-finite values are rejected).
789
939
  */
790
940
  stateRecoveryDelaySeconds?: number
941
+ /**
942
+ * Subsystem under which published JSON collections are advertised.
943
+ * Uses `PROSODY_SUBSYSTEM` when omitted. Published collections require it.
944
+ */
945
+ subsystem?: string
946
+ /**
947
+ * Socket address for the peer gRPC listener. Uses
948
+ * `PROSODY_PEER_BIND_ADDRESS` when omitted.
949
+ */
950
+ peerBindAddress?: string
951
+ /**
952
+ * gRPC connect URI that remote peers use. Uses
953
+ * `PROSODY_PEER_ADVERTISED_CONNECT` when omitted.
954
+ */
955
+ peerAdvertisedConnect?: string
956
+ /**
957
+ * Network name used to select direct peer routes. Uses
958
+ * `PROSODY_PEER_NETWORK_NAME` when omitted.
959
+ */
960
+ peerNetworkName?: string
961
+ /**
962
+ * Maximum channels and peer records in each peer cache. Uses
963
+ * `PROSODY_PEER_CACHE_CAPACITY` when omitted.
964
+ */
965
+ peerCacheCapacity?: number
966
+ /**
967
+ * Peer registration lease duration in seconds. Uses
968
+ * `PROSODY_PEER_REGISTRATION_TTL` when omitted.
969
+ */
970
+ peerRegistrationTtlSeconds?: number
791
971
  }
792
972
 
793
- /**
794
- * Current state of the consumer.
795
- * Represents the lifecycle stages of a Prosody consumer.
796
- */
797
- export type ConsumerState = /** The consumer is not yet configured */
973
+ /** Current consumer state. */
974
+ export type ConsumerState = /** The client is shut down. */
975
+ 'Shutdown'|
976
+ /** The consumer is not configured. */
798
977
  'Unconfigured'|
799
- /** The consumer is configured but not running */
978
+ /** The consumer is configured but not active. */
800
979
  'Configured'|
801
- /** The consumer is actively running */
980
+ /** The consumer is active. */
802
981
  'Running'|
803
- /** The consumer configuration failed */
982
+ /** The consumer configuration failed. */
804
983
  'ConfigurationFailed';
805
984
 
985
+ /**
986
+ * Event metadata read off a payload before it was serialized.
987
+ *
988
+ * It lets the send path forward the payload without another parse.
989
+ */
990
+ export interface EventMetadata {
991
+ /** The payload's `id` field. */
992
+ eventId?: string
993
+ /** The payload's `type` field. */
994
+ eventType?: string
995
+ }
996
+
997
+ /** Type alias for excise handler arguments. */
998
+ export type ExciseHandlerArgs =
999
+ [NativeContext, ExciseMessage, Record<string, string>]
1000
+
1001
+ /**
1002
+ * Exports all pending telemetry data.
1003
+ *
1004
+ * # Errors
1005
+ *
1006
+ * Returns an error if an exporter cannot flush its pending data.
1007
+ */
1008
+ export declare function flushTelemetry(): void
1009
+
806
1010
  /**
807
1011
  * Initializes the logging system for the Prosody client.
808
1012
  *
@@ -841,27 +1045,6 @@ export interface Logger {
841
1045
  */
842
1046
  export declare function loggerIsSet(): boolean
843
1047
 
844
- /**
845
- * Represents a message consumed from a Kafka topic.
846
- *
847
- * This object contains all the relevant information about a Kafka message,
848
- * including its topic, partition, offset, timestamp, key, and payload.
849
- */
850
- export interface Message {
851
- /** The name of the topic from which the message was consumed. */
852
- topic: string
853
- /** The partition number from which the message was consumed. */
854
- partition: number
855
- /** The message offset within the partition. */
856
- offset: bigint
857
- /** The timestamp when the message was created or sent to Kafka. */
858
- timestamp: Date
859
- /** The message key. */
860
- key: string
861
- /** The message payload as a JSON-serializable value. */
862
- payload: any
863
- }
864
-
865
1048
  /** Type alias for message handler arguments. */
866
1049
  export type MessageHandlerArgs =
867
1050
  [NativeContext, Message, Record<string, string>]
@@ -877,6 +1060,18 @@ export type Mode = /** Pipeline mode for standard processing. */
877
1060
  */
878
1061
  'BestEffort';
879
1062
 
1063
+ /** One excise subsystem request. */
1064
+ export interface NativeExciseRequest {
1065
+ /** Kafka topic. */
1066
+ topic: string
1067
+ /** Message key. */
1068
+ key: string
1069
+ /** Subsystems that must respond. */
1070
+ subsystems: Array<string>
1071
+ /** Response deadline in milliseconds. */
1072
+ timeoutMs: number
1073
+ }
1074
+
880
1075
  /**
881
1076
  * Represents a native handler for processing messages and timers.
882
1077
  *
@@ -895,7 +1090,9 @@ export interface NativeHandler {
895
1090
  *
896
1091
  * Note: Error parameter is automatically added by CalleeHandled=true
897
1092
  */
898
- onMessage: (arg: MessageHandlerArgs) => Promise<undefined>
1093
+ onMessage: (arg: MessageHandlerArgs) => Promise<string>
1094
+ /** A function to call when an excise record arrives. */
1095
+ onExcise: (arg: ExciseHandlerArgs) => Promise<string>
899
1096
  /**
900
1097
  * A function to be called when a timer fires.
901
1098
  *
@@ -907,7 +1104,7 @@ export interface NativeHandler {
907
1104
  *
908
1105
  * Note: Error parameter is automatically added by CalleeHandled=true
909
1106
  */
910
- onTimer: (arg: TimerHandlerArgs) => Promise<undefined>
1107
+ onTimer: (arg: TimerHandlerArgs) => Promise<string>
911
1108
  /**
912
1109
  * Function that determines whether an error is permanent.
913
1110
  *
@@ -918,6 +1115,52 @@ export interface NativeHandler {
918
1115
  isPermanent: (arg: IsPermanentArgs) => boolean
919
1116
  }
920
1117
 
1118
+ /** One subsystem request. */
1119
+ export interface NativeRequest {
1120
+ /** Kafka topic. */
1121
+ topic: string
1122
+ /** Message key. */
1123
+ key: string
1124
+ /** JSON payload text. */
1125
+ payload: string
1126
+ /** Event metadata read before serialization. */
1127
+ metadata: EventMetadata
1128
+ /** Subsystems that must respond. */
1129
+ subsystems: Array<string>
1130
+ /** Response deadline in milliseconds. */
1131
+ timeoutMs: number
1132
+ }
1133
+
1134
+ /** One response failure. */
1135
+ export interface NativeResponseError {
1136
+ /** Failure discriminator. */
1137
+ kind: NativeResponseErrorKind
1138
+ /** Failure text. */
1139
+ message: string
1140
+ }
1141
+
1142
+ /** One response failure kind. */
1143
+ export type NativeResponseErrorKind = 'handler'|
1144
+ 'timeout'|
1145
+ 'formatMismatch'|
1146
+ 'malformedResponse';
1147
+
1148
+ /** One subsystem and its outcome. */
1149
+ export interface NativeSubsystemOutcome {
1150
+ /** Canonical subsystem name. */
1151
+ subsystem: string
1152
+ /** Encoded response or failure. */
1153
+ outcome: string | NativeResponseError
1154
+ }
1155
+
1156
+ /** Default cache policy for published-state reads. */
1157
+ export interface ReadCacheConfiguration {
1158
+ /** Cache duration in milliseconds. */
1159
+ ttlMs?: number
1160
+ /** Read durable storage on every operation. */
1161
+ disabled?: boolean
1162
+ }
1163
+
921
1164
  /**
922
1165
  * Sets a new JavaScript logger for the Prosody client.
923
1166
  *
@@ -944,11 +1187,22 @@ export declare function setLogger(logger: Logger): void
944
1187
  */
945
1188
  export declare function setLoggerIfUnset(logger: Logger): boolean
946
1189
 
1190
+ /**
1191
+ * Stops the global telemetry providers after they export pending data.
1192
+ *
1193
+ * Call this function only when the Node.js process no longer needs telemetry.
1194
+ *
1195
+ * # Errors
1196
+ *
1197
+ * Returns an error if a provider cannot stop.
1198
+ */
1199
+ export declare function shutdownTelemetry(): void
1200
+
947
1201
  /** Declares one keyed-state collection to register before subscribe. */
948
1202
  export interface StateCollectionConfig {
949
1203
  /**
950
- * The collection name. Must be non-empty and unique within the client's
951
- * definition set.
1204
+ * The collection name. Prosody requires it to be non-empty and unique
1205
+ * within the definition set.
952
1206
  */
953
1207
  name: string
954
1208
  /** The collection kind: `"value"`, `"map"`, or `"deque"`. */
@@ -969,11 +1223,13 @@ export interface StateCollectionConfig {
969
1223
  * once). Defaults to transactional.
970
1224
  */
971
1225
  readUncommitted?: boolean
1226
+ /** Whether other consumer groups may read this collection. */
1227
+ published?: boolean
972
1228
  /**
973
1229
  * Optional map-only keyset bound (`0..=4096`; default 128 core-side; `0`
974
- * disables ordered-scan tracking). Must be a whole number in that range
975
- * (fractional, negative, and non-finite values are rejected). Invalid on
976
- * value or deque collections.
1230
+ * disables ordered-scan tracking). The binding rejects values that cannot
1231
+ * map to an unsigned integer. Prosody enforces the semantic ceiling.
1232
+ * Invalid on value or deque collections.
977
1233
  */
978
1234
  keysetLimit?: number
979
1235
  /**