@nxtedition/deepstream.io-client-js 31.0.9 → 31.0.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "31.0.9",
3
+ "version": "31.0.11",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -76,7 +76,7 @@ Connection.prototype.authenticate = function (authParams, callback) {
76
76
  }
77
77
 
78
78
  Connection.prototype.sendMsg = function (topic, action, data) {
79
- return this.send(messageBuilder.getMsg(topic, action, data, false /*utils.isNode*/))
79
+ return this.send(messageBuilder.getMsg(topic, action, data, utils.isNode))
80
80
  }
81
81
 
82
82
  Connection.prototype.close = function () {
@@ -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
- first: true,
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 {Promise}
472
+ * @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
479
473
  */
480
- get(...args) {
481
- return new Promise((resolve, reject) => {
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
- get2(...args) {
491
- return new Promise((resolve, reject) => {
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 {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
488
+ * @returns {Promise}
499
489
  */
500
- observe2(...args) {
501
- return this._observe(OBSERVE2_DEFAULTS, ...args)
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) => this._subscribe(subscriber, defaults, name, ...args))
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
- * @returns {{ unsubscribe: () => void }}
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
- let idx = 0
522
+ if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
523
+ const options = args[idx++] || {}
524
524
 
525
- if (
526
- idx < args.length &&
527
- (args[idx] == null ||
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
- if (idx < args.length && (args[idx] == null || typeof args[idx] === 'number')) {
536
- state = args[idx++]
537
- }
529
+ if (options.timeout !== undefined) {
530
+ timeout = options.timeout
531
+ }
538
532
 
539
- if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
540
- const options = args[idx++] || {}
533
+ if (options.path !== undefined) {
534
+ path = options.path
535
+ }
541
536
 
542
- if (options.signal !== undefined) {
543
- signal = options.signal
544
- }
537
+ if (options.state !== undefined) {
538
+ state = options.state
539
+ }
545
540
 
546
- if (options.timeout !== undefined) {
547
- timeout = options.timeout
548
- }
541
+ if (options.dataOnly !== undefined) {
542
+ dataOnly = options.dataOnly
543
+ }
549
544
 
550
- if (options.path !== undefined) {
551
- path = options.path
545
+ if (options.sync !== undefined) {
546
+ sync = options.sync
547
+ }
552
548
  }
553
549
 
554
- if (options.state !== undefined) {
555
- state = options.state
550
+ if (typeof state === 'string') {
551
+ state = C.RECORD_STATE[state.toUpperCase()]
556
552
  }
557
553
 
558
- if (options.dataOnly !== undefined) {
559
- dataOnly = options.dataOnly
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
- if (options.sync !== undefined) {
563
- sync = options.sync
564
- }
575
+ if (this.signal) {
576
+ utils.removeAbortListener(this.signal, this.abort)
577
+ this.signal = null
578
+ this.abort = null
579
+ }
565
580
 
566
- if (options.first !== undefined) {
567
- first = options.first
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
- if (this.record) {
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
- const record = subscription.record
591
+ const record = subscription.record
614
592
 
615
- if (sync && record.state >= C.RECORD_STATE.SERVER) {
616
- this._sync(onSync, sync === true ? 'WEAK' : sync, subscription)
617
- } else {
618
- subscription.synced = true
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
- if (timeout > 0 && state && record.state < state) {
622
- // TODO (perf): Avoid Timer allocation.
623
- subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
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
- if (signal) {
627
- // TODO (perf): Avoid abort closure allocation.
628
- subscription.abort = () => subscriber.error(new utils.AbortError())
629
- utils.addAbortListener(signal, subscription.abort)
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
- if (record.version) {
633
- onUpdate(null, subscription)
634
- }
610
+ if (record.version) {
611
+ onUpdate(null, subscription)
612
+ }
635
613
 
636
- return subscription
614
+ return subscription
615
+ })
637
616
  }
638
617
 
639
618
  _$handle(message) {