@nxtedition/deepstream.io-client-js 24.2.10 → 24.3.0
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
|
@@ -16,6 +16,7 @@ class Record {
|
|
|
16
16
|
this._handler = handler
|
|
17
17
|
|
|
18
18
|
this._name = name
|
|
19
|
+
this._key = connection.hasher?.h64(name) ?? name
|
|
19
20
|
this._version = ''
|
|
20
21
|
this._data = jsonPath.EMPTY
|
|
21
22
|
this._state = C.RECORD_STATE.VOID
|
|
@@ -24,7 +25,10 @@ class Record {
|
|
|
24
25
|
this._emitting = false
|
|
25
26
|
/** @type Map? */ this._updating = null
|
|
26
27
|
/** @type Array? */ this._patching = null
|
|
27
|
-
this._subscribed = connection.
|
|
28
|
+
this._subscribed = connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [
|
|
29
|
+
this._name,
|
|
30
|
+
this._key,
|
|
31
|
+
])
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** @type {string} */
|
|
@@ -62,7 +66,8 @@ class Record {
|
|
|
62
66
|
if (this._refs === 1) {
|
|
63
67
|
this._handler._onPruning(this, false)
|
|
64
68
|
this._subscribed =
|
|
65
|
-
this._subscribed ||
|
|
69
|
+
this._subscribed ||
|
|
70
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
|
|
66
71
|
}
|
|
67
72
|
return this
|
|
68
73
|
}
|
|
@@ -323,8 +328,10 @@ class Record {
|
|
|
323
328
|
const connection = this._handler._connection
|
|
324
329
|
|
|
325
330
|
if (connected) {
|
|
331
|
+
this._key = typeof this._key === 'bigint' ? this._key : connection.hasher?.h64(this._name)
|
|
326
332
|
this._subscribed =
|
|
327
|
-
this._refs > 0 &&
|
|
333
|
+
this._refs > 0 &&
|
|
334
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
|
|
328
335
|
|
|
329
336
|
if (this._updating) {
|
|
330
337
|
for (const update of this._updating.values()) {
|
|
@@ -349,7 +356,7 @@ class Record {
|
|
|
349
356
|
invariant(!this._updating, 'must not have updates')
|
|
350
357
|
|
|
351
358
|
if (this._subscribed) {
|
|
352
|
-
connection.
|
|
359
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [this._key])
|
|
353
360
|
this._subscribed = false
|
|
354
361
|
}
|
|
355
362
|
|
|
@@ -371,7 +378,7 @@ class Record {
|
|
|
371
378
|
const prevVersion = this._version
|
|
372
379
|
const nextVersion = this._makeVersion(parseInt(prevVersion) + 1)
|
|
373
380
|
|
|
374
|
-
const update = [this.
|
|
381
|
+
const update = [this._key, nextVersion, jsonPath.stringify(nextData), prevVersion]
|
|
375
382
|
|
|
376
383
|
if (!this._updating) {
|
|
377
384
|
this._onUpdating(true)
|