@nxtedition/deepstream.io-client-js 28.1.22 → 28.1.23

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": "28.1.22",
3
+ "version": "28.1.23",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -163,13 +163,16 @@ class RecordHandler {
163
163
  }
164
164
 
165
165
  _onUpdating(rec, value) {
166
+ const callbacks = this._updating.get(rec)
167
+
166
168
  if (value) {
169
+ invariant(!callbacks, 'updating callbacks must not exist')
167
170
  this._stats.updating += 1
168
171
  this._updating.set(rec, [])
169
172
  } else {
170
- this._stats.updating -= 1
173
+ invariant(callbacks, 'updating callbacks must exist')
171
174
 
172
- const callbacks = this._updating.get(rec)
175
+ this._stats.updating -= 1
173
176
  this._updating.delete(rec)
174
177
  for (const callback of callbacks) {
175
178
  callback()
@@ -287,40 +290,6 @@ class RecordHandler {
287
290
 
288
291
  signalPromise?.catch(noop)
289
292
 
290
- if (this._putting.size) {
291
- const promises = []
292
-
293
- {
294
- const puttingPromises = []
295
- for (const callbacks of this._putting.values()) {
296
- puttingPromises.push(new Promise((resolve) => callbacks.push(resolve)))
297
- }
298
- promises.push(puttingPromises)
299
- }
300
-
301
- if (timeout) {
302
- promises.push(
303
- new Promise((resolve) => {
304
- const patchingTimeout = timers.setTimeout(() => {
305
- this._client._$onError(
306
- C.TOPIC.RECORD,
307
- C.EVENT.TIMEOUT,
308
- new Error('sync putting timeout'),
309
- )
310
- resolve(null)
311
- }, timeout)
312
- disposers.push(() => timers.clearTimeout(patchingTimeout))
313
- }),
314
- )
315
- }
316
-
317
- if (signalPromise) {
318
- promises.push(signalPromise)
319
- }
320
-
321
- await Promise.race(promises)
322
- }
323
-
324
293
  if (this._patching.size) {
325
294
  const promises = []
326
295
 
@@ -329,7 +298,7 @@ class RecordHandler {
329
298
  for (const callbacks of this._patching.values()) {
330
299
  patchingPromises.push(new Promise((resolve) => callbacks.push(resolve)))
331
300
  }
332
- promises.push(patchingPromises)
301
+ promises.push(Promise.all(patchingPromises))
333
302
  }
334
303
 
335
304
  if (timeout) {
@@ -363,7 +332,7 @@ class RecordHandler {
363
332
  for (const callbacks of this._updating.values()) {
364
333
  updatingPromises.push(new Promise((resolve) => callbacks.push(resolve)))
365
334
  }
366
- promises.push(updatingPromises)
335
+ promises.push(Promise.all(updatingPromises))
367
336
  }
368
337
 
369
338
  if (timeout) {
@@ -388,13 +357,7 @@ class RecordHandler {
388
357
  {
389
358
  const promises = []
390
359
 
391
- promises.push(
392
- new Promise((resolve) => {
393
- const token = xuid()
394
- this._syncEmitter.once(token, resolve)
395
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
396
- }),
397
- )
360
+ promises.push(new Promise((resolve) => this._sync(resolve)))
398
361
 
399
362
  if (timeout) {
400
363
  promises.push(
@@ -420,7 +383,7 @@ class RecordHandler {
420
383
  }
421
384
  }
422
385
 
423
- _sync(callback, opaque) {
386
+ _sync(callback, type, opaque) {
424
387
  this._syncQueue.push(callback, opaque)
425
388
 
426
389
  if (this._syncQueue.length > 2) {
@@ -437,7 +400,7 @@ class RecordHandler {
437
400
  queue[n](queue[n + 1])
438
401
  }
439
402
  })
440
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token, 'WEAK'])
403
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, type ? [token, type] : [token])
441
404
  }, 1)
442
405
  }
443
406
 
@@ -476,9 +439,7 @@ class RecordHandler {
476
439
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.PUT, update)
477
440
 
478
441
  this._putting.set(update, [])
479
- this._sync((update) => {
480
- this._putting.delete(update)
481
- }, update)
442
+ this._sync((update) => this._putting.delete(update), 'WEAK', update)
482
443
  }
483
444
 
484
445
  /**
@@ -545,7 +506,7 @@ class RecordHandler {
545
506
  rec.subscribe(onUpdateFast, opaque)
546
507
 
547
508
  if (!opaque.synced) {
548
- this._sync(onSyncFast, opaque)
509
+ this._sync(onSyncFast, 'WEAK', opaque)
549
510
  }
550
511
  }
551
512
  })
@@ -736,13 +697,14 @@ class RecordHandler {
736
697
 
737
698
  if (connected) {
738
699
  this._connected = Date.now()
739
- for (const token of this._syncEmitter.eventNames()) {
740
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
741
- }
742
700
 
743
701
  for (const update of this._putting.keys()) {
744
702
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.PUT, update)
745
703
  }
704
+
705
+ for (const token of this._syncEmitter.eventNames()) {
706
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
707
+ }
746
708
  } else {
747
709
  this._connected = 0
748
710
  }