@nxtedition/deepstream.io-client-js 24.2.0 → 24.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "24.2.0",
3
+ "version": "24.2.2",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -140,10 +140,10 @@ Connection.prototype.send = function (message) {
140
140
  if (this._endpoint._socket && !this._corked) {
141
141
  this._endpoint._socket.cork()
142
142
  this._corked = true
143
- setImmediate(() => {
143
+ setTimeout(() => {
144
144
  this._endpoint._socket.uncork()
145
145
  this._corked = false
146
- })
146
+ }, 1)
147
147
  }
148
148
 
149
149
  this.emit('send', message)
@@ -188,7 +188,7 @@ Connection.prototype._onOpen = function () {
188
188
  }
189
189
 
190
190
  Connection.prototype._onError = function (err) {
191
- this._recvMessages()
191
+ this._recvMessages({ didTimeout: true, timeRemaining: () => 0 })
192
192
 
193
193
  if (err.error) {
194
194
  const { message, error } = err
@@ -210,7 +210,7 @@ Connection.prototype._onError = function (err) {
210
210
  }
211
211
 
212
212
  Connection.prototype._onClose = function () {
213
- this._recvMessages()
213
+ this._recvMessages({ didTimeout: true, timeRemaining: () => 0 })
214
214
 
215
215
  if (this._deliberateClose === true) {
216
216
  this._setState(C.CONNECTION_STATE.CLOSED)
@@ -236,7 +236,7 @@ Connection.prototype._recvMessages = function (deadline) {
236
236
  for (
237
237
  let n = 0;
238
238
  // eslint-disable-next-line no-unmodified-loop-condition
239
- n < this._batchSize && (!deadline || deadline.timeRemaining() || deadline.didTimeout);
239
+ deadline ? deadline.didTimeout || deadline.timeRemaining() : n < this._batchSize;
240
240
  ++n
241
241
  ) {
242
242
  const message = this._recvQueue.shift()
@@ -45,9 +45,12 @@ function onTimeout(subscription) {
45
45
  const current = C.RECORD_STATE_NAME[subscription.record.state]
46
46
 
47
47
  subscription.subscriber.error(
48
- Object.assign(new Error(`timeout ${subscription.record.name} [${current}<${expected}]`), {
49
- code: 'ETIMEDOUT',
50
- })
48
+ Object.assign(
49
+ new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
50
+ {
51
+ code: 'ETIMEDOUT',
52
+ }
53
+ )
51
54
  )
52
55
  }
53
56
 
@@ -68,16 +71,20 @@ function onSyncFast(opaque) {
68
71
  }
69
72
 
70
73
  function onTimeoutFast(opaque) {
71
- const { rec, resolve } = opaque
74
+ const { rec, synced, resolve } = opaque
72
75
  rec.unsubscribe(onUpdateFast, opaque)
73
76
  rec.unref()
74
- resolve(
75
- Promise.reject(
76
- Object.assign(new Error(`timeout ${opaque.rec.name} [${opaque.rec.state}<${opaque.state}]`), {
77
- code: 'ETIMEDOUT',
78
- })
79
- )
80
- )
77
+
78
+ let err
79
+ if (rec.state < opaque.state) {
80
+ err = new Error(`timeout state: ${opaque.rec.name} [${opaque.rec.state}<${opaque.state}]`)
81
+ } else if (!synced) {
82
+ err = new Error(`timeout sync: ${opaque.rec.name} `)
83
+ } else {
84
+ err = new Error('timeout')
85
+ }
86
+
87
+ resolve(Promise.reject(Object.assign(err, { code: 'ETIMEDOUT' })))
81
88
  }
82
89
 
83
90
  class RecordHandler {
@@ -356,7 +363,7 @@ class RecordHandler {
356
363
  return
357
364
  }
358
365
 
359
- setImmediate(() => {
366
+ setTimeout(() => {
360
367
  // Token must be universally unique until deepstream properly separates
361
368
  // sync requests from different sockets.
362
369
  const token = xuid()
@@ -367,7 +374,7 @@ class RecordHandler {
367
374
  }
368
375
  })
369
376
  this._connection.sendMsg2(C.TOPIC.RECORD, C.ACTIONS.SYNC, token, 'WEAK')
370
- })
377
+ }, 1)
371
378
  }
372
379
 
373
380
  set(name, ...args) {
@@ -128,7 +128,7 @@ class Record {
128
128
  if (!path) {
129
129
  return this._data
130
130
  } else if (typeof path === 'string' || Array.isArray(path)) {
131
- return path ? jsonPath.get(this._data, path) : this._data
131
+ return jsonPath.get(this._data, path)
132
132
  } else if (typeof path === 'function') {
133
133
  return path(this._data)
134
134
  } else {
@@ -126,7 +126,11 @@ module.exports.AbortError = class AbortError extends Error {
126
126
  }
127
127
  }
128
128
 
129
- module.exports.schedule = isNode ? setImmediate : window.requestIdleCallback
129
+ function defaultSchedule(fn) {
130
+ setTimeout(fn, 0)
131
+ }
132
+
133
+ module.exports.schedule = isNode ? defaultSchedule : window.requestIdleCallback
130
134
 
131
135
  const abortSignals = new WeakMap()
132
136
  const onAbort = function () {