amqp-extension 1.0.5 → 1.1.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/.eslintrc +3 -1
- package/.husky/commit-msg +4 -0
- package/CHANGELOG.md +6 -0
- package/LICENSE +1 -1
- package/README.MD +102 -216
- package/commitlint.config.js +10 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +7 -1
- package/dist/config/module.d.ts +4 -0
- package/dist/config/module.js +44 -0
- package/dist/config/type.d.ts +8 -12
- package/dist/config/type.js +6 -1
- package/dist/config/utils.d.ts +3 -4
- package/dist/config/utils.js +23 -33
- package/dist/connection/index.d.ts +1 -1
- package/dist/connection/index.js +7 -2
- package/dist/connection/module.d.ts +7 -0
- package/dist/connection/module.js +48 -0
- package/dist/consume/index.d.ts +1 -1
- package/dist/consume/index.js +7 -2
- package/dist/consume/module.d.ts +3 -0
- package/dist/consume/module.js +72 -0
- package/dist/consume/static.js +6 -1
- package/dist/consume/type.d.ts +5 -32
- package/dist/consume/type.js +6 -1
- package/dist/consume/utils.d.ts +3 -2
- package/dist/consume/utils.js +11 -127
- package/dist/exchange/constants.d.ts +7 -0
- package/dist/exchange/constants.js +11 -0
- package/dist/exchange/index.d.ts +3 -0
- package/dist/{message → exchange}/index.js +2 -2
- package/dist/exchange/type.d.ts +7 -0
- package/dist/{message → exchange}/type.js +0 -1
- package/dist/exchange/utils.d.ts +5 -0
- package/dist/exchange/utils.js +17 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -2
- package/dist/publish/index.d.ts +1 -1
- package/dist/publish/index.js +7 -2
- package/dist/publish/module.d.ts +2 -0
- package/dist/publish/module.js +67 -0
- package/dist/publish/type.d.ts +9 -8
- package/dist/publish/type.js +6 -1
- package/dist/publish/utils.d.ts +3 -3
- package/dist/publish/utils.js +11 -84
- package/dist/type.d.ts +33 -0
- package/dist/type.js +2 -0
- package/dist/utils.d.ts +1 -6
- package/dist/utils.js +9 -77
- package/package.json +24 -9
- package/release.config.js +10 -0
- package/dist/config/index.js.map +0 -1
- package/dist/config/type.js.map +0 -1
- package/dist/config/utils.js.map +0 -1
- package/dist/connection/index.js.map +0 -1
- package/dist/connection/utils.d.ts +0 -6
- package/dist/connection/utils.js +0 -84
- package/dist/connection/utils.js.map +0 -1
- package/dist/consume/index.js.map +0 -1
- package/dist/consume/static.js.map +0 -1
- package/dist/consume/type.js.map +0 -1
- package/dist/consume/utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/message/build.d.ts +0 -2
- package/dist/message/build.js +0 -16
- package/dist/message/build.js.map +0 -1
- package/dist/message/index.d.ts +0 -2
- package/dist/message/index.js.map +0 -1
- package/dist/message/type.d.ts +0 -46
- package/dist/message/type.js.map +0 -1
- package/dist/publish/index.js.map +0 -1
- package/dist/publish/type.js.map +0 -1
- package/dist/publish/utils.js.map +0 -1
- package/dist/utils.js.map +0 -1
package/.eslintrc
CHANGED
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
"rules": {
|
|
13
13
|
"class-methods-use-this": "off",
|
|
14
14
|
"import/no-cycle": [2, {
|
|
15
|
-
"maxDepth": 1
|
|
15
|
+
"maxDepth": 1,
|
|
16
16
|
}],
|
|
17
17
|
|
|
18
|
+
"no-underscore-dangle": "off",
|
|
18
19
|
"no-continue": "off",
|
|
19
20
|
"no-use-before-define": "off",
|
|
20
21
|
"no-nested-ternary": "off",
|
|
22
|
+
"no-shadow": "off",
|
|
21
23
|
|
|
22
24
|
"@typescript-eslint/no-unused-vars": "off",
|
|
23
25
|
"@typescript-eslint/no-use-before-define": "off"
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# [1.1.0](https://github.com/Tada5hi/amqp-extension/compare/v1.0.5...v1.1.0) (2023-02-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* refactored and enhance publish & subscribe pattern \n\n BREAKING CHANGE: api rewritten ([#224](https://github.com/Tada5hi/amqp-extension/issues/224)) ([5bc43c2](https://github.com/Tada5hi/amqp-extension/commit/5bc43c235113ec8d604ad259434ad94fb7bb09f8))
|
package/LICENSE
CHANGED
package/README.MD
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# AMQP Extension 🏰
|
|
2
|
+
|
|
1
3
|
[](https://badge.fury.io/js/amqp-extension)
|
|
2
4
|
[](https://codecov.io/gh/Tada5hi/amqp-extension)
|
|
3
5
|
[](https://github.com/Tada5hi/amqp-extension)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
[](https://snyk.io/test/github/Tada5hi/amqp-extension?targetFile=package.json)
|
|
7
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
6
8
|
|
|
7
9
|
This is a library on top of the famous [amqplib](https://www.npmjs.com/package/amqplib) library and defines a [message format](#message-types) for queue messages through a message broker across multiple standalone services.
|
|
8
10
|
All utility functions support the usage of multiple registered connections.
|
|
@@ -11,19 +13,16 @@ All utility functions support the usage of multiple registered connections.
|
|
|
11
13
|
|
|
12
14
|
- [Installation](#installation)
|
|
13
15
|
- [Usage](#usage)
|
|
14
|
-
- [Publish](#publish)
|
|
15
|
-
- [Consume](#consume)
|
|
16
|
+
- [Publish](#publish-to-queue)
|
|
17
|
+
- [Consume](#consume-queue)
|
|
16
18
|
- [Functions](#functions)
|
|
17
19
|
- [setConfig](#setconfig)
|
|
18
20
|
- [useConnection](#useconnection)
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
+
- [publish](#publish)
|
|
22
|
+
- [consume](#consume)
|
|
21
23
|
- [Types](#types)
|
|
22
24
|
- [Config](#config-types)
|
|
23
|
-
|
|
24
|
-
- [Message](#message-types)
|
|
25
|
-
- [Publish](#publish-types)
|
|
26
|
-
|
|
25
|
+
- [License](#license)
|
|
27
26
|
|
|
28
27
|
|
|
29
28
|
## Installation
|
|
@@ -34,17 +33,15 @@ npm install amqp-extension --save
|
|
|
34
33
|
|
|
35
34
|
## Usage
|
|
36
35
|
|
|
37
|
-
### Publish
|
|
36
|
+
### Publish to Queue
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
The `publish` function allows you to send messages quickly.
|
|
39
|
+
Existing options can be added or overwritten
|
|
41
40
|
|
|
42
41
|
```typescript
|
|
43
42
|
import {
|
|
44
|
-
buildMessage,
|
|
45
|
-
Message,
|
|
46
43
|
useConnection,
|
|
47
|
-
|
|
44
|
+
publish,
|
|
48
45
|
setConfig
|
|
49
46
|
} from "amqp-extension";
|
|
50
47
|
|
|
@@ -57,33 +54,26 @@ setConfig({
|
|
|
57
54
|
}
|
|
58
55
|
});
|
|
59
56
|
|
|
60
|
-
const message: Message = buildMessage({
|
|
61
|
-
type: 'resourceCreated',
|
|
62
|
-
options: {
|
|
63
|
-
routingKey: '<routing-key>'
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
console.log(message);
|
|
68
|
-
// {id: 'xxxx-xxxx-xxxx-xxxx', type: 'resourceCreated', options: {routingKey: '<routing-key>'}, data: {}, metadata: {}}
|
|
69
|
-
|
|
70
57
|
(async () => {
|
|
71
|
-
await
|
|
58
|
+
await publish({
|
|
59
|
+
data: {
|
|
60
|
+
type: 'resourceCreated',
|
|
61
|
+
name: 'foo'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
72
64
|
})();
|
|
73
65
|
```
|
|
74
66
|
|
|
75
|
-
### Consume
|
|
67
|
+
### Consume Queue
|
|
76
68
|
|
|
77
|
-
To consume a queue
|
|
69
|
+
To consume a queue use the `consume` function. As first argument it accepts a configuration object
|
|
78
70
|
and as second argument and object to specify an async callback function handler for a specific message `type`.
|
|
79
71
|
|
|
80
72
|
```typescript
|
|
81
73
|
import {
|
|
82
|
-
|
|
74
|
+
consume,
|
|
75
|
+
ConsumeMessage,
|
|
83
76
|
ConsumeOptions,
|
|
84
|
-
Message,
|
|
85
|
-
MessageContext,
|
|
86
|
-
publishMessage,
|
|
87
77
|
setConfig
|
|
88
78
|
} from "amqp-extension";
|
|
89
79
|
|
|
@@ -97,15 +87,18 @@ setConfig({
|
|
|
97
87
|
});
|
|
98
88
|
|
|
99
89
|
const options: ConsumeOptions = {
|
|
100
|
-
|
|
90
|
+
exchange: {
|
|
91
|
+
routingKey: '<routing-key>'
|
|
92
|
+
}
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
(async () => {
|
|
104
|
-
await
|
|
105
|
-
resourceCreated: async (message:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
96
|
+
await consume(options, {
|
|
97
|
+
resourceCreated: async (message: ConsumeMessage) => {
|
|
98
|
+
const content = message.content.toString('utf-8');
|
|
99
|
+
const payload = JSON.parse(content);
|
|
100
|
+
console.log(payload);
|
|
101
|
+
// { type: 'resourceCreated', name: 'foo' }
|
|
109
102
|
}
|
|
110
103
|
});
|
|
111
104
|
})();
|
|
@@ -118,12 +111,9 @@ get overwritten.
|
|
|
118
111
|
|
|
119
112
|
```typescript
|
|
120
113
|
import {
|
|
121
|
-
buildMessage,
|
|
122
114
|
ConsumeOptions,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
publishMessage,
|
|
126
|
-
PublishOptions,
|
|
115
|
+
publish,
|
|
116
|
+
PublishOptionsExtended,
|
|
127
117
|
setConfig
|
|
128
118
|
} from "amqp-extension";
|
|
129
119
|
|
|
@@ -144,19 +134,24 @@ setConfig({
|
|
|
144
134
|
type: 'topic'
|
|
145
135
|
}
|
|
146
136
|
});
|
|
147
|
-
|
|
148
|
-
const consumeOptions: ConsumeOptions = {
|
|
149
|
-
routingKey: '<routing-key>',
|
|
150
|
-
alias: 'foo' // <--- use another connection :)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const publishOptions: PublishOptions = {
|
|
154
|
-
alias: 'foo' // <--- use another connection :)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
137
|
(async () => {
|
|
158
|
-
await
|
|
159
|
-
|
|
138
|
+
await consume(
|
|
139
|
+
{
|
|
140
|
+
routingKey: '<routing-key>',
|
|
141
|
+
alias: 'foo' // <--- use another connection :)
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
// ... handlers
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await publish({
|
|
149
|
+
routingKey: '<routing-key>',
|
|
150
|
+
alias: 'foo', // <--- use another connection :)
|
|
151
|
+
data: {
|
|
152
|
+
foo: 'bar'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
160
155
|
})();
|
|
161
156
|
|
|
162
157
|
```
|
|
@@ -165,7 +160,7 @@ const publishOptions: PublishOptions = {
|
|
|
165
160
|
|
|
166
161
|
### setConfig
|
|
167
162
|
|
|
168
|
-
▸ `function` **setConfig**(`key?: string |
|
|
163
|
+
▸ `function` **setConfig**(`key?: string | ConfigInput`, `value?: ConfigInput`): `Config`
|
|
169
164
|
|
|
170
165
|
Register a connection as `default` alias or specify an `<alias>` as config property.
|
|
171
166
|
|
|
@@ -194,7 +189,7 @@ import {setConfig, useConnection} from "amqp-extension";
|
|
|
194
189
|
Define a non default connection.
|
|
195
190
|
|
|
196
191
|
```typescript
|
|
197
|
-
import {setConfig, useConnection} from "amqp-extension";
|
|
192
|
+
import { setConfig, useConnection } from "amqp-extension";
|
|
198
193
|
|
|
199
194
|
(async () => {
|
|
200
195
|
setConfig({
|
|
@@ -223,17 +218,17 @@ import {setConfig, useConnection} from "amqp-extension";
|
|
|
223
218
|
|
|
224
219
|
#### Type parameters
|
|
225
220
|
|
|
226
|
-
| Name
|
|
227
|
-
|
|
221
|
+
| Name | Description |
|
|
222
|
+
|:------|:------------|
|
|
228
223
|
|
|
229
224
|
|
|
230
225
|
|
|
231
226
|
#### Parameters
|
|
232
227
|
|
|
233
|
-
| Name
|
|
234
|
-
|
|
235
|
-
| `key`
|
|
236
|
-
| `value` | `Config`
|
|
228
|
+
| Name | Type | Description |
|
|
229
|
+
|:--------|:--------------------------|:-----------------------------------------------------------|
|
|
230
|
+
| `key` | `string` or `ConfigInput` | Config object or alias of config. [more](#config-types) |
|
|
231
|
+
| `value` | `Config` | Config object. [more](#config-types) |
|
|
237
232
|
|
|
238
233
|
#### Returns
|
|
239
234
|
|
|
@@ -243,7 +238,7 @@ The function returns the Config object.
|
|
|
243
238
|
|
|
244
239
|
### useConnection
|
|
245
240
|
|
|
246
|
-
▸ `function` **useConnection**(`key?: string |
|
|
241
|
+
▸ `function` **useConnection**(`key?: string | ConfigInput`): `Promise<Connection>`
|
|
247
242
|
|
|
248
243
|
Either register a connection as `default` alias or specify an `alias` as config property.
|
|
249
244
|
If you have registered a connection you can receive the connection by specifying no arguments or provide an alias name if specified.
|
|
@@ -287,15 +282,15 @@ import {setConfig, useConnection} from "amqp-extension";
|
|
|
287
282
|
|
|
288
283
|
#### Type parameters
|
|
289
284
|
|
|
290
|
-
| Name
|
|
291
|
-
|
|
285
|
+
| Name | Description |
|
|
286
|
+
|:------|:--------------|
|
|
292
287
|
|
|
293
288
|
|
|
294
289
|
|
|
295
290
|
#### Parameters
|
|
296
291
|
|
|
297
|
-
| Name
|
|
298
|
-
|
|
292
|
+
| Name | Type | Description |
|
|
293
|
+
|:------|:---------------------|:-------------------------------------------------|
|
|
299
294
|
| `key` | `string` or `Config` | Config or alias of config. [more](#config-types) |
|
|
300
295
|
|
|
301
296
|
#### Returns
|
|
@@ -304,9 +299,9 @@ import {setConfig, useConnection} from "amqp-extension";
|
|
|
304
299
|
|
|
305
300
|
The function returns the Connection object of the `amqplib`.
|
|
306
301
|
|
|
307
|
-
###
|
|
302
|
+
### publish
|
|
308
303
|
|
|
309
|
-
▸ `function` **
|
|
304
|
+
▸ `function` **publish**(`message: Message`, `options?: PublishOptions`): `Promise<void>`
|
|
310
305
|
|
|
311
306
|
Send the constructed queue message to the message broker.
|
|
312
307
|
As second parameter a registered config can be used by specifying the alias or provide the full config object.
|
|
@@ -315,36 +310,29 @@ As second parameter a registered config can be used by specifying the alias or p
|
|
|
315
310
|
|
|
316
311
|
```typescript
|
|
317
312
|
import {
|
|
318
|
-
|
|
319
|
-
publishMessage
|
|
313
|
+
publish
|
|
320
314
|
} from "amqp-extension";
|
|
321
315
|
|
|
322
|
-
const message: Message = buildMessage({
|
|
323
|
-
type: 'resourceCreated',
|
|
324
|
-
options: {
|
|
325
|
-
routingKey: '<routing-key>'
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
console.log(message);
|
|
330
|
-
// {id: 'xxxx-xxxx-xxxx-xxxx', type: 'resourceCreated', options: {routingKey: '<routing-key>'}, data: {}, metadata: {}}
|
|
331
|
-
|
|
332
316
|
(async () => {
|
|
333
|
-
await
|
|
317
|
+
await publish({
|
|
318
|
+
data: {
|
|
319
|
+
type: 'resourceCreated'
|
|
320
|
+
}
|
|
321
|
+
});
|
|
334
322
|
})();
|
|
335
323
|
```
|
|
336
324
|
|
|
337
325
|
#### Type parameters
|
|
338
326
|
|
|
339
|
-
| Name
|
|
340
|
-
|
|
327
|
+
| Name | Description |
|
|
328
|
+
|:------|:------------|
|
|
341
329
|
|
|
342
330
|
#### Parameters
|
|
343
331
|
|
|
344
|
-
| Name
|
|
345
|
-
|
|
346
|
-
| `message` | `Message`
|
|
347
|
-
| `options` | `PublishOptions` | Publish options.
|
|
332
|
+
| Name | Type | Description |
|
|
333
|
+
|:----------|:-----------------|:----------------------------|
|
|
334
|
+
| `message` | `Message` | Constructed message object. |
|
|
335
|
+
| `options` | `PublishOptions` | Publish options. |
|
|
348
336
|
|
|
349
337
|
#### Returns
|
|
350
338
|
|
|
@@ -352,9 +340,9 @@ console.log(message);
|
|
|
352
340
|
|
|
353
341
|
The function does not return a value.
|
|
354
342
|
|
|
355
|
-
###
|
|
343
|
+
### consume
|
|
356
344
|
|
|
357
|
-
▸ `function` **
|
|
345
|
+
▸ `function` **consume**(`options: ConsumeOptions`, `cb: ConsumeHandlers`): `Promise<void>`
|
|
358
346
|
|
|
359
347
|
Send the constructed queue message to the message broker.
|
|
360
348
|
As second parameter a registered config can be used by specifying the alias or provide the full config object.
|
|
@@ -363,10 +351,9 @@ As second parameter a registered config can be used by specifying the alias or p
|
|
|
363
351
|
|
|
364
352
|
```typescript
|
|
365
353
|
import {
|
|
366
|
-
|
|
354
|
+
consume,
|
|
367
355
|
ConsumeOptions,
|
|
368
|
-
|
|
369
|
-
MessageContext
|
|
356
|
+
ConsumeMessage,
|
|
370
357
|
} from "amqp-extension";
|
|
371
358
|
|
|
372
359
|
const options: ConsumeOptions = {
|
|
@@ -374,11 +361,9 @@ const options: ConsumeOptions = {
|
|
|
374
361
|
}
|
|
375
362
|
|
|
376
363
|
(async () => {
|
|
377
|
-
await
|
|
378
|
-
'<type>': async (message:
|
|
364
|
+
await consume(options, {
|
|
365
|
+
'<type>': async (message: ConsumeMessage) => {
|
|
379
366
|
// do some async action :)
|
|
380
|
-
console.log(message);
|
|
381
|
-
// {id: 'xxxx-xxxx-xxxx-xxxx', type: 'resourceCreated', data: {}, metadata: {}}
|
|
382
367
|
}
|
|
383
368
|
});
|
|
384
369
|
})();
|
|
@@ -387,17 +372,17 @@ const options: ConsumeOptions = {
|
|
|
387
372
|
|
|
388
373
|
#### Type parameters
|
|
389
374
|
|
|
390
|
-
| Name
|
|
391
|
-
|
|
375
|
+
| Name | Description |
|
|
376
|
+
|:-------|:------------|
|
|
392
377
|
|
|
393
378
|
|
|
394
379
|
|
|
395
380
|
#### Parameters
|
|
396
381
|
|
|
397
|
-
| Name
|
|
398
|
-
|
|
399
|
-
| `options`
|
|
400
|
-
| `handlers` | `ConsumeHandlers` | Handlers object.
|
|
382
|
+
| Name | Type | Description |
|
|
383
|
+
|:-----------|:------------------|:-------------------|
|
|
384
|
+
| `options` | `ConsumeOptions` | Consume options. ) |
|
|
385
|
+
| `handlers` | `ConsumeHandlers` | Handlers object. |
|
|
401
386
|
|
|
402
387
|
#### Returns
|
|
403
388
|
|
|
@@ -410,123 +395,24 @@ The function does not return a value.
|
|
|
410
395
|
### Config Types
|
|
411
396
|
|
|
412
397
|
```typescript
|
|
413
|
-
import {Options} from
|
|
414
|
-
import {
|
|
415
|
-
|
|
416
|
-
export type ExchangeType = 'fanout' | 'direct' | 'topic' | 'match' | string;
|
|
398
|
+
import { Options } from 'amqplib';
|
|
399
|
+
import { ExchangeOptions } from '../exchange';
|
|
400
|
+
import { ConsumeOptions, PublishOptions } from '../type';
|
|
417
401
|
|
|
418
402
|
export type Config = {
|
|
419
|
-
alias
|
|
403
|
+
alias: string,
|
|
420
404
|
connection: Options.Connect | string,
|
|
421
|
-
exchange:
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
options?: Options.AssertExchange
|
|
425
|
-
},
|
|
426
|
-
publish?: PublishOptions,
|
|
427
|
-
consume?: ConsumeOptions
|
|
405
|
+
exchange: ExchangeOptions,
|
|
406
|
+
publish: PublishOptions,
|
|
407
|
+
consume: ConsumeOptions
|
|
428
408
|
};
|
|
429
|
-
```
|
|
430
409
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
import {Options} from "amqplib";
|
|
434
|
-
import {Config, MessageContext, Message} from "amqp-extension";
|
|
435
|
-
|
|
436
|
-
export type ConsumeHandler = (message: Message, context: MessageContext) => Promise<void>;
|
|
437
|
-
export type ConsumeHandlers = Record<'$any' | string, ConsumeHandler>;
|
|
438
|
-
|
|
439
|
-
export type ConsumeOptions = {
|
|
440
|
-
/**
|
|
441
|
-
* Queue routing key(s).
|
|
442
|
-
*/
|
|
443
|
-
routingKey?: string | string[],
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* Config key or object.
|
|
447
|
-
*/
|
|
448
|
-
alias?: string | Config,
|
|
449
|
-
/**
|
|
450
|
-
* Queue name.
|
|
451
|
-
*
|
|
452
|
-
* Default: ''
|
|
453
|
-
*/
|
|
454
|
-
name?: string,
|
|
455
|
-
/**
|
|
456
|
-
* Amqplib consume options.
|
|
457
|
-
*
|
|
458
|
-
* Default: {}
|
|
459
|
-
*/
|
|
460
|
-
options?: Options.Consume
|
|
461
|
-
}
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
### Message Types
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
import {Options} from "amqplib";
|
|
468
|
-
|
|
469
|
-
export interface MessageOptions {
|
|
470
|
-
/**
|
|
471
|
-
* Routing key for message broker.
|
|
472
|
-
*/
|
|
473
|
-
routingKey?: string;
|
|
474
|
-
/**
|
|
475
|
-
* Override default publish options.
|
|
476
|
-
*/
|
|
477
|
-
publish?: Options.Publish;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
export type Message = {
|
|
481
|
-
/**
|
|
482
|
-
* Routing information for amqp library.
|
|
483
|
-
* This property will be removed, before it is passed to the message queue.
|
|
484
|
-
*/
|
|
485
|
-
options?: MessageOptions;
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
*
|
|
489
|
-
* Default: <generated uuid>
|
|
490
|
-
*/
|
|
491
|
-
id: string;
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* Event- or Command-name.
|
|
495
|
-
*/
|
|
496
|
-
type: string;
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Metadata object to provide details for the message broker.
|
|
500
|
-
*
|
|
501
|
-
* Default: {}
|
|
502
|
-
*/
|
|
503
|
-
metadata: Record<string, any>;
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* The message data.
|
|
507
|
-
*
|
|
508
|
-
* Default: {}
|
|
509
|
-
*/
|
|
510
|
-
data: Record<string, any>;
|
|
511
|
-
};
|
|
410
|
+
export type ConfigInput = Partial<Exclude<Config, 'connection'>> &
|
|
411
|
+
Pick<Config, 'connection'>;
|
|
512
412
|
```
|
|
513
413
|
|
|
514
|
-
|
|
414
|
+
## License
|
|
515
415
|
|
|
516
|
-
|
|
517
|
-
import {Options} from "amqplib";
|
|
518
|
-
import {Config} from "amqp-extension";
|
|
519
|
-
|
|
520
|
-
export type PublishOptions = {
|
|
521
|
-
/**
|
|
522
|
-
* Config key or object.
|
|
523
|
-
*/
|
|
524
|
-
alias?: string | Config;
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Amqplib publish options.
|
|
528
|
-
*/
|
|
529
|
-
options?: Options.Publish;
|
|
530
|
-
}
|
|
416
|
+
Made with 💚
|
|
531
417
|
|
|
532
|
-
|
|
418
|
+
Published under [MIT License](./LICENSE).
|
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
2
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
9
|
if (k2 === undefined) k2 = k;
|
|
4
10
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -15,5 +21,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
21
|
};
|
|
16
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
23
|
__exportStar(require("./type"), exports);
|
|
24
|
+
__exportStar(require("./module"), exports);
|
|
18
25
|
__exportStar(require("./utils"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getConfig = exports.hasConfig = exports.setConfig = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const instances = {};
|
|
12
|
+
function setConfig(key, value) {
|
|
13
|
+
if (typeof key === 'string') {
|
|
14
|
+
if (typeof value === 'undefined') {
|
|
15
|
+
throw new Error(`A config must be defined for the alias: ${key}`);
|
|
16
|
+
}
|
|
17
|
+
value.alias = key;
|
|
18
|
+
instances[key] = (0, utils_1.extendConfig)(value);
|
|
19
|
+
return instances[key];
|
|
20
|
+
}
|
|
21
|
+
key.alias = (0, utils_1.getConfigKey)(key.alias);
|
|
22
|
+
instances[key.alias] = (0, utils_1.extendConfig)(key);
|
|
23
|
+
return instances[key.alias];
|
|
24
|
+
}
|
|
25
|
+
exports.setConfig = setConfig;
|
|
26
|
+
function hasConfig(key) {
|
|
27
|
+
key = (0, utils_1.getConfigKey)(key);
|
|
28
|
+
return Object.prototype.hasOwnProperty.call(instances, key);
|
|
29
|
+
}
|
|
30
|
+
exports.hasConfig = hasConfig;
|
|
31
|
+
function getConfig(key) {
|
|
32
|
+
if (typeof key === 'string' || typeof key === 'undefined') {
|
|
33
|
+
key = (0, utils_1.getConfigKey)(key);
|
|
34
|
+
const data = instances[key];
|
|
35
|
+
if (typeof data === 'undefined') {
|
|
36
|
+
throw new Error(`A config must be defined for the alias: ${key}`);
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
const config = (0, utils_1.extendConfig)(key);
|
|
41
|
+
setConfig(config);
|
|
42
|
+
return config;
|
|
43
|
+
}
|
|
44
|
+
exports.getConfig = getConfig;
|
package/dist/config/type.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { Options } from 'amqplib';
|
|
2
|
-
import {
|
|
3
|
-
import { PublishOptions } from '../
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
alias?: string;
|
|
2
|
+
import { ExchangeOptions } from '../exchange';
|
|
3
|
+
import { ConsumeOptions, PublishOptions } from '../type';
|
|
4
|
+
export type Config = {
|
|
5
|
+
alias: string;
|
|
7
6
|
connection: Options.Connect | string;
|
|
8
|
-
exchange:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
options?: Options.AssertExchange;
|
|
12
|
-
};
|
|
13
|
-
publish?: PublishOptions;
|
|
14
|
-
consume?: ConsumeOptions;
|
|
7
|
+
exchange: ExchangeOptions;
|
|
8
|
+
publish: PublishOptions;
|
|
9
|
+
consume: ConsumeOptions;
|
|
15
10
|
};
|
|
11
|
+
export type ConfigInput = Partial<Exclude<Config, 'connection'>> & Pick<Config, 'connection'>;
|
package/dist/config/type.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//# sourceMappingURL=type.js.map
|
package/dist/config/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Config } from './type';
|
|
2
|
-
export declare
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function getConfig(key?: string | Config): Config;
|
|
1
|
+
import { Config, ConfigInput } from './type';
|
|
2
|
+
export declare function getConfigKey(alias?: string): string;
|
|
3
|
+
export declare function extendConfig(input: ConfigInput): Config;
|