@amqp-contract/contract 0.6.0 → 0.8.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 +23 -19
- package/dist/index.cjs +21 -2
- package/dist/index.d.cts +46 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +46 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +21 -2
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +122 -73
- package/package.json +14 -7
package/README.md
CHANGED
|
@@ -23,33 +23,37 @@ pnpm add @amqp-contract/contract
|
|
|
23
23
|
For robust contract definitions with guaranteed consistency, use `definePublisherFirst` (for events) or `defineConsumerFirst` (for commands):
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
-
import {
|
|
27
|
-
|
|
26
|
+
import {
|
|
27
|
+
definePublisherFirst,
|
|
28
|
+
defineContract,
|
|
29
|
+
defineExchange,
|
|
30
|
+
defineQueue,
|
|
31
|
+
defineMessage,
|
|
32
|
+
} from "@amqp-contract/contract";
|
|
33
|
+
import { z } from "zod";
|
|
28
34
|
|
|
29
35
|
// Event-oriented pattern: publisher doesn't need to know about queues
|
|
30
|
-
const ordersExchange = defineExchange(
|
|
31
|
-
const orderMessage = defineMessage(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const {
|
|
37
|
-
publisher: orderCreatedPublisher,
|
|
38
|
-
createConsumer: createOrderCreatedConsumer,
|
|
39
|
-
} = definePublisherFirst(
|
|
40
|
-
ordersExchange,
|
|
41
|
-
orderMessage,
|
|
42
|
-
{ routingKey: 'order.created' }
|
|
36
|
+
const ordersExchange = defineExchange("orders", "topic", { durable: true });
|
|
37
|
+
const orderMessage = defineMessage(
|
|
38
|
+
z.object({
|
|
39
|
+
orderId: z.string(),
|
|
40
|
+
amount: z.number(),
|
|
41
|
+
}),
|
|
43
42
|
);
|
|
44
43
|
|
|
44
|
+
const { publisher: orderCreatedPublisher, createConsumer: createOrderCreatedConsumer } =
|
|
45
|
+
definePublisherFirst(ordersExchange, orderMessage, { routingKey: "order.created" });
|
|
46
|
+
|
|
45
47
|
// Multiple queues can consume the same event
|
|
46
|
-
const orderQueue = defineQueue(
|
|
48
|
+
const orderQueue = defineQueue("order-processing", { durable: true });
|
|
47
49
|
const { consumer, binding } = createOrderCreatedConsumer(orderQueue);
|
|
48
50
|
|
|
49
51
|
// For topic exchanges, consumers can override with their own pattern
|
|
50
|
-
const analyticsQueue = defineQueue(
|
|
51
|
-
const { consumer: analyticsConsumer, binding: analyticsBinding } =
|
|
52
|
-
|
|
52
|
+
const analyticsQueue = defineQueue("analytics", { durable: true });
|
|
53
|
+
const { consumer: analyticsConsumer, binding: analyticsBinding } = createOrderCreatedConsumer(
|
|
54
|
+
analyticsQueue,
|
|
55
|
+
"order.*",
|
|
56
|
+
); // Subscribe to all order events
|
|
53
57
|
|
|
54
58
|
const contract = defineContract({
|
|
55
59
|
exchanges: { orders: ordersExchange },
|
package/dist/index.cjs
CHANGED
|
@@ -32,7 +32,8 @@ function defineExchange(name, type, options) {
|
|
|
32
32
|
* @param options.exclusive - If true, the queue can only be used by the declaring connection (default: false)
|
|
33
33
|
* @param options.autoDelete - If true, the queue is deleted when the last consumer unsubscribes (default: false)
|
|
34
34
|
* @param options.deadLetter - Dead letter configuration for handling failed messages
|
|
35
|
-
* @param options.
|
|
35
|
+
* @param options.maxPriority - Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument.
|
|
36
|
+
* @param options.arguments - Additional AMQP arguments (e.g., x-message-ttl)
|
|
36
37
|
* @returns A queue definition
|
|
37
38
|
*
|
|
38
39
|
* @example
|
|
@@ -42,6 +43,12 @@ function defineExchange(name, type, options) {
|
|
|
42
43
|
* durable: true,
|
|
43
44
|
* });
|
|
44
45
|
*
|
|
46
|
+
* // Priority queue with max priority of 10
|
|
47
|
+
* const taskQueue = defineQueue('urgent-tasks', {
|
|
48
|
+
* durable: true,
|
|
49
|
+
* maxPriority: 10,
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
45
52
|
* // Queue with dead letter exchange
|
|
46
53
|
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
47
54
|
* const orderQueueWithDLX = defineQueue('order-processing', {
|
|
@@ -57,9 +64,21 @@ function defineExchange(name, type, options) {
|
|
|
57
64
|
* ```
|
|
58
65
|
*/
|
|
59
66
|
function defineQueue(name, options) {
|
|
67
|
+
const { maxPriority, ...queueOptions } = options ?? {};
|
|
68
|
+
if (maxPriority !== void 0) {
|
|
69
|
+
if (maxPriority < 1 || maxPriority > 255) throw new Error(`Invalid maxPriority: ${maxPriority}. Must be between 1 and 255. Recommended range: 1-10.`);
|
|
70
|
+
return {
|
|
71
|
+
name,
|
|
72
|
+
...queueOptions,
|
|
73
|
+
arguments: {
|
|
74
|
+
...queueOptions.arguments,
|
|
75
|
+
"x-max-priority": maxPriority
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
60
79
|
return {
|
|
61
80
|
name,
|
|
62
|
-
...
|
|
81
|
+
...queueOptions
|
|
63
82
|
};
|
|
64
83
|
}
|
|
65
84
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -12,6 +12,35 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
12
12
|
* @see https://github.com/standard-schema/standard-schema
|
|
13
13
|
*/
|
|
14
14
|
type AnySchema = StandardSchemaV1;
|
|
15
|
+
/**
|
|
16
|
+
* Supported compression algorithms for message payloads.
|
|
17
|
+
*
|
|
18
|
+
* - `gzip`: GZIP compression (standard, widely supported, good compression ratio)
|
|
19
|
+
* - `deflate`: DEFLATE compression (faster than gzip, slightly less compression)
|
|
20
|
+
*
|
|
21
|
+
* Compression is configured at runtime via PublishOptions when calling
|
|
22
|
+
* AmqpClient.publish, not at publisher definition time.
|
|
23
|
+
*
|
|
24
|
+
* When compression is enabled, the message payload is compressed before publishing
|
|
25
|
+
* and automatically decompressed when consuming. The `content-encoding` AMQP
|
|
26
|
+
* message property is set to indicate the compression algorithm used.
|
|
27
|
+
*
|
|
28
|
+
* To disable compression, simply omit the `compression` option (it's optional).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Define a publisher without compression configuration
|
|
33
|
+
* const orderCreatedPublisher = definePublisher(exchange, message, {
|
|
34
|
+
* routingKey: "order.created",
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Later, choose whether to compress at publish time
|
|
38
|
+
* await client.publish("orderCreated", payload, {
|
|
39
|
+
* compression: "gzip",
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type CompressionAlgorithm = "gzip" | "deflate";
|
|
15
44
|
/**
|
|
16
45
|
* Base definition of an AMQP exchange.
|
|
17
46
|
*
|
|
@@ -306,6 +335,9 @@ type BindingDefinition = QueueBindingDefinition | ExchangeBindingDefinition;
|
|
|
306
335
|
* A publisher sends messages to an exchange with automatic schema validation.
|
|
307
336
|
* The message payload is validated against the schema before being sent to RabbitMQ.
|
|
308
337
|
*
|
|
338
|
+
* Compression can be optionally applied at publish time by specifying a compression
|
|
339
|
+
* algorithm when calling the publish method.
|
|
340
|
+
*
|
|
309
341
|
* @template TMessage - The message definition with payload schema
|
|
310
342
|
*
|
|
311
343
|
* @example
|
|
@@ -339,6 +371,8 @@ type PublisherDefinition<TMessage extends MessageDefinition = MessageDefinition>
|
|
|
339
371
|
*
|
|
340
372
|
* A consumer receives and processes messages from a queue with automatic schema validation.
|
|
341
373
|
* The message payload is validated against the schema before being passed to your handler.
|
|
374
|
+
* If the message is compressed (indicated by the content-encoding header), it will be
|
|
375
|
+
* automatically decompressed before validation.
|
|
342
376
|
*
|
|
343
377
|
* @template TMessage - The message definition with payload schema
|
|
344
378
|
*
|
|
@@ -534,7 +568,8 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
534
568
|
* @param options.exclusive - If true, the queue can only be used by the declaring connection (default: false)
|
|
535
569
|
* @param options.autoDelete - If true, the queue is deleted when the last consumer unsubscribes (default: false)
|
|
536
570
|
* @param options.deadLetter - Dead letter configuration for handling failed messages
|
|
537
|
-
* @param options.
|
|
571
|
+
* @param options.maxPriority - Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument.
|
|
572
|
+
* @param options.arguments - Additional AMQP arguments (e.g., x-message-ttl)
|
|
538
573
|
* @returns A queue definition
|
|
539
574
|
*
|
|
540
575
|
* @example
|
|
@@ -544,6 +579,12 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
544
579
|
* durable: true,
|
|
545
580
|
* });
|
|
546
581
|
*
|
|
582
|
+
* // Priority queue with max priority of 10
|
|
583
|
+
* const taskQueue = defineQueue('urgent-tasks', {
|
|
584
|
+
* durable: true,
|
|
585
|
+
* maxPriority: 10,
|
|
586
|
+
* });
|
|
587
|
+
*
|
|
547
588
|
* // Queue with dead letter exchange
|
|
548
589
|
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
549
590
|
* const orderQueueWithDLX = defineQueue('order-processing', {
|
|
@@ -558,7 +599,9 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
558
599
|
* });
|
|
559
600
|
* ```
|
|
560
601
|
*/
|
|
561
|
-
declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">
|
|
602
|
+
declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name"> & {
|
|
603
|
+
maxPriority?: number;
|
|
604
|
+
}): QueueDefinition;
|
|
562
605
|
/**
|
|
563
606
|
* Define a message definition with payload and optional headers/metadata.
|
|
564
607
|
*
|
|
@@ -1433,5 +1476,5 @@ declare function defineConsumerFirst<TMessage extends MessageDefinition, TRoutin
|
|
|
1433
1476
|
exchange: TopicExchangeDefinition;
|
|
1434
1477
|
}>>;
|
|
1435
1478
|
//#endregion
|
|
1436
|
-
export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type BindingPattern, type ConsumerDefinition, type ConsumerFirstResult, type ConsumerFirstResultWithRoutingKey, type ContractDefinition, type DeadLetterConfig, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MatchingRoutingKey, type MessageDefinition, type PublisherDefinition, type PublisherFirstResult, type PublisherFirstResultWithRoutingKey, type QueueBindingDefinition, type QueueDefinition, type RoutingKey, type TopicExchangeDefinition, defineConsumer, defineConsumerFirst, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, definePublisherFirst, defineQueue, defineQueueBinding };
|
|
1479
|
+
export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type BindingPattern, type CompressionAlgorithm, type ConsumerDefinition, type ConsumerFirstResult, type ConsumerFirstResultWithRoutingKey, type ContractDefinition, type DeadLetterConfig, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MatchingRoutingKey, type MessageDefinition, type PublisherDefinition, type PublisherFirstResult, type PublisherFirstResultWithRoutingKey, type QueueBindingDefinition, type QueueDefinition, type RoutingKey, type TopicExchangeDefinition, defineConsumer, defineConsumerFirst, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, definePublisherFirst, defineQueue, defineQueueBinding };
|
|
1437
1480
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAQA;AA6CA;AAiBA;AAqBA;AASA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AA8BA;AAQA;AA6CA;AAiBA;AAqBA;AASA;AACI,KAnIQ,SAAA,GAAY,gBAmIpB;;;;AAWJ;AAoBA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mCACD;cAEK,WAAW;cACX;IAEb,qBACD,UACA,QACE,oBAAoB;YACR,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiE3B,sCACG,yDAGP,kCACD;cAEK,WAAW;cACX;IAEb,mCACD,UACA,QACE,oBAAoB;YACR,2BAA2B;IAEzC;;;;;;;;;;;KAgEU,qCACO,qCACC,mBAAmB,4BACpB;;YAGP;;WAED;;;;;;;yBAOc,6BAA6B,2BAChD,QAAQ,oBAAoB;cAAuB;OACnD,QACE,oBAAoB;cACR,2BAA2B;;;;;;;;;;;;;KAcnC,mDACO,qCACC,mBAAmB,4BACpB;;YAGP;;WAED;;;;;;;;qEASK,WAAW,0BACpB,QACH,oBAAoB;cACR,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmD3B,qCAAqC,0BAC5C,2BACG,mCACD,oBACC,KACR,QAAQ;YAAoC;oDAG7C,oBACD,UACA,mBAAmB,WACnB,QAAQ;YAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoD9B,qCAAqC,sDAC5C,2BACG,mCACD;cAEK,WAAW;cACX;IAEb,oBACD,UACA,mBAAmB,WACnB,QAAQ;YAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuD9B,qCAAqC,sDAC5C,2BACG,kCACD;cAEK,eAAe;cACf;IAEb,kCACD,UACA,mBAAmB,WACnB,QAAQ;YAAoC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,35 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
|
12
12
|
* @see https://github.com/standard-schema/standard-schema
|
|
13
13
|
*/
|
|
14
14
|
type AnySchema = StandardSchemaV1;
|
|
15
|
+
/**
|
|
16
|
+
* Supported compression algorithms for message payloads.
|
|
17
|
+
*
|
|
18
|
+
* - `gzip`: GZIP compression (standard, widely supported, good compression ratio)
|
|
19
|
+
* - `deflate`: DEFLATE compression (faster than gzip, slightly less compression)
|
|
20
|
+
*
|
|
21
|
+
* Compression is configured at runtime via PublishOptions when calling
|
|
22
|
+
* AmqpClient.publish, not at publisher definition time.
|
|
23
|
+
*
|
|
24
|
+
* When compression is enabled, the message payload is compressed before publishing
|
|
25
|
+
* and automatically decompressed when consuming. The `content-encoding` AMQP
|
|
26
|
+
* message property is set to indicate the compression algorithm used.
|
|
27
|
+
*
|
|
28
|
+
* To disable compression, simply omit the `compression` option (it's optional).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Define a publisher without compression configuration
|
|
33
|
+
* const orderCreatedPublisher = definePublisher(exchange, message, {
|
|
34
|
+
* routingKey: "order.created",
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Later, choose whether to compress at publish time
|
|
38
|
+
* await client.publish("orderCreated", payload, {
|
|
39
|
+
* compression: "gzip",
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type CompressionAlgorithm = "gzip" | "deflate";
|
|
15
44
|
/**
|
|
16
45
|
* Base definition of an AMQP exchange.
|
|
17
46
|
*
|
|
@@ -306,6 +335,9 @@ type BindingDefinition = QueueBindingDefinition | ExchangeBindingDefinition;
|
|
|
306
335
|
* A publisher sends messages to an exchange with automatic schema validation.
|
|
307
336
|
* The message payload is validated against the schema before being sent to RabbitMQ.
|
|
308
337
|
*
|
|
338
|
+
* Compression can be optionally applied at publish time by specifying a compression
|
|
339
|
+
* algorithm when calling the publish method.
|
|
340
|
+
*
|
|
309
341
|
* @template TMessage - The message definition with payload schema
|
|
310
342
|
*
|
|
311
343
|
* @example
|
|
@@ -339,6 +371,8 @@ type PublisherDefinition<TMessage extends MessageDefinition = MessageDefinition>
|
|
|
339
371
|
*
|
|
340
372
|
* A consumer receives and processes messages from a queue with automatic schema validation.
|
|
341
373
|
* The message payload is validated against the schema before being passed to your handler.
|
|
374
|
+
* If the message is compressed (indicated by the content-encoding header), it will be
|
|
375
|
+
* automatically decompressed before validation.
|
|
342
376
|
*
|
|
343
377
|
* @template TMessage - The message definition with payload schema
|
|
344
378
|
*
|
|
@@ -534,7 +568,8 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
534
568
|
* @param options.exclusive - If true, the queue can only be used by the declaring connection (default: false)
|
|
535
569
|
* @param options.autoDelete - If true, the queue is deleted when the last consumer unsubscribes (default: false)
|
|
536
570
|
* @param options.deadLetter - Dead letter configuration for handling failed messages
|
|
537
|
-
* @param options.
|
|
571
|
+
* @param options.maxPriority - Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument.
|
|
572
|
+
* @param options.arguments - Additional AMQP arguments (e.g., x-message-ttl)
|
|
538
573
|
* @returns A queue definition
|
|
539
574
|
*
|
|
540
575
|
* @example
|
|
@@ -544,6 +579,12 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
544
579
|
* durable: true,
|
|
545
580
|
* });
|
|
546
581
|
*
|
|
582
|
+
* // Priority queue with max priority of 10
|
|
583
|
+
* const taskQueue = defineQueue('urgent-tasks', {
|
|
584
|
+
* durable: true,
|
|
585
|
+
* maxPriority: 10,
|
|
586
|
+
* });
|
|
587
|
+
*
|
|
547
588
|
* // Queue with dead letter exchange
|
|
548
589
|
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
549
590
|
* const orderQueueWithDLX = defineQueue('order-processing', {
|
|
@@ -558,7 +599,9 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
558
599
|
* });
|
|
559
600
|
* ```
|
|
560
601
|
*/
|
|
561
|
-
declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">
|
|
602
|
+
declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name"> & {
|
|
603
|
+
maxPriority?: number;
|
|
604
|
+
}): QueueDefinition;
|
|
562
605
|
/**
|
|
563
606
|
* Define a message definition with payload and optional headers/metadata.
|
|
564
607
|
*
|
|
@@ -1433,5 +1476,5 @@ declare function defineConsumerFirst<TMessage extends MessageDefinition, TRoutin
|
|
|
1433
1476
|
exchange: TopicExchangeDefinition;
|
|
1434
1477
|
}>>;
|
|
1435
1478
|
//#endregion
|
|
1436
|
-
export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type BindingPattern, type ConsumerDefinition, type ConsumerFirstResult, type ConsumerFirstResultWithRoutingKey, type ContractDefinition, type DeadLetterConfig, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MatchingRoutingKey, type MessageDefinition, type PublisherDefinition, type PublisherFirstResult, type PublisherFirstResultWithRoutingKey, type QueueBindingDefinition, type QueueDefinition, type RoutingKey, type TopicExchangeDefinition, defineConsumer, defineConsumerFirst, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, definePublisherFirst, defineQueue, defineQueueBinding };
|
|
1479
|
+
export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type BindingPattern, type CompressionAlgorithm, type ConsumerDefinition, type ConsumerFirstResult, type ConsumerFirstResultWithRoutingKey, type ContractDefinition, type DeadLetterConfig, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MatchingRoutingKey, type MessageDefinition, type PublisherDefinition, type PublisherFirstResult, type PublisherFirstResultWithRoutingKey, type QueueBindingDefinition, type QueueDefinition, type RoutingKey, type TopicExchangeDefinition, defineConsumer, defineConsumerFirst, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, definePublisherFirst, defineQueue, defineQueueBinding };
|
|
1437
1480
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAQA;AA6CA;AAiBA;AAqBA;AASA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AA8BA;AAQA;AA6CA;AAiBA;AAqBA;AASA;AACI,KAnIQ,SAAA,GAAY,gBAmIpB;;;;AAWJ;AAoBA;AA4EA;;;;;;;;AAoCA;;;;;;;AAgDA;;;;;;;AAoCA;AAsBY,KA9VA,oBAAA,GA8VmB,MAAA,GAAA,SAAA;;;;;;;AAeS,KArW5B,sBAAA,GAqW4B;EAwB5B;;;EAEH,IAAA,EAAA,MAAA;EAGE;;AAoCX;;EAKc,OAAA,CAAA,EAAA,OAAA;EAMY;;;;EAaI,UAAA,CAAA,EAAA,OAAA;EAAf;;;;AAyBf;EAAkD,QAAA,CAAA,EAAA,OAAA;EAChD;;;;EAiBU,SAAA,CAAA,EA5cE,MA4cF,CAAA,MAAkB,EAAA,OAAA,CAAA;CAAmB;;;;;;;;ACpfjD;;;;;AA4BA;AAGiB,KDyBL,wBAAA,GAA2B,sBCzBtB,GAAA;EAAL,IAAA,EAAA,QAAA;CACT;;AAyBH;;;;;AA0EA;;;;;AAkEA;;AAEoC,KD9HxB,wBAAA,GAA2B,sBC8HH,GAAA;EAAjB,IAAA,EAAA,QAAA;CAER;;;;;;AAiCX;;;;;;;;;;;AA2CA;AACS,KDxLG,uBAAA,GAA0B,sBCwL7B,GAAA;EACG,IAAA,EAAA,OAAA;CAA2B;;;;;;AASrC,KDzLU,kBAAA,GACR,wBCwLF,GDvLE,wBCuLF,GDtLE,uBCsLF;;;;;AA8DF;;;AAIY,KD/OA,gBAAA,GC+OA;EAAqC;;;;EAGD,QAAA,ED7OpC,kBC6OoC;EAA7C;;AA0BH;;EAEU,UAAA,CAAA,EAAA,MAAA;CAA2B;;;;;;;AAUzB,KDpQA,eAAA,GCoQA;EAA2B;;;EAqEvB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UACA,mBAAmB,WACnB,QAAQ;YAAoC"}
|
package/dist/index.mjs
CHANGED
|
@@ -31,7 +31,8 @@ function defineExchange(name, type, options) {
|
|
|
31
31
|
* @param options.exclusive - If true, the queue can only be used by the declaring connection (default: false)
|
|
32
32
|
* @param options.autoDelete - If true, the queue is deleted when the last consumer unsubscribes (default: false)
|
|
33
33
|
* @param options.deadLetter - Dead letter configuration for handling failed messages
|
|
34
|
-
* @param options.
|
|
34
|
+
* @param options.maxPriority - Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument.
|
|
35
|
+
* @param options.arguments - Additional AMQP arguments (e.g., x-message-ttl)
|
|
35
36
|
* @returns A queue definition
|
|
36
37
|
*
|
|
37
38
|
* @example
|
|
@@ -41,6 +42,12 @@ function defineExchange(name, type, options) {
|
|
|
41
42
|
* durable: true,
|
|
42
43
|
* });
|
|
43
44
|
*
|
|
45
|
+
* // Priority queue with max priority of 10
|
|
46
|
+
* const taskQueue = defineQueue('urgent-tasks', {
|
|
47
|
+
* durable: true,
|
|
48
|
+
* maxPriority: 10,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
44
51
|
* // Queue with dead letter exchange
|
|
45
52
|
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
46
53
|
* const orderQueueWithDLX = defineQueue('order-processing', {
|
|
@@ -56,9 +63,21 @@ function defineExchange(name, type, options) {
|
|
|
56
63
|
* ```
|
|
57
64
|
*/
|
|
58
65
|
function defineQueue(name, options) {
|
|
66
|
+
const { maxPriority, ...queueOptions } = options ?? {};
|
|
67
|
+
if (maxPriority !== void 0) {
|
|
68
|
+
if (maxPriority < 1 || maxPriority > 255) throw new Error(`Invalid maxPriority: ${maxPriority}. Must be between 1 and 255. Recommended range: 1-10.`);
|
|
69
|
+
return {
|
|
70
|
+
name,
|
|
71
|
+
...queueOptions,
|
|
72
|
+
arguments: {
|
|
73
|
+
...queueOptions.arguments,
|
|
74
|
+
"x-max-priority": maxPriority
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
59
78
|
return {
|
|
60
79
|
name,
|
|
61
|
-
...
|
|
80
|
+
...queueOptions
|
|
62
81
|
};
|
|
63
82
|
}
|
|
64
83
|
/**
|