@nxtedition/deepstream.io-client-js 31.2.19 → 32.0.2
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 +13 -13
- package/src/client.test-d.ts +3 -0
- package/src/record/record-handler.d.ts +74 -7
- package/src/record/record-handler.js +48 -43
- package/src/record/record.js +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/deepstream.io-client-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "32.0.2",
|
|
4
4
|
"description": "the javascript client for deepstream.io",
|
|
5
5
|
"homepage": "http://deepstream.io",
|
|
6
6
|
"type": "module",
|
|
@@ -36,36 +36,36 @@
|
|
|
36
36
|
"singleQuote": true
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@nxtedition/json-path": "^
|
|
40
|
-
"bufferutil": "^4.0
|
|
39
|
+
"@nxtedition/json-path": "^2.0.2",
|
|
40
|
+
"bufferutil": "^4.1.0",
|
|
41
41
|
"component-emitter2": "^1.3.5",
|
|
42
42
|
"invariant": "^2.2.4",
|
|
43
43
|
"lodash.clonedeep": "^4.5.0",
|
|
44
|
-
"utf-8-validate": "^6.0.
|
|
44
|
+
"utf-8-validate": "^6.0.6",
|
|
45
45
|
"varint": "^6.0.0",
|
|
46
|
-
"ws": "^8.
|
|
46
|
+
"ws": "^8.19.0",
|
|
47
47
|
"xuid": "^4.1.3",
|
|
48
48
|
"xxhash-wasm": "^1.0.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"eslint": "^9.
|
|
53
|
-
"eslint-config-prettier": "^
|
|
51
|
+
"@types/node": "^25.0.10",
|
|
52
|
+
"eslint": "^9.39.2",
|
|
53
|
+
"eslint-config-prettier": "^10.1.8",
|
|
54
54
|
"eslint-config-standard": "^17.1.0",
|
|
55
55
|
"eslint-plugin-import": "^2.31.0",
|
|
56
|
-
"eslint-plugin-n": "^17.
|
|
56
|
+
"eslint-plugin-n": "^17.23.2",
|
|
57
57
|
"eslint-plugin-node": "^11.1.0",
|
|
58
58
|
"eslint-plugin-promise": "^7.1.0",
|
|
59
59
|
"husky": "^9.1.6",
|
|
60
|
-
"lint-staged": "^
|
|
60
|
+
"lint-staged": "^16.2.7",
|
|
61
61
|
"mitata": "^1.0.10",
|
|
62
62
|
"pinst": "^3.0.0",
|
|
63
|
-
"prettier": "^3.
|
|
63
|
+
"prettier": "^3.8.1",
|
|
64
64
|
"rxjs": "^7.8.1",
|
|
65
65
|
"tsd": "^0.33.0",
|
|
66
|
-
"type-fest": "^4.
|
|
66
|
+
"type-fest": "^5.4.1",
|
|
67
67
|
"typescript": "^5.6.3",
|
|
68
|
-
"typescript-eslint": "^8.
|
|
68
|
+
"typescript-eslint": "^8.53.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"rxjs": ">=6.x"
|
package/src/client.test-d.ts
CHANGED
|
@@ -96,6 +96,9 @@ expectError(ds.record.set('n', 'n1.x2', {}))
|
|
|
96
96
|
expectError(ds.record.set('n', 'n1.n2.n3', { n4: 22 }))
|
|
97
97
|
|
|
98
98
|
expectAssignable<string>(await ds.record.get('p', 'p1'))
|
|
99
|
+
expectAssignable<{ name: string; version: string; state: number; data: string }>(
|
|
100
|
+
await ds.record.get2('p', 'p1'),
|
|
101
|
+
)
|
|
99
102
|
expectAssignable<string>(await ds.record.get('p', 'p1', { signal: new AbortController().signal }))
|
|
100
103
|
expectAssignable<string>(await ds.record.get('p', { path: 'p1' }))
|
|
101
104
|
expectAssignable<string | undefined>(await ds.record.get('p', 'p2'))
|
|
@@ -113,6 +113,73 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
113
113
|
): Observable<Get<Lookup<Records, Name>, Path>>
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
observe2: {
|
|
117
|
+
<Name extends string>(
|
|
118
|
+
name: Name,
|
|
119
|
+
options: ObserveOptions,
|
|
120
|
+
): Observable<{
|
|
121
|
+
name: string
|
|
122
|
+
version: string
|
|
123
|
+
state: number
|
|
124
|
+
data: Lookup<Records, Name>
|
|
125
|
+
}>
|
|
126
|
+
|
|
127
|
+
<Name extends string, Path extends string | string[]>(
|
|
128
|
+
name: Name,
|
|
129
|
+
options: ObserveOptionsWithPath<Path>,
|
|
130
|
+
): Observable<{
|
|
131
|
+
name: string
|
|
132
|
+
version: string
|
|
133
|
+
state: number
|
|
134
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
135
|
+
}>
|
|
136
|
+
|
|
137
|
+
<Name extends string>(
|
|
138
|
+
name: Name,
|
|
139
|
+
state?: number,
|
|
140
|
+
options?: ObserveOptions,
|
|
141
|
+
): Observable<{
|
|
142
|
+
name: string
|
|
143
|
+
version: string
|
|
144
|
+
state: number
|
|
145
|
+
data: Lookup<Records, Name>
|
|
146
|
+
}>
|
|
147
|
+
|
|
148
|
+
<Name extends string, Path extends string | string[]>(
|
|
149
|
+
name: Name,
|
|
150
|
+
state?: number,
|
|
151
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
152
|
+
): Observable<{
|
|
153
|
+
name: string
|
|
154
|
+
version: string
|
|
155
|
+
state: number
|
|
156
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
157
|
+
}>
|
|
158
|
+
|
|
159
|
+
<Name extends string, Path extends string | string[]>(
|
|
160
|
+
name: Name,
|
|
161
|
+
path: Path,
|
|
162
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
163
|
+
): Observable<{
|
|
164
|
+
name: string
|
|
165
|
+
version: string
|
|
166
|
+
state: number
|
|
167
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
168
|
+
}>
|
|
169
|
+
|
|
170
|
+
<Name extends string, Path extends string | string[]>(
|
|
171
|
+
name: Name,
|
|
172
|
+
path: Path,
|
|
173
|
+
state?: number,
|
|
174
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
175
|
+
): Observable<{
|
|
176
|
+
name: string
|
|
177
|
+
version: string
|
|
178
|
+
state: number
|
|
179
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
180
|
+
}>
|
|
181
|
+
}
|
|
182
|
+
|
|
116
183
|
get: {
|
|
117
184
|
<Name extends string>(name: Name, options: ObserveOptions): Promise<Lookup<Records, Name>>
|
|
118
185
|
|
|
@@ -147,11 +214,11 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
147
214
|
): Promise<Get<Lookup<Records, Name>, Path>>
|
|
148
215
|
}
|
|
149
216
|
|
|
150
|
-
|
|
217
|
+
get2: {
|
|
151
218
|
<Name extends string>(
|
|
152
219
|
name: Name,
|
|
153
220
|
options: ObserveOptions,
|
|
154
|
-
):
|
|
221
|
+
): Promise<{
|
|
155
222
|
name: string
|
|
156
223
|
version: string
|
|
157
224
|
state: number
|
|
@@ -161,7 +228,7 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
161
228
|
<Name extends string, Path extends string | string[]>(
|
|
162
229
|
name: Name,
|
|
163
230
|
options: ObserveOptionsWithPath<Path>,
|
|
164
|
-
):
|
|
231
|
+
): Promise<{
|
|
165
232
|
name: string
|
|
166
233
|
version: string
|
|
167
234
|
state: number
|
|
@@ -172,7 +239,7 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
172
239
|
name: Name,
|
|
173
240
|
state?: number,
|
|
174
241
|
options?: ObserveOptions,
|
|
175
|
-
):
|
|
242
|
+
): Promise<{
|
|
176
243
|
name: string
|
|
177
244
|
version: string
|
|
178
245
|
state: number
|
|
@@ -183,7 +250,7 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
183
250
|
name: Name,
|
|
184
251
|
state?: number,
|
|
185
252
|
options?: ObserveOptionsWithPath<Path>,
|
|
186
|
-
):
|
|
253
|
+
): Promise<{
|
|
187
254
|
name: string
|
|
188
255
|
version: string
|
|
189
256
|
state: number
|
|
@@ -194,7 +261,7 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
194
261
|
name: Name,
|
|
195
262
|
path: Path,
|
|
196
263
|
options?: ObserveOptionsWithPath<Path>,
|
|
197
|
-
):
|
|
264
|
+
): Promise<{
|
|
198
265
|
name: string
|
|
199
266
|
version: string
|
|
200
267
|
state: number
|
|
@@ -206,7 +273,7 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
206
273
|
path: Path,
|
|
207
274
|
state?: number,
|
|
208
275
|
options?: ObserveOptionsWithPath<Path>,
|
|
209
|
-
):
|
|
276
|
+
): Promise<{
|
|
210
277
|
name: string
|
|
211
278
|
version: string
|
|
212
279
|
state: number
|
|
@@ -44,17 +44,10 @@ function onUpdate(record, subscription) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (!subscription.synced || subscription.record.state < subscription.state) {
|
|
47
|
-
if (subscription.timeoutValue > 0) {
|
|
48
|
-
if (!subscription.timeout) {
|
|
49
|
-
subscription.timeout = timers.setTimeout(onTimeout, subscription.timeoutValue, subscription)
|
|
50
|
-
} else {
|
|
51
|
-
subscription.timeout.refresh()
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
47
|
return
|
|
55
48
|
}
|
|
56
49
|
|
|
57
|
-
if (subscription.timeout) {
|
|
50
|
+
if (subscription.timeout != null) {
|
|
58
51
|
timers.clearTimeout(subscription.timeout)
|
|
59
52
|
subscription.timeout = null
|
|
60
53
|
}
|
|
@@ -101,6 +94,34 @@ function onTimeout(subscription) {
|
|
|
101
94
|
)
|
|
102
95
|
}
|
|
103
96
|
|
|
97
|
+
class Subscription {
|
|
98
|
+
/** @type {unknown} */
|
|
99
|
+
subscriber = null
|
|
100
|
+
/** @type {unknown} */
|
|
101
|
+
path = null
|
|
102
|
+
/** @type {number} */
|
|
103
|
+
state = 0
|
|
104
|
+
/** @type {AbortSignal|null} */
|
|
105
|
+
signal = null
|
|
106
|
+
/** @type {boolean} */
|
|
107
|
+
dataOnly = false
|
|
108
|
+
|
|
109
|
+
/** @type {Record|null} */
|
|
110
|
+
record = null
|
|
111
|
+
/** @type {Timeout|null} */
|
|
112
|
+
timeout = null
|
|
113
|
+
/** @type {Function?} */
|
|
114
|
+
abort = null
|
|
115
|
+
/** @type {object|Array} */
|
|
116
|
+
data = kEmpty
|
|
117
|
+
/** @type {boolean} */
|
|
118
|
+
synced = false
|
|
119
|
+
|
|
120
|
+
index = -1
|
|
121
|
+
|
|
122
|
+
onUpdate = onUpdate
|
|
123
|
+
}
|
|
124
|
+
|
|
104
125
|
class RecordHandler {
|
|
105
126
|
constructor(options, connection, client) {
|
|
106
127
|
this.JSON = jsonPath
|
|
@@ -163,13 +184,9 @@ class RecordHandler {
|
|
|
163
184
|
_onPruning(rec, value) {
|
|
164
185
|
if (value) {
|
|
165
186
|
this._stats.pruning += 1
|
|
166
|
-
} else {
|
|
167
|
-
this._stats.pruning -= 1
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (value) {
|
|
171
187
|
this._pruning.add(rec)
|
|
172
188
|
} else {
|
|
189
|
+
this._stats.pruning -= 1
|
|
173
190
|
this._pruning.delete(rec)
|
|
174
191
|
}
|
|
175
192
|
}
|
|
@@ -242,15 +259,16 @@ class RecordHandler {
|
|
|
242
259
|
}
|
|
243
260
|
|
|
244
261
|
let record = this._records.get(name)
|
|
245
|
-
|
|
246
262
|
if (!record) {
|
|
247
263
|
record = new Record(name, this)
|
|
248
264
|
this._stats.records += 1
|
|
249
265
|
this._stats.created += 1
|
|
250
266
|
this._records.set(name, record)
|
|
267
|
+
} else {
|
|
268
|
+
record.ref()
|
|
251
269
|
}
|
|
252
270
|
|
|
253
|
-
return record
|
|
271
|
+
return record
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
provide(pattern, callback, options) {
|
|
@@ -638,36 +656,19 @@ class RecordHandler {
|
|
|
638
656
|
}
|
|
639
657
|
|
|
640
658
|
return new rxjs.Observable((subscriber) => {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
subscriber,
|
|
645
|
-
/** @readonly @type {unknown} */
|
|
646
|
-
path,
|
|
647
|
-
/** @readonly @type {number} */
|
|
648
|
-
state,
|
|
649
|
-
/** @type {AbortSignal|null} */
|
|
650
|
-
signal,
|
|
651
|
-
/** @readonly @type {boolean} */
|
|
652
|
-
dataOnly,
|
|
653
|
-
/** @readonly @type {number} */
|
|
654
|
-
timeoutValue: timeout,
|
|
655
|
-
|
|
656
|
-
/** @type {Record|null} */
|
|
657
|
-
record: null,
|
|
658
|
-
/** @type {Timeout|null} */
|
|
659
|
-
timeout: null,
|
|
660
|
-
/** @type {Function?} */
|
|
661
|
-
abort: null,
|
|
662
|
-
/** @type {object|Array} */
|
|
663
|
-
data: kEmpty,
|
|
664
|
-
/** @type {boolean} */
|
|
665
|
-
synced: false,
|
|
666
|
-
|
|
667
|
-
index: -1,
|
|
668
|
-
onUpdate,
|
|
659
|
+
if (signal?.aborted) {
|
|
660
|
+
subscriber.error(new utils.AbortError())
|
|
661
|
+
return
|
|
669
662
|
}
|
|
670
663
|
|
|
664
|
+
const subscription = new Subscription()
|
|
665
|
+
|
|
666
|
+
subscription.subscriber = subscriber
|
|
667
|
+
subscription.path = path
|
|
668
|
+
subscription.state = state
|
|
669
|
+
subscription.signal = signal
|
|
670
|
+
subscription.dataOnly = dataOnly
|
|
671
|
+
|
|
671
672
|
subscriber.add(() => {
|
|
672
673
|
if (subscription.timeout) {
|
|
673
674
|
timers.clearTimeout(subscription.timeout)
|
|
@@ -700,6 +701,10 @@ class RecordHandler {
|
|
|
700
701
|
} else {
|
|
701
702
|
onSync(subscription)
|
|
702
703
|
}
|
|
704
|
+
|
|
705
|
+
if (timeout > 0 && (!subscription.synced || subscription.record.state < subscription.state)) {
|
|
706
|
+
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
707
|
+
}
|
|
703
708
|
})
|
|
704
709
|
}
|
|
705
710
|
|
package/src/record/record.js
CHANGED
|
@@ -16,9 +16,9 @@ class Record {
|
|
|
16
16
|
this._handler = handler
|
|
17
17
|
this._name = name
|
|
18
18
|
this._version = ''
|
|
19
|
-
this._data = jsonPath.
|
|
19
|
+
this._data = jsonPath.EMPTY_OBJ
|
|
20
20
|
this._state = C.RECORD_STATE.VOID
|
|
21
|
-
this._refs =
|
|
21
|
+
this._refs = 1
|
|
22
22
|
this._subscriptions = []
|
|
23
23
|
|
|
24
24
|
/** @type {Array|null} */
|
|
@@ -141,6 +141,11 @@ class Record {
|
|
|
141
141
|
throw new Error('already observing')
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
if (this._emittingArr === this._observers) {
|
|
145
|
+
// TODO (perf): Shift from start if emitting?
|
|
146
|
+
this._observers = this._observers.slice()
|
|
147
|
+
}
|
|
148
|
+
|
|
144
149
|
subscription.index = this._observers.push(subscription) - 1
|
|
145
150
|
}
|
|
146
151
|
|