@@ -22,7 +22,7 @@ import {
22
22
} from '../../../clusterTypes/clusterTypes.js' ;
23
23
import type { AnyCollection } from '../../../clusterTypes/index.js' ;
24
24
import type {
25
- LookupInSpecResults ,
25
+ LookupInSpecResult ,
26
26
MakeLookupInSpec ,
27
27
} from '../../../clusterTypes/kv/lookup/lookupIn.types.js' ;
28
28
import type {
@@ -38,60 +38,63 @@ import type { LookupMethodName } from './types.js';
38
38
// prettier-ignore
39
39
type LookupResult <
40
40
Method extends LookupMethodName ,
41
- MatchingDocDef ,
42
- SpecDefinitions ,
41
+ SpecResults extends ReadonlyArray < unknown > ,
43
42
ThrowOnSpecError extends boolean ,
44
43
> =
45
44
Method extends 'lookupIn' ?
46
- LookupInResult < LookupInSpecResults < SpecDefinitions , MatchingDocDef > , ThrowOnSpecError > :
45
+ LookupInResult < SpecResults , ThrowOnSpecError > :
47
46
Method extends 'lookupInAnyReplica' ?
48
47
LookupInReplicaResult <
49
- LookupInSpecResults < SpecDefinitions , MatchingDocDef > ,
48
+ SpecResults ,
50
49
ThrowOnSpecError
51
50
> :
52
51
Method extends 'lookupInAllReplicas' ?
53
52
LookupInReplicaResult <
54
- LookupInSpecResults < SpecDefinitions , MatchingDocDef > ,
53
+ SpecResults ,
55
54
ThrowOnSpecError
56
55
> [ ] :
57
56
never
58
57
;
59
58
60
- type ThisAnd < T , Spec extends LookupInSpec > =
59
+ type ThisAnd < T , Spec > =
61
60
T extends ChainableLookupIn <
62
61
infer C ,
63
62
infer Method ,
64
63
infer Key ,
65
- infer SpecDefinitions ,
64
+ infer SpecResults ,
66
65
infer ThrowOnSpecError ,
67
- infer Doc
66
+ infer Def
68
67
>
69
- ? ChainableLookupIn < C , Method , Key , [ ...SpecDefinitions , Spec ] , ThrowOnSpecError , Doc >
68
+ ? ChainableLookupIn <
69
+ C ,
70
+ Method ,
71
+ Key ,
72
+ [ ...SpecResults , LookupInSpecResult < Spec , Def > ] ,
73
+ ThrowOnSpecError ,
74
+ Def
75
+ >
70
76
: never ;
71
77
72
78
export class ChainableLookupIn <
73
79
out C extends AnyCollection ,
74
80
out Method extends LookupMethodName ,
75
81
out Key extends ExtractCollectionJsonDocKey < C > ,
76
- out SpecDefinitions extends ReadonlyArray < LookupInSpec > ,
82
+ in out SpecResults extends ReadonlyArray < unknown > ,
77
83
out ThrowOnSpecError extends boolean ,
78
84
in out Def extends CollectionDocDefMatchingKey < C , Key > = CollectionDocDefMatchingKey <
79
85
C ,
80
86
Key
81
87
> ,
82
- > implements Promise < LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError > >
88
+ > implements Promise < LookupResult < Method , SpecResults , ThrowOnSpecError > >
83
89
{
84
90
// Promise stuff
85
91
86
92
[ Symbol . toStringTag ] = 'ChainableLookupInSpecs' ;
87
93
88
- then <
89
- TResult1 = LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError > ,
90
- TResult2 = never ,
91
- > (
94
+ then < TResult1 = LookupResult < Method , SpecResults , ThrowOnSpecError > , TResult2 = never > (
92
95
onFulfilled ?:
93
96
| ( (
94
- value : LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError >
97
+ value : LookupResult < Method , SpecResults , ThrowOnSpecError >
95
98
) => TResult1 | PromiseLike < TResult1 > )
96
99
| undefined
97
100
| null ,
@@ -105,13 +108,13 @@ export class ChainableLookupIn<
105
108
106
109
catch < TResult = never > (
107
110
onRejected ?: ( ( reason : unknown ) => TResult | PromiseLike < TResult > ) | null | undefined
108
- ) : Promise < LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError > | TResult > {
111
+ ) : Promise < LookupResult < Method , SpecResults , ThrowOnSpecError > | TResult > {
109
112
return this . then ( undefined , onRejected ) ;
110
113
}
111
114
112
115
finally (
113
116
onFinally ?: ( ( ) => void ) | null | undefined
114
- ) : Promise < LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError > > {
117
+ ) : Promise < LookupResult < Method , SpecResults , ThrowOnSpecError > > {
115
118
return this . then (
116
119
( value ) => {
117
120
onFinally ?.( ) ;
@@ -130,7 +133,7 @@ export class ChainableLookupIn<
130
133
protected method : Method ,
131
134
protected key : Key ,
132
135
protected options : LookupInOptions < ThrowOnSpecError > | undefined ,
133
- protected specs : SpecDefinitions
136
+ protected specs : LookupInSpec [ ]
134
137
) { }
135
138
136
139
static for <
@@ -148,12 +151,11 @@ export class ChainableLookupIn<
148
151
}
149
152
150
153
push < Spec extends LookupInSpec > ( spec : Spec ) : ThisAnd < this, Spec > {
151
- const newSpecs : [ ...SpecDefinitions , Spec ] = [ ...this . getSpecs ( ) , spec ] ;
152
- this . specs = newSpecs as never ;
153
- return this as never as ThisAnd < this, Spec > ;
154
+ this . specs = [ ...this . getSpecs ( ) , spec ] ;
155
+ return this as never as ThisAnd < this, LookupInSpecResult < Spec , Def > > ;
154
156
}
155
157
156
- execute ( ) : Promise < LookupResult < Method , Def , SpecDefinitions , ThrowOnSpecError > > {
158
+ execute ( ) : Promise < LookupResult < Method , SpecResults , ThrowOnSpecError > > {
157
159
const lookupMethod = this . collection [ this . method as Method & keyof C ] ;
158
160
const lookup = lookupMethod . bind ( this . collection ) as any ;
159
161
@@ -231,7 +233,7 @@ export class ChainableLookupIn<
231
233
/**
232
234
* Return the array of specs.
233
235
*/
234
- getSpecs ( ) : SpecDefinitions {
236
+ getSpecs ( ) : LookupInSpec [ ] {
235
237
return this . specs ;
236
238
}
237
239
}
0 commit comments