@nxtedition/deepstream.io-client-js 31.2.2 → 31.2.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/event/event-handler.d.ts +5 -5
- package/src/record/record-handler.js +72 -41
- package/src/utils/timers.js +22 -4
- package/.claude/settings.local.json +0 -9
- package/nxtedition-deepstream.io-client-js-31.0.18-b1.tgz +0 -0
- package/nxtedition-deepstream.io-client-js-31.0.18-b2.tgz +0 -0
- package/nxtedition-deepstream.io-client-js-31.0.18-b3.tgz +0 -0
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@ import { Observable } from 'rxjs'
|
|
|
3
3
|
export default class EventHandler {
|
|
4
4
|
connected: boolean
|
|
5
5
|
stats: EventStats
|
|
6
|
-
subscribe: (name: string, callback: () => void) => void
|
|
7
|
-
unsubscribe: (name: string, callback: () => void) => void
|
|
8
|
-
on: (name: string, callback: () => void) => this
|
|
9
|
-
once: (name: string, callback: () => void) => this
|
|
10
|
-
off: (name: string, callback: () => void) => this
|
|
6
|
+
subscribe: (name: string, callback: (data: unknown) => void) => void
|
|
7
|
+
unsubscribe: (name: string, callback: (data: unknown) => void) => void
|
|
8
|
+
on: (name: string, callback: (data: unknown) => void) => this
|
|
9
|
+
once: (name: string, callback: (data: unknown) => void) => this
|
|
10
|
+
off: (name: string, callback: (data: unknown) => void) => this
|
|
11
11
|
observe: <Data>(name: string) => Observable<Data>
|
|
12
12
|
emit: <Data>(name: string, data?: Data) => void
|
|
13
13
|
provide: (pattern: string, callback: (name: string) => void, options: unknown) => () => void
|
|
@@ -9,6 +9,8 @@ import * as utils from '../utils/utils.js'
|
|
|
9
9
|
import xuid from 'xuid'
|
|
10
10
|
import * as timers from '../utils/timers.js'
|
|
11
11
|
|
|
12
|
+
/** @import {Timeout} from '../utils/timers.js' */
|
|
13
|
+
|
|
12
14
|
function noop() {}
|
|
13
15
|
|
|
14
16
|
const kEmpty = Symbol('kEmpty')
|
|
@@ -41,17 +43,24 @@ function onUpdate(record, subscription) {
|
|
|
41
43
|
return
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
if (!subscription.synced) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
if (!subscription.synced || subscription.record.state < subscription.state) {
|
|
47
|
+
if (subscription.timeoutValue > 0) {
|
|
48
|
+
if (!subscription.timeoutHandle) {
|
|
49
|
+
subscription.timeoutHandle = timers.setTimeout(
|
|
50
|
+
onTimeout,
|
|
51
|
+
subscription.timeoutValue,
|
|
52
|
+
subscription,
|
|
53
|
+
)
|
|
54
|
+
} else {
|
|
55
|
+
subscription.timeoutHandle.refresh()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
return
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
if (subscription.
|
|
53
|
-
timers.clearTimeout(subscription.
|
|
54
|
-
subscription.
|
|
61
|
+
if (subscription.timeoutHandle) {
|
|
62
|
+
timers.clearTimeout(subscription.timeoutHandle)
|
|
63
|
+
subscription.timeoutHandle = null
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
const data = subscription.path
|
|
@@ -542,11 +551,11 @@ class RecordHandler {
|
|
|
542
551
|
_observe(defaults, name, ...args) {
|
|
543
552
|
return new rxjs.Observable((subscriber) => {
|
|
544
553
|
let path
|
|
545
|
-
let state = defaults?.state
|
|
546
|
-
let signal
|
|
547
|
-
let timeout = defaults?.timeout
|
|
548
|
-
let dataOnly = defaults?.dataOnly
|
|
549
|
-
let sync = defaults?.sync
|
|
554
|
+
let state = defaults?.state ?? C.RECORD_STATE.CLIENT
|
|
555
|
+
let signal = null
|
|
556
|
+
let timeout = defaults?.timeout ?? 0
|
|
557
|
+
let dataOnly = defaults?.dataOnly ?? false
|
|
558
|
+
let sync = defaults?.sync ?? false
|
|
550
559
|
|
|
551
560
|
let idx = 0
|
|
552
561
|
|
|
@@ -596,31 +605,61 @@ class RecordHandler {
|
|
|
596
605
|
state = C.RECORD_STATE[state.toUpperCase()]
|
|
597
606
|
}
|
|
598
607
|
|
|
608
|
+
// TODO (fix): Validate path?
|
|
609
|
+
// TODO (fix): Validate signal?
|
|
610
|
+
|
|
611
|
+
if (!Number.isInteger(state) || state < 0) {
|
|
612
|
+
throw new Error('invalid argument: state')
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (!Number.isInteger(timeout) || timeout < 0) {
|
|
616
|
+
throw new Error('invalid argument: timeout')
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (typeof dataOnly !== 'boolean') {
|
|
620
|
+
throw new Error('invalid argument: dataOnly')
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (typeof sync !== 'boolean') {
|
|
624
|
+
throw new Error('invalid argument: sync')
|
|
625
|
+
}
|
|
626
|
+
|
|
599
627
|
// TODO (perf): Make a class
|
|
600
628
|
const subscription = {
|
|
629
|
+
/** @readonly @type {unknown} */
|
|
601
630
|
subscriber,
|
|
631
|
+
/** @type {Record|null} */
|
|
632
|
+
record: this.getRecord(name),
|
|
633
|
+
/** @readonly @type {unknown} */
|
|
602
634
|
path,
|
|
635
|
+
/** @readonly @type {number} */
|
|
603
636
|
state,
|
|
604
|
-
|
|
637
|
+
/** @type {AbortSignal|null} */
|
|
605
638
|
signal,
|
|
639
|
+
/** @readonly @type {boolean} */
|
|
606
640
|
dataOnly,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
/** @type {
|
|
611
|
-
|
|
641
|
+
/** @readonly @type {number} */
|
|
642
|
+
timeoutValue: timeout,
|
|
643
|
+
|
|
644
|
+
/** @type {Timeout|null} */
|
|
645
|
+
timeoutHandle: null,
|
|
612
646
|
/** @type {Function?} */
|
|
613
647
|
abort: null,
|
|
648
|
+
/** @type {object|Array} */
|
|
649
|
+
data: kEmpty,
|
|
650
|
+
/** @type {boolean} */
|
|
651
|
+
synced: false,
|
|
652
|
+
|
|
614
653
|
unsubscribe() {
|
|
615
|
-
if (this.
|
|
616
|
-
timers.clearTimeout(this.
|
|
617
|
-
this.
|
|
654
|
+
if (this.timeoutHandle) {
|
|
655
|
+
timers.clearTimeout(this.timeoutHandle)
|
|
656
|
+
this.timeoutHandle = null
|
|
618
657
|
}
|
|
619
658
|
|
|
620
659
|
if (this.signal) {
|
|
621
660
|
utils.removeAbortListener(this.signal, this.abort)
|
|
622
|
-
this.signal = null
|
|
623
661
|
this.abort = null
|
|
662
|
+
this.signal = null
|
|
624
663
|
}
|
|
625
664
|
|
|
626
665
|
if (this.record) {
|
|
@@ -631,30 +670,22 @@ class RecordHandler {
|
|
|
631
670
|
},
|
|
632
671
|
}
|
|
633
672
|
|
|
634
|
-
subscription.record
|
|
635
|
-
|
|
636
|
-
const record = subscription.record
|
|
637
|
-
|
|
638
|
-
if (sync && record.state >= C.RECORD_STATE.SERVER) {
|
|
639
|
-
this._sync(onSync, sync === true ? 'WEAK' : sync, subscription)
|
|
640
|
-
} else {
|
|
641
|
-
subscription.synced = true
|
|
642
|
-
}
|
|
673
|
+
if (subscription.record) {
|
|
674
|
+
subscription.record.subscribe(onUpdate, subscription)
|
|
643
675
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
676
|
+
if (sync && subscription.record.state >= C.RECORD_STATE.SERVER) {
|
|
677
|
+
this._sync(onSync, sync === true ? 'WEAK' : sync, subscription)
|
|
678
|
+
} else {
|
|
679
|
+
subscription.synced = true
|
|
680
|
+
}
|
|
647
681
|
}
|
|
648
682
|
|
|
649
|
-
if (signal) {
|
|
650
|
-
// TODO (perf): Avoid abort closure allocation.
|
|
683
|
+
if (subscription.signal) {
|
|
651
684
|
subscription.abort = () => subscriber.error(new utils.AbortError())
|
|
652
|
-
utils.addAbortListener(signal, subscription.abort)
|
|
685
|
+
utils.addAbortListener(subscription.signal, subscription.abort)
|
|
653
686
|
}
|
|
654
687
|
|
|
655
|
-
|
|
656
|
-
onUpdate(null, subscription)
|
|
657
|
-
}
|
|
688
|
+
onUpdate(subscription.record, subscription)
|
|
658
689
|
|
|
659
690
|
return subscription
|
|
660
691
|
})
|
package/src/utils/timers.js
CHANGED
|
@@ -49,7 +49,7 @@ function refreshTimeout() {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
class
|
|
52
|
+
class FastTimeout {
|
|
53
53
|
constructor(callback, delay, opaque) {
|
|
54
54
|
this.callback = callback
|
|
55
55
|
this.delay = delay
|
|
@@ -84,14 +84,32 @@ class Timeout {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {{
|
|
89
|
+
* refresh: () => void,
|
|
90
|
+
* [Symbol.dispose]: () => void,
|
|
91
|
+
* }} Timeout
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {(opaque?: any) => void} callback
|
|
96
|
+
* @param {number} delay
|
|
97
|
+
* @param {any} [opaque]
|
|
98
|
+
* @returns {Timeout}
|
|
99
|
+
*/
|
|
87
100
|
export function setTimeout(callback, delay, opaque) {
|
|
88
101
|
return delay < fastNowInterval
|
|
89
|
-
?
|
|
90
|
-
|
|
102
|
+
? opaque
|
|
103
|
+
? globalThis.setTimeout(() => callback(opaque), delay)
|
|
104
|
+
: globalThis.setTimeout(callback, delay)
|
|
105
|
+
: new FastTimeout(callback, delay, opaque)
|
|
91
106
|
}
|
|
92
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @param {Timeout} timeout
|
|
110
|
+
*/
|
|
93
111
|
export function clearTimeout(timeout) {
|
|
94
|
-
if (timeout instanceof
|
|
112
|
+
if (timeout instanceof FastTimeout) {
|
|
95
113
|
timeout.clear()
|
|
96
114
|
} else {
|
|
97
115
|
globalThis.clearTimeout(timeout)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|