@vercel/queue 0.0.0-alpha.6 → 0.0.0-alpha.7
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 +130 -192
- package/dist/index.d.mts +1 -385
- package/dist/index.d.ts +1 -385
- package/dist/index.js +75 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -83
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -71,19 +71,6 @@ declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
|
|
|
71
71
|
* Vercel Queue Service client types
|
|
72
72
|
*/
|
|
73
73
|
|
|
74
|
-
interface QueueClientOptions {
|
|
75
|
-
/**
|
|
76
|
-
* Base URL for the Vercel Queue Service API
|
|
77
|
-
* @default "https://vqs.vercel.sh"
|
|
78
|
-
*/
|
|
79
|
-
baseUrl?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Vercel function OIDC token
|
|
82
|
-
* Can be obtained from x-vercel-oidc-token header in Vercel Serverless Functions
|
|
83
|
-
* If not provided, will automatically attempt to retrieve from Vercel Function environment
|
|
84
|
-
*/
|
|
85
|
-
token?: string;
|
|
86
|
-
}
|
|
87
74
|
/**
|
|
88
75
|
* Shared options for publishing messages
|
|
89
76
|
*/
|
|
@@ -145,79 +132,6 @@ interface Message<T = unknown> {
|
|
|
145
132
|
*/
|
|
146
133
|
ticket: string;
|
|
147
134
|
}
|
|
148
|
-
interface ReceiveMessagesOptions<T = unknown> {
|
|
149
|
-
/**
|
|
150
|
-
* The queue name to receive messages from
|
|
151
|
-
*/
|
|
152
|
-
queueName: string;
|
|
153
|
-
/**
|
|
154
|
-
* Consumer group name
|
|
155
|
-
*/
|
|
156
|
-
consumerGroup: string;
|
|
157
|
-
/**
|
|
158
|
-
* Time in seconds that messages will be invisible to other consumers
|
|
159
|
-
* @default 900 (15 minutes)
|
|
160
|
-
*/
|
|
161
|
-
visibilityTimeoutSeconds?: number;
|
|
162
|
-
/**
|
|
163
|
-
* Maximum number of messages to retrieve
|
|
164
|
-
* @default 10
|
|
165
|
-
* @max 10
|
|
166
|
-
*/
|
|
167
|
-
limit?: number;
|
|
168
|
-
}
|
|
169
|
-
interface DeleteMessageOptions {
|
|
170
|
-
/**
|
|
171
|
-
* The queue name the message belongs to
|
|
172
|
-
*/
|
|
173
|
-
queueName: string;
|
|
174
|
-
/**
|
|
175
|
-
* Consumer group name
|
|
176
|
-
*/
|
|
177
|
-
consumerGroup: string;
|
|
178
|
-
/**
|
|
179
|
-
* The message ID to delete
|
|
180
|
-
*/
|
|
181
|
-
messageId: string;
|
|
182
|
-
/**
|
|
183
|
-
* Ticket received from the message
|
|
184
|
-
*/
|
|
185
|
-
ticket: string;
|
|
186
|
-
}
|
|
187
|
-
interface DeleteMessageResponse {
|
|
188
|
-
/**
|
|
189
|
-
* Whether the message was successfully deleted
|
|
190
|
-
*/
|
|
191
|
-
deleted: boolean;
|
|
192
|
-
}
|
|
193
|
-
interface ChangeVisibilityOptions {
|
|
194
|
-
/**
|
|
195
|
-
* The queue name the message belongs to
|
|
196
|
-
*/
|
|
197
|
-
queueName: string;
|
|
198
|
-
/**
|
|
199
|
-
* Consumer group name
|
|
200
|
-
*/
|
|
201
|
-
consumerGroup: string;
|
|
202
|
-
/**
|
|
203
|
-
* The message ID to update
|
|
204
|
-
*/
|
|
205
|
-
messageId: string;
|
|
206
|
-
/**
|
|
207
|
-
* Ticket received from the message
|
|
208
|
-
*/
|
|
209
|
-
ticket: string;
|
|
210
|
-
/**
|
|
211
|
-
* New visibility timeout in seconds
|
|
212
|
-
*/
|
|
213
|
-
visibilityTimeoutSeconds: number;
|
|
214
|
-
}
|
|
215
|
-
interface ChangeVisibilityResponse {
|
|
216
|
-
/**
|
|
217
|
-
* Whether the visibility was successfully updated
|
|
218
|
-
*/
|
|
219
|
-
updated: boolean;
|
|
220
|
-
}
|
|
221
135
|
/**
|
|
222
136
|
* Result indicating the message should be timed out for retry later
|
|
223
137
|
*/
|
|
@@ -263,34 +177,6 @@ interface ConsumerGroupOptions<T = unknown> {
|
|
|
263
177
|
*/
|
|
264
178
|
refreshInterval?: number;
|
|
265
179
|
}
|
|
266
|
-
interface ReceiveMessageByIdOptions<T = unknown> {
|
|
267
|
-
/**
|
|
268
|
-
* The queue name to receive the message from
|
|
269
|
-
*/
|
|
270
|
-
queueName: string;
|
|
271
|
-
/**
|
|
272
|
-
* Consumer group name
|
|
273
|
-
*/
|
|
274
|
-
consumerGroup: string;
|
|
275
|
-
/**
|
|
276
|
-
* The message ID to retrieve
|
|
277
|
-
*/
|
|
278
|
-
messageId: string;
|
|
279
|
-
/**
|
|
280
|
-
* Time in seconds that the message will be invisible to other consumers
|
|
281
|
-
* @default 900 (15 minutes)
|
|
282
|
-
*/
|
|
283
|
-
visibilityTimeoutSeconds?: number;
|
|
284
|
-
/**
|
|
285
|
-
* Skip payload content and only return message metadata
|
|
286
|
-
* When true, the server returns a 204 status with headers containing message metadata
|
|
287
|
-
* @default false
|
|
288
|
-
*/
|
|
289
|
-
skipPayload?: boolean;
|
|
290
|
-
}
|
|
291
|
-
interface ReceiveMessageByIdResponse<T = unknown, TSkipPayload extends boolean = false> {
|
|
292
|
-
message: TSkipPayload extends true ? Message<void> : Message<T>;
|
|
293
|
-
}
|
|
294
180
|
/**
|
|
295
181
|
* Error thrown when a message is not found (404)
|
|
296
182
|
*/
|
|
@@ -354,103 +240,6 @@ declare class InvalidLimitError extends Error {
|
|
|
354
240
|
constructor(limit: number, min?: number, max?: number);
|
|
355
241
|
}
|
|
356
242
|
|
|
357
|
-
/**
|
|
358
|
-
* Client for interacting with the Vercel Queue Service API
|
|
359
|
-
*/
|
|
360
|
-
declare class QueueClient {
|
|
361
|
-
private baseUrl;
|
|
362
|
-
private token;
|
|
363
|
-
/**
|
|
364
|
-
* Internal default instance for use by createTopic and other convenience functions
|
|
365
|
-
* @internal
|
|
366
|
-
*/
|
|
367
|
-
private static _defaultInstance;
|
|
368
|
-
/**
|
|
369
|
-
* Create a new Vercel Queue Service client
|
|
370
|
-
* @param options Client configuration options (optional - will auto-detect Vercel Function environment)
|
|
371
|
-
*/
|
|
372
|
-
constructor(options?: QueueClientOptions);
|
|
373
|
-
/**
|
|
374
|
-
* Get the default client instance for internal use by convenience functions
|
|
375
|
-
* @internal
|
|
376
|
-
*/
|
|
377
|
-
static _getDefaultInstance(): QueueClient;
|
|
378
|
-
/**
|
|
379
|
-
* Synchronously get OIDC token from environment
|
|
380
|
-
* Used internally by constructor - mirrors the logic from getVercelOidcToken but synchronously
|
|
381
|
-
*/
|
|
382
|
-
private getVercelOidcTokenSync;
|
|
383
|
-
/**
|
|
384
|
-
* Send a message to a queue
|
|
385
|
-
* @param options Send message options
|
|
386
|
-
* @param transport Serializer/deserializer for the payload
|
|
387
|
-
* @returns Promise with the message ID
|
|
388
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
389
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
390
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
391
|
-
* @throws {InternalServerError} When server encounters an error
|
|
392
|
-
*/
|
|
393
|
-
sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
|
|
394
|
-
/**
|
|
395
|
-
* Receive messages from a queue
|
|
396
|
-
* @param options Receive messages options
|
|
397
|
-
* @param transport Serializer/deserializer for the payload
|
|
398
|
-
* @returns AsyncGenerator that yields messages as they arrive
|
|
399
|
-
* @throws {InvalidLimitError} When limit parameter is not between 1 and 10
|
|
400
|
-
* @throws {QueueEmptyError} When no messages are available (204)
|
|
401
|
-
* @throws {MessageLockedError} When messages are temporarily locked (423)
|
|
402
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
403
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
404
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
405
|
-
* @throws {InternalServerError} When server encounters an error
|
|
406
|
-
*/
|
|
407
|
-
receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
|
|
408
|
-
/**
|
|
409
|
-
* Receive a specific message by its ID from a queue
|
|
410
|
-
* @param options Receive message by ID options
|
|
411
|
-
* @param transport Serializer/deserializer for the payload
|
|
412
|
-
* @returns Promise with the message or null if not found/available
|
|
413
|
-
* @throws {MessageNotFoundError} When the message doesn't exist (404)
|
|
414
|
-
* @throws {MessageLockedError} When the message is temporarily locked (423)
|
|
415
|
-
* @throws {MessageNotAvailableError} When message exists but isn't available (409)
|
|
416
|
-
* @throws {MessageCorruptedError} When message data is corrupted
|
|
417
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
418
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
419
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
420
|
-
* @throws {InternalServerError} When server encounters an error
|
|
421
|
-
*/
|
|
422
|
-
receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
|
|
423
|
-
skipPayload: true;
|
|
424
|
-
}, transport?: Transport<T>): Promise<ReceiveMessageByIdResponse<T, true>>;
|
|
425
|
-
receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
|
|
426
|
-
skipPayload?: false | undefined;
|
|
427
|
-
}, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T, false>>;
|
|
428
|
-
/**
|
|
429
|
-
* Delete a message (acknowledge processing)
|
|
430
|
-
* @param options Delete message options
|
|
431
|
-
* @returns Promise with delete status
|
|
432
|
-
* @throws {MessageNotFoundError} When the message doesn't exist (404)
|
|
433
|
-
* @throws {MessageNotAvailableError} When message can't be deleted (409)
|
|
434
|
-
* @throws {BadRequestError} When ticket is missing or invalid (400)
|
|
435
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
436
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
437
|
-
* @throws {InternalServerError} When server encounters an error
|
|
438
|
-
*/
|
|
439
|
-
deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
|
|
440
|
-
/**
|
|
441
|
-
* Change the visibility timeout of a message
|
|
442
|
-
* @param options Change visibility options
|
|
443
|
-
* @returns Promise with update status
|
|
444
|
-
* @throws {MessageNotFoundError} When the message doesn't exist (404)
|
|
445
|
-
* @throws {MessageNotAvailableError} When message can't be updated (409)
|
|
446
|
-
* @throws {BadRequestError} When ticket is missing or visibility timeout invalid (400)
|
|
447
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
448
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
449
|
-
* @throws {InternalServerError} When server encounters an error
|
|
450
|
-
*/
|
|
451
|
-
changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
243
|
/**
|
|
455
244
|
* Options for the consume method
|
|
456
245
|
*/
|
|
@@ -460,140 +249,7 @@ interface ConsumeOptions {
|
|
|
460
249
|
/** Whether to skip downloading the payload (only allowed when messageId is provided) */
|
|
461
250
|
skipPayload?: boolean;
|
|
462
251
|
}
|
|
463
|
-
/**
|
|
464
|
-
* A ConsumerGroup represents a named group of consumers that process messages from a topic
|
|
465
|
-
*/
|
|
466
|
-
declare class ConsumerGroup<T = unknown> {
|
|
467
|
-
private client;
|
|
468
|
-
private topicName;
|
|
469
|
-
private consumerGroupName;
|
|
470
|
-
private visibilityTimeout;
|
|
471
|
-
private refreshInterval;
|
|
472
|
-
private transport;
|
|
473
|
-
/**
|
|
474
|
-
* Create a new ConsumerGroup instance
|
|
475
|
-
* @param client QueueClient instance to use for API calls
|
|
476
|
-
* @param topicName Name of the topic to consume from
|
|
477
|
-
* @param consumerGroupName Name of the consumer group
|
|
478
|
-
* @param options Optional configuration
|
|
479
|
-
*/
|
|
480
|
-
constructor(client: QueueClient, topicName: string, consumerGroupName: string, options?: ConsumerGroupOptions<T>);
|
|
481
|
-
/**
|
|
482
|
-
* Starts a background loop that periodically extends the visibility timeout for a message.
|
|
483
|
-
* This prevents the message from becoming visible to other consumers while it's being processed.
|
|
484
|
-
*
|
|
485
|
-
* The extension loop runs every `refreshInterval` seconds and updates the message's
|
|
486
|
-
* visibility timeout to `visibilityTimeout` seconds from the current time.
|
|
487
|
-
*
|
|
488
|
-
* @param messageId - The unique identifier of the message to extend visibility for
|
|
489
|
-
* @param ticket - The receipt ticket that proves ownership of the message
|
|
490
|
-
* @returns A function that when called will stop the extension loop
|
|
491
|
-
*
|
|
492
|
-
* @remarks
|
|
493
|
-
* - The first extension attempt occurs after `refreshInterval` seconds, not immediately
|
|
494
|
-
* - If an extension fails, the loop terminates with an error logged to console
|
|
495
|
-
* - The returned stop function is idempotent - calling it multiple times is safe
|
|
496
|
-
* - By default, the stop function returns immediately without waiting for in-flight
|
|
497
|
-
* - Pass `true` to the stop function to wait for any in-flight extension to complete
|
|
498
|
-
*/
|
|
499
|
-
private startVisibilityExtension;
|
|
500
|
-
/**
|
|
501
|
-
* Process a single message with the given handler
|
|
502
|
-
* @param message The message to process
|
|
503
|
-
* @param handler Function to process the message
|
|
504
|
-
*/
|
|
505
|
-
private processMessage;
|
|
506
|
-
/**
|
|
507
|
-
* Consume the next available message from the queue
|
|
508
|
-
* @param handler Function to process the message
|
|
509
|
-
* @returns Promise that resolves when the message is processed
|
|
510
|
-
* @throws All the same errors as the underlying client methods
|
|
511
|
-
*/
|
|
512
|
-
consume(handler: MessageHandler<T>): Promise<void>;
|
|
513
|
-
/**
|
|
514
|
-
* Consume a specific message by its ID with full payload
|
|
515
|
-
* @param handler Function to process the message
|
|
516
|
-
* @param options Consume options with messageId specified
|
|
517
|
-
* @returns Promise that resolves when the message is processed
|
|
518
|
-
* @throws All the same errors as the underlying client methods
|
|
519
|
-
*/
|
|
520
|
-
consume(handler: MessageHandler<T>, options: {
|
|
521
|
-
messageId: string;
|
|
522
|
-
skipPayload?: false | undefined;
|
|
523
|
-
}): Promise<void>;
|
|
524
|
-
/**
|
|
525
|
-
* Consume a specific message by its ID without downloading the payload (metadata only)
|
|
526
|
-
* @param handler Function to process the message metadata (payload will be void)
|
|
527
|
-
* @param options Consume options with messageId and skipPayload specified
|
|
528
|
-
* @returns Promise that resolves when the message is processed
|
|
529
|
-
* @throws All the same errors as the underlying client methods
|
|
530
|
-
*/
|
|
531
|
-
consume(handler: MessageHandler<void>, options: {
|
|
532
|
-
messageId: string;
|
|
533
|
-
skipPayload: true;
|
|
534
|
-
}): Promise<void>;
|
|
535
|
-
/**
|
|
536
|
-
* Get the consumer group name
|
|
537
|
-
*/
|
|
538
|
-
get name(): string;
|
|
539
|
-
/**
|
|
540
|
-
* Get the topic name this consumer group is subscribed to
|
|
541
|
-
*/
|
|
542
|
-
get topic(): string;
|
|
543
|
-
}
|
|
544
252
|
|
|
545
|
-
/**
|
|
546
|
-
* A Topic represents a named channel for publishing messages in a pub/sub pattern
|
|
547
|
-
*/
|
|
548
|
-
declare class Topic<T = unknown> {
|
|
549
|
-
private client;
|
|
550
|
-
private topicName;
|
|
551
|
-
private transport;
|
|
552
|
-
/**
|
|
553
|
-
* Create a new Topic instance
|
|
554
|
-
* @param client QueueClient instance to use for API calls
|
|
555
|
-
* @param topicName Name of the topic to work with
|
|
556
|
-
* @param transport Optional serializer/deserializer for the payload (defaults to JSON)
|
|
557
|
-
*/
|
|
558
|
-
constructor(client: QueueClient, topicName: string, transport?: Transport<T>);
|
|
559
|
-
/**
|
|
560
|
-
* Publish a message to the topic
|
|
561
|
-
* @param payload The data to publish
|
|
562
|
-
* @param options Optional publish options
|
|
563
|
-
* @returns An object containing the message ID
|
|
564
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
565
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
566
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
567
|
-
* @throws {InternalServerError} When server encounters an error
|
|
568
|
-
*/
|
|
569
|
-
publish(payload: T, options?: PublishOptions): Promise<{
|
|
570
|
-
messageId: string;
|
|
571
|
-
}>;
|
|
572
|
-
/**
|
|
573
|
-
* Create a consumer group for this topic
|
|
574
|
-
* @param consumerGroupName Name of the consumer group
|
|
575
|
-
* @param options Optional configuration for the consumer group
|
|
576
|
-
* @returns A ConsumerGroup instance
|
|
577
|
-
*/
|
|
578
|
-
consumerGroup<U = T>(consumerGroupName: string, options?: ConsumerGroupOptions<U>): ConsumerGroup<U>;
|
|
579
|
-
/**
|
|
580
|
-
* Get the topic name
|
|
581
|
-
*/
|
|
582
|
-
get name(): string;
|
|
583
|
-
/**
|
|
584
|
-
* Get the transport used by this topic
|
|
585
|
-
*/
|
|
586
|
-
get serializer(): Transport<T>;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Create a new Topic instance using the default QueueClient
|
|
591
|
-
* For custom client configuration, use `new Topic(customClient, topicName, transport)` directly
|
|
592
|
-
* @param topicName Name of the topic
|
|
593
|
-
* @param transport Optional serializer/deserializer for the payload (defaults to JSON)
|
|
594
|
-
* @returns A Topic instance
|
|
595
|
-
*/
|
|
596
|
-
declare function createTopic<T = unknown>(topicName: string, transport?: Transport<T>): Topic<T>;
|
|
597
253
|
/**
|
|
598
254
|
* Options for the send function
|
|
599
255
|
*/
|
|
@@ -661,10 +317,6 @@ declare function receive<T = unknown>(topicName: string, consumerGroup: string,
|
|
|
661
317
|
skipPayload: true;
|
|
662
318
|
}): Promise<void>;
|
|
663
319
|
|
|
664
|
-
/**
|
|
665
|
-
* Queue Callback utilities for handling incoming webhook payloads from Vercel triggers
|
|
666
|
-
*/
|
|
667
|
-
|
|
668
320
|
/**
|
|
669
321
|
* Configuration object with handlers for different topics and consumer groups
|
|
670
322
|
*/
|
|
@@ -673,42 +325,6 @@ type CallbackHandlers = {
|
|
|
673
325
|
[consumerGroup: string]: MessageHandler;
|
|
674
326
|
};
|
|
675
327
|
};
|
|
676
|
-
/**
|
|
677
|
-
* Parsed callback request information
|
|
678
|
-
*/
|
|
679
|
-
type ParsedCallbackRequest = {
|
|
680
|
-
queueName: string;
|
|
681
|
-
consumerGroup: string;
|
|
682
|
-
messageId: string;
|
|
683
|
-
};
|
|
684
|
-
/**
|
|
685
|
-
* Parse and validate callback request headers
|
|
686
|
-
*
|
|
687
|
-
* Extracts queue information from Vercel-provided headers and validates
|
|
688
|
-
* that all required headers are present.
|
|
689
|
-
*
|
|
690
|
-
* @param request The incoming webhook request
|
|
691
|
-
* @returns Parsed queue information
|
|
692
|
-
* @throws Error if required headers are missing
|
|
693
|
-
*
|
|
694
|
-
* @example
|
|
695
|
-
* ```typescript
|
|
696
|
-
* // In Next.js API route
|
|
697
|
-
* export async function POST(request: Request) {
|
|
698
|
-
* try {
|
|
699
|
-
* const { queueName, consumerGroup, messageId } = parseCallbackRequest(request);
|
|
700
|
-
*
|
|
701
|
-
* // Use the parsed information...
|
|
702
|
-
* await myWorkflow.handleWebhook(queueName, consumerGroup, messageId);
|
|
703
|
-
*
|
|
704
|
-
* return Response.json({ status: "success" });
|
|
705
|
-
* } catch (error) {
|
|
706
|
-
* return Response.json({ error: error.message }, { status: 400 });
|
|
707
|
-
* }
|
|
708
|
-
* }
|
|
709
|
-
* ```
|
|
710
|
-
*/
|
|
711
|
-
declare function parseCallbackRequest(request: Request): ParsedCallbackRequest;
|
|
712
328
|
/**
|
|
713
329
|
* Simplified queue callback handler for Next.js route handlers
|
|
714
330
|
*
|
|
@@ -743,4 +359,4 @@ declare function parseCallbackRequest(request: Request): ParsedCallbackRequest;
|
|
|
743
359
|
*/
|
|
744
360
|
declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
|
|
745
361
|
|
|
746
|
-
export { BadRequestError, BufferTransport,
|
|
362
|
+
export { BadRequestError, BufferTransport, ForbiddenError, InternalServerError, InvalidLimitError, JsonTransport, type Message, MessageCorruptedError, type MessageHandler, type MessageHandlerResult, MessageLockedError, type MessageMetadata, MessageNotAvailableError, MessageNotFoundError, type MessageTimeoutResult, type PublishOptions, QueueEmptyError, type ReceiveOptions, type SendMessageOptions, type SendMessageResponse, type SendOptions, StreamTransport, type Transport, UnauthorizedError, handleCallback, receive, send };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,6 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
BadRequestError: () => BadRequestError,
|
|
24
24
|
BufferTransport: () => BufferTransport,
|
|
25
|
-
ConsumerGroup: () => ConsumerGroup,
|
|
26
25
|
ForbiddenError: () => ForbiddenError,
|
|
27
26
|
InternalServerError: () => InternalServerError,
|
|
28
27
|
InvalidLimitError: () => InvalidLimitError,
|
|
@@ -31,19 +30,87 @@ __export(index_exports, {
|
|
|
31
30
|
MessageLockedError: () => MessageLockedError,
|
|
32
31
|
MessageNotAvailableError: () => MessageNotAvailableError,
|
|
33
32
|
MessageNotFoundError: () => MessageNotFoundError,
|
|
34
|
-
QueueClient: () => QueueClient,
|
|
35
33
|
QueueEmptyError: () => QueueEmptyError,
|
|
36
34
|
StreamTransport: () => StreamTransport,
|
|
37
|
-
Topic: () => Topic,
|
|
38
35
|
UnauthorizedError: () => UnauthorizedError,
|
|
39
|
-
createTopic: () => createTopic,
|
|
40
36
|
handleCallback: () => handleCallback,
|
|
41
|
-
parseCallbackRequest: () => parseCallbackRequest,
|
|
42
37
|
receive: () => receive,
|
|
43
38
|
send: () => send
|
|
44
39
|
});
|
|
45
40
|
module.exports = __toCommonJS(index_exports);
|
|
46
41
|
|
|
42
|
+
// src/transports.ts
|
|
43
|
+
var JsonTransport = class {
|
|
44
|
+
contentType = "application/json";
|
|
45
|
+
serialize(value) {
|
|
46
|
+
return Buffer.from(JSON.stringify(value), "utf8");
|
|
47
|
+
}
|
|
48
|
+
async deserialize(stream) {
|
|
49
|
+
const reader = stream.getReader();
|
|
50
|
+
let totalLength = 0;
|
|
51
|
+
const chunks = [];
|
|
52
|
+
try {
|
|
53
|
+
while (true) {
|
|
54
|
+
const { done, value } = await reader.read();
|
|
55
|
+
if (done) break;
|
|
56
|
+
chunks.push(value);
|
|
57
|
+
totalLength += value.length;
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
reader.releaseLock();
|
|
61
|
+
}
|
|
62
|
+
const buffer = Buffer.concat(chunks, totalLength);
|
|
63
|
+
return JSON.parse(buffer.toString("utf8"));
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var BufferTransport = class {
|
|
67
|
+
contentType = "application/octet-stream";
|
|
68
|
+
serialize(value) {
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
async deserialize(stream) {
|
|
72
|
+
const reader = stream.getReader();
|
|
73
|
+
const chunks = [];
|
|
74
|
+
try {
|
|
75
|
+
while (true) {
|
|
76
|
+
const { done, value } = await reader.read();
|
|
77
|
+
if (done) break;
|
|
78
|
+
chunks.push(value);
|
|
79
|
+
}
|
|
80
|
+
} finally {
|
|
81
|
+
reader.releaseLock();
|
|
82
|
+
}
|
|
83
|
+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
84
|
+
const buffer = new Uint8Array(totalLength);
|
|
85
|
+
let offset = 0;
|
|
86
|
+
for (const chunk of chunks) {
|
|
87
|
+
buffer.set(chunk, offset);
|
|
88
|
+
offset += chunk.length;
|
|
89
|
+
}
|
|
90
|
+
return Buffer.from(buffer);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var StreamTransport = class {
|
|
94
|
+
contentType = "application/octet-stream";
|
|
95
|
+
serialize(value) {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
async deserialize(stream) {
|
|
99
|
+
return stream;
|
|
100
|
+
}
|
|
101
|
+
async finalize(payload) {
|
|
102
|
+
const reader = payload.getReader();
|
|
103
|
+
try {
|
|
104
|
+
while (true) {
|
|
105
|
+
const { done } = await reader.read();
|
|
106
|
+
if (done) break;
|
|
107
|
+
}
|
|
108
|
+
} finally {
|
|
109
|
+
reader.releaseLock();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
47
114
|
// src/client.ts
|
|
48
115
|
var import_mixpart = require("mixpart");
|
|
49
116
|
|
|
@@ -153,7 +220,7 @@ var QueueClient = class _QueueClient {
|
|
|
153
220
|
baseUrl;
|
|
154
221
|
token;
|
|
155
222
|
/**
|
|
156
|
-
* Internal default instance for use by
|
|
223
|
+
* Internal default instance for use by convenience functions
|
|
157
224
|
* @internal
|
|
158
225
|
*/
|
|
159
226
|
static _defaultInstance = null;
|
|
@@ -589,78 +656,6 @@ var QueueClient = class _QueueClient {
|
|
|
589
656
|
}
|
|
590
657
|
};
|
|
591
658
|
|
|
592
|
-
// src/transports.ts
|
|
593
|
-
var JsonTransport = class {
|
|
594
|
-
contentType = "application/json";
|
|
595
|
-
serialize(value) {
|
|
596
|
-
return Buffer.from(JSON.stringify(value), "utf8");
|
|
597
|
-
}
|
|
598
|
-
async deserialize(stream) {
|
|
599
|
-
const reader = stream.getReader();
|
|
600
|
-
let totalLength = 0;
|
|
601
|
-
const chunks = [];
|
|
602
|
-
try {
|
|
603
|
-
while (true) {
|
|
604
|
-
const { done, value } = await reader.read();
|
|
605
|
-
if (done) break;
|
|
606
|
-
chunks.push(value);
|
|
607
|
-
totalLength += value.length;
|
|
608
|
-
}
|
|
609
|
-
} finally {
|
|
610
|
-
reader.releaseLock();
|
|
611
|
-
}
|
|
612
|
-
const buffer = Buffer.concat(chunks, totalLength);
|
|
613
|
-
return JSON.parse(buffer.toString("utf8"));
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
var BufferTransport = class {
|
|
617
|
-
contentType = "application/octet-stream";
|
|
618
|
-
serialize(value) {
|
|
619
|
-
return value;
|
|
620
|
-
}
|
|
621
|
-
async deserialize(stream) {
|
|
622
|
-
const reader = stream.getReader();
|
|
623
|
-
const chunks = [];
|
|
624
|
-
try {
|
|
625
|
-
while (true) {
|
|
626
|
-
const { done, value } = await reader.read();
|
|
627
|
-
if (done) break;
|
|
628
|
-
chunks.push(value);
|
|
629
|
-
}
|
|
630
|
-
} finally {
|
|
631
|
-
reader.releaseLock();
|
|
632
|
-
}
|
|
633
|
-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
634
|
-
const buffer = new Uint8Array(totalLength);
|
|
635
|
-
let offset = 0;
|
|
636
|
-
for (const chunk of chunks) {
|
|
637
|
-
buffer.set(chunk, offset);
|
|
638
|
-
offset += chunk.length;
|
|
639
|
-
}
|
|
640
|
-
return Buffer.from(buffer);
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
var StreamTransport = class {
|
|
644
|
-
contentType = "application/octet-stream";
|
|
645
|
-
serialize(value) {
|
|
646
|
-
return value;
|
|
647
|
-
}
|
|
648
|
-
async deserialize(stream) {
|
|
649
|
-
return stream;
|
|
650
|
-
}
|
|
651
|
-
async finalize(payload) {
|
|
652
|
-
const reader = payload.getReader();
|
|
653
|
-
try {
|
|
654
|
-
while (true) {
|
|
655
|
-
const { done } = await reader.read();
|
|
656
|
-
if (done) break;
|
|
657
|
-
}
|
|
658
|
-
} finally {
|
|
659
|
-
reader.releaseLock();
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
};
|
|
663
|
-
|
|
664
659
|
// src/consumer-group.ts
|
|
665
660
|
var ConsumerGroup = class {
|
|
666
661
|
client;
|
|
@@ -931,10 +926,6 @@ var Topic = class {
|
|
|
931
926
|
};
|
|
932
927
|
|
|
933
928
|
// src/factory.ts
|
|
934
|
-
function createTopic(topicName, transport) {
|
|
935
|
-
const client = QueueClient._getDefaultInstance();
|
|
936
|
-
return new Topic(client, topicName, transport);
|
|
937
|
-
}
|
|
938
929
|
async function send(topicName, payload, options) {
|
|
939
930
|
const transport = options?.transport || new JsonTransport();
|
|
940
931
|
const client = QueueClient._getDefaultInstance();
|
|
@@ -951,7 +942,8 @@ async function send(topicName, payload, options) {
|
|
|
951
942
|
}
|
|
952
943
|
async function receive(topicName, consumerGroup, handler, options) {
|
|
953
944
|
const transport = options?.transport || new JsonTransport();
|
|
954
|
-
const
|
|
945
|
+
const client = QueueClient._getDefaultInstance();
|
|
946
|
+
const topic = new Topic(client, topicName, transport);
|
|
955
947
|
const { messageId, skipPayload, ...consumerGroupOptions } = options || {};
|
|
956
948
|
const consumer = topic.consumerGroup(consumerGroup, consumerGroupOptions);
|
|
957
949
|
if (messageId) {
|
|
@@ -1035,7 +1027,6 @@ function handleCallback(handlers) {
|
|
|
1035
1027
|
0 && (module.exports = {
|
|
1036
1028
|
BadRequestError,
|
|
1037
1029
|
BufferTransport,
|
|
1038
|
-
ConsumerGroup,
|
|
1039
1030
|
ForbiddenError,
|
|
1040
1031
|
InternalServerError,
|
|
1041
1032
|
InvalidLimitError,
|
|
@@ -1044,14 +1035,10 @@ function handleCallback(handlers) {
|
|
|
1044
1035
|
MessageLockedError,
|
|
1045
1036
|
MessageNotAvailableError,
|
|
1046
1037
|
MessageNotFoundError,
|
|
1047
|
-
QueueClient,
|
|
1048
1038
|
QueueEmptyError,
|
|
1049
1039
|
StreamTransport,
|
|
1050
|
-
Topic,
|
|
1051
1040
|
UnauthorizedError,
|
|
1052
|
-
createTopic,
|
|
1053
1041
|
handleCallback,
|
|
1054
|
-
parseCallbackRequest,
|
|
1055
1042
|
receive,
|
|
1056
1043
|
send
|
|
1057
1044
|
});
|