@nxtedition/deepstream.io-client-js 26.0.5 → 26.0.8

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": "26.0.5",
3
+ "version": "26.0.8",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
package/src/client.js CHANGED
@@ -36,13 +36,13 @@ const Client = function (url, options) {
36
36
  Emitter(Client.prototype)
37
37
 
38
38
  Object.defineProperty(Client.prototype, 'stats', {
39
- get: function stats () {
39
+ get: function stats() {
40
40
  return {
41
41
  record: this.record.stats,
42
42
  rpc: this.rpc.stats,
43
- event: this.event.stats
43
+ event: this.event.stats,
44
44
  }
45
- }
45
+ },
46
46
  })
47
47
 
48
48
  Client.prototype.login = function (authParamsOrCallback, callback) {
@@ -81,7 +81,7 @@ Client.prototype._$onMessage = function (message) {
81
81
  this._$onError(
82
82
  message.topic,
83
83
  C.EVENT.MESSAGE_PARSE_ERROR,
84
- `Received message for unknown topic ${message.topic}`
84
+ `Received message for unknown topic ${message.topic}`,
85
85
  )
86
86
  }
87
87
 
@@ -127,7 +127,7 @@ Client.prototype._getOptions = function (options) {
127
127
  return mergedOptions
128
128
  }
129
129
 
130
- function createDeepstream (url, options) {
130
+ function createDeepstream(url, options) {
131
131
  return new Client(url, options)
132
132
  }
133
133
 
@@ -5,5 +5,5 @@ export default {
5
5
  maxPacketSize: 1024 * 1024,
6
6
  batchSize: 4096,
7
7
  schedule: null,
8
- logger: null
8
+ logger: null,
9
9
  }
@@ -13,7 +13,7 @@ const EventHandler = function (options, connection, client) {
13
13
  this._emitter = new EventEmitter()
14
14
  this._listeners = new Map()
15
15
  this._stats = {
16
- emitted: 0
16
+ emitted: 0,
17
17
  }
18
18
 
19
19
  this.subscribe = this.subscribe.bind(this)
@@ -26,19 +26,19 @@ const EventHandler = function (options, connection, client) {
26
26
  }
27
27
 
28
28
  Object.defineProperty(EventHandler.prototype, 'connected', {
29
- get: function connected () {
29
+ get: function connected() {
30
30
  return this._client.getConnectionState() === C.CONNECTION_STATE.OPEN
31
- }
31
+ },
32
32
  })
33
33
 
34
34
  Object.defineProperty(EventHandler.prototype, 'stats', {
35
- get: function stats () {
35
+ get: function stats() {
36
36
  return {
37
37
  ...this._stats,
38
38
  listeners: this._listeners.size,
39
- events: this._emitter.eventNames().length
39
+ events: this._emitter.eventNames().length,
40
40
  }
41
- }
41
+ },
42
42
  })
43
43
 
44
44
  EventHandler.prototype.subscribe = function (name, callback) {
@@ -170,7 +170,7 @@ 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
- '26.0.5', // TODO (fix): How to read from package.json?
173
+ '26.0.8', // TODO (fix): How to read from package.json?
174
174
  utils.isNode
175
175
  ? `Node/${process.version}`
176
176
  : globalThis.navigator && globalThis.navigator.userAgent,
@@ -1,6 +1,5 @@
1
1
  import * as C from '../constants/constants.js'
2
2
  import varint from 'varint'
3
- import * as utils from '../utils/utils.js'
4
3
 
5
4
  const poolEncoder = new TextEncoder()
6
5
 
@@ -9,16 +8,14 @@ let poolBuffer
9
8
  let poolView
10
9
  let poolOffset
11
10
 
12
- function allocPool (size) {
11
+ function reallocPool(size) {
13
12
  poolSize = size || poolSize || 1024 * 1024
14
- poolBuffer = utils.isNode
15
- ? globalThis.Buffer.allocUnsafe(poolSize)
16
- : new Uint8Array(new ArrayBuffer(poolSize))
13
+ poolBuffer = new Uint8Array(new ArrayBuffer(poolSize))
17
14
  poolView = new DataView(poolBuffer.buffer)
18
15
  poolOffset = 0
19
16
  }
20
17
 
21
- function alignPool () {
18
+ function alignPool() {
22
19
  // Ensure aligned slices
23
20
  if (poolOffset & 0x7) {
24
21
  poolOffset |= 0x7
@@ -26,22 +23,13 @@ function alignPool () {
26
23
  }
27
24
  }
28
25
 
29
- function writeString (dst, str, offset) {
30
- if (utils.isNode) {
31
- return dst.write(str, offset)
32
- } else {
33
- const res = poolEncoder.encodeInto(str, new Uint8Array(dst.buffer, offset))
34
- return res.written
35
- }
36
- }
37
-
38
- export function getMsg (topic, action, data) {
26
+ export function getMsg(topic, action, data) {
39
27
  if (data && !(data instanceof Array)) {
40
28
  throw new Error('data must be an array')
41
29
  }
42
30
 
43
31
  if (!poolSize || poolOffset + poolSize / 16 >= poolSize) {
44
- allocPool()
32
+ reallocPool()
45
33
  } else {
46
34
  alignPool()
47
35
  }
@@ -68,14 +56,19 @@ export function getMsg (topic, action, data) {
68
56
  len = 0
69
57
  } else if (type === 'object') {
70
58
  poolBuffer[poolOffset++] = 31
71
- len = writeString(poolBuffer, JSON.stringify(data[i]), poolOffset)
59
+ const res = poolEncoder.encodeInto(
60
+ JSON.stringify(data[i]),
61
+ new Uint8Array(poolBuffer.buffer, poolOffset),
62
+ )
63
+ len = res.written
72
64
  } else if (type === 'bigint') {
73
65
  poolBuffer[poolOffset++] = 31
74
66
  poolView.setBigUint64(poolOffset, data[i], false)
75
67
  len = 8
76
68
  } else if (type === 'string') {
77
69
  poolBuffer[poolOffset++] = 31
78
- len = writeString(poolBuffer, data[i], poolOffset)
70
+ const res = poolEncoder.encodeInto(data[i], new Uint8Array(poolBuffer.buffer, poolOffset))
71
+ len = res.written
79
72
  } else {
80
73
  throw new Error('invalid data')
81
74
  }
@@ -89,7 +82,7 @@ export function getMsg (topic, action, data) {
89
82
  }
90
83
 
91
84
  if (poolOffset >= poolBuffer.length) {
92
- allocPool(start === 0 ? poolSize * 2 : poolSize)
85
+ reallocPool(start === 0 ? poolSize * 2 : poolSize)
93
86
  return getMsg(topic, action, data)
94
87
  }
95
88
  }
@@ -98,7 +91,7 @@ export function getMsg (topic, action, data) {
98
91
  return new Uint8Array(poolBuffer.buffer, start, poolOffset - start)
99
92
  }
100
93
 
101
- export function typed (value) {
94
+ export function typed(value) {
102
95
  const type = typeof value
103
96
 
104
97
  if (type === 'string') {
@@ -62,7 +62,7 @@ MessageParser.prototype.parseMessage = function (message, client, result) {
62
62
  client._$onError(
63
63
  C.TOPIC.ERROR,
64
64
  C.EVENT.MESSAGE_PARSE_ERROR,
65
- new Error('Insufficiant message parts')
65
+ new Error('Insufficiant message parts'),
66
66
  )
67
67
  return null
68
68
  }
@@ -77,7 +77,7 @@ MessageParser.prototype.parseMessage = function (message, client, result) {
77
77
  C.TOPIC.ERROR,
78
78
  C.EVENT.MESSAGE_PARSE_ERROR,
79
79
  new Error('Unknown action'),
80
- message
80
+ message,
81
81
  )
82
82
  return null
83
83
  }
@@ -13,7 +13,7 @@ import * as timers from '../utils/timers.js'
13
13
 
14
14
  const kEmpty = Symbol('kEmpty')
15
15
 
16
- function onUpdate (record, subscription) {
16
+ function onUpdate(record, subscription) {
17
17
  if (subscription.state && record.state < subscription.state) {
18
18
  return
19
19
  }
@@ -35,12 +35,12 @@ function onUpdate (record, subscription) {
35
35
  name: record.name,
36
36
  version: record.version,
37
37
  state: record.state,
38
- data
38
+ data,
39
39
  })
40
40
  }
41
41
  }
42
42
 
43
- function onTimeout (subscription) {
43
+ function onTimeout(subscription) {
44
44
  const expected = C.RECORD_STATE_NAME[subscription.state]
45
45
  const current = C.RECORD_STATE_NAME[subscription.record.state]
46
46
 
@@ -48,13 +48,13 @@ function onTimeout (subscription) {
48
48
  Object.assign(
49
49
  new Error(`timeout state: ${subscription.record.name} [${current}<${expected}]`),
50
50
  {
51
- code: 'ETIMEDOUT'
52
- }
53
- )
51
+ code: 'ETIMEDOUT',
52
+ },
53
+ ),
54
54
  )
55
55
  }
56
56
 
57
- function onUpdateFast (rec, opaque) {
57
+ function onUpdateFast(rec, opaque) {
58
58
  const { timeout, resolve, synced, state } = opaque
59
59
 
60
60
  if (rec.state >= state && synced) {
@@ -65,12 +65,12 @@ function onUpdateFast (rec, opaque) {
65
65
  }
66
66
  }
67
67
 
68
- function onSyncFast (opaque) {
68
+ function onSyncFast(opaque) {
69
69
  opaque.synced = true
70
70
  onUpdateFast(opaque.rec, opaque)
71
71
  }
72
72
 
73
- function onTimeoutFast (opaque) {
73
+ function onTimeoutFast(opaque) {
74
74
  const { rec, synced, resolve } = opaque
75
75
  rec.unsubscribe(onUpdateFast, opaque)
76
76
  rec.unref()
@@ -88,7 +88,7 @@ function onTimeoutFast (opaque) {
88
88
  }
89
89
 
90
90
  class RecordHandler {
91
- constructor (options, connection, client) {
91
+ constructor(options, connection, client) {
92
92
  this.JSON = jsonPath
93
93
  this.STATE = C.RECORD_STATE
94
94
  Object.assign(this, C.RECORD_STATE)
@@ -110,7 +110,7 @@ class RecordHandler {
110
110
  destroyed: 0,
111
111
  records: 0,
112
112
  pruning: 0,
113
- patching: 0
113
+ patching: 0,
114
114
  }
115
115
 
116
116
  this._syncQueue = []
@@ -147,7 +147,7 @@ class RecordHandler {
147
147
  this._pruningTimeout = timers.setTimeout(_prune, 1e3)
148
148
  }
149
149
 
150
- _onPruning (rec, value) {
150
+ _onPruning(rec, value) {
151
151
  if (value) {
152
152
  this._stats.pruning += 1
153
153
  } else {
@@ -161,7 +161,7 @@ class RecordHandler {
161
161
  }
162
162
  }
163
163
 
164
- _onUpdating (rec, value) {
164
+ _onUpdating(rec, value) {
165
165
  if (value) {
166
166
  this._stats.updating += 1
167
167
  this._updating.set(rec, [])
@@ -176,7 +176,7 @@ class RecordHandler {
176
176
  }
177
177
  }
178
178
 
179
- _onPatching (rec, value) {
179
+ _onPatching(rec, value) {
180
180
  if (value) {
181
181
  this._stats.patching += 1
182
182
  this._patching.set(rec, [])
@@ -191,11 +191,11 @@ class RecordHandler {
191
191
  }
192
192
  }
193
193
 
194
- get connected () {
194
+ get connected() {
195
195
  return Boolean(this._connected)
196
196
  }
197
197
 
198
- get stats () {
198
+ get stats() {
199
199
  let subscriptions = 0
200
200
  for (const listener of this._listeners.values()) {
201
201
  subscriptions += listener.subscriptions ?? 0
@@ -203,26 +203,24 @@ class RecordHandler {
203
203
 
204
204
  return {
205
205
  ...this._stats,
206
- subscriptions
206
+ subscriptions,
207
207
  }
208
208
  }
209
209
 
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)
210
+ getKey(name) {
211
+ return name.length <= 8 && this._encoder.encode(name).byteLength === 8
212
+ ? name
213
+ : this._connection.hasher.h64(name)
216
214
  }
217
215
 
218
216
  /**
219
217
  * @param {string} name
220
218
  * @returns {Record}
221
219
  */
222
- getRecord (name) {
220
+ getRecord(name) {
223
221
  invariant(
224
222
  typeof name === 'string' && name.length > 0 && name !== '[object Object]',
225
- `invalid name ${name}`
223
+ `invalid name ${name}`,
226
224
  )
227
225
 
228
226
  let record = this._records.get(name)
@@ -237,7 +235,7 @@ class RecordHandler {
237
235
  return record.ref()
238
236
  }
239
237
 
240
- provide (pattern, callback, options) {
238
+ provide(pattern, callback, options) {
241
239
  if (typeof pattern !== 'string' || pattern.length === 0) {
242
240
  throw new Error('invalid argument pattern')
243
241
  }
@@ -272,7 +270,7 @@ class RecordHandler {
272
270
  }
273
271
  }
274
272
 
275
- async sync (opts) {
273
+ async sync(opts) {
276
274
  // TODO (fix): Sync pending? What about VOID state?
277
275
 
278
276
  let onAbort
@@ -282,11 +280,11 @@ class RecordHandler {
282
280
 
283
281
  const signalPromise = signal
284
282
  ? new Promise((resolve, reject) => {
285
- onAbort = () => {
286
- reject(signal.reason ?? new utils.AbortError())
287
- }
288
- signal.addEventListener('abort', onAbort)
289
- })
283
+ onAbort = () => {
284
+ reject(signal.reason ?? new utils.AbortError())
285
+ }
286
+ signal.addEventListener('abort', onAbort)
287
+ })
290
288
  : null
291
289
  signalPromise?.catch(() => {})
292
290
 
@@ -296,7 +294,7 @@ class RecordHandler {
296
294
  const patching = [...this._patching.values()]
297
295
  await Promise.race([
298
296
  Promise.all(
299
- patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
297
+ patching.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
300
298
  ),
301
299
  new Promise((resolve) => {
302
300
  patchingTimeout = timers.setTimeout(
@@ -305,15 +303,15 @@ class RecordHandler {
305
303
  C.TOPIC.RECORD,
306
304
  C.EVENT.TIMEOUT,
307
305
  Object.assign(new Error('sync patching timeout'), {
308
- data: { patching, timeout }
309
- })
306
+ data: { patching, timeout },
307
+ }),
310
308
  )
311
309
  resolve(null)
312
310
  },
313
- timeout ?? 2 * 60e3
311
+ timeout ?? 2 * 60e3,
314
312
  )
315
313
  }),
316
- signalPromise
314
+ signalPromise,
317
315
  ]).finally(() => {
318
316
  timers.clearTimeout(patchingTimeout)
319
317
  })
@@ -324,7 +322,7 @@ class RecordHandler {
324
322
  const updating = [...this._updating.values()]
325
323
  await Promise.race([
326
324
  Promise.all(
327
- updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve)))
325
+ updating.map((callbacks) => new Promise((resolve) => callbacks.push(resolve))),
328
326
  ),
329
327
  new Promise((resolve) => {
330
328
  updatingTimeout = timers.setTimeout(
@@ -333,15 +331,15 @@ class RecordHandler {
333
331
  C.TOPIC.RECORD,
334
332
  C.EVENT.TIMEOUT,
335
333
  Object.assign(new Error('sync updating timeout'), {
336
- data: { updating, timeout }
337
- })
334
+ data: { updating, timeout },
335
+ }),
338
336
  )
339
337
  resolve(null)
340
338
  },
341
- timeout ?? 2 * 60e3
339
+ timeout ?? 2 * 60e3,
342
340
  )
343
341
  }),
344
- signalPromise
342
+ signalPromise,
345
343
  ]).finally(() => {
346
344
  timers.clearTimeout(updatingTimeout)
347
345
  })
@@ -360,14 +358,14 @@ class RecordHandler {
360
358
  this._client._$onError(
361
359
  C.TOPIC.RECORD,
362
360
  C.EVENT.TIMEOUT,
363
- Object.assign(new Error('sync server timeout'), { data: { token, timeout } })
361
+ Object.assign(new Error('sync server timeout'), { data: { token, timeout } }),
364
362
  )
365
363
  resolve(null)
366
364
  },
367
- timeout ?? 2 * 60e3
365
+ timeout ?? 2 * 60e3,
368
366
  )
369
367
  }),
370
- signalPromise
368
+ signalPromise,
371
369
  ]).finally(() => {
372
370
  timers.clearTimeout(serverTimeout)
373
371
  })
@@ -378,7 +376,7 @@ class RecordHandler {
378
376
  }
379
377
  }
380
378
 
381
- _sync (callback, opaque) {
379
+ _sync(callback, opaque) {
382
380
  this._syncQueue.push(callback, opaque)
383
381
 
384
382
  if (this._syncQueue.length > 2) {
@@ -399,7 +397,7 @@ class RecordHandler {
399
397
  }, 1)
400
398
  }
401
399
 
402
- set (name, ...args) {
400
+ set(name, ...args) {
403
401
  const record = this.getRecord(name)
404
402
  try {
405
403
  return record.set(...args)
@@ -414,7 +412,7 @@ class RecordHandler {
414
412
  * @param {...any} args
415
413
  * @returns {Promise}
416
414
  */
417
- update (name, ...args) {
415
+ update(name, ...args) {
418
416
  try {
419
417
  const record = this.getRecord(name)
420
418
  try {
@@ -431,14 +429,14 @@ class RecordHandler {
431
429
  * @param {...any} args
432
430
  * @returns {rxjs.Observable}
433
431
  */
434
- observe (...args) {
432
+ observe(...args) {
435
433
  return this._observe(
436
434
  {
437
435
  state: C.RECORD_STATE.SERVER,
438
436
  timeout: 2 * 60e3,
439
- dataOnly: true
437
+ dataOnly: true,
440
438
  },
441
- ...args
439
+ ...args,
442
440
  )
443
441
  }
444
442
 
@@ -446,7 +444,7 @@ class RecordHandler {
446
444
  * @param {...any} args
447
445
  * @returns {Promise}
448
446
  */
449
- get (...args) {
447
+ get(...args) {
450
448
  if (args.length === 1 || (args.length === 2 && typeof args[1] === 'number')) {
451
449
  return new Promise((resolve) => {
452
450
  const rec = this.getRecord(args[0])
@@ -466,7 +464,7 @@ class RecordHandler {
466
464
  state,
467
465
  resolve,
468
466
  timeout: null,
469
- synced
467
+ synced,
470
468
  }
471
469
  opaque.timeout = timers.setTimeout(onTimeoutFast, 2 * 60e3, opaque)
472
470
  rec.subscribe(onUpdateFast, opaque)
@@ -484,7 +482,7 @@ class RecordHandler {
484
482
  .pipe(rx.first())
485
483
  .subscribe({
486
484
  next: resolve,
487
- error: reject
485
+ error: reject,
488
486
  })
489
487
  })
490
488
  }
@@ -494,13 +492,13 @@ class RecordHandler {
494
492
  * @param {...any} args
495
493
  * @returns {Promise}
496
494
  */
497
- get2 (...args) {
495
+ get2(...args) {
498
496
  return new Promise((resolve, reject) => {
499
497
  this.observe2(...args)
500
498
  .pipe(rx.first())
501
499
  .subscribe({
502
500
  next: resolve,
503
- error: reject
501
+ error: reject,
504
502
  })
505
503
  })
506
504
  }
@@ -509,12 +507,12 @@ class RecordHandler {
509
507
  * @param {...any} args
510
508
  * @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
511
509
  */
512
- observe2 (...args) {
510
+ observe2(...args) {
513
511
  return this._observe(
514
512
  {
515
- timeout: 2 * 60e3
513
+ timeout: 2 * 60e3,
516
514
  },
517
- ...args
515
+ ...args,
518
516
  )
519
517
  }
520
518
 
@@ -522,7 +520,7 @@ class RecordHandler {
522
520
  * @returns {rxjs.Observable}
523
521
  */
524
522
  // TODO (perf): Avoid rest parameters.
525
- _observe (defaults, name, ...args) {
523
+ _observe(defaults, name, ...args) {
526
524
  let path
527
525
  let state = defaults ? defaults.state : undefined
528
526
  let signal
@@ -585,7 +583,7 @@ class RecordHandler {
585
583
  timeout: null,
586
584
  /** @type {Record?} */ record: null,
587
585
  /** @type {Function?} */ abort: null,
588
- unsubscribe () {
586
+ unsubscribe() {
589
587
  if (this.timeout) {
590
588
  timers.clearTimeout(this.timeout)
591
589
  this.timeout = null
@@ -602,7 +600,7 @@ class RecordHandler {
602
600
  this.record.unref()
603
601
  this.record = null
604
602
  }
605
- }
603
+ },
606
604
  }
607
605
 
608
606
  const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
@@ -626,7 +624,7 @@ class RecordHandler {
626
624
  })
627
625
  }
628
626
 
629
- _$handle (message) {
627
+ _$handle(message) {
630
628
  let name
631
629
  if (message.action === C.ACTIONS.ERROR) {
632
630
  name = message.data[1]
@@ -652,7 +650,7 @@ class RecordHandler {
652
650
  return false
653
651
  }
654
652
 
655
- _onConnectionStateChange (connected) {
653
+ _onConnectionStateChange(connected) {
656
654
  for (const listener of this._listeners.values()) {
657
655
  listener._$onConnectionStateChange(connected)
658
656
  }
@@ -392,7 +392,7 @@ class Record {
392
392
  this._version = nextVersion
393
393
  }
394
394
 
395
- _onUpdate([, version, data, hasProvider]) {
395
+ _onUpdate([, version, data]) {
396
396
  const prevData = this._data
397
397
  const prevVersion = this._version
398
398
  const prevState = this._state
@@ -429,14 +429,6 @@ 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
-
440
432
  if (this._state !== prevState || this._data !== prevData || this._version !== prevVersion) {
441
433
  this._emitUpdate()
442
434
  }
@@ -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 {
@@ -186,7 +186,6 @@ class Listener {
186
186
  } else if (message.action === C.ACTIONS.LISTEN_ACCEPT) {
187
187
  const provider = this._subscriptions.get(name)
188
188
  if (!provider?.value$) {
189
- this._error(name, 'invalid accept: listener missing')
190
189
  return
191
190
  }
192
191
 
@@ -211,7 +210,7 @@ class Listener {
211
210
  return true
212
211
  }
213
212
 
214
- _$onConnectionStateChange () {
213
+ _$onConnectionStateChange() {
215
214
  if (this.connected) {
216
215
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern])
217
216
  } else {
@@ -219,11 +218,15 @@ class Listener {
219
218
  }
220
219
  }
221
220
 
222
- _error (name, err) {
223
- this._client._$onError(this._topic, C.EVENT.LISTENER_ERROR, err, [this._pattern, name])
221
+ _error(name, err) {
222
+ this._client._$onError(this._topic, C.EVENT.LISTENER_ERROR, err, [
223
+ this._pattern,
224
+ name,
225
+ this._handler.getKey(name),
226
+ ])
224
227
  }
225
228
 
226
- _reset () {
229
+ _reset() {
227
230
  for (const provider of this._subscriptions.values()) {
228
231
  provider.stop()
229
232
  }
@@ -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
  }
@@ -2,7 +2,7 @@ const NODE_ENV = typeof process !== 'undefined' && process.env && process.env.NO
2
2
  export const isNode = typeof process !== 'undefined' && process.toString() === '[object process]'
3
3
  export const isProduction = NODE_ENV === 'production'
4
4
 
5
- export function deepFreeze (o) {
5
+ export function deepFreeze(o) {
6
6
  if (isProduction) {
7
7
  return o
8
8
  }
@@ -18,7 +18,7 @@ export function deepFreeze (o) {
18
18
  return o
19
19
  }
20
20
 
21
- export function splitRev (s) {
21
+ export function splitRev(s) {
22
22
  if (!s) {
23
23
  return [-1, '00000000000000']
24
24
  }
@@ -29,7 +29,7 @@ export function splitRev (s) {
29
29
  return [ver.charAt(0) === 'I' ? Infinity : parseInt(ver, 10), s.slice(i + 1)]
30
30
  }
31
31
 
32
- export function isPlainObject (value, isPlainJSON) {
32
+ export function isPlainObject(value, isPlainJSON) {
33
33
  if (isPlainJSON) {
34
34
  return value && typeof value === 'object' && !Array.isArray(value)
35
35
  }
@@ -50,13 +50,13 @@ export function isPlainObject (value, isPlainJSON) {
50
50
  return Object.getPrototypeOf(value) === proto
51
51
  }
52
52
 
53
- export function isSameOrNewer (a, b) {
53
+ export function isSameOrNewer(a, b) {
54
54
  const [av, ar] = splitRev(a)
55
55
  const [bv, br] = splitRev(b)
56
56
  return av > bv || (av === bv && ar >= br)
57
57
  }
58
58
 
59
- export function shallowCopy (obj) {
59
+ export function shallowCopy(obj) {
60
60
  if (Array.isArray(obj)) {
61
61
  return obj.slice(0)
62
62
  }
@@ -69,7 +69,7 @@ export function shallowCopy (obj) {
69
69
  return copy
70
70
  }
71
71
 
72
- export function setTimeout (callback, timeoutDuration) {
72
+ export function setTimeout(callback, timeoutDuration) {
73
73
  if (timeoutDuration !== null) {
74
74
  return globalThis.setTimeout(callback, timeoutDuration)
75
75
  } else {
@@ -77,7 +77,7 @@ export function setTimeout (callback, timeoutDuration) {
77
77
  }
78
78
  }
79
79
 
80
- export function setInterval (callback, intervalDuration) {
80
+ export function setInterval(callback, intervalDuration) {
81
81
  if (intervalDuration !== null) {
82
82
  return setInterval(callback, intervalDuration)
83
83
  } else {
@@ -85,7 +85,7 @@ export function setInterval (callback, intervalDuration) {
85
85
  }
86
86
  }
87
87
 
88
- export function compareRev (a, b) {
88
+ export function compareRev(a, b) {
89
89
  if (!a) {
90
90
  return b ? -1 : 0
91
91
  }
@@ -116,14 +116,14 @@ export function compareRev (a, b) {
116
116
  }
117
117
 
118
118
  export class AbortError extends Error {
119
- constructor () {
119
+ constructor() {
120
120
  super('The operation was aborted')
121
121
  this.code = 'ABORT_ERR'
122
122
  this.name = 'AbortError'
123
123
  }
124
124
  }
125
125
 
126
- function defaultSchedule (fn) {
126
+ function defaultSchedule(fn) {
127
127
  setTimeout(fn, 0)
128
128
  }
129
129
 
@@ -139,7 +139,7 @@ const onAbort = function () {
139
139
  }
140
140
  }
141
141
 
142
- export function addAbortListener (signal, handler) {
142
+ export function addAbortListener(signal, handler) {
143
143
  if (!signal) {
144
144
  return
145
145
  }
@@ -157,7 +157,7 @@ export function addAbortListener (signal, handler) {
157
157
  }
158
158
  }
159
159
 
160
- export function removeAbortListener (signal, handler) {
160
+ export function removeAbortListener(signal, handler) {
161
161
  if (!signal) {
162
162
  return
163
163
  }
@@ -174,14 +174,3 @@ 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
- }