@nxtedition/deepstream.io-client-js 28.1.12 → 28.1.13

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.12",
3
+ "version": "28.1.13",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -101,6 +101,7 @@ class RecordHandler {
101
101
  this._patching = new Map()
102
102
  this._updating = new Map()
103
103
  this._putting = new Set()
104
+ this._syncing = new Set()
104
105
 
105
106
  this._connected = 0
106
107
  this._stats = {
@@ -278,31 +279,41 @@ class RecordHandler {
278
279
  }
279
280
  signal.addEventListener('abort', onAbort)
280
281
  })
281
- : null
282
+ : Promise.resolve()
282
283
  signalPromise?.catch(() => {})
283
284
 
285
+ const sync = {
286
+ status: 'pending',
287
+ data: undefined,
288
+ timeout: timeout || 2 * 60e3,
289
+ timestamp: Date.now(),
290
+ }
291
+
292
+ this._syncing.add(sync)
284
293
  try {
285
294
  if (this._patching.size) {
286
295
  let patchingTimeout
287
296
  const patching = [...this._patching.values()]
297
+
298
+ sync.status = 'patching'
299
+ sync.data = patching
300
+ sync.timestamp = Date.now()
301
+
288
302
  await Promise.race([
289
303
  Promise.all(
290
304
  patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
291
305
  ),
292
306
  new Promise((resolve) => {
293
- patchingTimeout = timers.setTimeout(
294
- () => {
295
- this._client._$onError(
296
- C.TOPIC.RECORD,
297
- C.EVENT.TIMEOUT,
298
- Object.assign(new Error('sync patching timeout'), {
299
- data: { patching, timeout },
300
- }),
301
- )
302
- resolve(null)
303
- },
304
- timeout ?? 2 * 60e3,
305
- )
307
+ patchingTimeout = timers.setTimeout(() => {
308
+ this._client._$onError(
309
+ C.TOPIC.RECORD,
310
+ C.EVENT.TIMEOUT,
311
+ Object.assign(new Error('sync patching timeout'), {
312
+ data: sync,
313
+ }),
314
+ )
315
+ resolve(null)
316
+ }, sync.timeout)
306
317
  }),
307
318
  signalPromise,
308
319
  ]).finally(() => {
@@ -313,24 +324,26 @@ class RecordHandler {
313
324
  if (this._updating.size) {
314
325
  let updatingTimeout
315
326
  const updating = [...this._updating.values()]
327
+
328
+ sync.status = 'updating'
329
+ sync.data = updating
330
+ sync.timestamp = Date.now()
331
+
316
332
  await Promise.race([
317
333
  Promise.all(
318
334
  updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
319
335
  ),
320
336
  new Promise((resolve) => {
321
- updatingTimeout = timers.setTimeout(
322
- () => {
323
- this._client._$onError(
324
- C.TOPIC.RECORD,
325
- C.EVENT.TIMEOUT,
326
- Object.assign(new Error('sync updating timeout'), {
327
- data: { updating, timeout },
328
- }),
329
- )
330
- resolve(null)
331
- },
332
- timeout ?? 2 * 60e3,
333
- )
337
+ updatingTimeout = timers.setTimeout(() => {
338
+ this._client._$onError(
339
+ C.TOPIC.RECORD,
340
+ C.EVENT.TIMEOUT,
341
+ Object.assign(new Error('sync updating timeout'), {
342
+ data: sync,
343
+ }),
344
+ )
345
+ resolve(null)
346
+ }, sync.timeout)
334
347
  }),
335
348
  signalPromise,
336
349
  ]).finally(() => {
@@ -340,29 +353,33 @@ class RecordHandler {
340
353
 
341
354
  let serverTimeout
342
355
  const token = xuid()
356
+
357
+ sync.status = 'token'
358
+ sync.data = token
359
+ sync.timestamp = Date.now()
360
+
343
361
  return await Promise.race([
344
362
  await new Promise((resolve) => {
345
363
  this._syncEmitter.once(token, resolve)
346
364
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
347
365
  }),
348
366
  new Promise((resolve) => {
349
- serverTimeout = timers.setTimeout(
350
- () => {
351
- this._client._$onError(
352
- C.TOPIC.RECORD,
353
- C.EVENT.TIMEOUT,
354
- Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
355
- )
356
- resolve(null)
357
- },
358
- timeout ?? 2 * 60e3,
359
- )
367
+ serverTimeout = timers.setTimeout(() => {
368
+ this._client._$onError(
369
+ C.TOPIC.RECORD,
370
+ C.EVENT.TIMEOUT,
371
+ Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
372
+ )
373
+ resolve(null)
374
+ }, sync.timeout)
360
375
  }),
361
376
  signalPromise,
362
377
  ]).finally(() => {
363
378
  timers.clearTimeout(serverTimeout)
364
379
  })
365
380
  } finally {
381
+ this._syncing.delete(sync)
382
+
366
383
  if (onAbort) {
367
384
  signal?.removeEventListener('abort', onAbort)
368
385
  }