@nxtedition/deepstream.io-client-js 31.0.15 → 31.0.17

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "31.0.15",
3
+ "version": "31.0.17",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "type": "module",
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 extends Record<string, unknown> = Record<string, unknown>,
11
+ Records,
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 extends Record<string, unknown> = Record<string, unknown>,
82
+ Records = Record<string, unknown>,
83
83
  Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
84
84
  > {
85
85
  nuid: () => string
@@ -72,6 +72,8 @@ ds.record.set('c', 'a.b1', 'test')
72
72
  ds.record.set('x:domain', 'd1', 'test')
73
73
  const id = 'id'
74
74
  ds.record.set(`${id}:domain`, 'd2.d3', 'test')
75
+ expectError(ds.record.set(`${id}:domain`, 'd2.d3', 22))
76
+ ds.record.set(`${id}:domain`, ['d2', 'd3'] as const, 'test')
75
77
 
76
78
  expectAssignable<string>(await ds.record.get(`${id}:domain`, 'd2.d3'))
77
79
 
@@ -98,8 +100,7 @@ const daRec = ds.record.getRecord('o')
98
100
  daRec.set({ o0: {} })
99
101
 
100
102
  daRec.update('o0', (x) => ({ ...x, o1: {} }))
103
+ expectError(daRec.set('o0.x1', {}))
104
+ daRec.set('o0.o1', {})
101
105
  expectError(daRec.update((x) => 'x'))
102
106
  expectError(daRec.update('o0', (x) => ({ ...x, o1: '22' })))
103
-
104
- ds.record.set('foo', { num: [22, true] })
105
- ds.record.set('foo', { num: ['22'] })
@@ -1,10 +1,10 @@
1
1
  import type { Observable } from 'rxjs'
2
2
  import type DsRecord from './record.js'
3
- import type { EmptyObject, Get, Paths } from './record.js'
3
+ import type { EmptyObject, Get } from './record.js'
4
4
 
5
- export default class RecordHandler<
6
- Lookup extends Record<string, unknown> = Record<string, unknown>,
7
- > {
5
+ type Lookup<Table, Name> = Name extends keyof Table ? Table[Name] : unknown
6
+
7
+ export default class RecordHandler<Records = Record<string, unknown>> {
8
8
  VOID: 0
9
9
  CLIENT: 1
10
10
  SERVER: 2
@@ -20,9 +20,7 @@ export default class RecordHandler<
20
20
  connected: boolean
21
21
  stats: RecordStats
22
22
 
23
- getRecord<Name extends string, Data = Name extends keyof Lookup ? Lookup[Name] : unknown>(
24
- name: Name,
25
- ): DsRecord<Data>
23
+ getRecord<Name extends string, Data = Lookup<Records, Name>>(name: Name): DsRecord<Data>
26
24
 
27
25
  provide: (
28
26
  pattern: string,
@@ -34,13 +32,15 @@ export default class RecordHandler<
34
32
 
35
33
  set: {
36
34
  // without path:
37
- <Name extends string>(name: Name, data: Lookup[Name] | EmptyObject): void
35
+ <Name extends string>(name: Name, data: Lookup<Records, Name> | EmptyObject): void
38
36
 
39
37
  // with path:
40
38
  <Name extends string, Path extends string | string[]>(
41
39
  name: Name,
42
40
  path: Path,
43
- data: Path extends Paths<Lookup[Name]> ? Get<Lookup[Name], Path> : never,
41
+ data: unknown extends Get<Lookup<Records, Name>, Path>
42
+ ? never
43
+ : Get<Lookup<Records, Name>, Path>,
44
44
  ): void
45
45
  }
46
46
 
@@ -48,48 +48,48 @@ export default class RecordHandler<
48
48
  // without path:
49
49
  <Name extends string>(
50
50
  name: Name,
51
- updater: (data: Lookup[Name]) => Lookup[Name] | EmptyObject,
51
+ updater: (data: Lookup<Records, Name>) => Lookup<Records, Name> | EmptyObject,
52
52
  ): Promise<void>
53
53
 
54
54
  // with path:
55
55
  <Name extends string, Path extends string | string[]>(
56
56
  name: Name,
57
57
  path: Path,
58
- updater: (data: Get<Lookup[Name], Path>) => Get<Lookup[Name], Path>,
58
+ updater: (data: Get<Lookup<Records, Name>, Path>) => Get<Lookup<Records, Name>, Path>,
59
59
  ): Promise<void>
60
60
  }
61
61
 
62
62
  observe: {
63
63
  // without path:
64
- <Name extends string>(name: Name): Observable<Lookup[Name]>
64
+ <Name extends string>(name: Name): Observable<Lookup<Records, Name>>
65
65
 
66
66
  // with path:
67
67
  <Name extends string, Path extends string | string[]>(
68
68
  name: Name,
69
69
  path: Path,
70
- ): Observable<Get<Lookup[Name], Path>>
70
+ ): Observable<Get<Lookup<Records, Name>, Path>>
71
71
 
72
72
  // with state:
73
- <Name extends string>(name: Name, state: number): Observable<Lookup[Name]>
73
+ <Name extends string>(name: Name, state: number): Observable<Lookup<Records, Name>>
74
74
 
75
75
  // with path and state:
76
76
  <Name extends string, Path extends string | string[]>(
77
77
  name: Name,
78
78
  path: Path,
79
79
  state: number,
80
- ): Observable<Get<Lookup[Name], Path>>
80
+ ): Observable<Get<Lookup<Records, Name>, Path>>
81
81
  }
82
82
 
83
83
  get: {
84
84
  // without path:
85
- <Name extends string>(name: Name, state?: number): Promise<Lookup[Name]>
85
+ <Name extends string>(name: Name, state?: number): Promise<Lookup<Records, Name>>
86
86
 
87
87
  // with path:
88
88
  <Name extends string, Path extends string | string[]>(
89
89
  name: Name,
90
90
  path: Path,
91
91
  state?: number,
92
- ): Promise<Get<Lookup[Name], Path>>
92
+ ): Promise<Get<Lookup<Records, Name>, Path>>
93
93
  }
94
94
 
95
95
  observe2: {
@@ -100,7 +100,7 @@ export default class RecordHandler<
100
100
  name: string
101
101
  version: string
102
102
  state: number
103
- data: Lookup[Name]
103
+ data: Lookup<Records, Name>
104
104
  }>
105
105
 
106
106
  // with path:
@@ -111,7 +111,7 @@ export default class RecordHandler<
111
111
  name: string
112
112
  version: string
113
113
  state: number
114
- data: Get<Lookup[Name], Path>
114
+ data: Get<Lookup<Records, Name>, Path>
115
115
  }>
116
116
 
117
117
  // with state:
@@ -122,7 +122,7 @@ export default class RecordHandler<
122
122
  name: string
123
123
  version: string
124
124
  state: number
125
- data: Lookup[Name]
125
+ data: Lookup<Records, Name>
126
126
  }>
127
127
 
128
128
  // with path and state:
@@ -134,7 +134,7 @@ export default class RecordHandler<
134
134
  name: string
135
135
  version: string
136
136
  state: number
137
- data: Get<Lookup[Name], Path>
137
+ data: Get<Lookup<Records, Name>, Path>
138
138
  }>
139
139
  }
140
140
  }
@@ -64,7 +64,10 @@ export default class Record<Data = unknown> {
64
64
 
65
65
  set: {
66
66
  // with path
67
- <P extends string | string[]>(path: P, dataAtPath: Get<Data, P>): void
67
+ <P extends string | readonly string[]>(
68
+ path: P,
69
+ dataAtPath: unknown extends Get<Data, P> ? never : Get<Data, P>,
70
+ ): void
68
71
  // without path
69
72
  (data: SettablePossibleEmpty<Data>): void
70
73
  }
@@ -2,7 +2,9 @@ import RpcResponse from './rpc-response.js'
2
2
 
3
3
  export type RpcMethodDef = [arguments: unknown, response: unknown]
4
4
 
5
- export default class RpcHandler<Methods extends Record<string, RpcMethodDef>> {
5
+ export default class RpcHandler<
6
+ Methods extends Record<string, RpcMethodDef> = Record<string, RpcMethodDef>,
7
+ > {
6
8
  connected: boolean
7
9
  stats: RpcStats
8
10