@nxtedition/deepstream.io-client-js 24.0.7 → 24.0.9

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": "24.0.7",
3
+ "version": "24.0.9",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
package/src/client.js CHANGED
@@ -91,7 +91,8 @@ Client.prototype._$onMessage = function (message) {
91
91
  }
92
92
 
93
93
  Client.prototype._$onError = function (topic, event, msgOrError, data) {
94
- const error = msgOrError && msgOrError.message ? msgOrError : new Error(msgOrError)
94
+ const error =
95
+ msgOrError && msgOrError.message ? msgOrError : new Error(msgOrError || 'unknown error')
95
96
  error.topic = topic
96
97
  error.event = event
97
98
  error.data = data
@@ -158,7 +158,15 @@ class RecordHandler {
158
158
  }
159
159
 
160
160
  get stats() {
161
- return this._stats
161
+ let subscriptions = 0
162
+ for (const listener of this._listeners.values()) {
163
+ subscriptions += listener.subscriptions ?? 0
164
+ }
165
+
166
+ return {
167
+ ...this._stats,
168
+ subscriptions,
169
+ }
162
170
  }
163
171
 
164
172
  /**
@@ -376,23 +384,23 @@ class RecordHandler {
376
384
  if (idx < args.length && (args[idx] == null || typeof args[idx] === 'object')) {
377
385
  const options = args[idx++] || {}
378
386
 
379
- if (options.signal != null) {
387
+ if (options.signal !== undefined) {
380
388
  signal = options.signal
381
389
  }
382
390
 
383
- if (options.timeout != null) {
391
+ if (options.timeout !== undefined) {
384
392
  timeout = options.timeout
385
393
  }
386
394
 
387
- if (options.path != null) {
395
+ if (options.path !== undefined) {
388
396
  path = options.path
389
397
  }
390
398
 
391
- if (options.state != null) {
399
+ if (options.state !== undefined) {
392
400
  state = options.state
393
401
  }
394
402
 
395
- if (options.dataOnly != null) {
403
+ if (options.dataOnly !== undefined) {
396
404
  dataOnly = options.dataOnly
397
405
  }
398
406
  }
@@ -435,7 +443,7 @@ class RecordHandler {
435
443
 
436
444
  const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
437
445
 
438
- if (timeout && state && record.state < state) {
446
+ if (timeout > 0 && state && record.state < state) {
439
447
  // TODO (perf): Avoid Timer allocation.
440
448
  subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
441
449
  }
@@ -9,7 +9,7 @@ class Listener {
9
9
  this._handler = handler
10
10
  this._client = this._handler._client
11
11
  this._connection = this._handler._connection
12
- this._providers = new Map()
12
+ this._subscriptions = new Map()
13
13
  this._recursive = recursive
14
14
  this._stringify = stringify || JSON.stringify
15
15
 
@@ -20,6 +20,12 @@ class Listener {
20
20
  return this._client.getConnectionState() === C.CONNECTION_STATE.OPEN
21
21
  }
22
22
 
23
+ get stats() {
24
+ return {
25
+ subscriptions: this._subscriptions.size,
26
+ }
27
+ }
28
+
23
29
  _$destroy() {
24
30
  this._reset()
25
31
 
@@ -42,7 +48,7 @@ class Listener {
42
48
  const name = message.data[1]
43
49
 
44
50
  if (message.action === C.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND) {
45
- if (this._providers.has(name)) {
51
+ if (this._subscriptions.has(name)) {
46
52
  this._error(name, 'invalid add: listener exists')
47
53
  return
48
54
  }
@@ -175,9 +181,9 @@ class Listener {
175
181
 
176
182
  provider.start()
177
183
 
178
- this._providers.set(provider.name, provider)
184
+ this._subscriptions.set(provider.name, provider)
179
185
  } else if (message.action === C.ACTIONS.LISTEN_ACCEPT) {
180
- const provider = this._providers.get(name)
186
+ const provider = this._subscriptions.get(name)
181
187
  if (!provider?.value$) {
182
188
  return
183
189
  }
@@ -189,13 +195,13 @@ class Listener {
189
195
  provider.valueSubscription = provider.value$.subscribe(provider.observer)
190
196
  }
191
197
  } else if (message.action === C.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED) {
192
- const provider = this._providers.get(name)
198
+ const provider = this._subscriptions.get(name)
193
199
 
194
200
  if (!provider) {
195
201
  this._error(name, 'invalid remove: listener missing')
196
202
  } else {
197
203
  provider.stop()
198
- this._providers.delete(provider.name)
204
+ this._subscriptions.delete(provider.name)
199
205
  }
200
206
  } else {
201
207
  return false
@@ -216,10 +222,10 @@ class Listener {
216
222
  }
217
223
 
218
224
  _reset() {
219
- for (const provider of this._providers.values()) {
225
+ for (const provider of this._subscriptions.values()) {
220
226
  provider.stop()
221
227
  }
222
- this._providers.clear()
228
+ this._subscriptions.clear()
223
229
  }
224
230
  }
225
231
 
@@ -43,6 +43,12 @@ class Listener {
43
43
  return this._client.getConnectionState() === C.CONNECTION_STATE.OPEN
44
44
  }
45
45
 
46
+ get stats() {
47
+ return {
48
+ subscriptions: this._subscriptions.size,
49
+ }
50
+ }
51
+
46
52
  _$destroy() {
47
53
  this._reset()
48
54