@nxtedition/deepstream.io-client-js 31.0.9 → 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 +105 -126
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,165 +469,150 @@ 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
|
/**
|
|
505
495
|
* @returns {rxjs.Observable}
|
|
506
496
|
*/
|
|
507
497
|
_observe(defaults, name, ...args) {
|
|
508
|
-
return new rxjs.Observable((subscriber) =>
|
|
509
|
-
|
|
498
|
+
return new rxjs.Observable((subscriber) => {
|
|
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
|
+
}
|
|
510
517
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
_subscribe(subscriber, defaults, name, ...args) {
|
|
515
|
-
let path
|
|
516
|
-
let state = defaults?.state
|
|
517
|
-
let signal
|
|
518
|
-
let timeout = defaults?.timeout
|
|
519
|
-
let dataOnly = defaults?.dataOnly
|
|
520
|
-
let sync = defaults?.sync
|
|
521
|
-
let first = defaults?.first
|
|
518
|
+
if (idx < args.length && (args[idx] == null || typeof args[idx] === 'number')) {
|
|
519
|
+
state = args[idx++]
|
|
520
|
+
}
|
|
522
521
|
|
|
523
|
-
|
|
522
|
+
if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
|
|
523
|
+
const options = args[idx++] || {}
|
|
524
524
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
typeof args[idx] === 'string' ||
|
|
529
|
-
Array.isArray(args[idx]) ||
|
|
530
|
-
typeof args[idx] === 'function')
|
|
531
|
-
) {
|
|
532
|
-
path = args[idx++]
|
|
533
|
-
}
|
|
525
|
+
if (options.signal !== undefined) {
|
|
526
|
+
signal = options.signal
|
|
527
|
+
}
|
|
534
528
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
529
|
+
if (options.timeout !== undefined) {
|
|
530
|
+
timeout = options.timeout
|
|
531
|
+
}
|
|
538
532
|
|
|
539
|
-
|
|
540
|
-
|
|
533
|
+
if (options.path !== undefined) {
|
|
534
|
+
path = options.path
|
|
535
|
+
}
|
|
541
536
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
537
|
+
if (options.state !== undefined) {
|
|
538
|
+
state = options.state
|
|
539
|
+
}
|
|
545
540
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
541
|
+
if (options.dataOnly !== undefined) {
|
|
542
|
+
dataOnly = options.dataOnly
|
|
543
|
+
}
|
|
549
544
|
|
|
550
|
-
|
|
551
|
-
|
|
545
|
+
if (options.sync !== undefined) {
|
|
546
|
+
sync = options.sync
|
|
547
|
+
}
|
|
552
548
|
}
|
|
553
549
|
|
|
554
|
-
if (
|
|
555
|
-
state =
|
|
550
|
+
if (typeof state === 'string') {
|
|
551
|
+
state = C.RECORD_STATE[state.toUpperCase()]
|
|
556
552
|
}
|
|
557
553
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
+
}
|
|
561
574
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
575
|
+
if (this.signal) {
|
|
576
|
+
utils.removeAbortListener(this.signal, this.abort)
|
|
577
|
+
this.signal = null
|
|
578
|
+
this.abort = null
|
|
579
|
+
}
|
|
565
580
|
|
|
566
|
-
|
|
567
|
-
|
|
581
|
+
if (this.record) {
|
|
582
|
+
this.record.unsubscribe(onUpdate, this)
|
|
583
|
+
this.record.unref()
|
|
584
|
+
this.record = null
|
|
585
|
+
}
|
|
586
|
+
},
|
|
568
587
|
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
if (typeof state === 'string') {
|
|
572
|
-
state = C.RECORD_STATE[state.toUpperCase()]
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
// TODO (perf): Make a class
|
|
576
|
-
const subscription = {
|
|
577
|
-
subscriber,
|
|
578
|
-
first,
|
|
579
|
-
path,
|
|
580
|
-
state,
|
|
581
|
-
synced: false,
|
|
582
|
-
signal,
|
|
583
|
-
dataOnly,
|
|
584
|
-
data: kEmpty,
|
|
585
|
-
/** @type {NodeJS.Timeout|Timeout|null} */
|
|
586
|
-
timeout: null,
|
|
587
|
-
/** @type {Record?} */
|
|
588
|
-
record: null,
|
|
589
|
-
/** @type {Function?} */
|
|
590
|
-
abort: null,
|
|
591
|
-
unsubscribe() {
|
|
592
|
-
if (this.timeout) {
|
|
593
|
-
timers.clearTimeout(this.timeout)
|
|
594
|
-
this.timeout = null
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
if (this.signal) {
|
|
598
|
-
utils.removeAbortListener(this.signal, this.abort)
|
|
599
|
-
this.signal = null
|
|
600
|
-
this.abort = null
|
|
601
|
-
}
|
|
602
588
|
|
|
603
|
-
|
|
604
|
-
this.record.unsubscribe(onUpdate, this)
|
|
605
|
-
this.record.unref()
|
|
606
|
-
this.record = null
|
|
607
|
-
}
|
|
608
|
-
},
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
589
|
+
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
612
590
|
|
|
613
|
-
|
|
591
|
+
const record = subscription.record
|
|
614
592
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
+
}
|
|
620
598
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
599
|
+
if (timeout > 0 && state && record.state < state) {
|
|
600
|
+
// TODO (perf): Avoid Timer allocation.
|
|
601
|
+
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
602
|
+
}
|
|
625
603
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
+
}
|
|
631
609
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
610
|
+
if (record.version) {
|
|
611
|
+
onUpdate(null, subscription)
|
|
612
|
+
}
|
|
635
613
|
|
|
636
|
-
|
|
614
|
+
return subscription
|
|
615
|
+
})
|
|
637
616
|
}
|
|
638
617
|
|
|
639
618
|
_$handle(message) {
|