@@ -167,89 +167,6 @@ export type RPCCallNodes<
167167 : SelectQueryError < 'Invalid first node in RPC call' >
168168 : Prettify < Acc >
169169
170- type SplitArray <
171- T extends readonly unknown [ ] ,
172- N extends number ,
173- Acc extends readonly unknown [ ] = [ ]
174- > = Acc [ 'length' ] extends N
175- ? [ Acc , T ]
176- : T extends readonly [ infer Head , ...infer Tail ]
177- ? SplitArray < Tail , N , [ ...Acc , Head ] >
178- : [ Acc , T ]
179-
180- type ProcessBatch <
181- ClientOptions extends ClientServerOptions ,
182- Schema extends GenericSchema ,
183- Row extends Record < string , unknown > ,
184- RelationName extends string ,
185- Relationships extends GenericRelationship [ ] ,
186- Batch extends Ast . Node [ ] ,
187- Acc extends Record < string , unknown >
188- > = Batch extends [ infer Head , ...infer Tail ]
189- ? Head extends Ast . Node
190- ? Tail extends Ast . Node [ ]
191- ? ProcessNode <
192- ClientOptions ,
193- Schema ,
194- Row ,
195- RelationName ,
196- Relationships ,
197- Head
198- > extends infer Result
199- ? Result extends Record < string , unknown >
200- ? ProcessBatch <
201- ClientOptions ,
202- Schema ,
203- Row ,
204- RelationName ,
205- Relationships ,
206- Tail ,
207- Omit < Acc , keyof Result > & Result
208- >
209- : Result
210- : SelectQueryError < 'Node processing failed' >
211- : Acc
212- : Acc
213- : Acc
214-
215- type ProcessNodesBatched <
216- ClientOptions extends ClientServerOptions ,
217- Schema extends GenericSchema ,
218- Row extends Record < string , unknown > ,
219- RelationName extends string ,
220- Relationships extends GenericRelationship [ ] ,
221- Nodes extends Ast . Node [ ] ,
222- Acc extends Record < string , unknown > = { }
223- > = Nodes extends [ ]
224- ? Prettify < Acc >
225- : SplitArray < Nodes , 5 > extends [ infer Batch , infer Remaining ]
226- ? Batch extends Ast . Node [ ]
227- ? Remaining extends Ast . Node [ ]
228- ? ProcessBatch <
229- ClientOptions ,
230- Schema ,
231- Row ,
232- RelationName ,
233- Relationships ,
234- Batch ,
235- Acc
236- > extends infer BatchResult
237- ? BatchResult extends Record < string , unknown >
238- ? ProcessNodesBatched <
239- ClientOptions ,
240- Schema ,
241- Row ,
242- RelationName ,
243- Relationships ,
244- Remaining ,
245- BatchResult
246- >
247- : BatchResult
248- : SelectQueryError < 'Batch processing failed' >
249- : SelectQueryError < 'Invalid remaining nodes' >
250- : SelectQueryError < 'Invalid batch nodes' >
251- : SelectQueryError < 'Array splitting failed' >
252-
253170/**
254171 * Recursively processes an array of Nodes and accumulates the resulting TypeScript type.
255172 *
@@ -266,9 +183,48 @@ export type ProcessNodes<
266183 Row extends Record < string , unknown > ,
267184 RelationName extends string ,
268185 Relationships extends GenericRelationship [ ] ,
269- Nodes extends Ast . Node [ ]
186+ Nodes extends Ast . Node [ ] ,
187+ Acc extends Record < string , unknown > = { } // Acc is now an object
270188> = CheckDuplicateEmbededReference < Schema , RelationName , Relationships , Nodes > extends false
271- ? ProcessNodesBatched < ClientOptions , Schema , Row , RelationName , Relationships , Nodes >
189+ ? Nodes extends [ infer FirstNode , ...infer RestNodes ]
190+ ? FirstNode extends Ast . Node
191+ ? RestNodes extends Ast . Node [ ]
192+ ? ProcessNode <
193+ ClientOptions ,
194+ Schema ,
195+ Row ,
196+ RelationName ,
197+ Relationships ,
198+ FirstNode
199+ > extends infer FieldResult
200+ ? FieldResult extends Record < string , unknown >
201+ ? ProcessNodes <
202+ ClientOptions ,
203+ Schema ,
204+ Row ,
205+ RelationName ,
206+ Relationships ,
207+ RestNodes ,
208+ // TODO:
209+ // This SHOULD be `Omit<Acc, keyof FieldResult> & FieldResult` since in the case where the key
210+ // is present in the Acc already, the intersection will create bad intersection types
211+ // (eg: `{ a: number } & { a: { property } }` will become `{ a: number & { property } }`)
212+ // but using Omit here explode the inference complexity resulting in "infinite recursion error" from typescript
213+ // very early (see: 'Check that selecting many fields doesn't yield an possibly infinite recursion error') test
214+ // in this case we can't get above ~10 fields before reaching the recursion error
215+ // If someone find a better way to do this, please do it !
216+ // It'll also allow to fix those two tests:
217+ // - `'join over a 1-M relation with both nullables and non-nullables fields using column name hinting on nested relation'`
218+ // - `'self reference relation via column''`
219+ Acc & FieldResult
220+ >
221+ : FieldResult extends SelectQueryError < infer E >
222+ ? SelectQueryError < E >
223+ : SelectQueryError < 'Could not retrieve a valid record or error value' >
224+ : SelectQueryError < 'Processing node failed.' >
225+ : SelectQueryError < 'Invalid rest nodes array type in ProcessNodes' >
226+ : SelectQueryError < 'Invalid first node type in ProcessNodes' >
227+ : Prettify < Acc >
272228 : Prettify < CheckDuplicateEmbededReference < Schema , RelationName , Relationships , Nodes > >
273229
274230/**
0 commit comments