-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathExpression.swift
More file actions
1892 lines (1730 loc) · 77.3 KB
/
Expression.swift
File metadata and controls
1892 lines (1730 loc) · 77.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#if SWIFT_PACKAGE
@_exported import FirebaseFirestoreInternalWrapper
#else
@_exported import FirebaseFirestoreInternal
#endif // SWIFT_PACKAGE
import Foundation
public protocol Expression: Sendable {
/// Casts the expression to a `BooleanExpression`.
///
/// - Returns: A `BooleanExpression` representing the same expression.
func asBoolean() -> BooleanExpression
/// Assigns an alias to this expression.
///
/// Aliases are useful for renaming fields in the output of a stage or for giving meaningful
/// names to calculated values.
///
/// ```swift
/// // Calculate total price and alias it "totalPrice"
/// Field("price").multiply(Field("quantity")).as("totalPrice")
/// ```
///
/// - Parameter name: The alias to assign to this expression.
/// - Returns: A new `AliasedExpression` wrapping this expression with the alias.
func `as`(_ name: String) -> AliasedExpression
// --- Added Mathematical Operations ---
/// Creates an expression that returns the value of self rounded to the nearest integer.
///
/// ```swift
/// // Get the value of the "amount" field rounded to the nearest integer.
/// Field("amount").round()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the rounded number.
func round() -> FunctionExpression
/// Creates an expression that returns the square root of self.
///
/// ```swift
/// // Get the square root of the "area" field.
/// Field("area").sqrt()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the square root of the number.
func sqrt() -> FunctionExpression
/// Creates an expression that returns the value of self raised to the power of self.
///
/// Returns zero on underflow.
///
/// ```swift
/// // Get the value of the "amount" field raised to the power of 2.
/// Field("amount").pow(2)
/// ```
///
/// - Parameter exponent: The exponent to raise self to.
/// - Returns: A new `FunctionExpression` representing the power of the number.
func pow(_ exponent: Sendable) -> FunctionExpression
/// Creates an expression that returns the value of self raised to the power of self.
///
/// Returns zero on underflow.
///
/// ```swift
/// // Get the value of the "amount" field raised to the power of the "exponent" field.
/// Field("amount").pow(Field("exponent"))
/// ```
///
/// - Parameter exponent: The exponent to raise self to.
/// - Returns: A new `FunctionExpression` representing the power of the number.
func pow(_ exponent: Expression) -> FunctionExpression
/// Creates an expression that returns the natural logarithm of self.
///
/// ```swift
/// // Get the natural logarithm of the "amount" field.
/// Field("amount").ln()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the natural logarithm of the number.
func ln() -> FunctionExpression
/// Creates an expression that returns the largest numeric value that isn't greater than self.
///
/// ```swift
/// // Get the floor of the "amount" field.
/// Field("amount").floor()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the floor of the number.
func floor() -> FunctionExpression
/// Creates an expression that returns e to the power of self.
///
/// Returns zero on underflow and nil on overflow.
///
/// ```swift
/// // Get the exp of the "amount" field.
/// Field("amount").exp()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the exp of the number.
func exp() -> FunctionExpression
/// Creates an expression that returns the smallest numeric value that isn't less than the number.
///
/// ```swift
/// // Get the ceiling of the "amount" field.
/// Field("amount").ceil()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the ceiling of the number.
func ceil() -> FunctionExpression
/// Creates an expression that returns the absolute value of the number.
///
/// ```swift
/// // Get the absolute value of the "amount" field.
/// Field("amount").abs()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the absolute value of the number.
func abs() -> FunctionExpression
/// Creates an expression that adds another expression to this expression.
/// To add multiple expressions, chain calls to this method.
/// Assumes `self` and the parameter evaluate to compatible types for addition (e.g., numbers, or
/// string/array concatenation if supported by the specific "add" implementation).
///
/// ```swift
/// // Add the value of the "quantity" field and the "reserve" field.
/// Field("quantity").add(Field("reserve"))
///
/// // Add multiple numeric fields
/// Field("subtotal").add(Field("tax")).add(Field("shipping"))
/// ```
///
/// - Parameter value: An `Expression` to add.
/// - Returns: A new `FunctionExpression` representing the addition operation.
func add(_ value: Expression) -> FunctionExpression
/// Creates an expression that adds a literal value to this expression.
/// To add multiple literals, chain calls to this method.
/// Assumes `self` and the parameter evaluate to compatible types for addition.
///
/// ```swift
/// // Add 5 to the "count" field
/// Field("count").add(5)
///
/// // Add multiple literal numbers
/// Field("score").add(10).add(20).add(-5)
/// ```
///
/// - Parameter value: A `Sendable` literal value to add.
/// - Returns: A new `FunctionExpression` representing the addition operation.
func add(_ value: Sendable) -> FunctionExpression
/// Creates an expression that subtracts another expression from this expression.
/// Assumes `self` and `other` evaluate to numeric types.
///
/// ```swift
/// // Subtract the "discount" field from the "price" field
/// Field("price").subtract(Field("discount"))
/// ```
///
/// - Parameter other: The `Expression` (evaluating to a number) to subtract from this expression.
/// - Returns: A new `FunctionExpression` representing the subtraction operation.
func subtract(_ other: Expression) -> FunctionExpression
/// Creates an expression that subtracts a literal value from this expression.
/// Assumes `self` evaluates to a numeric type.
///
/// ```swift
/// // Subtract 20 from the value of the "total" field
/// Field("total").subtract(20)
/// ```
///
/// - Parameter other: The `Sendable` literal (numeric) value to subtract from this expression.
/// - Returns: A new `FunctionExpression` representing the subtraction operation.
func subtract(_ other: Sendable) -> FunctionExpression
/// Creates an expression that multiplies this expression by another expression.
/// To multiply multiple expressions, chain calls to this method.
/// Assumes `self` and the parameter evaluate to numeric types.
///
/// ```swift
/// // Multiply the "quantity" field by the "price" field
/// Field("quantity").multiply(Field("price"))
///
/// // Multiply "rate" by "time" and "conversionFactor" fields
/// Field("rate").multiply(Field("time")).multiply(Field("conversionFactor"))
/// ```
///
/// - Parameter value: An `Expression` to multiply by.
/// - Returns: A new `FunctionExpression` representing the multiplication operation.
func multiply(_ value: Expression) -> FunctionExpression
/// Creates an expression that multiplies this expression by a literal value.
/// To multiply multiple literals, chain calls to this method.
/// Assumes `self` evaluates to a numeric type.
///
/// ```swift
/// // Multiply the "score" by 1.1
/// Field("score").multiply(1.1)
///
/// // Multiply "base" by 2 and then by 3.0
/// Field("base").multiply(2).multiply(3.0)
/// ```
///
/// - Parameter value: A `Sendable` literal value to multiply by.
/// - Returns: A new `FunctionExpression` representing the multiplication operation.
func multiply(_ value: Sendable) -> FunctionExpression
/// Creates an expression that divides this expression by another expression.
/// Assumes `self` and `other` evaluate to numeric types.
///
/// ```swift
/// // Divide the "total" field by the "count" field
/// Field("total").divide(Field("count"))
/// ```
///
/// - Parameter other: The `Expression` (evaluating to a number) to divide by.
/// - Returns: A new `FunctionExpression` representing the division operation.
func divide(_ other: Expression) -> FunctionExpression
/// Creates an expression that divides this expression by a literal value.
/// Assumes `self` evaluates to a numeric type.
///
/// ```swift
/// // Divide the "value" field by 10
/// Field("value").divide(10)
/// ```
///
/// - Parameter other: The `Sendable` literal (numeric) value to divide by.
/// - Returns: A new `FunctionExpression` representing the division operation.
func divide(_ other: Sendable) -> FunctionExpression
/// Creates an expression that calculates the modulo (remainder) of dividing this expression by
/// another expression.
/// Assumes `self` and `other` evaluate to numeric types.
///
/// ```swift
/// // Calculate the remainder of dividing the "value" field by the "divisor" field
/// Field("value").mod(Field("divisor"))
/// ```
///
/// - Parameter other: The `Expression` (evaluating to a number) to use as the divisor.
/// - Returns: A new `FunctionExpression` representing the modulo operation.
func mod(_ other: Expression) -> FunctionExpression
/// Creates an expression that calculates the modulo (remainder) of dividing this expression by a
/// literal value.
/// Assumes `self` evaluates to a numeric type.
///
/// ```swift
/// // Calculate the remainder of dividing the "value" field by 10
/// Field("value").mod(10)
/// ```
///
/// - Parameter other: The `Sendable` literal (numeric) value to use as the divisor.
/// - Returns: A new `FunctionExpression` representing the modulo operation.
func mod(_ other: Sendable) -> FunctionExpression
// --- Added Array Operations ---
/// Creates an expression that returns the `input` with elements in reverse order.
///
/// ```swift
/// // Reverse the "tags" array.
/// Field("tags").arrayReverse()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the reversed array.
func arrayReverse() -> FunctionExpression
/// Creates an expression that concatenates an array expression (from `self`) with one or more
/// other array expressions.
/// Assumes `self` and all parameters evaluate to arrays.
///
/// ```swift
/// // Combine the "items" array with "otherItems" and "archiveItems" array fields.
/// Field("items").arrayConcat(Field("otherItems"), Field("archiveItems"))
/// ```
/// - Parameter arrays: An array of at least one `Expression` (evaluating to an array) to
/// concatenate.
/// - Returns: A new `FunctionExpression` representing the concatenated array.
func arrayConcat(_ arrays: [Expression]) -> FunctionExpression
/// Creates an expression that concatenates an array expression (from `self`) with one or more
/// array literals.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Combine "tags" (an array field) with ["new", "featured"] and ["urgent"]
/// Field("tags").arrayConcat(["new", "featured"], ["urgent"])
/// ```
/// - Parameter arrays: An array of at least one `Sendable` values to concatenate.
/// - Returns: A new `FunctionExpression` representing the concatenated array.
func arrayConcat(_ arrays: [[Sendable]]) -> FunctionExpression
/// Creates an expression that checks if an array (from `self`) contains a specific element
/// expression.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "sizes" contains the value from "selectedSize" field
/// Field("sizes").arrayContains(Field("selectedSize"))
/// ```
///
/// - Parameter element: The `Expression` representing the element to search for in the array.
/// - Returns: A new `BooleanExpr` representing the "array_contains" comparison.
func arrayContains(_ element: Expression) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains a specific literal
/// element.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "colors" array contains "red"
/// Field("colors").arrayContains("red")
/// ```
///
/// - Parameter element: The `Sendable` literal element to search for in the array.
/// - Returns: A new `BooleanExpr` representing the "array_contains" comparison.
func arrayContains(_ element: Sendable) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains all the specified element
/// expressions.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "candidateSkills" contains all skills from "requiredSkill1" and "requiredSkill2"
/// fields
/// Field("candidateSkills").arrayContainsAll([Field("requiredSkill1"), Field("requiredSkill2")])
/// ```
///
/// - Parameter values: A list of `Expression` elements to check for in the array represented
/// by `self`.
/// - Returns: A new `BooleanExpr` representing the "array_contains_all" comparison.
func arrayContainsAll(_ values: [Expression]) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains all the specified literal
/// elements.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "tags" contains both "urgent" and "review"
/// Field("tags").arrayContainsAll(["urgent", "review"])
/// ```
///
/// - Parameter values: An array of at least one `Sendable` element to check for in the array.
/// - Returns: A new `BooleanExpr` representing the "array_contains_all" comparison.
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains all the specified element
/// expressions.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if the "tags" array contains "foo", "bar", and "baz"
/// Field("tags").arrayContainsAll(Constant(["foo", "bar", "baz"]))
/// ```
///
/// - Parameter values: An `Expression` elements evaluated to be array.
/// - Returns: A new `BooleanExpr` representing the "array_contains_all" comparison.
func arrayContainsAll(_ arrayExpression: Expression) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains any of the specified
/// element expressions.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "userGroups" contains any group from "allowedGroup1" or "allowedGroup2" fields
/// Field("userGroups").arrayContainsAny([Field("allowedGroup1"), Field("allowedGroup2")])
/// ```
///
/// - Parameter values: A list of `Expression` elements to check for in the array.
/// - Returns: A new `BooleanExpr` representing the "array_contains_any" comparison.
func arrayContainsAny(_ values: [Expression]) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains any of the specified
/// literal elements.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "categories" contains either "electronics" or "books"
/// Field("categories").arrayContainsAny(["electronics", "books"])
/// ```
///
/// - Parameter values: An array of at least one `Sendable` element to check for in the array.
/// - Returns: A new `BooleanExpr` representing the "array_contains_any" comparison.
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpression
/// Creates an expression that checks if an array (from `self`) contains any of the specified
/// element expressions.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Check if "groups" array contains any of the values from the "userGroup" field
/// Field("groups").arrayContainsAny(Field("userGroup"))
/// ```
///
/// - Parameter arrayExpression: An `Expression` elements evaluated to be array.
/// - Returns: A new `BooleanExpr` representing the "array_contains_any" comparison.
func arrayContainsAny(_ arrayExpression: Expression) -> BooleanExpression
/// Creates an expression that calculates the length of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the number of items in the "cart" array
/// Field("cart").arrayLength()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the length of the array.
func arrayLength() -> FunctionExpression
/// Creates an expression that returns the first element of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the first item in the "tags" array.
/// Field("tags").arrayFirst()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the first element of the array.
func arrayFirst() -> FunctionExpression
/// Creates an expression that returns the first `n` elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the first 3 items in the "tags" array.
/// Field("tags").arrayFirstN(3)
/// ```
///
/// - Parameter n: The number of elements to return.
/// - Returns: A new `FunctionExpression` representing the first `n` elements of the array.
func arrayFirstN(_ n: Int) -> FunctionExpression
/// Creates an expression that returns the first `n` elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the first n items in the "tags" array where n is specified by field "count".
/// Field("tags").arrayFirstN(Field("count"))
/// ```
///
/// - Parameter n: An `Expression` (evaluating to an Int) representing the number of elements to
/// return.
/// - Returns: A new `FunctionExpression` representing the first `n` elements of the array.
func arrayFirstN(_ n: Expression) -> FunctionExpression
/// Creates an expression that returns the last element of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the last item in the "tags" array.
/// Field("tags").arrayLast()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the last element of the array.
func arrayLast() -> FunctionExpression
/// Creates an expression that returns the last `n` elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the last 3 items in the "tags" array.
/// Field("tags").arrayLastN(3)
/// ```
///
/// - Parameter n: The number of elements to return.
/// - Returns: A new `FunctionExpression` representing the last `n` elements of the array.
func arrayLastN(_ n: Int) -> FunctionExpression
/// Creates an expression that returns the last `n` elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the last n items in the "tags" array where n is specified by field "count".
/// Field("tags").arrayLastN(Field("count"))
/// ```
///
/// - Parameter n: An `Expression` (evaluating to an Int) representing the number of elements to
/// return.
/// - Returns: A new `FunctionExpression` representing the last `n` elements of the array.
func arrayLastN(_ n: Expression) -> FunctionExpression
/// Creates an expression that accesses an element in an array (from `self`) at the specified
/// integer offset.
/// A negative offset starts from the end. If the offset is out of bounds, an error may be
/// returned during evaluation.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Return the value in the "tags" field array at index 1.
/// Field("tags").arrayGet(1)
/// // Return the last element in the "tags" field array.
/// Field("tags").arrayGet(-1)
/// ```
///
/// - Parameter offset: The literal `Int` offset of the element to return.
/// - Returns: A new `FunctionExpression` representing the "arrayGet" operation.
func arrayGet(_ offset: Int) -> FunctionExpression
/// Creates an expression that accesses an element in an array (from `self`) at the offset
/// specified by an expression.
/// A negative offset starts from the end. If the offset is out of bounds, an error may be
/// returned during evaluation.
/// Assumes `self` evaluates to an array and `offsetExpr` evaluates to an integer.
///
/// ```swift
/// // Return the value in the tags field array at index specified by field "favoriteTagIndex".
/// Field("tags").arrayGet(Field("favoriteTagIndex"))
/// ```
///
/// - Parameter offsetExpression: An `Expression` (evaluating to an Int) representing the offset
/// of the
/// element to return.
/// - Returns: A new `FunctionExpression` representing the "arrayGet" operation.
func arrayGet(_ offsetExpression: Expression) -> FunctionExpression
/// Creates an expression that returns the index of the first occurrence of a value in an array.
/// Returns nil if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the index of "urgent" in the "tags" array.
/// Field("tags").arrayIndexOf("urgent")
/// ```
///
/// - Parameter value: The literal `Sendable` value to search for.
/// - Returns: A new `FunctionExpression` representing the index of the value.
func arrayIndexOf(_ value: Sendable) -> FunctionExpression
/// Creates an expression that returns the index of the first occurrence of a value in an array.
/// Returns nil if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the index of the value of field "searchTag" in the "tags" array.
/// Field("tags").arrayIndexOf(Field("searchTag"))
/// ```
///
/// - Parameter value: An `Expression` representing the value to search for.
/// - Returns: A new `FunctionExpression` representing the index of the value.
func arrayIndexOf(_ value: Expression) -> FunctionExpression
/// Creates an expression that returns the index of the last occurrence of a value in an array.
/// Returns nil if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the last index of "urgent" in the "tags" array.
/// Field("tags").arrayLastIndexOf("urgent")
/// ```
///
/// - Parameter value: The literal `Sendable` value to search for.
/// - Returns: A new `FunctionExpression` representing the last index of the value.
func arrayLastIndexOf(_ value: Sendable) -> FunctionExpression
/// Creates an expression that returns the index of the last occurrence of a value in an array.
/// Returns nil if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the last index of the value of field "searchTag" in the "tags" array.
/// Field("tags").arrayLastIndexOf(Field("searchTag"))
/// ```
///
/// - Parameter value: An `Expression` representing the value to search for.
/// - Returns: A new `FunctionExpression` representing the last index of the value.
func arrayLastIndexOf(_ value: Expression) -> FunctionExpression
/// Creates an expression that returns all indices of a value in an array.
/// Returns an empty array if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get all indices of "urgent" in the "tags" array.
/// Field("tags").arrayIndexOfAll("urgent")
/// ```
///
/// - Parameter value: The literal `Sendable` value to search for.
/// - Returns: A new `FunctionExpression` representing the indices of the value.
func arrayIndexOfAll(_ value: Sendable) -> FunctionExpression
/// Creates an expression that returns all indices of a value in an array.
/// Returns an empty array if the value is not found.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get all indices of the value of field "searchTag" in the "tags" array.
/// Field("tags").arrayIndexOfAll(Field("searchTag"))
/// ```
///
/// - Parameter value: An `Expression` representing the value to search for.
/// - Returns: A new `FunctionExpression` representing the indices of the value.
func arrayIndexOfAll(_ value: Expression) -> FunctionExpression
/// Creates an expression that returns the maximum element of an array.
///
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the maximum value in the "scores" array.
/// Field("scores").arrayMaximum()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the maximum element of the array.
func arrayMaximum() -> FunctionExpression
/// Creates an expression that returns the minimum element of an array.
///
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the minimum value in the "scores" array.
/// Field("scores").arrayMinimum()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the minimum element of the array.
func arrayMinimum() -> FunctionExpression
/// Creates an expression that returns the `n` smallest elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the 3 lowest scores in the "scores" array.
/// Field("scores").arrayMinimumN(3)
/// ```
///
/// - Parameter n: The number of elements to return.
/// - Returns: A new `FunctionExpression` representing the `n` smallest elements of the array.
func arrayMinimumN(_ n: Int) -> FunctionExpression
/// Creates an expression that returns the `n` smallest elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the n lowest scores in the "scores" array where n is specified by field "count".
/// Field("scores").arrayMinimumN(Field("count"))
/// ```
///
/// - Parameter n: An `Expression` (evaluating to an Int) representing the number of elements to
/// return.
/// - Returns: A new `FunctionExpression` representing the `n` smallest elements of the array.
func arrayMinimumN(_ n: Expression) -> FunctionExpression
/// Creates an expression that returns the `n` largest elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the 3 highest scores in the "scores" array.
/// Field("scores").arrayMaximumN(3)
/// ```
///
/// - Parameter n: The number of elements to return.
/// - Returns: A new `FunctionExpression` representing the `n` largest elements of the array.
func arrayMaximumN(_ n: Int) -> FunctionExpression
/// Creates an expression that returns the `n` largest elements of an array.
/// Assumes `self` evaluates to an array.
///
/// ```swift
/// // Get the n highest scores in the "scores" array where n is specified by field "count".
/// Field("scores").arrayMaximumN(Field("count"))
/// ```
///
/// - Parameter n: An `Expression` (evaluating to an Int) representing the number of elements to
/// return.
/// - Returns: A new `FunctionExpression` representing the `n` largest elements of the array.
func arrayMaximumN(_ n: Expression) -> FunctionExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is greater
/// than the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func greaterThan(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is greater
/// than the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func greaterThan(_ other: Sendable) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is
/// greater than or equal to the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func greaterThanOrEqual(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is
/// greater than or equal to the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func greaterThanOrEqual(_ other: Sendable) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is less
/// than the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func lessThan(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is less
/// than the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func lessThan(_ other: Sendable) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is less
/// than or equal to the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func lessThanOrEqual(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is less
/// than or equal to the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func lessThanOrEqual(_ other: Sendable) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is equal
/// to the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func equal(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is equal
/// to the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func equal(_ other: Sendable) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is not
/// equal to the given expression.
///
/// - Parameter other: The expression to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func notEqual(_ other: Expression) -> BooleanExpression
/// Creates a `BooleanExpression` that returns `true` if this expression is not
/// equal to the given value.
///
/// - Parameter other: The value to compare against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func notEqual(_ other: Sendable) -> BooleanExpression
/// Creates an expression that checks if this expression is equal to any of the provided
/// expression values.
///
/// ```swift
/// // Check if "categoryID" field is equal to "featuredCategory" or "popularCategory" fields
/// Field("categoryID").equalAny([Field("featuredCategory"), Field("popularCategory")])
/// ```
///
/// - Parameter others: An array of at least one `Expression` value to check against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func equalAny(_ others: [Expression]) -> BooleanExpression
/// Creates an expression that checks if this expression is equal to any of the provided literal
/// values.
///
/// ```swift
/// // Check if "category" is "Electronics", "Books", or "Home Goods"
/// Field("category").equalAny(["Electronics", "Books", "Home Goods"])
/// ```
///
/// - Parameter others: An array of at least one `Sendable` literal value to check against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func equalAny(_ others: [Sendable]) -> BooleanExpression
/// Creates an expression that checks if this expression is equal to any of the provided
/// expression values.
///
/// ```swift
/// // Check if "categoryID" field is equal to any of "categoryIDs" fields
/// Field("categoryID").equalAny(Field("categoryIDs"))
/// ```
///
/// - Parameter arrayExpression: An `Expression` elements evaluated to be array.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func equalAny(_ arrayExpression: Expression) -> BooleanExpression
/// Creates an expression that checks if this expression is not equal to any of the provided
/// expression values.
///
/// ```swift
/// // Check if "statusValue" is not equal to "archivedStatus" or "deletedStatus" fields
/// Field("statusValue").notEqualAny([Field("archivedStatus"), Field("deletedStatus")])
/// ```
///
/// - Parameter others: An array of at least one `Expression` value to check against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func notEqualAny(_ others: [Expression]) -> BooleanExpression
/// Creates an expression that checks if this expression is not equal to any of the provided
/// literal values.
///
/// ```swift
/// // Check if "status" is neither "pending" nor "archived"
/// Field("status").notEqualAny(["pending", "archived"])
/// ```
///
/// - Parameter others: An array of at least one `Sendable` literal value to check against.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func notEqualAny(_ others: [Sendable]) -> BooleanExpression
/// Creates an expression that checks if this expression is equal to any of the provided
/// expression values.
///
/// ```swift
/// // Check if "categoryID" field is not equal to any of "categoryIDs" fields
/// Field("categoryID").equalAny(Field("categoryIDs"))
/// ```
///
/// - Parameter arrayExpression: An `Expression` elements evaluated to be array.
/// - Returns: A `BooleanExpression` that can be used in a where stage, together with other
/// boolean expressions.
func notEqualAny(_ arrayExpression: Expression) -> BooleanExpression
/// Creates an expression that checks if a field exists in the document.
///
/// ```swift
/// // Check if the document has a field named "phoneNumber"
/// Field("phoneNumber").exists()
/// ```
///
/// - Returns: A new `BooleanExpression` representing the "exists" check.
func exists() -> BooleanExpression
/// Creates an expression that checks if this expression produces an error during evaluation.
///
/// ```swift
/// // Check if accessing a non-existent array index causes an error
/// Field("myArray").arrayGet(100).isError()
/// ```
///
/// - Returns: A new `BooleanExpression` representing the "isError" check.
func isError() -> BooleanExpression
/// Creates an expression that returns `true` if the result of this expression
/// is absent (e.g., a field does not exist in a map). Otherwise, returns `false`.
///
/// ```swift
/// // Check if the field `value` is absent.
/// Field("value").isAbsent()
/// ```
///
/// - Returns: A new `BooleanExpression` representing the "isAbsent" check.
func isAbsent() -> BooleanExpression
// MARK: String Operations
/// Creates an expression that joins the elements of an array of strings with a given separator.
///
/// Assumes `self` evaluates to an array of strings.
///
/// ```swift
/// // Join the "tags" array with a ", " separator.
/// Field("tags").join(separator: ", ")
/// ```
///
/// - Parameter delimiter: The string to use as a delimiter.
/// - Returns: A new `FunctionExpression` representing the joined string.
func join(delimiter: String) -> FunctionExpression
/// Creates an expression that splits a string into an array of substrings based on a delimiter.
///
/// - Parameter delimiter: The string to split on.
/// - Returns: A new `FunctionExpression` representing the array of substrings.
func split(delimiter: String) -> FunctionExpression
/// Creates an expression that splits a string into an array of substrings based on a delimiter.
///
/// - Parameter delimiter: An expression that evaluates to a string or bytes to split on.
/// - Returns: A new `FunctionExpression` representing the array of substrings.
func split(delimiter: Expression) -> FunctionExpression
/// Creates an expression that returns the length of a string.
///
/// ```swift
/// // Get the length of the "name" field.
/// Field("name").length()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the length of the string.
func length() -> FunctionExpression
/// Creates an expression that calculates the character length of a string in UTF-8.
/// Assumes `self` evaluates to a string.
///
/// ```swift
/// // Get the character length of the "name" field in its UTF-8 form.
/// Field("name").charLength()
/// ```
///
/// - Returns: A new `FunctionExpression` representing the length of the string.
func charLength() -> FunctionExpression
/// Creates an expression that performs a case-sensitive string comparison using wildcards against
/// a literal pattern.
/// Assumes `self` evaluates to a string.
///
/// ```swift
/// // Check if the "title" field contains the word "guide" (case-sensitive)
/// Field("title").like("%guide%")
/// ```
///
/// - Parameter pattern: The literal string pattern to search for. Use "%" as a wildcard.
/// - Returns: A new `BooleanExpression` representing the "like" comparison.
func like(_ pattern: String) -> BooleanExpression
/// Creates an expression that performs a case-sensitive string comparison using wildcards against
/// an expression pattern.
/// Assumes `self` evaluates to a string, and `pattern` evaluates to a string.
///
/// ```swift
/// // Check if "filename" matches a pattern stored in "patternField"
/// Field("filename").like(Field("patternField"))
/// ```
///
/// - Parameter pattern: An `Expression` (evaluating to a string) representing the pattern to
/// search for.
/// - Returns: A new `BooleanExpression` representing the "like" comparison.
func like(_ pattern: Expression) -> BooleanExpression
/// Creates an expression that checks if a string (from `self`) contains a specified regular
/// expression literal as a substring.
/// Assumes `self` evaluates to a string.
///
/// ```swift
/// // Check if "description" contains "example" (case-insensitive)
/// Field("description").regexContains("(?i)example")
/// ```
///
/// - Parameter pattern: The literal string regular expression to use for the search.
/// - Returns: A new `BooleanExpression` representing the "regex_contains" comparison.
func regexContains(_ pattern: String) -> BooleanExpression
/// Creates an expression that checks if a string (from `self`) contains a specified regular
/// expression (from an expression) as a substring.
/// Assumes `self` evaluates to a string, and `pattern` evaluates to a string.
///
/// ```swift
/// // Check if "logEntry" contains a pattern from "errorPattern" field
/// Field("logEntry").regexContains(Field("errorPattern"))
/// ```
///
/// - Parameter pattern: An `Expression` (evaluating to a string) representing the regular
/// expression to use for the search.
/// - Returns: A new `BooleanExpression` representing the "regex_contains" comparison.
func regexContains(_ pattern: Expression) -> BooleanExpression
/// Creates an expression that returns the first substring of a string expression that matches