@nxtedition/deepstream.io-client-js 28.1.7 → 28.1.9
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
|
@@ -199,7 +199,7 @@ Connection.prototype._onError = function (err) {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
if (err.code === 'ECONNRESET' || err.code === 'ECONNREFUSED') {
|
|
202
|
-
err.message = "Can't
|
|
202
|
+
err.message = "Can't connect! Deepstream server unreachable on " + this._url
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
this._client._$onError(C.TOPIC.CONNECTION, C.EVENT.CONNECTION_ERROR, err)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as rxjs from 'rxjs'
|
|
2
2
|
import * as C from '../constants/constants.js'
|
|
3
|
-
import { h64ToString } from '../utils/utils.js'
|
|
3
|
+
import { h64ToString, findBigIntPaths } from '../utils/utils.js'
|
|
4
4
|
|
|
5
5
|
export default class Listener {
|
|
6
6
|
constructor(topic, pattern, callback, handler, { recursive = false, stringify = null } = {}) {
|
|
@@ -151,7 +151,22 @@ export default class Listener {
|
|
|
151
151
|
return
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
if (typeof value !== 'string') {
|
|
155
|
+
try {
|
|
156
|
+
value = this._stringify(value)
|
|
157
|
+
} catch (err) {
|
|
158
|
+
const bigIntPaths = /BigInt/.test(err.message) ? findBigIntPaths(value) : undefined
|
|
159
|
+
this._error(
|
|
160
|
+
Object.assign(new Error(`invalid value: ${value}`), {
|
|
161
|
+
cause: err,
|
|
162
|
+
data: { name: provider.name, bigIntPaths },
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const body = value
|
|
155
170
|
const hash = h64ToString(body)
|
|
156
171
|
const version = `INF-${hash}`
|
|
157
172
|
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import * as rxjs from 'rxjs'
|
|
2
2
|
import * as C from '../constants/constants.js'
|
|
3
|
-
import { h64ToString } from '../utils/utils.js'
|
|
3
|
+
import { h64ToString, findBigIntPaths } from '../utils/utils.js'
|
|
4
4
|
|
|
5
5
|
const PIPE = rxjs.pipe(
|
|
6
6
|
rxjs.map((value) => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
if (value == null) {
|
|
8
|
+
return null
|
|
9
|
+
} else if (typeof value === 'string') {
|
|
9
10
|
if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
|
|
10
11
|
throw new Error(`invalid value: ${value}`)
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
} else if (
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
return value
|
|
14
|
+
} else if (typeof value === 'object') {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.stringify(value)
|
|
17
|
+
} catch (err) {
|
|
18
|
+
const bigIntPaths = /BigInt/.test(err.message) ? findBigIntPaths(value) : undefined
|
|
19
|
+
throw Object.assign(new Error(`invalid value: ${value}`), { cause: err, data: { bigIntPaths }})
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
16
22
|
throw new Error(`invalid value: ${value}`)
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
return data
|
|
20
24
|
}),
|
|
21
25
|
rxjs.takeWhile((data) => data != null),
|
|
22
26
|
rxjs.distinctUntilChanged(),
|
package/src/utils/utils.js
CHANGED
|
@@ -185,3 +185,19 @@ xxhash().then((hasher) => (HASHER = hasher))
|
|
|
185
185
|
export function h64ToString(str) {
|
|
186
186
|
return HASHER.h64ToString(str)
|
|
187
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
|
+
}
|
|
Binary file
|
package/src/test.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import make from './client.js'
|
|
2
|
-
import {
|
|
3
|
-
EmptyObject,
|
|
4
|
-
GettablePossibleEmpty,
|
|
5
|
-
PossiblyEmptyData,
|
|
6
|
-
SettablePossibleEmpty,
|
|
7
|
-
} from './record/record.js'
|
|
8
|
-
import { assertNonEmpty } from './record/record-handler.js'
|
|
9
|
-
|
|
10
|
-
interface Records {
|
|
11
|
-
test: {
|
|
12
|
-
name: string
|
|
13
|
-
age: number
|
|
14
|
-
}
|
|
15
|
-
foo: {
|
|
16
|
-
bar: number
|
|
17
|
-
}
|
|
18
|
-
tjena: {
|
|
19
|
-
optional?: string
|
|
20
|
-
}
|
|
21
|
-
num: number
|
|
22
|
-
str: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface Methods {
|
|
26
|
-
test: [{ name: string }, { age: number }]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const ds = make<Records, Methods>('http://localhost:3000')
|
|
30
|
-
|
|
31
|
-
const y = await ds.record.get('test')
|
|
32
|
-
if ('age' in y) {
|
|
33
|
-
console.log(y.name)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const q: PossiblyEmptyData<{ test: number }> = {}
|
|
37
|
-
console.log(q.test)
|
|
38
|
-
if ('test' in q) {
|
|
39
|
-
console.log(q.test)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const w: PossiblyEmptyData<{ test: number; haj: number }> = { test: 22, haj: 22 }
|
|
43
|
-
|
|
44
|
-
function test<D>(cb: (data: GettablePossibleEmpty<D>) => SettablePossibleEmpty<D>) {
|
|
45
|
-
// cb({})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
test<{ foo: number; bar: number }>((data) => {
|
|
49
|
-
return data
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test<{ foo?: number; bar: number }>(() => {
|
|
53
|
-
return {
|
|
54
|
-
foo: 22,
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test<{ foo?: number; bar: number }>((data) => {
|
|
59
|
-
// return data
|
|
60
|
-
const a= {
|
|
61
|
-
...data,
|
|
62
|
-
foo: 22,
|
|
63
|
-
}
|
|
64
|
-
return a
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test<{ foo?: number; bar?: number }>((data) => {
|
|
68
|
-
return {
|
|
69
|
-
...data,
|
|
70
|
-
foo: 22,
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const y = await ds.record.get('test')
|
|
75
|
-
if ('age' in y) {
|
|
76
|
-
console.log(y.name)
|
|
77
|
-
|
|
78
|
-
test<{ foo?: number }>((data) => {
|
|
79
|
-
return data
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test<{ foo: number }>((data) => {
|
|
83
|
-
return {
|
|
84
|
-
...data,
|
|
85
|
-
foo: 22,
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
if ('test' in w) {
|
|
90
|
-
console.log(w.haj)
|
|
91
|
-
}
|
|
92
|
-
console.log(w.test)
|
|
93
|
-
console.log(w.test)
|
|
94
|
-
|
|
95
|
-
const m: PossiblyEmptyData<{ test?: number }> = {}
|
|
96
|
-
console.log(m.test)
|
|
97
|
-
|
|
98
|
-
assertNonEmpty(q)
|
|
99
|
-
q.test
|
|
100
|
-
// q.test
|
|
101
|
-
|
|
102
|
-
// q
|
|
103
|
-
|
|
104
|
-
ds.record.set('test', ds.record.JSON.EMPTY_OBJ)
|
|
105
|
-
|
|
106
|
-
ds.record.update('test', (data) => {
|
|
107
|
-
const a = {
|
|
108
|
-
// ...data,
|
|
109
|
-
age: 22,
|
|
110
|
-
}
|
|
111
|
-
console.log(data.name)
|
|
112
|
-
return {
|
|
113
|
-
...data,
|
|
114
|
-
age: 22,
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
ds.record.provide('test', () => {})
|
|
119
|
-
|
|
120
|
-
ds.record.set('test', {
|
|
121
|
-
name: 23,
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
ds.record.set('foo', { value: 'namn' })
|
|
125
|
-
ds.record.set('foo', { bar: 22 })
|
|
126
|
-
ds.record.set('foo', {})
|
|
127
|
-
|
|
128
|
-
ds.record.set('test', 'name', '23')
|
|
129
|
-
|
|
130
|
-
ds.record.provide('test', () => {
|
|
131
|
-
return {
|
|
132
|
-
name: 23,
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
ds.record.update('test', 'name', (name) => {
|
|
137
|
-
return name
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
const r = ds.record.getRecord('test')
|
|
141
|
-
//const name = r.get('bar')
|
|
142
|
-
|
|
143
|
-
r.update('name', (name) => name + 'a2', { signal: new AbortSignal() })
|
|
144
|
-
|
|
145
|
-
r.update((name) => ({ name: 'hej', age: 22 }))
|
|
146
|
-
|
|
147
|
-
r.update('age', (age) => age + 1, { signal: new AbortSignal() })
|
|
148
|
-
|
|
149
|
-
r.set({ age: 23, name: 'test' })
|
|
150
|
-
r.set({ age: '23', name: 'test' })
|
|
151
|
-
|
|
152
|
-
r.set('name', 22)
|
|
153
|
-
r.set('name', 'name')
|
|
154
|
-
r.set('age', true)
|
|
155
|
-
r.set('age', 22)
|
|
156
|
-
|
|
157
|
-
ds.record.set('test', {})
|
|
158
|
-
|
|
159
|
-
const a1 = r.get()
|
|
160
|
-
const a2 = r.get('age')
|
|
161
|
-
const a3 = r.get('name')
|
|
162
|
-
const a4 = r.get('what')
|
|
163
|
-
|
|
164
|
-
const name = r.get('age')
|
|
165
|
-
|
|
166
|
-
const s = Object.freeze({})
|
|
167
|
-
|
|
168
|
-
ds.record.JSON.EMPTY
|
|
169
|
-
|
|
170
|
-
ds.event.provide('test', (what) => {}, {})
|
|
171
|
-
|
|
172
|
-
const a = ds.rpc.provide('test', (args, response) => {
|
|
173
|
-
console.log(args.name)
|
|
174
|
-
response.send({ age: 22 })
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
a()
|