comq 0.4.0-dev.5 → 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/lerna.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "useWorkspaces": true,
3
- "version": "0.4.0-dev.0",
3
+ "version": "0.4.0-dev.6",
4
4
  "conventionalCommits": true
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comq",
3
- "version": "0.4.0-dev.5",
3
+ "version": "0.4.0-dev.6",
4
4
  "description": "ComQ",
5
5
  "author": {
6
6
  "name": "Artem Gurtovoi",
package/readme.md CHANGED
@@ -94,7 +94,7 @@ await io.reply('add_numbers', ({ a, b }) => (a + b))
94
94
 
95
95
  ## Request
96
96
 
97
- `async IO.request(queue: string, payload: any, [encoding: string, replyTo: string])`
97
+ `async IO.request(queue: string, payload: any, [encoding: string])`
98
98
 
99
99
  Send encoded Request message with `replyTo` and `correlationId` properties set and
100
100
  return decoded Reply content.
package/source/io.js CHANGED
@@ -61,16 +61,14 @@ class IO {
61
61
  * @param {string} queue
62
62
  * @param {any} payload
63
63
  * @param {comq.encoding} [encoding]
64
- * @param {string} replyTo
64
+ * @param {comq.ReplyToPropertyFormatter} replyToFormatter
65
65
  * @returns {Promise<void>}
66
66
  */
67
- async (queue, payload, encoding, replyTo) => {
67
+ async (queue, payload, encoding, replyToFormatter) => {
68
68
  const [buffer, contentType] = this.#encode(payload, encoding)
69
69
  const correlationId = randomBytes(8).toString('hex')
70
70
  const emitter = this.#emitters[queue]
71
-
72
- replyTo ??= emitter.queue
73
-
71
+ const replyTo = replyToFormatter?.(emitter.queue) ?? emitter.queue
74
72
  const properties = { contentType, correlationId, replyTo }
75
73
  const reply = this.#createReply()
76
74
 
@@ -83,21 +83,22 @@ describe('send', () => {
83
83
  expect(typeof properties.correlationId).toStrictEqual('string')
84
84
  })
85
85
 
86
- it('should set default replyTo', async () => {
86
+ it('should set replyTo', async () => {
87
87
  const properties = call[2]
88
88
  const rx = new RegExp(`^${queue}..[a-z0-9]+`)
89
89
 
90
90
  expect(properties.replyTo).toMatch(rx)
91
91
  })
92
92
 
93
- it('should set specified replyTo', async () => {
93
+ it('should set replyTo using specified formatter', async () => {
94
94
  jest.clearAllMocks()
95
95
 
96
96
  /** @type {comq.encoding} */
97
+ const prefix = generate()
97
98
  const encoding = 'application/json'
98
- const replyTo = generate()
99
+ const formatter = (replyTo) => prefix + replyTo
99
100
 
100
- promise = io.request(queue, payload, encoding, replyTo)
101
+ promise = io.request(queue, payload, encoding, formatter)
101
102
 
102
103
  await immediate()
103
104
 
@@ -105,7 +106,7 @@ describe('send', () => {
105
106
 
106
107
  const properties = requests.send.mock.calls[0][2]
107
108
 
108
- expect(properties.replyTo).toStrictEqual(replyTo)
109
+ expect(properties.replyTo).toMatch(new RegExp(`${prefix}${queue}..[a-z0-9]+`))
109
110
  })
110
111
 
111
112
  it('should consume replyTo', 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(queue: string, payload: any, encoding?: _encoding.encoding, replyTo?: string): Promise<any>
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