@nxtedition/deepstream.io-client-js 24.3.2 → 24.3.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/deepstream.io-client-js",
|
|
3
|
-
"version": "24.3.
|
|
3
|
+
"version": "24.3.3",
|
|
4
4
|
"description": "the javascript client for deepstream.io",
|
|
5
5
|
"homepage": "http://deepstream.io",
|
|
6
6
|
"type": "module",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"invariant": "^2.2.4",
|
|
66
66
|
"lodash.clonedeep": "^4.5.0",
|
|
67
67
|
"utf-8-validate": "^6.0.3",
|
|
68
|
+
"varint": "^6.0.0",
|
|
68
69
|
"ws": "^8.13.0",
|
|
69
70
|
"xuid": "^4.1.2",
|
|
70
71
|
"xxhash-wasm": "^1.0.2"
|
|
@@ -151,8 +151,8 @@ Connection.prototype.send = function (message) {
|
|
|
151
151
|
Connection.prototype._submit = function (message) {
|
|
152
152
|
const { maxPacketSize } = this._options
|
|
153
153
|
|
|
154
|
-
if (message.
|
|
155
|
-
const err = new Error(`Packet to big: ${message.
|
|
154
|
+
if (message.byteLength > maxPacketSize) {
|
|
155
|
+
const err = new Error(`Packet to big: ${message.byteLength} > ${maxPacketSize}`)
|
|
156
156
|
this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
|
|
157
157
|
return false
|
|
158
158
|
} else if (this._endpoint.readyState === this._endpoint.OPEN) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as C from '../constants/constants.js'
|
|
2
|
+
import varint from 'varint'
|
|
2
3
|
|
|
3
4
|
const poolEncoder = new TextEncoder()
|
|
4
5
|
|
|
@@ -8,7 +9,7 @@ let poolView
|
|
|
8
9
|
let poolOffset
|
|
9
10
|
|
|
10
11
|
function reallocPool(size) {
|
|
11
|
-
poolSize = size
|
|
12
|
+
poolSize = size || poolSize || 1024 * 1024
|
|
12
13
|
poolBuffer = new Uint8Array(new ArrayBuffer(poolSize))
|
|
13
14
|
poolView = new DataView(poolBuffer.buffer)
|
|
14
15
|
poolOffset = 0
|
|
@@ -22,14 +23,12 @@ function alignPool() {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
reallocPool()
|
|
26
|
-
|
|
27
26
|
export function getMsg(topic, action, data) {
|
|
28
27
|
if (data && !(data instanceof Array)) {
|
|
29
28
|
throw new Error('data must be an array')
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
if (poolOffset + poolSize / 16 >= poolSize) {
|
|
31
|
+
if (!poolSize || poolOffset + poolSize / 16 >= poolSize) {
|
|
33
32
|
reallocPool()
|
|
34
33
|
} else {
|
|
35
34
|
alignPool()
|
|
@@ -37,6 +36,11 @@ export function getMsg(topic, action, data) {
|
|
|
37
36
|
|
|
38
37
|
const start = poolOffset
|
|
39
38
|
|
|
39
|
+
const headerSize = 8
|
|
40
|
+
poolBuffer[poolOffset++] = 128 + headerSize
|
|
41
|
+
let headerPos = poolOffset
|
|
42
|
+
poolOffset += headerSize - 1
|
|
43
|
+
|
|
40
44
|
poolBuffer[poolOffset++] = topic.charCodeAt(0)
|
|
41
45
|
poolBuffer[poolOffset++] = 31
|
|
42
46
|
for (let n = 0; n < action.length; n++) {
|
|
@@ -46,33 +50,44 @@ export function getMsg(topic, action, data) {
|
|
|
46
50
|
if (data) {
|
|
47
51
|
for (let i = 0; i < data.length; i++) {
|
|
48
52
|
const type = typeof data[i]
|
|
53
|
+
let len
|
|
49
54
|
if (data[i] == null) {
|
|
50
55
|
poolBuffer[poolOffset++] = 31
|
|
56
|
+
len = 0
|
|
51
57
|
} else if (type === 'object') {
|
|
52
58
|
poolBuffer[poolOffset++] = 31
|
|
53
59
|
const res = poolEncoder.encodeInto(
|
|
54
60
|
JSON.stringify(data[i]),
|
|
55
61
|
new Uint8Array(poolBuffer.buffer, poolOffset)
|
|
56
62
|
)
|
|
57
|
-
|
|
63
|
+
len = res.written
|
|
58
64
|
} else if (type === 'bigint') {
|
|
59
65
|
poolBuffer[poolOffset++] = 31
|
|
60
66
|
poolView.setBigUint64(poolOffset, data[i], false)
|
|
61
|
-
|
|
67
|
+
len = 8
|
|
62
68
|
} else if (type === 'string') {
|
|
63
69
|
poolBuffer[poolOffset++] = 31
|
|
64
70
|
const res = poolEncoder.encodeInto(data[i], new Uint8Array(poolBuffer.buffer, poolOffset))
|
|
65
|
-
|
|
71
|
+
len = res.written
|
|
66
72
|
} else {
|
|
67
73
|
throw new Error('invalid data')
|
|
68
74
|
}
|
|
69
75
|
|
|
76
|
+
poolOffset += len
|
|
77
|
+
|
|
78
|
+
varint.encode(len + 1, poolBuffer, headerPos)
|
|
79
|
+
headerPos += varint.encode.bytes
|
|
80
|
+
if (headerPos - start >= headerSize) {
|
|
81
|
+
throw new Error(`header too large: ${headerPos - start} ${headerSize}`)
|
|
82
|
+
}
|
|
83
|
+
|
|
70
84
|
if (poolOffset >= poolBuffer.length) {
|
|
71
85
|
reallocPool(start === 0 ? poolSize * 2 : poolSize)
|
|
72
86
|
return getMsg(topic, action, data)
|
|
73
87
|
}
|
|
74
88
|
}
|
|
75
89
|
}
|
|
90
|
+
|
|
76
91
|
return new Uint8Array(poolBuffer.buffer, start, poolOffset - start)
|
|
77
92
|
}
|
|
78
93
|
|
|
@@ -101,6 +101,7 @@ class RecordHandler {
|
|
|
101
101
|
this._pruning = new Set()
|
|
102
102
|
this._patching = new Map()
|
|
103
103
|
this._updating = new Map()
|
|
104
|
+
this._encoder = new TextEncoder()
|
|
104
105
|
|
|
105
106
|
this._connected = 0
|
|
106
107
|
this._stats = {
|
|
@@ -206,6 +207,12 @@ class RecordHandler {
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
_getKey(name) {
|
|
211
|
+
return name.length <= 8 && this._encoder.encode(name).byteLength === 8
|
|
212
|
+
? name
|
|
213
|
+
: this._connection.hasher.h64(name)
|
|
214
|
+
}
|
|
215
|
+
|
|
209
216
|
/**
|
|
210
217
|
* @param {string} name
|
|
211
218
|
* @returns {Record}
|
|
@@ -219,7 +226,7 @@ class RecordHandler {
|
|
|
219
226
|
let record = this._records.get(name)
|
|
220
227
|
|
|
221
228
|
if (!record) {
|
|
222
|
-
record = new Record(name, this)
|
|
229
|
+
record = new Record(this._getKey(name), name, this)
|
|
223
230
|
this._stats.records += 1
|
|
224
231
|
this._stats.created += 1
|
|
225
232
|
this._records.set(name, record)
|
package/src/record/record.js
CHANGED
|
@@ -12,18 +12,13 @@ import * as timers from '../utils/timers.js'
|
|
|
12
12
|
class Record {
|
|
13
13
|
static STATE = C.RECORD_STATE
|
|
14
14
|
|
|
15
|
-
constructor(name, handler) {
|
|
15
|
+
constructor(key, name, handler) {
|
|
16
16
|
const connection = handler._connection
|
|
17
17
|
|
|
18
18
|
this._handler = handler
|
|
19
19
|
|
|
20
|
-
// TODO (fix): Implement this once we have binary header.
|
|
21
|
-
// this._key = name.length <= 8 && encoder.encode(name).byteLength === 8
|
|
22
|
-
// ? name
|
|
23
|
-
// : connection.hasher?.h64(name)
|
|
24
|
-
|
|
25
20
|
this._name = name
|
|
26
|
-
this._key =
|
|
21
|
+
this._key = key
|
|
27
22
|
this._version = ''
|
|
28
23
|
this._data = jsonPath.EMPTY
|
|
29
24
|
this._state = C.RECORD_STATE.VOID
|