@nxtedition/deepstream.io-client-js 31.2.1 → 31.2.2
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/.claude/settings.local.json +9 -0
- 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/package.json +1 -1
- package/src/client.d.ts +2 -2
- package/src/client.test-d.ts +119 -9
- package/src/record/record-handler.d.ts +83 -21
- package/src/record/record.d.ts +17 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type RpcHandler from './rpc/rpc-handler.js'
|
|
|
8
8
|
import type { RpcStats, RpcMethodDef } from './rpc/rpc-handler.js'
|
|
9
9
|
|
|
10
10
|
export default function <
|
|
11
|
-
Records,
|
|
11
|
+
Records extends Record<string, unknown> = Record<string, unknown>,
|
|
12
12
|
Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
|
|
13
13
|
>(url: string, options?: unknown): DeepstreamClient<Records, Methods>
|
|
14
14
|
|
|
@@ -79,7 +79,7 @@ type EventKey = keyof EventConstants
|
|
|
79
79
|
type EventName = EventConstants[EventKey]
|
|
80
80
|
|
|
81
81
|
export interface DeepstreamClient<
|
|
82
|
-
Records,
|
|
82
|
+
Records extends Record<string, unknown> = Record<string, unknown>,
|
|
83
83
|
Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
|
|
84
84
|
> {
|
|
85
85
|
nuid: () => string
|
package/src/client.test-d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import make, { type DeepstreamClient } from './client.js'
|
|
2
3
|
import { expectAssignable, expectError } from 'tsd'
|
|
4
|
+
import type { Observable } from 'rxjs'
|
|
3
5
|
|
|
4
6
|
interface Records extends Record<string, unknown> {
|
|
5
7
|
o: {
|
|
@@ -48,6 +50,14 @@ interface Circular {
|
|
|
48
50
|
|
|
49
51
|
const ds = make<Records>('')
|
|
50
52
|
|
|
53
|
+
// Test that make() returns DeepstreamClient with appropriate generics
|
|
54
|
+
expectAssignable<DeepstreamClient>(make(''))
|
|
55
|
+
// When you want to accept "any client" regardless of Records type, use DeepstreamClient<any>
|
|
56
|
+
expectAssignable<DeepstreamClient<any>>(make<Records>(''))
|
|
57
|
+
expectAssignable<DeepstreamClient<any, any>>(make<Records>(''))
|
|
58
|
+
expectAssignable<DeepstreamClient<any>>(ds)
|
|
59
|
+
expectAssignable<DeepstreamClient<any, any>>(ds)
|
|
60
|
+
|
|
51
61
|
expectAssignable<{ n0?: { n1: { n2: { n3: string } } } } | undefined>(await ds.record.get('n'))
|
|
52
62
|
expectAssignable<{ n1: { n2: { n3: string } } } | undefined>(await ds.record.get('n', 'n0'))
|
|
53
63
|
|
|
@@ -86,9 +96,89 @@ expectError(ds.record.set('n', 'n1.x2', {}))
|
|
|
86
96
|
expectError(ds.record.set('n', 'n1.n2.n3', { n4: 22 }))
|
|
87
97
|
|
|
88
98
|
expectAssignable<string>(await ds.record.get('p', 'p1'))
|
|
99
|
+
expectAssignable<string>(await ds.record.get('p', 'p1', { signal: new AbortController().signal }))
|
|
100
|
+
expectAssignable<string>(await ds.record.get('p', { path: 'p1' }))
|
|
89
101
|
expectAssignable<string | undefined>(await ds.record.get('p', 'p2'))
|
|
90
102
|
expectAssignable<unknown>(await ds.record.get('p', 'x1'))
|
|
91
103
|
|
|
104
|
+
// observe with options
|
|
105
|
+
expectAssignable<Observable<{ p1: string; p2?: string; p3: { p4: string } }>>(
|
|
106
|
+
ds.record.observe('p', { signal: new AbortController().signal }),
|
|
107
|
+
)
|
|
108
|
+
expectAssignable<Observable<{ p1: string; p2?: string; p3: { p4: string } }>>(
|
|
109
|
+
ds.record.observe('p', { timeout: 5000 }),
|
|
110
|
+
)
|
|
111
|
+
expectAssignable<Observable<string>>(
|
|
112
|
+
ds.record.observe('p', 'p1', { signal: new AbortController().signal }),
|
|
113
|
+
)
|
|
114
|
+
expectAssignable<Observable<string>>(ds.record.observe('p', { path: 'p1', timeout: 5000 }))
|
|
115
|
+
expectAssignable<Observable<string>>(
|
|
116
|
+
ds.record.observe('p', 'p1', 2, { signal: new AbortController().signal }),
|
|
117
|
+
)
|
|
118
|
+
expectAssignable<Observable<{ p1: string; p2?: string; p3: { p4: string } }>>(
|
|
119
|
+
ds.record.observe('p', 2, { timeout: 5000 }),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
// observe2 with options
|
|
123
|
+
expectAssignable<
|
|
124
|
+
Observable<{
|
|
125
|
+
name: string
|
|
126
|
+
version: string
|
|
127
|
+
state: number
|
|
128
|
+
data: { p1: string; p2?: string; p3: { p4: string } }
|
|
129
|
+
}>
|
|
130
|
+
>(ds.record.observe2('p', { signal: new AbortController().signal }))
|
|
131
|
+
expectAssignable<
|
|
132
|
+
Observable<{
|
|
133
|
+
name: string
|
|
134
|
+
version: string
|
|
135
|
+
state: number
|
|
136
|
+
data: { p1: string; p2?: string; p3: { p4: string } }
|
|
137
|
+
}>
|
|
138
|
+
>(ds.record.observe2('p', { timeout: 5000 }))
|
|
139
|
+
expectAssignable<
|
|
140
|
+
Observable<{
|
|
141
|
+
name: string
|
|
142
|
+
version: string
|
|
143
|
+
state: number
|
|
144
|
+
data: string
|
|
145
|
+
}>
|
|
146
|
+
>(ds.record.observe2('p', 'p1', { signal: new AbortController().signal }))
|
|
147
|
+
expectAssignable<
|
|
148
|
+
Observable<{
|
|
149
|
+
name: string
|
|
150
|
+
version: string
|
|
151
|
+
state: number
|
|
152
|
+
data: string
|
|
153
|
+
}>
|
|
154
|
+
>(ds.record.observe2('p', { path: 'p1', timeout: 5000 }))
|
|
155
|
+
expectAssignable<
|
|
156
|
+
Observable<{
|
|
157
|
+
name: string
|
|
158
|
+
version: string
|
|
159
|
+
state: number
|
|
160
|
+
data: string
|
|
161
|
+
}>
|
|
162
|
+
>(ds.record.observe2('p', 'p1', 2, { signal: new AbortController().signal }))
|
|
163
|
+
expectAssignable<
|
|
164
|
+
Observable<{
|
|
165
|
+
name: string
|
|
166
|
+
version: string
|
|
167
|
+
state: number
|
|
168
|
+
data: { p1: string; p2?: string; p3: { p4: string } }
|
|
169
|
+
}>
|
|
170
|
+
>(ds.record.observe2('p', 2, { timeout: 5000 }))
|
|
171
|
+
|
|
172
|
+
// update with options
|
|
173
|
+
expectAssignable<Promise<void>>(
|
|
174
|
+
ds.record.update('p', (data) => data, { signal: new AbortController().signal }),
|
|
175
|
+
)
|
|
176
|
+
expectAssignable<Promise<void>>(ds.record.update('p', (data) => data, { timeout: 5000 }))
|
|
177
|
+
expectAssignable<Promise<void>>(
|
|
178
|
+
ds.record.update('p', 'p1', (data) => data, { signal: new AbortController().signal }),
|
|
179
|
+
)
|
|
180
|
+
expectAssignable<Promise<void>>(ds.record.update('p', 'p1', (data) => data, { timeout: 5000 }))
|
|
181
|
+
|
|
92
182
|
// Circular
|
|
93
183
|
expectAssignable<string | undefined>(await ds.record.get('c', 'a.b1'))
|
|
94
184
|
|
|
@@ -96,11 +186,31 @@ expectAssignable<string | undefined>(await ds.record.get('c', 'a.b1'))
|
|
|
96
186
|
//
|
|
97
187
|
|
|
98
188
|
// getRecord
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
expectError(
|
|
104
|
-
|
|
105
|
-
expectError(
|
|
106
|
-
expectError(
|
|
189
|
+
const rec = ds.record.getRecord('o')
|
|
190
|
+
rec.set({ o0: {} })
|
|
191
|
+
|
|
192
|
+
rec.update('o0', (x) => ({ ...x, o1: {} }))
|
|
193
|
+
expectError(rec.set('o0.x1', {}))
|
|
194
|
+
rec.set('o0.o1', {})
|
|
195
|
+
expectError(rec.update((x) => 'x'))
|
|
196
|
+
expectError(rec.update('o0', (x) => ({ ...x, o1: '22' })))
|
|
197
|
+
|
|
198
|
+
// when with options
|
|
199
|
+
expectAssignable<Promise<typeof rec>>(rec.when())
|
|
200
|
+
expectAssignable<Promise<typeof rec>>(rec.when(2))
|
|
201
|
+
expectAssignable<Promise<typeof rec>>(rec.when({ timeout: 5000 }))
|
|
202
|
+
expectAssignable<Promise<typeof rec>>(rec.when({ signal: new AbortController().signal }))
|
|
203
|
+
expectAssignable<Promise<typeof rec>>(rec.when({ state: 2 }))
|
|
204
|
+
expectAssignable<Promise<typeof rec>>(rec.when({ state: 2, timeout: 5000 }))
|
|
205
|
+
expectAssignable<Promise<typeof rec>>(rec.when(2, { timeout: 5000 }))
|
|
206
|
+
expectAssignable<Promise<typeof rec>>(rec.when(2, { signal: new AbortController().signal }))
|
|
207
|
+
|
|
208
|
+
// Record.update with options
|
|
209
|
+
expectAssignable<Promise<void>>(rec.update((x) => x, { signal: new AbortController().signal }))
|
|
210
|
+
expectAssignable<Promise<void>>(rec.update((x) => x, { timeout: 5000 }))
|
|
211
|
+
expectAssignable<Promise<void>>(rec.update((x) => x, { state: 2 }))
|
|
212
|
+
expectAssignable<Promise<void>>(
|
|
213
|
+
rec.update('o0', (x) => x, { signal: new AbortController().signal }),
|
|
214
|
+
)
|
|
215
|
+
expectAssignable<Promise<void>>(rec.update('o0', (x) => x, { timeout: 5000 }))
|
|
216
|
+
expectAssignable<Promise<void>>(rec.update('o0', (x) => x, { state: 2 }))
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs'
|
|
2
2
|
import type DsRecord from './record.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
EmptyObject,
|
|
5
|
+
Get,
|
|
6
|
+
UpdateOptions,
|
|
7
|
+
ObserveOptions,
|
|
8
|
+
ObserveOptionsWithPath,
|
|
9
|
+
} from './record.js'
|
|
4
10
|
|
|
5
11
|
type Lookup<Table, Name> = Name extends keyof Table ? Table[Name] : unknown
|
|
6
12
|
|
|
@@ -45,57 +51,92 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
update: {
|
|
48
|
-
// without path:
|
|
49
54
|
<Name extends string>(
|
|
50
55
|
name: Name,
|
|
51
56
|
updater: (data: Lookup<Records, Name>) => Lookup<Records, Name> | EmptyObject,
|
|
57
|
+
options?: UpdateOptions,
|
|
52
58
|
): Promise<void>
|
|
53
59
|
|
|
54
|
-
// with path:
|
|
55
60
|
<Name extends string, Path extends string | string[]>(
|
|
56
61
|
name: Name,
|
|
57
62
|
path: Path,
|
|
58
63
|
updater: (data: Get<Lookup<Records, Name>, Path>) => Get<Lookup<Records, Name>, Path>,
|
|
64
|
+
options?: UpdateOptions,
|
|
59
65
|
): Promise<void>
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
observe: {
|
|
63
|
-
|
|
64
|
-
<Name extends string>(name: Name): Observable<Lookup<Records, Name>>
|
|
69
|
+
<Name extends string>(name: Name, options: ObserveOptions): Observable<Lookup<Records, Name>>
|
|
65
70
|
|
|
66
|
-
// with path:
|
|
67
71
|
<Name extends string, Path extends string | string[]>(
|
|
68
72
|
name: Name,
|
|
69
|
-
|
|
73
|
+
options: ObserveOptionsWithPath<Path>,
|
|
74
|
+
): Observable<Get<Lookup<Records, Name>, Path>>
|
|
75
|
+
|
|
76
|
+
<Name extends string>(
|
|
77
|
+
name: Name,
|
|
78
|
+
state?: number,
|
|
79
|
+
options?: ObserveOptions,
|
|
80
|
+
): Observable<Lookup<Records, Name>>
|
|
81
|
+
|
|
82
|
+
<Name extends string, Path extends string | string[]>(
|
|
83
|
+
name: Name,
|
|
84
|
+
state?: number,
|
|
85
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
70
86
|
): Observable<Get<Lookup<Records, Name>, Path>>
|
|
71
87
|
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
<Name extends string, Path extends string | string[]>(
|
|
89
|
+
name: Name,
|
|
90
|
+
path: Path,
|
|
91
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
92
|
+
): Observable<Get<Lookup<Records, Name>, Path>>
|
|
74
93
|
|
|
75
|
-
// with path and state:
|
|
76
94
|
<Name extends string, Path extends string | string[]>(
|
|
77
95
|
name: Name,
|
|
78
96
|
path: Path,
|
|
79
|
-
state
|
|
97
|
+
state?: number,
|
|
98
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
80
99
|
): Observable<Get<Lookup<Records, Name>, Path>>
|
|
81
100
|
}
|
|
82
101
|
|
|
83
102
|
get: {
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
<Name extends string>(name: Name, options: ObserveOptions): Promise<Lookup<Records, Name>>
|
|
104
|
+
|
|
105
|
+
<Name extends string, Path extends string | string[]>(
|
|
106
|
+
name: Name,
|
|
107
|
+
options: ObserveOptionsWithPath<Path>,
|
|
108
|
+
): Promise<Get<Lookup<Records, Name>, Path>>
|
|
109
|
+
|
|
110
|
+
<Name extends string>(
|
|
111
|
+
name: Name,
|
|
112
|
+
state?: number,
|
|
113
|
+
options?: ObserveOptions,
|
|
114
|
+
): Promise<Lookup<Records, Name>>
|
|
115
|
+
|
|
116
|
+
<Name extends string, Path extends string | string[]>(
|
|
117
|
+
name: Name,
|
|
118
|
+
state?: number,
|
|
119
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
120
|
+
): Promise<Get<Lookup<Records, Name>, Path>>
|
|
121
|
+
|
|
122
|
+
<Name extends string, Path extends string | string[]>(
|
|
123
|
+
name: Name,
|
|
124
|
+
path: Path,
|
|
125
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
126
|
+
): Promise<Get<Lookup<Records, Name>, Path>>
|
|
86
127
|
|
|
87
|
-
// with path:
|
|
88
128
|
<Name extends string, Path extends string | string[]>(
|
|
89
129
|
name: Name,
|
|
90
130
|
path: Path,
|
|
91
131
|
state?: number,
|
|
132
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
92
133
|
): Promise<Get<Lookup<Records, Name>, Path>>
|
|
93
134
|
}
|
|
94
135
|
|
|
95
136
|
observe2: {
|
|
96
|
-
// without path:
|
|
97
137
|
<Name extends string>(
|
|
98
138
|
name: Name,
|
|
139
|
+
options: ObserveOptions,
|
|
99
140
|
): Observable<{
|
|
100
141
|
name: string
|
|
101
142
|
version: string
|
|
@@ -103,10 +144,9 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
103
144
|
data: Lookup<Records, Name>
|
|
104
145
|
}>
|
|
105
146
|
|
|
106
|
-
// with path:
|
|
107
147
|
<Name extends string, Path extends string | string[]>(
|
|
108
148
|
name: Name,
|
|
109
|
-
|
|
149
|
+
options: ObserveOptionsWithPath<Path>,
|
|
110
150
|
): Observable<{
|
|
111
151
|
name: string
|
|
112
152
|
version: string
|
|
@@ -114,10 +154,10 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
114
154
|
data: Get<Lookup<Records, Name>, Path>
|
|
115
155
|
}>
|
|
116
156
|
|
|
117
|
-
// with state:
|
|
118
157
|
<Name extends string>(
|
|
119
158
|
name: Name,
|
|
120
|
-
state
|
|
159
|
+
state?: number,
|
|
160
|
+
options?: ObserveOptions,
|
|
121
161
|
): Observable<{
|
|
122
162
|
name: string
|
|
123
163
|
version: string
|
|
@@ -125,11 +165,33 @@ export default class RecordHandler<Records = Record<string, unknown>> {
|
|
|
125
165
|
data: Lookup<Records, Name>
|
|
126
166
|
}>
|
|
127
167
|
|
|
128
|
-
|
|
168
|
+
<Name extends string, Path extends string | string[]>(
|
|
169
|
+
name: Name,
|
|
170
|
+
state?: number,
|
|
171
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
172
|
+
): Observable<{
|
|
173
|
+
name: string
|
|
174
|
+
version: string
|
|
175
|
+
state: number
|
|
176
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
177
|
+
}>
|
|
178
|
+
|
|
179
|
+
<Name extends string, Path extends string | string[]>(
|
|
180
|
+
name: Name,
|
|
181
|
+
path: Path,
|
|
182
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
183
|
+
): Observable<{
|
|
184
|
+
name: string
|
|
185
|
+
version: string
|
|
186
|
+
state: number
|
|
187
|
+
data: Get<Lookup<Records, Name>, Path>
|
|
188
|
+
}>
|
|
189
|
+
|
|
129
190
|
<Name extends string, Path extends string | string[]>(
|
|
130
191
|
name: Name,
|
|
131
192
|
path: Path,
|
|
132
|
-
state
|
|
193
|
+
state?: number,
|
|
194
|
+
options?: ObserveOptionsWithPath<Path>,
|
|
133
195
|
): Observable<{
|
|
134
196
|
name: string
|
|
135
197
|
version: string
|
package/src/record/record.d.ts
CHANGED
|
@@ -33,12 +33,27 @@ export type GettablePossibleEmpty<Data> = keyof Data extends never
|
|
|
33
33
|
export type SettablePossibleEmpty<Data> = Data | EmptyObject
|
|
34
34
|
|
|
35
35
|
export interface WhenOptions {
|
|
36
|
-
timeout?: number
|
|
37
36
|
signal?: AbortSignal
|
|
37
|
+
timeout?: number
|
|
38
|
+
state?: number
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export interface UpdateOptions {
|
|
41
42
|
signal?: AbortSignal
|
|
43
|
+
timeout?: number
|
|
44
|
+
state?: number
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ObserveOptions {
|
|
48
|
+
signal?: AbortSignal
|
|
49
|
+
timeout?: number
|
|
50
|
+
state?: number
|
|
51
|
+
dataOnly?: boolean
|
|
52
|
+
sync?: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ObserveOptionsWithPath<Path extends string | string[]> extends ObserveOptions {
|
|
56
|
+
path?: Path
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
export default class Record<Data = unknown> {
|
|
@@ -74,9 +89,8 @@ export default class Record<Data = unknown> {
|
|
|
74
89
|
|
|
75
90
|
when: {
|
|
76
91
|
(): Promise<Record<Data>>
|
|
77
|
-
(state: number): Promise<Record<Data>>
|
|
78
92
|
(options: WhenOptions): Promise<Record<Data>>
|
|
79
|
-
(state: number, options
|
|
93
|
+
(state: number, options?: WhenOptions): Promise<Record<Data>>
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
update: {
|