@nxtedition/deepstream.io-client-js 24.0.3 → 24.0.5

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.3",
3
+ "version": "24.0.5",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -62,7 +62,6 @@ class RecordHandler {
62
62
  this._client = client
63
63
  this._records = new Map()
64
64
  this._listeners = new Map()
65
- this._pending = new Map()
66
65
  this._pruning = new Set()
67
66
 
68
67
  this._connected = 0
@@ -90,8 +89,6 @@ class RecordHandler {
90
89
 
91
90
  this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
92
91
 
93
- this._pruningTimeout = null
94
-
95
92
  const _prune = () => {
96
93
  const pruning = this._pruning
97
94
  this._pruning = new Set()
@@ -105,24 +102,20 @@ class RecordHandler {
105
102
  this._stats.records -= pruning.size
106
103
  this._stats.destroyed += pruning.size
107
104
 
108
- if (this._pruningTimeout) {
109
- this._pruningTimeout.refresh()
110
- } else {
111
- this._pruningTimeout = timers.setTimeout(_prune, 1e3)
112
- }
105
+ this._pruningTimeout.refresh()
113
106
  }
114
107
 
115
- _prune()
108
+ this._pruningTimeout = timers.setTimeout(_prune, 1e3)
116
109
  }
117
110
 
118
- _onPruning(rec, isPruning) {
119
- if (isPruning) {
111
+ _onPruning(rec, value) {
112
+ if (value) {
120
113
  this._stats.pruning += 1
121
114
  } else {
122
115
  this._stats.pruning -= 1
123
116
  }
124
117
 
125
- if (isPruning) {
118
+ if (value) {
126
119
  this._pruning.add(rec)
127
120
  } else {
128
121
  this._pruning.delete(rec)
@@ -135,15 +128,6 @@ class RecordHandler {
135
128
  } else {
136
129
  this._stats.pending -= 1
137
130
  }
138
-
139
- if (value) {
140
- this._pending.set(rec, [])
141
- } else {
142
- for (const callback of this._pending.get(rec)) {
143
- callback()
144
- }
145
- this._pending.delete(rec)
146
- }
147
131
  }
148
132
 
149
133
  _onUpdating(rec, value) {
@@ -229,25 +213,11 @@ class RecordHandler {
229
213
 
230
214
  sync() {
231
215
  // TODO (fix): Sync patching & updating?
216
+ // TODO (fix): Ensure no pending?
232
217
  return new Promise((resolve) => {
233
- let counter = this._pending.size + 1
234
-
235
- const maybeSync = () => {
236
- counter -= 1
237
- if (counter > 0) {
238
- return
239
- }
240
-
241
- const token = xuid()
242
- this._syncEmitter.once(token, resolve)
243
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
244
- }
245
-
246
- for (const callbacks of this._pending.values()) {
247
- callbacks.push(maybeSync)
248
- }
249
-
250
- maybeSync()
218
+ const token = xuid()
219
+ this._syncEmitter.once(token, resolve)
220
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
251
221
  })
252
222
  }
253
223
 
@@ -314,12 +284,18 @@ class RecordHandler {
314
284
  * @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
315
285
  */
316
286
  observe2(...args) {
317
- return this._observe(null, ...args)
287
+ return this._observe(
288
+ {
289
+ timeout: 10 * 60e3,
290
+ },
291
+ ...args
292
+ )
318
293
  }
319
294
 
320
295
  /**
321
296
  * @returns {rxjs.Observable}
322
297
  */
298
+ // TODO (perf): Avoid rest parameters.
323
299
  _observe(defaults, name, ...args) {
324
300
  let path
325
301
  let state = defaults ? defaults.state : undefined
@@ -365,6 +341,7 @@ class RecordHandler {
365
341
  state = C.RECORD_STATE[state.toUpperCase()]
366
342
  }
367
343
 
344
+ // TODO (perf): Avoid subscribe closure allocation.
368
345
  return new rxjs.Observable((subscriber) => {
369
346
  const subscription = {
370
347
  subscriber,
@@ -396,19 +373,21 @@ class RecordHandler {
396
373
  },
397
374
  }
398
375
 
399
- subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
376
+ const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
400
377
 
401
- if (timeout && subscription.state && subscription.record.state < subscription.state) {
378
+ if (timeout && state && record.state < state) {
379
+ // TODO (perf): Avoid Timer allocation.
402
380
  subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
403
381
  }
404
382
 
405
- if (subscription.record.version) {
406
- onUpdate(subscription.record, subscription)
383
+ if (record.version) {
384
+ onUpdate(record, subscription)
407
385
  }
408
386
 
409
- if (subscription.signal) {
410
- subscription.abort = () => subscription.subscriber.error(new utils.AbortError())
411
- utils.addAbortListener(subscription.signal, subscription.abort)
387
+ if (signal) {
388
+ // TODO (perf): Avoid abort closure allocation.
389
+ subscription.abort = () => subscriber.error(new utils.AbortError())
390
+ utils.addAbortListener(signal, subscription.abort)
412
391
  }
413
392
 
414
393
  return subscription
@@ -19,8 +19,8 @@ class Record {
19
19
  this._refs = 0
20
20
  this._subscriptions = []
21
21
  this._emitting = false
22
- this._updating = null
23
- this._patching = null
22
+ /** @type Map? */ this._updating = null
23
+ /** @type Array? */ this._patching = null
24
24
  this._pending = false
25
25
  this._subscribed = this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
26
26
 
@@ -160,7 +160,11 @@ class Record {
160
160
  this._patching.splice(0)
161
161
  }
162
162
 
163
- this._patching.push(path, cloneDeep(data))
163
+ if (this._patching) {
164
+ this._patching.push(path, cloneDeep(data))
165
+ } else {
166
+ throw new Error('invalid state')
167
+ }
164
168
  } else {
165
169
  this._update(jsonPath.set(this._data, path, data, false))
166
170
  }
@@ -311,7 +315,11 @@ class Record {
311
315
  this._onUpdating(true)
312
316
  }
313
317
 
314
- this._updating.set(nextVersion, update)
318
+ if (this._updating) {
319
+ this._updating.set(nextVersion, update)
320
+ } else {
321
+ throw new Error('invalid state')
322
+ }
315
323
 
316
324
  connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
317
325
 
@@ -396,10 +404,8 @@ class Record {
396
404
  _onPending(value) {
397
405
  if (value) {
398
406
  this._pending = true
399
- this.ref()
400
407
  } else {
401
408
  this._pending = false
402
- this.unref()
403
409
  }
404
410
 
405
411
  this._handler._onPending(this, value)
@@ -448,23 +454,15 @@ class Record {
448
454
 
449
455
  _emitUpdate() {
450
456
  this._emitting = true
451
- try {
452
- const arr = this._subscriptions
453
- const len = arr.length
454
-
455
- for (let n = 0; n < len; n += 2) {
456
- try {
457
- arr[n + 0](this, arr[n + 1])
458
- } catch (err) {
459
- this._error(
460
- C.EVENT.USER_ERROR,
461
- Object.assign(new Error('user callback failed'), { cause: err })
462
- )
463
- }
464
- }
465
- } finally {
466
- this._emitting = false
457
+
458
+ const arr = this._subscriptions
459
+ const len = arr.length
460
+
461
+ for (let n = 0; n < len; n += 2) {
462
+ arr[n + 0](this, arr[n + 1])
467
463
  }
464
+
465
+ this._emitting = false
468
466
  }
469
467
  }
470
468