@nxtedition/deepstream.io-client-js 24.4.4 → 24.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "24.4.4",
3
+ "version": "24.4.5",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
package/src/client.js CHANGED
@@ -1,12 +1,12 @@
1
- import * as C from './constants/constants.js'
2
- import Emitter from 'component-emitter2'
3
- import Connection from './message/connection.js'
4
- import EventHandler from './event/event-handler.js'
5
- import RpcHandler from './rpc/rpc-handler.js'
6
- import RecordHandler from './record/record-handler.js'
7
- import defaultOptions from './default-options.js'
8
- import xuid from 'xuid'
9
- import * as utils from './utils/utils.js'
1
+ const C = require('./constants/constants')
2
+ const Emitter = require('component-emitter2')
3
+ const Connection = require('./message/connection')
4
+ const EventHandler = require('./event/event-handler')
5
+ const RpcHandler = require('./rpc/rpc-handler')
6
+ const RecordHandler = require('./record/record-handler')
7
+ const defaultOptions = require('./default-options')
8
+ const xuid = require('xuid')
9
+ const utils = require('./utils/utils')
10
10
 
11
11
  const Client = function (url, options) {
12
12
  this._url = url
@@ -127,10 +127,12 @@ Client.prototype._getOptions = function (options) {
127
127
  return mergedOptions
128
128
  }
129
129
 
130
- export default function createDeepstream(url, options) {
130
+ function createDeepstream(url, options) {
131
131
  return new Client(url, options)
132
132
  }
133
133
 
134
134
  Client.prototype.isSameOrNewer = utils.isSameOrNewer
135
135
  Client.prototype.CONSTANTS = C
136
136
  createDeepstream.CONSTANTS = C
137
+
138
+ module.exports = createDeepstream
@@ -1,98 +1,98 @@
1
- export const CONNECTION_STATE = {}
1
+ module.exports.CONNECTION_STATE = {}
2
2
 
3
- CONNECTION_STATE.CLOSED = 'CLOSED'
4
- CONNECTION_STATE.AWAITING_CONNECTION = 'AWAITING_CONNECTION'
5
- CONNECTION_STATE.CHALLENGING = 'CHALLENGING'
6
- CONNECTION_STATE.AWAITING_AUTHENTICATION = 'AWAITING_AUTHENTICATION'
7
- CONNECTION_STATE.AUTHENTICATING = 'AUTHENTICATING'
8
- CONNECTION_STATE.OPEN = 'OPEN'
9
- CONNECTION_STATE.ERROR = 'ERROR'
10
- CONNECTION_STATE.RECONNECTING = 'RECONNECTING'
3
+ module.exports.CONNECTION_STATE.CLOSED = 'CLOSED'
4
+ module.exports.CONNECTION_STATE.AWAITING_CONNECTION = 'AWAITING_CONNECTION'
5
+ module.exports.CONNECTION_STATE.CHALLENGING = 'CHALLENGING'
6
+ module.exports.CONNECTION_STATE.AWAITING_AUTHENTICATION = 'AWAITING_AUTHENTICATION'
7
+ module.exports.CONNECTION_STATE.AUTHENTICATING = 'AUTHENTICATING'
8
+ module.exports.CONNECTION_STATE.OPEN = 'OPEN'
9
+ module.exports.CONNECTION_STATE.ERROR = 'ERROR'
10
+ module.exports.CONNECTION_STATE.RECONNECTING = 'RECONNECTING'
11
11
 
12
- export const RECORD_STATE = {}
13
- RECORD_STATE.VOID = 0
14
- RECORD_STATE.CLIENT = 1
15
- RECORD_STATE.SERVER = 2
16
- RECORD_STATE.STALE = 3
17
- RECORD_STATE.PROVIDER = 4
12
+ module.exports.RECORD_STATE = {}
13
+ module.exports.RECORD_STATE.VOID = 0
14
+ module.exports.RECORD_STATE.CLIENT = 1
15
+ module.exports.RECORD_STATE.SERVER = 2
16
+ module.exports.RECORD_STATE.STALE = 3
17
+ module.exports.RECORD_STATE.PROVIDER = 4
18
18
 
19
- export const RECORD_STATE_NAME = []
20
- for (const [key, val] of Object.entries(RECORD_STATE)) {
21
- RECORD_STATE_NAME[val] = key
19
+ module.exports.RECORD_STATE_NAME = []
20
+ for (const [key, val] of Object.entries(module.exports.RECORD_STATE)) {
21
+ module.exports.RECORD_STATE_NAME[val] = key
22
22
  }
23
23
 
24
- export const MESSAGE_SEPERATOR = String.fromCharCode(30) // ASCII Record Seperator 1E
25
- export const MESSAGE_PART_SEPERATOR = String.fromCharCode(31) // ASCII Unit Separator 1F
24
+ module.exports.MESSAGE_SEPERATOR = String.fromCharCode(30) // ASCII Record Seperator 1E
25
+ module.exports.MESSAGE_PART_SEPERATOR = String.fromCharCode(31) // ASCII Unit Separator 1F
26
26
 
27
- export const TYPES = {}
28
- TYPES.STRING = 'S'
29
- TYPES.OBJECT = 'O'
30
- TYPES.NUMBER = 'N'
31
- TYPES.NULL = 'L'
32
- TYPES.TRUE = 'T'
33
- TYPES.FALSE = 'F'
34
- TYPES.UNDEFINED = 'U'
27
+ module.exports.TYPES = {}
28
+ module.exports.TYPES.STRING = 'S'
29
+ module.exports.TYPES.OBJECT = 'O'
30
+ module.exports.TYPES.NUMBER = 'N'
31
+ module.exports.TYPES.NULL = 'L'
32
+ module.exports.TYPES.TRUE = 'T'
33
+ module.exports.TYPES.FALSE = 'F'
34
+ module.exports.TYPES.UNDEFINED = 'U'
35
35
 
36
- export const TOPIC = {}
37
- TOPIC.CONNECTION = 'C'
38
- TOPIC.AUTH = 'A'
39
- TOPIC.ERROR = 'X'
40
- TOPIC.EVENT = 'E'
41
- TOPIC.RECORD = 'R'
42
- TOPIC.RPC = 'P'
43
- TOPIC.PRIVATE = 'PRIVATE/'
36
+ module.exports.TOPIC = {}
37
+ module.exports.TOPIC.CONNECTION = 'C'
38
+ module.exports.TOPIC.AUTH = 'A'
39
+ module.exports.TOPIC.ERROR = 'X'
40
+ module.exports.TOPIC.EVENT = 'E'
41
+ module.exports.TOPIC.RECORD = 'R'
42
+ module.exports.TOPIC.RPC = 'P'
43
+ module.exports.TOPIC.PRIVATE = 'PRIVATE/'
44
44
 
45
- export const EVENT = {}
46
- EVENT.CONNECTION_ERROR = 'connectionError'
47
- EVENT.CONNECTION_STATE_CHANGED = 'connectionStateChanged'
48
- EVENT.CONNECTED = 'connected'
49
- EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED = 'MAX_RECONNECTION_ATTEMPTS_REACHED'
50
- EVENT.CONNECTION_AUTHENTICATION_TIMEOUT = 'CONNECTION_AUTHENTICATION_TIMEOUT'
51
- EVENT.NO_RPC_PROVIDER = 'NO_RPC_PROVIDER'
52
- EVENT.RPC_ERROR = 'RPC_ERROR'
53
- EVENT.TIMEOUT = 'TIMEOUT'
54
- EVENT.UNSOLICITED_MESSAGE = 'UNSOLICITED_MESSAGE'
55
- EVENT.MESSAGE_DENIED = 'MESSAGE_DENIED'
56
- EVENT.NOT_CONNECTED = 'NOT_CONNECTED'
57
- EVENT.MESSAGE_PARSE_ERROR = 'MESSAGE_PARSE_ERROR'
58
- EVENT.NOT_AUTHENTICATED = 'NOT_AUTHENTICATED'
59
- EVENT.MESSAGE_PERMISSION_ERROR = 'MESSAGE_PERMISSION_ERROR'
60
- EVENT.LISTENER_EXISTS = 'LISTENER_EXISTS'
61
- EVENT.PROVIDER_ERROR = 'PROVIDER_ERROR'
62
- EVENT.CACHE_ERROR = 'CACHE_ERROR'
63
- EVENT.UPDATE_ERROR = 'UPDATE_ERROR'
64
- EVENT.USER_ERROR = 'USER_ERROR'
65
- EVENT.REF_ERROR = 'REF_ERROR'
66
- EVENT.PROVIDER_EXISTS = 'PROVIDER_EXISTS'
67
- EVENT.NOT_LISTENING = 'NOT_LISTENING'
68
- EVENT.NOT_PROVIDING = 'NOT_PROVIDING'
69
- EVENT.LISTENER_ERROR = 'LISTENER_ERROR'
70
- EVENT.TOO_MANY_AUTH_ATTEMPTS = 'TOO_MANY_AUTH_ATTEMPTS'
71
- EVENT.IS_CLOSED = 'IS_CLOSED'
72
- EVENT.RECORD_NOT_FOUND = 'RECORD_NOT_FOUND'
73
- EVENT.NOT_SUBSCRIBED = 'NOT_SUBSCRIBED'
45
+ module.exports.EVENT = {}
46
+ module.exports.EVENT.CONNECTION_ERROR = 'connectionError'
47
+ module.exports.EVENT.CONNECTION_STATE_CHANGED = 'connectionStateChanged'
48
+ module.exports.EVENT.CONNECTED = 'connected'
49
+ module.exports.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED = 'MAX_RECONNECTION_ATTEMPTS_REACHED'
50
+ module.exports.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT = 'CONNECTION_AUTHENTICATION_TIMEOUT'
51
+ module.exports.EVENT.NO_RPC_PROVIDER = 'NO_RPC_PROVIDER'
52
+ module.exports.EVENT.RPC_ERROR = 'RPC_ERROR'
53
+ module.exports.EVENT.TIMEOUT = 'TIMEOUT'
54
+ module.exports.EVENT.UNSOLICITED_MESSAGE = 'UNSOLICITED_MESSAGE'
55
+ module.exports.EVENT.MESSAGE_DENIED = 'MESSAGE_DENIED'
56
+ module.exports.EVENT.NOT_CONNECTED = 'NOT_CONNECTED'
57
+ module.exports.EVENT.MESSAGE_PARSE_ERROR = 'MESSAGE_PARSE_ERROR'
58
+ module.exports.EVENT.NOT_AUTHENTICATED = 'NOT_AUTHENTICATED'
59
+ module.exports.EVENT.MESSAGE_PERMISSION_ERROR = 'MESSAGE_PERMISSION_ERROR'
60
+ module.exports.EVENT.LISTENER_EXISTS = 'LISTENER_EXISTS'
61
+ module.exports.EVENT.PROVIDER_ERROR = 'PROVIDER_ERROR'
62
+ module.exports.EVENT.CACHE_ERROR = 'CACHE_ERROR'
63
+ module.exports.EVENT.UPDATE_ERROR = 'UPDATE_ERROR'
64
+ module.exports.EVENT.USER_ERROR = 'USER_ERROR'
65
+ module.exports.EVENT.REF_ERROR = 'REF_ERROR'
66
+ module.exports.EVENT.PROVIDER_EXISTS = 'PROVIDER_EXISTS'
67
+ module.exports.EVENT.NOT_LISTENING = 'NOT_LISTENING'
68
+ module.exports.EVENT.NOT_PROVIDING = 'NOT_PROVIDING'
69
+ module.exports.EVENT.LISTENER_ERROR = 'LISTENER_ERROR'
70
+ module.exports.EVENT.TOO_MANY_AUTH_ATTEMPTS = 'TOO_MANY_AUTH_ATTEMPTS'
71
+ module.exports.EVENT.IS_CLOSED = 'IS_CLOSED'
72
+ module.exports.EVENT.RECORD_NOT_FOUND = 'RECORD_NOT_FOUND'
73
+ module.exports.EVENT.NOT_SUBSCRIBED = 'NOT_SUBSCRIBED'
74
74
 
75
- export const ACTIONS = {}
76
- ACTIONS.PING = 'PI'
77
- ACTIONS.PONG = 'PO'
78
- ACTIONS.ACK = 'A'
79
- ACTIONS.REDIRECT = 'RED'
80
- ACTIONS.CHALLENGE = 'CH'
81
- ACTIONS.CHALLENGE_RESPONSE = 'CHR'
82
- ACTIONS.READ = 'R'
83
- ACTIONS.UPDATE = 'U'
84
- ACTIONS.SUBSCRIBE = 'S'
85
- ACTIONS.SYNC = 'SY'
86
- ACTIONS.UNSUBSCRIBE = 'US'
87
- ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND = 'SP'
88
- ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED = 'SR'
89
- ACTIONS.SUBSCRIPTION_HAS_PROVIDER = 'SH'
90
- ACTIONS.LISTEN = 'L'
91
- ACTIONS.UNLISTEN = 'UL'
92
- ACTIONS.LISTEN_ACCEPT = 'LA'
93
- ACTIONS.LISTEN_REJECT = 'LR'
94
- ACTIONS.EVENT = 'EVT'
95
- ACTIONS.ERROR = 'E'
96
- ACTIONS.REQUEST = 'REQ'
97
- ACTIONS.RESPONSE = 'RES'
98
- ACTIONS.REJECTION = 'REJ'
75
+ module.exports.ACTIONS = {}
76
+ module.exports.ACTIONS.PING = 'PI'
77
+ module.exports.ACTIONS.PONG = 'PO'
78
+ module.exports.ACTIONS.ACK = 'A'
79
+ module.exports.ACTIONS.REDIRECT = 'RED'
80
+ module.exports.ACTIONS.CHALLENGE = 'CH'
81
+ module.exports.ACTIONS.CHALLENGE_RESPONSE = 'CHR'
82
+ module.exports.ACTIONS.READ = 'R'
83
+ module.exports.ACTIONS.UPDATE = 'U'
84
+ module.exports.ACTIONS.SUBSCRIBE = 'S'
85
+ module.exports.ACTIONS.SYNC = 'SY'
86
+ module.exports.ACTIONS.UNSUBSCRIBE = 'US'
87
+ module.exports.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND = 'SP'
88
+ module.exports.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED = 'SR'
89
+ module.exports.ACTIONS.SUBSCRIPTION_HAS_PROVIDER = 'SH'
90
+ module.exports.ACTIONS.LISTEN = 'L'
91
+ module.exports.ACTIONS.UNLISTEN = 'UL'
92
+ module.exports.ACTIONS.LISTEN_ACCEPT = 'LA'
93
+ module.exports.ACTIONS.LISTEN_REJECT = 'LR'
94
+ module.exports.ACTIONS.EVENT = 'EVT'
95
+ module.exports.ACTIONS.ERROR = 'E'
96
+ module.exports.ACTIONS.REQUEST = 'REQ'
97
+ module.exports.ACTIONS.RESPONSE = 'RES'
98
+ module.exports.ACTIONS.REJECTION = 'REJ'
@@ -1,4 +1,4 @@
1
- export default {
1
+ module.exports = {
2
2
  reconnectIntervalIncrement: 1e3,
3
3
  maxReconnectInterval: 6e3,
4
4
  maxReconnectAttempts: Infinity,
@@ -1,10 +1,10 @@
1
- import * as C from '../constants/constants.js'
2
- import * as messageBuilder from '../message/message-builder.js'
3
- import * as messageParser from '../message/message-parser.js'
4
- import MulticastListener from '../utils/multicast-listener.js'
5
- import UnicastListener from '../utils/unicast-listener.js'
6
- import EventEmitter from 'component-emitter2'
7
- import * as rxjs from 'rxjs'
1
+ const messageBuilder = require('../message/message-builder')
2
+ const messageParser = require('../message/message-parser')
3
+ const C = require('../constants/constants')
4
+ const MulticastListener = require('../utils/multicast-listener')
5
+ const UnicastListener = require('../utils/unicast-listener')
6
+ const EventEmitter = require('component-emitter2')
7
+ const rxjs = require('rxjs')
8
8
 
9
9
  const EventHandler = function (options, connection, client) {
10
10
  this._options = options
@@ -164,4 +164,4 @@ EventHandler.prototype._onConnectionStateChange = function (connected) {
164
164
  }
165
165
  }
166
166
 
167
- export default EventHandler
167
+ module.exports = EventHandler
@@ -1,14 +1,15 @@
1
- import * as utils from '../utils/utils.js'
2
- import * as messageParser from './message-parser.js'
3
- import * as messageBuilder from './message-builder.js'
4
- import * as C from '../constants/constants.js'
5
- import FixedQueue from '../utils/fixed-queue.js'
6
- import Emitter from 'component-emitter2'
7
-
8
- const NodeWebSocket = utils.isNode ? await import('ws').then((x) => x.default) : null
9
1
  const BrowserWebSocket = globalThis.WebSocket || globalThis.MozWebSocket
10
-
11
- export default function Connection(client, url, options) {
2
+ const utils = require('../utils/utils')
3
+ const NodeWebSocket = utils.isNode ? require('ws') : null
4
+ const messageParser = require('./message-parser')
5
+ const messageBuilder = require('./message-builder')
6
+ const C = require('../constants/constants')
7
+ const pkg = require('../../package.json')
8
+ const xxhash = require('xxhash-wasm')
9
+ const FixedQueue = require('../utils/fixed-queue')
10
+ const Emitter = require('component-emitter2')
11
+
12
+ const Connection = function (client, url, options) {
12
13
  this._client = client
13
14
  this._options = options
14
15
  this._logger = options.logger
@@ -26,7 +27,6 @@ export default function Connection(client, url, options) {
26
27
  action: null,
27
28
  data: null,
28
29
  }
29
- this._decoder = new globalThis.TextDecoder()
30
30
  this._recvQueue = new FixedQueue()
31
31
  this._reconnectTimeout = null
32
32
  this._reconnectionAttempt = 0
@@ -39,7 +39,11 @@ export default function Connection(client, url, options) {
39
39
 
40
40
  this._state = C.CONNECTION_STATE.CLOSED
41
41
 
42
- this._createEndpoint()
42
+ this.hasher = null
43
+ xxhash().then((hasher) => {
44
+ this.hasher = hasher
45
+ this._createEndpoint()
46
+ })
43
47
  }
44
48
 
45
49
  Emitter(Connection.prototype)
@@ -78,6 +82,14 @@ Connection.prototype.sendMsg = function (topic, action, data) {
78
82
  return this.send(messageBuilder.getMsg(topic, action, data))
79
83
  }
80
84
 
85
+ Connection.prototype.sendMsg1 = function (topic, action, p0) {
86
+ return this.send(messageBuilder.getMsg1(topic, action, p0))
87
+ }
88
+
89
+ Connection.prototype.sendMsg2 = function (topic, action, p0, p1) {
90
+ return this.send(messageBuilder.getMsg2(topic, action, p0, p1))
91
+ }
92
+
81
93
  Connection.prototype.close = function () {
82
94
  this._deliberateClose = true
83
95
  this._endpoint?.close()
@@ -89,23 +101,19 @@ Connection.prototype.close = function () {
89
101
  }
90
102
 
91
103
  Connection.prototype._createEndpoint = function () {
92
- if (utils.isNode) {
93
- this._endpoint = new NodeWebSocket(this._url, {
94
- generateMask() {},
95
- })
96
- this._endpoint.binaryType = 'nodebuffer'
97
- } else {
98
- this._endpoint = new BrowserWebSocket(this._url)
99
- this._endpoint.binaryType = 'arraybuffer'
100
- }
101
-
104
+ this._endpoint = NodeWebSocket
105
+ ? new NodeWebSocket(this._url, {
106
+ generateMask() {},
107
+ })
108
+ : new BrowserWebSocket(this._url)
102
109
  this._corked = false
103
110
 
104
111
  this._endpoint.onopen = this._onOpen.bind(this)
105
112
  this._endpoint.onerror = this._onError.bind(this)
106
113
  this._endpoint.onclose = this._onClose.bind(this)
107
- this._endpoint.onmessage = ({ data }) =>
108
- this._onMessage(typeof data === 'string' ? data : this._decoder.decode(data))
114
+ this._endpoint.onmessage = BrowserWebSocket
115
+ ? ({ data }) => this._onMessage(typeof data === 'string' ? data : Buffer.from(data).toString())
116
+ : ({ data }) => this._onMessage(typeof data === 'string' ? data : data.toString())
109
117
  }
110
118
 
111
119
  Connection.prototype.send = function (message) {
@@ -166,7 +174,7 @@ Connection.prototype._sendAuthParams = function () {
166
174
  this._setState(C.CONNECTION_STATE.AUTHENTICATING)
167
175
  const authMessage = messageBuilder.getMsg(C.TOPIC.AUTH, C.ACTIONS.REQUEST, [
168
176
  this._authParams,
169
- '24.4.4',
177
+ pkg.version,
170
178
  utils.isNode
171
179
  ? `Node/${process.version}`
172
180
  : globalThis.navigator && globalThis.navigator.userAgent,
@@ -365,3 +373,5 @@ Connection.prototype._clearReconnect = function () {
365
373
  }
366
374
  this._reconnectionAttempt = 0
367
375
  }
376
+
377
+ module.exports = Connection
@@ -1,8 +1,8 @@
1
- import * as C from '../constants/constants.js'
1
+ const C = require('../constants/constants')
2
2
 
3
3
  const SEP = C.MESSAGE_PART_SEPERATOR
4
4
 
5
- export function getMsg(topic, action, data) {
5
+ module.exports.getMsg = function (topic, action, data) {
6
6
  if (data && !(data instanceof Array)) {
7
7
  throw new Error('data must be an array')
8
8
  }
@@ -22,7 +22,15 @@ export function getMsg(topic, action, data) {
22
22
  return sendData.join(SEP)
23
23
  }
24
24
 
25
- export function typed(value) {
25
+ module.exports.getMsg1 = function (topic, action, p0) {
26
+ return `${topic}${SEP}${action}${SEP}${p0}`
27
+ }
28
+
29
+ module.exports.getMsg2 = function (topic, action, p0, p1) {
30
+ return `${topic}${SEP}${action}${SEP}${p0}${SEP}${p1}`
31
+ }
32
+
33
+ module.exports.typed = function (value) {
26
34
  const type = typeof value
27
35
 
28
36
  if (type === 'string') {
@@ -1,12 +1,10 @@
1
- import * as C from '../constants/constants.js'
1
+ const C = require('../constants/constants')
2
2
 
3
- const actions = {}
4
-
5
- for (const key in C.ACTIONS) {
6
- actions[C.ACTIONS[key]] = key
3
+ const MessageParser = function () {
4
+ this._actions = this._getActions()
7
5
  }
8
6
 
9
- export function convertTyped(value, client) {
7
+ MessageParser.prototype.convertTyped = function (value, client) {
10
8
  const type = value.charAt(0)
11
9
 
12
10
  if (type === C.TYPES.STRING) {
@@ -47,7 +45,17 @@ export function convertTyped(value, client) {
47
45
  return undefined
48
46
  }
49
47
 
50
- export function parseMessage(message, client, result) {
48
+ MessageParser.prototype._getActions = function () {
49
+ const actions = {}
50
+
51
+ for (const key in C.ACTIONS) {
52
+ actions[C.ACTIONS[key]] = key
53
+ }
54
+
55
+ return actions
56
+ }
57
+
58
+ MessageParser.prototype.parseMessage = function (message, client, result) {
51
59
  const parts = message.split(C.MESSAGE_PART_SEPERATOR)
52
60
 
53
61
  if (parts.length < 2) {
@@ -64,7 +72,7 @@ export function parseMessage(message, client, result) {
64
72
  return null
65
73
  }
66
74
 
67
- if (actions[parts[1]] === undefined) {
75
+ if (this._actions[parts[1]] === undefined) {
68
76
  client._$onError(
69
77
  C.TOPIC.ERROR,
70
78
  C.EVENT.MESSAGE_PARSE_ERROR,
@@ -79,3 +87,5 @@ export function parseMessage(message, client, result) {
79
87
  result.action = parts[1]
80
88
  result.data = parts.splice(2)
81
89
  }
90
+
91
+ module.exports = new MessageParser()
@@ -1,14 +1,15 @@
1
- import Record from './record.js'
2
- import MulticastListener from '../utils/multicast-listener.js'
3
- import UnicastListener from '../utils/unicast-listener.js'
4
- import * as C from '../constants/constants.js'
5
- import * as rxjs from 'rxjs'
6
- import invariant from 'invariant'
7
- import EventEmitter from 'component-emitter2'
8
- import jsonPath from '@nxtedition/json-path'
9
- import * as utils from '../utils/utils.js'
10
- import xuid from 'xuid'
11
- import * as timers from '../utils/timers.js'
1
+ const Record = require('./record')
2
+ const MulticastListener = require('../utils/multicast-listener')
3
+ const UnicastListener = require('../utils/unicast-listener')
4
+ const C = require('../constants/constants')
5
+ const rxjs = require('rxjs')
6
+ const invariant = require('invariant')
7
+ const EventEmitter = require('component-emitter2')
8
+ const jsonPath = require('@nxtedition/json-path')
9
+ const utils = require('../utils/utils')
10
+ const rx = require('rxjs/operators')
11
+ const xuid = require('xuid')
12
+ const timers = require('../utils/timers')
12
13
 
13
14
  const kEmpty = Symbol('kEmpty')
14
15
 
@@ -385,7 +386,7 @@ class RecordHandler {
385
386
  queue[n](queue[n + 1])
386
387
  }
387
388
  })
388
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token, 'WEAK'])
389
+ this._connection.sendMsg2(C.TOPIC.RECORD, C.ACTIONS.SYNC, token, 'WEAK')
389
390
  }, 1)
390
391
  }
391
392
 
@@ -471,7 +472,7 @@ class RecordHandler {
471
472
  // TODO (fix): Missing sync..
472
473
  return new Promise((resolve, reject) => {
473
474
  this.observe(...args)
474
- .pipe(rxjs.first())
475
+ .pipe(rx.first())
475
476
  .subscribe({
476
477
  next: resolve,
477
478
  error: reject,
@@ -487,7 +488,7 @@ class RecordHandler {
487
488
  get2(...args) {
488
489
  return new Promise((resolve, reject) => {
489
490
  this.observe2(...args)
490
- .pipe(rxjs.first())
491
+ .pipe(rx.first())
491
492
  .subscribe({
492
493
  next: resolve,
493
494
  error: reject,
@@ -662,4 +663,4 @@ class RecordHandler {
662
663
  }
663
664
  }
664
665
 
665
- export default RecordHandler
666
+ module.exports = RecordHandler
@@ -1,11 +1,11 @@
1
- import jsonPath from '@nxtedition/json-path'
2
- import * as utils from '../utils/utils.js'
3
- import * as C from '../constants/constants.js'
4
- import * as messageParser from '../message/message-parser.js'
5
- import xuid from 'xuid'
6
- import invariant from 'invariant'
7
- import cloneDeep from 'lodash.clonedeep'
8
- import * as timers from '../utils/timers.js'
1
+ const jsonPath = require('@nxtedition/json-path')
2
+ const utils = require('../utils/utils')
3
+ const C = require('../constants/constants')
4
+ const messageParser = require('../message/message-parser')
5
+ const xuid = require('xuid')
6
+ const invariant = require('invariant')
7
+ const cloneDeep = require('lodash.clonedeep')
8
+ const timers = require('../utils/timers')
9
9
 
10
10
  class Record {
11
11
  static STATE = C.RECORD_STATE
@@ -14,6 +14,7 @@ class Record {
14
14
  const connection = handler._connection
15
15
 
16
16
  this._handler = handler
17
+
17
18
  this._name = name
18
19
  this._version = ''
19
20
  this._data = jsonPath.EMPTY
@@ -21,10 +22,9 @@ class Record {
21
22
  this._refs = 0
22
23
  this._subscriptions = []
23
24
  this._emitting = false
24
-
25
25
  /** @type Map? */ this._updating = null
26
26
  /** @type Array? */ this._patching = null
27
- this._subscribed = connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
27
+ this._subscribed = connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
28
28
  }
29
29
 
30
30
  /** @type {string} */
@@ -62,7 +62,7 @@ class Record {
62
62
  if (this._refs === 1) {
63
63
  this._handler._onPruning(this, false)
64
64
  this._subscribed =
65
- this._subscribed || connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
65
+ this._subscribed || connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
66
66
  }
67
67
  return this
68
68
  }
@@ -324,7 +324,7 @@ class Record {
324
324
 
325
325
  if (connected) {
326
326
  this._subscribed =
327
- this._refs > 0 && connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, [this._name])
327
+ this._refs > 0 && connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
328
328
 
329
329
  if (this._updating) {
330
330
  for (const update of this._updating.values()) {
@@ -349,7 +349,7 @@ class Record {
349
349
  invariant(!this._updating, 'must not have updates')
350
350
 
351
351
  if (this._subscribed) {
352
- connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [this._name])
352
+ connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, this._name)
353
353
  this._subscribed = false
354
354
  }
355
355
 
@@ -572,4 +572,4 @@ Object.defineProperty(Record.prototype, 'hasProvider', {
572
572
  },
573
573
  })
574
574
 
575
- export default Record
575
+ module.exports = Record
@@ -1,8 +1,8 @@
1
- import * as C from '../constants/constants.js'
2
- import RpcResponse from './rpc-response.js'
3
- import * as messageParser from '../message/message-parser.js'
4
- import * as messageBuilder from '../message/message-builder.js'
5
- import xuid from 'xuid'
1
+ const C = require('../constants/constants')
2
+ const RpcResponse = require('./rpc-response')
3
+ const messageParser = require('../message/message-parser')
4
+ const messageBuilder = require('../message/message-builder')
5
+ const xuid = require('xuid')
6
6
 
7
7
  const RpcHandler = function (options, connection, client) {
8
8
  this._options = options
@@ -175,4 +175,4 @@ RpcHandler.prototype._onConnectionStateChange = function (connected) {
175
175
  }
176
176
  }
177
177
 
178
- export default RpcHandler
178
+ module.exports = RpcHandler
@@ -1,5 +1,5 @@
1
- import * as C from '../constants/constants.js'
2
- import * as messageBuilder from '../message/message-builder.js'
1
+ const C = require('../constants/constants')
2
+ const messageBuilder = require('../message/message-builder')
3
3
 
4
4
  const RpcResponse = function (connection, name, id) {
5
5
  this._connection = connection
@@ -44,4 +44,4 @@ RpcResponse.prototype.send = function (data) {
44
44
  ])
45
45
  }
46
46
 
47
- export default RpcResponse
47
+ module.exports = RpcResponse
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  // Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
2
4
  const kSize = 2048
3
5
  const kMask = kSize - 1
@@ -80,7 +82,7 @@ class FixedCircularBuffer {
80
82
  }
81
83
  }
82
84
 
83
- export default class FixedQueue {
85
+ module.exports = class FixedQueue {
84
86
  constructor() {
85
87
  this.head = this.tail = new FixedCircularBuffer()
86
88
  }
@@ -1,8 +1,7 @@
1
- import * as rxjs from 'rxjs'
2
- import * as C from '../constants/constants.js'
3
- import { h64ToString } from '../utils/utils.js'
1
+ const C = require('../constants/constants')
2
+ const rxjs = require('rxjs')
4
3
 
5
- export default class Listener {
4
+ class Listener {
6
5
  constructor(topic, pattern, callback, handler, { recursive = false, stringify = null } = {}) {
7
6
  this._topic = topic
8
7
  this._pattern = pattern
@@ -152,7 +151,7 @@ export default class Listener {
152
151
  }
153
152
 
154
153
  const body = typeof value !== 'string' ? this._stringify(value) : value
155
- const hash = h64ToString(body)
154
+ const hash = this._connection.hasher.h64ToString(body)
156
155
  const version = `INF-${hash}`
157
156
 
158
157
  if (provider.version !== version) {
@@ -229,3 +228,5 @@ export default class Listener {
229
228
  this._subscriptions.clear()
230
229
  }
231
230
  }
231
+
232
+ module.exports = Listener
@@ -1,11 +1,14 @@
1
- const fastNowInterval = 1e3
2
- let fastNow = 0
1
+ // undici timers
2
+
3
+ 'use strict'
4
+
5
+ let fastNow = Date.now()
3
6
  let fastNowTimeout
4
7
 
5
8
  const fastTimers = []
6
9
 
7
10
  function onTimeout() {
8
- fastNow += fastNowInterval
11
+ fastNow = Date.now()
9
12
 
10
13
  let len = fastTimers.length
11
14
  let idx = 0
@@ -41,8 +44,8 @@ function refreshTimeout() {
41
44
  if (fastNowTimeout && fastNowTimeout.refresh) {
42
45
  fastNowTimeout.refresh()
43
46
  } else {
44
- globalThis.clearTimeout(fastNowTimeout)
45
- fastNowTimeout = globalThis.setTimeout(onTimeout, fastNowInterval)
47
+ clearTimeout(fastNowTimeout)
48
+ fastNowTimeout = setTimeout(onTimeout, 1e3)
46
49
  if (fastNowTimeout.unref) {
47
50
  fastNowTimeout.unref()
48
51
  }
@@ -80,16 +83,15 @@ class Timeout {
80
83
  }
81
84
  }
82
85
 
83
- export function setTimeout(callback, delay, opaque) {
84
- return delay < fastNowInterval
85
- ? globalThis.setTimeout(callback, delay, opaque)
86
- : new Timeout(callback, delay, opaque)
87
- }
88
-
89
- export function clearTimeout(timeout) {
90
- if (timeout instanceof Timeout) {
91
- timeout.clear()
92
- } else {
93
- globalThis.clearTimeout(timeout)
94
- }
86
+ module.exports = {
87
+ setTimeout(callback, delay, opaque) {
88
+ return delay < 1e3 ? setTimeout(callback, delay, opaque) : new Timeout(callback, delay, opaque)
89
+ },
90
+ clearTimeout(timeout) {
91
+ if (timeout instanceof Timeout) {
92
+ timeout.clear()
93
+ } else {
94
+ clearTimeout(timeout)
95
+ }
96
+ },
95
97
  }
@@ -1,9 +1,9 @@
1
- import * as rxjs from 'rxjs'
2
- import * as C from '../constants/constants.js'
3
- import { h64ToString } from '../utils/utils.js'
1
+ const C = require('../constants/constants')
2
+ const rx = require('rxjs/operators')
3
+ const rxjs = require('rxjs')
4
4
 
5
5
  const PIPE = rxjs.pipe(
6
- rxjs.map((value) => {
6
+ rx.map((value) => {
7
7
  let data
8
8
  if (value && typeof value === 'string') {
9
9
  if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
@@ -18,10 +18,10 @@ const PIPE = rxjs.pipe(
18
18
 
19
19
  return data
20
20
  }),
21
- rxjs.distinctUntilChanged(),
21
+ rx.distinctUntilChanged(),
22
22
  )
23
23
 
24
- export default class Listener {
24
+ class Listener {
25
25
  constructor(topic, pattern, callback, handler, opts) {
26
26
  if (opts.recursive) {
27
27
  throw new Error('invalid argument: recursive')
@@ -76,7 +76,7 @@ export default class Listener {
76
76
  this._subscriptions.delete(name)
77
77
  subscription.unsubscribe()
78
78
  } else {
79
- const version = `INF-${h64ToString(data)}`
79
+ const version = `INF-${this._connection.hasher.h64ToString(data)}`
80
80
  this._connection.sendMsg(this._topic, C.ACTIONS.UPDATE, [name, version, data])
81
81
  }
82
82
  },
@@ -126,3 +126,5 @@ export default class Listener {
126
126
  this._connection.sendMsg(this._topic, C.ACTIONS.UNLISTEN, [this._pattern])
127
127
  }
128
128
  }
129
+
130
+ module.exports = Listener
@@ -1,10 +1,11 @@
1
- import xxhash from 'xxhash-wasm'
2
-
3
1
  const NODE_ENV = typeof process !== 'undefined' && process.env && process.env.NODE_ENV
4
- export const isNode = typeof process !== 'undefined' && process.toString() === '[object process]'
5
- export const isProduction = NODE_ENV === 'production'
2
+ const isNode = typeof process !== 'undefined' && process.toString() === '[object process]'
3
+ const isProduction = NODE_ENV === 'production'
4
+
5
+ module.exports.isNode = isNode
6
+ module.exports.isProduction = isProduction
6
7
 
7
- export function deepFreeze(o) {
8
+ module.exports.deepFreeze = function (o) {
8
9
  if (isProduction) {
9
10
  return o
10
11
  }
@@ -15,12 +16,12 @@ export function deepFreeze(o) {
15
16
 
16
17
  Object.freeze(o)
17
18
 
18
- Object.getOwnPropertyNames(o).forEach((prop) => deepFreeze(o[prop]))
19
+ Object.getOwnPropertyNames(o).forEach((prop) => module.exports.deepFreeze(o[prop]))
19
20
 
20
21
  return o
21
22
  }
22
23
 
23
- export function splitRev(s) {
24
+ module.exports.splitRev = function (s) {
24
25
  if (!s) {
25
26
  return [-1, '00000000000000']
26
27
  }
@@ -31,7 +32,7 @@ export function splitRev(s) {
31
32
  return [ver.charAt(0) === 'I' ? Infinity : parseInt(ver, 10), s.slice(i + 1)]
32
33
  }
33
34
 
34
- export function isPlainObject(value, isPlainJSON) {
35
+ module.exports.isPlainObject = function (value, isPlainJSON) {
35
36
  if (isPlainJSON) {
36
37
  return value && typeof value === 'object' && !Array.isArray(value)
37
38
  }
@@ -52,13 +53,13 @@ export function isPlainObject(value, isPlainJSON) {
52
53
  return Object.getPrototypeOf(value) === proto
53
54
  }
54
55
 
55
- export function isSameOrNewer(a, b) {
56
- const [av, ar] = splitRev(a)
57
- const [bv, br] = splitRev(b)
56
+ module.exports.isSameOrNewer = function (a, b) {
57
+ const [av, ar] = module.exports.splitRev(a)
58
+ const [bv, br] = module.exports.splitRev(b)
58
59
  return av > bv || (av === bv && ar >= br)
59
60
  }
60
61
 
61
- export function shallowCopy(obj) {
62
+ module.exports.shallowCopy = function (obj) {
62
63
  if (Array.isArray(obj)) {
63
64
  return obj.slice(0)
64
65
  }
@@ -71,15 +72,15 @@ export function shallowCopy(obj) {
71
72
  return copy
72
73
  }
73
74
 
74
- export function setTimeout(callback, timeoutDuration) {
75
+ module.exports.setTimeout = function (callback, timeoutDuration) {
75
76
  if (timeoutDuration !== null) {
76
- return globalThis.setTimeout(callback, timeoutDuration)
77
+ return setTimeout(callback, timeoutDuration)
77
78
  } else {
78
79
  return -1
79
80
  }
80
81
  }
81
82
 
82
- export function setInterval(callback, intervalDuration) {
83
+ module.exports.setInterval = function (callback, intervalDuration) {
83
84
  if (intervalDuration !== null) {
84
85
  return setInterval(callback, intervalDuration)
85
86
  } else {
@@ -87,7 +88,7 @@ export function setInterval(callback, intervalDuration) {
87
88
  }
88
89
  }
89
90
 
90
- export function compareRev(a, b) {
91
+ module.exports.compareRev = function compareRev(a, b) {
91
92
  if (!a) {
92
93
  return b ? -1 : 0
93
94
  }
@@ -117,7 +118,7 @@ export function compareRev(a, b) {
117
118
  return 0
118
119
  }
119
120
 
120
- export class AbortError extends Error {
121
+ module.exports.AbortError = class AbortError extends Error {
121
122
  constructor() {
122
123
  super('The operation was aborted')
123
124
  this.code = 'ABORT_ERR'
@@ -129,7 +130,7 @@ function defaultSchedule(fn) {
129
130
  setTimeout(fn, 0)
130
131
  }
131
132
 
132
- export const schedule = isNode ? defaultSchedule : window.requestIdleCallback
133
+ module.exports.schedule = isNode ? defaultSchedule : window.requestIdleCallback
133
134
 
134
135
  const abortSignals = new WeakMap()
135
136
  const onAbort = function () {
@@ -141,7 +142,7 @@ const onAbort = function () {
141
142
  }
142
143
  }
143
144
 
144
- export function addAbortListener(signal, handler) {
145
+ module.exports.addAbortListener = function addAbortListener(signal, handler) {
145
146
  if (!signal) {
146
147
  return
147
148
  }
@@ -159,7 +160,7 @@ export function addAbortListener(signal, handler) {
159
160
  }
160
161
  }
161
162
 
162
- export function removeAbortListener(signal, handler) {
163
+ module.exports.removeAbortListener = function removeAbortListener(signal, handler) {
163
164
  if (!signal) {
164
165
  return
165
166
  }
@@ -176,9 +177,3 @@ export function removeAbortListener(signal, handler) {
176
177
  }
177
178
  }
178
179
  }
179
-
180
- const HASHER = await xxhash()
181
-
182
- export function h64ToString(str) {
183
- return HASHER.h64ToString(str)
184
- }