@nxtedition/deepstream.io-client-js 26.0.4 → 26.0.7

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.
@@ -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 (key, name, handler) {
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 (fn, opaque = null) {
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 (fn, opaque = null) {
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 (path) {
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 (pathOrData, dataOrNil) {
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 (stateOrNil, optionsOrNil) {
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 (...args) {
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 (message) {
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 (connected) {
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 (nextData) {
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 ([, version, data]) {
395
+ _onUpdate([, version, data, hasProvider]) {
396
396
  const prevData = this._data
397
397
  const prevVersion = this._version
398
398
  const prevState = this._state
@@ -425,7 +425,9 @@ class Record {
425
425
  this._onPatching(false)
426
426
  }
427
427
 
428
- if (this._state < C.RECORD_STATE.SERVER) {
428
+ if (this._state < C.RECORD_STATE.PROVIDER && hasProvider === 'T') {
429
+ this._state = C.RECORD_STATE.PROVIDER
430
+ } else if (this._state < C.RECORD_STATE.SERVER) {
429
431
  this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
430
432
  }
431
433
 
@@ -434,7 +436,7 @@ class Record {
434
436
  }
435
437
  }
436
438
 
437
- _onPatching (value) {
439
+ _onPatching(value) {
438
440
  invariant(this._refs > 0, 'missing refs')
439
441
 
440
442
  if (value) {
@@ -448,7 +450,7 @@ class Record {
448
450
  this._handler._onPatching(this, value)
449
451
  }
450
452
 
451
- _onUpdating (value) {
453
+ _onUpdating(value) {
452
454
  invariant(this._refs > 0, 'missing refs')
453
455
 
454
456
  if (value) {
@@ -462,7 +464,7 @@ class Record {
462
464
  this._handler._onUpdating(this, value)
463
465
  }
464
466
 
465
- _onSubscriptionHasProvider ([, hasProvider]) {
467
+ _onSubscriptionHasProvider([, hasProvider]) {
466
468
  if (this._state < C.RECORD_STATE.SERVER) {
467
469
  return
468
470
  }
@@ -481,16 +483,16 @@ class Record {
481
483
  }
482
484
  }
483
485
 
484
- _error (event, msgOrError, data) {
486
+ _error(event, msgOrError, data) {
485
487
  this._handler._client._$onError(C.TOPIC.RECORD, event, msgOrError, [
486
488
  ...(Array.isArray(data) ? data : []),
487
489
  this._name,
488
490
  this._version,
489
- this._state
491
+ this._state,
490
492
  ])
491
493
  }
492
494
 
493
- _makeVersion (start) {
495
+ _makeVersion(start) {
494
496
  let revid = `${xuid()}-${this._handler._client.user || ''}`
495
497
  if (revid.length === 32 || revid.length === 16) {
496
498
  // HACK: https://github.com/apache/couchdb/issues/2015
@@ -499,7 +501,7 @@ class Record {
499
501
  return `${start}-${revid}`
500
502
  }
501
503
 
502
- _emitUpdate () {
504
+ _emitUpdate() {
503
505
  this._emitting = true
504
506
 
505
507
  const arr = this._subscriptions
@@ -521,58 +523,58 @@ Record.prototype.destroy = Record.prototype.unref
521
523
 
522
524
  // TODO (fix): Remove
523
525
  Object.defineProperty(Record.prototype, 'connected', {
524
- get: function connected () {
526
+ get: function connected() {
525
527
  return this._handler._client.getConnectionState() === C.CONNECTION_STATE.OPEN
526
- }
528
+ },
527
529
  })
528
530
 
529
531
  // TODO (fix): Remove
530
532
  Object.defineProperty(Record.prototype, 'empty', {
531
- get: function empty () {
533
+ get: function empty() {
532
534
  return Object.keys(this.data).length === 0
533
- }
535
+ },
534
536
  })
535
537
 
536
538
  // TODO (fix): Remove
537
539
  Object.defineProperty(Record.prototype, 'ready', {
538
- get: function ready () {
540
+ get: function ready() {
539
541
  return this._state >= C.RECORD_STATE.SERVER
540
- }
542
+ },
541
543
  })
542
544
 
543
545
  // TODO (fix): Remove
544
546
  Object.defineProperty(Record.prototype, 'provided', {
545
- get: function provided () {
547
+ get: function provided() {
546
548
  return this.state >= C.RECORD_STATE.PROVIDER
547
- }
549
+ },
548
550
  })
549
551
 
550
552
  // TODO (fix): Remove
551
553
  Object.defineProperty(Record.prototype, 'usages', {
552
- get: function usages () {
554
+ get: function usages() {
553
555
  return this._refs
554
- }
556
+ },
555
557
  })
556
558
 
557
559
  // TODO (fix): Remove
558
560
  Object.defineProperty(Record.prototype, 'stale', {
559
- get: function ready () {
561
+ get: function ready() {
560
562
  return !this.version
561
- }
563
+ },
562
564
  })
563
565
 
564
566
  // TODO (fix): Remove
565
567
  Object.defineProperty(Record.prototype, 'isReady', {
566
- get: function isReady () {
568
+ get: function isReady() {
567
569
  return this._state >= C.RECORD_STATE.SERVER
568
- }
570
+ },
569
571
  })
570
572
 
571
573
  // TODO (fix): Remove
572
574
  Object.defineProperty(Record.prototype, 'hasProvider', {
573
- get: function hasProvider () {
575
+ get: function hasProvider() {
574
576
  return this.state >= C.RECORD_STATE.PROVIDER
575
- }
577
+ },
576
578
  })
577
579
 
578
580
  export default Record
@@ -20,19 +20,19 @@ const RpcHandler = function (options, connection, client) {
20
20
  }
21
21
 
22
22
  Object.defineProperty(RpcHandler.prototype, 'connected', {
23
- get: function connected () {
23
+ get: function connected() {
24
24
  return this._client.getConnectionState() === C.CONNECTION_STATE.OPEN
25
- }
25
+ },
26
26
  })
27
27
 
28
28
  Object.defineProperty(RpcHandler.prototype, 'stats', {
29
- get: function stats () {
29
+ get: function stats() {
30
30
  return {
31
31
  ...this._stats,
32
32
  listeners: this._providers.size,
33
- rpcs: this._rpcs.size
33
+ rpcs: this._rpcs.size,
34
34
  }
35
- }
35
+ },
36
36
  })
37
37
 
38
38
  RpcHandler.prototype.provide = function (name, callback) {
@@ -95,7 +95,7 @@ RpcHandler.prototype.make = function (name, data, callback) {
95
95
  id,
96
96
  name,
97
97
  data,
98
- callback
98
+ callback,
99
99
  })
100
100
  this._connection.sendMsg(C.TOPIC.RPC, C.ACTIONS.REQUEST, [name, id, messageBuilder.typed(data)])
101
101
 
@@ -152,8 +152,8 @@ RpcHandler.prototype._$handle = function (message) {
152
152
  Object.assign(new Error(data), {
153
153
  rpcId: rpc.id,
154
154
  rpcName: rpc.name,
155
- rpcData: rpc.data
156
- })
155
+ rpcData: rpc.data,
156
+ }),
157
157
  )
158
158
  } else {
159
159
  rpc.callback(null, messageParser.convertTyped(data, this._client))
@@ -27,7 +27,7 @@ RpcResponse.prototype.error = function (error) {
27
27
  this._name,
28
28
  this._id,
29
29
  error.message || error,
30
- true
30
+ true,
31
31
  ])
32
32
  }
33
33
 
@@ -40,7 +40,7 @@ RpcResponse.prototype.send = function (data) {
40
40
  this._connection.sendMsg(C.TOPIC.RPC, C.ACTIONS.RESPONSE, [
41
41
  this._name,
42
42
  this._id,
43
- messageBuilder.typed(data)
43
+ messageBuilder.typed(data),
44
44
  ])
45
45
  }
46
46
 
@@ -51,27 +51,27 @@ const kMask = kSize - 1
51
51
  // but allows much quicker checks.
52
52
 
53
53
  class FixedCircularBuffer {
54
- constructor () {
54
+ constructor() {
55
55
  this.bottom = 0
56
56
  this.top = 0
57
57
  this.list = new Array(kSize)
58
58
  this.next = null
59
59
  }
60
60
 
61
- isEmpty () {
61
+ isEmpty() {
62
62
  return this.top === this.bottom
63
63
  }
64
64
 
65
- isFull () {
65
+ isFull() {
66
66
  return ((this.top + 1) & kMask) === this.bottom
67
67
  }
68
68
 
69
- push (data) {
69
+ push(data) {
70
70
  this.list[this.top] = data
71
71
  this.top = (this.top + 1) & kMask
72
72
  }
73
73
 
74
- shift () {
74
+ shift() {
75
75
  const nextItem = this.list[this.bottom]
76
76
  if (nextItem === undefined) return null
77
77
  this.list[this.bottom] = undefined
@@ -81,15 +81,15 @@ class FixedCircularBuffer {
81
81
  }
82
82
 
83
83
  export default class FixedQueue {
84
- constructor () {
84
+ constructor() {
85
85
  this.head = this.tail = new FixedCircularBuffer()
86
86
  }
87
87
 
88
- isEmpty () {
88
+ isEmpty() {
89
89
  return this.head.isEmpty()
90
90
  }
91
91
 
92
- push (data) {
92
+ push(data) {
93
93
  if (this.head.isFull()) {
94
94
  // Head is full: Creates a new queue, sets the old queue's `.next` to it,
95
95
  // and sets it as the new main queue.
@@ -98,7 +98,7 @@ export default class FixedQueue {
98
98
  this.head.push(data)
99
99
  }
100
100
 
101
- shift () {
101
+ shift() {
102
102
  const tail = this.tail
103
103
  const next = tail.shift()
104
104
  if (tail.isEmpty() && tail.next !== null) {
@@ -2,7 +2,7 @@ import * as C from '../constants/constants.js'
2
2
  import rxjs from 'rxjs'
3
3
 
4
4
  class Listener {
5
- constructor (topic, pattern, callback, handler, { recursive = false, stringify = null } = {}) {
5
+ constructor(topic, pattern, callback, handler, { recursive = false, stringify = null } = {}) {
6
6
  this._topic = topic
7
7
  this._pattern = pattern
8
8
  this._callback = callback
@@ -16,17 +16,17 @@ class Listener {
16
16
  this._$onConnectionStateChange()
17
17
  }
18
18
 
19
- get connected () {
19
+ get connected() {
20
20
  return this._connection.connected
21
21
  }
22
22
 
23
- get stats () {
23
+ get stats() {
24
24
  return {
25
- subscriptions: this._subscriptions.size
25
+ subscriptions: this._subscriptions.size,
26
26
  }
27
27
  }
28
28
 
29
- _$destroy () {
29
+ _$destroy() {
30
30
  this._reset()
31
31
 
32
32
  if (this.connected) {
@@ -34,13 +34,13 @@ class Listener {
34
34
  }
35
35
  }
36
36
 
37
- _$onMessage (message) {
37
+ _$onMessage(message) {
38
38
  if (!this.connected) {
39
39
  this._client._$onError(
40
40
  C.TOPIC.RECORD,
41
41
  C.EVENT.NOT_CONNECTED,
42
42
  new Error('received message while not connected'),
43
- message
43
+ message,
44
44
  )
45
45
  return
46
46
  }
@@ -63,13 +63,13 @@ class Listener {
63
63
  version: null,
64
64
  timeout: null,
65
65
  patternSubscription: null,
66
- valueSubscription: null
66
+ valueSubscription: null,
67
67
  }
68
68
  provider.stop = () => {
69
69
  if (this.connected && provider.accepted) {
70
70
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [
71
71
  this._pattern,
72
- provider.key
72
+ provider.key,
73
73
  ])
74
74
  }
75
75
 
@@ -102,7 +102,7 @@ class Listener {
102
102
  this._connection.sendMsg(
103
103
  this._topic,
104
104
  accepted ? C.ACTIONS.LISTEN_ACCEPT : C.ACTIONS.LISTEN_REJECT,
105
- [this._pattern, provider.key]
105
+ [this._pattern, provider.key],
106
106
  )
107
107
 
108
108
  provider.version = null
@@ -160,12 +160,12 @@ class Listener {
160
160
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, [
161
161
  provider.key,
162
162
  version,
163
- body
163
+ body,
164
164
  ])
165
165
  }
166
166
  }
167
167
  },
168
- error: provider.error
168
+ error: provider.error,
169
169
  }
170
170
  provider.start = () => {
171
171
  try {
@@ -211,7 +211,7 @@ class Listener {
211
211
  return true
212
212
  }
213
213
 
214
- _$onConnectionStateChange () {
214
+ _$onConnectionStateChange() {
215
215
  if (this.connected) {
216
216
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern])
217
217
  } else {
@@ -219,11 +219,11 @@ class Listener {
219
219
  }
220
220
  }
221
221
 
222
- _error (name, err) {
222
+ _error(name, err) {
223
223
  this._client._$onError(this._topic, C.EVENT.LISTENER_ERROR, err, [this._pattern, name])
224
224
  }
225
225
 
226
- _reset () {
226
+ _reset() {
227
227
  for (const provider of this._subscriptions.values()) {
228
228
  provider.stop()
229
229
  }
@@ -3,7 +3,7 @@ let fastNowTimeout
3
3
 
4
4
  const fastTimers = []
5
5
 
6
- function onTimeout () {
6
+ function onTimeout() {
7
7
  fastNow = Date.now()
8
8
 
9
9
  let len = fastTimers.length
@@ -36,7 +36,7 @@ function onTimeout () {
36
36
  }
37
37
  }
38
38
 
39
- function refreshTimeout () {
39
+ function refreshTimeout() {
40
40
  if (fastNowTimeout && fastNowTimeout.refresh) {
41
41
  fastNowTimeout.refresh()
42
42
  } else {
@@ -49,7 +49,7 @@ function refreshTimeout () {
49
49
  }
50
50
 
51
51
  class Timeout {
52
- constructor (callback, delay, opaque) {
52
+ constructor(callback, delay, opaque) {
53
53
  this.callback = callback
54
54
  this.delay = delay
55
55
  this.opaque = opaque
@@ -63,7 +63,7 @@ class Timeout {
63
63
  this.refresh()
64
64
  }
65
65
 
66
- refresh () {
66
+ refresh() {
67
67
  if (this.state === -2) {
68
68
  fastTimers.push(this)
69
69
  if (!fastNowTimeout || fastTimers.length === 1) {
@@ -74,18 +74,18 @@ class Timeout {
74
74
  this.state = 0
75
75
  }
76
76
 
77
- clear () {
77
+ clear() {
78
78
  this.state = -1
79
79
  }
80
80
  }
81
81
 
82
- export function setTimeout (callback, delay, opaque) {
82
+ export function setTimeout(callback, delay, opaque) {
83
83
  return delay < 1e3
84
84
  ? globalThis.setTimeout(callback, delay, opaque)
85
85
  : new Timeout(callback, delay, opaque)
86
86
  }
87
87
 
88
- export function clearTimeout (timeout) {
88
+ export function clearTimeout(timeout) {
89
89
  if (timeout instanceof Timeout) {
90
90
  timeout.clear()
91
91
  } else {
@@ -18,11 +18,11 @@ const PIPE = rxjs.pipe(
18
18
 
19
19
  return data
20
20
  }),
21
- rx.distinctUntilChanged()
21
+ rx.distinctUntilChanged(),
22
22
  )
23
23
 
24
24
  class Listener {
25
- constructor (topic, pattern, callback, handler, opts) {
25
+ constructor(topic, pattern, callback, handler, opts) {
26
26
  if (opts.recursive) {
27
27
  throw new Error('invalid argument: recursive')
28
28
  }
@@ -42,17 +42,17 @@ class Listener {
42
42
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern, 'U'])
43
43
  }
44
44
 
45
- get stats () {
45
+ get stats() {
46
46
  return {
47
- subscriptions: this._subscriptions.size
47
+ subscriptions: this._subscriptions.size,
48
48
  }
49
49
  }
50
50
 
51
- _$destroy () {
51
+ _$destroy() {
52
52
  this._reset()
53
53
  }
54
54
 
55
- _$onMessage (message) {
55
+ _$onMessage(message) {
56
56
  const name = message.data[1]
57
57
 
58
58
  if (message.action === C.ACTIONS.LISTEN_ACCEPT) {
@@ -86,7 +86,7 @@ class Listener {
86
86
  this._error(name, err)
87
87
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, key])
88
88
  this._subscriptions.delete(name)
89
- }
89
+ },
90
90
  })
91
91
  this._subscriptions.set(name, subscription)
92
92
  } else {
@@ -107,7 +107,7 @@ class Listener {
107
107
  return true
108
108
  }
109
109
 
110
- _$onConnectionStateChange (connected) {
110
+ _$onConnectionStateChange(connected) {
111
111
  if (connected) {
112
112
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern, 'U'])
113
113
  } else {
@@ -115,11 +115,11 @@ class Listener {
115
115
  }
116
116
  }
117
117
 
118
- _error (name, err) {
118
+ _error(name, err) {
119
119
  this._client._$onError(this._topic, C.EVENT.LISTENER_ERROR, err, [this._pattern, name])
120
120
  }
121
121
 
122
- _reset () {
122
+ _reset() {
123
123
  for (const subscription of this._subscriptions.values()) {
124
124
  subscription.unsubscribe()
125
125
  }