@@ -167,99 +167,6 @@ export type RPCCallNodes<
167
167
: SelectQueryError < 'Invalid first node in RPC call' >
168
168
: Prettify < Acc >
169
169
170
- // Helper types for optimization
171
- type SplitArray <
172
- T extends readonly unknown [ ] ,
173
- N extends number ,
174
- Acc extends readonly unknown [ ] = [ ]
175
- > = Acc [ 'length' ] extends N
176
- ? [ Acc , T ]
177
- : T extends readonly [ infer Head , ...infer Tail ]
178
- ? SplitArray < Tail , N , [ ...Acc , Head ] >
179
- : [ Acc , T ]
180
-
181
- type ProcessBatch <
182
- ClientOptions extends ClientServerOptions ,
183
- Schema extends GenericSchema ,
184
- Row extends Record < string , unknown > ,
185
- RelationName extends string ,
186
- Relationships extends GenericRelationship [ ] ,
187
- Batch extends Ast . Node [ ] ,
188
- Acc extends Record < string , unknown >
189
- > = Batch extends [ infer Head , ...infer Tail ]
190
- ? Head extends Ast . Node
191
- ? Tail extends Ast . Node [ ]
192
- ? ProcessNode <
193
- ClientOptions ,
194
- Schema ,
195
- Row ,
196
- RelationName ,
197
- Relationships ,
198
- Head
199
- > extends infer Result
200
- ? Result extends Record < string , unknown >
201
- ? ProcessBatch <
202
- ClientOptions ,
203
- Schema ,
204
- Row ,
205
- RelationName ,
206
- Relationships ,
207
- Tail ,
208
- Acc & Result
209
- >
210
- : Result
211
- : SelectQueryError < 'Node processing failed' >
212
- : Acc
213
- : Acc
214
- : Acc
215
-
216
- type ProcessSingleNode <
217
- ClientOptions extends ClientServerOptions ,
218
- Schema extends GenericSchema ,
219
- Row extends Record < string , unknown > ,
220
- RelationName extends string ,
221
- Relationships extends GenericRelationship [ ] ,
222
- Node extends Ast . Node
223
- > = ProcessNode < ClientOptions , Schema , Row , RelationName , Relationships , Node >
224
-
225
- type ProcessNodesBatched <
226
- ClientOptions extends ClientServerOptions ,
227
- Schema extends GenericSchema ,
228
- Row extends Record < string , unknown > ,
229
- RelationName extends string ,
230
- Relationships extends GenericRelationship [ ] ,
231
- Nodes extends Ast . Node [ ] ,
232
- Acc extends Record < string , unknown > = { }
233
- > = Nodes extends [ ]
234
- ? Prettify < Acc >
235
- : SplitArray < Nodes , 5 > extends [ infer Batch , infer Remaining ]
236
- ? Batch extends Ast . Node [ ]
237
- ? Remaining extends Ast . Node [ ]
238
- ? ProcessBatch <
239
- ClientOptions ,
240
- Schema ,
241
- Row ,
242
- RelationName ,
243
- Relationships ,
244
- Batch ,
245
- Acc
246
- > extends infer BatchResult
247
- ? BatchResult extends Record < string , unknown >
248
- ? ProcessNodesBatched <
249
- ClientOptions ,
250
- Schema ,
251
- Row ,
252
- RelationName ,
253
- Relationships ,
254
- Remaining ,
255
- BatchResult
256
- >
257
- : BatchResult
258
- : SelectQueryError < 'Batch processing failed' >
259
- : SelectQueryError < 'Invalid remaining nodes' >
260
- : SelectQueryError < 'Invalid batch nodes' >
261
- : SelectQueryError < 'Array splitting failed' >
262
-
263
170
/**
264
171
* Recursively processes an array of Nodes and accumulates the resulting TypeScript type.
265
172
*
@@ -276,24 +183,38 @@ export type ProcessNodes<
276
183
Row extends Record < string , unknown > ,
277
184
RelationName extends string ,
278
185
Relationships extends GenericRelationship [ ] ,
279
- Nodes extends Ast . Node [ ]
186
+ Nodes extends Ast . Node [ ] ,
187
+ Acc extends Record < string , unknown > = { } // Acc is now an object
280
188
> = CheckDuplicateEmbededReference < Schema , RelationName , Relationships , Nodes > extends false
281
- ? Nodes [ 'length' ] extends 0
282
- ? { }
283
- : Nodes [ 'length' ] extends 1
284
- ? Prettify < ProcessSingleNode < ClientOptions , Schema , Row , RelationName , Relationships , Nodes [ 0 ] > >
285
- : // : Nodes['length'] extends 2
286
- // ? Prettify<
287
- // ProcessTwoNodes<
288
- // ClientOptions,
289
- // Schema,
290
- // Row,
291
- // RelationName,
292
- // Relationships,
293
- // [Nodes[0], Nodes[1]]
294
- // >
295
- // >
296
- 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
+ // Replace fields that exist in both Acc and FieldResult instead of intersecting
209
+ Acc & FieldResult
210
+ >
211
+ : FieldResult extends SelectQueryError < infer E >
212
+ ? SelectQueryError < E >
213
+ : SelectQueryError < 'Could not retrieve a valid record or error value' >
214
+ : SelectQueryError < 'Processing node failed.' >
215
+ : SelectQueryError < 'Invalid rest nodes array type in ProcessNodes' >
216
+ : SelectQueryError < 'Invalid first node type in ProcessNodes' >
217
+ : Prettify < Acc >
297
218
: Prettify < CheckDuplicateEmbededReference < Schema , RelationName , Relationships , Nodes > >
298
219
299
220
/**
0 commit comments