comq 0.4.0-dev.2 → 0.4.0-dev.6
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/.github/workflows/release.yaml +53 -0
- package/.husky/pre-commit +4 -0
- package/LICENSE +21 -0
- package/docs/notes.md +1 -1
- package/features/steps/.test/comq.mock.js +0 -2
- package/features/steps/.test/events.test.js +1 -1
- package/features/steps/broker.js +1 -1
- package/features/steps/context.js +1 -1
- package/lerna.json +5 -0
- package/package.json +31 -9
- package/readme.md +2 -1
- package/source/io.js +3 -2
- package/test/io.close.test.js +1 -1
- package/test/io.reply.test.js +1 -1
- package/test/io.request.test.js +30 -2
- package/types/io.d.ts +8 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [closed]
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
- dev
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
if: github.event.pull_request.merged == true
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- name: Setup Node
|
|
17
|
+
uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: 16
|
|
20
|
+
registry-url: 'https://registry.npmjs.org'
|
|
21
|
+
|
|
22
|
+
- name: Checkout
|
|
23
|
+
uses: actions/checkout@v3
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: npm i && npm test
|
|
29
|
+
|
|
30
|
+
- name: Bump version
|
|
31
|
+
run: |
|
|
32
|
+
git config user.name "toabot"
|
|
33
|
+
git config user.email "127577558+toabot@users.noreply.github.com"
|
|
34
|
+
|
|
35
|
+
if [ ${{ github.base_ref }} = main ]; then
|
|
36
|
+
npx lerna@6.5.1 version --conventional-graduate --no-commit-hooks --no-changelog --yes --message "chore(release): %s"
|
|
37
|
+
git fetch
|
|
38
|
+
git checkout dev
|
|
39
|
+
git merge main
|
|
40
|
+
git push --all origin --no-verify
|
|
41
|
+
else
|
|
42
|
+
npx lerna@6.5.1 version --conventional-prerelease --preid dev --no-commit-hooks --no-changelog --yes --message "chore(prerelease): %s"
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
- name: Publish packages
|
|
46
|
+
env:
|
|
47
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
48
|
+
run: |
|
|
49
|
+
if [ ${{ github.base_ref }} = main ]; then
|
|
50
|
+
npm publish
|
|
51
|
+
else
|
|
52
|
+
npm publish --tag dev
|
|
53
|
+
fi
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Toa
|
|
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/docs/notes.md
CHANGED
|
@@ -21,7 +21,7 @@ The current message is acknowledged once the Producer function is completed, whi
|
|
|
21
21
|
considered to be published when a confirmation is received from the broker.
|
|
22
22
|
|
|
23
23
|
In summary, the next "cause" message will be consumed from the queue only after the "effect" message
|
|
24
|
-
publication has been confirmed. Due to the
|
|
24
|
+
publication has been confirmed. Due to the "at least once" effect, *there is a
|
|
25
25
|
delay between the moment when a Reply **is delivered** to the Consumer and the moment when the
|
|
26
26
|
next Request is consumed from the Request queue*.
|
|
27
27
|
|
|
@@ -52,7 +52,7 @@ describe('Given (that ){token} is consuming events from the {token} exchange', (
|
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
describe('Given {token} consuming events from the {token} exchange is expected', () => {
|
|
55
|
-
|
|
55
|
+
tomato.steps.Gi('{token} consuming events from the {token} exchange is expected')
|
|
56
56
|
|
|
57
57
|
it('should be', async () => undefined)
|
|
58
58
|
})
|
package/features/steps/broker.js
CHANGED
package/lerna.json
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comq",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.6",
|
|
4
4
|
"description": "ComQ",
|
|
5
|
-
"homepage": "https://toa.io",
|
|
6
5
|
"author": {
|
|
7
6
|
"name": "Artem Gurtovoi",
|
|
8
7
|
"url": "https://github.com/temich"
|
|
@@ -10,10 +9,10 @@
|
|
|
10
9
|
"license": "MIT",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/toa-io/
|
|
12
|
+
"url": "git+https://github.com/toa-io/comq.git"
|
|
14
13
|
},
|
|
15
14
|
"bugs": {
|
|
16
|
-
"url": "https://github.com/toa-io/
|
|
15
|
+
"url": "https://github.com/toa-io/comq/issues"
|
|
17
16
|
},
|
|
18
17
|
"engines": {
|
|
19
18
|
"node": ">= 12.0.0"
|
|
@@ -24,13 +23,36 @@
|
|
|
24
23
|
"main": "source/index.js",
|
|
25
24
|
"types": "types/index.d.ts",
|
|
26
25
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@toa.io/
|
|
29
|
-
"@toa.io/
|
|
26
|
+
"@cucumber/cucumber": "9.0.0",
|
|
27
|
+
"@toa.io/command": "0.3.0",
|
|
28
|
+
"@toa.io/mock": "0.3.0",
|
|
29
|
+
"@toa.io/tomato": "0.4.0-dev.2",
|
|
30
|
+
"@toa.io/yaml": "0.4.0-dev.2",
|
|
31
|
+
"@types/amqplib": "0.10.1",
|
|
32
|
+
"@types/jest": "29.4.2",
|
|
33
|
+
"husky": "8.0.3",
|
|
34
|
+
"jest": "29.5.0",
|
|
35
|
+
"randomstring": "1.2.3",
|
|
36
|
+
"snazzy": "9.0.0",
|
|
37
|
+
"standard": "17.0.0"
|
|
30
38
|
},
|
|
31
39
|
"dependencies": {
|
|
32
|
-
"@toa.io/generic": "0.
|
|
40
|
+
"@toa.io/generic": "0.3.0",
|
|
33
41
|
"amqplib": "0.10.3",
|
|
34
42
|
"msgpackr": "1.8.5"
|
|
35
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"prepare": "husky install",
|
|
46
|
+
"test": "npm run lint && jest",
|
|
47
|
+
"test:features": "npx cucumber-js",
|
|
48
|
+
"lint": "npx standard --verbose | npx snazzy"
|
|
49
|
+
},
|
|
50
|
+
"standard": {
|
|
51
|
+
"env": [
|
|
52
|
+
"jest"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"workspaces": [
|
|
56
|
+
"."
|
|
57
|
+
]
|
|
36
58
|
}
|
package/readme.md
CHANGED
|
@@ -51,7 +51,8 @@ await io.close()
|
|
|
51
51
|
|
|
52
52
|
The following documentation refers to a few terms:
|
|
53
53
|
|
|
54
|
-
**Request** is an AMQP message that has the `replyTo` and `correlationId`
|
|
54
|
+
**Request** is an AMQP message that is sent to a queue and has the `replyTo` and `correlationId`
|
|
55
|
+
properties set.
|
|
55
56
|
|
|
56
57
|
**Reply** is an AMQP message sent in response to a Request and sent to the queue specified in
|
|
57
58
|
the `replyTo` property of the Request. The `correlationId` property of the Reply is set to the same
|
package/source/io.js
CHANGED
|
@@ -61,13 +61,14 @@ class IO {
|
|
|
61
61
|
* @param {string} queue
|
|
62
62
|
* @param {any} payload
|
|
63
63
|
* @param {comq.encoding} [encoding]
|
|
64
|
+
* @param {comq.ReplyToPropertyFormatter} replyToFormatter
|
|
64
65
|
* @returns {Promise<void>}
|
|
65
66
|
*/
|
|
66
|
-
async (queue, payload, encoding) => {
|
|
67
|
+
async (queue, payload, encoding, replyToFormatter) => {
|
|
67
68
|
const [buffer, contentType] = this.#encode(payload, encoding)
|
|
68
69
|
const correlationId = randomBytes(8).toString('hex')
|
|
69
70
|
const emitter = this.#emitters[queue]
|
|
70
|
-
const replyTo = emitter.queue
|
|
71
|
+
const replyTo = replyToFormatter?.(emitter.queue) ?? emitter.queue
|
|
71
72
|
const properties = { contentType, correlationId, replyTo }
|
|
72
73
|
const reply = this.#createReply()
|
|
73
74
|
|
package/test/io.close.test.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const { randomBytes } = require('node:crypto')
|
|
3
4
|
const { generate } = require('randomstring')
|
|
4
5
|
const { promex, immediate } = require('@toa.io/generic')
|
|
5
6
|
|
|
6
7
|
const mock = require('./connection.mock')
|
|
7
8
|
const { IO } = require('../source/io')
|
|
8
|
-
const { randomBytes } = require('crypto')
|
|
9
9
|
|
|
10
10
|
/** @type {comq.IO} */
|
|
11
11
|
let io
|
package/test/io.reply.test.js
CHANGED
package/test/io.request.test.js
CHANGED
|
@@ -43,6 +43,8 @@ let promise
|
|
|
43
43
|
const REPLY = new RegExp(`^${queue}..[0-9a-f]+$`)
|
|
44
44
|
|
|
45
45
|
beforeEach(async () => {
|
|
46
|
+
jest.clearAllMocks()
|
|
47
|
+
|
|
46
48
|
promise = io.request(queue, payload)
|
|
47
49
|
|
|
48
50
|
// allows initializers to run
|
|
@@ -82,10 +84,36 @@ describe('send', () => {
|
|
|
82
84
|
})
|
|
83
85
|
|
|
84
86
|
it('should set replyTo', async () => {
|
|
85
|
-
const
|
|
87
|
+
const properties = call[2]
|
|
88
|
+
const rx = new RegExp(`^${queue}..[a-z0-9]+`)
|
|
89
|
+
|
|
90
|
+
expect(properties.replyTo).toMatch(rx)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should set replyTo using specified formatter', async () => {
|
|
94
|
+
jest.clearAllMocks()
|
|
95
|
+
|
|
96
|
+
/** @type {comq.encoding} */
|
|
97
|
+
const prefix = generate()
|
|
98
|
+
const encoding = 'application/json'
|
|
99
|
+
const formatter = (replyTo) => prefix + replyTo
|
|
100
|
+
|
|
101
|
+
promise = io.request(queue, payload, encoding, formatter)
|
|
102
|
+
|
|
103
|
+
await immediate()
|
|
104
|
+
|
|
105
|
+
call = requests.send.mock.calls[0]
|
|
106
|
+
|
|
107
|
+
const properties = requests.send.mock.calls[0][2]
|
|
108
|
+
|
|
109
|
+
expect(properties.replyTo).toMatch(new RegExp(`${prefix}${queue}..[a-z0-9]+`))
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('should consume replyTo', async () => {
|
|
113
|
+
const properties = call[2]
|
|
86
114
|
const queue = replies.consume.mock.calls[0][0]
|
|
87
115
|
|
|
88
|
-
expect(
|
|
116
|
+
expect(properties.replyTo).toStrictEqual(queue)
|
|
89
117
|
})
|
|
90
118
|
|
|
91
119
|
it('should encode message with msgpack by default', async () => {
|
package/types/io.d.ts
CHANGED
|
@@ -16,10 +16,17 @@ declare namespace comq {
|
|
|
16
16
|
clear(): void
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
type ReplyToPropertyFormatter = (queue: string) => string
|
|
20
|
+
|
|
19
21
|
interface IO {
|
|
20
22
|
reply(queue: string, produce: producer): Promise<void>
|
|
21
23
|
|
|
22
|
-
request(
|
|
24
|
+
request(
|
|
25
|
+
queue: string,
|
|
26
|
+
payload: any,
|
|
27
|
+
encoding?: _encoding.encoding,
|
|
28
|
+
replyToFormatter?: ReplyToPropertyFormatter)
|
|
29
|
+
: Promise<any>
|
|
23
30
|
|
|
24
31
|
consume(exchange: string, group: string, consumer: consumer): Promise<void>
|
|
25
32
|
|