@prosody-events/prosody 0.1.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/LICENSE +21 -0
- package/README.md +978 -0
- package/bindings.d.ts +522 -0
- package/bindings.js +587 -0
- package/index.d.ts +307 -0
- package/index.js +588 -0
- package/package.json +82 -0
package/bindings.d.ts
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Represents a client for performing administrative operations on a Prosody
|
|
5
|
+
* cluster.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AdminClient {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new `AdminClient` instance.
|
|
10
|
+
*
|
|
11
|
+
* @param bootstrapServers - A single server address or an array of server
|
|
12
|
+
* addresses to connect to. @throws Error if the client cannot be
|
|
13
|
+
* created.
|
|
14
|
+
*/
|
|
15
|
+
constructor(bootstrapServers: string | Array<string>)
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new topic in the Prosody cluster.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The name of the topic to create.
|
|
20
|
+
* @param partitionCount - The number of partitions for the topic.
|
|
21
|
+
* @param replicationFactor - The replication factor for the topic.
|
|
22
|
+
* @throws Error if the topic creation fails.
|
|
23
|
+
*/
|
|
24
|
+
createTopic(name: string, partitionCount: number, replicationFactor: number): Promise<void>
|
|
25
|
+
/**
|
|
26
|
+
* Deletes a topic from the Prosody cluster.
|
|
27
|
+
*
|
|
28
|
+
* @param name - The name of the topic to delete.
|
|
29
|
+
* @throws Error if the topic deletion fails.
|
|
30
|
+
*/
|
|
31
|
+
deleteTopic(name: string): Promise<void>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A native client wrapper for the Prosody high-level client.
|
|
36
|
+
* Provides methods for sending messages, subscribing to topics, and managing
|
|
37
|
+
* consumer state.
|
|
38
|
+
*/
|
|
39
|
+
export declare class NativeClient {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new `NativeClient` instance.
|
|
42
|
+
*
|
|
43
|
+
* @param config - The configuration for the client
|
|
44
|
+
* @throws Error if the client creation fails
|
|
45
|
+
*/
|
|
46
|
+
constructor(config: Configuration)
|
|
47
|
+
/**
|
|
48
|
+
* Gets the current state of the consumer.
|
|
49
|
+
*
|
|
50
|
+
* @returns The current state of the consumer
|
|
51
|
+
* @throws Error if the operation fails
|
|
52
|
+
*/
|
|
53
|
+
consumerState(): Promise<ConsumerState>
|
|
54
|
+
/**
|
|
55
|
+
* Sends a message to a specified topic.
|
|
56
|
+
*
|
|
57
|
+
* @param topic - The topic to send the message to
|
|
58
|
+
* @param key - The key of the message
|
|
59
|
+
* @param payload - The payload of the message (must be JSON-serializable)
|
|
60
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
61
|
+
* @param maybeAbort - Optional promise that resolves when the operation
|
|
62
|
+
* should be aborted @returns A promise that resolves when the message
|
|
63
|
+
* has been sent @throws Error if the send operation fails or is
|
|
64
|
+
* aborted
|
|
65
|
+
*/
|
|
66
|
+
send(topic: string, key: string, payload: any, otelContext: Record<string, string>, maybeAbort?: Promise<undefined> | undefined | null): Promise<void>
|
|
67
|
+
/**
|
|
68
|
+
* Subscribes to receive messages using the provided event handler.
|
|
69
|
+
*
|
|
70
|
+
* @param eventHandler - The event handler to process received messages and
|
|
71
|
+
* timers @returns A promise that resolves when the subscription is
|
|
72
|
+
* established @throws Error if the subscription fails
|
|
73
|
+
*/
|
|
74
|
+
subscribe(eventHandler: { onMessage: (err: null | Error, args: [Context, Message, Record<string, string>]) => Promise<void>; onTimer: (err: null | Error, args: [Context, Timer, Record<string, string>]) => Promise<void>; isPermanent: (args: [Error]) => boolean }): Promise<void>
|
|
75
|
+
/**
|
|
76
|
+
* Gets the number of partitions assigned to the consumer.
|
|
77
|
+
*
|
|
78
|
+
* @returns The number of assigned partitions, or 0 if the consumer is not
|
|
79
|
+
* in the Running state @throws Error if the operation fails
|
|
80
|
+
*/
|
|
81
|
+
assignedPartitionCount(): Promise<number>
|
|
82
|
+
/**
|
|
83
|
+
* Checks if the consumer is stalled.
|
|
84
|
+
*
|
|
85
|
+
* @returns Whether the consumer is stalled, or false if the consumer is
|
|
86
|
+
* not in the Running state @throws Error if the operation fails
|
|
87
|
+
*/
|
|
88
|
+
isStalled(): Promise<boolean>
|
|
89
|
+
/**
|
|
90
|
+
* Unsubscribes from receiving messages and shuts down the consumer.
|
|
91
|
+
*
|
|
92
|
+
* @returns A promise that resolves when the unsubscribe operation is
|
|
93
|
+
* complete @throws Error if the unsubscribe operation fails
|
|
94
|
+
*/
|
|
95
|
+
unsubscribe(): Promise<void>
|
|
96
|
+
/**
|
|
97
|
+
* Gets the source system identifier configured for the client.
|
|
98
|
+
*
|
|
99
|
+
* @returns The source system identifier
|
|
100
|
+
*/
|
|
101
|
+
get sourceSystem(): string
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Wrapper around `MessageContext` for use in Node.js bindings. */
|
|
105
|
+
export declare class NativeContext {
|
|
106
|
+
/**
|
|
107
|
+
* Checks whether cancellation has been signaled.
|
|
108
|
+
*
|
|
109
|
+
* Cancellation includes message-level cancellation (e.g., timeout) and
|
|
110
|
+
* partition shutdown. During shutdown, cancellation is delayed until near
|
|
111
|
+
* the end of the shutdown timeout to allow in-flight work to complete.
|
|
112
|
+
*
|
|
113
|
+
* @returns True if cancellation was requested, otherwise false.
|
|
114
|
+
*/
|
|
115
|
+
get shouldCancel(): boolean
|
|
116
|
+
/**
|
|
117
|
+
* Waits for a cancellation signal.
|
|
118
|
+
*
|
|
119
|
+
* Cancellation includes message-level cancellation (e.g., timeout) and
|
|
120
|
+
* partition shutdown. During shutdown, cancellation is delayed until near
|
|
121
|
+
* the end of the shutdown timeout to allow in-flight work to complete.
|
|
122
|
+
*
|
|
123
|
+
* @returns A promise that resolves when cancellation is signaled.
|
|
124
|
+
*/
|
|
125
|
+
onCancel(): Promise<void>
|
|
126
|
+
/**
|
|
127
|
+
* Schedule a timer at the given time.
|
|
128
|
+
*
|
|
129
|
+
* @param time - The UTC timestamp to schedule.
|
|
130
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
131
|
+
* @throws Error if time conversion or scheduling fails.
|
|
132
|
+
*/
|
|
133
|
+
schedule(time: Date, otelContext: Record<string, string>): Promise<void>
|
|
134
|
+
/**
|
|
135
|
+
* Clear existing timers and schedule a new one at the given time.
|
|
136
|
+
*
|
|
137
|
+
* @param time - The UTC timestamp to schedule.
|
|
138
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
139
|
+
* @throws Error if time conversion or scheduling fails.
|
|
140
|
+
*/
|
|
141
|
+
clearAndSchedule(time: Date, otelContext: Record<string, string>): Promise<void>
|
|
142
|
+
/**
|
|
143
|
+
* Unschedules the timer for the specified time.
|
|
144
|
+
* @param time - The time to unschedule.
|
|
145
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
146
|
+
* @throws Error if unscheduling fails.
|
|
147
|
+
*/
|
|
148
|
+
unschedule(time: Date, otelContext: Record<string, string>): Promise<void>
|
|
149
|
+
/**
|
|
150
|
+
* Clears all scheduled timers.
|
|
151
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
152
|
+
* @throws Error if clearing schedules fails.
|
|
153
|
+
*/
|
|
154
|
+
clearScheduled(otelContext: Record<string, string>): Promise<void>
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves all scheduled times.
|
|
157
|
+
* @param otelContext - The OpenTelemetry context for tracing
|
|
158
|
+
* @returns An array of scheduled times as Date objects.
|
|
159
|
+
* @throws Error if retrieval fails.
|
|
160
|
+
*/
|
|
161
|
+
scheduled(otelContext: Record<string, string>): Promise<Array<Date>>
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Configuration options for the Prosody client. */
|
|
165
|
+
export interface Configuration {
|
|
166
|
+
/** Kafka servers for initial connection. */
|
|
167
|
+
bootstrapServers?: string | Array<string>
|
|
168
|
+
/** Use mock client for testing if true. */
|
|
169
|
+
mock?: boolean
|
|
170
|
+
/** Timeout for message send operations in milliseconds. */
|
|
171
|
+
sendTimeoutMs?: number
|
|
172
|
+
/** Consumer group name. */
|
|
173
|
+
groupId?: string
|
|
174
|
+
/**
|
|
175
|
+
* Global shared cache capacity across all partitions for deduplicating
|
|
176
|
+
* messages. Set to 0 to disable deduplication entirely.
|
|
177
|
+
*/
|
|
178
|
+
idempotenceCacheSize?: number
|
|
179
|
+
/**
|
|
180
|
+
* Version string for cache-busting deduplication hashes.
|
|
181
|
+
*
|
|
182
|
+
* Changing this value invalidates all previously recorded dedup entries,
|
|
183
|
+
* causing messages to be reprocessed.
|
|
184
|
+
*/
|
|
185
|
+
idempotenceVersion?: string
|
|
186
|
+
/**
|
|
187
|
+
* TTL for deduplication records in Cassandra in seconds.
|
|
188
|
+
*
|
|
189
|
+
* Must be at least 1 minute. Defaults to 7 days.
|
|
190
|
+
*/
|
|
191
|
+
idempotenceTtlS?: number
|
|
192
|
+
/** Topics to subscribe to. */
|
|
193
|
+
subscribedTopics?: string | Array<string>
|
|
194
|
+
/** Allowed event type prefixes. All event types are allowed if unset. */
|
|
195
|
+
allowedEvents?: string | Array<string>
|
|
196
|
+
/**
|
|
197
|
+
* Identifier for the producing system, used to prevent loops.
|
|
198
|
+
* Defaults to the consumer group name.
|
|
199
|
+
*/
|
|
200
|
+
sourceSystem?: string
|
|
201
|
+
/** Maximum global concurrency limit. */
|
|
202
|
+
maxConcurrency?: number
|
|
203
|
+
/** Max number of uncommitted messages. */
|
|
204
|
+
maxUncommitted?: number
|
|
205
|
+
/** Threshold determining when message processing has stalled. */
|
|
206
|
+
stallThresholdMs?: number
|
|
207
|
+
/**
|
|
208
|
+
* Shutdown budget; handlers complete freely before cancellation fires
|
|
209
|
+
* near the deadline.
|
|
210
|
+
*/
|
|
211
|
+
shutdownTimeoutMs?: number
|
|
212
|
+
/** Time between message polls in milliseconds. */
|
|
213
|
+
pollIntervalMs?: number
|
|
214
|
+
/** Time between offset commits in milliseconds. */
|
|
215
|
+
commitIntervalMs?: number
|
|
216
|
+
/** Operating mode. */
|
|
217
|
+
mode?: Mode
|
|
218
|
+
/** Initial delay for exponential backoff in retries in milliseconds. */
|
|
219
|
+
retryBaseMs?: number
|
|
220
|
+
/** Maximum number of retries. */
|
|
221
|
+
maxRetries?: number
|
|
222
|
+
/** Maximum delay between retries in milliseconds. */
|
|
223
|
+
maxRetryDelayMs?: number
|
|
224
|
+
/** Topic for failed messages in low-latency mode. */
|
|
225
|
+
failureTopic?: string
|
|
226
|
+
/** Port for the probe server. Set to null to disable. */
|
|
227
|
+
probePort?: number | null
|
|
228
|
+
/**
|
|
229
|
+
* Timer slab partitioning duration in milliseconds.
|
|
230
|
+
* Controls how timers are grouped for storage and retrieval.
|
|
231
|
+
*/
|
|
232
|
+
slabSizeMs?: number
|
|
233
|
+
/** Cassandra contact nodes (hostnames or IPs). */
|
|
234
|
+
cassandraNodes?: string | Array<string>
|
|
235
|
+
/** Cassandra keyspace to use for storing timer data. */
|
|
236
|
+
cassandraKeyspace?: string
|
|
237
|
+
/** Preferred Cassandra datacenter for query routing. */
|
|
238
|
+
cassandraDatacenter?: string
|
|
239
|
+
/** Preferred Cassandra rack identifier for topology-aware routing. */
|
|
240
|
+
cassandraRack?: string
|
|
241
|
+
/** Username for authenticating with Cassandra. */
|
|
242
|
+
cassandraUser?: string
|
|
243
|
+
/** Password for authenticating with Cassandra. */
|
|
244
|
+
cassandraPassword?: string
|
|
245
|
+
/**
|
|
246
|
+
* Retention period for failed/unprocessed timer data in Cassandra in
|
|
247
|
+
* seconds.
|
|
248
|
+
*/
|
|
249
|
+
cassandraRetentionSeconds?: number
|
|
250
|
+
/**
|
|
251
|
+
* Target proportion of execution time for failure/retry task processing
|
|
252
|
+
* (0.0 to 1.0). Controls bandwidth allocation between Normal and
|
|
253
|
+
* Failure task classes. Higher values allocate more execution time to
|
|
254
|
+
* retrying failed tasks.
|
|
255
|
+
*/
|
|
256
|
+
schedulerFailureWeight?: number
|
|
257
|
+
/**
|
|
258
|
+
* Wait duration (in milliseconds) at which urgency boost reaches maximum
|
|
259
|
+
* intensity. Controls how quickly wait urgency ramps up for queued
|
|
260
|
+
* tasks. Shorter values make the scheduler more responsive to wait
|
|
261
|
+
* time.
|
|
262
|
+
*/
|
|
263
|
+
schedulerMaxWaitMs?: number
|
|
264
|
+
/**
|
|
265
|
+
* Maximum urgency boost (in seconds of virtual time) for waiting tasks.
|
|
266
|
+
* Higher values increase the importance of wait time relative to virtual
|
|
267
|
+
* time fairness.
|
|
268
|
+
*/
|
|
269
|
+
schedulerWaitWeight?: number
|
|
270
|
+
/**
|
|
271
|
+
* Cache capacity for tracking per-key virtual time in the scheduler.
|
|
272
|
+
* Larger caches provide more accurate long-term fairness across many keys.
|
|
273
|
+
*/
|
|
274
|
+
schedulerCacheSize?: number
|
|
275
|
+
/**
|
|
276
|
+
* Whether monopolization detection is enabled.
|
|
277
|
+
* When disabled, the monopolization middleware is bypassed.
|
|
278
|
+
*/
|
|
279
|
+
monopolizationEnabled?: boolean
|
|
280
|
+
/**
|
|
281
|
+
* Threshold for monopolization detection (0.0 to 1.0).
|
|
282
|
+
* If a key's execution time exceeds this fraction of the window duration,
|
|
283
|
+
* it is considered to be monopolizing execution.
|
|
284
|
+
*/
|
|
285
|
+
monopolizationThreshold?: number
|
|
286
|
+
/** Rolling window duration (in milliseconds) for monopolization detection. */
|
|
287
|
+
monopolizationWindowMs?: number
|
|
288
|
+
/**
|
|
289
|
+
* Cache size for tracking key execution intervals in monopolization
|
|
290
|
+
* detection.
|
|
291
|
+
*/
|
|
292
|
+
monopolizationCacheSize?: number
|
|
293
|
+
/**
|
|
294
|
+
* Whether deferral is enabled for new messages.
|
|
295
|
+
* When disabled, transient failures will not be deferred.
|
|
296
|
+
*/
|
|
297
|
+
deferEnabled?: boolean
|
|
298
|
+
/**
|
|
299
|
+
* Base exponential backoff delay for deferred retries in milliseconds.
|
|
300
|
+
* Handles persistent failures that need time to recover.
|
|
301
|
+
*/
|
|
302
|
+
deferBaseMs?: number
|
|
303
|
+
/**
|
|
304
|
+
* Maximum delay between deferred retries in milliseconds.
|
|
305
|
+
* Caps exponential backoff to prevent excessively long delays.
|
|
306
|
+
*/
|
|
307
|
+
deferMaxDelayMs?: number
|
|
308
|
+
/**
|
|
309
|
+
* Failure rate threshold for enabling deferral (0.0 to 1.0).
|
|
310
|
+
* When exceeded within the failure window, deferral is disabled.
|
|
311
|
+
*/
|
|
312
|
+
deferFailureThreshold?: number
|
|
313
|
+
/** Sliding window duration (in milliseconds) for failure rate tracking. */
|
|
314
|
+
deferFailureWindowMs?: number
|
|
315
|
+
/**
|
|
316
|
+
* Cache size for defer middleware.
|
|
317
|
+
* Controls capacity for store cache and loader cache.
|
|
318
|
+
*/
|
|
319
|
+
deferCacheSize?: number
|
|
320
|
+
/** Timeout for Kafka seek operations in milliseconds. */
|
|
321
|
+
deferSeekTimeoutMs?: number
|
|
322
|
+
/**
|
|
323
|
+
* Messages to read sequentially before seeking.
|
|
324
|
+
* If next offset is within this threshold, reads rather than seeks.
|
|
325
|
+
*/
|
|
326
|
+
deferDiscardThreshold?: number
|
|
327
|
+
/**
|
|
328
|
+
* Fixed timeout duration for handler execution in milliseconds.
|
|
329
|
+
* If unset, defaults to 80% of stall threshold.
|
|
330
|
+
*/
|
|
331
|
+
timeoutMs?: number
|
|
332
|
+
/** Kafka topic to produce telemetry events to. */
|
|
333
|
+
telemetryTopic?: string
|
|
334
|
+
/** Whether the telemetry emitter is enabled. */
|
|
335
|
+
telemetryEnabled?: boolean
|
|
336
|
+
/**
|
|
337
|
+
* Span linking for message execution spans.
|
|
338
|
+
*
|
|
339
|
+
* Controls how the receive span connects to the `OTel` context propagated
|
|
340
|
+
* from the Kafka message producer. Accepted values: `"child"` (child-of
|
|
341
|
+
* relationship) or `"follows_from"`. Default: `"child"`.
|
|
342
|
+
*/
|
|
343
|
+
messageSpans?: string
|
|
344
|
+
/**
|
|
345
|
+
* Span linking for timer execution spans.
|
|
346
|
+
*
|
|
347
|
+
* Controls how timer spans connect to the `OTel` context stored when the
|
|
348
|
+
* timer was scheduled. Accepted values: `"child"` (child-of relationship)
|
|
349
|
+
* or `"follows_from"`. Default: `"follows_from"`.
|
|
350
|
+
*/
|
|
351
|
+
timerSpans?: string
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Current state of the consumer.
|
|
356
|
+
* Represents the lifecycle stages of a Prosody consumer.
|
|
357
|
+
*/
|
|
358
|
+
export type ConsumerState = /** The consumer is not yet configured */
|
|
359
|
+
'Unconfigured'|
|
|
360
|
+
/** The consumer is configured but not running */
|
|
361
|
+
'Configured'|
|
|
362
|
+
/** The consumer is actively running */
|
|
363
|
+
'Running'|
|
|
364
|
+
/** The consumer configuration failed */
|
|
365
|
+
'ConfigurationFailed';
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Initializes the logging system for the Prosody client.
|
|
369
|
+
*
|
|
370
|
+
* This function sets up the tracing infrastructure and prepares the logging
|
|
371
|
+
* system to accept JavaScript loggers. It should be called once during
|
|
372
|
+
* application startup before any other logging operations.
|
|
373
|
+
*/
|
|
374
|
+
export declare function initialize(): void
|
|
375
|
+
|
|
376
|
+
/** Type alias for error classification arguments. */
|
|
377
|
+
export type IsPermanentArgs =
|
|
378
|
+
[Error]
|
|
379
|
+
|
|
380
|
+
/** Type alias for the arguments passed to JavaScript logging functions. */
|
|
381
|
+
export type LogArgs =
|
|
382
|
+
[string | undefined | null, any]
|
|
383
|
+
|
|
384
|
+
/** JavaScript-compatible logger structure. */
|
|
385
|
+
export interface Logger {
|
|
386
|
+
/** Function for logging error messages. */
|
|
387
|
+
error: (arg: LogArgs) => void
|
|
388
|
+
/** Function for logging warning messages. */
|
|
389
|
+
warn: (arg: LogArgs) => void
|
|
390
|
+
/** Function for logging informational messages. */
|
|
391
|
+
info: (arg: LogArgs) => void
|
|
392
|
+
/** Function for logging debug messages. */
|
|
393
|
+
debug: (arg: LogArgs) => void
|
|
394
|
+
/** Function for logging trace messages. */
|
|
395
|
+
trace: (arg: LogArgs) => void
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Checks if a logger has been set in the logging system.
|
|
400
|
+
*
|
|
401
|
+
* @returns True if a logger is currently configured, false otherwise.
|
|
402
|
+
*/
|
|
403
|
+
export declare function loggerIsSet(): boolean
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Represents a message consumed from a Kafka topic.
|
|
407
|
+
*
|
|
408
|
+
* This object contains all the relevant information about a Kafka message,
|
|
409
|
+
* including its topic, partition, offset, timestamp, key, and payload.
|
|
410
|
+
*/
|
|
411
|
+
export interface Message {
|
|
412
|
+
/** The name of the topic from which the message was consumed. */
|
|
413
|
+
topic: string
|
|
414
|
+
/** The partition number from which the message was consumed. */
|
|
415
|
+
partition: number
|
|
416
|
+
/** The message offset within the partition. */
|
|
417
|
+
offset: number
|
|
418
|
+
/** The timestamp when the message was created or sent to Kafka. */
|
|
419
|
+
timestamp: Date
|
|
420
|
+
/** The message key. */
|
|
421
|
+
key: string
|
|
422
|
+
/** The message payload as a JSON-serializable value. */
|
|
423
|
+
payload: any
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Type alias for message handler arguments. */
|
|
427
|
+
export type MessageHandlerArgs =
|
|
428
|
+
[NativeContext, Message, Record<string, string>]
|
|
429
|
+
|
|
430
|
+
/** Enum representing the operating mode of the Prosody client. */
|
|
431
|
+
export type Mode = /** Pipeline mode for standard processing. */
|
|
432
|
+
'Pipeline'|
|
|
433
|
+
/** Low-latency mode for faster processing with potential trade-offs. */
|
|
434
|
+
'LowLatency'|
|
|
435
|
+
/**
|
|
436
|
+
* Best-effort mode for development or when messages can be discarded when
|
|
437
|
+
* processing fails
|
|
438
|
+
*/
|
|
439
|
+
'BestEffort';
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Represents a native handler for processing messages and timers.
|
|
443
|
+
*
|
|
444
|
+
* This struct contains functions that handle incoming messages, timer events,
|
|
445
|
+
* and error classification for the Prosody consumer.
|
|
446
|
+
*/
|
|
447
|
+
export interface NativeHandler {
|
|
448
|
+
/**
|
|
449
|
+
* A function to be called when a message is received.
|
|
450
|
+
*
|
|
451
|
+
* @param context - A Context object representing the message processing
|
|
452
|
+
* context @param message - A Message object containing the received
|
|
453
|
+
* Kafka message @param otelContext - A record of string key-value
|
|
454
|
+
* pairs representing the OpenTelemetry context @returns A Promise that
|
|
455
|
+
* resolves when the message has been processed
|
|
456
|
+
*
|
|
457
|
+
* Note: Error parameter is automatically added by CalleeHandled=true
|
|
458
|
+
*/
|
|
459
|
+
onMessage: (arg: MessageHandlerArgs) => Promise<undefined>
|
|
460
|
+
/**
|
|
461
|
+
* A function to be called when a timer fires.
|
|
462
|
+
*
|
|
463
|
+
* @param context - A Context object representing the timer processing
|
|
464
|
+
* context @param timer - A Timer object containing the timer details
|
|
465
|
+
* @param otelContext - A record of string key-value pairs representing the
|
|
466
|
+
* OpenTelemetry context @returns A Promise that resolves when the
|
|
467
|
+
* timer has been processed
|
|
468
|
+
*
|
|
469
|
+
* Note: Error parameter is automatically added by CalleeHandled=true
|
|
470
|
+
*/
|
|
471
|
+
onTimer: (arg: TimerHandlerArgs) => Promise<undefined>
|
|
472
|
+
/**
|
|
473
|
+
* Function that determines whether an error is permanent.
|
|
474
|
+
*
|
|
475
|
+
* @param err - An Error object to classify
|
|
476
|
+
* @returns A boolean that is true when the given error is permanent and
|
|
477
|
+
* false otherwise
|
|
478
|
+
*/
|
|
479
|
+
isPermanent: (arg: IsPermanentArgs) => boolean
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Sets a new JavaScript logger for the Prosody client.
|
|
484
|
+
*
|
|
485
|
+
* This function configures the logging system to use the provided JavaScript
|
|
486
|
+
* logger for all log output. The logger must implement all required log
|
|
487
|
+
* levels.
|
|
488
|
+
*
|
|
489
|
+
* @param logger - The JavaScript logger object with error, warn, info, debug,
|
|
490
|
+
* and trace methods. @throws Error if creating the new JavaScript logger
|
|
491
|
+
* fails.
|
|
492
|
+
*/
|
|
493
|
+
export declare function setLogger(logger: Logger): void
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Sets a JavaScript logger only if no logger is currently configured.
|
|
497
|
+
*
|
|
498
|
+
* This function is useful for providing a default logger without overriding
|
|
499
|
+
* an existing one that may have been set earlier.
|
|
500
|
+
*
|
|
501
|
+
* @param logger - The JavaScript logger object with error, warn, info, debug,
|
|
502
|
+
* and trace methods. @returns True if the logger was set (no previous logger
|
|
503
|
+
* existed), false if a logger was already configured. @throws Error if
|
|
504
|
+
* creating the new JavaScript logger fails.
|
|
505
|
+
*/
|
|
506
|
+
export declare function setLoggerIfUnset(logger: Logger): boolean
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Represents a timer event.
|
|
510
|
+
*
|
|
511
|
+
* Contains the key and scheduled time for a timer trigger.
|
|
512
|
+
*/
|
|
513
|
+
export interface Timer {
|
|
514
|
+
/** The timer key. */
|
|
515
|
+
key: string
|
|
516
|
+
/** The timer trigger time */
|
|
517
|
+
time: Date
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** Type alias for timer handler arguments. */
|
|
521
|
+
export type TimerHandlerArgs =
|
|
522
|
+
[NativeContext, Timer, Record<string, string>]
|