@amqp-contract/contract 0.1.4 → 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 +79 -29
- package/dist/index.cjs +34 -17
- package/dist/index.d.cts +135 -94
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +135 -94
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +33 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,
|
|
16
|
+
import { defineContract, defineExchange, defineQueue, defineQueueBinding, defineExchangeBinding, definePublisher, defineConsumer, defineMessage } from '@amqp-contract/contract';
|
|
17
17
|
import { z } from 'zod';
|
|
18
18
|
|
|
19
|
-
// Define
|
|
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:
|
|
23
|
-
analytics:
|
|
40
|
+
orders: ordersExchange,
|
|
41
|
+
analytics: analyticsExchange,
|
|
24
42
|
},
|
|
25
43
|
queues: {
|
|
26
|
-
orderProcessing:
|
|
27
|
-
analyticsProcessing:
|
|
44
|
+
orderProcessing: orderProcessingQueue,
|
|
45
|
+
analyticsProcessing: analyticsProcessingQueue,
|
|
28
46
|
},
|
|
29
47
|
bindings: {
|
|
30
48
|
// Queue-to-exchange binding
|
|
31
|
-
orderBinding:
|
|
49
|
+
orderBinding: defineQueueBinding(orderProcessingQueue, ordersExchange, {
|
|
32
50
|
routingKey: 'order.created',
|
|
33
51
|
}),
|
|
34
52
|
// Exchange-to-exchange binding
|
|
35
|
-
analyticsBinding: defineExchangeBinding(
|
|
53
|
+
analyticsBinding: defineExchangeBinding(analyticsExchange, ordersExchange, {
|
|
36
54
|
routingKey: 'order.#',
|
|
37
55
|
}),
|
|
38
56
|
// Queue receives from analytics exchange
|
|
39
|
-
analyticsQueueBinding:
|
|
57
|
+
analyticsQueueBinding: defineQueueBinding(analyticsProcessingQueue, analyticsExchange, {
|
|
40
58
|
routingKey: 'order.#',
|
|
41
59
|
}),
|
|
42
60
|
},
|
|
43
61
|
publishers: {
|
|
44
|
-
orderCreated: definePublisher(
|
|
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(
|
|
53
|
-
orderId: z.string(),
|
|
54
|
-
amount: z.number(),
|
|
55
|
-
}), {
|
|
67
|
+
processOrder: defineConsumer(orderProcessingQueue, orderMessage, {
|
|
56
68
|
prefetch: 10,
|
|
57
69
|
}),
|
|
58
|
-
processAnalytics: defineConsumer(
|
|
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
|
-
|
|
94
|
+
Define a binding between a queue and an exchange. Pass the queue and exchange objects (not strings).
|
|
77
95
|
|
|
78
|
-
|
|
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
|
-
|
|
103
|
+
Pass the exchange objects (not strings).
|
|
85
104
|
|
|
86
|
-
|
|
105
|
+
### `definePublisher(exchange, message, options?)`
|
|
87
106
|
|
|
88
|
-
|
|
107
|
+
Define a message publisher with validation schema. Pass the exchange object (not a string).
|
|
89
108
|
|
|
90
|
-
|
|
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
|
|
23
|
+
* Define a message definition with payload and optional headers/metadata
|
|
34
24
|
*/
|
|
35
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
+
type QueueBindingDefinition = {
|
|
38
49
|
type: "queue";
|
|
39
|
-
queue:
|
|
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
|
-
|
|
62
|
+
type ExchangeBindingDefinition = {
|
|
48
63
|
type: "exchange";
|
|
49
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
70
|
-
queue:
|
|
71
|
-
message:
|
|
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
|
-
|
|
80
|
-
exchanges?:
|
|
81
|
-
queues?:
|
|
82
|
-
bindings?:
|
|
83
|
-
publishers?:
|
|
84
|
-
consumers?:
|
|
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
|
|
109
|
+
* Infer publisher names from a contract
|
|
88
110
|
*/
|
|
89
|
-
type
|
|
111
|
+
type InferPublisherNames<TContract extends ContractDefinition> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
|
|
90
112
|
/**
|
|
91
|
-
* Infer
|
|
113
|
+
* Infer consumer names from a contract
|
|
92
114
|
*/
|
|
93
|
-
type
|
|
115
|
+
type InferConsumerNames<TContract extends ContractDefinition> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
|
|
94
116
|
/**
|
|
95
|
-
* Infer
|
|
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
|
|
119
|
+
type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
|
|
106
120
|
/**
|
|
107
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
131
|
+
type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
|
|
124
132
|
/**
|
|
125
|
-
* Infer
|
|
133
|
+
* Infer publisher input type (message payload) for a specific publisher in a contract
|
|
126
134
|
*/
|
|
127
|
-
type
|
|
135
|
+
type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
128
136
|
/**
|
|
129
|
-
*
|
|
137
|
+
* Infer all consumers from contract
|
|
130
138
|
*/
|
|
131
|
-
type
|
|
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
|
-
*
|
|
145
|
+
* Infer consumer message input type
|
|
138
146
|
*/
|
|
139
|
-
type
|
|
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
|
-
*
|
|
153
|
+
* Infer consumer handler type for a specific consumer
|
|
146
154
|
*/
|
|
147
|
-
type
|
|
155
|
+
type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumerInput<TContract, TName>) => Promise<void> | void;
|
|
148
156
|
/**
|
|
149
|
-
*
|
|
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
|
-
*
|
|
170
|
+
* Define a message definition with payload and optional headers/metadata
|
|
160
171
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
178
|
+
* Define a binding between queue and fanout exchange (exchange -> queue)
|
|
179
|
+
* Fanout exchanges don't use routing keys
|
|
168
180
|
*/
|
|
169
|
-
declare function
|
|
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
|
|
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
|
|
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
|
|
196
|
+
* Define a binding between fanout exchange and exchange (source -> destination)
|
|
197
|
+
* Fanout exchanges don't use routing keys
|
|
176
198
|
*/
|
|
177
|
-
declare function
|
|
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
|
|
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
|
|
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
|
|
214
|
+
* Define a message publisher for fanout exchange
|
|
215
|
+
* Fanout exchanges don't use routing keys
|
|
184
216
|
*/
|
|
185
|
-
declare function
|
|
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<
|
|
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<
|
|
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
|
|
238
|
+
declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
|
|
198
239
|
//#endregion
|
|
199
|
-
export { type AnySchema, type
|
|
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
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAKY,KALA,SAAA,GAAY,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAKY,KALA,SAAA,GAAY,gBAUV;AAGd;AAIA;AAIA;AAIY,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AA,QAAA,ECoFtB,wBDpFsB,GCoFK,uBDpFL,EAAA,OAAA,ECqFvB,QDrFuB,EAAA,OAAA,ECsFvB,IDtFuB,CCuF9B,ODvF8B,CCwF5B,mBDxF4B,CCwFR,QDxFQ,CAAA,EAAA;EAAgC,QAAA,ECyFhD,wBDzFgD,GCyFrB,uBDzFqB;CAAS,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAA,EC6FxE,OD7FwE,CC8FzE,mBD9FyE,CC8FrD,QD9FqD,CAAA,EAAA;EAK/D,QAAA,EC0FE,wBD1FgB,GC0FW,uBD1FX;CAAmB,CAAA;;;;AACyB,iBCqH1D,cDrH0D,CAAA,iBCqH1B,iBDrH0B,CAAA,CAAA,KAAA,ECsHjE,eDtHiE,EAAA,OAAA,ECuH/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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
+
type QueueBindingDefinition = {
|
|
38
49
|
type: "queue";
|
|
39
|
-
queue:
|
|
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
|
-
|
|
62
|
+
type ExchangeBindingDefinition = {
|
|
48
63
|
type: "exchange";
|
|
49
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
70
|
-
queue:
|
|
71
|
-
message:
|
|
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
|
-
|
|
80
|
-
exchanges?:
|
|
81
|
-
queues?:
|
|
82
|
-
bindings?:
|
|
83
|
-
publishers?:
|
|
84
|
-
consumers?:
|
|
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
|
|
109
|
+
* Infer publisher names from a contract
|
|
88
110
|
*/
|
|
89
|
-
type
|
|
111
|
+
type InferPublisherNames<TContract extends ContractDefinition> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
|
|
90
112
|
/**
|
|
91
|
-
* Infer
|
|
113
|
+
* Infer consumer names from a contract
|
|
92
114
|
*/
|
|
93
|
-
type
|
|
115
|
+
type InferConsumerNames<TContract extends ContractDefinition> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
|
|
94
116
|
/**
|
|
95
|
-
* Infer
|
|
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
|
|
119
|
+
type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
|
|
106
120
|
/**
|
|
107
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
131
|
+
type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
|
|
124
132
|
/**
|
|
125
|
-
* Infer
|
|
133
|
+
* Infer publisher input type (message payload) for a specific publisher in a contract
|
|
126
134
|
*/
|
|
127
|
-
type
|
|
135
|
+
type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
128
136
|
/**
|
|
129
|
-
*
|
|
137
|
+
* Infer all consumers from contract
|
|
130
138
|
*/
|
|
131
|
-
type
|
|
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
|
-
*
|
|
145
|
+
* Infer consumer message input type
|
|
138
146
|
*/
|
|
139
|
-
type
|
|
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
|
-
*
|
|
153
|
+
* Infer consumer handler type for a specific consumer
|
|
146
154
|
*/
|
|
147
|
-
type
|
|
155
|
+
type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumerInput<TContract, TName>) => Promise<void> | void;
|
|
148
156
|
/**
|
|
149
|
-
*
|
|
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
|
-
*
|
|
170
|
+
* Define a message definition with payload and optional headers/metadata
|
|
160
171
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
178
|
+
* Define a binding between queue and fanout exchange (exchange -> queue)
|
|
179
|
+
* Fanout exchanges don't use routing keys
|
|
168
180
|
*/
|
|
169
|
-
declare function
|
|
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
|
|
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
|
|
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
|
|
196
|
+
* Define a binding between fanout exchange and exchange (source -> destination)
|
|
197
|
+
* Fanout exchanges don't use routing keys
|
|
176
198
|
*/
|
|
177
|
-
declare function
|
|
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
|
|
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
|
|
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
|
|
214
|
+
* Define a message publisher for fanout exchange
|
|
215
|
+
* Fanout exchanges don't use routing keys
|
|
184
216
|
*/
|
|
185
|
-
declare function
|
|
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<
|
|
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<
|
|
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
|
|
238
|
+
declare function defineContract<TContract extends ContractDefinition>(definition: TContract): TContract;
|
|
198
239
|
//#endregion
|
|
199
|
-
export { type AnySchema, type
|
|
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
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/builder.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAKY,KALA,SAAA,GAAY,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.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QAAA,ECoFyB,wBDpFzB;CAAf,CAAA;;AAMd;;;AACkC,iBCmFlB,eDnFkB,CAAA,iBCmFe,iBDnFf,CAAA,CAAA,QAAA,ECoFtB,wBDpFsB,GCoFK,uBDpFL,EAAA,OAAA,ECqFvB,QDrFuB,EAAA,OAAA,ECsFvB,IDtFuB,CCuF9B,ODvF8B,CCwF5B,mBDxF4B,CCwFR,QDxFQ,CAAA,EAAA;EAAgC,QAAA,ECyFhD,wBDzFgD,GCyFrB,uBDzFqB;CAAS,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAA,EC6FxE,OD7FwE,CC8FzE,mBD9FyE,CC8FrD,QD9FqD,CAAA,EAAA;EAK/D,QAAA,EC0FE,wBD1FgB,GC0FW,uBD1FX;CAAmB,CAAA;;;;AACyB,iBCqH1D,cDrH0D,CAAA,iBCqH1B,iBDrH0B,CAAA,CAAA,KAAA,ECsHjE,eDtHiE,EAAA,OAAA,ECuH/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.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
|
|
22
|
+
* Define a message definition with payload and optional headers/metadata
|
|
33
23
|
*/
|
|
34
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
98
|
+
export { defineConsumer, defineContract, defineExchange, defineExchangeBinding, defineMessage, definePublisher, defineQueue, defineQueueBinding };
|
|
82
99
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import type {\n
|
|
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"}
|