@prosody-events/prosody 0.5.0 → 0.6.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.
- package/README.md +157 -55
- package/bindings.d.ts +302 -404
- package/bindings.js +168 -85
- package/index.d.ts +30 -962
- package/index.js +42 -1898
- package/lib/client.d.ts +232 -0
- package/lib/client.js +347 -0
- package/lib/context.d.ts +161 -0
- package/lib/context.js +86 -0
- package/lib/errors.d.ts +103 -0
- package/lib/errors.js +102 -0
- package/lib/logging.d.ts +75 -0
- package/lib/logging.js +99 -0
- package/lib/payload.d.ts +59 -0
- package/lib/state/bridge.js +103 -0
- package/lib/state/codec.js +206 -0
- package/lib/state/definitions.d.ts +233 -0
- package/lib/state/definitions.js +151 -0
- package/lib/state/deque.d.ts +75 -0
- package/lib/state/deque.js +77 -0
- package/lib/state/handle.d.ts +25 -0
- package/lib/state/handle.js +26 -0
- package/lib/state/iterator.js +66 -0
- package/lib/state/map.d.ts +94 -0
- package/lib/state/map.js +79 -0
- package/lib/state/published.d.ts +113 -0
- package/lib/state/published.js +147 -0
- package/lib/state/query.d.ts +85 -0
- package/lib/state/query.js +206 -0
- package/lib/state/set.d.ts +52 -0
- package/lib/state/set.js +54 -0
- package/lib/state/value.d.ts +33 -0
- package/lib/state/value.js +31 -0
- package/package.json +21 -20
package/index.d.ts
CHANGED
|
@@ -5,24 +5,29 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
ConsumerState,
|
|
11
|
-
ExciseMessage as NativeExciseMessage,
|
|
12
|
-
Message as NativeMessage,
|
|
13
|
-
Mode,
|
|
14
|
-
ReadCacheConfiguration,
|
|
15
|
-
Timer,
|
|
8
|
+
ConsumerState as ConsumerStateName,
|
|
9
|
+
Mode as ModeName,
|
|
16
10
|
} from "./bindings";
|
|
17
11
|
|
|
18
|
-
export {
|
|
19
|
-
|
|
12
|
+
export { AdminClient } from "./bindings";
|
|
13
|
+
export type {
|
|
20
14
|
Configuration,
|
|
21
|
-
ConsumerState,
|
|
22
15
|
ReadCacheConfiguration,
|
|
23
16
|
Timer,
|
|
24
|
-
|
|
17
|
+
TopicOptions,
|
|
18
|
+
} from "./bindings";
|
|
19
|
+
|
|
20
|
+
/** The consumer states, keyed by name: `ConsumerState.Running` is `"Running"`. */
|
|
21
|
+
export declare const ConsumerState: {
|
|
22
|
+
readonly [State in ConsumerStateName]: State;
|
|
25
23
|
};
|
|
24
|
+
/** A consumer state that `consumerState()` reports. */
|
|
25
|
+
export type ConsumerState = ConsumerStateName;
|
|
26
|
+
|
|
27
|
+
/** The operating modes, keyed by name: `Mode.Pipeline` is `"Pipeline"`. */
|
|
28
|
+
export declare const Mode: { readonly [Name in ModeName]: Name };
|
|
29
|
+
/** The operating mode of a client. */
|
|
30
|
+
export type Mode = ModeName;
|
|
26
31
|
|
|
27
32
|
/** Exports all pending telemetry data. */
|
|
28
33
|
export function flushTelemetry(): void;
|
|
@@ -30,826 +35,6 @@ export function flushTelemetry(): void;
|
|
|
30
35
|
/** Stops the global telemetry providers after they export pending data. */
|
|
31
36
|
export function shutdownTelemetry(): void;
|
|
32
37
|
|
|
33
|
-
/** A primitive value representable in JSON. */
|
|
34
|
-
export type JsonPrimitive = null | boolean | number | string;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Any value representable in JSON.
|
|
38
|
-
*
|
|
39
|
-
* This is a compile-time contract. Prosody serializes payloads at runtime but
|
|
40
|
-
* does not validate them against a more specific application payload type.
|
|
41
|
-
*/
|
|
42
|
-
export type JsonValue =
|
|
43
|
-
JsonPrimitive | readonly JsonValue[] | { readonly [key: string]: JsonValue };
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Maps an application type to its JSON-compatible shape. This lets APIs
|
|
47
|
-
* accept ordinary interfaces and type aliases without requiring an index
|
|
48
|
-
* signature, while rejecting non-JSON members wherever they are nested.
|
|
49
|
-
*/
|
|
50
|
-
export type JsonCompatible<T> = T extends JsonPrimitive
|
|
51
|
-
? T
|
|
52
|
-
: T extends bigint | symbol | undefined | ((...args: never[]) => unknown)
|
|
53
|
-
? never
|
|
54
|
-
: T extends readonly (infer Item)[]
|
|
55
|
-
? readonly JsonCompatible<Item>[]
|
|
56
|
-
: T extends object
|
|
57
|
-
? { readonly [Key in keyof T]: JsonCompatible<T[Key]> }
|
|
58
|
-
: never;
|
|
59
|
-
|
|
60
|
-
/** A value that a handler can return now or through a promise. */
|
|
61
|
-
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Represents a message consumed from a Kafka topic.
|
|
65
|
-
*
|
|
66
|
-
* The optional payload type parameter is annotation-level only: the runtime
|
|
67
|
-
* payload is unchanged. An unparameterized `Message` uses {@link JsonValue};
|
|
68
|
-
* provide an application payload type for precise field-level checking.
|
|
69
|
-
* Message-backed keyed-state collections vend their items as `Message<P>`.
|
|
70
|
-
*
|
|
71
|
-
* A message can be stored into a message collection, whether it arrived from the
|
|
72
|
-
* topic or was read back out of a collection. What is stored is the message
|
|
73
|
-
* itself, so mutating its parsed `payload` does not change what is written.
|
|
74
|
-
*/
|
|
75
|
-
export interface Message<P = JsonValue> extends Omit<NativeMessage, "payload"> {
|
|
76
|
-
/** The message payload as a JSON-serializable value. */
|
|
77
|
-
payload: P;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** An excise record with Kafka metadata and no payload. */
|
|
81
|
-
export type ExciseMessage = NativeExciseMessage;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Wrapper around `MessageContext` for use in Node.js bindings.
|
|
85
|
-
* Automatically injects OpenTelemetry context for all operations.
|
|
86
|
-
*/
|
|
87
|
-
export declare class Context {
|
|
88
|
-
/**
|
|
89
|
-
* Checks whether cancellation has been signaled.
|
|
90
|
-
* Cancellation includes message-level cancellation (e.g., timeout) and partition shutdown. During shutdown, cancellation is delayed until near the end of the shutdown timeout to allow in-flight work to complete.
|
|
91
|
-
*
|
|
92
|
-
* @returns True if cancellation was requested, otherwise false.
|
|
93
|
-
*/
|
|
94
|
-
get shouldCancel(): boolean;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Waits for a cancellation signal.
|
|
98
|
-
* Cancellation includes message-level cancellation (e.g., timeout) and partition shutdown. During shutdown, cancellation is delayed until near the end of the shutdown timeout to allow in-flight work to complete.
|
|
99
|
-
*
|
|
100
|
-
* @returns A promise that resolves when cancellation is signaled.
|
|
101
|
-
*/
|
|
102
|
-
onCancel(): Promise<void>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Schedule a timer at the given time.
|
|
106
|
-
*
|
|
107
|
-
* @param time - The UTC timestamp to schedule.
|
|
108
|
-
* @returns A promise that resolves when the timer has been scheduled.
|
|
109
|
-
* @throws Error if time conversion or scheduling fails.
|
|
110
|
-
*/
|
|
111
|
-
schedule(time: Date): Promise<void>;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Clear existing timers and schedule a new one at the given time.
|
|
115
|
-
*
|
|
116
|
-
* @param time - The UTC timestamp to schedule.
|
|
117
|
-
* @returns A promise that resolves when the timer has been scheduled.
|
|
118
|
-
* @throws Error if time conversion or scheduling fails.
|
|
119
|
-
*/
|
|
120
|
-
clearAndSchedule(time: Date): Promise<void>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Unschedules the timer for the specified time.
|
|
124
|
-
* @param time - The time to unschedule.
|
|
125
|
-
* @returns A promise that resolves when the timer has been unscheduled.
|
|
126
|
-
* @throws Error if unscheduling fails.
|
|
127
|
-
*/
|
|
128
|
-
unschedule(time: Date): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Clears all scheduled timers.
|
|
132
|
-
* @returns A promise that resolves when all timers have been cleared.
|
|
133
|
-
* @throws Error if clearing schedules fails.
|
|
134
|
-
*/
|
|
135
|
-
clearScheduled(): Promise<void>;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Retrieves all scheduled times.
|
|
139
|
-
* @returns An array of scheduled times as Date objects.
|
|
140
|
-
* @throws Error if retrieval fails.
|
|
141
|
-
*/
|
|
142
|
-
scheduled(): Promise<Array<Date>>;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Binds a registered message single-value collection, vending a handle whose
|
|
146
|
-
* item is the full `Message<P>`.
|
|
147
|
-
*
|
|
148
|
-
* The handle and any iterator it opens are valid only within this event
|
|
149
|
-
* attempt. Throws a {@link PermanentStateError} if the collection name is
|
|
150
|
-
* unregistered or its registered identity mismatches.
|
|
151
|
-
* @param definition - A definition from {@link messageValue}.
|
|
152
|
-
*/
|
|
153
|
-
state<P>(definition: MessageValueDefinition<P>): ValueState<Message<P>>;
|
|
154
|
-
/**
|
|
155
|
-
* Binds a registered message ordered-map collection, vending a handle whose
|
|
156
|
-
* values are the full `Message<P>`. Valid only within this event attempt;
|
|
157
|
-
* throws {@link PermanentStateError} on an unregistered name or identity
|
|
158
|
-
* mismatch.
|
|
159
|
-
* @param definition - A definition from {@link messageMap}.
|
|
160
|
-
*/
|
|
161
|
-
state<P>(definition: MessageMapDefinition<P>): MapState<Message<P>>;
|
|
162
|
-
/**
|
|
163
|
-
* Binds a registered message deque collection, vending a handle whose
|
|
164
|
-
* elements are the full `Message<P>`. Valid only within this event attempt;
|
|
165
|
-
* throws {@link PermanentStateError} on an unregistered name or identity
|
|
166
|
-
* mismatch.
|
|
167
|
-
* @param definition - A definition from {@link messageDeque}.
|
|
168
|
-
*/
|
|
169
|
-
state<P>(definition: MessageDequeDefinition<P>): DequeState<Message<P>>;
|
|
170
|
-
/**
|
|
171
|
-
* Binds a registered single-value JSON collection. Valid only within this
|
|
172
|
-
* event attempt; throws {@link PermanentStateError} on an unregistered name
|
|
173
|
-
* or identity mismatch.
|
|
174
|
-
* @param definition - A definition from {@link value}.
|
|
175
|
-
*/
|
|
176
|
-
state<T>(definition: ValueDefinition<T>): ValueState<T>;
|
|
177
|
-
/**
|
|
178
|
-
* Binds a registered ordered-map JSON collection (string keys). Valid only
|
|
179
|
-
* within this event attempt; throws {@link PermanentStateError} on an
|
|
180
|
-
* unregistered name or identity mismatch.
|
|
181
|
-
* @param definition - A definition from {@link map}.
|
|
182
|
-
*/
|
|
183
|
-
state<V>(definition: MapDefinition<V>): MapState<V>;
|
|
184
|
-
/**
|
|
185
|
-
* Binds a registered deque JSON collection. Valid only within this event
|
|
186
|
-
* attempt; throws {@link PermanentStateError} on an unregistered name or
|
|
187
|
-
* identity mismatch.
|
|
188
|
-
* @param definition - A definition from {@link deque}.
|
|
189
|
-
*/
|
|
190
|
-
state<T>(definition: DequeDefinition<T>): DequeState<T>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Scan direction over a map or deque collection. `"forward"` visits a map in
|
|
195
|
-
* ascending key order and a deque from front to back; `"backward"` reverses
|
|
196
|
-
* each. Defaults to `"forward"` wherever it is optional.
|
|
197
|
-
*/
|
|
198
|
-
export type ScanDirection = "forward" | "backward";
|
|
199
|
-
|
|
200
|
-
/** Options accepted by every keyed-state definition constructor. */
|
|
201
|
-
export interface StateDefinitionOptions {
|
|
202
|
-
/**
|
|
203
|
-
* Optional per-write TTL in whole seconds. Must be at least 1 and must
|
|
204
|
-
* exceed the client's recovery delay (enforced core-side).
|
|
205
|
-
*/
|
|
206
|
-
ttlSeconds?: number;
|
|
207
|
-
/**
|
|
208
|
-
* Opt out of transactional staging (read-uncommitted, at-least-once).
|
|
209
|
-
* Defaults to transactional.
|
|
210
|
-
*/
|
|
211
|
-
readUncommitted?: boolean;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** Options accepted by JSON collections that may be published. */
|
|
215
|
-
export interface PublishedStateDefinitionOptions extends StateDefinitionOptions {
|
|
216
|
-
/** Allow read-only access from other consumer groups. */
|
|
217
|
-
published?: boolean;
|
|
218
|
-
/** Override caching when this descriptor opens a published reader. */
|
|
219
|
-
readCache?: ReadCacheOptions | false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** Options accepted by the map definition constructors. */
|
|
223
|
-
export interface MapDefinitionOptions extends PublishedStateDefinitionOptions {
|
|
224
|
-
/**
|
|
225
|
-
* Keyset bound for ordered scans (`0..=4096`; default 128 core-side; `0`
|
|
226
|
-
* disables ordered-scan tracking). Map collections only.
|
|
227
|
-
*/
|
|
228
|
-
keysetLimit?: number;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/** Options accepted by the deque definition constructors. */
|
|
232
|
-
export interface DequeDefinitionOptions extends PublishedStateDefinitionOptions {
|
|
233
|
-
/**
|
|
234
|
-
* Optional maximum element count (bounded backlog). Must be a whole number
|
|
235
|
-
* >= 1. Runtime-only: not persisted, not part of collection identity, and
|
|
236
|
-
* changeable across deploys. Enforced lazily on push — the opposite end is
|
|
237
|
-
* evicted toward the bound (no decode, no fetch); a shrunk deque reports its
|
|
238
|
-
* old length until the next push trims it. Deque collections only.
|
|
239
|
-
*/
|
|
240
|
-
capacity?: number;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** Options accepted by message-map definitions, which cannot be published. */
|
|
244
|
-
export interface MessageMapDefinitionOptions extends StateDefinitionOptions {
|
|
245
|
-
/** Keyset bound for ordered scans (`0..=4096`; default 128 core-side). */
|
|
246
|
-
keysetLimit?: number;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** Options accepted by message-deque definitions, which cannot be published. */
|
|
250
|
-
export interface MessageDequeDefinitionOptions extends StateDefinitionOptions {
|
|
251
|
-
/** Optional maximum element count. Must be a whole number >= 1. */
|
|
252
|
-
capacity?: number;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Phantom brand carrying a definition's item type. Never present at runtime —
|
|
257
|
-
* it exists only so the item type survives on the frozen definition object and
|
|
258
|
-
* flows into the vended handle.
|
|
259
|
-
*/
|
|
260
|
-
declare const StateItem: unique symbol;
|
|
261
|
-
declare const StateDescriptor: unique symbol;
|
|
262
|
-
|
|
263
|
-
interface DefinitionBrand {
|
|
264
|
-
readonly [StateDescriptor]: true;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/** A frozen single-value JSON collection definition. */
|
|
268
|
-
export interface ValueDefinition<T = JsonValue> extends DefinitionBrand {
|
|
269
|
-
readonly name: string;
|
|
270
|
-
readonly kind: "value";
|
|
271
|
-
readonly payload: "json";
|
|
272
|
-
readonly ttlSeconds?: number;
|
|
273
|
-
readonly readUncommitted?: boolean;
|
|
274
|
-
readonly published?: boolean;
|
|
275
|
-
readonly readCache?: ReadCacheOptions | false;
|
|
276
|
-
readonly [StateItem]?: T;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/** A frozen ordered-map JSON collection definition (string keys). */
|
|
280
|
-
export interface MapDefinition<V = JsonValue> extends DefinitionBrand {
|
|
281
|
-
readonly name: string;
|
|
282
|
-
readonly kind: "map";
|
|
283
|
-
readonly payload: "json";
|
|
284
|
-
readonly ttlSeconds?: number;
|
|
285
|
-
readonly readUncommitted?: boolean;
|
|
286
|
-
readonly published?: boolean;
|
|
287
|
-
readonly readCache?: ReadCacheOptions | false;
|
|
288
|
-
readonly keysetLimit?: number;
|
|
289
|
-
readonly [StateItem]?: V;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/** A frozen deque JSON collection definition. */
|
|
293
|
-
export interface DequeDefinition<T = JsonValue> extends DefinitionBrand {
|
|
294
|
-
readonly name: string;
|
|
295
|
-
readonly kind: "deque";
|
|
296
|
-
readonly payload: "json";
|
|
297
|
-
readonly ttlSeconds?: number;
|
|
298
|
-
readonly readUncommitted?: boolean;
|
|
299
|
-
readonly published?: boolean;
|
|
300
|
-
readonly readCache?: ReadCacheOptions | false;
|
|
301
|
-
readonly capacity?: number;
|
|
302
|
-
readonly [StateItem]?: T;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/** A frozen single-value message collection definition (items are `Message<P>`). */
|
|
306
|
-
export interface MessageValueDefinition<P = JsonValue> extends DefinitionBrand {
|
|
307
|
-
readonly name: string;
|
|
308
|
-
readonly kind: "value";
|
|
309
|
-
readonly payload: "message";
|
|
310
|
-
readonly ttlSeconds?: number;
|
|
311
|
-
readonly readUncommitted?: boolean;
|
|
312
|
-
readonly [StateItem]?: P;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/** A frozen ordered-map message collection definition (values are `Message<P>`). */
|
|
316
|
-
export interface MessageMapDefinition<P = JsonValue> extends DefinitionBrand {
|
|
317
|
-
readonly name: string;
|
|
318
|
-
readonly kind: "map";
|
|
319
|
-
readonly payload: "message";
|
|
320
|
-
readonly ttlSeconds?: number;
|
|
321
|
-
readonly readUncommitted?: boolean;
|
|
322
|
-
readonly keysetLimit?: number;
|
|
323
|
-
readonly [StateItem]?: P;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/** A frozen deque message collection definition (elements are `Message<P>`). */
|
|
327
|
-
export interface MessageDequeDefinition<P = JsonValue> extends DefinitionBrand {
|
|
328
|
-
readonly name: string;
|
|
329
|
-
readonly kind: "deque";
|
|
330
|
-
readonly payload: "message";
|
|
331
|
-
readonly ttlSeconds?: number;
|
|
332
|
-
readonly readUncommitted?: boolean;
|
|
333
|
-
readonly capacity?: number;
|
|
334
|
-
readonly [StateItem]?: P;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Declares a single-value JSON collection. The returned frozen definition is
|
|
339
|
-
* the single source of typing: place it in `Configuration.stateCollections` to
|
|
340
|
-
* register the collection, and pass it to `Context.state()` to vend a typed
|
|
341
|
-
* handle. The type parameter annotates the stored value and is compile-time
|
|
342
|
-
* only — payloads cross as plain JSON with no runtime validation.
|
|
343
|
-
* @param name - The collection name (unique per client).
|
|
344
|
-
* @param options - Optional retention, transaction, publication, and read-cache
|
|
345
|
-
* settings.
|
|
346
|
-
*/
|
|
347
|
-
export function value<T = JsonValue>(
|
|
348
|
-
name: string,
|
|
349
|
-
options?: PublishedStateDefinitionOptions,
|
|
350
|
-
): ValueDefinition<T>;
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Declares an ordered-map JSON collection. Map keys are always `string`. The
|
|
354
|
-
* returned frozen definition is used both in `Configuration.stateCollections`
|
|
355
|
-
* and with `Context.state()`. The type parameter annotates the stored value
|
|
356
|
-
* (compile-time only).
|
|
357
|
-
* @param name - The collection name (unique per client).
|
|
358
|
-
* @param options - Optional retention, transaction, publication, read-cache,
|
|
359
|
-
* and `keysetLimit` settings.
|
|
360
|
-
*/
|
|
361
|
-
export function map<V = JsonValue>(
|
|
362
|
-
name: string,
|
|
363
|
-
options?: MapDefinitionOptions,
|
|
364
|
-
): MapDefinition<V>;
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Declares a double-ended-queue JSON collection. The returned frozen definition
|
|
368
|
-
* is used both in `Configuration.stateCollections` and with `Context.state()`.
|
|
369
|
-
* The type parameter annotates the stored element (compile-time only).
|
|
370
|
-
* @param name - The collection name (unique per client).
|
|
371
|
-
* @param options - Optional retention, transaction, publication, read-cache,
|
|
372
|
-
* and `capacity` settings.
|
|
373
|
-
*/
|
|
374
|
-
export function deque<T = JsonValue>(
|
|
375
|
-
name: string,
|
|
376
|
-
options?: DequeDefinitionOptions,
|
|
377
|
-
): DequeDefinition<T>;
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Declares a single-value message collection: each stored item is the full
|
|
381
|
-
* Kafka `Message<P>` the handler received. The type parameter annotates the
|
|
382
|
-
* message payload (compile-time only).
|
|
383
|
-
* @param name - The collection name (unique per client).
|
|
384
|
-
* @param options - Optional `ttlSeconds` (whole seconds) and `readUncommitted`.
|
|
385
|
-
*/
|
|
386
|
-
export function messageValue<P = JsonValue>(
|
|
387
|
-
name: string,
|
|
388
|
-
options?: StateDefinitionOptions,
|
|
389
|
-
): MessageValueDefinition<P>;
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Declares an ordered-map message collection (string keys; values are the full
|
|
393
|
-
* Kafka `Message<P>`). The type parameter annotates the message payload
|
|
394
|
-
* (compile-time only).
|
|
395
|
-
* @param name - The collection name (unique per client).
|
|
396
|
-
* @param options - Optional `ttlSeconds`, `readUncommitted`, and `keysetLimit`.
|
|
397
|
-
*/
|
|
398
|
-
export function messageMap<P = JsonValue>(
|
|
399
|
-
name: string,
|
|
400
|
-
options?: MessageMapDefinitionOptions,
|
|
401
|
-
): MessageMapDefinition<P>;
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Declares a double-ended-queue message collection: each stored element is the
|
|
405
|
-
* full Kafka `Message<P>`. The type parameter annotates the message payload
|
|
406
|
-
* (compile-time only).
|
|
407
|
-
* @param name - The collection name (unique per client).
|
|
408
|
-
* @param options - Optional `ttlSeconds` (whole seconds), `readUncommitted`, and
|
|
409
|
-
* `capacity` (bounded backlog; enforced lazily on push).
|
|
410
|
-
*/
|
|
411
|
-
export function messageDeque<P = JsonValue>(
|
|
412
|
-
name: string,
|
|
413
|
-
options?: MessageDequeDefinitionOptions,
|
|
414
|
-
): MessageDequeDefinition<P>;
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Typed handle over a single-value keyed-state collection, vended by
|
|
418
|
-
* `Context.state()`. Valid only within the handler invocation (attempt) that
|
|
419
|
-
* vended it. Every method opens its own per-operation trace span.
|
|
420
|
-
*/
|
|
421
|
-
export declare class ValueState<T = JsonValue> {
|
|
422
|
-
/** Vended only by {@link Context#state}; not constructible directly. */
|
|
423
|
-
private constructor(native: unknown);
|
|
424
|
-
/** Reads the current value, or null when absent/cleared. */
|
|
425
|
-
get(): Promise<T | null>;
|
|
426
|
-
/**
|
|
427
|
-
* Buffers a write of the value. The parameter type excludes `null`/`undefined`
|
|
428
|
-
* (via {@link !NonNullable}) because a top-level `null` is not a storable
|
|
429
|
-
* value — writing one (or an unrepresentable value) is a caller mistake,
|
|
430
|
-
* rejected at runtime with a {@link TransientStateError} naming `clear()` —
|
|
431
|
-
* use {@link ValueState#clear}. Transient so it retries and stays visible
|
|
432
|
-
* rather than discarding the message. (Nested `null`, e.g. inside an object or
|
|
433
|
-
* array, is permitted and round-trips.)
|
|
434
|
-
*/
|
|
435
|
-
set(value: NonNullable<T>): Promise<void>;
|
|
436
|
-
/** Deletes the stored value. */
|
|
437
|
-
clear(): Promise<void>;
|
|
438
|
-
/**
|
|
439
|
-
* Durably commits the buffered operations mid-handler (at-least-once).
|
|
440
|
-
* Resolves with no value — the erased seam drops the store outcome.
|
|
441
|
-
*/
|
|
442
|
-
commit(): Promise<void>;
|
|
443
|
-
/** Discards buffered uncommitted operations back to the committed floor. */
|
|
444
|
-
rollback(): Promise<void>;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Typed handle over an ordered-map keyed-state collection, vended by
|
|
449
|
-
* `Context.state()`. Map keys are always `string`. Valid only within the
|
|
450
|
-
* handler invocation (attempt) that vended it. Every method opens its own
|
|
451
|
-
* per-operation trace span.
|
|
452
|
-
*/
|
|
453
|
-
export declare class MapState<V = JsonValue> {
|
|
454
|
-
/** Vended only by {@link Context#state}; not constructible directly. */
|
|
455
|
-
private constructor(native: unknown);
|
|
456
|
-
/** Reads the value for `key`, or null when the key is absent. */
|
|
457
|
-
get(key: string): Promise<V | null>;
|
|
458
|
-
/**
|
|
459
|
-
* Reads several keys in a single call. Returns an array with one entry per
|
|
460
|
-
* key, in the same order you asked, so `result[i]` is the value for
|
|
461
|
-
* `keys[i]`. A key that isn't there comes back as `null`, and a key you list
|
|
462
|
-
* more than once is answered at each spot. The whole read happens as one
|
|
463
|
-
* step, so no other change to this event's state can slip in partway through.
|
|
464
|
-
*/
|
|
465
|
-
getMany(keys: readonly string[]): Promise<(V | null)[]>;
|
|
466
|
-
/**
|
|
467
|
-
* Reports whether `key` currently has a stored value. A presence check that
|
|
468
|
-
* skips the value decode and the resolver: for a message-backed map it
|
|
469
|
-
* answers with zero Kafka fetches and can report `true` for a message that
|
|
470
|
-
* can no longer be fetched. Not zero-I/O — a cache miss can still reach the
|
|
471
|
-
* store — but cheaper than {@link MapState#get} when you only need presence.
|
|
472
|
-
*/
|
|
473
|
-
has(key: string): Promise<boolean>;
|
|
474
|
-
/**
|
|
475
|
-
* Inserts or overwrites `key`. The value type excludes `null`/`undefined`
|
|
476
|
-
* (via {@link !NonNullable}) because a top-level `null` is not a storable
|
|
477
|
-
* value — writing one (or an unrepresentable value) is a caller mistake,
|
|
478
|
-
* rejected at runtime with a {@link TransientStateError} — use
|
|
479
|
-
* {@link MapState#delete} to remove. Transient so it retries and stays visible
|
|
480
|
-
* rather than discarding the message. (Nested `null` is permitted.)
|
|
481
|
-
*/
|
|
482
|
-
set(key: string, value: NonNullable<V>): Promise<void>;
|
|
483
|
-
/**
|
|
484
|
-
* Removes `key`.
|
|
485
|
-
*
|
|
486
|
-
* Deliberate divergence from `Map#delete`: returns void, NOT a boolean
|
|
487
|
-
* "was present" flag — surfacing that boolean would force a hidden read on
|
|
488
|
-
* every delete. (The underlying native operation is named `remove`.)
|
|
489
|
-
*/
|
|
490
|
-
delete(key: string): Promise<void>;
|
|
491
|
-
/** Removes every entry. */
|
|
492
|
-
clear(): Promise<void>;
|
|
493
|
-
/**
|
|
494
|
-
* Async iterator over the live `[key, value]` entries in key order. Valid
|
|
495
|
-
* only within the handler invocation (attempt) that opened it; early exit
|
|
496
|
-
* from a `for await` loop closes the underlying cursor.
|
|
497
|
-
*/
|
|
498
|
-
entries(direction?: ScanDirection): AsyncIterableIterator<[string, V]>;
|
|
499
|
-
/**
|
|
500
|
-
* Async iterator over the live keys in key order. Skips the value decode and
|
|
501
|
-
* the resolver, so a message-backed map enumerates keys with zero Kafka
|
|
502
|
-
* fetches; it still reads presence, so it is not zero-I/O. Valid only within
|
|
503
|
-
* the handler invocation (attempt) that opened it; early exit from a
|
|
504
|
-
* `for await` loop closes the underlying cursor.
|
|
505
|
-
*/
|
|
506
|
-
keys(direction?: ScanDirection): AsyncIterableIterator<string>;
|
|
507
|
-
/**
|
|
508
|
-
* Async iterator over the live values in key order. Valid only within the
|
|
509
|
-
* handler invocation (attempt) that opened it; early exit from a `for await`
|
|
510
|
-
* loop closes the underlying cursor.
|
|
511
|
-
*/
|
|
512
|
-
values(direction?: ScanDirection): AsyncIterableIterator<V>;
|
|
513
|
-
/**
|
|
514
|
-
* Forward iteration over `[key, value]` entries. Valid only within the
|
|
515
|
-
* handler invocation (attempt) that opened it.
|
|
516
|
-
*/
|
|
517
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<[string, V]>;
|
|
518
|
-
/**
|
|
519
|
-
* Durably commits the buffered operations mid-handler (at-least-once).
|
|
520
|
-
* Resolves with no value — the erased seam drops the store outcome.
|
|
521
|
-
*/
|
|
522
|
-
commit(): Promise<void>;
|
|
523
|
-
/** Discards buffered uncommitted operations back to the committed floor. */
|
|
524
|
-
rollback(): Promise<void>;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Typed handle over a double-ended-queue keyed-state collection, vended by
|
|
529
|
-
* `Context.state()`. Valid only within the handler invocation (attempt) that
|
|
530
|
-
* vended it. Every method opens its own per-operation trace span.
|
|
531
|
-
*/
|
|
532
|
-
export declare class DequeState<T = JsonValue> {
|
|
533
|
-
/** Vended only by {@link Context#state}; not constructible directly. */
|
|
534
|
-
private constructor(native: unknown);
|
|
535
|
-
/**
|
|
536
|
-
* Appends an element at the back. The item type excludes `null`/`undefined`
|
|
537
|
-
* (via {@link !NonNullable}) because a top-level `null` is not a storable
|
|
538
|
-
* element — writing one (or an unrepresentable value) is a caller mistake,
|
|
539
|
-
* rejected at runtime with a {@link TransientStateError} so it retries and
|
|
540
|
-
* stays visible rather than discarding the message. (Nested `null` is
|
|
541
|
-
* permitted.)
|
|
542
|
-
*/
|
|
543
|
-
push(item: NonNullable<T>): Promise<void>;
|
|
544
|
-
/**
|
|
545
|
-
* Prepends an element at the front. The item type excludes `null`/`undefined`
|
|
546
|
-
* (via {@link !NonNullable}); see {@link DequeState#push}.
|
|
547
|
-
*/
|
|
548
|
-
unshift(item: NonNullable<T>): Promise<void>;
|
|
549
|
-
/** Removes and returns the back element, or null when empty. */
|
|
550
|
-
pop(): Promise<T | null>;
|
|
551
|
-
/** Removes and returns the front element, or null when empty. */
|
|
552
|
-
shift(): Promise<T | null>;
|
|
553
|
-
/** Returns the number of live elements. */
|
|
554
|
-
length(): Promise<number>;
|
|
555
|
-
/** Reports whether the deque holds no live elements. */
|
|
556
|
-
isEmpty(): Promise<boolean>;
|
|
557
|
-
/** Removes every element. */
|
|
558
|
-
clear(): Promise<void>;
|
|
559
|
-
/**
|
|
560
|
-
* Reads the element at `index`, like `Array.prototype.at`: a non-negative
|
|
561
|
-
* `index` counts from the front (`0` is the front), a negative `index` counts
|
|
562
|
-
* back from the end (`-1` is the back). Any out-of-range position — including
|
|
563
|
-
* every index on an empty deque — resolves to null. `index` must be a safe
|
|
564
|
-
* integer; a fractional, `NaN`, or infinite value is a caller mistake,
|
|
565
|
-
* rejected with a {@link TransientStateError} (it retries and stays visible).
|
|
566
|
-
*
|
|
567
|
-
* The endpoints `at(0)` and `at(-1)` ride the front/back peeks — a single
|
|
568
|
-
* read, and `at(-1)` makes no length read. Any other negative `index` is
|
|
569
|
-
* resolved against the current {@link DequeState#length}, so it makes an
|
|
570
|
-
* extra boundary crossing that a non-negative one does not.
|
|
571
|
-
*/
|
|
572
|
-
at(index: number): Promise<T | null>;
|
|
573
|
-
/**
|
|
574
|
-
* Async iterator over the live elements in index order. Valid only within
|
|
575
|
-
* the handler invocation (attempt) that opened it; early exit from a
|
|
576
|
-
* `for await` loop closes the underlying cursor.
|
|
577
|
-
*/
|
|
578
|
-
values(direction?: ScanDirection): AsyncIterableIterator<T>;
|
|
579
|
-
/**
|
|
580
|
-
* Forward iteration over the elements. Valid only within the handler
|
|
581
|
-
* invocation (attempt) that opened it.
|
|
582
|
-
*/
|
|
583
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
584
|
-
/**
|
|
585
|
-
* Durably commits the buffered operations mid-handler (at-least-once).
|
|
586
|
-
* Resolves with no value — the erased seam drops the store outcome.
|
|
587
|
-
*/
|
|
588
|
-
commit(): Promise<void>;
|
|
589
|
-
/** Discards buffered uncommitted operations back to the committed floor. */
|
|
590
|
-
rollback(): Promise<void>;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
/**
|
|
594
|
-
* JavaScript logger interface for use with Prosody client.
|
|
595
|
-
*
|
|
596
|
-
* Each logging method receives a message string and optional metadata object.
|
|
597
|
-
*/
|
|
598
|
-
export interface Logger {
|
|
599
|
-
/** Logs error-level messages. */
|
|
600
|
-
error: (
|
|
601
|
-
message: string | undefined | null,
|
|
602
|
-
metadata?: Record<string, unknown>,
|
|
603
|
-
) => void;
|
|
604
|
-
/** Logs warning-level messages. */
|
|
605
|
-
warn: (
|
|
606
|
-
message: string | undefined | null,
|
|
607
|
-
metadata?: Record<string, unknown>,
|
|
608
|
-
) => void;
|
|
609
|
-
/** Logs info-level messages. */
|
|
610
|
-
info: (
|
|
611
|
-
message: string | undefined | null,
|
|
612
|
-
metadata?: Record<string, unknown>,
|
|
613
|
-
) => void;
|
|
614
|
-
/** Logs debug-level messages. */
|
|
615
|
-
debug: (
|
|
616
|
-
message: string | undefined | null,
|
|
617
|
-
metadata?: Record<string, unknown>,
|
|
618
|
-
) => void;
|
|
619
|
-
/** Logs trace-level messages. */
|
|
620
|
-
trace: (
|
|
621
|
-
message: string | undefined | null,
|
|
622
|
-
metadata?: Record<string, unknown>,
|
|
623
|
-
) => void;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
export interface EventHandler<P = JsonValue, R = JsonValue> {
|
|
627
|
-
/** Handles an excise record. */
|
|
628
|
-
onExcise: (
|
|
629
|
-
context: Context,
|
|
630
|
-
message: ExciseMessage,
|
|
631
|
-
signal: AbortSignal,
|
|
632
|
-
) => MaybePromise<R & JsonCompatible<R>>;
|
|
633
|
-
/**
|
|
634
|
-
* Callback function to handle incoming messages.
|
|
635
|
-
*
|
|
636
|
-
* @param context - The context of the message processing.
|
|
637
|
-
* @param message - The received Kafka message.
|
|
638
|
-
* @param signal - An AbortSignal that can be used to cancel the message processing.
|
|
639
|
-
* @returns A JSON response for subsystem requests. JSON null is valid.
|
|
640
|
-
*/
|
|
641
|
-
onMessage: (
|
|
642
|
-
context: Context,
|
|
643
|
-
message: Message<P>,
|
|
644
|
-
signal: AbortSignal,
|
|
645
|
-
) => MaybePromise<R & JsonCompatible<R>>;
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Callback function to handle timers.
|
|
649
|
-
*
|
|
650
|
-
* @param context - The context of the message processing.
|
|
651
|
-
* @param timer - The triggered timer.
|
|
652
|
-
* @param signal - An AbortSignal that can be used to cancel the message processing.
|
|
653
|
-
* @returns No value.
|
|
654
|
-
*/
|
|
655
|
-
onTimer: (
|
|
656
|
-
context: Context,
|
|
657
|
-
timer: Timer,
|
|
658
|
-
signal: AbortSignal,
|
|
659
|
-
) => MaybePromise<void>;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
/** One successful subsystem outcome. */
|
|
663
|
-
export interface Success<T> {
|
|
664
|
-
readonly ok: true;
|
|
665
|
-
readonly value: T;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/** One failed subsystem outcome. */
|
|
669
|
-
export interface Failure {
|
|
670
|
-
readonly ok: false;
|
|
671
|
-
readonly error: ResponseError;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/** One subsystem outcome. */
|
|
675
|
-
export type Outcome<T> = Success<T> | Failure;
|
|
676
|
-
|
|
677
|
-
/** One subsystem failure. */
|
|
678
|
-
export type ResponseError =
|
|
679
|
-
| { readonly kind: "handler"; readonly message: string }
|
|
680
|
-
| { readonly kind: "timeout"; readonly message: string }
|
|
681
|
-
| { readonly kind: "formatMismatch"; readonly message: string }
|
|
682
|
-
| { readonly kind: "malformedResponse"; readonly message: string };
|
|
683
|
-
|
|
684
|
-
/** Request targets, deadline, and cancellation. */
|
|
685
|
-
export interface RequestOptions {
|
|
686
|
-
/** The subsystems that must respond. */
|
|
687
|
-
readonly subsystems: readonly string[];
|
|
688
|
-
/** The response deadline in milliseconds. */
|
|
689
|
-
readonly timeoutMs: number;
|
|
690
|
-
/** Cancels the local wait. */
|
|
691
|
-
readonly signal?: AbortSignal;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
export declare class ProsodyClient {
|
|
695
|
-
private constructor();
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* Creates a Prosody client without blocking the Node.js event loop.
|
|
699
|
-
*
|
|
700
|
-
* @param config - The configuration options for the client.
|
|
701
|
-
*/
|
|
702
|
-
static create(config: Configuration): Promise<ProsodyClient>;
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
* Gets the current state of the consumer.
|
|
706
|
-
*
|
|
707
|
-
* @returns The current state of the consumer.
|
|
708
|
-
* @throws Error if the operation fails.
|
|
709
|
-
*/
|
|
710
|
-
consumerState(): Promise<ConsumerState>;
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
* Gets the number of partitions assigned to the consumer.
|
|
714
|
-
*
|
|
715
|
-
* @returns The number of assigned partitions, or 0 if the consumer is not in the Running state.
|
|
716
|
-
* @throws Error if the operation fails.
|
|
717
|
-
*/
|
|
718
|
-
assignedPartitionCount(): Promise<number>;
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* Checks if the consumer is stalled.
|
|
722
|
-
*
|
|
723
|
-
* @returns Whether the consumer is stalled, or false if the consumer is not in the Running state.
|
|
724
|
-
* @throws Error if the operation fails.
|
|
725
|
-
*/
|
|
726
|
-
isStalled(): Promise<boolean>;
|
|
727
|
-
|
|
728
|
-
/** Opens a read-only view of a published JSON value collection. */
|
|
729
|
-
state<T>(
|
|
730
|
-
subsystem: string,
|
|
731
|
-
definition: ValueDefinition<T>,
|
|
732
|
-
): Promise<PublishedValue<T>>;
|
|
733
|
-
/** Opens a read-only view of a published JSON map collection. */
|
|
734
|
-
state<V>(
|
|
735
|
-
subsystem: string,
|
|
736
|
-
definition: MapDefinition<V>,
|
|
737
|
-
): Promise<PublishedMap<V>>;
|
|
738
|
-
/** Opens a read-only view of a published JSON deque collection. */
|
|
739
|
-
state<T>(
|
|
740
|
-
subsystem: string,
|
|
741
|
-
definition: DequeDefinition<T>,
|
|
742
|
-
): Promise<PublishedDeque<T>>;
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Gets the source system identifier configured for the client.
|
|
746
|
-
*
|
|
747
|
-
* @returns The source system identifier.
|
|
748
|
-
*/
|
|
749
|
-
get sourceSystem(): string;
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Sends a message to a specified topic.
|
|
753
|
-
*
|
|
754
|
-
* @param topic - The name of the topic to send the message to.
|
|
755
|
-
* @param key - The key of the message.
|
|
756
|
-
* @param payload - The message payload (must be JSON-serializable).
|
|
757
|
-
* @param signal - An optional AbortSignal that can be used to cancel the send operation. When aborted, the promise will reject with the abort reason.
|
|
758
|
-
* @returns A promise that resolves when the message has been successfully sent.
|
|
759
|
-
* @throws Error if the send operation fails or is aborted.
|
|
760
|
-
*/
|
|
761
|
-
send<P>(
|
|
762
|
-
topic: string,
|
|
763
|
-
key: string,
|
|
764
|
-
payload: P & JsonCompatible<P>,
|
|
765
|
-
signal?: AbortSignal,
|
|
766
|
-
): Promise<void>;
|
|
767
|
-
|
|
768
|
-
/** Sends an excise record for a key. */
|
|
769
|
-
excise(topic: string, key: string, signal?: AbortSignal): Promise<void>;
|
|
770
|
-
|
|
771
|
-
/**
|
|
772
|
-
* Sends a request and returns one outcome for each subsystem.
|
|
773
|
-
*
|
|
774
|
-
* The map contains every selected subsystem. A missing response has a timeout outcome.
|
|
775
|
-
* @throws Error if the input is invalid, sending fails, shutdown starts, or the signal aborts.
|
|
776
|
-
*/
|
|
777
|
-
request<R = JsonValue>(
|
|
778
|
-
topic: string,
|
|
779
|
-
key: string,
|
|
780
|
-
payload: JsonValue,
|
|
781
|
-
options: RequestOptions,
|
|
782
|
-
): Promise<ReadonlyMap<string, Outcome<R>>>;
|
|
783
|
-
|
|
784
|
-
/** Sends an excise request and returns one outcome for each subsystem. */
|
|
785
|
-
requestExcise<R = JsonValue>(
|
|
786
|
-
topic: string,
|
|
787
|
-
key: string,
|
|
788
|
-
options: RequestOptions,
|
|
789
|
-
): Promise<ReadonlyMap<string, Outcome<R>>>;
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Subscribes to receive messages using the provided event handler.
|
|
793
|
-
*
|
|
794
|
-
* @param eventHandler - The event handler to process received messages and timers.
|
|
795
|
-
* @returns A promise that resolves when the subscription is successfully established and the consumer is ready to receive messages.
|
|
796
|
-
* @throws TypeError if any required handler method is missing.
|
|
797
|
-
* @throws Error if the subscription fails to establish.
|
|
798
|
-
*/
|
|
799
|
-
subscribe<P = JsonValue, R = JsonValue>(
|
|
800
|
-
eventHandler: EventHandler<P, R>,
|
|
801
|
-
): Promise<void>;
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Stops the consumer. You can subscribe again later.
|
|
805
|
-
*
|
|
806
|
-
* @returns A promise that resolves when the unsubscribe operation is complete.
|
|
807
|
-
* @throws Error if the unsubscribe operation fails.
|
|
808
|
-
*/
|
|
809
|
-
unsubscribe(): Promise<void>;
|
|
810
|
-
|
|
811
|
-
/**
|
|
812
|
-
* Shuts down the client and all its services.
|
|
813
|
-
* Concurrent and repeated calls await the same shutdown operation.
|
|
814
|
-
*
|
|
815
|
-
* @returns A promise that resolves when shutdown is complete.
|
|
816
|
-
* @throws Error if shutdown fails.
|
|
817
|
-
*/
|
|
818
|
-
shutdown(): Promise<void>;
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
/** Per-collection cache override for published reads. */
|
|
822
|
-
export interface ReadCacheOptions {
|
|
823
|
-
/** Cache duration in milliseconds. */
|
|
824
|
-
ttlMs: number;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
/** Read-only published value collection. */
|
|
828
|
-
export declare class PublishedValue<T = JsonValue> {
|
|
829
|
-
get(key: string): Promise<T | null>;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/** Read-only published map collection. */
|
|
833
|
-
export declare class PublishedMap<V = JsonValue> {
|
|
834
|
-
get(key: string, mapKey: string): Promise<V | null>;
|
|
835
|
-
getMany(key: string, mapKeys: string[]): Promise<Array<V | null>>;
|
|
836
|
-
has(key: string, mapKey: string): Promise<boolean>;
|
|
837
|
-
entries(
|
|
838
|
-
key: string,
|
|
839
|
-
direction?: ScanDirection,
|
|
840
|
-
): AsyncIterableIterator<[string, V]>;
|
|
841
|
-
keys(key: string, direction?: ScanDirection): AsyncIterableIterator<string>;
|
|
842
|
-
values(key: string, direction?: ScanDirection): AsyncIterableIterator<V>;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
/** Read-only published deque collection. */
|
|
846
|
-
export declare class PublishedDeque<T = JsonValue> {
|
|
847
|
-
length(key: string): Promise<number>;
|
|
848
|
-
isEmpty(key: string): Promise<boolean>;
|
|
849
|
-
at(key: string, index: number): Promise<T | null>;
|
|
850
|
-
values(key: string, direction?: ScanDirection): AsyncIterableIterator<T>;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
38
|
/**
|
|
854
39
|
* Initializes the logging system for the Prosody client.
|
|
855
40
|
*
|
|
@@ -859,133 +44,16 @@ export declare class PublishedDeque<T = JsonValue> {
|
|
|
859
44
|
*/
|
|
860
45
|
export function initialize(): void;
|
|
861
46
|
|
|
862
|
-
|
|
863
|
-
*
|
|
864
|
-
*
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
export
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
* @param logger - The JavaScript logger object with error, warn, info, debug, and trace methods.
|
|
876
|
-
* @throws Error if creating the new JavaScript logger fails.
|
|
877
|
-
*/
|
|
878
|
-
export function setLogger(logger: Logger): void;
|
|
879
|
-
|
|
880
|
-
/**
|
|
881
|
-
* Sets a JavaScript logger only if no logger is currently configured.
|
|
882
|
-
*
|
|
883
|
-
* This function is useful for providing a default logger without overriding
|
|
884
|
-
* an existing one that may have been set earlier.
|
|
885
|
-
*
|
|
886
|
-
* @param logger - The JavaScript logger object with error, warn, info, debug, and trace methods.
|
|
887
|
-
* @returns True if the logger was set (no previous logger existed), false if a logger was already configured.
|
|
888
|
-
* @throws Error if creating the new JavaScript logger fails.
|
|
889
|
-
*/
|
|
890
|
-
export function setLoggerIfUnset(logger: Logger): boolean;
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* Gets the current configured logger.
|
|
894
|
-
*
|
|
895
|
-
* @returns The current logger instance, or null/undefined if no logger is configured.
|
|
896
|
-
*/
|
|
897
|
-
export function getCurrentLogger(): Logger | null | undefined;
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* Base class for event handler errors.
|
|
901
|
-
* Provides a common interface for determining if an error is permanent.
|
|
902
|
-
*/
|
|
903
|
-
export abstract class EventHandlerError extends Error {
|
|
904
|
-
/**
|
|
905
|
-
* Indicates whether the error is permanent and should not be retried.
|
|
906
|
-
*/
|
|
907
|
-
abstract get isPermanent(): boolean;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Represents a transient error that may be resolved by retrying.
|
|
912
|
-
* These errors are temporary and the operation should be retried.
|
|
913
|
-
*/
|
|
914
|
-
export class TransientError extends EventHandlerError {
|
|
915
|
-
/**
|
|
916
|
-
* @returns Always false, indicating the error is not permanent.
|
|
917
|
-
*/
|
|
918
|
-
get isPermanent(): false;
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* Represents a permanent error that should not be retried.
|
|
923
|
-
* These errors indicate unrecoverable failures.
|
|
924
|
-
*/
|
|
925
|
-
export class PermanentError extends EventHandlerError {
|
|
926
|
-
/**
|
|
927
|
-
* @returns Always true, indicating the error is permanent.
|
|
928
|
-
*/
|
|
929
|
-
get isPermanent(): true;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
/**
|
|
933
|
-
* Represents a transient keyed-state failure that may succeed on a later
|
|
934
|
-
* attempt — a store read/write timeout, AND every caller mistake (a
|
|
935
|
-
* null/unrepresentable write, an item-shape mismatch, an out-of-range index, an
|
|
936
|
-
* invalid scan direction). Caller mistakes are transient on purpose so they
|
|
937
|
-
* retry and stay visible rather than discarding the message. Subclasses
|
|
938
|
-
* {@link TransientError}, so rethrowing it from a handler classifies the event
|
|
939
|
-
* transient through the existing error bridge unchanged.
|
|
940
|
-
*/
|
|
941
|
-
export class TransientStateError extends TransientError {}
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* Represents a permanent keyed-state failure a retry cannot resolve in-process
|
|
945
|
-
* — an unregistered collection name, a registered-identity mismatch, or a
|
|
946
|
-
* duplicate registration (or one a handler throws explicitly). Caller mistakes
|
|
947
|
-
* are NOT permanent; they are {@link TransientStateError}. Subclasses
|
|
948
|
-
* {@link PermanentError}, so rethrowing it from a handler classifies the event
|
|
949
|
-
* permanent through the existing error bridge unchanged.
|
|
950
|
-
*/
|
|
951
|
-
export class PermanentStateError extends PermanentError {}
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Name-branded predicate that narrows to either keyed-state error class,
|
|
955
|
-
* regardless of category.
|
|
956
|
-
*
|
|
957
|
-
* @param error - The value to test.
|
|
958
|
-
* @returns True when the value is a keyed-state error.
|
|
959
|
-
*/
|
|
960
|
-
export function isStateError(
|
|
961
|
-
error: unknown,
|
|
962
|
-
): error is PermanentStateError | TransientStateError;
|
|
963
|
-
|
|
964
|
-
/** Type alias for a constructor of an Error subclass. */
|
|
965
|
-
type ErrorClass<T extends Error> = new (...args: never[]) => T;
|
|
966
|
-
|
|
967
|
-
/**
|
|
968
|
-
* Type for a decorator function that can be applied to both methods and standalone functions.
|
|
969
|
-
*/
|
|
970
|
-
type DecoratorFunction = (
|
|
971
|
-
target: Function,
|
|
972
|
-
context: ClassMethodDecoratorContext | ClassFieldDecoratorContext,
|
|
973
|
-
) => Function | void;
|
|
974
|
-
|
|
975
|
-
/**
|
|
976
|
-
* Decorator factory for marking errors as transient.
|
|
977
|
-
* Can be applied to both methods and standalone functions.
|
|
978
|
-
* @param exceptionTypes The error types to be treated as transient.
|
|
979
|
-
*/
|
|
980
|
-
export declare function transient<E extends Error>(
|
|
981
|
-
...exceptionTypes: ErrorClass<E>[]
|
|
982
|
-
): DecoratorFunction;
|
|
983
|
-
|
|
984
|
-
/**
|
|
985
|
-
* Decorator factory for marking errors as permanent.
|
|
986
|
-
* Can be applied to both methods and standalone functions.
|
|
987
|
-
* @param exceptionTypes The error types to be treated as permanent.
|
|
988
|
-
*/
|
|
989
|
-
export declare function permanent<E extends Error>(
|
|
990
|
-
...exceptionTypes: ErrorClass<E>[]
|
|
991
|
-
): DecoratorFunction;
|
|
47
|
+
export * from "./lib/payload";
|
|
48
|
+
export * from "./lib/context";
|
|
49
|
+
export * from "./lib/state/query";
|
|
50
|
+
export * from "./lib/state/handle";
|
|
51
|
+
export * from "./lib/state/definitions";
|
|
52
|
+
export * from "./lib/state/value";
|
|
53
|
+
export * from "./lib/state/map";
|
|
54
|
+
export * from "./lib/state/set";
|
|
55
|
+
export * from "./lib/state/deque";
|
|
56
|
+
export * from "./lib/state/published";
|
|
57
|
+
export * from "./lib/client";
|
|
58
|
+
export * from "./lib/logging";
|
|
59
|
+
export * from "./lib/errors";
|