@nxtedition/deepstream.io-client-js 26.0.8 → 26.0.10

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": "26.0.8",
3
+ "version": "26.0.10",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -1,5 +1,6 @@
1
1
  import * as C from '../constants/constants.js'
2
2
  import varint from 'varint'
3
+ import * as utils from '../utils/utils.js'
3
4
 
4
5
  const poolEncoder = new TextEncoder()
5
6
 
@@ -8,9 +9,11 @@ let poolBuffer
8
9
  let poolView
9
10
  let poolOffset
10
11
 
11
- function reallocPool(size) {
12
+ function allocPool(size) {
12
13
  poolSize = size || poolSize || 1024 * 1024
13
- poolBuffer = new Uint8Array(new ArrayBuffer(poolSize))
14
+ poolBuffer = utils.isNode
15
+ ? globalThis.Buffer.allocUnsafe(poolSize)
16
+ : new Uint8Array(new ArrayBuffer(poolSize))
14
17
  poolView = new DataView(poolBuffer.buffer)
15
18
  poolOffset = 0
16
19
  }
@@ -23,13 +26,22 @@ function alignPool() {
23
26
  }
24
27
  }
25
28
 
29
+ function writeString(dst, str, offset) {
30
+ if (utils.isNode) {
31
+ return dst.write(str, offset)
32
+ } else {
33
+ const res = poolEncoder.encodeInto(str, new Uint8Array(dst.buffer, offset))
34
+ return res.written
35
+ }
36
+ }
37
+
26
38
  export function getMsg(topic, action, data) {
27
39
  if (data && !(data instanceof Array)) {
28
40
  throw new Error('data must be an array')
29
41
  }
30
42
 
31
43
  if (!poolSize || poolOffset + poolSize / 16 >= poolSize) {
32
- reallocPool()
44
+ allocPool()
33
45
  } else {
34
46
  alignPool()
35
47
  }
@@ -56,19 +68,14 @@ export function getMsg(topic, action, data) {
56
68
  len = 0
57
69
  } else if (type === 'object') {
58
70
  poolBuffer[poolOffset++] = 31
59
- const res = poolEncoder.encodeInto(
60
- JSON.stringify(data[i]),
61
- new Uint8Array(poolBuffer.buffer, poolOffset),
62
- )
63
- len = res.written
71
+ len = writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
64
72
  } else if (type === 'bigint') {
65
73
  poolBuffer[poolOffset++] = 31
66
74
  poolView.setBigUint64(poolOffset, data[i], false)
67
75
  len = 8
68
76
  } else if (type === 'string') {
69
77
  poolBuffer[poolOffset++] = 31
70
- const res = poolEncoder.encodeInto(data[i], new Uint8Array(poolBuffer.buffer, poolOffset))
71
- len = res.written
78
+ len = writeString(poolBuffer, data[i], poolOffset)
72
79
  } else {
73
80
  throw new Error('invalid data')
74
81
  }
@@ -82,7 +89,7 @@ export function getMsg(topic, action, data) {
82
89
  }
83
90
 
84
91
  if (poolOffset >= poolBuffer.length) {
85
- reallocPool(start === 0 ? poolSize * 2 : poolSize)
92
+ allocPool(start === 0 ? poolSize * 2 : poolSize)
86
93
  return getMsg(topic, action, data)
87
94
  }
88
95
  }
@@ -392,7 +392,7 @@ class Record {
392
392
  this._version = nextVersion
393
393
  }
394
394
 
395
- _onUpdate([, version, data]) {
395
+ _onUpdate([, version, data, hasProvider]) {
396
396
  const prevData = this._data
397
397
  const prevVersion = this._version
398
398
  const prevState = this._state
@@ -425,7 +425,9 @@ class Record {
425
425
  this._onPatching(false)
426
426
  }
427
427
 
428
- if (this._state < C.RECORD_STATE.SERVER) {
428
+ if (this._state < C.RECORD_STATE.PROVIDER && hasProvider === 'T') {
429
+ this._state = C.RECORD_STATE.PROVIDER
430
+ } else if (this._state < C.RECORD_STATE.SERVER) {
429
431
  this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
430
432
  }
431
433