comq 0.11.2 → 0.11.3

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,4 +1,4 @@
1
1
  {
2
- "version": "0.11.2",
2
+ "version": "0.11.3",
3
3
  "conventionalCommits": true
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comq",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "ComQ",
5
5
  "author": {
6
6
  "name": "Artem Gurtovoi",
package/readme.md CHANGED
@@ -283,9 +283,9 @@ At the same time, there is no guarantee that the stream will be transmitted to t
283
283
 
284
284
  ## Encoding
285
285
 
286
- By default, outgoing message contents are encoded with [msgpack](https://msgpack.org) and
287
- the `contentType` property is set to `application/msgpack`. If the encoding format is
288
- specified ([request](#request), [emit](#emission)), contents are encoded accordingly.
286
+ By default, outgoing message contents are encoded with JSON and
287
+ the `contentType` property is set to `application/json`.
288
+ If the encoding format is specified ([request](#request), [emit](#emission)), contents are encoded accordingly.
289
289
 
290
290
  Exceptions are Buffers, which are sent without encoding and the `contentType` property set
291
291
  to specified encoding format or `application/octet-stream` by default.
@@ -298,8 +298,8 @@ If the specified encoding format is not supported, an exception will be thrown.
298
298
 
299
299
  The following encoding formats are supported:
300
300
 
301
- - `application/msgpack`
302
301
  - `application/json`
302
+ - `application/msgpack`
303
303
  - `application/octet-stream`
304
304
  - `text/plain`
305
305
 
@@ -5,6 +5,8 @@
5
5
  * @returns {Buffer}
6
6
  */
7
7
  const encode = (value) => {
8
+ if (value === undefined) { return Buffer.alloc(0) }
9
+
8
10
  const json = JSON.stringify(value)
9
11
 
10
12
  return Buffer.from(json)
@@ -14,6 +16,8 @@ const encode = (value) => {
14
16
  * @param {Buffer} buffer
15
17
  */
16
18
  const decode = (buffer) => {
19
+ if (buffer.length === 0) { return undefined }
20
+
17
21
  const json = buffer.toString()
18
22
 
19
23
  return JSON.parse(json)
package/source/io.js CHANGED
@@ -452,7 +452,7 @@ class IO {
452
452
  const OCTETS = 'application/octet-stream'
453
453
 
454
454
  /** @type {comq.Encoding} */
455
- const DEFAULT = 'application/msgpack'
455
+ const DEFAULT = 'application/json'
456
456
 
457
457
  const RETRANSMISSION = /** @type {Error} */ Symbol('retransmission')
458
458
 
@@ -64,8 +64,8 @@ it('should publish stream of events', async () => {
64
64
  expect(events.publish).toHaveBeenCalledTimes(10)
65
65
  })
66
66
 
67
- it('should encode message as msgpack by default', async () => {
68
- const encoding = 'application/msgpack'
67
+ it('should encode message as json by default', async () => {
68
+ const encoding = 'application/json'
69
69
  const buf = encode(payload, encoding)
70
70
  const [, buffer, properties] = events.publish.mock.calls[0]
71
71
 
@@ -96,9 +96,9 @@ describe('send', () => {
96
96
  expect(properties.replyTo).toStrictEqual(queue)
97
97
  })
98
98
 
99
- it('should encode message with msgpack by default', async () => {
99
+ it('should encode message with json by default', async () => {
100
100
  /** @type {comq.Encoding} */
101
- const contentType = 'application/msgpack'
101
+ const contentType = 'application/json'
102
102
  const buffer = encode(payload, contentType)
103
103
 
104
104
  expect(call[1]).toStrictEqual(buffer)
package/types/io.d.ts CHANGED
@@ -51,7 +51,7 @@ declare namespace comq {
51
51
 
52
52
  enqueue (exchange: string, stream: Readable, properties?: _amqp.Properties): Promise<void>
53
53
 
54
- process<T = any> (queue: string, consumer: Consumer<T>): Promise<void>
54
+ process<T = any> (queue: string, processor: Consumer<T>): Promise<void>
55
55
 
56
56
  seal (): Promise<void>
57
57