@nxtedition/deepstream.io-client-js 24.0.2 → 24.0.4
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/record/record-handler.js +47 -37
- package/src/record/record.js +20 -20
package/package.json
CHANGED
|
@@ -90,8 +90,6 @@ class RecordHandler {
|
|
|
90
90
|
|
|
91
91
|
this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
|
|
92
92
|
|
|
93
|
-
this._pruningTimeout = null
|
|
94
|
-
|
|
95
93
|
const _prune = () => {
|
|
96
94
|
const pruning = this._pruning
|
|
97
95
|
this._pruning = new Set()
|
|
@@ -105,24 +103,20 @@ class RecordHandler {
|
|
|
105
103
|
this._stats.records -= pruning.size
|
|
106
104
|
this._stats.destroyed += pruning.size
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
this._pruningTimeout.refresh()
|
|
110
|
-
} else {
|
|
111
|
-
this._pruningTimeout = timers.setTimeout(_prune, 1e3)
|
|
112
|
-
}
|
|
106
|
+
this._pruningTimeout.refresh()
|
|
113
107
|
}
|
|
114
108
|
|
|
115
|
-
_prune
|
|
109
|
+
this._pruningTimeout = timers.setTimeout(_prune, 1e3)
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
_onPruning(rec,
|
|
119
|
-
if (
|
|
112
|
+
_onPruning(rec, value) {
|
|
113
|
+
if (value) {
|
|
120
114
|
this._stats.pruning += 1
|
|
121
115
|
} else {
|
|
122
116
|
this._stats.pruning -= 1
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
if (
|
|
119
|
+
if (value) {
|
|
126
120
|
this._pruning.add(rec)
|
|
127
121
|
} else {
|
|
128
122
|
this._pruning.delete(rec)
|
|
@@ -229,25 +223,11 @@ class RecordHandler {
|
|
|
229
223
|
|
|
230
224
|
sync() {
|
|
231
225
|
// TODO (fix): Sync patching & updating?
|
|
226
|
+
// TODO (fix): Ensure no pending?
|
|
232
227
|
return new Promise((resolve) => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
counter -= 1
|
|
237
|
-
if (counter > 0) {
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const token = xuid()
|
|
242
|
-
this._syncEmitter.once(token, resolve)
|
|
243
|
-
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
for (const callbacks of this._pending.values()) {
|
|
247
|
-
callbacks.push(maybeSync)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
maybeSync()
|
|
228
|
+
const token = xuid()
|
|
229
|
+
this._syncEmitter.once(token, resolve)
|
|
230
|
+
this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
|
|
251
231
|
})
|
|
252
232
|
}
|
|
253
233
|
|
|
@@ -260,6 +240,12 @@ class RecordHandler {
|
|
|
260
240
|
}
|
|
261
241
|
}
|
|
262
242
|
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @param {*} name
|
|
246
|
+
* @param {...any} args
|
|
247
|
+
* @returns {Promise}
|
|
248
|
+
*/
|
|
263
249
|
update(name, ...args) {
|
|
264
250
|
try {
|
|
265
251
|
const record = this.getRecord(name)
|
|
@@ -273,6 +259,10 @@ class RecordHandler {
|
|
|
273
259
|
}
|
|
274
260
|
}
|
|
275
261
|
|
|
262
|
+
/**
|
|
263
|
+
* @param {...any} args
|
|
264
|
+
* @returns {rxjs.Observable}
|
|
265
|
+
*/
|
|
276
266
|
observe(...args) {
|
|
277
267
|
return this._observe(
|
|
278
268
|
{
|
|
@@ -284,6 +274,10 @@ class RecordHandler {
|
|
|
284
274
|
)
|
|
285
275
|
}
|
|
286
276
|
|
|
277
|
+
/**
|
|
278
|
+
* @param {...any} args
|
|
279
|
+
* @returns {Promise}
|
|
280
|
+
*/
|
|
287
281
|
get(...args) {
|
|
288
282
|
return new Promise((resolve, reject) => {
|
|
289
283
|
this.observe(...args)
|
|
@@ -295,10 +289,23 @@ class RecordHandler {
|
|
|
295
289
|
})
|
|
296
290
|
}
|
|
297
291
|
|
|
292
|
+
/**
|
|
293
|
+
* @param {...any} args
|
|
294
|
+
* @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
|
|
295
|
+
*/
|
|
298
296
|
observe2(...args) {
|
|
299
|
-
return this._observe(
|
|
297
|
+
return this._observe(
|
|
298
|
+
{
|
|
299
|
+
timeout: 10 * 60e3,
|
|
300
|
+
},
|
|
301
|
+
...args
|
|
302
|
+
)
|
|
300
303
|
}
|
|
301
304
|
|
|
305
|
+
/**
|
|
306
|
+
* @returns {rxjs.Observable}
|
|
307
|
+
*/
|
|
308
|
+
// TODO (perf): Avoid rest parameters.
|
|
302
309
|
_observe(defaults, name, ...args) {
|
|
303
310
|
let path
|
|
304
311
|
let state = defaults ? defaults.state : undefined
|
|
@@ -344,6 +351,7 @@ class RecordHandler {
|
|
|
344
351
|
state = C.RECORD_STATE[state.toUpperCase()]
|
|
345
352
|
}
|
|
346
353
|
|
|
354
|
+
// TODO (perf): Avoid subscribe closure allocation.
|
|
347
355
|
return new rxjs.Observable((subscriber) => {
|
|
348
356
|
const subscription = {
|
|
349
357
|
subscriber,
|
|
@@ -375,19 +383,21 @@ class RecordHandler {
|
|
|
375
383
|
},
|
|
376
384
|
}
|
|
377
385
|
|
|
378
|
-
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
386
|
+
const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
|
|
379
387
|
|
|
380
|
-
if (timeout &&
|
|
388
|
+
if (timeout && state && record.state < state) {
|
|
389
|
+
// TODO (perf): Avoid Timer allocation.
|
|
381
390
|
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
382
391
|
}
|
|
383
392
|
|
|
384
|
-
if (
|
|
385
|
-
onUpdate(
|
|
393
|
+
if (record.version) {
|
|
394
|
+
onUpdate(record, subscription)
|
|
386
395
|
}
|
|
387
396
|
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
397
|
+
if (signal) {
|
|
398
|
+
// TODO (perf): Avoid abort closure allocation.
|
|
399
|
+
subscription.abort = () => subscriber.error(new utils.AbortError())
|
|
400
|
+
utils.addAbortListener(signal, subscription.abort)
|
|
391
401
|
}
|
|
392
402
|
|
|
393
403
|
return subscription
|
package/src/record/record.js
CHANGED
|
@@ -19,8 +19,8 @@ class Record {
|
|
|
19
19
|
this._refs = 0
|
|
20
20
|
this._subscriptions = []
|
|
21
21
|
this._emitting = false
|
|
22
|
-
this._updating = null
|
|
23
|
-
this._patching = null
|
|
22
|
+
/** @type Map? */ this._updating = null
|
|
23
|
+
/** @type Array? */ this._patching = null
|
|
24
24
|
this._pending = false
|
|
25
25
|
this._subscribed = this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
|
|
26
26
|
|
|
@@ -160,7 +160,11 @@ class Record {
|
|
|
160
160
|
this._patching.splice(0)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
this._patching
|
|
163
|
+
if (this._patching) {
|
|
164
|
+
this._patching.push(path, cloneDeep(data))
|
|
165
|
+
} else {
|
|
166
|
+
throw new Error('invalid state')
|
|
167
|
+
}
|
|
164
168
|
} else {
|
|
165
169
|
this._update(jsonPath.set(this._data, path, data, false))
|
|
166
170
|
}
|
|
@@ -311,7 +315,11 @@ class Record {
|
|
|
311
315
|
this._onUpdating(true)
|
|
312
316
|
}
|
|
313
317
|
|
|
314
|
-
this._updating
|
|
318
|
+
if (this._updating) {
|
|
319
|
+
this._updating.set(nextVersion, update)
|
|
320
|
+
} else {
|
|
321
|
+
throw new Error('invalid state')
|
|
322
|
+
}
|
|
315
323
|
|
|
316
324
|
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
|
|
317
325
|
|
|
@@ -448,23 +456,15 @@ class Record {
|
|
|
448
456
|
|
|
449
457
|
_emitUpdate() {
|
|
450
458
|
this._emitting = true
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
arr[n + 0](this, arr[n + 1])
|
|
458
|
-
} catch (err) {
|
|
459
|
-
this._error(
|
|
460
|
-
C.EVENT.USER_ERROR,
|
|
461
|
-
Object.assign(new Error('user callback failed'), { cause: err })
|
|
462
|
-
)
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
} finally {
|
|
466
|
-
this._emitting = false
|
|
459
|
+
|
|
460
|
+
const arr = this._subscriptions
|
|
461
|
+
const len = arr.length
|
|
462
|
+
|
|
463
|
+
for (let n = 0; n < len; n += 2) {
|
|
464
|
+
arr[n + 0](this, arr[n + 1])
|
|
467
465
|
}
|
|
466
|
+
|
|
467
|
+
this._emitting = false
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
|