@nxtedition/deepstream.io-client-js 26.0.4 → 26.0.5
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 +1 -1
- package/src/message/connection.js +10 -10
- package/src/record/record.js +53 -45
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ const Connection = function (client, url, options) {
|
|
|
27
27
|
raw: null,
|
|
28
28
|
topic: null,
|
|
29
29
|
action: null,
|
|
30
|
-
data: null
|
|
30
|
+
data: null,
|
|
31
31
|
}
|
|
32
32
|
this._recvQueue = new FixedQueue()
|
|
33
33
|
this._reconnectTimeout = null
|
|
@@ -49,9 +49,9 @@ Emitter(Connection.prototype)
|
|
|
49
49
|
|
|
50
50
|
// TODO (fix): Remove
|
|
51
51
|
Object.defineProperty(Connection.prototype, 'connected', {
|
|
52
|
-
get: function connected
|
|
52
|
+
get: function connected() {
|
|
53
53
|
return this._state === C.CONNECTION_STATE.OPEN
|
|
54
|
-
}
|
|
54
|
+
},
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
Connection.prototype.getState = function () {
|
|
@@ -94,7 +94,7 @@ Connection.prototype.close = function () {
|
|
|
94
94
|
Connection.prototype._createEndpoint = function () {
|
|
95
95
|
if (utils.isNode) {
|
|
96
96
|
this._endpoint = new NodeWebSocket(this._url, {
|
|
97
|
-
generateMask
|
|
97
|
+
generateMask() {},
|
|
98
98
|
})
|
|
99
99
|
} else {
|
|
100
100
|
this._endpoint = new BrowserWebSocket(this._url)
|
|
@@ -121,7 +121,7 @@ Connection.prototype.send = function (message) {
|
|
|
121
121
|
C.TOPIC.CONNECTION,
|
|
122
122
|
C.EVENT.CONNECTION_ERROR,
|
|
123
123
|
err,
|
|
124
|
-
message.split(C.MESSAGE_PART_SEPERATOR).map((x) => x.slice(0, 256))
|
|
124
|
+
message.split(C.MESSAGE_PART_SEPERATOR).map((x) => x.slice(0, 256)),
|
|
125
125
|
)
|
|
126
126
|
return false
|
|
127
127
|
}
|
|
@@ -170,10 +170,10 @@ Connection.prototype._sendAuthParams = function () {
|
|
|
170
170
|
this._setState(C.CONNECTION_STATE.AUTHENTICATING)
|
|
171
171
|
const authMessage = messageBuilder.getMsg(C.TOPIC.AUTH, C.ACTIONS.REQUEST, [
|
|
172
172
|
this._authParams,
|
|
173
|
-
'
|
|
173
|
+
'26.0.5', // TODO (fix): How to read from package.json?
|
|
174
174
|
utils.isNode
|
|
175
175
|
? `Node/${process.version}`
|
|
176
|
-
: globalThis.navigator && globalThis.navigator.userAgent
|
|
176
|
+
: globalThis.navigator && globalThis.navigator.userAgent,
|
|
177
177
|
])
|
|
178
178
|
this._submit(authMessage)
|
|
179
179
|
}
|
|
@@ -276,7 +276,7 @@ Connection.prototype._handleConnectionResponse = function (message) {
|
|
|
276
276
|
} else if (message.action === C.ACTIONS.CHALLENGE) {
|
|
277
277
|
this._setState(C.CONNECTION_STATE.CHALLENGING)
|
|
278
278
|
this._submit(
|
|
279
|
-
messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [this._url])
|
|
279
|
+
messageBuilder.getMsg(C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [this._url]),
|
|
280
280
|
)
|
|
281
281
|
} else if (message.action === C.ACTIONS.REJECTION) {
|
|
282
282
|
this._challengeDenied = true
|
|
@@ -351,8 +351,8 @@ Connection.prototype._tryReconnect = function () {
|
|
|
351
351
|
},
|
|
352
352
|
Math.min(
|
|
353
353
|
this._options.maxReconnectInterval,
|
|
354
|
-
this._options.reconnectIntervalIncrement * this._reconnectionAttempt
|
|
355
|
-
)
|
|
354
|
+
this._options.reconnectIntervalIncrement * this._reconnectionAttempt,
|
|
355
|
+
),
|
|
356
356
|
)
|
|
357
357
|
this._reconnectionAttempt++
|
|
358
358
|
} else {
|
package/src/record/record.js
CHANGED
|
@@ -12,7 +12,7 @@ import * as timers from '../utils/timers.js'
|
|
|
12
12
|
class Record {
|
|
13
13
|
static STATE = C.RECORD_STATE
|
|
14
14
|
|
|
15
|
-
constructor
|
|
15
|
+
constructor(key, name, handler) {
|
|
16
16
|
this._handler = handler
|
|
17
17
|
this._name = name
|
|
18
18
|
this._key = key
|
|
@@ -29,34 +29,34 @@ class Record {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** @type {string} */
|
|
32
|
-
get name
|
|
32
|
+
get name() {
|
|
33
33
|
return this._name
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/** @type {string} */
|
|
37
|
-
get version
|
|
37
|
+
get version() {
|
|
38
38
|
return this._version
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/** @type {Object} */
|
|
42
|
-
get data
|
|
42
|
+
get data() {
|
|
43
43
|
return this._data
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** @type {Number} */
|
|
47
|
-
get state
|
|
47
|
+
get state() {
|
|
48
48
|
return this._state
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/** @type {Number} */
|
|
52
|
-
get refs
|
|
52
|
+
get refs() {
|
|
53
53
|
return this._refs
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @returns {Record}
|
|
58
58
|
*/
|
|
59
|
-
ref
|
|
59
|
+
ref() {
|
|
60
60
|
const connection = this._handler._connection
|
|
61
61
|
|
|
62
62
|
this._refs += 1
|
|
@@ -72,7 +72,7 @@ class Record {
|
|
|
72
72
|
/**
|
|
73
73
|
* @returns {Record}
|
|
74
74
|
*/
|
|
75
|
-
unref
|
|
75
|
+
unref() {
|
|
76
76
|
this._refs -= 1
|
|
77
77
|
if (this._refs === 0) {
|
|
78
78
|
this._handler._onPruning(this, true)
|
|
@@ -85,7 +85,7 @@ class Record {
|
|
|
85
85
|
* @param {*} opaque
|
|
86
86
|
* @returns {Record}
|
|
87
87
|
*/
|
|
88
|
-
subscribe
|
|
88
|
+
subscribe(fn, opaque = null) {
|
|
89
89
|
if (this._emitting) {
|
|
90
90
|
this._subscriptions = this._subscriptions.slice()
|
|
91
91
|
this._emitting = false
|
|
@@ -102,7 +102,7 @@ class Record {
|
|
|
102
102
|
* @param {*} opaque
|
|
103
103
|
* @returns {Record}
|
|
104
104
|
*/
|
|
105
|
-
unsubscribe
|
|
105
|
+
unsubscribe(fn, opaque = null) {
|
|
106
106
|
if (this._emitting) {
|
|
107
107
|
this._subscriptions = this._subscriptions.slice()
|
|
108
108
|
this._emitting = false
|
|
@@ -126,7 +126,7 @@ class Record {
|
|
|
126
126
|
return this
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
get
|
|
129
|
+
get(path) {
|
|
130
130
|
if (!path) {
|
|
131
131
|
return this._data
|
|
132
132
|
} else if (typeof path === 'string' || Array.isArray(path)) {
|
|
@@ -138,7 +138,7 @@ class Record {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
set
|
|
141
|
+
set(pathOrData, dataOrNil) {
|
|
142
142
|
const prevData = this._data
|
|
143
143
|
const prevVersion = this._version
|
|
144
144
|
|
|
@@ -185,7 +185,7 @@ class Record {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
when
|
|
188
|
+
when(stateOrNil, optionsOrNil) {
|
|
189
189
|
invariant(this._refs > 0, 'missing refs')
|
|
190
190
|
|
|
191
191
|
if (stateOrNil != null && stateOrNil === 'object') {
|
|
@@ -250,8 +250,8 @@ class Record {
|
|
|
250
250
|
|
|
251
251
|
onDone(
|
|
252
252
|
Object.assign(new Error(`timeout ${this.name} [${current}<${expected}]`), {
|
|
253
|
-
code: 'ETIMEDOUT'
|
|
254
|
-
})
|
|
253
|
+
code: 'ETIMEDOUT',
|
|
254
|
+
}),
|
|
255
255
|
)
|
|
256
256
|
}, timeout)
|
|
257
257
|
}
|
|
@@ -263,14 +263,14 @@ class Record {
|
|
|
263
263
|
})
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
update
|
|
266
|
+
update(...args) {
|
|
267
267
|
invariant(this._refs > 0, 'missing refs')
|
|
268
268
|
|
|
269
269
|
if (this._version.charAt(0) === 'I') {
|
|
270
270
|
this._handler._client._$onError(C.TOPIC.RECORD, C.EVENT.UPDATE_ERROR, 'cannot update', [
|
|
271
271
|
this._name,
|
|
272
272
|
this._version,
|
|
273
|
-
this._state
|
|
273
|
+
this._state,
|
|
274
274
|
])
|
|
275
275
|
return Promise.resolve()
|
|
276
276
|
}
|
|
@@ -309,7 +309,7 @@ class Record {
|
|
|
309
309
|
})
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
-
_$onMessage
|
|
312
|
+
_$onMessage(message) {
|
|
313
313
|
if (message.action === C.ACTIONS.UPDATE) {
|
|
314
314
|
this._onUpdate(message.data)
|
|
315
315
|
} else if (message.action === C.ACTIONS.SUBSCRIPTION_HAS_PROVIDER) {
|
|
@@ -321,7 +321,7 @@ class Record {
|
|
|
321
321
|
return true
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
_$onConnectionStateChange
|
|
324
|
+
_$onConnectionStateChange(connected) {
|
|
325
325
|
const connection = this._handler._connection
|
|
326
326
|
|
|
327
327
|
if (connected) {
|
|
@@ -344,7 +344,7 @@ class Record {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
_$dispose
|
|
347
|
+
_$dispose() {
|
|
348
348
|
const connection = this._handler._connection
|
|
349
349
|
|
|
350
350
|
invariant(!this._refs, 'must not have refs')
|
|
@@ -362,7 +362,7 @@ class Record {
|
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
_update
|
|
365
|
+
_update(nextData) {
|
|
366
366
|
invariant(this._version, 'must have version')
|
|
367
367
|
|
|
368
368
|
const connection = this._handler._connection
|
|
@@ -392,7 +392,7 @@ class Record {
|
|
|
392
392
|
this._version = nextVersion
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
_onUpdate
|
|
395
|
+
_onUpdate([, version, data, hasProvider]) {
|
|
396
396
|
const prevData = this._data
|
|
397
397
|
const prevVersion = this._version
|
|
398
398
|
const prevState = this._state
|
|
@@ -429,12 +429,20 @@ class Record {
|
|
|
429
429
|
this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
+
if (hasProvider) {
|
|
433
|
+
this._state = messageParser.convertTyped(hasProvider, this._handler._client)
|
|
434
|
+
? C.RECORD_STATE.PROVIDER
|
|
435
|
+
: this._version.charAt(0) === 'I'
|
|
436
|
+
? C.RECORD_STATE.STALE
|
|
437
|
+
: C.RECORD_STATE.SERVER
|
|
438
|
+
}
|
|
439
|
+
|
|
432
440
|
if (this._state !== prevState || this._data !== prevData || this._version !== prevVersion) {
|
|
433
441
|
this._emitUpdate()
|
|
434
442
|
}
|
|
435
443
|
}
|
|
436
444
|
|
|
437
|
-
_onPatching
|
|
445
|
+
_onPatching(value) {
|
|
438
446
|
invariant(this._refs > 0, 'missing refs')
|
|
439
447
|
|
|
440
448
|
if (value) {
|
|
@@ -448,7 +456,7 @@ class Record {
|
|
|
448
456
|
this._handler._onPatching(this, value)
|
|
449
457
|
}
|
|
450
458
|
|
|
451
|
-
_onUpdating
|
|
459
|
+
_onUpdating(value) {
|
|
452
460
|
invariant(this._refs > 0, 'missing refs')
|
|
453
461
|
|
|
454
462
|
if (value) {
|
|
@@ -462,7 +470,7 @@ class Record {
|
|
|
462
470
|
this._handler._onUpdating(this, value)
|
|
463
471
|
}
|
|
464
472
|
|
|
465
|
-
_onSubscriptionHasProvider
|
|
473
|
+
_onSubscriptionHasProvider([, hasProvider]) {
|
|
466
474
|
if (this._state < C.RECORD_STATE.SERVER) {
|
|
467
475
|
return
|
|
468
476
|
}
|
|
@@ -481,16 +489,16 @@ class Record {
|
|
|
481
489
|
}
|
|
482
490
|
}
|
|
483
491
|
|
|
484
|
-
_error
|
|
492
|
+
_error(event, msgOrError, data) {
|
|
485
493
|
this._handler._client._$onError(C.TOPIC.RECORD, event, msgOrError, [
|
|
486
494
|
...(Array.isArray(data) ? data : []),
|
|
487
495
|
this._name,
|
|
488
496
|
this._version,
|
|
489
|
-
this._state
|
|
497
|
+
this._state,
|
|
490
498
|
])
|
|
491
499
|
}
|
|
492
500
|
|
|
493
|
-
_makeVersion
|
|
501
|
+
_makeVersion(start) {
|
|
494
502
|
let revid = `${xuid()}-${this._handler._client.user || ''}`
|
|
495
503
|
if (revid.length === 32 || revid.length === 16) {
|
|
496
504
|
// HACK: https://github.com/apache/couchdb/issues/2015
|
|
@@ -499,7 +507,7 @@ class Record {
|
|
|
499
507
|
return `${start}-${revid}`
|
|
500
508
|
}
|
|
501
509
|
|
|
502
|
-
_emitUpdate
|
|
510
|
+
_emitUpdate() {
|
|
503
511
|
this._emitting = true
|
|
504
512
|
|
|
505
513
|
const arr = this._subscriptions
|
|
@@ -521,58 +529,58 @@ Record.prototype.destroy = Record.prototype.unref
|
|
|
521
529
|
|
|
522
530
|
// TODO (fix): Remove
|
|
523
531
|
Object.defineProperty(Record.prototype, 'connected', {
|
|
524
|
-
get: function connected
|
|
532
|
+
get: function connected() {
|
|
525
533
|
return this._handler._client.getConnectionState() === C.CONNECTION_STATE.OPEN
|
|
526
|
-
}
|
|
534
|
+
},
|
|
527
535
|
})
|
|
528
536
|
|
|
529
537
|
// TODO (fix): Remove
|
|
530
538
|
Object.defineProperty(Record.prototype, 'empty', {
|
|
531
|
-
get: function empty
|
|
539
|
+
get: function empty() {
|
|
532
540
|
return Object.keys(this.data).length === 0
|
|
533
|
-
}
|
|
541
|
+
},
|
|
534
542
|
})
|
|
535
543
|
|
|
536
544
|
// TODO (fix): Remove
|
|
537
545
|
Object.defineProperty(Record.prototype, 'ready', {
|
|
538
|
-
get: function ready
|
|
546
|
+
get: function ready() {
|
|
539
547
|
return this._state >= C.RECORD_STATE.SERVER
|
|
540
|
-
}
|
|
548
|
+
},
|
|
541
549
|
})
|
|
542
550
|
|
|
543
551
|
// TODO (fix): Remove
|
|
544
552
|
Object.defineProperty(Record.prototype, 'provided', {
|
|
545
|
-
get: function provided
|
|
553
|
+
get: function provided() {
|
|
546
554
|
return this.state >= C.RECORD_STATE.PROVIDER
|
|
547
|
-
}
|
|
555
|
+
},
|
|
548
556
|
})
|
|
549
557
|
|
|
550
558
|
// TODO (fix): Remove
|
|
551
559
|
Object.defineProperty(Record.prototype, 'usages', {
|
|
552
|
-
get: function usages
|
|
560
|
+
get: function usages() {
|
|
553
561
|
return this._refs
|
|
554
|
-
}
|
|
562
|
+
},
|
|
555
563
|
})
|
|
556
564
|
|
|
557
565
|
// TODO (fix): Remove
|
|
558
566
|
Object.defineProperty(Record.prototype, 'stale', {
|
|
559
|
-
get: function ready
|
|
567
|
+
get: function ready() {
|
|
560
568
|
return !this.version
|
|
561
|
-
}
|
|
569
|
+
},
|
|
562
570
|
})
|
|
563
571
|
|
|
564
572
|
// TODO (fix): Remove
|
|
565
573
|
Object.defineProperty(Record.prototype, 'isReady', {
|
|
566
|
-
get: function isReady
|
|
574
|
+
get: function isReady() {
|
|
567
575
|
return this._state >= C.RECORD_STATE.SERVER
|
|
568
|
-
}
|
|
576
|
+
},
|
|
569
577
|
})
|
|
570
578
|
|
|
571
579
|
// TODO (fix): Remove
|
|
572
580
|
Object.defineProperty(Record.prototype, 'hasProvider', {
|
|
573
|
-
get: function hasProvider
|
|
581
|
+
get: function hasProvider() {
|
|
574
582
|
return this.state >= C.RECORD_STATE.PROVIDER
|
|
575
|
-
}
|
|
583
|
+
},
|
|
576
584
|
})
|
|
577
585
|
|
|
578
586
|
export default Record
|