@nxtedition/deepstream.io-client-js 24.2.10 → 24.3.1
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
|
@@ -82,14 +82,6 @@ Connection.prototype.sendMsg = function (topic, action, data) {
|
|
|
82
82
|
return this.send(messageBuilder.getMsg(topic, action, data))
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
Connection.prototype.sendMsg1 = function (topic, action, p0) {
|
|
86
|
-
return this.send(messageBuilder.getMsg1(topic, action, p0))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
Connection.prototype.sendMsg2 = function (topic, action, p0, p1) {
|
|
90
|
-
return this.send(messageBuilder.getMsg2(topic, action, p0, p1))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
85
|
Connection.prototype.close = function () {
|
|
94
86
|
this._deliberateClose = true
|
|
95
87
|
this._endpoint?.close()
|
|
@@ -1,33 +1,79 @@
|
|
|
1
1
|
const C = require('../constants/constants')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const poolEncoder = new TextEncoder()
|
|
4
|
+
|
|
5
|
+
let poolSize
|
|
6
|
+
let poolBuffer
|
|
7
|
+
let poolView
|
|
8
|
+
let poolOffset
|
|
9
|
+
|
|
10
|
+
function reallocPool(size) {
|
|
11
|
+
poolSize = size ?? poolSize ?? 1024 * 1024
|
|
12
|
+
poolBuffer = new Uint8Array(new ArrayBuffer(poolSize))
|
|
13
|
+
poolView = new DataView(poolBuffer.buffer)
|
|
14
|
+
poolOffset = 0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function alignPool() {
|
|
18
|
+
// Ensure aligned slices
|
|
19
|
+
if (poolOffset & 0x7) {
|
|
20
|
+
poolOffset |= 0x7
|
|
21
|
+
poolOffset++
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
reallocPool()
|
|
4
26
|
|
|
5
27
|
module.exports.getMsg = function (topic, action, data) {
|
|
6
28
|
if (data && !(data instanceof Array)) {
|
|
7
29
|
throw new Error('data must be an array')
|
|
8
30
|
}
|
|
9
31
|
|
|
10
|
-
|
|
32
|
+
if (poolOffset + poolSize / 16 >= poolSize) {
|
|
33
|
+
reallocPool()
|
|
34
|
+
} else {
|
|
35
|
+
alignPool()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const start = poolOffset
|
|
39
|
+
|
|
40
|
+
poolBuffer[poolOffset++] = topic.charCodeAt(0)
|
|
41
|
+
poolBuffer[poolOffset++] = 31
|
|
42
|
+
for (let n = 0; n < action.length; n++) {
|
|
43
|
+
poolBuffer[poolOffset++] = action.charCodeAt(n)
|
|
44
|
+
}
|
|
11
45
|
|
|
12
46
|
if (data) {
|
|
13
47
|
for (let i = 0; i < data.length; i++) {
|
|
14
|
-
|
|
15
|
-
|
|
48
|
+
const type = typeof data[i]
|
|
49
|
+
if (data[i] == null) {
|
|
50
|
+
poolBuffer[poolOffset++] = 31
|
|
51
|
+
} else if (type === 'object') {
|
|
52
|
+
poolBuffer[poolOffset++] = 31
|
|
53
|
+
const res = poolEncoder.encodeInto(
|
|
54
|
+
JSON.stringify(data[i]),
|
|
55
|
+
new Uint8Array(poolBuffer.buffer, poolOffset)
|
|
56
|
+
)
|
|
57
|
+
poolOffset += res.written
|
|
58
|
+
} else if (type === 'bigint') {
|
|
59
|
+
poolBuffer[poolOffset++] = 31
|
|
60
|
+
poolView.setBigUint64(poolOffset, data[i], false)
|
|
61
|
+
poolOffset += 8
|
|
62
|
+
} else if (type === 'string') {
|
|
63
|
+
poolBuffer[poolOffset++] = 31
|
|
64
|
+
const res = poolEncoder.encodeInto(data[i], new Uint8Array(poolBuffer.buffer, poolOffset))
|
|
65
|
+
poolOffset += res.written
|
|
16
66
|
} else {
|
|
17
|
-
|
|
67
|
+
throw new Error('invalid data')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (poolOffset >= poolBuffer.length) {
|
|
71
|
+
reallocPool(start === 0 ? poolSize * 2 : poolSize)
|
|
72
|
+
return this.getMsg(topic, action, data)
|
|
18
73
|
}
|
|
19
74
|
}
|
|
20
75
|
}
|
|
21
|
-
|
|
22
|
-
return sendData.join(SEP)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports.getMsg1 = function (topic, action, p0) {
|
|
26
|
-
return `${topic}${SEP}${action}${SEP}${p0}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports.getMsg2 = function (topic, action, p0, p1) {
|
|
30
|
-
return `${topic}${SEP}${action}${SEP}${p0}${SEP}${p1}`
|
|
76
|
+
return new Uint8Array(poolBuffer.buffer, start, poolOffset - start)
|
|
31
77
|
}
|
|
32
78
|
|
|
33
79
|
module.exports.typed = function (value) {
|
package/src/record/record.js
CHANGED
|
@@ -7,6 +7,8 @@ const invariant = require('invariant')
|
|
|
7
7
|
const cloneDeep = require('lodash.clonedeep')
|
|
8
8
|
const timers = require('../utils/timers')
|
|
9
9
|
|
|
10
|
+
const encoder = new TextEncoder()
|
|
11
|
+
|
|
10
12
|
class Record {
|
|
11
13
|
static STATE = C.RECORD_STATE
|
|
12
14
|
|
|
@@ -16,15 +18,21 @@ class Record {
|
|
|
16
18
|
this._handler = handler
|
|
17
19
|
|
|
18
20
|
this._name = name
|
|
21
|
+
this._key = name
|
|
19
22
|
this._version = ''
|
|
20
23
|
this._data = jsonPath.EMPTY
|
|
21
24
|
this._state = C.RECORD_STATE.VOID
|
|
22
25
|
this._refs = 0
|
|
23
26
|
this._subscriptions = []
|
|
24
27
|
this._emitting = false
|
|
28
|
+
|
|
25
29
|
/** @type Map? */ this._updating = null
|
|
26
30
|
/** @type Array? */ this._patching = null
|
|
27
|
-
this.
|
|
31
|
+
this._hashName()
|
|
32
|
+
this._subscribed = connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [
|
|
33
|
+
this._name,
|
|
34
|
+
this._key,
|
|
35
|
+
])
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
/** @type {string} */
|
|
@@ -62,7 +70,8 @@ class Record {
|
|
|
62
70
|
if (this._refs === 1) {
|
|
63
71
|
this._handler._onPruning(this, false)
|
|
64
72
|
this._subscribed =
|
|
65
|
-
this._subscribed ||
|
|
73
|
+
this._subscribed ||
|
|
74
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
|
|
66
75
|
}
|
|
67
76
|
return this
|
|
68
77
|
}
|
|
@@ -307,6 +316,16 @@ class Record {
|
|
|
307
316
|
})
|
|
308
317
|
}
|
|
309
318
|
|
|
319
|
+
_hashName() {
|
|
320
|
+
// TODO (fix): It's hacky that hasher is not always available...
|
|
321
|
+
this._key =
|
|
322
|
+
typeof this._key === 'bigint'
|
|
323
|
+
? this._key
|
|
324
|
+
: this._name.length <= 8 && encoder.encode(this._name).byteLength === 8
|
|
325
|
+
? this._name
|
|
326
|
+
: this._handler.connection.hasher?.h64(this._name)
|
|
327
|
+
}
|
|
328
|
+
|
|
310
329
|
_$onMessage(message) {
|
|
311
330
|
if (message.action === C.ACTIONS.UPDATE) {
|
|
312
331
|
this._onUpdate(message.data)
|
|
@@ -323,8 +342,10 @@ class Record {
|
|
|
323
342
|
const connection = this._handler._connection
|
|
324
343
|
|
|
325
344
|
if (connected) {
|
|
345
|
+
this._hashName()
|
|
326
346
|
this._subscribed =
|
|
327
|
-
this._refs > 0 &&
|
|
347
|
+
this._refs > 0 &&
|
|
348
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
|
|
328
349
|
|
|
329
350
|
if (this._updating) {
|
|
330
351
|
for (const update of this._updating.values()) {
|
|
@@ -349,7 +370,7 @@ class Record {
|
|
|
349
370
|
invariant(!this._updating, 'must not have updates')
|
|
350
371
|
|
|
351
372
|
if (this._subscribed) {
|
|
352
|
-
connection.
|
|
373
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [this._key])
|
|
353
374
|
this._subscribed = false
|
|
354
375
|
}
|
|
355
376
|
|
|
@@ -371,7 +392,7 @@ class Record {
|
|
|
371
392
|
const prevVersion = this._version
|
|
372
393
|
const nextVersion = this._makeVersion(parseInt(prevVersion) + 1)
|
|
373
394
|
|
|
374
|
-
const update = [this.
|
|
395
|
+
const update = [this._key, nextVersion, jsonPath.stringify(nextData), prevVersion]
|
|
375
396
|
|
|
376
397
|
if (!this._updating) {
|
|
377
398
|
this._onUpdating(true)
|