@amqp-contract/contract 0.0.1
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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/index.cjs +65 -0
- package/dist/index.d.cts +167 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +167 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Benoit Travers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @amqp-contract/contract
|
|
2
|
+
|
|
3
|
+
Contract builder for amqp-contract - Define type-safe AMQP messaging contracts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @amqp-contract/contract
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { defineContract, defineExchange, defineQueue, defineBinding, definePublisher, defineConsumer } from '@amqp-contract/contract';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
|
|
17
|
+
// Define your contract
|
|
18
|
+
const contract = defineContract({
|
|
19
|
+
exchanges: {
|
|
20
|
+
orders: defineExchange('orders', 'topic', { durable: true }),
|
|
21
|
+
},
|
|
22
|
+
queues: {
|
|
23
|
+
orderProcessing: defineQueue('order-processing', { durable: true }),
|
|
24
|
+
},
|
|
25
|
+
bindings: {
|
|
26
|
+
orderBinding: defineBinding('order-processing', 'orders', {
|
|
27
|
+
routingKey: 'order.created',
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
publishers: {
|
|
31
|
+
orderCreated: definePublisher('orders', z.object({
|
|
32
|
+
orderId: z.string(),
|
|
33
|
+
amount: z.number(),
|
|
34
|
+
}), {
|
|
35
|
+
routingKey: 'order.created',
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
consumers: {
|
|
39
|
+
processOrder: defineConsumer('order-processing', z.object({
|
|
40
|
+
orderId: z.string(),
|
|
41
|
+
amount: z.number(),
|
|
42
|
+
}), {
|
|
43
|
+
prefetch: 10,
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API
|
|
50
|
+
|
|
51
|
+
### `defineExchange(name, type, options?)`
|
|
52
|
+
|
|
53
|
+
Define an AMQP exchange.
|
|
54
|
+
|
|
55
|
+
### `defineQueue(name, options?)`
|
|
56
|
+
|
|
57
|
+
Define an AMQP queue.
|
|
58
|
+
|
|
59
|
+
### `defineBinding(queue, exchange, options?)`
|
|
60
|
+
|
|
61
|
+
Define a binding between a queue and an exchange.
|
|
62
|
+
|
|
63
|
+
### `definePublisher(exchange, messageSchema, options?)`
|
|
64
|
+
|
|
65
|
+
Define a message publisher with validation schema.
|
|
66
|
+
|
|
67
|
+
### `defineConsumer(queue, messageSchema, options?)`
|
|
68
|
+
|
|
69
|
+
Define a message consumer with validation schema.
|
|
70
|
+
|
|
71
|
+
### `defineContract(definition)`
|
|
72
|
+
|
|
73
|
+
Create a complete AMQP contract with exchanges, queues, bindings, publishers, and consumers.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/builder.ts
|
|
3
|
+
/**
|
|
4
|
+
* Define an AMQP exchange
|
|
5
|
+
*/
|
|
6
|
+
function defineExchange(name, type, options) {
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
type,
|
|
10
|
+
...options
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Define an AMQP queue
|
|
15
|
+
*/
|
|
16
|
+
function defineQueue(name, options) {
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
...options
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Define a binding between queue and exchange
|
|
24
|
+
*/
|
|
25
|
+
function defineBinding(queue, exchange, options) {
|
|
26
|
+
return {
|
|
27
|
+
queue,
|
|
28
|
+
exchange,
|
|
29
|
+
...options
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Define a message publisher
|
|
34
|
+
*/
|
|
35
|
+
function definePublisher(exchange, message, options) {
|
|
36
|
+
return {
|
|
37
|
+
exchange,
|
|
38
|
+
message,
|
|
39
|
+
...options
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Define a message consumer
|
|
44
|
+
*/
|
|
45
|
+
function defineConsumer(queue, message, options) {
|
|
46
|
+
return {
|
|
47
|
+
queue,
|
|
48
|
+
message,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Define an AMQP contract
|
|
54
|
+
*/
|
|
55
|
+
function defineContract(definition) {
|
|
56
|
+
return definition;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.defineBinding = defineBinding;
|
|
61
|
+
exports.defineConsumer = defineConsumer;
|
|
62
|
+
exports.defineContract = defineContract;
|
|
63
|
+
exports.defineExchange = defineExchange;
|
|
64
|
+
exports.definePublisher = definePublisher;
|
|
65
|
+
exports.defineQueue = defineQueue;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Any schema that conforms to Standard Schema v1
|
|
7
|
+
*/
|
|
8
|
+
type AnySchema = StandardSchemaV1;
|
|
9
|
+
/**
|
|
10
|
+
* Exchange types supported by AMQP
|
|
11
|
+
*/
|
|
12
|
+
type ExchangeType = 'direct' | 'fanout' | 'topic' | 'headers';
|
|
13
|
+
/**
|
|
14
|
+
* Definition of an AMQP exchange
|
|
15
|
+
*/
|
|
16
|
+
interface ExchangeDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
type: ExchangeType;
|
|
19
|
+
durable?: boolean;
|
|
20
|
+
autoDelete?: boolean;
|
|
21
|
+
internal?: boolean;
|
|
22
|
+
arguments?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Definition of an AMQP queue
|
|
26
|
+
*/
|
|
27
|
+
interface QueueDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
durable?: boolean;
|
|
30
|
+
exclusive?: boolean;
|
|
31
|
+
autoDelete?: boolean;
|
|
32
|
+
arguments?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Binding between queue and exchange
|
|
36
|
+
*/
|
|
37
|
+
interface BindingDefinition {
|
|
38
|
+
queue: string;
|
|
39
|
+
exchange: string;
|
|
40
|
+
routingKey?: string;
|
|
41
|
+
arguments?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Definition of a message publisher
|
|
45
|
+
*/
|
|
46
|
+
interface PublisherDefinition<TMessageSchema extends AnySchema = AnySchema> {
|
|
47
|
+
exchange: string;
|
|
48
|
+
routingKey?: string;
|
|
49
|
+
message: TMessageSchema;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Definition of a message consumer
|
|
53
|
+
*/
|
|
54
|
+
interface ConsumerDefinition<TMessageSchema extends AnySchema = AnySchema, THandlerResultSchema extends AnySchema = AnySchema> {
|
|
55
|
+
queue: string;
|
|
56
|
+
message: TMessageSchema;
|
|
57
|
+
handlerResult?: THandlerResultSchema;
|
|
58
|
+
prefetch?: number;
|
|
59
|
+
noAck?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Contract definition containing all AMQP resources
|
|
63
|
+
*/
|
|
64
|
+
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>> {
|
|
65
|
+
exchanges?: TExchanges;
|
|
66
|
+
queues?: TQueues;
|
|
67
|
+
bindings?: TBindings;
|
|
68
|
+
publishers?: TPublishers;
|
|
69
|
+
consumers?: TConsumers;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Infer the TypeScript type from a schema
|
|
73
|
+
*/
|
|
74
|
+
type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
|
|
75
|
+
/**
|
|
76
|
+
* Infer the output type from a schema
|
|
77
|
+
*/
|
|
78
|
+
type InferSchemaOutput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<unknown, infer TOutput> ? TOutput : never;
|
|
79
|
+
/**
|
|
80
|
+
* Infer publisher message input type
|
|
81
|
+
*/
|
|
82
|
+
type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher['message']>;
|
|
83
|
+
/**
|
|
84
|
+
* Infer consumer message input type
|
|
85
|
+
*/
|
|
86
|
+
type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer['message']>;
|
|
87
|
+
/**
|
|
88
|
+
* Infer consumer handler result type
|
|
89
|
+
*/
|
|
90
|
+
type ConsumerInferHandlerResult<TConsumer extends ConsumerDefinition> = TConsumer['handlerResult'] extends AnySchema ? InferSchemaOutput<TConsumer['handlerResult']> : void;
|
|
91
|
+
/**
|
|
92
|
+
* Consumer handler function type
|
|
93
|
+
*/
|
|
94
|
+
type ConsumerHandler<TConsumer extends ConsumerDefinition> = (message: ConsumerInferInput<TConsumer>) => ConsumerInferHandlerResult<TConsumer> | Promise<ConsumerInferHandlerResult<TConsumer>>;
|
|
95
|
+
/**
|
|
96
|
+
* Infer all publishers from contract
|
|
97
|
+
*/
|
|
98
|
+
type InferPublishers<TContract extends ContractDefinition> = TContract['publishers'] extends Record<string, PublisherDefinition> ? TContract['publishers'] : never;
|
|
99
|
+
/**
|
|
100
|
+
* Infer all consumers from contract
|
|
101
|
+
*/
|
|
102
|
+
type InferConsumers<TContract extends ContractDefinition> = TContract['consumers'] extends Record<string, ConsumerDefinition> ? TContract['consumers'] : never;
|
|
103
|
+
/**
|
|
104
|
+
* Infer publisher names from contract
|
|
105
|
+
*/
|
|
106
|
+
type InferPublisherNames<TContract extends ContractDefinition> = keyof InferPublishers<TContract>;
|
|
107
|
+
/**
|
|
108
|
+
* Infer consumer names from contract
|
|
109
|
+
*/
|
|
110
|
+
type InferConsumerNames<TContract extends ContractDefinition> = keyof InferConsumers<TContract>;
|
|
111
|
+
/**
|
|
112
|
+
* Get specific publisher definition from contract
|
|
113
|
+
*/
|
|
114
|
+
type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
|
|
115
|
+
/**
|
|
116
|
+
* Get specific consumer definition from contract
|
|
117
|
+
*/
|
|
118
|
+
type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
|
|
119
|
+
/**
|
|
120
|
+
* Client perspective types - for publishing messages
|
|
121
|
+
*/
|
|
122
|
+
type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
123
|
+
/**
|
|
124
|
+
* Worker perspective types - for consuming messages
|
|
125
|
+
*/
|
|
126
|
+
type WorkerInferConsumerInput<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferInput<InferConsumer<TContract, TName>>;
|
|
127
|
+
/**
|
|
128
|
+
* Worker perspective - consumer handler result type
|
|
129
|
+
*/
|
|
130
|
+
type WorkerInferConsumerHandlerResult<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHandlerResult<InferConsumer<TContract, TName>>;
|
|
131
|
+
/**
|
|
132
|
+
* Worker perspective - consumer handler type
|
|
133
|
+
*/
|
|
134
|
+
type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerHandler<InferConsumer<TContract, TName>>;
|
|
135
|
+
/**
|
|
136
|
+
* Map of all consumer handlers for a contract
|
|
137
|
+
*/
|
|
138
|
+
type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandler<TContract, K> };
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/builder.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Define an AMQP exchange
|
|
143
|
+
*/
|
|
144
|
+
declare function defineExchange(name: string, type: ExchangeType, options?: Omit<ExchangeDefinition, 'name' | 'type'>): ExchangeDefinition;
|
|
145
|
+
/**
|
|
146
|
+
* Define an AMQP queue
|
|
147
|
+
*/
|
|
148
|
+
declare function defineQueue(name: string, options?: Omit<QueueDefinition, 'name'>): QueueDefinition;
|
|
149
|
+
/**
|
|
150
|
+
* Define a binding between queue and exchange
|
|
151
|
+
*/
|
|
152
|
+
declare function defineBinding(queue: string, exchange: string, options?: Omit<BindingDefinition, 'queue' | 'exchange'>): BindingDefinition;
|
|
153
|
+
/**
|
|
154
|
+
* Define a message publisher
|
|
155
|
+
*/
|
|
156
|
+
declare function definePublisher<TMessageSchema extends AnySchema>(exchange: string, message: TMessageSchema, options?: Omit<PublisherDefinition<TMessageSchema>, 'exchange' | 'message'>): PublisherDefinition<TMessageSchema>;
|
|
157
|
+
/**
|
|
158
|
+
* Define a message consumer
|
|
159
|
+
*/
|
|
160
|
+
declare function defineConsumer<TMessageSchema extends AnySchema, THandlerResultSchema extends AnySchema = AnySchema>(queue: string, message: TMessageSchema, options?: Omit<ConsumerDefinition<TMessageSchema, THandlerResultSchema>, 'queue' | 'message'>): ConsumerDefinition<TMessageSchema, THandlerResultSchema>;
|
|
161
|
+
/**
|
|
162
|
+
* Define an AMQP contract
|
|
163
|
+
*/
|
|
164
|
+
declare function defineContract<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: ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>): ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { type AnySchema, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ConsumerHandler, type ConsumerInferHandlerResult, type ConsumerInferInput, type ContractDefinition, type ExchangeDefinition, type ExchangeType, type InferConsumer, type InferConsumerNames, type InferConsumers, type InferPublisher, type InferPublisherNames, type InferPublishers, type InferSchemaInput, type InferSchemaOutput, type PublisherDefinition, type PublisherInferInput, type QueueDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerResult, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineBinding, defineConsumer, defineContract, defineExchange, definePublisher, defineQueue };
|
|
167
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +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;AAUiB,KAtCL,YAAA,GAsCwB,QAAA,GAAA,QAAA,GAAA,OAAA,GAAA,SAAA;;;;AAKX,UAtCR,kBAAA,CAsCQ;EAMR,IAAA,EAAA,MAAA;EACQ,IAAA,EA3CjB,YA2CiB;EAAY,OAAA,CAAA,EAAA,OAAA;EACN,UAAA,CAAA,EAAA,OAAA;EAAY,QAAA,CAAA,EAAA,OAAA;EAGhC,SAAA,CAAA,EA3CG,MA2CH,CAAA,MAAA,EAAA,OAAA,CAAA;;;AASX;;AACqB,UA/CJ,eAAA,CA+CI;EAEjB,IAAA,EAAA,MAAA;EAFsD,OAAA,CAAA,EAAA,OAAA;EAIzB,SAAA,CAAA,EAAA,OAAA;EAAf,UAAA,CAAA,EAAA,OAAA;EAEd,SAAA,CAAA,EAhDU,MAgDV,CAAA,MAAA,EAAA,OAAA,CAAA;;;;;A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A,oBDjBA,CAAA;AAQtC;;;AAGI,iBCiBY,cDjBZ,CAAA,mBCkBiB,MDlBjB,CAAA,MAAA,ECkBgC,kBDlBhC,CAAA,GCkBsD,MDlBtD,CAAA,MAAA,ECoBA,kBDpBA,CAAA,EAAA,gBCsBc,MDtBd,CAAA,MAAA,ECsB6B,eDtB7B,CAAA,GCsBgD,MDtBhD,CAAA,MAAA,ECwBA,eDxBA,CAAA,EAAA,kBC0BgB,MD1BhB,CAAA,MAAA,EC0B+B,iBD1B/B,CAAA,GC0BoD,MD1BpD,CAAA,MAAA,EC4BA,iBD5BA,CAAA,EAAA,oBC8BkB,MD9BlB,CAAA,MAAA,EC8BiC,mBD9BjC,CAAA,GC8BwD,MD9BxD,CAAA,MAAA,ECgCA,mBDhCA,CAAA,EAAA,mBCkCiB,MDlCjB,CAAA,MAAA,ECkCgC,kBDlChC,CAAA,GCkCsD,MDlCtD,CAAA,MAAA,ECoCA,kBDpCA,CAAA,CAAA,CAAA,UAAA,ECuCU,kBDvCV,CCwCA,UDxCA,ECyCA,ODzCA,EC0CA,SD1CA,EC2CA,WD3CA,EC4CA,UD5CA,CAAA,CAAA,EC8CD,kBD9CC,CC8CkB,UD9ClB,EC8C8B,OD9C9B,EC8CuC,SD9CvC,EC8CkD,WD9ClD,EC8C+D,UD9C/D,CAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Any schema that conforms to Standard Schema v1
|
|
7
|
+
*/
|
|
8
|
+
type AnySchema = StandardSchemaV1;
|
|
9
|
+
/**
|
|
10
|
+
* Exchange types supported by AMQP
|
|
11
|
+
*/
|
|
12
|
+
type ExchangeType = 'direct' | 'fanout' | 'topic' | 'headers';
|
|
13
|
+
/**
|
|
14
|
+
* Definition of an AMQP exchange
|
|
15
|
+
*/
|
|
16
|
+
interface ExchangeDefinition {
|
|
17
|
+
name: string;
|
|
18
|
+
type: ExchangeType;
|
|
19
|
+
durable?: boolean;
|
|
20
|
+
autoDelete?: boolean;
|
|
21
|
+
internal?: boolean;
|
|
22
|
+
arguments?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Definition of an AMQP queue
|
|
26
|
+
*/
|
|
27
|
+
interface QueueDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
durable?: boolean;
|
|
30
|
+
exclusive?: boolean;
|
|
31
|
+
autoDelete?: boolean;
|
|
32
|
+
arguments?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Binding between queue and exchange
|
|
36
|
+
*/
|
|
37
|
+
interface BindingDefinition {
|
|
38
|
+
queue: string;
|
|
39
|
+
exchange: string;
|
|
40
|
+
routingKey?: string;
|
|
41
|
+
arguments?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Definition of a message publisher
|
|
45
|
+
*/
|
|
46
|
+
interface PublisherDefinition<TMessageSchema extends AnySchema = AnySchema> {
|
|
47
|
+
exchange: string;
|
|
48
|
+
routingKey?: string;
|
|
49
|
+
message: TMessageSchema;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Definition of a message consumer
|
|
53
|
+
*/
|
|
54
|
+
interface ConsumerDefinition<TMessageSchema extends AnySchema = AnySchema, THandlerResultSchema extends AnySchema = AnySchema> {
|
|
55
|
+
queue: string;
|
|
56
|
+
message: TMessageSchema;
|
|
57
|
+
handlerResult?: THandlerResultSchema;
|
|
58
|
+
prefetch?: number;
|
|
59
|
+
noAck?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Contract definition containing all AMQP resources
|
|
63
|
+
*/
|
|
64
|
+
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>> {
|
|
65
|
+
exchanges?: TExchanges;
|
|
66
|
+
queues?: TQueues;
|
|
67
|
+
bindings?: TBindings;
|
|
68
|
+
publishers?: TPublishers;
|
|
69
|
+
consumers?: TConsumers;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Infer the TypeScript type from a schema
|
|
73
|
+
*/
|
|
74
|
+
type InferSchemaInput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<infer TInput> ? TInput : never;
|
|
75
|
+
/**
|
|
76
|
+
* Infer the output type from a schema
|
|
77
|
+
*/
|
|
78
|
+
type InferSchemaOutput<TSchema extends AnySchema> = TSchema extends StandardSchemaV1<unknown, infer TOutput> ? TOutput : never;
|
|
79
|
+
/**
|
|
80
|
+
* Infer publisher message input type
|
|
81
|
+
*/
|
|
82
|
+
type PublisherInferInput<TPublisher extends PublisherDefinition> = InferSchemaInput<TPublisher['message']>;
|
|
83
|
+
/**
|
|
84
|
+
* Infer consumer message input type
|
|
85
|
+
*/
|
|
86
|
+
type ConsumerInferInput<TConsumer extends ConsumerDefinition> = InferSchemaInput<TConsumer['message']>;
|
|
87
|
+
/**
|
|
88
|
+
* Infer consumer handler result type
|
|
89
|
+
*/
|
|
90
|
+
type ConsumerInferHandlerResult<TConsumer extends ConsumerDefinition> = TConsumer['handlerResult'] extends AnySchema ? InferSchemaOutput<TConsumer['handlerResult']> : void;
|
|
91
|
+
/**
|
|
92
|
+
* Consumer handler function type
|
|
93
|
+
*/
|
|
94
|
+
type ConsumerHandler<TConsumer extends ConsumerDefinition> = (message: ConsumerInferInput<TConsumer>) => ConsumerInferHandlerResult<TConsumer> | Promise<ConsumerInferHandlerResult<TConsumer>>;
|
|
95
|
+
/**
|
|
96
|
+
* Infer all publishers from contract
|
|
97
|
+
*/
|
|
98
|
+
type InferPublishers<TContract extends ContractDefinition> = TContract['publishers'] extends Record<string, PublisherDefinition> ? TContract['publishers'] : never;
|
|
99
|
+
/**
|
|
100
|
+
* Infer all consumers from contract
|
|
101
|
+
*/
|
|
102
|
+
type InferConsumers<TContract extends ContractDefinition> = TContract['consumers'] extends Record<string, ConsumerDefinition> ? TContract['consumers'] : never;
|
|
103
|
+
/**
|
|
104
|
+
* Infer publisher names from contract
|
|
105
|
+
*/
|
|
106
|
+
type InferPublisherNames<TContract extends ContractDefinition> = keyof InferPublishers<TContract>;
|
|
107
|
+
/**
|
|
108
|
+
* Infer consumer names from contract
|
|
109
|
+
*/
|
|
110
|
+
type InferConsumerNames<TContract extends ContractDefinition> = keyof InferConsumers<TContract>;
|
|
111
|
+
/**
|
|
112
|
+
* Get specific publisher definition from contract
|
|
113
|
+
*/
|
|
114
|
+
type InferPublisher<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = InferPublishers<TContract>[TName];
|
|
115
|
+
/**
|
|
116
|
+
* Get specific consumer definition from contract
|
|
117
|
+
*/
|
|
118
|
+
type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
|
|
119
|
+
/**
|
|
120
|
+
* Client perspective types - for publishing messages
|
|
121
|
+
*/
|
|
122
|
+
type ClientInferPublisherInput<TContract extends ContractDefinition, TName extends InferPublisherNames<TContract>> = PublisherInferInput<InferPublisher<TContract, TName>>;
|
|
123
|
+
/**
|
|
124
|
+
* Worker perspective types - for consuming messages
|
|
125
|
+
*/
|
|
126
|
+
type WorkerInferConsumerInput<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferInput<InferConsumer<TContract, TName>>;
|
|
127
|
+
/**
|
|
128
|
+
* Worker perspective - consumer handler result type
|
|
129
|
+
*/
|
|
130
|
+
type WorkerInferConsumerHandlerResult<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHandlerResult<InferConsumer<TContract, TName>>;
|
|
131
|
+
/**
|
|
132
|
+
* Worker perspective - consumer handler type
|
|
133
|
+
*/
|
|
134
|
+
type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerHandler<InferConsumer<TContract, TName>>;
|
|
135
|
+
/**
|
|
136
|
+
* Map of all consumer handlers for a contract
|
|
137
|
+
*/
|
|
138
|
+
type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandler<TContract, K> };
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/builder.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Define an AMQP exchange
|
|
143
|
+
*/
|
|
144
|
+
declare function defineExchange(name: string, type: ExchangeType, options?: Omit<ExchangeDefinition, 'name' | 'type'>): ExchangeDefinition;
|
|
145
|
+
/**
|
|
146
|
+
* Define an AMQP queue
|
|
147
|
+
*/
|
|
148
|
+
declare function defineQueue(name: string, options?: Omit<QueueDefinition, 'name'>): QueueDefinition;
|
|
149
|
+
/**
|
|
150
|
+
* Define a binding between queue and exchange
|
|
151
|
+
*/
|
|
152
|
+
declare function defineBinding(queue: string, exchange: string, options?: Omit<BindingDefinition, 'queue' | 'exchange'>): BindingDefinition;
|
|
153
|
+
/**
|
|
154
|
+
* Define a message publisher
|
|
155
|
+
*/
|
|
156
|
+
declare function definePublisher<TMessageSchema extends AnySchema>(exchange: string, message: TMessageSchema, options?: Omit<PublisherDefinition<TMessageSchema>, 'exchange' | 'message'>): PublisherDefinition<TMessageSchema>;
|
|
157
|
+
/**
|
|
158
|
+
* Define a message consumer
|
|
159
|
+
*/
|
|
160
|
+
declare function defineConsumer<TMessageSchema extends AnySchema, THandlerResultSchema extends AnySchema = AnySchema>(queue: string, message: TMessageSchema, options?: Omit<ConsumerDefinition<TMessageSchema, THandlerResultSchema>, 'queue' | 'message'>): ConsumerDefinition<TMessageSchema, THandlerResultSchema>;
|
|
161
|
+
/**
|
|
162
|
+
* Define an AMQP contract
|
|
163
|
+
*/
|
|
164
|
+
declare function defineContract<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: ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>): ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers>;
|
|
165
|
+
//#endregion
|
|
166
|
+
export { type AnySchema, type BindingDefinition, type ClientInferPublisherInput, type ConsumerDefinition, type ConsumerHandler, type ConsumerInferHandlerResult, type ConsumerInferInput, type ContractDefinition, type ExchangeDefinition, type ExchangeType, type InferConsumer, type InferConsumerNames, type InferConsumers, type InferPublisher, type InferPublisherNames, type InferPublishers, type InferSchemaInput, type InferSchemaOutput, type PublisherDefinition, type PublisherInferInput, type QueueDefinition, type WorkerInferConsumerHandler, type WorkerInferConsumerHandlerResult, type WorkerInferConsumerHandlers, type WorkerInferConsumerInput, defineBinding, defineConsumer, defineContract, defineExchange, definePublisher, defineQueue };
|
|
167
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +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;AAUiB,KAtCL,YAAA,GAsCwB,QAAA,GAAA,QAAA,GAAA,OAAA,GAAA,SAAA;;;;AAKX,UAtCR,kBAAA,CAsCQ;EAMR,IAAA,EAAA,MAAA;EACQ,IAAA,EA3CjB,YA2CiB;EAAY,OAAA,CAAA,EAAA,OAAA;EACN,UAAA,CAAA,EAAA,OAAA;EAAY,QAAA,CAAA,EAAA,OAAA;EAG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/
|
|
5
|
+
function defineExchange(name, type, options) {
|
|
6
|
+
return {
|
|
7
|
+
name,
|
|
8
|
+
type,
|
|
9
|
+
...options
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Define an AMQP queue
|
|
14
|
+
*/
|
|
15
|
+
function defineQueue(name, options) {
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
...options
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Define a binding between queue and exchange
|
|
23
|
+
*/
|
|
24
|
+
function defineBinding(queue, exchange, options) {
|
|
25
|
+
return {
|
|
26
|
+
queue,
|
|
27
|
+
exchange,
|
|
28
|
+
...options
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Define a message publisher
|
|
33
|
+
*/
|
|
34
|
+
function definePublisher(exchange, message, options) {
|
|
35
|
+
return {
|
|
36
|
+
exchange,
|
|
37
|
+
message,
|
|
38
|
+
...options
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Define a message consumer
|
|
43
|
+
*/
|
|
44
|
+
function defineConsumer(queue, message, options) {
|
|
45
|
+
return {
|
|
46
|
+
queue,
|
|
47
|
+
message,
|
|
48
|
+
...options
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Define an AMQP contract
|
|
53
|
+
*/
|
|
54
|
+
function defineContract(definition) {
|
|
55
|
+
return definition;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { defineBinding, defineConsumer, defineContract, defineExchange, definePublisher, defineQueue };
|
|
60
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/builder.ts"],"sourcesContent":["import type {\n AnySchema,\n BindingDefinition,\n ConsumerDefinition,\n ContractDefinition,\n ExchangeDefinition,\n ExchangeType,\n PublisherDefinition,\n QueueDefinition,\n} from './types.js';\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<BindingDefinition, 'queue' | 'exchange'>\n): BindingDefinition {\n return {\n queue,\n exchange,\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<\n ConsumerDefinition<TMessageSchema, THandlerResultSchema>,\n 'queue' | 'message'\n >\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 TExchanges extends Record<string, ExchangeDefinition> = Record<\n string,\n ExchangeDefinition\n >,\n TQueues extends Record<string, QueueDefinition> = Record<\n string,\n QueueDefinition\n >,\n TBindings extends Record<string, BindingDefinition> = Record<\n string,\n BindingDefinition\n >,\n TPublishers extends Record<string, PublisherDefinition> = Record<\n string,\n PublisherDefinition\n >,\n TConsumers extends Record<string, ConsumerDefinition> = Record<\n string,\n ConsumerDefinition\n >,\n>(\n definition: ContractDefinition<\n TExchanges,\n TQueues,\n TBindings,\n TPublishers,\n TConsumers\n >\n): ContractDefinition<TExchanges, TQueues, TBindings, TPublishers, TConsumers> {\n return definition;\n}\n"],"mappings":";;;;AAcA,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,SACmB;AACnB,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,gBACd,UACA,SACA,SACqC;AACrC,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,eAId,OACA,SACA,SAI0D;AAC1D,QAAO;EACL;EACA;EACA,GAAG;EACJ;;;;;AAMH,SAAgB,eAsBd,YAO6E;AAC7E,QAAO"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amqp-contract/contract",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Contract builder for amqp-contract",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"amqp",
|
|
7
|
+
"typescript",
|
|
8
|
+
"contract",
|
|
9
|
+
"rabbitmq"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/btravers/amqp-contract#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/btravers/amqp-contract/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/btravers/amqp-contract.git",
|
|
18
|
+
"directory": "packages/contract"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Benoit TRAVERS <benoit.travers.fr@gmail.com>",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"main": "./dist/index.cjs",
|
|
37
|
+
"module": "./dist/index.mjs",
|
|
38
|
+
"types": "./dist/index.d.mts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@standard-schema/spec": "1.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@vitest/coverage-v8": "4.0.15",
|
|
47
|
+
"tsdown": "0.17.2",
|
|
48
|
+
"typescript": "5.9.3",
|
|
49
|
+
"vitest": "4.0.15",
|
|
50
|
+
"zod": "4.1.13",
|
|
51
|
+
"@amqp-contract/tsconfig": "0.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown src/index.ts --format cjs,esm --dts --clean",
|
|
55
|
+
"dev": "tsdown src/index.ts --format cjs,esm --dts --watch",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest",
|
|
58
|
+
"typecheck": "tsc --noEmit"
|
|
59
|
+
}
|
|
60
|
+
}
|