@nxtedition/deepstream.io-client-js 31.2.4 → 31.2.6
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 +58 -60
package/package.json
CHANGED
|
@@ -45,22 +45,18 @@ function onUpdate(record, subscription) {
|
|
|
45
45
|
|
|
46
46
|
if (!subscription.synced || subscription.record.state < subscription.state) {
|
|
47
47
|
if (subscription.timeoutValue > 0) {
|
|
48
|
-
if (!subscription.
|
|
49
|
-
subscription.
|
|
50
|
-
onTimeout,
|
|
51
|
-
subscription.timeoutValue,
|
|
52
|
-
subscription,
|
|
53
|
-
)
|
|
48
|
+
if (!subscription.timeout) {
|
|
49
|
+
subscription.timeout = timers.setTimeout(onTimeout, subscription.timeoutValue, subscription)
|
|
54
50
|
} else {
|
|
55
|
-
subscription.
|
|
51
|
+
subscription.timeout.refresh()
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
return
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
if (subscription.
|
|
62
|
-
timers.clearTimeout(subscription.
|
|
63
|
-
subscription.
|
|
57
|
+
if (subscription.timeout) {
|
|
58
|
+
timers.clearTimeout(subscription.timeout)
|
|
59
|
+
subscription.timeout = null
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
const data = subscription.path
|
|
@@ -472,30 +468,31 @@ class RecordHandler {
|
|
|
472
468
|
}
|
|
473
469
|
|
|
474
470
|
/**
|
|
471
|
+
* @param {string} name
|
|
475
472
|
* @param {...any} args
|
|
476
473
|
* @returns {rxjs.Observable}
|
|
477
474
|
*/
|
|
478
|
-
observe(...args) {
|
|
479
|
-
return this._observe(OBSERVE_DEFAULTS, ...args)
|
|
475
|
+
observe(name, ...args) {
|
|
476
|
+
return this._observe(OBSERVE_DEFAULTS, name, ...args)
|
|
480
477
|
}
|
|
481
478
|
|
|
482
479
|
/**
|
|
480
|
+
* @param {string} name
|
|
483
481
|
* @param {...any} args
|
|
484
482
|
* @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
|
|
485
483
|
*/
|
|
486
|
-
observe2(...args) {
|
|
487
|
-
return this._observe(OBSERVE2_DEFAULTS, ...args)
|
|
484
|
+
observe2(name, ...args) {
|
|
485
|
+
return this._observe(OBSERVE2_DEFAULTS, name, ...args)
|
|
488
486
|
}
|
|
489
487
|
|
|
490
488
|
/**
|
|
491
|
-
*
|
|
492
|
-
* @param {*} name
|
|
489
|
+
* @param {string} name
|
|
493
490
|
* @param {...any} args
|
|
494
491
|
* @returns { { value: object, async: false } | { value: Promise<object>, async: true } }
|
|
495
492
|
*/
|
|
496
493
|
getAsync(name, ...args) {
|
|
497
494
|
let path
|
|
498
|
-
let state = GET_DEFAULTS.state
|
|
495
|
+
let state = GET_DEFAULTS.state ?? C.RECORD_STATE.CLIENT
|
|
499
496
|
|
|
500
497
|
let idx = 0
|
|
501
498
|
|
|
@@ -517,32 +514,40 @@ class RecordHandler {
|
|
|
517
514
|
return { value: this.get(name, ...args), async: true }
|
|
518
515
|
}
|
|
519
516
|
|
|
517
|
+
if (typeof state === 'string') {
|
|
518
|
+
state = C.RECORD_STATE[state.toUpperCase()]
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (!Number.isInteger(state) || state < 0) {
|
|
522
|
+
throw new Error('invalid argument: state')
|
|
523
|
+
}
|
|
524
|
+
|
|
520
525
|
const rec = this.getRecord(name)
|
|
521
526
|
try {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
527
|
+
return rec.state >= state
|
|
528
|
+
? { value: rec.get(path), async: false }
|
|
529
|
+
: { value: this.get(name, ...args), async: true }
|
|
525
530
|
} finally {
|
|
526
531
|
rec.unref()
|
|
527
532
|
}
|
|
528
|
-
|
|
529
|
-
return { value: this.get(name, ...args), async: true }
|
|
530
533
|
}
|
|
531
534
|
|
|
532
535
|
/**
|
|
536
|
+
* @param {string} name
|
|
533
537
|
* @param {...any} args
|
|
534
538
|
* @returns {Promise<object>}
|
|
535
539
|
*/
|
|
536
|
-
get(...args) {
|
|
537
|
-
return rxjs.firstValueFrom(this._observe(GET_DEFAULTS, ...args))
|
|
540
|
+
get(name, ...args) {
|
|
541
|
+
return rxjs.firstValueFrom(this._observe(GET_DEFAULTS, name, ...args))
|
|
538
542
|
}
|
|
539
543
|
|
|
540
544
|
/**
|
|
545
|
+
* @param {string} name
|
|
541
546
|
* @param {...any} args
|
|
542
547
|
* @returns {Promise<object>}
|
|
543
548
|
*/
|
|
544
|
-
get2(...args) {
|
|
545
|
-
return rxjs.firstValueFrom(this._observe(GET2_DEFAULTS, ...args))
|
|
549
|
+
get2(name, ...args) {
|
|
550
|
+
return rxjs.firstValueFrom(this._observe(GET2_DEFAULTS, name, ...args))
|
|
546
551
|
}
|
|
547
552
|
|
|
548
553
|
/**
|
|
@@ -605,9 +610,6 @@ class RecordHandler {
|
|
|
605
610
|
state = C.RECORD_STATE[state.toUpperCase()]
|
|
606
611
|
}
|
|
607
612
|
|
|
608
|
-
// TODO (fix): Validate path?
|
|
609
|
-
// TODO (fix): Validate signal?
|
|
610
|
-
|
|
611
613
|
if (!Number.isInteger(state) || state < 0) {
|
|
612
614
|
throw new Error('invalid argument: state')
|
|
613
615
|
}
|
|
@@ -628,8 +630,6 @@ class RecordHandler {
|
|
|
628
630
|
const subscription = {
|
|
629
631
|
/** @readonly @type {unknown} */
|
|
630
632
|
subscriber,
|
|
631
|
-
/** @type {Record|null} */
|
|
632
|
-
record: this.getRecord(name),
|
|
633
633
|
/** @readonly @type {unknown} */
|
|
634
634
|
path,
|
|
635
635
|
/** @readonly @type {number} */
|
|
@@ -641,53 +641,51 @@ class RecordHandler {
|
|
|
641
641
|
/** @readonly @type {number} */
|
|
642
642
|
timeoutValue: timeout,
|
|
643
643
|
|
|
644
|
+
/** @type {Record|null} */
|
|
645
|
+
record: null,
|
|
644
646
|
/** @type {Timeout|null} */
|
|
645
|
-
|
|
647
|
+
timeout: null,
|
|
646
648
|
/** @type {Function?} */
|
|
647
649
|
abort: null,
|
|
648
650
|
/** @type {object|Array} */
|
|
649
651
|
data: kEmpty,
|
|
650
652
|
/** @type {boolean} */
|
|
651
653
|
synced: false,
|
|
652
|
-
|
|
653
|
-
unsubscribe() {
|
|
654
|
-
if (this.timeoutHandle) {
|
|
655
|
-
timers.clearTimeout(this.timeoutHandle)
|
|
656
|
-
this.timeoutHandle = null
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (this.signal) {
|
|
660
|
-
utils.removeAbortListener(this.signal, this.abort)
|
|
661
|
-
this.abort = null
|
|
662
|
-
this.signal = null
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
if (this.record) {
|
|
666
|
-
this.record.unsubscribe(onUpdate, this)
|
|
667
|
-
this.record.unref()
|
|
668
|
-
this.record = null
|
|
669
|
-
}
|
|
670
|
-
},
|
|
671
654
|
}
|
|
672
655
|
|
|
673
|
-
|
|
674
|
-
subscription.
|
|
656
|
+
subscriber.add(() => {
|
|
657
|
+
if (subscription.timeout) {
|
|
658
|
+
timers.clearTimeout(subscription.timeout)
|
|
659
|
+
subscription.timeout = null
|
|
660
|
+
}
|
|
675
661
|
|
|
676
|
-
if (
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
subscription.
|
|
662
|
+
if (subscription.signal) {
|
|
663
|
+
utils.removeAbortListener(subscription.signal, subscription.abort)
|
|
664
|
+
subscription.abort = null
|
|
665
|
+
subscription.signal = null
|
|
680
666
|
}
|
|
681
|
-
|
|
667
|
+
|
|
668
|
+
if (subscription.record) {
|
|
669
|
+
subscription.record.unsubscribe(onUpdate, subscription)
|
|
670
|
+
subscription.record.unref()
|
|
671
|
+
subscription.record = null
|
|
672
|
+
}
|
|
673
|
+
})
|
|
682
674
|
|
|
683
675
|
if (subscription.signal) {
|
|
684
676
|
subscription.abort = () => subscriber.error(new utils.AbortError())
|
|
685
677
|
utils.addAbortListener(subscription.signal, subscription.abort)
|
|
686
678
|
}
|
|
687
679
|
|
|
688
|
-
|
|
680
|
+
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
689
681
|
|
|
690
|
-
|
|
682
|
+
if (sync) {
|
|
683
|
+
this._sync(onSync, sync === true ? 'WEAK' : sync, subscription)
|
|
684
|
+
} else {
|
|
685
|
+
subscription.synced = true
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
onUpdate(subscription.record, subscription)
|
|
691
689
|
})
|
|
692
690
|
}
|
|
693
691
|
|