@nxtedition/deepstream.io-client-js 26.0.11 → 26.0.13

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.11",
3
+ "version": "26.0.13",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
@@ -75,14 +75,15 @@
75
75
  "eslint-config-prettier": "^9.1.0",
76
76
  "eslint-config-standard": "^17.1.0",
77
77
  "eslint-plugin-import": "^2.29.1",
78
- "eslint-plugin-n": "^17.9.0",
78
+ "eslint-plugin-n": "^17.10.1",
79
79
  "eslint-plugin-node": "^11.1.0",
80
80
  "eslint-plugin-promise": "^7.0.0",
81
- "husky": "^9.1.1",
81
+ "husky": "^9.1.3",
82
82
  "lint-staged": "^15.2.7",
83
83
  "mitata": "^0.1.11",
84
84
  "pinst": "^3.0.0",
85
- "prettier": "^3.3.3"
85
+ "prettier": "^3.3.3",
86
+ "rxjs": "^7.8.1"
86
87
  },
87
88
  "peerDependencies": {
88
89
  "rxjs": ">=6.x"
@@ -1,10 +1,10 @@
1
- import * as C from '../constants/constants.js'
2
1
  import * as messageBuilder from '../message/message-builder.js'
3
2
  import messageParser from '../message/message-parser.js'
3
+ import * as C from '../constants/constants.js'
4
4
  import MulticastListener from '../utils/multicast-listener.js'
5
5
  import UnicastListener from '../utils/unicast-listener.js'
6
6
  import EventEmitter from 'component-emitter2'
7
- import rxjs from 'rxjs'
7
+ import * as rxjs from 'rxjs'
8
8
 
9
9
  const EventHandler = function (options, connection, client) {
10
10
  this._options = options
@@ -6,10 +6,9 @@ import xxhash from 'xxhash-wasm'
6
6
  import FixedQueue from '../utils/fixed-queue.js'
7
7
  import Emitter from 'component-emitter2'
8
8
 
9
- const BrowserWebSocket = globalThis.WebSocket || globalThis.MozWebSocket
10
- const NodeWebSocket = utils.isNode ? await import('ws').then((x) => x.default) : null
11
-
12
9
  const HASHER = await xxhash()
10
+ const NodeWebSocket = utils.isNode ? await import('ws').then((x) => x.default) : null
11
+ const BrowserWebSocket = globalThis.WebSocket || globalThis.MozWebSocket
13
12
 
14
13
  const Connection = function (client, url, options) {
15
14
  this._client = client
@@ -32,6 +31,7 @@ const Connection = function (client, url, options) {
32
31
  this._recvQueue = new FixedQueue()
33
32
  this._reconnectTimeout = null
34
33
  this._reconnectionAttempt = 0
34
+ this._endpoint = null
35
35
 
36
36
  this._processingRecv = false
37
37
  this._recvMessages = this._recvMessages.bind(this)
@@ -86,7 +86,7 @@ Connection.prototype.close = function () {
86
86
  this._endpoint?.close()
87
87
 
88
88
  if (this._reconnectTimeout) {
89
- clearTimeout(this._reconnectTimeout)
89
+ globalThis.clearTimeout(this._reconnectTimeout)
90
90
  this._reconnectTimeout = null
91
91
  }
92
92
  }
@@ -136,7 +136,7 @@ Connection.prototype.send = function (message) {
136
136
  if (this._endpoint._socket && !this._corked) {
137
137
  this._endpoint._socket.cork()
138
138
  this._corked = true
139
- setTimeout(() => {
139
+ globalThis.setTimeout(() => {
140
140
  this._endpoint._socket.uncork()
141
141
  this._corked = false
142
142
  }, 1)
@@ -151,8 +151,8 @@ Connection.prototype.send = function (message) {
151
151
  Connection.prototype._submit = function (message) {
152
152
  const { maxPacketSize } = this._options
153
153
 
154
- if (message.byteLength > maxPacketSize) {
155
- const err = new Error(`Packet to big: ${message.byteLength} > ${maxPacketSize}`)
154
+ if (message.length > maxPacketSize) {
155
+ const err = new Error(`Packet to big: ${message.length} > ${maxPacketSize}`)
156
156
  this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
157
157
  return false
158
158
  } else if (this._endpoint.readyState === this._endpoint.OPEN) {
@@ -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.8', // TODO (fix): How to read from package.json?
173
+ '26.0.0',
174
174
  utils.isNode
175
175
  ? `Node/${process.version}`
176
176
  : globalThis.navigator && globalThis.navigator.userAgent,
@@ -245,10 +245,6 @@ Connection.prototype._recvMessages = function (deadline) {
245
245
  continue
246
246
  }
247
247
 
248
- if (this._logger) {
249
- this._logger.trace(message, 'receive')
250
- }
251
-
252
248
  messageParser.parseMessage(message, this._client, this._message)
253
249
 
254
250
  this.emit('recv', this._message)
@@ -2,7 +2,7 @@ import * as C from '../constants/constants.js'
2
2
  import varint from 'varint'
3
3
  import * as utils from '../utils/utils.js'
4
4
 
5
- const poolEncoder = new TextEncoder()
5
+ const poolEncoder = new globalThis.TextEncoder()
6
6
 
7
7
  let poolSize
8
8
  let poolBuffer
@@ -79,7 +79,6 @@ export function getMsg(topic, action, data) {
79
79
  } else {
80
80
  throw new Error('invalid data')
81
81
  }
82
-
83
82
  poolOffset += len
84
83
 
85
84
  varint.encode(len + 1, poolBuffer, headerPos)
@@ -2,7 +2,7 @@ import Record from './record.js'
2
2
  import MulticastListener from '../utils/multicast-listener.js'
3
3
  import UnicastListener from '../utils/unicast-listener.js'
4
4
  import * as C from '../constants/constants.js'
5
- import rxjs from 'rxjs'
5
+ import * as rxjs from 'rxjs'
6
6
  import invariant from 'invariant'
7
7
  import EventEmitter from 'component-emitter2'
8
8
  import jsonPath from '@nxtedition/json-path'
@@ -101,7 +101,6 @@ class RecordHandler {
101
101
  this._pruning = new Set()
102
102
  this._patching = new Map()
103
103
  this._updating = new Map()
104
- this._encoder = new TextEncoder()
105
104
 
106
105
  this._connected = 0
107
106
  this._stats = {
@@ -207,12 +206,6 @@ class RecordHandler {
207
206
  }
208
207
  }
209
208
 
210
- getKey(name) {
211
- return name.length <= 8 && this._encoder.encode(name).byteLength === 8
212
- ? name
213
- : this._connection.hasher.h64(name)
214
- }
215
-
216
209
  /**
217
210
  * @param {string} name
218
211
  * @returns {Record}
@@ -226,7 +219,7 @@ class RecordHandler {
226
219
  let record = this._records.get(name)
227
220
 
228
221
  if (!record) {
229
- record = new Record(this.getKey(name), name, this)
222
+ record = new Record(name, this)
230
223
  this._stats.records += 1
231
224
  this._stats.created += 1
232
225
  this._records.set(name, record)
@@ -7,25 +7,24 @@ import invariant from 'invariant'
7
7
  import cloneDeep from 'lodash.clonedeep'
8
8
  import * as timers from '../utils/timers.js'
9
9
 
10
- // const encoder = new TextEncoder()
11
-
12
- class Record {
10
+ export default class Record {
13
11
  static STATE = C.RECORD_STATE
14
12
 
15
- constructor(key, name, handler) {
13
+ constructor(name, handler) {
14
+ const connection = handler._connection
15
+
16
16
  this._handler = handler
17
+
17
18
  this._name = name
18
- this._key = key
19
19
  this._version = ''
20
20
  this._data = jsonPath.EMPTY
21
21
  this._state = C.RECORD_STATE.VOID
22
22
  this._refs = 0
23
23
  this._subscriptions = []
24
24
  this._emitting = false
25
-
26
25
  /** @type Map? */ this._updating = null
27
26
  /** @type Array? */ this._patching = null
28
- this._subscribed = false
27
+ this._subscribed = connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
29
28
  }
30
29
 
31
30
  /** @type {string} */
@@ -63,8 +62,7 @@ class Record {
63
62
  if (this._refs === 1) {
64
63
  this._handler._onPruning(this, false)
65
64
  this._subscribed =
66
- this._subscribed ||
67
- connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
65
+ this._subscribed || connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
68
66
  }
69
67
  return this
70
68
  }
@@ -326,8 +324,7 @@ class Record {
326
324
 
327
325
  if (connected) {
328
326
  this._subscribed =
329
- this._refs > 0 &&
330
- connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name, this._key])
327
+ this._refs > 0 && connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
331
328
 
332
329
  if (this._updating) {
333
330
  for (const update of this._updating.values()) {
@@ -352,7 +349,7 @@ class Record {
352
349
  invariant(!this._updating, 'must not have updates')
353
350
 
354
351
  if (this._subscribed) {
355
- connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [this._key])
352
+ connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [this._name])
356
353
  this._subscribed = false
357
354
  }
358
355
 
@@ -374,7 +371,7 @@ class Record {
374
371
  const prevVersion = this._version
375
372
  const nextVersion = this._makeVersion(parseInt(prevVersion) + 1)
376
373
 
377
- const update = [this._key, nextVersion, jsonPath.stringify(nextData), prevVersion]
374
+ const update = [this._name, nextVersion, jsonPath.stringify(nextData), prevVersion]
378
375
 
379
376
  if (!this._updating) {
380
377
  this._onUpdating(true)
@@ -576,5 +573,3 @@ Object.defineProperty(Record.prototype, 'hasProvider', {
576
573
  return this.state >= C.RECORD_STATE.PROVIDER
577
574
  },
578
575
  })
579
-
580
- export default Record
@@ -1,5 +1,5 @@
1
1
  import * as C from '../constants/constants.js'
2
- import rxjs from 'rxjs'
2
+ import * as rxjs from 'rxjs'
3
3
 
4
4
  class Listener {
5
5
  constructor(topic, pattern, callback, handler, { recursive = false, stringify = null } = {}) {
@@ -56,7 +56,6 @@ class Listener {
56
56
  // TODO (refactor): Move to class
57
57
  const provider = {
58
58
  name,
59
- key: this._handler.getKey(name),
60
59
  value$: null,
61
60
  sending: false,
62
61
  accepted: false,
@@ -69,7 +68,7 @@ class Listener {
69
68
  if (this.connected && provider.accepted) {
70
69
  this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [
71
70
  this._pattern,
72
- provider.key,
71
+ provider.name,
73
72
  ])
74
73
  }
75
74
 
@@ -78,7 +77,7 @@ class Listener {
78
77
  provider.accepted = false
79
78
  provider.sending = false
80
79
 
81
- clearTimeout(provider.timeout)
80
+ globalThis.clearTimeout(provider.timeout)
82
81
  provider.timeout = null
83
82
 
84
83
  provider.patternSubscription?.unsubscribe()
@@ -102,7 +101,7 @@ class Listener {
102
101
  this._connection.sendMsg(
103
102
  this._topic,
104
103
  accepted ? C.ACTIONS.LISTEN_ACCEPT : C.ACTIONS.LISTEN_REJECT,
105
- [this._pattern, provider.key],
104
+ [this._pattern, provider.name],
106
105
  )
107
106
 
108
107
  provider.version = null
@@ -158,7 +157,7 @@ class Listener {
158
157
  if (provider.version !== version) {
159
158
  provider.version = version
160
159
  this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, [
161
- provider.key,
160
+ provider.name,
162
161
  version,
163
162
  body,
164
163
  ])
@@ -1,9 +1,8 @@
1
1
  import * as C from '../constants/constants.js'
2
- import rx from 'rxjs/operators'
3
- import rxjs from 'rxjs'
2
+ import * as rxjs from 'rxjs'
4
3
 
5
4
  const PIPE = rxjs.pipe(
6
- rx.map((value) => {
5
+ rxjs.map((value) => {
7
6
  let data
8
7
  if (value && typeof value === 'string') {
9
8
  if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
@@ -18,7 +17,7 @@ const PIPE = rxjs.pipe(
18
17
 
19
18
  return data
20
19
  }),
21
- rx.distinctUntilChanged(),
20
+ rxjs.distinctUntilChanged(),
22
21
  )
23
22
 
24
23
  class Listener {
@@ -68,29 +67,27 @@ class Listener {
68
67
  value$ = rxjs.throwError(() => err)
69
68
  }
70
69
 
71
- const key = this._handler.getKey(name)
72
-
73
70
  if (value$) {
74
71
  const subscription = value$.pipe(PIPE).subscribe({
75
72
  next: (data) => {
76
73
  if (data == null) {
77
- this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, key])
74
+ this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
78
75
  this._subscriptions.delete(name)
79
76
  subscription.unsubscribe()
80
77
  } else {
81
78
  const version = `INF-${this._connection.hasher.h64ToString(data)}`
82
- this._connection.sendMsg(this._topic, C.ACTIONS.UPDATE, [key, version, data])
79
+ this._connection.sendMsg(this._topic, C.ACTIONS.UPDATE, [name, version, data])
83
80
  }
84
81
  },
85
82
  error: (err) => {
86
83
  this._error(name, err)
87
- this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, key])
84
+ this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
88
85
  this._subscriptions.delete(name)
89
86
  },
90
87
  })
91
88
  this._subscriptions.set(name, subscription)
92
89
  } else {
93
- this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, key])
90
+ this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
94
91
  }
95
92
  } else if (message.action === C.ACTIONS.LISTEN_REJECT) {
96
93
  const subscription = this._subscriptions.get(name)
@@ -79,7 +79,7 @@ export function setTimeout(callback, timeoutDuration) {
79
79
 
80
80
  export function setInterval(callback, intervalDuration) {
81
81
  if (intervalDuration !== null) {
82
- return setInterval(callback, intervalDuration)
82
+ return globalThis.setInterval(callback, intervalDuration)
83
83
  } else {
84
84
  return -1
85
85
  }