@amqp-contract/contract 0.1.3 → 0.2.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 CHANGED
@@ -13,52 +13,61 @@ pnpm add @amqp-contract/contract
13
13
  ## Usage
14
14
 
15
15
  ```typescript
16
- import { defineContract, defineExchange, defineQueue, defineBinding, defineExchangeBinding, definePublisher, defineConsumer } from '@amqp-contract/contract';
16
+ import { defineContract, defineExchange, defineQueue, defineQueueBinding, defineExchangeBinding, definePublisher, defineConsumer, defineMessage } from '@amqp-contract/contract';
17
17
  import { z } from 'zod';
18
18
 
19
- // Define your contract
19
+ // Define exchanges and queues first so they can be referenced
20
+ const ordersExchange = defineExchange('orders', 'topic', { durable: true });
21
+ const analyticsExchange = defineExchange('analytics', 'topic', { durable: true });
22
+ const orderProcessingQueue = defineQueue('order-processing', { durable: true });
23
+ const analyticsProcessingQueue = defineQueue('analytics-processing', { durable: true });
24
+
25
+ // Define message schemas with metadata
26
+ const orderMessage = defineMessage(
27
+ z.object({
28
+ orderId: z.string(),
29
+ amount: z.number(),
30
+ }),
31
+ {
32
+ summary: 'Order created event',
33
+ description: 'Emitted when a new order is created',
34
+ }
35
+ );
36
+
37
+ // Define your contract using object references
20
38
  const contract = defineContract({
21
39
  exchanges: {
22
- orders: defineExchange('orders', 'topic', { durable: true }),
23
- analytics: defineExchange('analytics', 'topic', { durable: true }),
40
+ orders: ordersExchange,
41
+ analytics: analyticsExchange,
24
42
  },
25
43
  queues: {
26
- orderProcessing: defineQueue('order-processing', { durable: true }),
27
- analyticsProcessing: defineQueue('analytics-processing', { durable: true }),
44
+ orderProcessing: orderProcessingQueue,
45
+ analyticsProcessing: analyticsProcessingQueue,
28
46
  },
29
47
  bindings: {
30
48
  // Queue-to-exchange binding
31
- orderBinding: defineBinding('order-processing', 'orders', {
49
+ orderBinding: defineQueueBinding(orderProcessingQueue, ordersExchange, {
32
50
  routingKey: 'order.created',
33
51
  }),
34
52
  // Exchange-to-exchange binding
35
- analyticsBinding: defineExchangeBinding('analytics', 'orders', {
53
+ analyticsBinding: defineExchangeBinding(analyticsExchange, ordersExchange, {
36
54
  routingKey: 'order.#',
37
55
  }),
38
56
  // Queue receives from analytics exchange
39
- analyticsQueueBinding: defineBinding('analytics-processing', 'analytics', {
57
+ analyticsQueueBinding: defineQueueBinding(analyticsProcessingQueue, analyticsExchange, {
40
58
  routingKey: 'order.#',
41
59
  }),
42
60
  },
43
61
  publishers: {
44
- orderCreated: definePublisher('orders', z.object({
45
- orderId: z.string(),
46
- amount: z.number(),
47
- }), {
62
+ orderCreated: definePublisher(ordersExchange, orderMessage, {
48
63
  routingKey: 'order.created',
49
64
  }),
50
65
  },
51
66
  consumers: {
52
- processOrder: defineConsumer('order-processing', z.object({
53
- orderId: z.string(),
54
- amount: z.number(),
55
- }), {
67
+ processOrder: defineConsumer(orderProcessingQueue, orderMessage, {
56
68
  prefetch: 10,
57
69
  }),
58
- processAnalytics: defineConsumer('analytics-processing', z.object({
59
- orderId: z.string(),
60
- amount: z.number(),
61
- })),
70
+ processAnalytics: defineConsumer(analyticsProcessingQueue, orderMessage),
62
71
  },
63
72
  });
64
73
  ```
@@ -67,32 +76,73 @@ const contract = defineContract({
67
76
 
68
77
  ### `defineExchange(name, type, options?)`
69
78
 
70
- Define an AMQP exchange.
79
+ Define an AMQP exchange. Returns an exchange definition object that can be referenced by bindings and publishers.
80
+
81
+ **Types:** `'fanout'`, `'direct'`, or `'topic'`
71
82
 
72
83
  ### `defineQueue(name, options?)`
73
84
 
74
- Define an AMQP queue.
85
+ Define an AMQP queue. Returns a queue definition object that can be referenced by bindings and consumers.
86
+
87
+ ### `defineMessage(payloadSchema, options?)`
88
+
89
+ Define a message definition with a payload schema and optional metadata (headers, summary, description).
90
+ This is useful for documentation generation and type inference.
91
+
92
+ ### `defineQueueBinding(queue, exchange, options?)`
75
93
 
76
- ### `defineBinding(queue, exchange, options?)`
94
+ Define a binding between a queue and an exchange. Pass the queue and exchange objects (not strings).
77
95
 
78
- Define a binding between a queue and an exchange.
96
+ **For fanout exchanges:** Routing key is optional (fanout ignores routing keys).
97
+ **For direct/topic exchanges:** Routing key is required in options.
79
98
 
80
99
  ### `defineExchangeBinding(destination, source, options?)`
81
100
 
82
101
  Define a binding between two exchanges (source → destination). Messages published to the source exchange will be routed to the destination exchange based on the routing key pattern.
83
102
 
84
- ### `definePublisher(exchange, messageSchema, options?)`
103
+ Pass the exchange objects (not strings).
85
104
 
86
- Define a message publisher with validation schema.
105
+ ### `definePublisher(exchange, message, options?)`
87
106
 
88
- ### `defineConsumer(queue, messageSchema, options?)`
107
+ Define a message publisher with validation schema. Pass the exchange object (not a string).
89
108
 
90
- Define a message consumer with validation schema.
109
+ **For fanout exchanges:** Routing key is optional (fanout ignores routing keys).
110
+ **For direct/topic exchanges:** Routing key is required in options.
111
+
112
+ ### `defineConsumer(queue, message, options?)`
113
+
114
+ Define a message consumer with validation schema. Pass the queue object (not a string).
91
115
 
92
116
  ### `defineContract(definition)`
93
117
 
94
118
  Create a complete AMQP contract with exchanges, queues, bindings, publishers, and consumers.
95
119
 
120
+ ## Key Concepts
121
+
122
+ ### Composition Pattern
123
+
124
+ The contract API uses a composition pattern where you:
125
+
126
+ 1. Define exchanges and queues first as variables
127
+ 2. Reference these objects in bindings, publishers, and consumers
128
+ 3. Compose everything together in `defineContract`
129
+
130
+ This provides:
131
+
132
+ - **Better type safety**: TypeScript can validate exchange/queue types
133
+ - **Better refactoring**: Rename an exchange in one place
134
+ - **DRY principle**: Define once, reference many times
135
+
136
+ ### Exchange Types & Routing Keys
137
+
138
+ The API enforces routing key requirements based on exchange type:
139
+
140
+ - **Fanout exchanges**: Don't use routing keys (all messages go to all bound queues)
141
+ - **Direct exchanges**: Require explicit routing keys for exact matching
142
+ - **Topic exchanges**: Require routing key patterns (e.g., `order.*`, `order.#`)
143
+
144
+ TypeScript enforces these rules at compile time through discriminated unions.
145
+
96
146
  ## License
97
147
 
98
148
  MIT
package/dist/index.cjs CHANGED
@@ -1,16 +1,6 @@
1
1
 
2
2
  //#region src/builder.ts
3
3
  /**
4
- * Define a message schema with metadata
5
- */
6
- function defineMessage(name, schema) {
7
- return {
8
- name,
9
- schema,
10
- "~standard": schema["~standard"]
11
- };
12
- }
13
- /**
14
4
  * Define an AMQP exchange
15
5
  */
16
6
  function defineExchange(name, type, options) {
@@ -30,35 +20,62 @@ function defineQueue(name, options) {
30
20
  };
31
21
  }
32
22
  /**
33
- * Define a binding between queue and exchange
23
+ * Define a message definition with payload and optional headers/metadata
34
24
  */
35
- function defineBinding(queue, exchange, options) {
25
+ function defineMessage(payload, options) {
36
26
  return {
27
+ payload,
28
+ ...options
29
+ };
30
+ }
31
+ /**
32
+ * Define a binding between queue and exchange (exchange -> queue)
33
+ */
34
+ function defineQueueBinding(queue, exchange, options) {
35
+ if (exchange.type === "fanout") return {
37
36
  type: "queue",
38
37
  queue,
39
38
  exchange,
40
- ...options
39
+ ...options?.arguments && { arguments: options.arguments }
40
+ };
41
+ return {
42
+ type: "queue",
43
+ queue,
44
+ exchange,
45
+ routingKey: options?.routingKey,
46
+ ...options?.arguments && { arguments: options.arguments }
41
47
  };
42
48
  }
43
49
  /**
44
50
  * Define a binding between exchange and exchange (source -> destination)
45
51
  */
46
52
  function defineExchangeBinding(destination, source, options) {
53
+ if (source.type === "fanout") return {
54
+ type: "exchange",
55
+ source,
56
+ destination,
57
+ ...options?.arguments && { arguments: options.arguments }
58
+ };
47
59
  return {
48
60
  type: "exchange",
49
61
  source,
50
62
  destination,
51
- ...options
63
+ routingKey: options?.routingKey ?? "",
64
+ ...options?.arguments && { arguments: options.arguments }
52
65
  };
53
66
  }
54
67
  /**
55
68
  * Define a message publisher
56
69
  */
57
70
  function definePublisher(exchange, message, options) {
71
+ if (exchange.type === "fanout") return {
72
+ exchange,
73
+ message
74
+ };
58
75
  return {
59
76
  exchange,
60
77
  message,
61
- ...options
78
+ routingKey: options?.routingKey ?? ""
62
79
  };
63
80
  }
64
81
  /**
@@ -79,11 +96,11 @@ function defineContract(definition) {
79
96
  }
80
97
 
81
98
  //#endregion
82
- exports.defineBinding = defineBinding;
83
99
  exports.defineConsumer = defineConsumer;
84
100
  exports.defineContract = defineContract;
85
101
  exports.defineExchange = defineExchange;
86
102
  exports.defineExchangeBinding = defineExchangeBinding;
87
103
  exports.defineMessage = defineMessage;
88
104
  exports.definePublisher = definePublisher;
89
- exports.defineQueue = defineQueue;
105
+ exports.defineQueue = defineQueue;
106
+ exports.defineQueueBinding = defineQueueBinding;
package/dist/index.d.cts CHANGED
@@ -6,51 +6,70 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
6
6
  * Any schema that conforms to Standard Schema v1
7
7
  */
8
8
  type AnySchema = StandardSchemaV1;
9
- /**
10
- * Exchange types supported by AMQP
11
- */
12
- type ExchangeType = "direct" | "fanout" | "topic" | "headers";
13
9
  /**
14
10
  * Definition of an AMQP exchange
15
11
  */
16
- interface ExchangeDefinition {
12
+ type BaseExchangeDefinition = {
17
13
  name: string;
18
- type: ExchangeType;
19
14
  durable?: boolean;
20
15
  autoDelete?: boolean;
21
16
  internal?: boolean;
22
17
  arguments?: Record<string, unknown>;
23
- }
18
+ };
19
+ type FanoutExchangeDefinition = BaseExchangeDefinition & {
20
+ type: "fanout";
21
+ };
22
+ type DirectExchangeDefinition = BaseExchangeDefinition & {
23
+ type: "direct";
24
+ };
25
+ type TopicExchangeDefinition = BaseExchangeDefinition & {
26
+ type: "topic";
27
+ };
28
+ type ExchangeDefinition = FanoutExchangeDefinition | DirectExchangeDefinition | TopicExchangeDefinition;
24
29
  /**
25
30
  * Definition of an AMQP queue
26
31
  */
27
- interface QueueDefinition {
32
+ type QueueDefinition = {
28
33
  name: string;
29
34
  durable?: boolean;
30
35
  exclusive?: boolean;
31
36
  autoDelete?: boolean;
32
37
  arguments?: Record<string, unknown>;
33
- }
38
+ };
39
+ type MessageDefinition<TPayload extends AnySchema = AnySchema, THeaders extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined> = {
40
+ payload: TPayload;
41
+ headers?: THeaders;
42
+ summary?: string;
43
+ description?: string;
44
+ };
34
45
  /**
35
46
  * Binding between queue and exchange
36
47
  */
37
- interface QueueBindingDefinition {
48
+ type QueueBindingDefinition = {
38
49
  type: "queue";
39
- queue: string;
40
- exchange: string;
41
- routingKey?: string;
50
+ queue: QueueDefinition;
42
51
  arguments?: Record<string, unknown>;
43
- }
52
+ } & ({
53
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
54
+ routingKey: string;
55
+ } | {
56
+ exchange: FanoutExchangeDefinition;
57
+ routingKey?: never;
58
+ });
44
59
  /**
45
60
  * Binding between exchange and exchange
46
61
  */
47
- interface ExchangeBindingDefinition {
62
+ type ExchangeBindingDefinition = {
48
63
  type: "exchange";
49
- source: string;
50
- destination: string;
51
- routingKey?: string;
64
+ destination: ExchangeDefinition;
52
65
  arguments?: Record<string, unknown>;
53
- }
66
+ } & ({
67
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
68
+ routingKey: string;
69
+ } | {
70
+ source: FanoutExchangeDefinition;
71
+ routingKey?: never;
72
+ });
54
73
  /**
55
74
  * Binding definition - can be either queue-to-exchange or exchange-to-exchange
56
75
  */
@@ -58,143 +77,165 @@ type BindingDefinition = QueueBindingDefinition | ExchangeBindingDefinition;
58
77
  /**
59
78
  * Definition of a message publisher
60
79
  */
61
- interface PublisherDefinition<TMessageSchema extends AnySchema = AnySchema> {
62
- exchange: string;
63
- routingKey?: string;
64
- message: TMessageSchema;
65
- }
80
+ type PublisherDefinition<TMessage extends MessageDefinition = MessageDefinition> = {
81
+ message: TMessage;
82
+ } & ({
83
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
84
+ routingKey: string;
85
+ } | {
86
+ exchange: FanoutExchangeDefinition;
87
+ routingKey?: never;
88
+ });
66
89
  /**
67
90
  * Definition of a message consumer
68
91
  */
69
- interface ConsumerDefinition<TMessageSchema extends AnySchema = AnySchema, THandlerResultSchema extends AnySchema = AnySchema> {
70
- queue: string;
71
- message: TMessageSchema;
72
- handlerResult?: THandlerResultSchema;
92
+ type ConsumerDefinition<TMessage extends MessageDefinition = MessageDefinition> = {
93
+ queue: QueueDefinition;
94
+ message: TMessage;
73
95
  prefetch?: number;
74
96
  noAck?: boolean;
75
- }
97
+ };
76
98
  /**
77
99
  * Contract definition containing all AMQP resources
78
100
  */
79
- interface ContractDefinition<TExchanges extends Record<string, ExchangeDefinition> = Record<string, ExchangeDefinition>, TQueues extends Record<string, QueueDefinition> = Record<string, QueueDefinition>, TBindings extends Record<string, BindingDefinition> = Record<string, BindingDefinition>, TPublishers extends Record<string, PublisherDefinition> = Record<string, PublisherDefinition>, TConsumers extends Record<string, ConsumerDefinition> = Record<string, ConsumerDefinition>> {
80
- exchanges?: TExchanges;
81
- queues?: TQueues;
82
- bindings?: TBindings;
83
- publishers?: TPublishers;
84
- consumers?: TConsumers;
85
- }
101
+ type ContractDefinition = {
102
+ exchanges?: Record<string, ExchangeDefinition>;
103
+ queues?: Record<string, QueueDefinition>;
104
+ bindings?: Record<string, BindingDefinition>;
105
+ publishers?: Record<string, PublisherDefinition>;
106
+ consumers?: Record<string, ConsumerDefinition>;
107
+ };
86
108
  /**
87
- * Infer the TypeScript type from a schema
109
+ * Infer publisher names from a contract
88
110
  */
89
- type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
111
+ type InferPublisherNames<TContract extends ContractDefinition> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
90
112
  /**
91
- * Infer the output type from a schema
113
+ * Infer consumer names from a contract
92
114
  */
93
- type InferSchemaOutput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<unknown, infer TOutput> ? TOutput : never;
115
+ type InferConsumerNames<TContract extends ContractDefinition> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
94
116
  /**
95
- * Infer publisher message input type
96
- */
97
- type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher["message"]>;
98
- /**
99
- * Infer consumer message input type
100
- */
101
- type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer["message"]>;
102
- /**
103
- * Infer consumer handler result type
117
+ * Infer the TypeScript type from a schema
104
118
  */
105
- type ConsumerInferHandlerResult<TConsumer extends ConsumerDefinition> = TConsumer["handlerResult"] extends AnySchema ? InferSchemaOutput<TConsumer["handlerResult"]> : void;
119
+ type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
106
120
  /**
107
- * Consumer handler function type
108
- * Handlers return Promise for async handling
109
- * where HandlerResult is inferred from the consumer's handlerResult schema (defaults to void)
121
+ * Infer publisher message input type
110
122
  */
111
- type ConsumerHandler<TConsumer extends ConsumerDefinition> = (message: ConsumerInferInput<TConsumer>) => Promise<ConsumerInferHandlerResult<TConsumer>>;
123
+ type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher["message"]["payload"]>;
112
124
  /**
113
125
  * Infer all publishers from contract
114
126
  */
115
127
  type InferPublishers<TContract extends ContractDefinition> = NonNullable<TContract["publishers"]>;
116
128
  /**
117
- * Infer all consumers from contract
118
- */
119
- type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
120
- /**
121
- * Infer publisher names from contract
129
+ * Get specific publisher definition from contract
122
130
  */
123
- type InferPublisherNames<TContract extends ContractDefinition> = keyof InferPublishers<TContract>;
131
+ type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
124
132
  /**
125
- * Infer consumer names from contract
133
+ * Infer publisher input type (message payload) for a specific publisher in a contract
126
134
  */
127
- type InferConsumerNames<TContract extends ContractDefinition> = keyof InferConsumers<TContract>;
135
+ type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
128
136
  /**
129
- * Get specific publisher definition from contract
137
+ * Infer all consumers from contract
130
138
  */
131
- type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
139
+ type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
132
140
  /**
133
141
  * Get specific consumer definition from contract
134
142
  */
135
143
  type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
136
144
  /**
137
- * Client perspective types - for publishing messages
145
+ * Infer consumer message input type
138
146
  */
139
- type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
147
+ type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer["message"]["payload"]>;
140
148
  /**
141
149
  * Worker perspective types - for consuming messages
142
150
  */
143
151
  type WorkerInferConsumerInput<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferInput<InferConsumer<TContract, TName>>;
144
152
  /**
145
- * Worker perspective - consumer handler result type
153
+ * Infer consumer handler type for a specific consumer
146
154
  */
147
- type WorkerInferConsumerHandlerResult<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHandlerResult<InferConsumer<TContract, TName>>;
155
+ type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumerInput<TContract, TName>) => Promise<void> | void;
148
156
  /**
149
- * Worker perspective - consumer handler type
150
- */
151
- type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerHandler<InferConsumer<TContract, TName>>;
152
- /**
153
- * Map of all consumer handlers for a contract
157
+ * Infer all consumer handlers for a contract
154
158
  */
155
159
  type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandler<TContract, K> };
156
160
  //#endregion
157
161
  //#region src/builder.d.ts
162
+ declare function defineExchange(name: string, type: "fanout", options?: Omit<BaseExchangeDefinition, "name" | "type">): FanoutExchangeDefinition;
163
+ declare function defineExchange(name: string, type: "direct", options?: Omit<BaseExchangeDefinition, "name" | "type">): DirectExchangeDefinition;
164
+ declare function defineExchange(name: string, type: "topic", options?: Omit<BaseExchangeDefinition, "name" | "type">): TopicExchangeDefinition;
165
+ /**
166
+ * Define an AMQP queue
167
+ */
168
+ declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">): QueueDefinition;
158
169
  /**
159
- * Message schema with metadata
170
+ * Define a message definition with payload and optional headers/metadata
160
171
  */
161
- interface MessageSchema<TSchema extends AnySchema = AnySchema> extends AnySchema {
162
- readonly name: string;
163
- readonly schema: TSchema;
164
- readonly "~standard": TSchema["~standard"];
165
- }
172
+ declare function defineMessage<TPayload extends MessageDefinition["payload"], THeaders extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined>(payload: TPayload, options?: {
173
+ headers?: THeaders;
174
+ summary?: string;
175
+ description?: string;
176
+ }): MessageDefinition<TPayload, THeaders>;
166
177
  /**
167
- * Define a message schema with metadata
178
+ * Define a binding between queue and fanout exchange (exchange -> queue)
179
+ * Fanout exchanges don't use routing keys
168
180
  */
169
- declare function defineMessage<TSchema extends AnySchema>(name: string, schema: TSchema): MessageSchema<TSchema>;
181
+ declare function defineQueueBinding(queue: QueueDefinition, exchange: FanoutExchangeDefinition, options?: Omit<Extract<QueueBindingDefinition, {
182
+ exchange: FanoutExchangeDefinition;
183
+ }>, "type" | "queue" | "exchange" | "routingKey">): Extract<QueueBindingDefinition, {
184
+ exchange: FanoutExchangeDefinition;
185
+ }>;
170
186
  /**
171
- * Define an AMQP exchange
187
+ * Define a binding between queue and direct/topic exchange (exchange -> queue)
188
+ * Direct and topic exchanges require a routing key
172
189
  */
173
- declare function defineExchange(name: string, type: ExchangeType, options?: Omit<ExchangeDefinition, "name" | "type">): ExchangeDefinition;
190
+ declare function defineQueueBinding(queue: QueueDefinition, exchange: DirectExchangeDefinition | TopicExchangeDefinition, options: Omit<Extract<QueueBindingDefinition, {
191
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
192
+ }>, "type" | "queue" | "exchange">): Extract<QueueBindingDefinition, {
193
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
194
+ }>;
174
195
  /**
175
- * Define an AMQP queue
196
+ * Define a binding between fanout exchange and exchange (source -> destination)
197
+ * Fanout exchanges don't use routing keys
176
198
  */
177
- declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">): QueueDefinition;
199
+ declare function defineExchangeBinding(destination: ExchangeDefinition, source: FanoutExchangeDefinition, options?: Omit<Extract<ExchangeBindingDefinition, {
200
+ source: FanoutExchangeDefinition;
201
+ }>, "type" | "source" | "destination" | "routingKey">): Extract<ExchangeBindingDefinition, {
202
+ source: FanoutExchangeDefinition;
203
+ }>;
178
204
  /**
179
- * Define a binding between queue and exchange
205
+ * Define a binding between direct/topic exchange and exchange (source -> destination)
206
+ * Direct and topic exchanges require a routing key
180
207
  */
181
- declare function defineBinding(queue: string, exchange: string, options?: Omit<QueueBindingDefinition, "type" | "queue" | "exchange">): QueueBindingDefinition;
208
+ declare function defineExchangeBinding(destination: ExchangeDefinition, source: DirectExchangeDefinition | TopicExchangeDefinition, options: Omit<Extract<ExchangeBindingDefinition, {
209
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
210
+ }>, "type" | "source" | "destination">): Extract<ExchangeBindingDefinition, {
211
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
212
+ }>;
182
213
  /**
183
- * Define a binding between exchange and exchange (source -> destination)
214
+ * Define a message publisher for fanout exchange
215
+ * Fanout exchanges don't use routing keys
184
216
  */
185
- declare function defineExchangeBinding(destination: string, source: string, options?: Omit<ExchangeBindingDefinition, "type" | "source" | "destination">): ExchangeBindingDefinition;
217
+ declare function definePublisher<TMessage extends MessageDefinition>(exchange: FanoutExchangeDefinition, message: TMessage, options?: Omit<Extract<PublisherDefinition<TMessage>, {
218
+ exchange: FanoutExchangeDefinition;
219
+ }>, "exchange" | "message" | "routingKey">): Extract<PublisherDefinition<TMessage>, {
220
+ exchange: FanoutExchangeDefinition;
221
+ }>;
186
222
  /**
187
- * Define a message publisher
223
+ * Define a message publisher for direct/topic exchange
224
+ * Direct and topic exchanges require a routing key
188
225
  */
189
- declare function definePublisher<TMessageSchema extends AnySchema>(exchange: string, message: TMessageSchema, options?: Omit<PublisherDefinition<TMessageSchema>, "exchange" | "message">): PublisherDefinition<TMessageSchema>;
226
+ declare function definePublisher<TMessage extends MessageDefinition>(exchange: DirectExchangeDefinition | TopicExchangeDefinition, message: TMessage, options: Omit<Extract<PublisherDefinition<TMessage>, {
227
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
228
+ }>, "exchange" | "message">): Extract<PublisherDefinition<TMessage>, {
229
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
230
+ }>;
190
231
  /**
191
232
  * Define a message consumer
192
233
  */
193
- declare function defineConsumer<TMessageSchema extends AnySchema, THandlerResultSchema extends AnySchema = AnySchema>(queue: string, message: TMessageSchema, options?: Omit<ConsumerDefinition<TMessageSchema, THandlerResultSchema>, "queue" | "message">): ConsumerDefinition<TMessageSchema, THandlerResultSchema>;
234
+ declare function defineConsumer<TMessage extends MessageDefinition>(queue: QueueDefinition, message: TMessage, options?: Omit<ConsumerDefinition<TMessage>, "queue" | "message">): ConsumerDefinition<TMessage>;
194
235
  /**
195
236
  * Define an AMQP contract
196
237
  */
197
- declare function defineContract<TContract extends ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>, TExchanges extends Record<string, ExchangeDefinition> = Record<string, ExchangeDefinition>, TQueues extends Record<string, QueueDefinition> = Record<string, QueueDefinition>, TBindings extends Record<string, BindingDefinition> = Record<string, BindingDefinition>, TPublishers extends Record<string, PublisherDefinition> = Record<string, PublisherDefinition>, TConsumers extends Record<string, ConsumerDefinition> = Record<string, ConsumerDefinition>>(definition: TContract): TContract;
238
+ declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
198
239
  //#endregion
199
- export { type AnySchema, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ConsumerHandler, type ConsumerInferHandlerResult, type ConsumerInferInput, type ContractDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type ExchangeType, type InferConsumer, type InferConsumerNames, type InferConsumers, type InferPublisher, type InferPublisherNames, type InferPublishers, type InferSchemaInput, type InferSchemaOutput, type MessageSchema, type PublisherDefinition, type PublisherInferInput, type QueueBindingDefinition, type QueueDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerResult, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineBinding, defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue };
240
+ export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ContractDefinition, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MessageDefinition, type PublisherDefinition, type QueueBindingDefinition, type QueueDefinition, type TopicExchangeDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue, defineQueueBinding };
200
241
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAKY,KALA,SAAA,GAAY,gBAKA;AAKxB;AAYA;AAWA;AAWiB,KAvCL,YAAA,GAuCK,QAAyB,GAAA,QAK5B,GAAA,OAAM,GAAA,SAAA;AAMpB;AAKA;;AAAwE,UAlDvD,kBAAA,CAkDuD;EAG7D,IAAA,EAAA,MAAA;EAAc,IAAA,EAnDjB,YAmDiB;EAMR,OAAA,CAAA,EAAA,OAAA;EACQ,UAAA,CAAA,EAAA,OAAA;EAA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H/D,QDvH+D,EAAA,OAAA,CAAA,ECwH9D,IDxH8D,CCwHzD,kBDxHyD,CCwHtC,QDxHsC,CAAA,EAAA,OAAA,GAAA,SAAA,CAAA,CAAA,ECyHvE,kBDzHuE,CCyHpD,QDzHoD,CAAA;AAK1E;;;AACkB,iBC8HF,cD9HE,CAAA,kBC8H+B,kBD9H/B,CAAA,CAAA,UAAA,EC+HJ,SD/HI,CAAA,ECgIf,SDhIe"}
package/dist/index.d.mts CHANGED
@@ -6,51 +6,70 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
6
6
  * Any schema that conforms to Standard Schema v1
7
7
  */
8
8
  type AnySchema = StandardSchemaV1;
9
- /**
10
- * Exchange types supported by AMQP
11
- */
12
- type ExchangeType = "direct" | "fanout" | "topic" | "headers";
13
9
  /**
14
10
  * Definition of an AMQP exchange
15
11
  */
16
- interface ExchangeDefinition {
12
+ type BaseExchangeDefinition = {
17
13
  name: string;
18
- type: ExchangeType;
19
14
  durable?: boolean;
20
15
  autoDelete?: boolean;
21
16
  internal?: boolean;
22
17
  arguments?: Record<string, unknown>;
23
- }
18
+ };
19
+ type FanoutExchangeDefinition = BaseExchangeDefinition & {
20
+ type: "fanout";
21
+ };
22
+ type DirectExchangeDefinition = BaseExchangeDefinition & {
23
+ type: "direct";
24
+ };
25
+ type TopicExchangeDefinition = BaseExchangeDefinition & {
26
+ type: "topic";
27
+ };
28
+ type ExchangeDefinition = FanoutExchangeDefinition | DirectExchangeDefinition | TopicExchangeDefinition;
24
29
  /**
25
30
  * Definition of an AMQP queue
26
31
  */
27
- interface QueueDefinition {
32
+ type QueueDefinition = {
28
33
  name: string;
29
34
  durable?: boolean;
30
35
  exclusive?: boolean;
31
36
  autoDelete?: boolean;
32
37
  arguments?: Record<string, unknown>;
33
- }
38
+ };
39
+ type MessageDefinition<TPayload extends AnySchema = AnySchema, THeaders extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined> = {
40
+ payload: TPayload;
41
+ headers?: THeaders;
42
+ summary?: string;
43
+ description?: string;
44
+ };
34
45
  /**
35
46
  * Binding between queue and exchange
36
47
  */
37
- interface QueueBindingDefinition {
48
+ type QueueBindingDefinition = {
38
49
  type: "queue";
39
- queue: string;
40
- exchange: string;
41
- routingKey?: string;
50
+ queue: QueueDefinition;
42
51
  arguments?: Record<string, unknown>;
43
- }
52
+ } & ({
53
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
54
+ routingKey: string;
55
+ } | {
56
+ exchange: FanoutExchangeDefinition;
57
+ routingKey?: never;
58
+ });
44
59
  /**
45
60
  * Binding between exchange and exchange
46
61
  */
47
- interface ExchangeBindingDefinition {
62
+ type ExchangeBindingDefinition = {
48
63
  type: "exchange";
49
- source: string;
50
- destination: string;
51
- routingKey?: string;
64
+ destination: ExchangeDefinition;
52
65
  arguments?: Record<string, unknown>;
53
- }
66
+ } & ({
67
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
68
+ routingKey: string;
69
+ } | {
70
+ source: FanoutExchangeDefinition;
71
+ routingKey?: never;
72
+ });
54
73
  /**
55
74
  * Binding definition - can be either queue-to-exchange or exchange-to-exchange
56
75
  */
@@ -58,143 +77,165 @@ type BindingDefinition = QueueBindingDefinition | ExchangeBindingDefinition;
58
77
  /**
59
78
  * Definition of a message publisher
60
79
  */
61
- interface PublisherDefinition<TMessageSchema extends AnySchema = AnySchema> {
62
- exchange: string;
63
- routingKey?: string;
64
- message: TMessageSchema;
65
- }
80
+ type PublisherDefinition<TMessage extends MessageDefinition = MessageDefinition> = {
81
+ message: TMessage;
82
+ } & ({
83
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
84
+ routingKey: string;
85
+ } | {
86
+ exchange: FanoutExchangeDefinition;
87
+ routingKey?: never;
88
+ });
66
89
  /**
67
90
  * Definition of a message consumer
68
91
  */
69
- interface ConsumerDefinition<TMessageSchema extends AnySchema = AnySchema, THandlerResultSchema extends AnySchema = AnySchema> {
70
- queue: string;
71
- message: TMessageSchema;
72
- handlerResult?: THandlerResultSchema;
92
+ type ConsumerDefinition<TMessage extends MessageDefinition = MessageDefinition> = {
93
+ queue: QueueDefinition;
94
+ message: TMessage;
73
95
  prefetch?: number;
74
96
  noAck?: boolean;
75
- }
97
+ };
76
98
  /**
77
99
  * Contract definition containing all AMQP resources
78
100
  */
79
- interface ContractDefinition<TExchanges extends Record<string, ExchangeDefinition> = Record<string, ExchangeDefinition>, TQueues extends Record<string, QueueDefinition> = Record<string, QueueDefinition>, TBindings extends Record<string, BindingDefinition> = Record<string, BindingDefinition>, TPublishers extends Record<string, PublisherDefinition> = Record<string, PublisherDefinition>, TConsumers extends Record<string, ConsumerDefinition> = Record<string, ConsumerDefinition>> {
80
- exchanges?: TExchanges;
81
- queues?: TQueues;
82
- bindings?: TBindings;
83
- publishers?: TPublishers;
84
- consumers?: TConsumers;
85
- }
101
+ type ContractDefinition = {
102
+ exchanges?: Record<string, ExchangeDefinition>;
103
+ queues?: Record<string, QueueDefinition>;
104
+ bindings?: Record<string, BindingDefinition>;
105
+ publishers?: Record<string, PublisherDefinition>;
106
+ consumers?: Record<string, ConsumerDefinition>;
107
+ };
86
108
  /**
87
- * Infer the TypeScript type from a schema
109
+ * Infer publisher names from a contract
88
110
  */
89
- type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
111
+ type InferPublisherNames<TContract extends ContractDefinition> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
90
112
  /**
91
- * Infer the output type from a schema
113
+ * Infer consumer names from a contract
92
114
  */
93
- type InferSchemaOutput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<unknown, infer TOutput> ? TOutput : never;
115
+ type InferConsumerNames<TContract extends ContractDefinition> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
94
116
  /**
95
- * Infer publisher message input type
96
- */
97
- type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher["message"]>;
98
- /**
99
- * Infer consumer message input type
100
- */
101
- type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer["message"]>;
102
- /**
103
- * Infer consumer handler result type
117
+ * Infer the TypeScript type from a schema
104
118
  */
105
- type ConsumerInferHandlerResult<TConsumer extends ConsumerDefinition> = TConsumer["handlerResult"] extends AnySchema ? InferSchemaOutput<TConsumer["handlerResult"]> : void;
119
+ type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
106
120
  /**
107
- * Consumer handler function type
108
- * Handlers return Promise for async handling
109
- * where HandlerResult is inferred from the consumer's handlerResult schema (defaults to void)
121
+ * Infer publisher message input type
110
122
  */
111
- type ConsumerHandler<TConsumer extends ConsumerDefinition> = (message: ConsumerInferInput<TConsumer>) => Promise<ConsumerInferHandlerResult<TConsumer>>;
123
+ type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher["message"]["payload"]>;
112
124
  /**
113
125
  * Infer all publishers from contract
114
126
  */
115
127
  type InferPublishers<TContract extends ContractDefinition> = NonNullable<TContract["publishers"]>;
116
128
  /**
117
- * Infer all consumers from contract
118
- */
119
- type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
120
- /**
121
- * Infer publisher names from contract
129
+ * Get specific publisher definition from contract
122
130
  */
123
- type InferPublisherNames<TContract extends ContractDefinition> = keyof InferPublishers<TContract>;
131
+ type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
124
132
  /**
125
- * Infer consumer names from contract
133
+ * Infer publisher input type (message payload) for a specific publisher in a contract
126
134
  */
127
- type InferConsumerNames<TContract extends ContractDefinition> = keyof InferConsumers<TContract>;
135
+ type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
128
136
  /**
129
- * Get specific publisher definition from contract
137
+ * Infer all consumers from contract
130
138
  */
131
- type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
139
+ type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
132
140
  /**
133
141
  * Get specific consumer definition from contract
134
142
  */
135
143
  type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
136
144
  /**
137
- * Client perspective types - for publishing messages
145
+ * Infer consumer message input type
138
146
  */
139
- type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
147
+ type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer["message"]["payload"]>;
140
148
  /**
141
149
  * Worker perspective types - for consuming messages
142
150
  */
143
151
  type WorkerInferConsumerInput<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferInput<InferConsumer<TContract, TName>>;
144
152
  /**
145
- * Worker perspective - consumer handler result type
153
+ * Infer consumer handler type for a specific consumer
146
154
  */
147
- type WorkerInferConsumerHandlerResult<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHandlerResult<InferConsumer<TContract, TName>>;
155
+ type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumerInput<TContract, TName>) => Promise<void> | void;
148
156
  /**
149
- * Worker perspective - consumer handler type
150
- */
151
- type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerHandler<InferConsumer<TContract, TName>>;
152
- /**
153
- * Map of all consumer handlers for a contract
157
+ * Infer all consumer handlers for a contract
154
158
  */
155
159
  type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandler<TContract, K> };
156
160
  //#endregion
157
161
  //#region src/builder.d.ts
162
+ declare function defineExchange(name: string, type: "fanout", options?: Omit<BaseExchangeDefinition, "name" | "type">): FanoutExchangeDefinition;
163
+ declare function defineExchange(name: string, type: "direct", options?: Omit<BaseExchangeDefinition, "name" | "type">): DirectExchangeDefinition;
164
+ declare function defineExchange(name: string, type: "topic", options?: Omit<BaseExchangeDefinition, "name" | "type">): TopicExchangeDefinition;
165
+ /**
166
+ * Define an AMQP queue
167
+ */
168
+ declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">): QueueDefinition;
158
169
  /**
159
- * Message schema with metadata
170
+ * Define a message definition with payload and optional headers/metadata
160
171
  */
161
- interface MessageSchema<TSchema extends AnySchema = AnySchema> extends AnySchema {
162
- readonly name: string;
163
- readonly schema: TSchema;
164
- readonly "~standard": TSchema["~standard"];
165
- }
172
+ declare function defineMessage<TPayload extends MessageDefinition["payload"], THeaders extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined>(payload: TPayload, options?: {
173
+ headers?: THeaders;
174
+ summary?: string;
175
+ description?: string;
176
+ }): MessageDefinition<TPayload, THeaders>;
166
177
  /**
167
- * Define a message schema with metadata
178
+ * Define a binding between queue and fanout exchange (exchange -> queue)
179
+ * Fanout exchanges don't use routing keys
168
180
  */
169
- declare function defineMessage<TSchema extends AnySchema>(name: string, schema: TSchema): MessageSchema<TSchema>;
181
+ declare function defineQueueBinding(queue: QueueDefinition, exchange: FanoutExchangeDefinition, options?: Omit<Extract<QueueBindingDefinition, {
182
+ exchange: FanoutExchangeDefinition;
183
+ }>, "type" | "queue" | "exchange" | "routingKey">): Extract<QueueBindingDefinition, {
184
+ exchange: FanoutExchangeDefinition;
185
+ }>;
170
186
  /**
171
- * Define an AMQP exchange
187
+ * Define a binding between queue and direct/topic exchange (exchange -> queue)
188
+ * Direct and topic exchanges require a routing key
172
189
  */
173
- declare function defineExchange(name: string, type: ExchangeType, options?: Omit<ExchangeDefinition, "name" | "type">): ExchangeDefinition;
190
+ declare function defineQueueBinding(queue: QueueDefinition, exchange: DirectExchangeDefinition | TopicExchangeDefinition, options: Omit<Extract<QueueBindingDefinition, {
191
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
192
+ }>, "type" | "queue" | "exchange">): Extract<QueueBindingDefinition, {
193
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
194
+ }>;
174
195
  /**
175
- * Define an AMQP queue
196
+ * Define a binding between fanout exchange and exchange (source -> destination)
197
+ * Fanout exchanges don't use routing keys
176
198
  */
177
- declare function defineQueue(name: string, options?: Omit<QueueDefinition, "name">): QueueDefinition;
199
+ declare function defineExchangeBinding(destination: ExchangeDefinition, source: FanoutExchangeDefinition, options?: Omit<Extract<ExchangeBindingDefinition, {
200
+ source: FanoutExchangeDefinition;
201
+ }>, "type" | "source" | "destination" | "routingKey">): Extract<ExchangeBindingDefinition, {
202
+ source: FanoutExchangeDefinition;
203
+ }>;
178
204
  /**
179
- * Define a binding between queue and exchange
205
+ * Define a binding between direct/topic exchange and exchange (source -> destination)
206
+ * Direct and topic exchanges require a routing key
180
207
  */
181
- declare function defineBinding(queue: string, exchange: string, options?: Omit<QueueBindingDefinition, "type" | "queue" | "exchange">): QueueBindingDefinition;
208
+ declare function defineExchangeBinding(destination: ExchangeDefinition, source: DirectExchangeDefinition | TopicExchangeDefinition, options: Omit<Extract<ExchangeBindingDefinition, {
209
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
210
+ }>, "type" | "source" | "destination">): Extract<ExchangeBindingDefinition, {
211
+ source: DirectExchangeDefinition | TopicExchangeDefinition;
212
+ }>;
182
213
  /**
183
- * Define a binding between exchange and exchange (source -> destination)
214
+ * Define a message publisher for fanout exchange
215
+ * Fanout exchanges don't use routing keys
184
216
  */
185
- declare function defineExchangeBinding(destination: string, source: string, options?: Omit<ExchangeBindingDefinition, "type" | "source" | "destination">): ExchangeBindingDefinition;
217
+ declare function definePublisher<TMessage extends MessageDefinition>(exchange: FanoutExchangeDefinition, message: TMessage, options?: Omit<Extract<PublisherDefinition<TMessage>, {
218
+ exchange: FanoutExchangeDefinition;
219
+ }>, "exchange" | "message" | "routingKey">): Extract<PublisherDefinition<TMessage>, {
220
+ exchange: FanoutExchangeDefinition;
221
+ }>;
186
222
  /**
187
- * Define a message publisher
223
+ * Define a message publisher for direct/topic exchange
224
+ * Direct and topic exchanges require a routing key
188
225
  */
189
- declare function definePublisher<TMessageSchema extends AnySchema>(exchange: string, message: TMessageSchema, options?: Omit<PublisherDefinition<TMessageSchema>, "exchange" | "message">): PublisherDefinition<TMessageSchema>;
226
+ declare function definePublisher<TMessage extends MessageDefinition>(exchange: DirectExchangeDefinition | TopicExchangeDefinition, message: TMessage, options: Omit<Extract<PublisherDefinition<TMessage>, {
227
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
228
+ }>, "exchange" | "message">): Extract<PublisherDefinition<TMessage>, {
229
+ exchange: DirectExchangeDefinition | TopicExchangeDefinition;
230
+ }>;
190
231
  /**
191
232
  * Define a message consumer
192
233
  */
193
- declare function defineConsumer<TMessageSchema extends AnySchema, THandlerResultSchema extends AnySchema = AnySchema>(queue: string, message: TMessageSchema, options?: Omit<ConsumerDefinition<TMessageSchema, THandlerResultSchema>, "queue" | "message">): ConsumerDefinition<TMessageSchema, THandlerResultSchema>;
234
+ declare function defineConsumer<TMessage extends MessageDefinition>(queue: QueueDefinition, message: TMessage, options?: Omit<ConsumerDefinition<TMessage>, "queue" | "message">): ConsumerDefinition<TMessage>;
194
235
  /**
195
236
  * Define an AMQP contract
196
237
  */
197
- declare function defineContract<TContract extends ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>, TExchanges extends Record<string, ExchangeDefinition> = Record<string, ExchangeDefinition>, TQueues extends Record<string, QueueDefinition> = Record<string, QueueDefinition>, TBindings extends Record<string, BindingDefinition> = Record<string, BindingDefinition>, TPublishers extends Record<string, PublisherDefinition> = Record<string, PublisherDefinition>, TConsumers extends Record<string, ConsumerDefinition> = Record<string, ConsumerDefinition>>(definition: TContract): TContract;
238
+ declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
198
239
  //#endregion
199
- export { type AnySchema, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ConsumerHandler, type ConsumerInferHandlerResult, type ConsumerInferInput, type ContractDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type ExchangeType, type InferConsumer, type InferConsumerNames, type InferConsumers, type InferPublisher, type InferPublisherNames, type InferPublishers, type InferSchemaInput, type InferSchemaOutput, type MessageSchema, type PublisherDefinition, type PublisherInferInput, type QueueBindingDefinition, type QueueDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerResult, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineBinding, defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue };
240
+ export { type AnySchema, type BaseExchangeDefinition, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ContractDefinition, type DirectExchangeDefinition, type ExchangeBindingDefinition, type ExchangeDefinition, type FanoutExchangeDefinition, type InferConsumerNames, type InferPublisherNames, type MessageDefinition, type PublisherDefinition, type QueueBindingDefinition, type QueueDefinition, type TopicExchangeDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue, defineQueueBinding };
200
241
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAKY,KALA,SAAA,GAAY,gBAKA;AAKxB;AAYA;AAWA;AAWiB,KAvCL,YAAA,GAuCK,QAAyB,GAAA,QAK5B,GAAA,OAAM,GAAA,SAAA;AAMpB;AAKA;;AAAwE,UAlDvD,kBAAA,CAkDuD;EAG7D,IAAA,EAAA,MAAA;EAAc,IAAA,EAnDjB,YAmDiB;EAMR,OAAA,CAAA,EAAA,OAAA;EACQ,UAAA,CAAA,EAAA,OAAA;EAAY,QAAA,CAAA,EAAA,OAAA;EACN,SAAA,CAAA,EAvDjB,MAu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,kBDxHyD,CCwHtC,QDxHsC,CAAA,EAAA,OAAA,GAAA,SAAA,CAAA,CAAA,ECyHvE,kBDzHuE,CCyHpD,QDzHoD,CAAA;AAK1E;;;AACkB,iBC8HF,cD9HE,CAAA,kBC8H+B,kBD9H/B,CAAA,CAAA,UAAA,EC+HJ,SD/HI,CAAA,ECgIf,SDhIe"}
package/dist/index.mjs CHANGED
@@ -1,15 +1,5 @@
1
1
  //#region src/builder.ts
2
2
  /**
3
- * Define a message schema with metadata
4
- */
5
- function defineMessage(name, schema) {
6
- return {
7
- name,
8
- schema,
9
- "~standard": schema["~standard"]
10
- };
11
- }
12
- /**
13
3
  * Define an AMQP exchange
14
4
  */
15
5
  function defineExchange(name, type, options) {
@@ -29,35 +19,62 @@ function defineQueue(name, options) {
29
19
  };
30
20
  }
31
21
  /**
32
- * Define a binding between queue and exchange
22
+ * Define a message definition with payload and optional headers/metadata
33
23
  */
34
- function defineBinding(queue, exchange, options) {
24
+ function defineMessage(payload, options) {
35
25
  return {
26
+ payload,
27
+ ...options
28
+ };
29
+ }
30
+ /**
31
+ * Define a binding between queue and exchange (exchange -> queue)
32
+ */
33
+ function defineQueueBinding(queue, exchange, options) {
34
+ if (exchange.type === "fanout") return {
36
35
  type: "queue",
37
36
  queue,
38
37
  exchange,
39
- ...options
38
+ ...options?.arguments && { arguments: options.arguments }
39
+ };
40
+ return {
41
+ type: "queue",
42
+ queue,
43
+ exchange,
44
+ routingKey: options?.routingKey,
45
+ ...options?.arguments && { arguments: options.arguments }
40
46
  };
41
47
  }
42
48
  /**
43
49
  * Define a binding between exchange and exchange (source -> destination)
44
50
  */
45
51
  function defineExchangeBinding(destination, source, options) {
52
+ if (source.type === "fanout") return {
53
+ type: "exchange",
54
+ source,
55
+ destination,
56
+ ...options?.arguments && { arguments: options.arguments }
57
+ };
46
58
  return {
47
59
  type: "exchange",
48
60
  source,
49
61
  destination,
50
- ...options
62
+ routingKey: options?.routingKey ?? "",
63
+ ...options?.arguments && { arguments: options.arguments }
51
64
  };
52
65
  }
53
66
  /**
54
67
  * Define a message publisher
55
68
  */
56
69
  function definePublisher(exchange, message, options) {
70
+ if (exchange.type === "fanout") return {
71
+ exchange,
72
+ message
73
+ };
57
74
  return {
58
75
  exchange,
59
76
  message,
60
- ...options
77
+ routingKey: options?.routingKey ?? ""
61
78
  };
62
79
  }
63
80
  /**
@@ -78,5 +95,5 @@ function defineContract(definition) {
78
95
  }
79
96
 
80
97
  //#endregion
81
- export { defineBinding, defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue };
98
+ export { defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue, defineQueueBinding };
82
99
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import type {\n AnySchema,\n BindingDefinition,\n QueueBindingDefinition,\n ExchangeBindingDefinition,\n ConsumerDefinition,\n ContractDefinition,\n ExchangeDefinition,\n ExchangeType,\n PublisherDefinition,\n QueueDefinition,\n} from \"./types.js\";\n\n/**\n * Message schema with metadata\n */\nexport interface MessageSchema<TSchema extends AnySchema = AnySchema> extends AnySchema {\n readonly name: string;\n readonly schema: TSchema;\n readonly \"~standard\": TSchema[\"~standard\"];\n}\n\n/**\n * Define a message schema with metadata\n */\nexport function defineMessage<TSchema extends AnySchema>(\n name: string,\n schema: TSchema,\n): MessageSchema<TSchema> {\n return {\n name,\n schema,\n \"~standard\": schema[\"~standard\"],\n };\n}\n\n/**\n * Define an AMQP exchange\n */\nexport function defineExchange(\n name: string,\n type: ExchangeType,\n options?: Omit<ExchangeDefinition, \"name\" | \"type\">,\n): ExchangeDefinition {\n return {\n name,\n type,\n ...options,\n };\n}\n\n/**\n * Define an AMQP queue\n */\nexport function defineQueue(\n name: string,\n options?: Omit<QueueDefinition, \"name\">,\n): QueueDefinition {\n return {\n name,\n ...options,\n };\n}\n\n/**\n * Define a binding between queue and exchange\n */\nexport function defineBinding(\n queue: string,\n exchange: string,\n options?: Omit<QueueBindingDefinition, \"type\" | \"queue\" | \"exchange\">,\n): QueueBindingDefinition {\n return {\n type: \"queue\",\n queue,\n exchange,\n ...options,\n };\n}\n\n/**\n * Define a binding between exchange and exchange (source -> destination)\n */\nexport function defineExchangeBinding(\n destination: string,\n source: string,\n options?: Omit<ExchangeBindingDefinition, \"type\" | \"source\" | \"destination\">,\n): ExchangeBindingDefinition {\n return {\n type: \"exchange\",\n source,\n destination,\n ...options,\n };\n}\n\n/**\n * Define a message publisher\n */\nexport function definePublisher<TMessageSchema extends AnySchema>(\n exchange: string,\n message: TMessageSchema,\n options?: Omit<PublisherDefinition<TMessageSchema>, \"exchange\" | \"message\">,\n): PublisherDefinition<TMessageSchema> {\n return {\n exchange,\n message,\n ...options,\n };\n}\n\n/**\n * Define a message consumer\n */\nexport function defineConsumer<\n TMessageSchema extends AnySchema,\n THandlerResultSchema extends AnySchema = AnySchema,\n>(\n queue: string,\n message: TMessageSchema,\n options?: Omit<ConsumerDefinition<TMessageSchema, THandlerResultSchema>, \"queue\" | \"message\">,\n): ConsumerDefinition<TMessageSchema, THandlerResultSchema> {\n return {\n queue,\n message,\n ...options,\n };\n}\n\n/**\n * Define an AMQP contract\n */\nexport function defineContract<\n TContract extends ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>,\n TExchanges extends Record<string, ExchangeDefinition> = Record<string, ExchangeDefinition>,\n TQueues extends Record<string, QueueDefinition> = Record<string, QueueDefinition>,\n TBindings extends Record<string, BindingDefinition> = Record<string, BindingDefinition>,\n TPublishers extends Record<string, PublisherDefinition> = Record<string, PublisherDefinition>,\n TConsumers extends Record<string, ConsumerDefinition> = Record<string, ConsumerDefinition>,\n>(definition: TContract): TContract {\n return definition;\n}\n"],"mappings":";;;;AAyBA,SAAgB,cACd,MACA,QACwB;AACxB,QAAO;EACL;EACA;EACA,aAAa,OAAO;EACrB;;;;;AAMH,SAAgB,eACd,MACA,MACA,SACoB;AACpB,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,YACd,MACA,SACiB;AACjB,QAAO;EACL;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,cACd,OACA,UACA,SACwB;AACxB,QAAO;EACL,MAAM;EACN;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,sBACd,aACA,QACA,SAC2B;AAC3B,QAAO;EACL,MAAM;EACN;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,gBACd,UACA,SACA,SACqC;AACrC,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,eAId,OACA,SACA,SAC0D;AAC1D,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,eAOd,YAAkC;AAClC,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type {\n QueueBindingDefinition,\n ExchangeBindingDefinition,\n ConsumerDefinition,\n ContractDefinition,\n ExchangeDefinition,\n PublisherDefinition,\n QueueDefinition,\n MessageDefinition,\n FanoutExchangeDefinition,\n TopicExchangeDefinition,\n DirectExchangeDefinition,\n BaseExchangeDefinition,\n} from \"./types.js\";\n\nexport function defineExchange(\n name: string,\n type: \"fanout\",\n options?: Omit<BaseExchangeDefinition, \"name\" | \"type\">,\n): FanoutExchangeDefinition;\n\nexport function defineExchange(\n name: string,\n type: \"direct\",\n options?: Omit<BaseExchangeDefinition, \"name\" | \"type\">,\n): DirectExchangeDefinition;\n\nexport function defineExchange(\n name: string,\n type: \"topic\",\n options?: Omit<BaseExchangeDefinition, \"name\" | \"type\">,\n): TopicExchangeDefinition;\n\n/**\n * Define an AMQP exchange\n */\nexport function defineExchange(\n name: string,\n type: \"fanout\" | \"direct\" | \"topic\",\n options?: Omit<BaseExchangeDefinition, \"name\" | \"type\">,\n): ExchangeDefinition {\n return {\n name,\n type,\n ...options,\n };\n}\n\n/**\n * Define an AMQP queue\n */\nexport function defineQueue(\n name: string,\n options?: Omit<QueueDefinition, \"name\">,\n): QueueDefinition {\n return {\n name,\n ...options,\n };\n}\n\n/**\n * Define a message definition with payload and optional headers/metadata\n */\nexport function defineMessage<\n TPayload extends MessageDefinition[\"payload\"],\n THeaders extends StandardSchemaV1<Record<string, unknown>> | undefined = undefined,\n>(\n payload: TPayload,\n options?: {\n headers?: THeaders;\n summary?: string;\n description?: string;\n },\n): MessageDefinition<TPayload, THeaders> {\n return {\n payload,\n ...options,\n };\n}\n\n/**\n * Define a binding between queue and fanout exchange (exchange -> queue)\n * Fanout exchanges don't use routing keys\n */\nexport function defineQueueBinding(\n queue: QueueDefinition,\n exchange: FanoutExchangeDefinition,\n options?: Omit<\n Extract<QueueBindingDefinition, { exchange: FanoutExchangeDefinition }>,\n \"type\" | \"queue\" | \"exchange\" | \"routingKey\"\n >,\n): Extract<QueueBindingDefinition, { exchange: FanoutExchangeDefinition }>;\n\n/**\n * Define a binding between queue and direct/topic exchange (exchange -> queue)\n * Direct and topic exchanges require a routing key\n */\nexport function defineQueueBinding(\n queue: QueueDefinition,\n exchange: DirectExchangeDefinition | TopicExchangeDefinition,\n options: Omit<\n Extract<\n QueueBindingDefinition,\n { exchange: DirectExchangeDefinition | TopicExchangeDefinition }\n >,\n \"type\" | \"queue\" | \"exchange\"\n >,\n): Extract<\n QueueBindingDefinition,\n { exchange: DirectExchangeDefinition | TopicExchangeDefinition }\n>;\n\n/**\n * Define a binding between queue and exchange (exchange -> queue)\n */\nexport function defineQueueBinding(\n queue: QueueDefinition,\n exchange: ExchangeDefinition,\n options?: {\n routingKey?: string;\n arguments?: Record<string, unknown>;\n },\n): QueueBindingDefinition {\n if (exchange.type === \"fanout\") {\n return {\n type: \"queue\",\n queue,\n exchange,\n ...(options?.arguments && { arguments: options.arguments }),\n } as QueueBindingDefinition;\n }\n\n return {\n type: \"queue\",\n queue,\n exchange,\n routingKey: options?.routingKey,\n ...(options?.arguments && { arguments: options.arguments }),\n } as QueueBindingDefinition;\n}\n\n/**\n * Define a binding between fanout exchange and exchange (source -> destination)\n * Fanout exchanges don't use routing keys\n */\nexport function defineExchangeBinding(\n destination: ExchangeDefinition,\n source: FanoutExchangeDefinition,\n options?: Omit<\n Extract<ExchangeBindingDefinition, { source: FanoutExchangeDefinition }>,\n \"type\" | \"source\" | \"destination\" | \"routingKey\"\n >,\n): Extract<ExchangeBindingDefinition, { source: FanoutExchangeDefinition }>;\n\n/**\n * Define a binding between direct/topic exchange and exchange (source -> destination)\n * Direct and topic exchanges require a routing key\n */\nexport function defineExchangeBinding(\n destination: ExchangeDefinition,\n source: DirectExchangeDefinition | TopicExchangeDefinition,\n options: Omit<\n Extract<\n ExchangeBindingDefinition,\n { source: DirectExchangeDefinition | TopicExchangeDefinition }\n >,\n \"type\" | \"source\" | \"destination\"\n >,\n): Extract<\n ExchangeBindingDefinition,\n { source: DirectExchangeDefinition | TopicExchangeDefinition }\n>;\n\n/**\n * Define a binding between exchange and exchange (source -> destination)\n */\nexport function defineExchangeBinding(\n destination: ExchangeDefinition,\n source: ExchangeDefinition,\n options?: {\n routingKey?: string;\n arguments?: Record<string, unknown>;\n },\n): ExchangeBindingDefinition {\n if (source.type === \"fanout\") {\n return {\n type: \"exchange\",\n source,\n destination,\n ...(options?.arguments && { arguments: options.arguments }),\n } as ExchangeBindingDefinition;\n }\n\n return {\n type: \"exchange\",\n source,\n destination,\n routingKey: options?.routingKey ?? \"\",\n ...(options?.arguments && { arguments: options.arguments }),\n } as ExchangeBindingDefinition;\n}\n\n/**\n * Define a message publisher for fanout exchange\n * Fanout exchanges don't use routing keys\n */\nexport function definePublisher<TMessage extends MessageDefinition>(\n exchange: FanoutExchangeDefinition,\n message: TMessage,\n options?: Omit<\n Extract<PublisherDefinition<TMessage>, { exchange: FanoutExchangeDefinition }>,\n \"exchange\" | \"message\" | \"routingKey\"\n >,\n): Extract<PublisherDefinition<TMessage>, { exchange: FanoutExchangeDefinition }>;\n\n/**\n * Define a message publisher for direct/topic exchange\n * Direct and topic exchanges require a routing key\n */\nexport function definePublisher<TMessage extends MessageDefinition>(\n exchange: DirectExchangeDefinition | TopicExchangeDefinition,\n message: TMessage,\n options: Omit<\n Extract<\n PublisherDefinition<TMessage>,\n { exchange: DirectExchangeDefinition | TopicExchangeDefinition }\n >,\n \"exchange\" | \"message\"\n >,\n): Extract<\n PublisherDefinition<TMessage>,\n { exchange: DirectExchangeDefinition | TopicExchangeDefinition }\n>;\n\n/**\n * Define a message publisher\n */\nexport function definePublisher<TMessage extends MessageDefinition>(\n exchange: ExchangeDefinition,\n message: TMessage,\n options?: { routingKey?: string },\n): PublisherDefinition<TMessage> {\n if (exchange.type === \"fanout\") {\n return {\n exchange,\n message,\n } as PublisherDefinition<TMessage>;\n }\n\n return {\n exchange,\n message,\n routingKey: options?.routingKey ?? \"\",\n } as PublisherDefinition<TMessage>;\n}\n\n/**\n * Define a message consumer\n */\nexport function defineConsumer<TMessage extends MessageDefinition>(\n queue: QueueDefinition,\n message: TMessage,\n options?: Omit<ConsumerDefinition<TMessage>, \"queue\" | \"message\">,\n): ConsumerDefinition<TMessage> {\n return {\n queue,\n message,\n ...options,\n };\n}\n\n/**\n * Define an AMQP contract\n */\nexport function defineContract<TContract extends ContractDefinition>(\n definition: TContract,\n): TContract {\n return definition;\n}\n"],"mappings":";;;;AAqCA,SAAgB,eACd,MACA,MACA,SACoB;AACpB,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,YACd,MACA,SACiB;AACjB,QAAO;EACL;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,cAId,SACA,SAKuC;AACvC,QAAO;EACL;EACA,GAAG;EACJ;;;;;AAsCH,SAAgB,mBACd,OACA,UACA,SAIwB;AACxB,KAAI,SAAS,SAAS,SACpB,QAAO;EACL,MAAM;EACN;EACA;EACA,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC3D;AAGH,QAAO;EACL,MAAM;EACN;EACA;EACA,YAAY,SAAS;EACrB,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC3D;;;;;AAsCH,SAAgB,sBACd,aACA,QACA,SAI2B;AAC3B,KAAI,OAAO,SAAS,SAClB,QAAO;EACL,MAAM;EACN;EACA;EACA,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC3D;AAGH,QAAO;EACL,MAAM;EACN;EACA;EACA,YAAY,SAAS,cAAc;EACnC,GAAI,SAAS,aAAa,EAAE,WAAW,QAAQ,WAAW;EAC3D;;;;;AAsCH,SAAgB,gBACd,UACA,SACA,SAC+B;AAC/B,KAAI,SAAS,SAAS,SACpB,QAAO;EACL;EACA;EACD;AAGH,QAAO;EACL;EACA;EACA,YAAY,SAAS,cAAc;EACpC;;;;;AAMH,SAAgB,eACd,OACA,SACA,SAC8B;AAC9B,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,eACd,YACW;AACX,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amqp-contract/contract",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Contract builder for amqp-contract",
5
5
  "keywords": [
6
6
  "amqp",