@nxtedition/deepstream.io-client-js 32.0.11 → 32.0.12
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 +30 -3
- package/src/client.test-d.ts +32 -1
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,
|
|
@@ -77,6 +88,16 @@ type EventConstants = Readonly<{
|
|
|
77
88
|
}>
|
|
78
89
|
type EventKey = keyof EventConstants
|
|
79
90
|
type EventName = EventConstants[EventKey]
|
|
91
|
+
type DeepstreamErrorEventName = Exclude<
|
|
92
|
+
EventName,
|
|
93
|
+
'connectionStateChanged' | 'connected' | 'MAX_RECONNECTION_ATTEMPTS_REACHED'
|
|
94
|
+
>
|
|
95
|
+
|
|
96
|
+
export interface DeepstreamError extends Error {
|
|
97
|
+
topic?: string
|
|
98
|
+
event?: EventName | null
|
|
99
|
+
data?: unknown
|
|
100
|
+
}
|
|
80
101
|
|
|
81
102
|
export interface DeepstreamClient<
|
|
82
103
|
Records extends Record<string, unknown> = Record<string, unknown>,
|
|
@@ -87,8 +108,14 @@ export interface DeepstreamClient<
|
|
|
87
108
|
rpc: RpcHandler<Methods>
|
|
88
109
|
record: RecordHandler<Records>
|
|
89
110
|
user: string | null
|
|
90
|
-
on
|
|
91
|
-
|
|
111
|
+
on(evt: 'connectionStateChanged', callback: (state: ConnectionStateName) => void): this
|
|
112
|
+
on(evt: 'connected', callback: (connected: boolean) => void): this
|
|
113
|
+
on(evt: 'MAX_RECONNECTION_ATTEMPTS_REACHED', callback: (attempt: number) => void): this
|
|
114
|
+
on(evt: 'error' | DeepstreamErrorEventName, callback: (error: DeepstreamError) => void): this
|
|
115
|
+
off(evt: 'connectionStateChanged', callback: (state: ConnectionStateName) => void): this
|
|
116
|
+
off(evt: 'connected', callback: (connected: boolean) => void): this
|
|
117
|
+
off(evt: 'MAX_RECONNECTION_ATTEMPTS_REACHED', callback: (attempt: number) => void): this
|
|
118
|
+
off(evt: 'error' | DeepstreamErrorEventName, callback: (error: DeepstreamError) => void): this
|
|
92
119
|
getConnectionState: () => ConnectionStateName
|
|
93
120
|
close: () => void
|
|
94
121
|
login(callback: (success: boolean, authData: unknown) => void): this
|
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) => {}))
|