15
15
*/
16
16
17
17
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
18
- import { IfStrict , IsNever , Not , Split } from '../../../misc/index.js' ;
18
+ import { IfStrict , IsNever , Not , Split , UnionKeys } from '../../../misc/index.js' ;
19
19
import { DefaultKeyspaceOptions } from '../cluster.types.js' ;
20
20
import type { IsFuzzyDocument } from '../document.types.js' ;
21
21
import {
@@ -123,7 +123,7 @@ type CCPerfectMatchPath<CC, UserPath> =
123
123
* When the user path matches a string template, it doesn't mean the path is valid.
124
124
* For example, given `[string, ...number[]]` for a `binary` operation, code completion path will include `arr[${number}]`.
125
125
* So `arr[0]` will match the path, and yet, it is not a valid path because arr[0] is not a number.
126
- * Returns `true` if the path is valid.
126
+ * @returns `true` if the path is valid.
127
127
*/
128
128
// prettier-ignore
129
129
export type IsLegalPath < Op extends KvOperation , Options , Doc , Path > =
@@ -204,16 +204,14 @@ type PTO<
204
204
Key ,
205
205
> =
206
206
[ FriendlyPath ] extends [ true ] ?
207
- OptionFriendlyPathRecordKey < Options > extends true ?
208
- IsTemplateString < Key > extends true ?
209
- [ true , `${ConcatPath < PathTo , OptionRecordFriendlyPlaceholder < Options > > } `] :
210
- [ true , ConcatPath < PathTo , Key > ] :
207
+ IsTemplateString < Key > extends true ?
208
+ [ true , ConcatPath < PathTo , '#' > ] :
211
209
[ true , ConcatPath < PathTo , Key > ] :
212
210
[ FriendlyPath ] extends [ false ] ?
213
211
[ false , ConcatPath < PathTo , Key > ] :
214
212
OptionFriendlyPathRecordKey < Options > extends true ?
215
213
IsTemplateString < Key > extends true ?
216
- [ false , `${ ConcatPath < PathTo , Key > } ` ] | [ true , ConcatPath < PathTo , OptionRecordFriendlyPlaceholder < Options > > ] :
214
+ [ false , ConcatPath < PathTo , Key > ] | [ true , ConcatPath < PathTo , '#' > ] :
217
215
[ boolean , ConcatPath < PathTo , Key > ] :
218
216
[ boolean , ConcatPath < PathTo , Key > ]
219
217
;
@@ -233,15 +231,20 @@ export type Keys<T> =
233
231
234
232
// prettier-ignore
235
233
export type Get < T , K > =
236
- K extends - 1 ?
237
- T extends ReadonlyArray < unknown > ?
234
+ T extends ReadonlyArray < unknown > ?
235
+ K extends - 1 ?
238
236
ArrayLastElement < T > :
237
+ K extends number ?
238
+ T [ K ] :
239
239
never :
240
- K extends keyof Extract < T , object > ?
241
- Extract < T , object > [ K ] :
240
+ K extends string | number ?
241
+ Extract < T , { [ Key in K ] ?: unknown } > [ K ] :
242
242
never
243
243
;
244
244
245
+ type TG = Get < { title ?: string } | { status : string } , 'status' > ;
246
+ type TTG = Extract < { title : string } | { status : string } , { [ Key in 'title' ] : any } >
247
+
245
248
// prettier-ignore
246
249
export type DocumentCodeCompletion < Op extends KvOperation , Options , T > =
247
250
T extends object ?
@@ -251,18 +254,17 @@ export type DocumentCodeCompletion<Op extends KvOperation, Options, T> =
251
254
never
252
255
;
253
256
254
- type BorrowId = `b::${string } `;
255
- type UserId = `user::${number } `;
256
- type User = {
257
- br ?: Record <
258
- BorrowId ,
259
- {
260
- at : number ;
261
- }
262
- > ;
263
- } ;
257
+ type TestDoc = { title : string } | { status : string } ;
258
+ type TBB = BuildBag < 'get' , NonNullable < unknown > , false , 'events' , TestDoc , [ ] > ;
264
259
265
- type TBB = BuildBag < 'remove' , DefaultKeyspaceOptions , boolean , '' , User , [ ] > ;
260
+ // prettier-ignore
261
+ type TTK =
262
+ Keys < TestDoc > extends infer KeyTuple ?
263
+ KeyTuple extends [ infer Key ] ?
264
+ Get < TestDoc , Key > :
265
+ never :
266
+ never
267
+ ;
266
268
267
269
// prettier-ignore
268
270
type BuildBag < Op extends KvOperation , Options , FriendlyPath , PathToDoc , Doc , UnionStack extends ReadonlyArray < unknown > > =
@@ -272,16 +274,13 @@ type BuildBag<Op extends KvOperation, Options, FriendlyPath, PathToDoc, Doc, Uni
272
274
Keys < Doc > extends infer KeyTuple ?
273
275
KeyTuple extends [ infer Key ] ?
274
276
Get < Doc , Key > extends infer SubDoc ?
275
-
276
277
PathToKey < Options , FriendlyPath , Doc , PathToDoc , Key > extends infer PTK ?
277
278
PTK extends [ infer BuildFriendly , infer Path ] ?
278
- // [PTK, SubDoc] | (PTK extends [infer BuildFriendly, infer Path] ?
279
- BuildBag < Op , Options , BuildFriendly , Path , SubDoc , [
280
- ...UnionStack ,
281
- CodeCompletion < Op , BuildFriendly , Doc , Key , Path , SubDoc >
282
- ] > :
283
- // never):
284
- never :
279
+ BuildBag < Op , Options , BuildFriendly , Path , SubDoc , [
280
+ ...UnionStack ,
281
+ CodeCompletion < Op , BuildFriendly , Doc , Key , Path , SubDoc >
282
+ ] > :
283
+ never :
285
284
never :
286
285
never :
287
286
UnionStack :
0 commit comments