@nxtedition/deepstream.io-client-js 24.1.9 → 24.1.10

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.
@@ -0,0 +1,14 @@
1
+ import { bench, run } from 'mitata'
2
+ import createDeepstream from '../src/client.js'
3
+
4
+ const ds = createDeepstream('ws://localhost:6020/deepstream')
5
+
6
+ bench('record.get', () => {
7
+ ds.record.get(Math.random().toString())
8
+ })
9
+
10
+ bench('record.observe', () => {
11
+ ds.record.observe(Math.random().toString()).subscribe()
12
+ })
13
+
14
+ await run()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "24.1.9",
3
+ "version": "24.1.10",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -78,6 +78,7 @@
78
78
  "eslint-plugin-promise": "^6.1.1",
79
79
  "husky": "^8.0.3",
80
80
  "lint-staged": "^13.2.2",
81
+ "mitata": "^0.1.11",
81
82
  "pinst": "^3.0.0",
82
83
  "prettier": "^2.8.8"
83
84
  },
@@ -51,6 +51,27 @@ function onTimeout(subscription) {
51
51
  )
52
52
  }
53
53
 
54
+ function onUpdateFast(rec, opaque) {
55
+ if (rec.state >= opaque.state) {
56
+ timers.clearTimeout(opaque.timeout)
57
+ rec.unsubscribe(onUpdateFast, opaque)
58
+ rec.unref()
59
+ opaque.resolve(rec.data)
60
+ }
61
+ }
62
+
63
+ function onTimeoutFast(opaque) {
64
+ opaque.unsubscribe(onUpdateFast, opaque)
65
+ opaque.unref()
66
+ opaque.resolve(
67
+ Promise.reject(
68
+ Object.assign(new Error(`timeout ${opaque.rec.name} [${opaque.rec.state}<${opaque.state}]`), {
69
+ code: 'ETIMEDOUT',
70
+ })
71
+ )
72
+ )
73
+ }
74
+
54
75
  class RecordHandler {
55
76
  constructor(options, connection, client) {
56
77
  this.JSON = jsonPath
@@ -367,14 +388,35 @@ class RecordHandler {
367
388
  * @returns {Promise}
368
389
  */
369
390
  get(...args) {
370
- return new Promise((resolve, reject) => {
371
- this.observe(...args)
372
- .pipe(rx.first())
373
- .subscribe({
374
- next: resolve,
375
- error: reject,
376
- })
377
- })
391
+ if (args.length === 1 || (args.length === 2 && typeof args[1] === 'number')) {
392
+ return new Promise((resolve) => {
393
+ const rec = this.getRecord(args[0])
394
+ const state = args.length === 2 ? args[1] : C.RECORD_STATE.SERVER
395
+
396
+ if (rec.state < state) {
397
+ rec.unref()
398
+ resolve(rec.data)
399
+ } else {
400
+ const opaque = {
401
+ rec,
402
+ state,
403
+ resolve,
404
+ timeout: null,
405
+ }
406
+ opaque.timeout = timers.setTimeout(onTimeoutFast, 2 * 60e3, opaque)
407
+ rec.subscribe(onUpdateFast, opaque)
408
+ }
409
+ })
410
+ } else {
411
+ return new Promise((resolve, reject) => {
412
+ this.observe(...args)
413
+ .pipe(rx.first())
414
+ .subscribe({
415
+ next: resolve,
416
+ error: reject,
417
+ })
418
+ })
419
+ }
378
420
  }
379
421
 
380
422
  /**
@@ -418,7 +460,10 @@ class RecordHandler {
418
460
 
419
461
  let idx = 0
420
462
 
421
- if (idx < args.length && (args[idx] == null || typeof args[idx] === 'string')) {
463
+ if (
464
+ idx < args.length &&
465
+ (args[idx] == null || typeof args[idx] === 'string' || Array.isArray(args[idx]))
466
+ ) {
422
467
  path = args[idx++]
423
468
  }
424
469