@nxtedition/deepstream.io-client-js 26.0.22 → 26.0.24
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,104 +1,25 @@
|
|
|
1
1
|
import * as C from '../constants/constants.js'
|
|
2
|
-
import * as utils from '../utils/utils.js'
|
|
3
|
-
import varint from 'varint'
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
// TODO (fix): Don't assume maxMesageSize is 1MB
|
|
8
|
-
const maxMessageSize = 1024 * 1024
|
|
9
|
-
const poolSize = maxMessageSize * 4
|
|
10
|
-
|
|
11
|
-
let poolBuffer
|
|
12
|
-
let poolView
|
|
13
|
-
let poolOffset
|
|
14
|
-
|
|
15
|
-
function reallocPool() {
|
|
16
|
-
poolBuffer = utils.isNode
|
|
17
|
-
? globalThis.Buffer.allocUnsafe(poolSize)
|
|
18
|
-
: new Uint8Array(new ArrayBuffer(poolSize))
|
|
19
|
-
poolView = new DataView(poolBuffer.buffer)
|
|
20
|
-
poolOffset = 0
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function alignPool() {
|
|
24
|
-
// Ensure aligned slices
|
|
25
|
-
if (poolOffset & 0x7) {
|
|
26
|
-
poolOffset |= 0x7
|
|
27
|
-
poolOffset++
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function writeString(dst, str, offset) {
|
|
32
|
-
if (utils.isNode) {
|
|
33
|
-
return dst.write(str, offset)
|
|
34
|
-
} else {
|
|
35
|
-
const res = poolEncoder.encodeInto(str, new Uint8Array(dst.buffer, offset))
|
|
36
|
-
return res.written
|
|
37
|
-
}
|
|
38
|
-
}
|
|
3
|
+
const SEP = C.MESSAGE_PART_SEPERATOR
|
|
39
4
|
|
|
40
5
|
export function getMsg(topic, action, data) {
|
|
41
6
|
if (data && !(data instanceof Array)) {
|
|
42
7
|
throw new Error('data must be an array')
|
|
43
8
|
}
|
|
44
9
|
|
|
45
|
-
|
|
46
|
-
reallocPool()
|
|
47
|
-
} else {
|
|
48
|
-
alignPool()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const start = poolOffset
|
|
52
|
-
|
|
53
|
-
const headerSize = 8
|
|
54
|
-
for (let n = 0; n < headerSize; n++) {
|
|
55
|
-
poolBuffer[poolOffset++] = 0
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let headerPos = start
|
|
59
|
-
poolBuffer[headerPos++] = 128 + headerSize
|
|
60
|
-
|
|
61
|
-
poolBuffer[poolOffset++] = topic.charCodeAt(0)
|
|
62
|
-
poolBuffer[poolOffset++] = 31
|
|
63
|
-
for (let n = 0; n < action.length; n++) {
|
|
64
|
-
poolBuffer[poolOffset++] = action.charCodeAt(n)
|
|
65
|
-
}
|
|
10
|
+
const sendData = [topic, action]
|
|
66
11
|
|
|
67
12
|
if (data) {
|
|
68
13
|
for (let i = 0; i < data.length; i++) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (data[i] == null) {
|
|
72
|
-
poolBuffer[poolOffset++] = 31
|
|
73
|
-
len = 0
|
|
74
|
-
} else if (type === 'object') {
|
|
75
|
-
poolBuffer[poolOffset++] = 31
|
|
76
|
-
len = writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
|
|
77
|
-
} else if (type === 'bigint') {
|
|
78
|
-
poolBuffer[poolOffset++] = 31
|
|
79
|
-
poolView.setBigUint64(poolOffset, data[i], false)
|
|
80
|
-
len = 8
|
|
81
|
-
} else if (type === 'string') {
|
|
82
|
-
poolBuffer[poolOffset++] = 31
|
|
83
|
-
len = writeString(poolBuffer, data[i], poolOffset)
|
|
14
|
+
if (typeof data[i] === 'object') {
|
|
15
|
+
sendData.push(JSON.stringify(data[i]))
|
|
84
16
|
} else {
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
poolOffset += len
|
|
88
|
-
|
|
89
|
-
varint.encode(len + 1, poolBuffer, headerPos)
|
|
90
|
-
headerPos += varint.encode.bytes
|
|
91
|
-
if (headerPos - start >= headerSize) {
|
|
92
|
-
throw new Error('header too large')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (poolOffset >= poolSize) {
|
|
96
|
-
throw new Error('message too large')
|
|
17
|
+
sendData.push(data[i])
|
|
97
18
|
}
|
|
98
19
|
}
|
|
99
20
|
}
|
|
100
21
|
|
|
101
|
-
return
|
|
22
|
+
return sendData.join(SEP)
|
|
102
23
|
}
|
|
103
24
|
|
|
104
25
|
export function typed(value) {
|
package/src/record/record.js
CHANGED
|
@@ -389,7 +389,7 @@ class Record {
|
|
|
389
389
|
this._version = nextVersion
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
_onUpdate([, version, data
|
|
392
|
+
_onUpdate([, version, data]) {
|
|
393
393
|
const prevData = this._data
|
|
394
394
|
const prevVersion = this._version
|
|
395
395
|
const prevState = this._state
|
|
@@ -422,9 +422,7 @@ class Record {
|
|
|
422
422
|
this._onPatching(false)
|
|
423
423
|
}
|
|
424
424
|
|
|
425
|
-
if (
|
|
426
|
-
this._state = C.RECORD_STATE.PROVIDER
|
|
427
|
-
} else if (this._state < C.RECORD_STATE.SERVER) {
|
|
425
|
+
if (this._state < C.RECORD_STATE.SERVER) {
|
|
428
426
|
this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
|
|
429
427
|
}
|
|
430
428
|
|