@nxtedition/deepstream.io-client-js 24.1.9 → 24.1.11
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.
|
|
3
|
+
"version": "24.1.11",
|
|
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
|
},
|
|
@@ -9,8 +9,6 @@ const xxhash = require('xxhash-wasm')
|
|
|
9
9
|
const FixedQueue = require('../utils/fixed-queue')
|
|
10
10
|
const Emitter = require('component-emitter2')
|
|
11
11
|
|
|
12
|
-
const kCorked = Symbol('corked')
|
|
13
|
-
|
|
14
12
|
const Connection = function (client, url, options) {
|
|
15
13
|
this._client = client
|
|
16
14
|
this._options = options
|
|
@@ -108,6 +106,7 @@ Connection.prototype._createEndpoint = function () {
|
|
|
108
106
|
: new NodeWebSocket(this._url, {
|
|
109
107
|
generateMask() {},
|
|
110
108
|
})
|
|
109
|
+
this._corked = false
|
|
111
110
|
|
|
112
111
|
this._endpoint.onopen = this._onOpen.bind(this)
|
|
113
112
|
this._endpoint.onerror = this._onError.bind(this)
|
|
@@ -138,12 +137,12 @@ Connection.prototype.send = function (message) {
|
|
|
138
137
|
return false
|
|
139
138
|
}
|
|
140
139
|
|
|
141
|
-
if (this._endpoint._socket && !this.
|
|
140
|
+
if (this._endpoint._socket && !this._corked) {
|
|
142
141
|
this._endpoint._socket.cork()
|
|
143
|
-
this.
|
|
142
|
+
this._corked = true
|
|
144
143
|
setImmediate(() => {
|
|
145
|
-
this._endpoint[kCorked] = false
|
|
146
144
|
this._endpoint._socket.uncork()
|
|
145
|
+
this._corked = false
|
|
147
146
|
})
|
|
148
147
|
}
|
|
149
148
|
|
|
@@ -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
|
-
|
|
371
|
-
|
|
372
|
-
.
|
|
373
|
-
.
|
|
374
|
-
|
|
375
|
-
|
|
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 (
|
|
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
|
|