@nxtedition/deepstream.io-client-js 32.0.10 → 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 +33 -1
- package/src/record/record.d.ts +11 -2
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'
|
|
@@ -109,6 +109,7 @@ expectAssignable<string>(await ds.record.get('p', 'p1', { signal: new AbortContr
|
|
|
109
109
|
expectAssignable<string>(await ds.record.get('p', { path: 'p1' }))
|
|
110
110
|
expectAssignable<string | undefined>(await ds.record.get('p', 'p2'))
|
|
111
111
|
expectAssignable<unknown>(await ds.record.get('p', 'x1'))
|
|
112
|
+
expectAssignable<string | undefined>(await ds.record.get('possiblyEmpty', 'pe1'))
|
|
112
113
|
|
|
113
114
|
// observe with options
|
|
114
115
|
expectAssignable<Observable<{ p1: string; p2?: string; p3: { p4: string } }>>(
|
|
@@ -286,3 +287,34 @@ expectAssignable<(() => void) | void>(ds.event.provide('pattern*', () => {}, {})
|
|
|
286
287
|
ds.on('error', (err) => {})
|
|
287
288
|
ds.off('error', (err) => {})
|
|
288
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.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type RecordHandler from './record-handler.js'
|
|
2
|
-
import type { Get } from 'type-fest'
|
|
3
|
-
export type {
|
|
2
|
+
import type { Get as _Get, AllUnionFields } from 'type-fest'
|
|
3
|
+
export type { Paths } from 'type-fest'
|
|
4
|
+
|
|
5
|
+
// HACK: Wrap type-fest's Get to get rid of EmptyObject from union
|
|
6
|
+
type RemoveSymbolKeys<T> = {
|
|
7
|
+
[K in keyof T as K extends symbol ? never : K]: T[K]
|
|
8
|
+
}
|
|
9
|
+
export type Get<BaseType, Path extends string | readonly string[]> = _Get<
|
|
10
|
+
RemoveSymbolKeys<AllUnionFields<BaseType>>,
|
|
11
|
+
Path
|
|
12
|
+
>
|
|
4
13
|
|
|
5
14
|
export interface WhenOptions {
|
|
6
15
|
signal?: AbortSignal
|