@nxtedition/deepstream.io-client-js 28.0.1 → 28.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "28.0.1",
3
+ "version": "28.0.2",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -1,81 +1,25 @@
1
1
  import * as C from '../constants/constants.js'
2
- import * as utils from '../utils/utils.js'
3
2
 
4
- const poolEncoder = new globalThis.TextEncoder()
5
-
6
- // TODO (fix): Don't assume maxMesageSize is 1MB
7
- const maxMessageSize = 1024 * 1024
8
- const poolSize = maxMessageSize * 8
9
-
10
- let poolBuffer
11
- let poolOffset
12
-
13
- function reallocPool() {
14
- poolBuffer = utils.isNode
15
- ? globalThis.Buffer.allocUnsafe(poolSize)
16
- : new Uint8Array(new ArrayBuffer(poolSize))
17
- poolOffset = 0
18
- }
19
-
20
- function alignPool() {
21
- // Ensure aligned slices
22
- if (poolOffset & 0x7) {
23
- poolOffset |= 0x7
24
- poolOffset++
25
- }
26
- }
27
-
28
- function writeString(dst, str, offset) {
29
- if (utils.isNode) {
30
- return dst.write(str, offset)
31
- } else {
32
- const res = poolEncoder.encodeInto(str, new Uint8Array(dst.buffer, offset))
33
- return res.written
34
- }
35
- }
3
+ const SEP = C.MESSAGE_PART_SEPERATOR
36
4
 
37
5
  export function getMsg(topic, action, data) {
38
6
  if (data && !(data instanceof Array)) {
39
7
  throw new Error('data must be an array')
40
8
  }
41
9
 
42
- if (!poolBuffer || poolOffset + maxMessageSize > poolSize) {
43
- reallocPool()
44
- } else {
45
- alignPool()
46
- }
47
-
48
- const start = poolOffset
49
-
50
- poolBuffer[poolOffset++] = topic.charCodeAt(0)
51
- poolBuffer[poolOffset++] = 31
52
- for (let n = 0; n < action.length; n++) {
53
- poolBuffer[poolOffset++] = action.charCodeAt(n)
54
- }
10
+ const sendData = [topic, action]
55
11
 
56
12
  if (data) {
57
13
  for (let i = 0; i < data.length; i++) {
58
- const type = typeof data[i]
59
- if (data[i] == null) {
60
- poolBuffer[poolOffset++] = 31
61
- poolOffset += 0
62
- } else if (type === 'object') {
63
- poolBuffer[poolOffset++] = 31
64
- poolOffset += writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
65
- } else if (type === 'string') {
66
- poolBuffer[poolOffset++] = 31
67
- poolOffset += writeString(poolBuffer, data[i], poolOffset)
14
+ if (typeof data[i] === 'object') {
15
+ sendData.push(JSON.stringify(data[i]))
68
16
  } else {
69
- throw new Error('invalid data')
70
- }
71
-
72
- if (poolOffset >= poolSize) {
73
- throw new Error('message too large')
17
+ sendData.push(data[i])
74
18
  }
75
19
  }
76
20
  }
77
21
 
78
- return new Uint8Array(poolBuffer.buffer, start, poolOffset - start)
22
+ return sendData.join(SEP)
79
23
  }
80
24
 
81
25
  export function typed(value) {