@nxtedition/deepstream.io-client-js 26.0.4 → 26.0.7
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 +1 -1
- package/src/client.js +5 -5
- package/src/default-options.js +1 -1
- package/src/event/event-handler.js +6 -6
- package/src/message/connection.js +10 -10
- package/src/message/message-builder.js +5 -5
- package/src/message/message-parser.js +2 -2
- package/src/record/record-handler.js +59 -59
- package/src/record/record.js +48 -46
- package/src/rpc/rpc-handler.js +8 -8
- package/src/rpc/rpc-response.js +2 -2
- package/src/utils/fixed-queue.js +9 -9
- package/src/utils/multicast-listener.js +15 -15
- package/src/utils/timers.js +7 -7
- package/src/utils/unicast-listener.js +10 -10
- package/src/utils/utils.js +13 -13
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -36,13 +36,13 @@ const Client = function (url, options) {
|
|
|
36
36
|
Emitter(Client.prototype)
|
|
37
37
|
|
|
38
38
|
Object.defineProperty(Client.prototype, 'stats', {
|
|
39
|
-
get: function stats
|
|
39
|
+
get: function stats() {
|
|
40
40
|
return {
|
|
41
41
|
record: this.record.stats,
|
|
42
42
|
rpc: this.rpc.stats,
|
|
43
|
-
event: this.event.stats
|
|
43
|
+
event: this.event.stats,
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
Client.prototype.login = function (authParamsOrCallback, callback) {
|
|
@@ -81,7 +81,7 @@ Client.prototype._$onMessage = function (message) {
|
|
|
81
81
|
this._$onError(
|
|
82
82
|
message.topic,
|
|
83
83
|
C.EVENT.MESSAGE_PARSE_ERROR,
|
|
84
|
-
`Received message for unknown topic ${message.topic}
|
|
84
|
+
`Received message for unknown topic ${message.topic}`,
|
|
85
85
|
)
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -127,7 +127,7 @@ Client.prototype._getOptions = function (options) {
|
|
|
127
127
|
return mergedOptions
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
function createDeepstream
|
|
130
|
+
function createDeepstream(url, options) {
|
|
131
131
|
return new Client(url, options)
|
|
132
132
|
}
|
|
133
133
|
|
package/src/default-options.js
CHANGED
|
@@ -13,7 +13,7 @@ const EventHandler = function (options, connection, client) {
|
|
|
13
13
|
this._emitter = new EventEmitter()
|
|
14
14
|
this._listeners = new Map()
|
|
15
15
|
this._stats = {
|
|
16
|
-
emitted: 0
|
|
16
|
+
emitted: 0,
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
this.subscribe = this.subscribe.bind(this)
|
|
@@ -26,19 +26,19 @@ const EventHandler = function (options, connection, client) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
Object.defineProperty(EventHandler.prototype, 'connected', {
|
|
29
|
-
get: function connected
|
|
29
|
+
get: function connected() {
|
|
30
30
|
return this._client.getConnectionState() === C.CONNECTION_STATE.OPEN
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
Object.defineProperty(EventHandler.prototype, 'stats', {
|
|
35
|
-
get: function stats
|
|
35
|
+
get: function stats() {
|
|
36
36
|
return {
|
|
37
37
|
...this._stats,
|
|
38
38
|
listeners: this._listeners.size,
|
|
39
|
-
events: this._emitter.eventNames().length
|
|
39
|
+
events: this._emitter.eventNames().length,
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
},
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
EventHandler.prototype.subscribe = function (name, callback) {
|
|
@@ -27,7 +27,7 @@ const Connection = function (client, url, options) {
|
|
|
27
27
|
raw: null,
|
|
28
28
|
topic: null,
|
|
29
29
|
action: null,
|
|
30
|
-
data: null
|
|
30
|
+
data: null,
|
|
31
31
|
}
|
|
32
32
|
this._recvQueue = new FixedQueue()
|
|
33
33
|
this._reconnectTimeout = null
|
|
@@ -49,9 +49,9 @@ Emitter(Connection.prototype)
|
|
|
49
49
|
|
|
50
50
|
// TODO (fix): Remove
|
|
51
51
|
Object.defineProperty(Connection.prototype, 'connected', {
|
|
52
|
-
get: function connected
|
|
52
|
+
get: function connected() {
|
|
53
53
|
return this._state === C.CONNECTION_STATE.OPEN
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
Connection.prototype.getState = function () {
|
|
@@ -94,7 +94,7 @@ Connection.prototype.close = function () {
|
|
|
94
94
|
Connection.prototype._createEndpoint = function () {
|
|
95
95
|
if (utils.isNode) {
|
|
96
96
|
this._endpoint = new NodeWebSocket(this._url, {
|
|
97
|
-
generateMask
|
|
97
|
+
generateMask() {},
|
|
98
98
|
})
|
|
99
99
|
} else {
|
|
100
100
|
this._endpoint = new BrowserWebSocket(this._url)
|
|
@@ -121,7 +121,7 @@ Connection.prototype.send = function (message) {
|
|
|
121
121
|
C.TOPIC.CONNECTION,
|
|
122
122
|
C.EVENT.CONNECTION_ERROR,
|
|
123
123
|
err,
|
|
124
|
-
message.split(C.MESSAGE_PART_SEPERATOR).map((x) => x.slice(0, 256))
|
|
124
|
+
message.split(C.MESSAGE_PART_SEPERATOR).map((x) => x.slice(0, 256)),
|
|
125
125
|
)
|
|
126
126
|
return false
|
|
127
127
|
}
|
|
@@ -170,10 +170,10 @@ Connection.prototype._sendAuthParams = function () {
|
|
|
170
170
|
this._setState(C.CONNECTION_STATE.AUTHENTICATING)
|
|
171
171
|
const authMessage = messageBuilder.getMsg(C.TOPIC.AUTH, C.ACTIONS.REQUEST, [
|
|
172
172
|
this._authParams,
|
|
173
|
-
'
|
|
173
|
+
'26.0.5', // TODO (fix): How to read from package.json?
|
|
174
174
|
utils.isNode
|
|
175
175
|
? `Node/${process.version}`
|
|
176
|
-
: globalThis.navigator && globalThis.navigator.userAgent
|
|
176
|
+
: globalThis.navigator && globalThis.navigator.userAgent,
|
|
177
177
|
])
|
|
178
178
|
this._submit(authMessage)
|
|
179
179
|
}
|
|
@@ -276,7 +276,7 @@ Connection.prototype._handleConnectionResponse = function (message) {
|
|
|
276
276
|
} else if (message.action === C.ACTIONS.CHALLENGE) {
|
|
277
277
|
this._setState(C.CONNECTION_STATE.CHALLENGING)
|
|
278
278
|
this._submit(
|
|
279
|
-
messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [this._url])
|
|
279
|
+
messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [this._url]),
|
|
280
280
|
)
|
|
281
281
|
} else if (message.action === C.ACTIONS.REJECTION) {
|
|
282
282
|
this._challengeDenied = true
|
|
@@ -351,8 +351,8 @@ Connection.prototype._tryReconnect = function () {
|
|
|
351
351
|
},
|
|
352
352
|
Math.min(
|
|
353
353
|
this._options.maxReconnectInterval,
|
|
354
|
-
this._options.reconnectIntervalIncrement * this._reconnectionAttempt
|
|
355
|
-
)
|
|
354
|
+
this._options.reconnectIntervalIncrement * this._reconnectionAttempt,
|
|
355
|
+
),
|
|
356
356
|
)
|
|
357
357
|
this._reconnectionAttempt++
|
|
358
358
|
} else {
|
|
@@ -9,7 +9,7 @@ let poolBuffer
|
|
|
9
9
|
let poolView
|
|
10
10
|
let poolOffset
|
|
11
11
|
|
|
12
|
-
function allocPool
|
|
12
|
+
function allocPool(size) {
|
|
13
13
|
poolSize = size || poolSize || 1024 * 1024
|
|
14
14
|
poolBuffer = utils.isNode
|
|
15
15
|
? globalThis.Buffer.allocUnsafe(poolSize)
|
|
@@ -18,7 +18,7 @@ function allocPool (size) {
|
|
|
18
18
|
poolOffset = 0
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function alignPool
|
|
21
|
+
function alignPool() {
|
|
22
22
|
// Ensure aligned slices
|
|
23
23
|
if (poolOffset & 0x7) {
|
|
24
24
|
poolOffset |= 0x7
|
|
@@ -26,7 +26,7 @@ function alignPool () {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function writeString
|
|
29
|
+
function writeString(dst, str, offset) {
|
|
30
30
|
if (utils.isNode) {
|
|
31
31
|
return dst.write(str, offset)
|
|
32
32
|
} else {
|
|
@@ -35,7 +35,7 @@ function writeString (dst, str, offset) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function getMsg
|
|
38
|
+
export function getMsg(topic, action, data) {
|
|
39
39
|
if (data && !(data instanceof Array)) {
|
|
40
40
|
throw new Error('data must be an array')
|
|
41
41
|
}
|
|
@@ -98,7 +98,7 @@ export function getMsg (topic, action, data) {
|
|
|
98
98
|
return new Uint8Array(poolBuffer.buffer, start, poolOffset - start)
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
export function typed
|
|
101
|
+
export function typed(value) {
|
|
102
102
|
const type = typeof value
|
|
103
103
|
|
|
104
104
|
if (type === 'string') {
|
|
@@ -62,7 +62,7 @@ MessageParser.prototype.parseMessage = function (message, client, result) {
|
|
|
62
62
|
client._$onError(
|
|
63
63
|
C.TOPIC.ERROR,
|
|
64
64
|
C.EVENT.MESSAGE_PARSE_ERROR,
|
|
65
|
-
new Error('Insufficiant message parts')
|
|
65
|
+
new Error('Insufficiant message parts'),
|
|
66
66
|
)
|
|
67
67
|
return null
|
|
68
68
|
}
|
|
@@ -77,7 +77,7 @@ MessageParser.prototype.parseMessage = function (message, client, result) {
|
|
|
77
77
|
C.TOPIC.ERROR,
|
|
78
78
|
C.EVENT.MESSAGE_PARSE_ERROR,
|
|
79
79
|
new Error('Unknown action'),
|
|
80
|
-
message
|
|
80
|
+
message,
|
|
81
81
|
)
|
|
82
82
|
return null
|
|
83
83
|
}
|
|
@@ -13,7 +13,7 @@ import * as timers from '../utils/timers.js'
|
|
|
13
13
|
|
|
14
14
|
const kEmpty = Symbol('kEmpty')
|
|
15
15
|
|
|
16
|
-
function onUpdate
|
|
16
|
+
function onUpdate(record, subscription) {
|
|
17
17
|
if (subscription.state && record.state < subscription.state) {
|
|
18
18
|
return
|
|
19
19
|
}
|
|
@@ -35,12 +35,12 @@ function onUpdate (record, subscription) {
|
|
|
35
35
|
name: record.name,
|
|
36
36
|
version: record.version,
|
|
37
37
|
state: record.state,
|
|
38
|
-
data
|
|
38
|
+
data,
|
|
39
39
|
})
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function onTimeout
|
|
43
|
+
function onTimeout(subscription) {
|
|
44
44
|
const expected = C.RECORD_STATE_NAME[subscription.state]
|
|
45
45
|
const current = C.RECORD_STATE_NAME[subscription.record.state]
|
|
46
46
|
|
|
@@ -48,13 +48,13 @@ function onTimeout (subscription) {
|
|
|
48
48
|
Object.assign(
|
|
49
49
|
new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
|
|
50
50
|
{
|
|
51
|
-
code: 'ETIMEDOUT'
|
|
52
|
-
}
|
|
53
|
-
)
|
|
51
|
+
code: 'ETIMEDOUT',
|
|
52
|
+
},
|
|
53
|
+
),
|
|
54
54
|
)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function onUpdateFast
|
|
57
|
+
function onUpdateFast(rec, opaque) {
|
|
58
58
|
const { timeout, resolve, synced, state } = opaque
|
|
59
59
|
|
|
60
60
|
if (rec.state >= state && synced) {
|
|
@@ -65,12 +65,12 @@ function onUpdateFast (rec, opaque) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function onSyncFast
|
|
68
|
+
function onSyncFast(opaque) {
|
|
69
69
|
opaque.synced = true
|
|
70
70
|
onUpdateFast(opaque.rec, opaque)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function onTimeoutFast
|
|
73
|
+
function onTimeoutFast(opaque) {
|
|
74
74
|
const { rec, synced, resolve } = opaque
|
|
75
75
|
rec.unsubscribe(onUpdateFast, opaque)
|
|
76
76
|
rec.unref()
|
|
@@ -88,7 +88,7 @@ function onTimeoutFast (opaque) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
class RecordHandler {
|
|
91
|
-
constructor
|
|
91
|
+
constructor(options, connection, client) {
|
|
92
92
|
this.JSON = jsonPath
|
|
93
93
|
this.STATE = C.RECORD_STATE
|
|
94
94
|
Object.assign(this, C.RECORD_STATE)
|
|
@@ -110,7 +110,7 @@ class RecordHandler {
|
|
|
110
110
|
destroyed: 0,
|
|
111
111
|
records: 0,
|
|
112
112
|
pruning: 0,
|
|
113
|
-
patching: 0
|
|
113
|
+
patching: 0,
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
this._syncQueue = []
|
|
@@ -147,7 +147,7 @@ class RecordHandler {
|
|
|
147
147
|
this._pruningTimeout = timers.setTimeout(_prune, 1e3)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
_onPruning
|
|
150
|
+
_onPruning(rec, value) {
|
|
151
151
|
if (value) {
|
|
152
152
|
this._stats.pruning += 1
|
|
153
153
|
} else {
|
|
@@ -161,7 +161,7 @@ class RecordHandler {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
_onUpdating
|
|
164
|
+
_onUpdating(rec, value) {
|
|
165
165
|
if (value) {
|
|
166
166
|
this._stats.updating += 1
|
|
167
167
|
this._updating.set(rec, [])
|
|
@@ -176,7 +176,7 @@ class RecordHandler {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
_onPatching
|
|
179
|
+
_onPatching(rec, value) {
|
|
180
180
|
if (value) {
|
|
181
181
|
this._stats.patching += 1
|
|
182
182
|
this._patching.set(rec, [])
|
|
@@ -191,11 +191,11 @@ class RecordHandler {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
get connected
|
|
194
|
+
get connected() {
|
|
195
195
|
return Boolean(this._connected)
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
get stats
|
|
198
|
+
get stats() {
|
|
199
199
|
let subscriptions = 0
|
|
200
200
|
for (const listener of this._listeners.values()) {
|
|
201
201
|
subscriptions += listener.subscriptions ?? 0
|
|
@@ -203,11 +203,11 @@ class RecordHandler {
|
|
|
203
203
|
|
|
204
204
|
return {
|
|
205
205
|
...this._stats,
|
|
206
|
-
subscriptions
|
|
206
|
+
subscriptions,
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
getKey
|
|
210
|
+
getKey(name) {
|
|
211
211
|
if (name.length > 8) {
|
|
212
212
|
return this._connection.hasher.h64(name)
|
|
213
213
|
}
|
|
@@ -219,10 +219,10 @@ class RecordHandler {
|
|
|
219
219
|
* @param {string} name
|
|
220
220
|
* @returns {Record}
|
|
221
221
|
*/
|
|
222
|
-
getRecord
|
|
222
|
+
getRecord(name) {
|
|
223
223
|
invariant(
|
|
224
224
|
typeof name === 'string' && name.length > 0 && name !== '[object Object]',
|
|
225
|
-
`invalid name ${name}
|
|
225
|
+
`invalid name ${name}`,
|
|
226
226
|
)
|
|
227
227
|
|
|
228
228
|
let record = this._records.get(name)
|
|
@@ -237,7 +237,7 @@ class RecordHandler {
|
|
|
237
237
|
return record.ref()
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
provide
|
|
240
|
+
provide(pattern, callback, options) {
|
|
241
241
|
if (typeof pattern !== 'string' || pattern.length === 0) {
|
|
242
242
|
throw new Error('invalid argument pattern')
|
|
243
243
|
}
|
|
@@ -272,7 +272,7 @@ class RecordHandler {
|
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
async sync
|
|
275
|
+
async sync(opts) {
|
|
276
276
|
// TODO (fix): Sync pending? What about VOID state?
|
|
277
277
|
|
|
278
278
|
let onAbort
|
|
@@ -282,11 +282,11 @@ class RecordHandler {
|
|
|
282
282
|
|
|
283
283
|
const signalPromise = signal
|
|
284
284
|
? new Promise((resolve, reject) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
285
|
+
onAbort = () => {
|
|
286
|
+
reject(signal.reason ?? new utils.AbortError())
|
|
287
|
+
}
|
|
288
|
+
signal.addEventListener('abort', onAbort)
|
|
289
|
+
})
|
|
290
290
|
: null
|
|
291
291
|
signalPromise?.catch(() => {})
|
|
292
292
|
|
|
@@ -296,7 +296,7 @@ class RecordHandler {
|
|
|
296
296
|
const patching = [...this._patching.values()]
|
|
297
297
|
await Promise.race([
|
|
298
298
|
Promise.all(
|
|
299
|
-
patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
|
|
299
|
+
patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
|
|
300
300
|
),
|
|
301
301
|
new Promise((resolve) => {
|
|
302
302
|
patchingTimeout = timers.setTimeout(
|
|
@@ -305,15 +305,15 @@ class RecordHandler {
|
|
|
305
305
|
C.TOPIC.RECORD,
|
|
306
306
|
C.EVENT.TIMEOUT,
|
|
307
307
|
Object.assign(new Error('sync patching timeout'), {
|
|
308
|
-
data: { patching, timeout }
|
|
309
|
-
})
|
|
308
|
+
data: { patching, timeout },
|
|
309
|
+
}),
|
|
310
310
|
)
|
|
311
311
|
resolve(null)
|
|
312
312
|
},
|
|
313
|
-
timeout ?? 2 * 60e3
|
|
313
|
+
timeout ?? 2 * 60e3,
|
|
314
314
|
)
|
|
315
315
|
}),
|
|
316
|
-
signalPromise
|
|
316
|
+
signalPromise,
|
|
317
317
|
]).finally(() => {
|
|
318
318
|
timers.clearTimeout(patchingTimeout)
|
|
319
319
|
})
|
|
@@ -324,7 +324,7 @@ class RecordHandler {
|
|
|
324
324
|
const updating = [...this._updating.values()]
|
|
325
325
|
await Promise.race([
|
|
326
326
|
Promise.all(
|
|
327
|
-
updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
|
|
327
|
+
updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
|
|
328
328
|
),
|
|
329
329
|
new Promise((resolve) => {
|
|
330
330
|
updatingTimeout = timers.setTimeout(
|
|
@@ -333,15 +333,15 @@ class RecordHandler {
|
|
|
333
333
|
C.TOPIC.RECORD,
|
|
334
334
|
C.EVENT.TIMEOUT,
|
|
335
335
|
Object.assign(new Error('sync updating timeout'), {
|
|
336
|
-
data: { updating, timeout }
|
|
337
|
-
})
|
|
336
|
+
data: { updating, timeout },
|
|
337
|
+
}),
|
|
338
338
|
)
|
|
339
339
|
resolve(null)
|
|
340
340
|
},
|
|
341
|
-
timeout ?? 2 * 60e3
|
|
341
|
+
timeout ?? 2 * 60e3,
|
|
342
342
|
)
|
|
343
343
|
}),
|
|
344
|
-
signalPromise
|
|
344
|
+
signalPromise,
|
|
345
345
|
]).finally(() => {
|
|
346
346
|
timers.clearTimeout(updatingTimeout)
|
|
347
347
|
})
|
|
@@ -360,14 +360,14 @@ class RecordHandler {
|
|
|
360
360
|
this._client._$onError(
|
|
361
361
|
C.TOPIC.RECORD,
|
|
362
362
|
C.EVENT.TIMEOUT,
|
|
363
|
-
Object.assign(new Error('sync server timeout'), { data: { token, timeout } })
|
|
363
|
+
Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
|
|
364
364
|
)
|
|
365
365
|
resolve(null)
|
|
366
366
|
},
|
|
367
|
-
timeout ?? 2 * 60e3
|
|
367
|
+
timeout ?? 2 * 60e3,
|
|
368
368
|
)
|
|
369
369
|
}),
|
|
370
|
-
signalPromise
|
|
370
|
+
signalPromise,
|
|
371
371
|
]).finally(() => {
|
|
372
372
|
timers.clearTimeout(serverTimeout)
|
|
373
373
|
})
|
|
@@ -378,7 +378,7 @@ class RecordHandler {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
_sync
|
|
381
|
+
_sync(callback, opaque) {
|
|
382
382
|
this._syncQueue.push(callback, opaque)
|
|
383
383
|
|
|
384
384
|
if (this._syncQueue.length > 2) {
|
|
@@ -399,7 +399,7 @@ class RecordHandler {
|
|
|
399
399
|
}, 1)
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
set
|
|
402
|
+
set(name, ...args) {
|
|
403
403
|
const record = this.getRecord(name)
|
|
404
404
|
try {
|
|
405
405
|
return record.set(...args)
|
|
@@ -414,7 +414,7 @@ class RecordHandler {
|
|
|
414
414
|
* @param {...any} args
|
|
415
415
|
* @returns {Promise}
|
|
416
416
|
*/
|
|
417
|
-
update
|
|
417
|
+
update(name, ...args) {
|
|
418
418
|
try {
|
|
419
419
|
const record = this.getRecord(name)
|
|
420
420
|
try {
|
|
@@ -431,14 +431,14 @@ class RecordHandler {
|
|
|
431
431
|
* @param {...any} args
|
|
432
432
|
* @returns {rxjs.Observable}
|
|
433
433
|
*/
|
|
434
|
-
observe
|
|
434
|
+
observe(...args) {
|
|
435
435
|
return this._observe(
|
|
436
436
|
{
|
|
437
437
|
state: C.RECORD_STATE.SERVER,
|
|
438
438
|
timeout: 2 * 60e3,
|
|
439
|
-
dataOnly: true
|
|
439
|
+
dataOnly: true,
|
|
440
440
|
},
|
|
441
|
-
...args
|
|
441
|
+
...args,
|
|
442
442
|
)
|
|
443
443
|
}
|
|
444
444
|
|
|
@@ -446,7 +446,7 @@ class RecordHandler {
|
|
|
446
446
|
* @param {...any} args
|
|
447
447
|
* @returns {Promise}
|
|
448
448
|
*/
|
|
449
|
-
get
|
|
449
|
+
get(...args) {
|
|
450
450
|
if (args.length === 1 || (args.length === 2 && typeof args[1] === 'number')) {
|
|
451
451
|
return new Promise((resolve) => {
|
|
452
452
|
const rec = this.getRecord(args[0])
|
|
@@ -466,7 +466,7 @@ class RecordHandler {
|
|
|
466
466
|
state,
|
|
467
467
|
resolve,
|
|
468
468
|
timeout: null,
|
|
469
|
-
synced
|
|
469
|
+
synced,
|
|
470
470
|
}
|
|
471
471
|
opaque.timeout = timers.setTimeout(onTimeoutFast, 2 * 60e3, opaque)
|
|
472
472
|
rec.subscribe(onUpdateFast, opaque)
|
|
@@ -484,7 +484,7 @@ class RecordHandler {
|
|
|
484
484
|
.pipe(rx.first())
|
|
485
485
|
.subscribe({
|
|
486
486
|
next: resolve,
|
|
487
|
-
error: reject
|
|
487
|
+
error: reject,
|
|
488
488
|
})
|
|
489
489
|
})
|
|
490
490
|
}
|
|
@@ -494,13 +494,13 @@ class RecordHandler {
|
|
|
494
494
|
* @param {...any} args
|
|
495
495
|
* @returns {Promise}
|
|
496
496
|
*/
|
|
497
|
-
get2
|
|
497
|
+
get2(...args) {
|
|
498
498
|
return new Promise((resolve, reject) => {
|
|
499
499
|
this.observe2(...args)
|
|
500
500
|
.pipe(rx.first())
|
|
501
501
|
.subscribe({
|
|
502
502
|
next: resolve,
|
|
503
|
-
error: reject
|
|
503
|
+
error: reject,
|
|
504
504
|
})
|
|
505
505
|
})
|
|
506
506
|
}
|
|
@@ -509,12 +509,12 @@ class RecordHandler {
|
|
|
509
509
|
* @param {...any} args
|
|
510
510
|
* @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
|
|
511
511
|
*/
|
|
512
|
-
observe2
|
|
512
|
+
observe2(...args) {
|
|
513
513
|
return this._observe(
|
|
514
514
|
{
|
|
515
|
-
timeout: 2 * 60e3
|
|
515
|
+
timeout: 2 * 60e3,
|
|
516
516
|
},
|
|
517
|
-
...args
|
|
517
|
+
...args,
|
|
518
518
|
)
|
|
519
519
|
}
|
|
520
520
|
|
|
@@ -522,7 +522,7 @@ class RecordHandler {
|
|
|
522
522
|
* @returns {rxjs.Observable}
|
|
523
523
|
*/
|
|
524
524
|
// TODO (perf): Avoid rest parameters.
|
|
525
|
-
_observe
|
|
525
|
+
_observe(defaults, name, ...args) {
|
|
526
526
|
let path
|
|
527
527
|
let state = defaults ? defaults.state : undefined
|
|
528
528
|
let signal
|
|
@@ -585,7 +585,7 @@ class RecordHandler {
|
|
|
585
585
|
timeout: null,
|
|
586
586
|
/** @type {Record?} */ record: null,
|
|
587
587
|
/** @type {Function?} */ abort: null,
|
|
588
|
-
unsubscribe
|
|
588
|
+
unsubscribe() {
|
|
589
589
|
if (this.timeout) {
|
|
590
590
|
timers.clearTimeout(this.timeout)
|
|
591
591
|
this.timeout = null
|
|
@@ -602,7 +602,7 @@ class RecordHandler {
|
|
|
602
602
|
this.record.unref()
|
|
603
603
|
this.record = null
|
|
604
604
|
}
|
|
605
|
-
}
|
|
605
|
+
},
|
|
606
606
|
}
|
|
607
607
|
|
|
608
608
|
const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
|
|
@@ -626,7 +626,7 @@ class RecordHandler {
|
|
|
626
626
|
})
|
|
627
627
|
}
|
|
628
628
|
|
|
629
|
-
_$handle
|
|
629
|
+
_$handle(message) {
|
|
630
630
|
let name
|
|
631
631
|
if (message.action === C.ACTIONS.ERROR) {
|
|
632
632
|
name = message.data[1]
|
|
@@ -652,7 +652,7 @@ class RecordHandler {
|
|
|
652
652
|
return false
|
|
653
653
|
}
|
|
654
654
|
|
|
655
|
-
_onConnectionStateChange
|
|
655
|
+
_onConnectionStateChange(connected) {
|
|
656
656
|
for (const listener of this._listeners.values()) {
|
|
657
657
|
listener._$onConnectionStateChange(connected)
|
|
658
658
|
}
|