@nxtedition/deepstream.io-client-js 31.0.8 → 31.0.10
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 +104 -127
package/package.json
CHANGED
|
@@ -23,13 +23,12 @@ const OBSERVE2_DEFAULTS = {
|
|
|
23
23
|
}
|
|
24
24
|
const GET_DEFAULTS = {
|
|
25
25
|
timeout: 2 * 60e3,
|
|
26
|
-
first: true,
|
|
27
26
|
sync: true,
|
|
28
27
|
dataOnly: true,
|
|
29
28
|
}
|
|
30
29
|
const GET2_DEFAULTS = {
|
|
31
30
|
timeout: 2 * 60e3,
|
|
32
|
-
|
|
31
|
+
sync: true,
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
function onSync(subscription) {
|
|
@@ -72,11 +71,6 @@ function onUpdate(record, subscription) {
|
|
|
72
71
|
data,
|
|
73
72
|
})
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
if (subscription.first) {
|
|
77
|
-
subscription.subscriber.complete?.()
|
|
78
|
-
subscription.unsubscribe()
|
|
79
|
-
}
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
function onTimeout(subscription) {
|
|
@@ -475,30 +469,26 @@ class RecordHandler {
|
|
|
475
469
|
|
|
476
470
|
/**
|
|
477
471
|
* @param {...any} args
|
|
478
|
-
* @returns {
|
|
472
|
+
* @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
|
|
479
473
|
*/
|
|
480
|
-
|
|
481
|
-
return
|
|
482
|
-
this._subscribe({ next: resolve, error: reject }, GET_DEFAULTS, ...args)
|
|
483
|
-
})
|
|
474
|
+
observe2(...args) {
|
|
475
|
+
return this._observe(OBSERVE2_DEFAULTS, ...args)
|
|
484
476
|
}
|
|
485
477
|
|
|
486
478
|
/**
|
|
487
479
|
* @param {...any} args
|
|
488
480
|
* @returns {Promise}
|
|
489
481
|
*/
|
|
490
|
-
|
|
491
|
-
return
|
|
492
|
-
this._subscribe({ next: resolve, error: reject }, GET2_DEFAULTS, ...args)
|
|
493
|
-
})
|
|
482
|
+
get(...args) {
|
|
483
|
+
return rxjs.firstValueFrom(this._observe(GET_DEFAULTS, ...args))
|
|
494
484
|
}
|
|
495
485
|
|
|
496
486
|
/**
|
|
497
487
|
* @param {...any} args
|
|
498
|
-
* @returns {
|
|
488
|
+
* @returns {Promise}
|
|
499
489
|
*/
|
|
500
|
-
|
|
501
|
-
return this._observe(
|
|
490
|
+
get2(...args) {
|
|
491
|
+
return rxjs.firstValueFrom(this._observe(GET2_DEFAULTS, ...args))
|
|
502
492
|
}
|
|
503
493
|
|
|
504
494
|
/**
|
|
@@ -506,136 +496,123 @@ class RecordHandler {
|
|
|
506
496
|
*/
|
|
507
497
|
_observe(defaults, name, ...args) {
|
|
508
498
|
return new rxjs.Observable((subscriber) => {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
499
|
+
let path
|
|
500
|
+
let state = defaults?.state
|
|
501
|
+
let signal
|
|
502
|
+
let timeout = defaults?.timeout
|
|
503
|
+
let dataOnly = defaults?.dataOnly
|
|
504
|
+
let sync = defaults?.sync
|
|
505
|
+
|
|
506
|
+
let idx = 0
|
|
507
|
+
|
|
508
|
+
if (
|
|
509
|
+
idx < args.length &&
|
|
510
|
+
(args[idx] == null ||
|
|
511
|
+
typeof args[idx] === 'string' ||
|
|
512
|
+
Array.isArray(args[idx]) ||
|
|
513
|
+
typeof args[idx] === 'function')
|
|
514
|
+
) {
|
|
515
|
+
path = args[idx++]
|
|
516
|
+
}
|
|
512
517
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
_subscribe(subscriber, defaults, name, ...args) {
|
|
517
|
-
let path
|
|
518
|
-
let state = defaults?.state
|
|
519
|
-
let signal
|
|
520
|
-
let timeout = defaults?.timeout
|
|
521
|
-
let dataOnly = defaults?.dataOnly
|
|
522
|
-
let sync = defaults?.sync
|
|
523
|
-
let first = defaults?.first
|
|
518
|
+
if (idx < args.length && (args[idx] == null || typeof args[idx] === 'number')) {
|
|
519
|
+
state = args[idx++]
|
|
520
|
+
}
|
|
524
521
|
|
|
525
|
-
|
|
522
|
+
if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
|
|
523
|
+
const options = args[idx++] || {}
|
|
526
524
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
typeof args[idx] === 'string' ||
|
|
531
|
-
Array.isArray(args[idx]) ||
|
|
532
|
-
typeof args[idx] === 'function')
|
|
533
|
-
) {
|
|
534
|
-
path = args[idx++]
|
|
535
|
-
}
|
|
525
|
+
if (options.signal !== undefined) {
|
|
526
|
+
signal = options.signal
|
|
527
|
+
}
|
|
536
528
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
529
|
+
if (options.timeout !== undefined) {
|
|
530
|
+
timeout = options.timeout
|
|
531
|
+
}
|
|
540
532
|
|
|
541
|
-
|
|
542
|
-
|
|
533
|
+
if (options.path !== undefined) {
|
|
534
|
+
path = options.path
|
|
535
|
+
}
|
|
543
536
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
537
|
+
if (options.state !== undefined) {
|
|
538
|
+
state = options.state
|
|
539
|
+
}
|
|
547
540
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
541
|
+
if (options.dataOnly !== undefined) {
|
|
542
|
+
dataOnly = options.dataOnly
|
|
543
|
+
}
|
|
551
544
|
|
|
552
|
-
|
|
553
|
-
|
|
545
|
+
if (options.sync !== undefined) {
|
|
546
|
+
sync = options.sync
|
|
547
|
+
}
|
|
554
548
|
}
|
|
555
549
|
|
|
556
|
-
if (
|
|
557
|
-
state =
|
|
550
|
+
if (typeof state === 'string') {
|
|
551
|
+
state = C.RECORD_STATE[state.toUpperCase()]
|
|
558
552
|
}
|
|
559
553
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
554
|
+
// TODO (perf): Make a class
|
|
555
|
+
const subscription = {
|
|
556
|
+
subscriber,
|
|
557
|
+
path,
|
|
558
|
+
state,
|
|
559
|
+
synced: false,
|
|
560
|
+
signal,
|
|
561
|
+
dataOnly,
|
|
562
|
+
data: kEmpty,
|
|
563
|
+
/** @type {NodeJS.Timeout|Timeout|null} */
|
|
564
|
+
timeout: null,
|
|
565
|
+
/** @type {Record?} */
|
|
566
|
+
record: null,
|
|
567
|
+
/** @type {Function?} */
|
|
568
|
+
abort: null,
|
|
569
|
+
unsubscribe() {
|
|
570
|
+
if (this.timeout) {
|
|
571
|
+
timers.clearTimeout(this.timeout)
|
|
572
|
+
this.timeout = null
|
|
573
|
+
}
|
|
563
574
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
575
|
+
if (this.signal) {
|
|
576
|
+
utils.removeAbortListener(this.signal, this.abort)
|
|
577
|
+
this.signal = null
|
|
578
|
+
this.abort = null
|
|
579
|
+
}
|
|
567
580
|
|
|
568
|
-
|
|
569
|
-
|
|
581
|
+
if (this.record) {
|
|
582
|
+
this.record.unsubscribe(onUpdate, this)
|
|
583
|
+
this.record.unref()
|
|
584
|
+
this.record = null
|
|
585
|
+
}
|
|
586
|
+
},
|
|
570
587
|
}
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if (typeof state === 'string') {
|
|
574
|
-
state = C.RECORD_STATE[state.toUpperCase()]
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// TODO (perf): Make a class
|
|
578
|
-
const subscription = {
|
|
579
|
-
subscriber,
|
|
580
|
-
first,
|
|
581
|
-
path,
|
|
582
|
-
state,
|
|
583
|
-
synced: false,
|
|
584
|
-
signal,
|
|
585
|
-
dataOnly,
|
|
586
|
-
data: kEmpty,
|
|
587
|
-
/** @type {NodeJS.Timeout|Timeout|null} */
|
|
588
|
-
timeout: null,
|
|
589
|
-
/** @type {Record?} */
|
|
590
|
-
record: null,
|
|
591
|
-
/** @type {Function?} */
|
|
592
|
-
abort: null,
|
|
593
|
-
unsubscribe() {
|
|
594
|
-
if (this.timeout) {
|
|
595
|
-
timers.clearTimeout(this.timeout)
|
|
596
|
-
this.timeout = null
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
if (this.signal) {
|
|
600
|
-
utils.removeAbortListener(this.signal, this.abort)
|
|
601
|
-
this.signal = null
|
|
602
|
-
this.abort = null
|
|
603
|
-
}
|
|
604
588
|
|
|
605
|
-
|
|
606
|
-
this.record.unsubscribe(onUpdate, this)
|
|
607
|
-
this.record.unref()
|
|
608
|
-
this.record = null
|
|
609
|
-
}
|
|
610
|
-
},
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
589
|
+
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
614
590
|
|
|
615
|
-
|
|
591
|
+
const record = subscription.record
|
|
616
592
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
593
|
+
if (sync && record.state >= C.RECORD_STATE.SERVER) {
|
|
594
|
+
this._sync(onSync, sync === true ? 'WEAK' : sync, subscription)
|
|
595
|
+
} else {
|
|
596
|
+
subscription.synced = true
|
|
597
|
+
}
|
|
622
598
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
599
|
+
if (timeout > 0 && state && record.state < state) {
|
|
600
|
+
// TODO (perf): Avoid Timer allocation.
|
|
601
|
+
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
602
|
+
}
|
|
627
603
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
604
|
+
if (signal) {
|
|
605
|
+
// TODO (perf): Avoid abort closure allocation.
|
|
606
|
+
subscription.abort = () => subscriber.error(new utils.AbortError())
|
|
607
|
+
utils.addAbortListener(signal, subscription.abort)
|
|
608
|
+
}
|
|
633
609
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
610
|
+
if (record.version) {
|
|
611
|
+
onUpdate(null, subscription)
|
|
612
|
+
}
|
|
637
613
|
|
|
638
|
-
|
|
614
|
+
return subscription
|
|
615
|
+
})
|
|
639
616
|
}
|
|
640
617
|
|
|
641
618
|
_$handle(message) {
|