@nxtedition/deepstream.io-client-js 28.1.21 → 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.21",
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
 
@@ -450,7 +413,7 @@ class RecordHandler {
450
413
  }
451
414
  }
452
415
 
453
- put(name, version, data) {
416
+ put(name, version, data, parent) {
454
417
  if (typeof name !== 'string' || name.startsWith('_')) {
455
418
  throw new Error('invalid argument: name')
456
419
  }
@@ -463,13 +426,20 @@ class RecordHandler {
463
426
  throw new Error('invalid argument: data')
464
427
  }
465
428
 
429
+ if (parent != null && (typeof version !== 'string' || !/^\d+-/.test(version))) {
430
+ throw new Error('invalid argument: parent')
431
+ }
432
+
466
433
  const update = [name, version, jsonPath.stringify(data)]
434
+
435
+ if (parent) {
436
+ update.push(parent)
437
+ }
438
+
467
439
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.PUT, update)
468
440
 
469
441
  this._putting.set(update, [])
470
- this._sync((update) => {
471
- this._putting.delete(update)
472
- }, update)
442
+ this._sync((update) => this._putting.delete(update), 'WEAK', update)
473
443
  }
474
444
 
475
445
  /**
@@ -536,7 +506,7 @@ class RecordHandler {
536
506
  rec.subscribe(onUpdateFast, opaque)
537
507
 
538
508
  if (!opaque.synced) {
539
- this._sync(onSyncFast, opaque)
509
+ this._sync(onSyncFast, 'WEAK', opaque)
540
510
  }
541
511
  }
542
512
  })
@@ -727,13 +697,14 @@ class RecordHandler {
727
697
 
728
698
  if (connected) {
729
699
  this._connected = Date.now()
730
- for (const token of this._syncEmitter.eventNames()) {
731
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
732
- }
733
700
 
734
701
  for (const update of this._putting.keys()) {
735
702
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.PUT, update)
736
703
  }
704
+
705
+ for (const token of this._syncEmitter.eventNames()) {
706
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
707
+ }
737
708
  } else {
738
709
  this._connected = 0
739
710
  }