@@ -8,60 +8,68 @@ import type { Ref } from "./types.js"
8
8
type ExpressionLike = BasicExpression | RefProxy < any > | Ref < any > | any
9
9
10
10
// Helper type to extract the underlying type from various expression types
11
- type ExtractType < T > =
12
- T extends RefProxy < infer U > ? U
13
- : T extends Ref < infer U > ? U
14
- : T extends BasicExpression < infer U > ? U
15
- : T extends undefined ? undefined
16
- : T extends null ? null
17
- : T
11
+ type ExtractType < T > =
12
+ T extends RefProxy < infer U >
13
+ ? U
14
+ : T extends Ref < infer U >
15
+ ? U
16
+ : T extends BasicExpression < infer U >
17
+ ? U
18
+ : T extends undefined
19
+ ? undefined
20
+ : T extends null
21
+ ? null
22
+ : T
18
23
19
24
// Helper type to determine aggregate return type based on input nullability
20
- type AggregateReturnType < T > = ExtractType < T > extends infer U
21
- ? U extends number | undefined | null
22
- ? Aggregate < U >
23
- : U extends number
24
- ? Aggregate < number >
25
- : Aggregate < number | undefined | null >
26
- : Aggregate < number | undefined | null >
25
+ type AggregateReturnType < T > =
26
+ ExtractType < T > extends infer U
27
+ ? U extends number | undefined | null
28
+ ? Aggregate < U >
29
+ : U extends number
30
+ ? Aggregate < number >
31
+ : Aggregate < number | undefined | null >
32
+ : Aggregate < number | undefined | null >
27
33
28
34
// Helper type to determine string function return type based on input nullability
29
- type StringFunctionReturnType < T > = ExtractType < T > extends infer U
30
- ? U extends string | undefined | null
31
- ? BasicExpression < U >
32
- : U extends string
33
- ? BasicExpression < string >
34
- : BasicExpression < string | undefined | null >
35
- : BasicExpression < string | undefined | null >
36
-
37
- // Helper type to determine numeric function return type based on input nullability
38
- // This handles string, array, and number inputs for functions like length()
39
- type NumericFunctionReturnType < T > = ExtractType < T > extends infer U
40
- ? U extends string
41
- ? BasicExpression < number >
42
- : U extends string | undefined
43
- ? BasicExpression < number | undefined >
44
- : U extends string | null
45
- ? BasicExpression < number | null >
46
- : U extends string | undefined | null
47
- ? BasicExpression < number | undefined | null >
48
- : U extends Array < any >
49
- ? BasicExpression < number >
50
- : U extends Array < any > | undefined
51
- ? BasicExpression < number | undefined >
52
- : U extends Array < any > | null
53
- ? BasicExpression < number | null >
54
- : U extends Array < any > | undefined | null
55
- ? BasicExpression < number | undefined | null >
56
- : U extends number | undefined | null
35
+ type StringFunctionReturnType < T > =
36
+ ExtractType < T > extends infer U
37
+ ? U extends string | undefined | null
57
38
? BasicExpression < U >
58
- : U extends number
39
+ : U extends string
40
+ ? BasicExpression < string >
41
+ : BasicExpression < string | undefined | null >
42
+ : BasicExpression < string | undefined | null >
43
+
44
+ // Helper type to determine numeric function return type based on input nullability
45
+ // This handles string, array, and number inputs for functions like length()
46
+ type NumericFunctionReturnType < T > =
47
+ ExtractType < T > extends infer U
48
+ ? U extends string
59
49
? BasicExpression < number >
60
- : BasicExpression < number | undefined | null >
61
- : BasicExpression < number | undefined | null >
50
+ : U extends string | undefined
51
+ ? BasicExpression < number | undefined >
52
+ : U extends string | null
53
+ ? BasicExpression < number | null >
54
+ : U extends string | undefined | null
55
+ ? BasicExpression < number | undefined | null >
56
+ : U extends Array < any >
57
+ ? BasicExpression < number >
58
+ : U extends Array < any > | undefined
59
+ ? BasicExpression < number | undefined >
60
+ : U extends Array < any > | null
61
+ ? BasicExpression < number | null >
62
+ : U extends Array < any > | undefined | null
63
+ ? BasicExpression < number | undefined | null >
64
+ : U extends number | undefined | null
65
+ ? BasicExpression < U >
66
+ : U extends number
67
+ ? BasicExpression < number >
68
+ : BasicExpression < number | undefined | null >
69
+ : BasicExpression < number | undefined | null >
62
70
63
71
// Helper type for binary numeric operations (combines nullability of both operands)
64
- type BinaryNumericReturnType < T1 , T2 > =
72
+ type BinaryNumericReturnType < T1 , T2 > =
65
73
ExtractType < T1 > extends infer U1
66
74
? ExtractType < T2 > extends infer U2
67
75
? U1 extends number
@@ -206,7 +214,9 @@ export function isUndefined(value: ExpressionLike): BasicExpression<boolean> {
206
214
return new Func ( `isUndefined` , [ toExpression ( value ) ] )
207
215
}
208
216
209
- export function isNotUndefined ( value : ExpressionLike ) : BasicExpression < boolean > {
217
+ export function isNotUndefined (
218
+ value : ExpressionLike
219
+ ) : BasicExpression < boolean > {
210
220
return new Func ( `isNotUndefined` , [ toExpression ( value ) ] )
211
221
}
212
222
@@ -231,17 +241,21 @@ export function like(
231
241
| RefProxy < string | null >
232
242
| RefProxy < string | undefined >
233
243
| string
234
- | string | null
235
- | string | undefined
244
+ | string
245
+ | null
246
+ | string
247
+ | undefined
236
248
| BasicExpression < string >
237
249
| BasicExpression < string | null >
238
250
| BasicExpression < string | undefined >
239
251
| null
240
252
| undefined ,
241
253
right :
242
254
| string
243
- | string | null
244
- | string | undefined
255
+ | string
256
+ | null
257
+ | string
258
+ | undefined
245
259
| RefProxy < string >
246
260
| RefProxy < string | null >
247
261
| RefProxy < string | undefined >
@@ -261,17 +275,21 @@ export function ilike(
261
275
| RefProxy < string | null >
262
276
| RefProxy < string | undefined >
263
277
| string
264
- | string | null
265
- | string | undefined
278
+ | string
279
+ | null
280
+ | string
281
+ | undefined
266
282
| BasicExpression < string >
267
283
| BasicExpression < string | null >
268
284
| BasicExpression < string | undefined >
269
285
| null
270
286
| undefined ,
271
287
right :
272
288
| string
273
- | string | null
274
- | string | undefined
289
+ | string
290
+ | null
291
+ | string
292
+ | undefined
275
293
| RefProxy < string >
276
294
| RefProxy < string | null >
277
295
| RefProxy < string | undefined >
@@ -286,15 +304,21 @@ export function ilike(
286
304
287
305
// Functions
288
306
289
- export function upper < T extends ExpressionLike > ( arg : T ) : StringFunctionReturnType < T > {
307
+ export function upper < T extends ExpressionLike > (
308
+ arg : T
309
+ ) : StringFunctionReturnType < T > {
290
310
return new Func ( `upper` , [ toExpression ( arg ) ] ) as StringFunctionReturnType < T >
291
311
}
292
312
293
- export function lower < T extends ExpressionLike > ( arg : T ) : StringFunctionReturnType < T > {
313
+ export function lower < T extends ExpressionLike > (
314
+ arg : T
315
+ ) : StringFunctionReturnType < T > {
294
316
return new Func ( `lower` , [ toExpression ( arg ) ] ) as StringFunctionReturnType < T >
295
317
}
296
318
297
- export function length < T extends ExpressionLike > ( arg : T ) : NumericFunctionReturnType < T > {
319
+ export function length < T extends ExpressionLike > (
320
+ arg : T
321
+ ) : NumericFunctionReturnType < T > {
298
322
return new Func ( `length` , [ toExpression ( arg ) ] ) as NumericFunctionReturnType < T >
299
323
}
300
324
@@ -318,7 +342,10 @@ export function add<T1 extends ExpressionLike, T2 extends ExpressionLike>(
318
342
left : T1 ,
319
343
right : T2
320
344
) : BinaryNumericReturnType < T1 , T2 > {
321
- return new Func ( `add` , [ toExpression ( left ) , toExpression ( right ) ] ) as BinaryNumericReturnType < T1 , T2 >
345
+ return new Func ( `add` , [
346
+ toExpression ( left ) ,
347
+ toExpression ( right ) ,
348
+ ] ) as BinaryNumericReturnType < T1 , T2 >
322
349
}
323
350
324
351
// Aggregates
0 commit comments