@nxtedition/deepstream.io-client-js 32.0.11 → 32.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 +1 -1
- package/src/client.d.ts +56 -4
- package/src/client.test-d.ts +32 -1
- package/src/event/event-handler.js +1 -1
- package/src/record/record.js +1 -1
- package/src/utils/utils.js +1 -1
- package/.claude/settings.local.json +0 -9
- package/nxtedition-deepstream.io-client-js-31.0.18-b1.tgz +0 -0
- package/nxtedition-deepstream.io-client-js-31.0.18-b2.tgz +0 -0
- package/nxtedition-deepstream.io-client-js-31.0.18-b3.tgz +0 -0
- package/nxtedition-deepstream.io-client-js-32.0.6-alpha.0.tgz +0 -0
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -7,10 +7,21 @@ import type { EventStats } from './event/event-handler.js'
|
|
|
7
7
|
import type RpcHandler from './rpc/rpc-handler.js'
|
|
8
8
|
import type { RpcStats, RpcMethodDef } from './rpc/rpc-handler.js'
|
|
9
9
|
|
|
10
|
+
export interface DeepstreamClientOptions {
|
|
11
|
+
reconnectIntervalIncrement?: number
|
|
12
|
+
maxReconnectInterval?: number
|
|
13
|
+
maxReconnectAttempts?: number
|
|
14
|
+
maxPacketSize?: number
|
|
15
|
+
batchSize?: number
|
|
16
|
+
schedule?: ((fn: () => void) => void) | null
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
logger?: any
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
export default function <
|
|
11
22
|
Records extends Record<string, unknown> = Record<string, unknown>,
|
|
12
23
|
Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
|
|
13
|
-
>(url: string, options?:
|
|
24
|
+
>(url: string, options?: DeepstreamClientOptions): DeepstreamClient<Records, Methods>
|
|
14
25
|
|
|
15
26
|
export type {
|
|
16
27
|
DsRecord,
|
|
@@ -22,6 +33,8 @@ export type {
|
|
|
22
33
|
SyncOptions,
|
|
23
34
|
Paths,
|
|
24
35
|
Get,
|
|
36
|
+
ConnectionStateName,
|
|
37
|
+
DeepstreamErrorEventName,
|
|
25
38
|
}
|
|
26
39
|
|
|
27
40
|
type RecordStateConstants = Readonly<{
|
|
@@ -77,6 +90,36 @@ type EventConstants = Readonly<{
|
|
|
77
90
|
}>
|
|
78
91
|
type EventKey = keyof EventConstants
|
|
79
92
|
type EventName = EventConstants[EventKey]
|
|
93
|
+
type DeepstreamErrorEventName = Exclude<
|
|
94
|
+
EventName,
|
|
95
|
+
'connectionStateChanged' | 'connected' | 'MAX_RECONNECTION_ATTEMPTS_REACHED'
|
|
96
|
+
>
|
|
97
|
+
|
|
98
|
+
export interface DeepstreamError extends Error {
|
|
99
|
+
topic?: string
|
|
100
|
+
event?: EventName | null
|
|
101
|
+
data?: unknown
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface DeepstreamMessage {
|
|
105
|
+
raw: string | null
|
|
106
|
+
topic: string | null
|
|
107
|
+
action: string | null
|
|
108
|
+
data: string[]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface DeepstreamClientEventMap {
|
|
112
|
+
connectionStateChanged: (state: ConnectionStateName) => void
|
|
113
|
+
connected: (connected: boolean) => void
|
|
114
|
+
MAX_RECONNECTION_ATTEMPTS_REACHED: (attempt: number) => void
|
|
115
|
+
error: (error: DeepstreamError) => void
|
|
116
|
+
recv: (message: DeepstreamMessage) => void
|
|
117
|
+
send: (message: DeepstreamMessage) => void
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type DeepstreamErrorEventMap = {
|
|
121
|
+
[K in DeepstreamErrorEventName]: (error: DeepstreamError) => void
|
|
122
|
+
}
|
|
80
123
|
|
|
81
124
|
export interface DeepstreamClient<
|
|
82
125
|
Records extends Record<string, unknown> = Record<string, unknown>,
|
|
@@ -87,12 +130,21 @@ export interface DeepstreamClient<
|
|
|
87
130
|
rpc: RpcHandler<Methods>
|
|
88
131
|
record: RecordHandler<Records>
|
|
89
132
|
user: string | null
|
|
90
|
-
on
|
|
91
|
-
|
|
133
|
+
on<K extends keyof (DeepstreamClientEventMap & DeepstreamErrorEventMap)>(
|
|
134
|
+
evt: K,
|
|
135
|
+
callback: (DeepstreamClientEventMap & DeepstreamErrorEventMap)[K],
|
|
136
|
+
): this
|
|
137
|
+
off<K extends keyof (DeepstreamClientEventMap & DeepstreamErrorEventMap)>(
|
|
138
|
+
evt: K,
|
|
139
|
+
callback: (DeepstreamClientEventMap & DeepstreamErrorEventMap)[K],
|
|
140
|
+
): this
|
|
92
141
|
getConnectionState: () => ConnectionStateName
|
|
93
142
|
close: () => void
|
|
94
143
|
login(callback: (success: boolean, authData: unknown) => void): this
|
|
95
|
-
login(
|
|
144
|
+
login(
|
|
145
|
+
authParams: Record<string, unknown>,
|
|
146
|
+
callback: (success: boolean, authData: unknown) => void,
|
|
147
|
+
): this
|
|
96
148
|
stats: {
|
|
97
149
|
record: RecordStats
|
|
98
150
|
rpc: RpcStats
|
package/src/client.test-d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import make, { type DeepstreamClient } from './client.js'
|
|
2
|
+
import make, { type DeepstreamClient, type DeepstreamError } from './client.js'
|
|
3
3
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
4
4
|
import type { Observable } from 'rxjs'
|
|
5
5
|
import type { EmptyObject } from 'type-fest'
|
|
@@ -287,3 +287,34 @@ expectAssignable<(() => void) | void>(ds.event.provide('pattern*', () => {}, {})
|
|
|
287
287
|
ds.on('error', (err) => {})
|
|
288
288
|
ds.off('error', (err) => {})
|
|
289
289
|
expectError(ds.on('unknownEvent', () => {}))
|
|
290
|
+
|
|
291
|
+
// client.on: callback arg types per event
|
|
292
|
+
ds.on('error', (err) => {
|
|
293
|
+
expectType<DeepstreamError>(err)
|
|
294
|
+
})
|
|
295
|
+
ds.on('connectionError', (err) => {
|
|
296
|
+
expectType<DeepstreamError>(err)
|
|
297
|
+
})
|
|
298
|
+
ds.on('connectionStateChanged', (state) => {
|
|
299
|
+
expectType<
|
|
300
|
+
| 'CLOSED'
|
|
301
|
+
| 'AWAITING_CONNECTION'
|
|
302
|
+
| 'CHALLENGING'
|
|
303
|
+
| 'AWAITING_AUTHENTICATION'
|
|
304
|
+
| 'AUTHENTICATING'
|
|
305
|
+
| 'OPEN'
|
|
306
|
+
| 'ERROR'
|
|
307
|
+
| 'RECONNECTING'
|
|
308
|
+
>(state)
|
|
309
|
+
})
|
|
310
|
+
ds.on('connected', (connected) => {
|
|
311
|
+
expectType<boolean>(connected)
|
|
312
|
+
})
|
|
313
|
+
ds.on('MAX_RECONNECTION_ATTEMPTS_REACHED', (attempt) => {
|
|
314
|
+
expectType<number>(attempt)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
// client.on: wrong callback arg types are errors
|
|
318
|
+
expectError(ds.on('connectionStateChanged', (state: number) => {}))
|
|
319
|
+
expectError(ds.on('connected', (connected: string) => {}))
|
|
320
|
+
expectError(ds.on('MAX_RECONNECTION_ATTEMPTS_REACHED', (attempt: string) => {}))
|
package/src/record/record.js
CHANGED
|
@@ -249,7 +249,7 @@ class Record {
|
|
|
249
249
|
when(stateOrNil, optionsOrNil) {
|
|
250
250
|
invariant(this._refs > 0, 'missing refs')
|
|
251
251
|
|
|
252
|
-
if (stateOrNil != null && stateOrNil === 'object') {
|
|
252
|
+
if (stateOrNil != null && typeof stateOrNil === 'object') {
|
|
253
253
|
optionsOrNil = stateOrNil
|
|
254
254
|
stateOrNil = optionsOrNil?.state
|
|
255
255
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -85,7 +85,7 @@ export function setTimeout(callback, timeoutDuration) {
|
|
|
85
85
|
|
|
86
86
|
export function setInterval(callback, intervalDuration) {
|
|
87
87
|
if (intervalDuration !== null) {
|
|
88
|
-
return setInterval(callback, intervalDuration)
|
|
88
|
+
return globalThis.setInterval(callback, intervalDuration)
|
|
89
89
|
} else {
|
|
90
90
|
return -1
|
|
91
91
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|