@amqp-contract/contract 0.3.5 → 0.4.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/docs/index.md CHANGED
@@ -12,7 +12,7 @@
12
12
  type AnySchema = StandardSchemaV1;
13
13
  ```
14
14
 
15
- Defined in: [types.ts:12](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L12)
15
+ Defined in: [types.ts:12](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L12)
16
16
 
17
17
  Any schema that conforms to Standard Schema v1.
18
18
 
@@ -32,7 +32,7 @@ https://github.com/standard-schema/standard-schema
32
32
  type BaseExchangeDefinition = object;
33
33
  ```
34
34
 
35
- Defined in: [types.ts:20](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L20)
35
+ Defined in: [types.ts:20](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L20)
36
36
 
37
37
  Base definition of an AMQP exchange.
38
38
 
@@ -43,11 +43,11 @@ type and routing rules. This type contains properties common to all exchange typ
43
43
 
44
44
  | Property | Type | Description | Defined in |
45
45
  | ------ | ------ | ------ | ------ |
46
- | <a id="arguments"></a> `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for advanced configuration. Common arguments include alternate-exchange for handling unroutable messages. | [types.ts:49](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L49) |
47
- | <a id="autodelete"></a> `autoDelete?` | `boolean` | If true, the exchange is deleted when all queues have finished using it. **Default** `false` | [types.ts:36](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L36) |
48
- | <a id="durable"></a> `durable?` | `boolean` | If true, the exchange survives broker restarts. Durable exchanges are persisted to disk. **Default** `false` | [types.ts:30](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L30) |
49
- | <a id="internal"></a> `internal?` | `boolean` | If true, the exchange cannot be directly published to by clients. It can only receive messages from other exchanges via exchange-to-exchange bindings. **Default** `false` | [types.ts:43](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L43) |
50
- | <a id="name"></a> `name` | `string` | The name of the exchange. Must be unique within the RabbitMQ virtual host. | [types.ts:24](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L24) |
46
+ | <a id="arguments"></a> `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for advanced configuration. Common arguments include alternate-exchange for handling unroutable messages. | [types.ts:49](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L49) |
47
+ | <a id="autodelete"></a> `autoDelete?` | `boolean` | If true, the exchange is deleted when all queues have finished using it. **Default** `false` | [types.ts:36](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L36) |
48
+ | <a id="durable"></a> `durable?` | `boolean` | If true, the exchange survives broker restarts. Durable exchanges are persisted to disk. **Default** `false` | [types.ts:30](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L30) |
49
+ | <a id="internal"></a> `internal?` | `boolean` | If true, the exchange cannot be directly published to by clients. It can only receive messages from other exchanges via exchange-to-exchange bindings. **Default** `false` | [types.ts:43](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L43) |
50
+ | <a id="name"></a> `name` | `string` | The name of the exchange. Must be unique within the RabbitMQ virtual host. | [types.ts:24](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L24) |
51
51
 
52
52
  ***
53
53
 
@@ -59,7 +59,7 @@ type BindingDefinition =
59
59
  | ExchangeBindingDefinition;
60
60
  ```
61
61
 
62
- Defined in: [types.ts:298](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L298)
62
+ Defined in: [types.ts:298](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L298)
63
63
 
64
64
  Union type of all binding definitions.
65
65
 
@@ -75,7 +75,7 @@ A binding can be either:
75
75
  type ConsumerDefinition<TMessage> = object;
76
76
  ```
77
77
 
78
- Defined in: [types.ts:354](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L354)
78
+ Defined in: [types.ts:354](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L354)
79
79
 
80
80
  Definition of a message consumer.
81
81
 
@@ -101,8 +101,39 @@ const consumer: ConsumerDefinition = {
101
101
 
102
102
  | Property | Type | Description | Defined in |
103
103
  | ------ | ------ | ------ | ------ |
104
- | <a id="message"></a> `message` | `TMessage` | The message definition including the payload schema | [types.ts:359](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L359) |
105
- | <a id="queue"></a> `queue` | [`QueueDefinition`](#queuedefinition) | The queue to consume messages from | [types.ts:356](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L356) |
104
+ | <a id="message"></a> `message` | `TMessage` | The message definition including the payload schema | [types.ts:359](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L359) |
105
+ | <a id="queue"></a> `queue` | [`QueueDefinition`](#queuedefinition) | The queue to consume messages from | [types.ts:356](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L356) |
106
+
107
+ ***
108
+
109
+ ### ConsumerFirstResult
110
+
111
+ ```ts
112
+ type ConsumerFirstResult<TMessage, TConsumer, TBinding> = object;
113
+ ```
114
+
115
+ Defined in: [builder.ts:936](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L936)
116
+
117
+ Consumer-first builder result.
118
+
119
+ This type represents a consumer with its binding and provides a method to create
120
+ a publisher that uses the same message schema and routing key.
121
+
122
+ #### Type Parameters
123
+
124
+ | Type Parameter | Description |
125
+ | ------ | ------ |
126
+ | `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
127
+ | `TConsumer` *extends* [`ConsumerDefinition`](#consumerdefinition)\<`TMessage`\> | The consumer definition |
128
+ | `TBinding` *extends* [`QueueBindingDefinition`](#queuebindingdefinition) | The queue binding definition |
129
+
130
+ #### Properties
131
+
132
+ | Property | Type | Description | Defined in |
133
+ | ------ | ------ | ------ | ------ |
134
+ | <a id="binding"></a> `binding` | `TBinding` | The binding definition connecting the exchange to the queue | [builder.ts:944](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L944) |
135
+ | <a id="consumer"></a> `consumer` | `TConsumer` | The consumer definition | [builder.ts:942](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L942) |
136
+ | <a id="createpublisher"></a> `createPublisher` | () => [`PublisherDefinition`](#publisherdefinition)\<`TMessage`\> | Create a publisher that sends messages to this consumer. The publisher will automatically use the same message schema and routing key. | [builder.ts:951](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L951) |
106
137
 
107
138
  ***
108
139
 
@@ -112,7 +143,7 @@ const consumer: ConsumerDefinition = {
112
143
  type ContractDefinition = object;
113
144
  ```
114
145
 
115
- Defined in: [types.ts:395](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L395)
146
+ Defined in: [types.ts:395](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L395)
116
147
 
117
148
  Complete AMQP contract definition.
118
149
 
@@ -151,11 +182,11 @@ const contract: ContractDefinition = {
151
182
 
152
183
  | Property | Type | Description | Defined in |
153
184
  | ------ | ------ | ------ | ------ |
154
- | <a id="bindings"></a> `bindings?` | `Record`\<`string`, [`BindingDefinition`](#bindingdefinition)\> | Named binding definitions. Bindings can be queue-to-exchange or exchange-to-exchange. | [types.ts:412](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L412) |
155
- | <a id="consumers"></a> `consumers?` | `Record`\<`string`, [`ConsumerDefinition`](#consumerdefinition)\> | Named consumer definitions. Each key requires a corresponding handler in the TypedAmqpWorker. The handler will be fully typed based on the message schema. | [types.ts:426](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L426) |
156
- | <a id="exchanges"></a> `exchanges?` | `Record`\<`string`, [`ExchangeDefinition`](#exchangedefinition)\> | Named exchange definitions. Each key becomes available as a named resource in the contract. | [types.ts:400](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L400) |
157
- | <a id="publishers"></a> `publishers?` | `Record`\<`string`, [`PublisherDefinition`](#publisherdefinition)\> | Named publisher definitions. Each key becomes a method on the TypedAmqpClient for publishing messages. The method will be fully typed based on the message schema. | [types.ts:419](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L419) |
158
- | <a id="queues"></a> `queues?` | `Record`\<`string`, [`QueueDefinition`](#queuedefinition)\> | Named queue definitions. Each key becomes available as a named resource in the contract. | [types.ts:406](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L406) |
185
+ | <a id="bindings"></a> `bindings?` | `Record`\<`string`, [`BindingDefinition`](#bindingdefinition)\> | Named binding definitions. Bindings can be queue-to-exchange or exchange-to-exchange. | [types.ts:412](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L412) |
186
+ | <a id="consumers"></a> `consumers?` | `Record`\<`string`, [`ConsumerDefinition`](#consumerdefinition)\> | Named consumer definitions. Each key requires a corresponding handler in the TypedAmqpWorker. The handler will be fully typed based on the message schema. | [types.ts:426](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L426) |
187
+ | <a id="exchanges"></a> `exchanges?` | `Record`\<`string`, [`ExchangeDefinition`](#exchangedefinition)\> | Named exchange definitions. Each key becomes available as a named resource in the contract. | [types.ts:400](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L400) |
188
+ | <a id="publishers"></a> `publishers?` | `Record`\<`string`, [`PublisherDefinition`](#publisherdefinition)\> | Named publisher definitions. Each key becomes a method on the TypedAmqpClient for publishing messages. The method will be fully typed based on the message schema. | [types.ts:419](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L419) |
189
+ | <a id="queues"></a> `queues?` | `Record`\<`string`, [`QueueDefinition`](#queuedefinition)\> | Named queue definitions. Each key becomes available as a named resource in the contract. | [types.ts:406](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L406) |
159
190
 
160
191
  ***
161
192
 
@@ -165,7 +196,7 @@ const contract: ContractDefinition = {
165
196
  type DirectExchangeDefinition = BaseExchangeDefinition & object;
166
197
  ```
167
198
 
168
- Defined in: [types.ts:82](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L82)
199
+ Defined in: [types.ts:82](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L82)
169
200
 
170
201
  A direct exchange definition.
171
202
 
@@ -176,7 +207,7 @@ This is ideal for point-to-point messaging where each message should go to speci
176
207
 
177
208
  | Name | Type | Defined in |
178
209
  | ------ | ------ | ------ |
179
- | `type` | `"direct"` | [types.ts:83](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L83) |
210
+ | `type` | `"direct"` | [types.ts:83](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L83) |
180
211
 
181
212
  #### Example
182
213
 
@@ -203,7 +234,7 @@ type ExchangeBindingDefinition = object &
203
234
  };
204
235
  ```
205
236
 
206
- Defined in: [types.ts:262](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L262)
237
+ Defined in: [types.ts:262](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L262)
207
238
 
208
239
  Binding between two exchanges (exchange-to-exchange routing).
209
240
 
@@ -214,9 +245,9 @@ This allows for more complex routing topologies.
214
245
 
215
246
  | Name | Type | Description | Defined in |
216
247
  | ------ | ------ | ------ | ------ |
217
- | `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for the binding. | [types.ts:272](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L272) |
218
- | `destination` | [`ExchangeDefinition`](#exchangedefinition) | The destination exchange that will receive forwarded messages | [types.ts:267](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L267) |
219
- | `type` | `"exchange"` | Discriminator indicating this is an exchange-to-exchange binding | [types.ts:264](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L264) |
248
+ | `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for the binding. | [types.ts:272](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L272) |
249
+ | `destination` | [`ExchangeDefinition`](#exchangedefinition) | The destination exchange that will receive forwarded messages | [types.ts:267](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L267) |
250
+ | `type` | `"exchange"` | Discriminator indicating this is an exchange-to-exchange binding | [types.ts:264](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L264) |
220
251
 
221
252
  #### Example
222
253
 
@@ -241,7 +272,7 @@ type ExchangeDefinition =
241
272
  | TopicExchangeDefinition;
242
273
  ```
243
274
 
244
- Defined in: [types.ts:112](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L112)
275
+ Defined in: [types.ts:112](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L112)
245
276
 
246
277
  Union type of all exchange definitions.
247
278
 
@@ -255,7 +286,7 @@ Represents any type of AMQP exchange: fanout, direct, or topic.
255
286
  type FanoutExchangeDefinition = BaseExchangeDefinition & object;
256
287
  ```
257
288
 
258
- Defined in: [types.ts:65](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L65)
289
+ Defined in: [types.ts:65](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L65)
259
290
 
260
291
  A fanout exchange definition.
261
292
 
@@ -266,7 +297,7 @@ This is the simplest exchange type for pub/sub messaging patterns.
266
297
 
267
298
  | Name | Type | Defined in |
268
299
  | ------ | ------ | ------ |
269
- | `type` | `"fanout"` | [types.ts:66](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L66) |
300
+ | `type` | `"fanout"` | [types.ts:66](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L66) |
270
301
 
271
302
  #### Example
272
303
 
@@ -284,7 +315,7 @@ const logsExchange: FanoutExchangeDefinition = defineExchange('logs', 'fanout',
284
315
  type InferConsumerNames<TContract> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
285
316
  ```
286
317
 
287
- Defined in: [types.ts:462](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L462)
318
+ Defined in: [types.ts:462](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L462)
288
319
 
289
320
  Extract consumer names from a contract.
290
321
 
@@ -316,7 +347,7 @@ type ConsumerNames = InferConsumerNames<typeof myContract>;
316
347
  type InferPublisherNames<TContract> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
317
348
  ```
318
349
 
319
- Defined in: [types.ts:444](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L444)
350
+ Defined in: [types.ts:444](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L444)
320
351
 
321
352
  Extract publisher names from a contract.
322
353
 
@@ -348,7 +379,7 @@ type PublisherNames = InferPublisherNames<typeof myContract>;
348
379
  type MessageDefinition<TPayload, THeaders> = object;
349
380
  ```
350
381
 
351
- Defined in: [types.ts:178](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L178)
382
+ Defined in: [types.ts:178](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L178)
352
383
 
353
384
  Definition of a message with typed payload and optional headers.
354
385
 
@@ -363,10 +394,10 @@ Definition of a message with typed payload and optional headers.
363
394
 
364
395
  | Property | Type | Description | Defined in |
365
396
  | ------ | ------ | ------ | ------ |
366
- | <a id="description"></a> `description?` | `string` | Detailed description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:204](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L204) |
367
- | <a id="headers"></a> `headers?` | `THeaders` | Optional headers schema for validating message metadata. Must be a Standard Schema v1 compatible schema. | [types.ts:192](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L192) |
368
- | <a id="payload"></a> `payload` | `TPayload` | The payload schema for validating message content. Must be a Standard Schema v1 compatible schema (Zod, Valibot, ArkType, etc.). | [types.ts:186](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L186) |
369
- | <a id="summary"></a> `summary?` | `string` | Brief description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:198](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L198) |
397
+ | <a id="description"></a> `description?` | `string` | Detailed description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:204](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L204) |
398
+ | <a id="headers"></a> `headers?` | `THeaders` | Optional headers schema for validating message metadata. Must be a Standard Schema v1 compatible schema. | [types.ts:192](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L192) |
399
+ | <a id="payload"></a> `payload` | `TPayload` | The payload schema for validating message content. Must be a Standard Schema v1 compatible schema (Zod, Valibot, ArkType, etc.). | [types.ts:186](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L186) |
400
+ | <a id="summary"></a> `summary?` | `string` | Brief description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:198](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L198) |
370
401
 
371
402
  ***
372
403
 
@@ -385,7 +416,7 @@ type PublisherDefinition<TMessage> = object &
385
416
  };
386
417
  ```
387
418
 
388
- Defined in: [types.ts:317](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L317)
419
+ Defined in: [types.ts:317](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L317)
389
420
 
390
421
  Definition of a message publisher.
391
422
 
@@ -396,7 +427,7 @@ The message payload is validated against the schema before being sent to RabbitM
396
427
 
397
428
  | Name | Type | Description | Defined in |
398
429
  | ------ | ------ | ------ | ------ |
399
- | `message` | `TMessage` | The message definition including the payload schema | [types.ts:319](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L319) |
430
+ | `message` | `TMessage` | The message definition including the payload schema | [types.ts:319](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L319) |
400
431
 
401
432
  #### Type Parameters
402
433
 
@@ -416,6 +447,38 @@ const publisher: PublisherDefinition = {
416
447
 
417
448
  ***
418
449
 
450
+ ### PublisherFirstResult
451
+
452
+ ```ts
453
+ type PublisherFirstResult<TMessage, TPublisher> = object;
454
+ ```
455
+
456
+ Defined in: [builder.ts:734](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L734)
457
+
458
+ Publisher-first builder result.
459
+
460
+ This type represents a publisher and provides a method to create
461
+ a consumer that uses the same message schema with a binding to the exchange.
462
+
463
+ This pattern is suitable for event-oriented messaging where publishers
464
+ emit events without knowing which queues will consume them.
465
+
466
+ #### Type Parameters
467
+
468
+ | Type Parameter | Description |
469
+ | ------ | ------ |
470
+ | `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
471
+ | `TPublisher` *extends* [`PublisherDefinition`](#publisherdefinition)\<`TMessage`\> | The publisher definition |
472
+
473
+ #### Properties
474
+
475
+ | Property | Type | Description | Defined in |
476
+ | ------ | ------ | ------ | ------ |
477
+ | <a id="createconsumer"></a> `createConsumer` | (`queue`) => `object` | Create a consumer that receives messages from this publisher. The consumer will automatically use the same message schema and a binding will be created with the same routing key. | [builder.ts:748](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L748) |
478
+ | <a id="publisher"></a> `publisher` | `TPublisher` | The publisher definition | [builder.ts:739](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L739) |
479
+
480
+ ***
481
+
419
482
  ### QueueBindingDefinition
420
483
 
421
484
  ```ts
@@ -431,7 +494,7 @@ type QueueBindingDefinition = object &
431
494
  };
432
495
  ```
433
496
 
434
- Defined in: [types.ts:214](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L214)
497
+ Defined in: [types.ts:214](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L214)
435
498
 
436
499
  Binding between a queue and an exchange.
437
500
 
@@ -443,9 +506,9 @@ For fanout exchanges, no routing key is needed as all messages are broadcast.
443
506
 
444
507
  | Name | Type | Description | Defined in |
445
508
  | ------ | ------ | ------ | ------ |
446
- | `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for the binding. Can be used for advanced routing scenarios with the headers exchange type. | [types.ts:225](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L225) |
447
- | `queue` | [`QueueDefinition`](#queuedefinition) | The queue that will receive messages | [types.ts:219](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L219) |
448
- | `type` | `"queue"` | Discriminator indicating this is a queue-to-exchange binding | [types.ts:216](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L216) |
509
+ | `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for the binding. Can be used for advanced routing scenarios with the headers exchange type. | [types.ts:225](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L225) |
510
+ | `queue` | [`QueueDefinition`](#queuedefinition) | The queue that will receive messages | [types.ts:219](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L219) |
511
+ | `type` | `"queue"` | Discriminator indicating this is a queue-to-exchange binding | [types.ts:216](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L216) |
449
512
 
450
513
  ***
451
514
 
@@ -455,7 +518,7 @@ For fanout exchanges, no routing key is needed as all messages are broadcast.
455
518
  type QueueDefinition = object;
456
519
  ```
457
520
 
458
- Defined in: [types.ts:123](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L123)
521
+ Defined in: [types.ts:123](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L123)
459
522
 
460
523
  Definition of an AMQP queue.
461
524
 
@@ -466,11 +529,11 @@ to receive messages based on routing rules.
466
529
 
467
530
  | Property | Type | Description | Defined in |
468
531
  | ------ | ------ | ------ | ------ |
469
- | <a id="arguments-1"></a> `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for advanced configuration. Common arguments include: - `x-message-ttl`: Message time-to-live in milliseconds - `x-expires`: Queue expiration time in milliseconds - `x-max-length`: Maximum number of messages in the queue - `x-max-length-bytes`: Maximum size of the queue in bytes - `x-dead-letter-exchange`: Exchange for dead-lettered messages - `x-dead-letter-routing-key`: Routing key for dead-lettered messages - `x-max-priority`: Maximum priority level for priority queues **Example** `{ 'x-message-ttl': 86400000, // 24 hours 'x-dead-letter-exchange': 'dlx', 'x-max-priority': 10 }` | [types.ts:169](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L169) |
470
- | <a id="autodelete-1"></a> `autoDelete?` | `boolean` | If true, the queue is deleted when the last consumer unsubscribes. **Default** `false` | [types.ts:146](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L146) |
471
- | <a id="durable-1"></a> `durable?` | `boolean` | If true, the queue survives broker restarts. Durable queues are persisted to disk. **Default** `false` | [types.ts:133](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L133) |
472
- | <a id="exclusive"></a> `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. **Default** `false` | [types.ts:140](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L140) |
473
- | <a id="name-1"></a> `name` | `string` | The name of the queue. Must be unique within the RabbitMQ virtual host. | [types.ts:127](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L127) |
532
+ | <a id="arguments-1"></a> `arguments?` | `Record`\<`string`, `unknown`\> | Additional AMQP arguments for advanced configuration. Common arguments include: - `x-message-ttl`: Message time-to-live in milliseconds - `x-expires`: Queue expiration time in milliseconds - `x-max-length`: Maximum number of messages in the queue - `x-max-length-bytes`: Maximum size of the queue in bytes - `x-dead-letter-exchange`: Exchange for dead-lettered messages - `x-dead-letter-routing-key`: Routing key for dead-lettered messages - `x-max-priority`: Maximum priority level for priority queues **Example** `{ 'x-message-ttl': 86400000, // 24 hours 'x-dead-letter-exchange': 'dlx', 'x-max-priority': 10 }` | [types.ts:169](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L169) |
533
+ | <a id="autodelete-1"></a> `autoDelete?` | `boolean` | If true, the queue is deleted when the last consumer unsubscribes. **Default** `false` | [types.ts:146](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L146) |
534
+ | <a id="durable-1"></a> `durable?` | `boolean` | If true, the queue survives broker restarts. Durable queues are persisted to disk. **Default** `false` | [types.ts:133](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L133) |
535
+ | <a id="exclusive"></a> `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. **Default** `false` | [types.ts:140](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L140) |
536
+ | <a id="name-1"></a> `name` | `string` | The name of the queue. Must be unique within the RabbitMQ virtual host. | [types.ts:127](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L127) |
474
537
 
475
538
  ***
476
539
 
@@ -480,7 +543,7 @@ to receive messages based on routing rules.
480
543
  type TopicExchangeDefinition = BaseExchangeDefinition & object;
481
544
  ```
482
545
 
483
- Defined in: [types.ts:103](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L103)
546
+ Defined in: [types.ts:103](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L103)
484
547
 
485
548
  A topic exchange definition.
486
549
 
@@ -494,7 +557,7 @@ Words are separated by dots (e.g., `order.created.high-value`).
494
557
 
495
558
  | Name | Type | Defined in |
496
559
  | ------ | ------ | ------ |
497
- | `type` | `"topic"` | [types.ts:104](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/types.ts#L104) |
560
+ | `type` | `"topic"` | [types.ts:104](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/types.ts#L104) |
498
561
 
499
562
  #### Example
500
563
 
@@ -516,7 +579,7 @@ function defineConsumer<TMessage>(
516
579
  options?): ConsumerDefinition<TMessage>;
517
580
  ```
518
581
 
519
- Defined in: [builder.ts:595](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/builder.ts#L595)
582
+ Defined in: [builder.ts:595](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L595)
520
583
 
521
584
  Define a message consumer.
522
585
 
@@ -583,7 +646,7 @@ const processOrderConsumer = defineConsumer(orderQueue, orderMessage);
583
646
  function defineContract<TContract>(definition): TContract;
584
647
  ```
585
648
 
586
- Defined in: [builder.ts:676](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/builder.ts#L676)
649
+ Defined in: [builder.ts:676](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L676)
587
650
 
588
651
  Define an AMQP contract.
589
652
 
@@ -672,7 +735,7 @@ export const contract = defineContract({
672
735
  function defineMessage<TPayload, THeaders>(payload, options?): MessageDefinition<TPayload, THeaders>;
673
736
  ```
674
737
 
675
- Defined in: [builder.ts:197](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/builder.ts#L197)
738
+ Defined in: [builder.ts:197](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L197)
676
739
 
677
740
  Define a message definition with payload and optional headers/metadata.
678
741
 
@@ -733,7 +796,7 @@ const orderMessage = defineMessage(
733
796
  function defineQueue(name, options?): QueueDefinition;
734
797
  ```
735
798
 
736
- Defined in: [builder.ts:152](https://github.com/btravers/amqp-contract/blob/d4ba5adf1e580179e8e0a4a6505d50b03f1a9b29/packages/contract/src/builder.ts#L152)
799
+ Defined in: [builder.ts:152](https://github.com/btravers/amqp-contract/blob/6a6c658de853e244d99f97019419401bb9a8d86d/packages/contract/src/builder.ts#L152)
737
800
 
738
801
  Define an AMQP queue.
739
802
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amqp-contract/contract",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "Contract builder for amqp-contract",
5
5
  "keywords": [
6
6
  "amqp",