@amqp-contract/contract 0.4.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 +19 -7
- package/dist/index.cjs +43 -3
- package/dist/index.d.cts +344 -45
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +344 -45
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +43 -3
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +258 -62
- package/package.json +2 -2
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;;AAEI,KAtGQ,SAAA,GAAY,gBAsGpB;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;AAQA;AA6CA;AAiBA;AAqBA;AASA;;AAEI,KAtGQ,SAAA,GAAY,gBAsGpB;;;AAUJ;AAoBA;AA4EA;;AAC+B,KAzMnB,sBAAA,GAyMmB;EACK;;;EAYxB,IAAA,EAAA,MAAA;EAAQ;AAsBpB;;;EAegB,OAAA,CAAA,EAAA,OAAA;EAA2B;;;AAiC3C;EAKe,UAAA,CAAA,EAAA,OAAA;EAKD;;;;;EA0BF,QAAA,CAAA,EAAA,OAAA;EAmBA;;;;EAMI,SAAA,CAAA,EA5TF,MA4TE,CAAA,MAAA,EAAA,OAAA,CAAA;CAA2B;;;AA+B3C;;;;;;AAyCA;;;;;AAiB4B,KArYhB,wBAAA,GAA2B,sBAqYX,GAAA;EAAf,IAAA,EAAA,QAAA;CAOiB;;;;;AAyB9B;;;;;;AAkBA;;;AACiC,KAvarB,wBAAA,GAA2B,sBAuaN,GAAA;EAAgC,IAAA,EAAA,QAAA;CAAS;;;;ACld1E;;;;;AA4BA;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,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
|
@@ -103,6 +103,25 @@ type TopicExchangeDefinition = BaseExchangeDefinition & {
|
|
|
103
103
|
* Represents any type of AMQP exchange: fanout, direct, or topic.
|
|
104
104
|
*/
|
|
105
105
|
type ExchangeDefinition = FanoutExchangeDefinition | DirectExchangeDefinition | TopicExchangeDefinition;
|
|
106
|
+
/**
|
|
107
|
+
* Configuration for dead letter exchange (DLX) on a queue.
|
|
108
|
+
*
|
|
109
|
+
* When a message in a queue is rejected, expires, or exceeds the queue length limit,
|
|
110
|
+
* it can be automatically forwarded to a dead letter exchange for further processing
|
|
111
|
+
* or storage.
|
|
112
|
+
*/
|
|
113
|
+
type DeadLetterConfig = {
|
|
114
|
+
/**
|
|
115
|
+
* The exchange to send dead-lettered messages to.
|
|
116
|
+
* This exchange must be declared in the contract.
|
|
117
|
+
*/
|
|
118
|
+
exchange: ExchangeDefinition;
|
|
119
|
+
/**
|
|
120
|
+
* Optional routing key to use when forwarding messages to the dead letter exchange.
|
|
121
|
+
* If not specified, the original message routing key is used.
|
|
122
|
+
*/
|
|
123
|
+
routingKey?: string;
|
|
124
|
+
};
|
|
106
125
|
/**
|
|
107
126
|
* Definition of an AMQP queue.
|
|
108
127
|
*
|
|
@@ -130,6 +149,25 @@ type QueueDefinition = {
|
|
|
130
149
|
* @default false
|
|
131
150
|
*/
|
|
132
151
|
autoDelete?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Dead letter configuration for handling failed or rejected messages.
|
|
154
|
+
*
|
|
155
|
+
* When configured, messages that are rejected, expire, or exceed queue limits
|
|
156
|
+
* will be automatically forwarded to the specified dead letter exchange.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
161
|
+
* const queue = defineQueue('order-processing', {
|
|
162
|
+
* durable: true,
|
|
163
|
+
* deadLetter: {
|
|
164
|
+
* exchange: dlx,
|
|
165
|
+
* routingKey: 'order.failed'
|
|
166
|
+
* }
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
deadLetter?: DeadLetterConfig;
|
|
133
171
|
/**
|
|
134
172
|
* Additional AMQP arguments for advanced configuration.
|
|
135
173
|
*
|
|
@@ -138,15 +176,16 @@ type QueueDefinition = {
|
|
|
138
176
|
* - `x-expires`: Queue expiration time in milliseconds
|
|
139
177
|
* - `x-max-length`: Maximum number of messages in the queue
|
|
140
178
|
* - `x-max-length-bytes`: Maximum size of the queue in bytes
|
|
141
|
-
* - `x-dead-letter-exchange`: Exchange for dead-lettered messages
|
|
142
|
-
* - `x-dead-letter-routing-key`: Routing key for dead-lettered messages
|
|
143
179
|
* - `x-max-priority`: Maximum priority level for priority queues
|
|
144
180
|
*
|
|
181
|
+
* Note: When using the `deadLetter` property, the `x-dead-letter-exchange` and
|
|
182
|
+
* `x-dead-letter-routing-key` arguments are automatically set and should not be
|
|
183
|
+
* specified in this arguments object.
|
|
184
|
+
*
|
|
145
185
|
* @example
|
|
146
186
|
* ```typescript
|
|
147
187
|
* {
|
|
148
188
|
* 'x-message-ttl': 86400000, // 24 hours
|
|
149
|
-
* 'x-dead-letter-exchange': 'dlx',
|
|
150
189
|
* 'x-max-priority': 10
|
|
151
190
|
* }
|
|
152
191
|
* ```
|
|
@@ -494,16 +533,27 @@ declare function defineExchange(name: string, type: "topic", options?: Omit<Base
|
|
|
494
533
|
* @param options.durable - If true, the queue survives broker restarts (default: false)
|
|
495
534
|
* @param options.exclusive - If true, the queue can only be used by the declaring connection (default: false)
|
|
496
535
|
* @param options.autoDelete - If true, the queue is deleted when the last consumer unsubscribes (default: false)
|
|
497
|
-
* @param options.
|
|
536
|
+
* @param options.deadLetter - Dead letter configuration for handling failed messages
|
|
537
|
+
* @param options.arguments - Additional AMQP arguments (e.g., x-message-ttl, x-max-priority)
|
|
498
538
|
* @returns A queue definition
|
|
499
539
|
*
|
|
500
540
|
* @example
|
|
501
541
|
* ```typescript
|
|
502
|
-
*
|
|
542
|
+
* // Basic queue
|
|
543
|
+
* const orderQueue = defineQueue('order-processing', {
|
|
503
544
|
* durable: true,
|
|
545
|
+
* });
|
|
546
|
+
*
|
|
547
|
+
* // Queue with dead letter exchange
|
|
548
|
+
* const dlx = defineExchange('orders-dlx', 'topic', { durable: true });
|
|
549
|
+
* const orderQueueWithDLX = defineQueue('order-processing', {
|
|
550
|
+
* durable: true,
|
|
551
|
+
* deadLetter: {
|
|
552
|
+
* exchange: dlx,
|
|
553
|
+
* routingKey: 'order.failed'
|
|
554
|
+
* },
|
|
504
555
|
* arguments: {
|
|
505
556
|
* 'x-message-ttl': 86400000, // 24 hours
|
|
506
|
-
* 'x-dead-letter-exchange': 'orders-dlx'
|
|
507
557
|
* }
|
|
508
558
|
* });
|
|
509
559
|
* ```
|
|
@@ -856,7 +906,7 @@ declare function defineConsumer<TMessage extends MessageDefinition>(queue: Queue
|
|
|
856
906
|
*/
|
|
857
907
|
declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
|
|
858
908
|
/**
|
|
859
|
-
* Publisher-first builder result.
|
|
909
|
+
* Publisher-first builder result for fanout and direct exchanges.
|
|
860
910
|
*
|
|
861
911
|
* This type represents a publisher and provides a method to create
|
|
862
912
|
* a consumer that uses the same message schema with a binding to the exchange.
|
|
@@ -883,6 +933,108 @@ type PublisherFirstResult<TMessage extends MessageDefinition, TPublisher extends
|
|
|
883
933
|
binding: QueueBindingDefinition;
|
|
884
934
|
};
|
|
885
935
|
};
|
|
936
|
+
/**
|
|
937
|
+
* Type-safe routing key that validates basic format.
|
|
938
|
+
*
|
|
939
|
+
* Validates that a routing key follows basic AMQP routing key rules:
|
|
940
|
+
* - Must not contain wildcards (* or #)
|
|
941
|
+
* - Must not be empty
|
|
942
|
+
* - Should contain alphanumeric characters, dots, hyphens, and underscores
|
|
943
|
+
*
|
|
944
|
+
* Note: Full character-by-character validation is not performed to avoid TypeScript
|
|
945
|
+
* recursion depth limits. Runtime validation is still recommended.
|
|
946
|
+
*
|
|
947
|
+
* @public
|
|
948
|
+
* @template S - The routing key string to validate
|
|
949
|
+
* @example
|
|
950
|
+
* ```typescript
|
|
951
|
+
* type Valid = RoutingKey<"order.created">; // "order.created"
|
|
952
|
+
* type Invalid = RoutingKey<"order.*">; // never (contains wildcard)
|
|
953
|
+
* type Invalid2 = RoutingKey<"">; // never (empty string)
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
type RoutingKey<S extends string> = S extends "" ? never : S extends `${string}*${string}` | `${string}#${string}` ? never : S;
|
|
957
|
+
/**
|
|
958
|
+
* Type-safe binding pattern that validates basic format and wildcards.
|
|
959
|
+
*
|
|
960
|
+
* Validates that a binding pattern follows basic AMQP binding pattern rules:
|
|
961
|
+
* - Can contain wildcards (* for one word, # for zero or more words)
|
|
962
|
+
* - Must not be empty
|
|
963
|
+
* - Should contain alphanumeric characters, dots, hyphens, underscores, and wildcards
|
|
964
|
+
*
|
|
965
|
+
* Note: Full character-by-character validation is not performed to avoid TypeScript
|
|
966
|
+
* recursion depth limits. Runtime validation is still recommended.
|
|
967
|
+
*
|
|
968
|
+
* @public
|
|
969
|
+
* @template S - The binding pattern string to validate
|
|
970
|
+
* @example
|
|
971
|
+
* ```typescript
|
|
972
|
+
* type ValidPattern = BindingPattern<"order.*">; // "order.*"
|
|
973
|
+
* type ValidHash = BindingPattern<"order.#">; // "order.#"
|
|
974
|
+
* type ValidConcrete = BindingPattern<"order.created">; // "order.created"
|
|
975
|
+
* type Invalid = BindingPattern<"">; // never (empty string)
|
|
976
|
+
* ```
|
|
977
|
+
*/
|
|
978
|
+
type BindingPattern<S extends string> = S extends "" ? never : S;
|
|
979
|
+
/**
|
|
980
|
+
* Helper type for pattern matching with # in the middle
|
|
981
|
+
* Handles backtracking to match # with zero or more segments
|
|
982
|
+
* @internal
|
|
983
|
+
*/
|
|
984
|
+
type MatchesAfterHash<Key extends string, PatternRest$1 extends string> = MatchesPattern<Key, PatternRest$1> extends true ? true : Key extends `${string}.${infer KeyRest}` ? MatchesAfterHash<KeyRest, PatternRest$1> : false;
|
|
985
|
+
/**
|
|
986
|
+
* Check if a routing key matches a binding pattern
|
|
987
|
+
* Implements AMQP topic exchange pattern matching:
|
|
988
|
+
* - * matches exactly one word
|
|
989
|
+
* - # matches zero or more words
|
|
990
|
+
* @internal
|
|
991
|
+
*/
|
|
992
|
+
type MatchesPattern<Key extends string, Pattern extends string> = Pattern extends `${infer PatternPart}.${infer PatternRest}` ? PatternPart extends "#" ? MatchesAfterHash<Key, PatternRest> : Key extends `${infer KeyPart}.${infer KeyRest}` ? PatternPart extends "*" ? MatchesPattern<KeyRest, PatternRest> : PatternPart extends KeyPart ? MatchesPattern<KeyRest, PatternRest> : false : false : Pattern extends "#" ? true : Pattern extends "*" ? Key extends `${string}.${string}` ? false : true : Pattern extends Key ? true : false;
|
|
993
|
+
/**
|
|
994
|
+
* Validate that a routing key matches a binding pattern.
|
|
995
|
+
*
|
|
996
|
+
* This is a utility type provided for users who want compile-time validation
|
|
997
|
+
* that a routing key matches a specific pattern. It's not enforced internally
|
|
998
|
+
* in the API to avoid TypeScript recursion depth issues with complex routing keys.
|
|
999
|
+
*
|
|
1000
|
+
* Returns the routing key if it's valid and matches the pattern, `never` otherwise.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* type ValidKey = MatchingRoutingKey<"order.*", "order.created">; // "order.created"
|
|
1005
|
+
* type InvalidKey = MatchingRoutingKey<"order.*", "user.created">; // never
|
|
1006
|
+
* ```
|
|
1007
|
+
*
|
|
1008
|
+
* @template Pattern - The binding pattern (can contain * and # wildcards)
|
|
1009
|
+
* @template Key - The routing key to validate
|
|
1010
|
+
*/
|
|
1011
|
+
type MatchingRoutingKey<Pattern extends string, Key extends string> = RoutingKey<Key> extends never ? never : BindingPattern<Pattern> extends never ? never : MatchesPattern<Key, Pattern> extends true ? Key : never;
|
|
1012
|
+
/**
|
|
1013
|
+
* Publisher-first builder result for topic exchanges.
|
|
1014
|
+
*
|
|
1015
|
+
* This type represents a publisher with a concrete routing key and provides a method
|
|
1016
|
+
* to create consumers that can use routing key patterns matching the publisher's key.
|
|
1017
|
+
*
|
|
1018
|
+
* @template TMessage - The message definition
|
|
1019
|
+
* @template TPublisher - The publisher definition
|
|
1020
|
+
* @template TRoutingKey - The literal routing key type from the publisher (for documentation purposes)
|
|
1021
|
+
*/
|
|
1022
|
+
type PublisherFirstResultWithRoutingKey<TMessage extends MessageDefinition, TPublisher extends PublisherDefinition<TMessage>, TRoutingKey extends string> = {
|
|
1023
|
+
/** The publisher definition */
|
|
1024
|
+
publisher: TPublisher;
|
|
1025
|
+
/**
|
|
1026
|
+
* Create a consumer that receives messages from this publisher.
|
|
1027
|
+
* For topic exchanges, the routing key pattern can be specified for the binding.
|
|
1028
|
+
*
|
|
1029
|
+
* @param queue - The queue that will consume the messages
|
|
1030
|
+
* @param routingKey - Optional routing key pattern for the binding (defaults to publisher's routing key)
|
|
1031
|
+
* @returns An object with the consumer definition and binding
|
|
1032
|
+
*/
|
|
1033
|
+
createConsumer: <TConsumerRoutingKey extends string = TRoutingKey>(queue: QueueDefinition, routingKey?: BindingPattern<TConsumerRoutingKey>) => {
|
|
1034
|
+
consumer: ConsumerDefinition<TMessage>;
|
|
1035
|
+
binding: QueueBindingDefinition;
|
|
1036
|
+
};
|
|
1037
|
+
};
|
|
886
1038
|
/**
|
|
887
1039
|
* Define a publisher-first relationship for event-oriented messaging.
|
|
888
1040
|
*
|
|
@@ -911,15 +1063,15 @@ type PublisherFirstResult<TMessage extends MessageDefinition, TPublisher extends
|
|
|
911
1063
|
* );
|
|
912
1064
|
*
|
|
913
1065
|
* // Create publisher-first relationship (event pattern)
|
|
914
|
-
* const
|
|
1066
|
+
* const { publisher: publishLog, createConsumer: createLogConsumer } = definePublisherFirst(logsExchange, logMessage);
|
|
915
1067
|
*
|
|
916
1068
|
* // Multiple queues can consume the same event
|
|
917
1069
|
* const logsQueue1 = defineQueue('logs-queue-1', { durable: true });
|
|
918
1070
|
* const logsQueue2 = defineQueue('logs-queue-2', { durable: true });
|
|
919
1071
|
*
|
|
920
1072
|
* // Use in contract
|
|
921
|
-
* const { consumer: consumer1, binding: binding1 } =
|
|
922
|
-
* const { consumer: consumer2, binding: binding2 } =
|
|
1073
|
+
* const { consumer: consumer1, binding: binding1 } = createLogConsumer(logsQueue1);
|
|
1074
|
+
* const { consumer: consumer2, binding: binding2 } = createLogConsumer(logsQueue2);
|
|
923
1075
|
*
|
|
924
1076
|
* const contract = defineContract({
|
|
925
1077
|
* exchanges: { logs: logsExchange },
|
|
@@ -928,7 +1080,7 @@ type PublisherFirstResult<TMessage extends MessageDefinition, TPublisher extends
|
|
|
928
1080
|
* logBinding1: binding1,
|
|
929
1081
|
* logBinding2: binding2,
|
|
930
1082
|
* },
|
|
931
|
-
* publishers: { publishLog
|
|
1083
|
+
* publishers: { publishLog },
|
|
932
1084
|
* consumers: {
|
|
933
1085
|
* consumeLog1: consumer1,
|
|
934
1086
|
* consumeLog2: consumer2,
|
|
@@ -942,7 +1094,7 @@ declare function definePublisherFirst<TMessage extends MessageDefinition>(exchan
|
|
|
942
1094
|
exchange: FanoutExchangeDefinition;
|
|
943
1095
|
}>>;
|
|
944
1096
|
/**
|
|
945
|
-
* Define a publisher-first relationship for event-oriented messaging.
|
|
1097
|
+
* Define a publisher-first relationship for event-oriented messaging with direct exchange.
|
|
946
1098
|
*
|
|
947
1099
|
* This builder enforces consistency by:
|
|
948
1100
|
* 1. Ensuring the publisher and consumer use the same message schema
|
|
@@ -951,7 +1103,7 @@ declare function definePublisherFirst<TMessage extends MessageDefinition>(exchan
|
|
|
951
1103
|
* Use this pattern for events where publishers don't need to know about queues.
|
|
952
1104
|
* Multiple consumers can be created for different queues, all using the same message schema.
|
|
953
1105
|
*
|
|
954
|
-
* @param exchange - The exchange to publish to (direct
|
|
1106
|
+
* @param exchange - The exchange to publish to (direct type)
|
|
955
1107
|
* @param message - The message definition (schema and metadata)
|
|
956
1108
|
* @param options - Binding configuration (routingKey is required)
|
|
957
1109
|
* @param options.routingKey - The routing key for message routing
|
|
@@ -961,6 +1113,61 @@ declare function definePublisherFirst<TMessage extends MessageDefinition>(exchan
|
|
|
961
1113
|
* ```typescript
|
|
962
1114
|
* import { z } from 'zod';
|
|
963
1115
|
*
|
|
1116
|
+
* const tasksExchange = defineExchange('tasks', 'direct', { durable: true });
|
|
1117
|
+
* const taskMessage = defineMessage(
|
|
1118
|
+
* z.object({
|
|
1119
|
+
* taskId: z.string(),
|
|
1120
|
+
* payload: z.record(z.unknown()),
|
|
1121
|
+
* })
|
|
1122
|
+
* );
|
|
1123
|
+
*
|
|
1124
|
+
* // Create publisher-first relationship with routing key
|
|
1125
|
+
* const { publisher: executeTaskPublisher, createConsumer: createTaskConsumer } = definePublisherFirst(
|
|
1126
|
+
* tasksExchange,
|
|
1127
|
+
* taskMessage,
|
|
1128
|
+
* { routingKey: 'task.execute' }
|
|
1129
|
+
* );
|
|
1130
|
+
*
|
|
1131
|
+
* // Use in contract - routing key is consistent across publisher and bindings
|
|
1132
|
+
* const taskQueue = defineQueue('task-queue', { durable: true });
|
|
1133
|
+
* const { consumer, binding } = createTaskConsumer(taskQueue);
|
|
1134
|
+
*
|
|
1135
|
+
* const contract = defineContract({
|
|
1136
|
+
* exchanges: { tasks: tasksExchange },
|
|
1137
|
+
* queues: { taskQueue },
|
|
1138
|
+
* bindings: { taskBinding: binding },
|
|
1139
|
+
* publishers: { executeTask: executeTaskPublisher },
|
|
1140
|
+
* consumers: { processTask: consumer },
|
|
1141
|
+
* });
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
declare function definePublisherFirst<TMessage extends MessageDefinition, TRoutingKey extends string>(exchange: DirectExchangeDefinition, message: TMessage, options: {
|
|
1145
|
+
routingKey: RoutingKey<TRoutingKey>;
|
|
1146
|
+
arguments?: Record<string, unknown>;
|
|
1147
|
+
}): PublisherFirstResult<TMessage, Extract<PublisherDefinition<TMessage>, {
|
|
1148
|
+
exchange: DirectExchangeDefinition | TopicExchangeDefinition;
|
|
1149
|
+
}>>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Define a publisher-first relationship for event-oriented messaging with topic exchange.
|
|
1152
|
+
*
|
|
1153
|
+
* This builder enforces consistency by:
|
|
1154
|
+
* 1. Ensuring the publisher and consumer use the same message schema
|
|
1155
|
+
* 2. The publisher uses a concrete routing key (e.g., 'order.created')
|
|
1156
|
+
* 3. Consumers can optionally specify routing key patterns (e.g., 'order.*') or use the default
|
|
1157
|
+
*
|
|
1158
|
+
* Use this pattern for events where publishers emit with specific routing keys,
|
|
1159
|
+
* and consumers can subscribe with patterns. This is less common than the consumer-first pattern.
|
|
1160
|
+
*
|
|
1161
|
+
* @param exchange - The exchange to publish to (topic type)
|
|
1162
|
+
* @param message - The message definition (schema and metadata)
|
|
1163
|
+
* @param options - Binding configuration (routingKey is required)
|
|
1164
|
+
* @param options.routingKey - The concrete routing key for the publisher
|
|
1165
|
+
* @returns A publisher-first result with publisher and consumer factory that accepts optional routing key patterns
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* ```typescript
|
|
1169
|
+
* import { z } from 'zod';
|
|
1170
|
+
*
|
|
964
1171
|
* const ordersExchange = defineExchange('orders', 'topic', { durable: true });
|
|
965
1172
|
* const orderMessage = defineMessage(
|
|
966
1173
|
* z.object({
|
|
@@ -969,43 +1176,46 @@ declare function definePublisherFirst<TMessage extends MessageDefinition>(exchan
|
|
|
969
1176
|
* })
|
|
970
1177
|
* );
|
|
971
1178
|
*
|
|
972
|
-
* // Create publisher-first relationship with routing key
|
|
973
|
-
* const
|
|
1179
|
+
* // Create publisher-first relationship with concrete routing key
|
|
1180
|
+
* const { publisher: orderCreatedPublisher, createConsumer: createOrderCreatedConsumer } = definePublisherFirst(
|
|
974
1181
|
* ordersExchange,
|
|
975
1182
|
* orderMessage,
|
|
976
|
-
* { routingKey: 'order.created' }
|
|
1183
|
+
* { routingKey: 'order.created' } // Concrete key
|
|
977
1184
|
* );
|
|
978
1185
|
*
|
|
979
|
-
* //
|
|
1186
|
+
* // Consumers can use patterns or specific keys
|
|
980
1187
|
* const orderQueue = defineQueue('order-processing', { durable: true });
|
|
981
|
-
* const
|
|
1188
|
+
* const allOrdersQueue = defineQueue('all-orders', { durable: true });
|
|
982
1189
|
*
|
|
983
|
-
* // Use in contract
|
|
984
|
-
* const { consumer: processConsumer, binding: processBinding } =
|
|
985
|
-
*
|
|
1190
|
+
* // Use in contract
|
|
1191
|
+
* const { consumer: processConsumer, binding: processBinding } =
|
|
1192
|
+
* createOrderCreatedConsumer(orderQueue); // Uses 'order.created'
|
|
1193
|
+
* const { consumer: allOrdersConsumer, binding: allOrdersBinding } =
|
|
1194
|
+
* createOrderCreatedConsumer(allOrdersQueue, 'order.*'); // Uses pattern
|
|
986
1195
|
*
|
|
987
1196
|
* const contract = defineContract({
|
|
988
1197
|
* exchanges: { orders: ordersExchange },
|
|
989
|
-
* queues: { orderQueue,
|
|
1198
|
+
* queues: { orderQueue, allOrdersQueue },
|
|
990
1199
|
* bindings: {
|
|
991
1200
|
* orderBinding: processBinding,
|
|
992
|
-
*
|
|
1201
|
+
* allOrdersBinding,
|
|
993
1202
|
* },
|
|
994
|
-
* publishers: { orderCreated:
|
|
1203
|
+
* publishers: { orderCreated: orderCreatedPublisher },
|
|
995
1204
|
* consumers: {
|
|
996
1205
|
* processOrder: processConsumer,
|
|
997
|
-
*
|
|
1206
|
+
* trackAllOrders: allOrdersConsumer,
|
|
998
1207
|
* },
|
|
999
1208
|
* });
|
|
1000
1209
|
* ```
|
|
1001
1210
|
*/
|
|
1002
|
-
declare function definePublisherFirst<TMessage extends MessageDefinition>(exchange:
|
|
1003
|
-
|
|
1004
|
-
|
|
1211
|
+
declare function definePublisherFirst<TMessage extends MessageDefinition, TRoutingKey extends string>(exchange: TopicExchangeDefinition, message: TMessage, options: {
|
|
1212
|
+
routingKey: RoutingKey<TRoutingKey>;
|
|
1213
|
+
arguments?: Record<string, unknown>;
|
|
1214
|
+
}): PublisherFirstResultWithRoutingKey<TMessage, Extract<PublisherDefinition<TMessage>, {
|
|
1005
1215
|
exchange: DirectExchangeDefinition | TopicExchangeDefinition;
|
|
1006
|
-
}
|
|
1216
|
+
}>, TRoutingKey>;
|
|
1007
1217
|
/**
|
|
1008
|
-
* Consumer-first builder result.
|
|
1218
|
+
* Consumer-first builder result for fanout and direct exchanges.
|
|
1009
1219
|
*
|
|
1010
1220
|
* This type represents a consumer with its binding and provides a method to create
|
|
1011
1221
|
* a publisher that uses the same message schema and routing key.
|
|
@@ -1025,7 +1235,37 @@ type ConsumerFirstResult<TMessage extends MessageDefinition, TConsumer extends C
|
|
|
1025
1235
|
*
|
|
1026
1236
|
* @returns A publisher definition with the same message type and routing key
|
|
1027
1237
|
*/
|
|
1028
|
-
createPublisher: () => PublisherDefinition<TMessage
|
|
1238
|
+
createPublisher: () => TBinding["exchange"] extends FanoutExchangeDefinition ? Extract<PublisherDefinition<TMessage>, {
|
|
1239
|
+
exchange: FanoutExchangeDefinition;
|
|
1240
|
+
}> : Extract<PublisherDefinition<TMessage>, {
|
|
1241
|
+
exchange: DirectExchangeDefinition | TopicExchangeDefinition;
|
|
1242
|
+
}>;
|
|
1243
|
+
};
|
|
1244
|
+
/**
|
|
1245
|
+
* Consumer-first builder result for topic exchanges.
|
|
1246
|
+
*
|
|
1247
|
+
* This type represents a consumer with its binding (which may use a pattern) and provides
|
|
1248
|
+
* a method to create a publisher with a concrete routing key that matches the pattern.
|
|
1249
|
+
*
|
|
1250
|
+
* @template TMessage - The message definition
|
|
1251
|
+
* @template TConsumer - The consumer definition
|
|
1252
|
+
* @template TBinding - The queue binding definition
|
|
1253
|
+
*/
|
|
1254
|
+
type ConsumerFirstResultWithRoutingKey<TMessage extends MessageDefinition, TConsumer extends ConsumerDefinition<TMessage>, TBinding extends QueueBindingDefinition> = {
|
|
1255
|
+
/** The consumer definition */
|
|
1256
|
+
consumer: TConsumer;
|
|
1257
|
+
/** The binding definition connecting the exchange to the queue */
|
|
1258
|
+
binding: TBinding;
|
|
1259
|
+
/**
|
|
1260
|
+
* Create a publisher that sends messages to this consumer.
|
|
1261
|
+
* For topic exchanges, the routing key can be specified to match the binding pattern.
|
|
1262
|
+
*
|
|
1263
|
+
* @param routingKey - The concrete routing key that matches the binding pattern
|
|
1264
|
+
* @returns A publisher definition with the specified routing key
|
|
1265
|
+
*/
|
|
1266
|
+
createPublisher: <TPublisherRoutingKey extends string>(routingKey: RoutingKey<TPublisherRoutingKey>) => Extract<PublisherDefinition<TMessage>, {
|
|
1267
|
+
exchange: DirectExchangeDefinition | TopicExchangeDefinition;
|
|
1268
|
+
}>;
|
|
1029
1269
|
};
|
|
1030
1270
|
/**
|
|
1031
1271
|
* Define a consumer-first relationship between a consumer and publisher.
|
|
@@ -1058,7 +1298,7 @@ type ConsumerFirstResult<TMessage extends MessageDefinition, TConsumer extends C
|
|
|
1058
1298
|
* );
|
|
1059
1299
|
*
|
|
1060
1300
|
* // Create consumer-first relationship
|
|
1061
|
-
* const
|
|
1301
|
+
* const { consumer: processNotificationConsumer, binding: notificationBinding, createPublisher: createNotificationPublisher } = defineConsumerFirst(
|
|
1062
1302
|
* notificationsQueue,
|
|
1063
1303
|
* notificationsExchange,
|
|
1064
1304
|
* notificationMessage
|
|
@@ -1068,9 +1308,9 @@ type ConsumerFirstResult<TMessage extends MessageDefinition, TConsumer extends C
|
|
|
1068
1308
|
* const contract = defineContract({
|
|
1069
1309
|
* exchanges: { notifications: notificationsExchange },
|
|
1070
1310
|
* queues: { notificationsQueue },
|
|
1071
|
-
* bindings: { notificationBinding
|
|
1072
|
-
* publishers: { sendNotification:
|
|
1073
|
-
* consumers: { processNotification:
|
|
1311
|
+
* bindings: { notificationBinding },
|
|
1312
|
+
* publishers: { sendNotification: createNotificationPublisher() },
|
|
1313
|
+
* consumers: { processNotification: processNotificationConsumer },
|
|
1074
1314
|
* });
|
|
1075
1315
|
* ```
|
|
1076
1316
|
*/
|
|
@@ -1091,7 +1331,7 @@ declare function defineConsumerFirst<TMessage extends MessageDefinition>(queue:
|
|
|
1091
1331
|
* send messages with the correct type and routing key.
|
|
1092
1332
|
*
|
|
1093
1333
|
* @param queue - The queue to consume from
|
|
1094
|
-
* @param exchange - The exchange that routes to the queue (direct
|
|
1334
|
+
* @param exchange - The exchange that routes to the queue (direct type)
|
|
1095
1335
|
* @param message - The message definition (schema and metadata)
|
|
1096
1336
|
* @param options - Binding configuration (routingKey is required)
|
|
1097
1337
|
* @param options.routingKey - The routing key for message routing
|
|
@@ -1111,7 +1351,7 @@ declare function defineConsumerFirst<TMessage extends MessageDefinition>(queue:
|
|
|
1111
1351
|
* );
|
|
1112
1352
|
*
|
|
1113
1353
|
* // Create consumer-first relationship with routing key
|
|
1114
|
-
* const
|
|
1354
|
+
* const { consumer: processTaskConsumer, binding: taskBinding, createPublisher: createTaskPublisher } = defineConsumerFirst(
|
|
1115
1355
|
* taskQueue,
|
|
1116
1356
|
* tasksExchange,
|
|
1117
1357
|
* taskMessage,
|
|
@@ -1122,17 +1362,76 @@ declare function defineConsumerFirst<TMessage extends MessageDefinition>(queue:
|
|
|
1122
1362
|
* const contract = defineContract({
|
|
1123
1363
|
* exchanges: { tasks: tasksExchange },
|
|
1124
1364
|
* queues: { taskQueue },
|
|
1125
|
-
* bindings: { taskBinding
|
|
1126
|
-
* publishers: { executeTask:
|
|
1127
|
-
* consumers: { processTask:
|
|
1365
|
+
* bindings: { taskBinding },
|
|
1366
|
+
* publishers: { executeTask: createTaskPublisher() },
|
|
1367
|
+
* consumers: { processTask: processTaskConsumer },
|
|
1128
1368
|
* });
|
|
1129
1369
|
* ```
|
|
1130
1370
|
*/
|
|
1131
|
-
declare function defineConsumerFirst<TMessage extends MessageDefinition>(queue: QueueDefinition, exchange: DirectExchangeDefinition
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1371
|
+
declare function defineConsumerFirst<TMessage extends MessageDefinition, TRoutingKey extends string>(queue: QueueDefinition, exchange: DirectExchangeDefinition, message: TMessage, options: {
|
|
1372
|
+
routingKey: RoutingKey<TRoutingKey>;
|
|
1373
|
+
arguments?: Record<string, unknown>;
|
|
1374
|
+
}): ConsumerFirstResult<TMessage, ConsumerDefinition<TMessage>, Extract<QueueBindingDefinition, {
|
|
1375
|
+
exchange: DirectExchangeDefinition;
|
|
1376
|
+
}>>;
|
|
1377
|
+
/**
|
|
1378
|
+
* Define a consumer-first relationship between a consumer and publisher with topic exchange.
|
|
1379
|
+
*
|
|
1380
|
+
* This builder enforces consistency by:
|
|
1381
|
+
* 1. Ensuring the consumer and publisher use the same message schema
|
|
1382
|
+
* 2. The binding uses a routing key pattern (e.g., 'order.*')
|
|
1383
|
+
* 3. The publisher factory accepts a concrete routing key that matches the pattern (e.g., 'order.created')
|
|
1384
|
+
*
|
|
1385
|
+
* Use this when you want to start with a consumer that uses a routing key pattern,
|
|
1386
|
+
* and allow publishers to specify concrete routing keys that match that pattern.
|
|
1387
|
+
*
|
|
1388
|
+
* @param queue - The queue to consume from
|
|
1389
|
+
* @param exchange - The exchange that routes to the queue (topic type)
|
|
1390
|
+
* @param message - The message definition (schema and metadata)
|
|
1391
|
+
* @param options - Binding configuration (routingKey is required)
|
|
1392
|
+
* @param options.routingKey - The routing key pattern for the binding (can use wildcards)
|
|
1393
|
+
* @returns A consumer-first result with consumer, binding, and publisher factory that accepts a routing key
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* ```typescript
|
|
1397
|
+
* import { z } from 'zod';
|
|
1398
|
+
*
|
|
1399
|
+
* const orderQueue = defineQueue('order-processing', { durable: true });
|
|
1400
|
+
* const ordersExchange = defineExchange('orders', 'topic', { durable: true });
|
|
1401
|
+
* const orderMessage = defineMessage(
|
|
1402
|
+
* z.object({
|
|
1403
|
+
* orderId: z.string(),
|
|
1404
|
+
* amount: z.number(),
|
|
1405
|
+
* })
|
|
1406
|
+
* );
|
|
1407
|
+
*
|
|
1408
|
+
* // Create consumer-first relationship with pattern
|
|
1409
|
+
* const { consumer: processOrderConsumer, binding: orderBinding, createPublisher: createOrderPublisher } = defineConsumerFirst(
|
|
1410
|
+
* orderQueue,
|
|
1411
|
+
* ordersExchange,
|
|
1412
|
+
* orderMessage,
|
|
1413
|
+
* { routingKey: 'order.*' } // Pattern in binding
|
|
1414
|
+
* );
|
|
1415
|
+
*
|
|
1416
|
+
* // Use in contract - publisher can specify concrete routing key
|
|
1417
|
+
* const contract = defineContract({
|
|
1418
|
+
* exchanges: { orders: ordersExchange },
|
|
1419
|
+
* queues: { orderQueue },
|
|
1420
|
+
* bindings: { orderBinding },
|
|
1421
|
+
* publishers: {
|
|
1422
|
+
* orderCreated: createOrderPublisher('order.created'), // Concrete key
|
|
1423
|
+
* orderUpdated: createOrderPublisher('order.updated'), // Concrete key
|
|
1424
|
+
* },
|
|
1425
|
+
* consumers: { processOrder: processOrderConsumer },
|
|
1426
|
+
* });
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
declare function defineConsumerFirst<TMessage extends MessageDefinition, TRoutingKey extends string>(queue: QueueDefinition, exchange: TopicExchangeDefinition, message: TMessage, options: {
|
|
1430
|
+
routingKey: BindingPattern<TRoutingKey>;
|
|
1431
|
+
arguments?: Record<string, unknown>;
|
|
1432
|
+
}): ConsumerFirstResultWithRoutingKey<TMessage, ConsumerDefinition<TMessage>, Extract<QueueBindingDefinition, {
|
|
1433
|
+
exchange: TopicExchangeDefinition;
|
|
1135
1434
|
}>>;
|
|
1136
1435
|
//#endregion
|
|
1137
|
-
export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type ConsumerDefinition, type ConsumerFirstResult, type ContractDefinition, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MessageDefinition, type PublisherDefinition, type PublisherFirstResult, type QueueBindingDefinition, type QueueDefinition, type TopicExchangeDefinition, defineConsumer, defineConsumerFirst, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, definePublisherFirst, defineQueue, defineQueueBinding };
|
|
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 };
|
|
1138
1437
|
//# sourceMappingURL=index.d.mts.map
|