@nxtedition/deepstream.io-client-js 30.0.1 → 31.0.1
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 +13 -10
- package/src/client.d.ts +104 -0
- package/src/constants/constants.js +1 -0
- package/src/event/event-handler.d.ts +20 -0
- package/src/message/connection.js +1 -1
- package/src/record/record-handler.d.ts +158 -0
- package/src/record/record-handler.js +316 -260
- package/src/record/record.d.ts +110 -0
- package/src/record/record.js +12 -19
- package/src/rpc/rpc-handler.d.ts +42 -0
- package/src/rpc/rpc-response.d.ts +5 -0
- package/src/utils/multicast-listener.js +164 -181
- package/src/utils/timers.js +4 -0
- package/src/utils/unicast-listener.js +35 -52
- package/src/utils/utils.js +20 -1
|
@@ -1,60 +1,30 @@
|
|
|
1
|
+
import * as rxjs from 'rxjs'
|
|
1
2
|
import * as C from '../constants/constants.js'
|
|
2
|
-
import { h64ToString } from '../utils/utils.js'
|
|
3
|
-
|
|
4
|
-
class Observer {
|
|
5
|
-
#name
|
|
6
|
-
#key
|
|
7
|
-
#listener
|
|
8
|
-
#version = ''
|
|
9
|
-
|
|
10
|
-
constructor(name, listener) {
|
|
11
|
-
this.#name = name
|
|
12
|
-
this.#key = h64ToString(name)
|
|
13
|
-
this.#listener = listener
|
|
14
|
-
}
|
|
3
|
+
import { h64ToString, findBigIntPaths } from '../utils/utils.js'
|
|
15
4
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
5
|
+
const PIPE = rxjs.pipe(
|
|
6
|
+
rxjs.map((value) => {
|
|
7
|
+
if (typeof value === 'string') {
|
|
19
8
|
if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
|
|
20
9
|
throw new Error(`invalid value: ${value}`)
|
|
21
10
|
}
|
|
22
|
-
|
|
23
|
-
} else if (value && typeof value === 'object') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (version) {
|
|
35
|
-
this.#listener._connection.sendMsg(this.#listener._topic, C.ACTIONS.UPDATE, [
|
|
36
|
-
this.#key,
|
|
37
|
-
version,
|
|
38
|
-
data,
|
|
39
|
-
])
|
|
11
|
+
return value
|
|
12
|
+
} else if (value != null && typeof value === 'object') {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(value)
|
|
15
|
+
} catch (err) {
|
|
16
|
+
const bigIntPaths = /BigInt/.test(err.message) ? findBigIntPaths(value) : undefined
|
|
17
|
+
throw Object.assign(new Error(`invalid value: ${value}`), {
|
|
18
|
+
cause: err,
|
|
19
|
+
data: { bigIntPaths },
|
|
20
|
+
})
|
|
21
|
+
}
|
|
40
22
|
} else {
|
|
41
|
-
|
|
42
|
-
this.#listener._pattern,
|
|
43
|
-
this.#key,
|
|
44
|
-
])
|
|
23
|
+
throw new Error(`invalid value: ${value}`)
|
|
45
24
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
error(err) {
|
|
51
|
-
this.#listener._error(this.#name, err)
|
|
52
|
-
this.#listener._connection.sendMsg(this.#listener._topic, C.ACTIONS.LISTEN_REJECT, [
|
|
53
|
-
this.#listener._pattern,
|
|
54
|
-
this.#key,
|
|
55
|
-
])
|
|
56
|
-
}
|
|
57
|
-
}
|
|
25
|
+
}),
|
|
26
|
+
rxjs.distinctUntilChanged(),
|
|
27
|
+
)
|
|
58
28
|
|
|
59
29
|
export default class Listener {
|
|
60
30
|
constructor(topic, pattern, callback, handler, opts) {
|
|
@@ -100,11 +70,24 @@ export default class Listener {
|
|
|
100
70
|
try {
|
|
101
71
|
value$ = this._callback(name)
|
|
102
72
|
} catch (err) {
|
|
103
|
-
|
|
73
|
+
value$ = rxjs.throwError(() => err)
|
|
104
74
|
}
|
|
105
75
|
|
|
106
76
|
if (value$) {
|
|
107
|
-
|
|
77
|
+
const subscription = value$.pipe(PIPE).subscribe({
|
|
78
|
+
next: (data) => {
|
|
79
|
+
const version = `INF-${h64ToString(data)}`
|
|
80
|
+
this._connection.sendMsg(this._topic, C.ACTIONS.UPDATE, [name, version, data])
|
|
81
|
+
},
|
|
82
|
+
error: (err) => {
|
|
83
|
+
this._error(name, err)
|
|
84
|
+
|
|
85
|
+
this._subscriptions.delete(name)
|
|
86
|
+
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
this._subscriptions.set(name, subscription)
|
|
108
91
|
} else {
|
|
109
92
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
|
|
110
93
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -177,8 +177,27 @@ export function removeAbortListener(signal, handler) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
// This is a hack to avoid top-level await
|
|
181
|
+
// const HASHER = await xxhash()
|
|
182
|
+
let HASHER
|
|
183
|
+
xxhash().then((hasher) => (HASHER = hasher))
|
|
181
184
|
|
|
182
185
|
export function h64ToString(str) {
|
|
183
186
|
return HASHER.h64ToString(str)
|
|
184
187
|
}
|
|
188
|
+
|
|
189
|
+
export function findBigIntPaths(obj, path = "") {
|
|
190
|
+
const paths = []
|
|
191
|
+
|
|
192
|
+
if (typeof obj === "bigint") {
|
|
193
|
+
return [path]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (typeof obj === "object" && obj !== null) {
|
|
197
|
+
for (const key of Object.keys(obj)) {
|
|
198
|
+
paths.push(...findBigIntPaths(obj[key], path ? `${path}.${key}` : key))
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return paths
|
|
203
|
+
}
|