@nxtedition/deepstream.io-client-js 25.1.0 → 25.1.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": "25.1.0",
3
+ "version": "25.1.2",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -49,8 +49,8 @@ function onTimeout(subscription) {
49
49
  new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
50
50
  {
51
51
  code: 'ETIMEDOUT',
52
- }
53
- )
52
+ },
53
+ ),
54
54
  )
55
55
  }
56
56
 
@@ -207,10 +207,12 @@ class RecordHandler {
207
207
  }
208
208
  }
209
209
 
210
- getKey(name) {
211
- return name.length <= 8 && this._encoder.encode(name).byteLength === 8
212
- ? name
213
- : this._connection.hasher.h64(name)
210
+ _getKey(name) {
211
+ if (name.length > 8) {
212
+ return this._connection.hasher.h64(name)
213
+ }
214
+ const buf = this._encoder.encode(name)
215
+ return buf.byteLength === 8 ? utils.readBigUInt64BE(buf) : this._connection.hasher.h64Raw(buf)
214
216
  }
215
217
 
216
218
  /**
@@ -220,13 +222,13 @@ class RecordHandler {
220
222
  getRecord(name) {
221
223
  invariant(
222
224
  typeof name === 'string' && name.length > 0 && name !== '[object Object]',
223
- `invalid name ${name}`
225
+ `invalid name ${name}`,
224
226
  )
225
227
 
226
228
  let record = this._records.get(name)
227
229
 
228
230
  if (!record) {
229
- record = new Record(this.getKey(name), name, this)
231
+ record = new Record(this._getKey(name), name, this)
230
232
  this._stats.records += 1
231
233
  this._stats.created += 1
232
234
  this._records.set(name, record)
@@ -294,17 +296,22 @@ class RecordHandler {
294
296
  const patching = [...this._patching.values()]
295
297
  await Promise.race([
296
298
  Promise.all(
297
- patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
299
+ patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
298
300
  ),
299
301
  new Promise((resolve) => {
300
- patchingTimeout = timers.setTimeout(() => {
301
- this._client._$onError(
302
- C.TOPIC.RECORD,
303
- C.EVENT.TIMEOUT,
304
- Object.assign(new Error('sync patching timeout'), { data: { patching, timeout } })
305
- )
306
- resolve(null)
307
- }, timeout ?? 2 * 60e3)
302
+ patchingTimeout = timers.setTimeout(
303
+ () => {
304
+ this._client._$onError(
305
+ C.TOPIC.RECORD,
306
+ C.EVENT.TIMEOUT,
307
+ Object.assign(new Error('sync patching timeout'), {
308
+ data: { patching, timeout },
309
+ }),
310
+ )
311
+ resolve(null)
312
+ },
313
+ timeout ?? 2 * 60e3,
314
+ )
308
315
  }),
309
316
  signalPromise,
310
317
  ]).finally(() => {
@@ -317,17 +324,22 @@ class RecordHandler {
317
324
  const updating = [...this._updating.values()]
318
325
  await Promise.race([
319
326
  Promise.all(
320
- updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
327
+ updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
321
328
  ),
322
329
  new Promise((resolve) => {
323
- updatingTimeout = timers.setTimeout(() => {
324
- this._client._$onError(
325
- C.TOPIC.RECORD,
326
- C.EVENT.TIMEOUT,
327
- Object.assign(new Error('sync updating timeout'), { data: { updating, timeout } })
328
- )
329
- resolve(null)
330
- }, timeout ?? 2 * 60e3)
330
+ updatingTimeout = timers.setTimeout(
331
+ () => {
332
+ this._client._$onError(
333
+ C.TOPIC.RECORD,
334
+ C.EVENT.TIMEOUT,
335
+ Object.assign(new Error('sync updating timeout'), {
336
+ data: { updating, timeout },
337
+ }),
338
+ )
339
+ resolve(null)
340
+ },
341
+ timeout ?? 2 * 60e3,
342
+ )
331
343
  }),
332
344
  signalPromise,
333
345
  ]).finally(() => {
@@ -343,14 +355,17 @@ class RecordHandler {
343
355
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
344
356
  }),
345
357
  new Promise((resolve) => {
346
- serverTimeout = timers.setTimeout(() => {
347
- this._client._$onError(
348
- C.TOPIC.RECORD,
349
- C.EVENT.TIMEOUT,
350
- Object.assign(new Error('sync server timeout'), { data: { token, timeout } })
351
- )
352
- resolve(null)
353
- }, timeout ?? 2 * 60e3)
358
+ serverTimeout = timers.setTimeout(
359
+ () => {
360
+ this._client._$onError(
361
+ C.TOPIC.RECORD,
362
+ C.EVENT.TIMEOUT,
363
+ Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
364
+ )
365
+ resolve(null)
366
+ },
367
+ timeout ?? 2 * 60e3,
368
+ )
354
369
  }),
355
370
  signalPromise,
356
371
  ]).finally(() => {
@@ -423,7 +438,7 @@ class RecordHandler {
423
438
  timeout: 2 * 60e3,
424
439
  dataOnly: true,
425
440
  },
426
- ...args
441
+ ...args,
427
442
  )
428
443
  }
429
444
 
@@ -499,7 +514,7 @@ class RecordHandler {
499
514
  {
500
515
  timeout: 2 * 60e3,
501
516
  },
502
- ...args
517
+ ...args,
503
518
  )
504
519
  }
505
520
 
@@ -28,6 +28,11 @@ class Record {
28
28
  this._subscribed = false
29
29
  }
30
30
 
31
+ /** @type {bigint} */
32
+ get key() {
33
+ return this._key
34
+ }
35
+
31
36
  /** @type {string} */
32
37
  get name() {
33
38
  return this._name
@@ -251,7 +256,7 @@ class Record {
251
256
  onDone(
252
257
  Object.assign(new Error(`timeout ${this.name} [${current}<${expected}]`), {
253
258
  code: 'ETIMEDOUT',
254
- })
259
+ }),
255
260
  )
256
261
  }, timeout)
257
262
  }
@@ -392,7 +397,7 @@ class Record {
392
397
  this._version = nextVersion
393
398
  }
394
399
 
395
- _onUpdate([, version, data, hasProvider]) {
400
+ _onUpdate([, version, data]) {
396
401
  const prevData = this._data
397
402
  const prevVersion = this._version
398
403
  const prevState = this._state
@@ -425,11 +430,17 @@ class Record {
425
430
  this._onPatching(false)
426
431
  }
427
432
 
428
- this._state = hasProvider != null && convertTyped(hasProvider, this._handler._client) === true
429
- ? C.RECORD_STATE.PROVIDER
430
- : this._version.charAt(0) === 'I'
431
- ? C.RECORD_STATE.STALE
432
- : C.RECORD_STATE.SERVER
433
+ if (this._state < C.RECORD_STATE.SERVER) {
434
+ this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
435
+ }
436
+
437
+ // if (hasProvider != null ) {
438
+ // this._state = convertTyped(hasProvider, this._handler._client)
439
+ // ? C.RECORD_STATE.PROVIDER
440
+ // : this._version.charAt(0) === 'I'
441
+ // ? C.RECORD_STATE.STALE
442
+ // : C.RECORD_STATE.SERVER
443
+ // }
433
444
 
434
445
  if (this._state !== prevState || this._data !== prevData || this._version !== prevVersion) {
435
446
  this._emitUpdate()
@@ -475,8 +486,8 @@ class Record {
475
486
  hasProvider && convertTyped(hasProvider, this._handler._client)
476
487
  ? C.RECORD_STATE.PROVIDER
477
488
  : this._version.charAt(0) === 'I'
478
- ? C.RECORD_STATE.STALE
479
- : C.RECORD_STATE.SERVER
489
+ ? C.RECORD_STATE.STALE
490
+ : C.RECORD_STATE.SERVER
480
491
 
481
492
  if (this._state !== prevState) {
482
493
  this._emitUpdate()
@@ -174,3 +174,14 @@ export function removeAbortListener(signal, handler) {
174
174
  }
175
175
  }
176
176
  }
177
+
178
+ export function readBigUInt64BE(buf, offset = 0) {
179
+ const first = buf[offset]
180
+ const last = buf[offset + 7]
181
+
182
+ const hi = first * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + buf[++offset]
183
+
184
+ const lo = buf[++offset] * 2 ** 24 + buf[++offset] * 2 ** 16 + buf[++offset] * 2 ** 8 + last
185
+
186
+ return (BigInt(hi) << 32n) + BigInt(lo)
187
+ }