@@ -6,10 +6,11 @@ enum QueryValue: Codable {
6
6
case double( Double )
7
7
case bool( Bool )
8
8
case query( Query )
9
+ case array( [ QueryValue ] ) // for nested arrays
9
10
10
11
init ( from decoder: Decoder ) throws {
11
12
let container = try decoder. singleValueContainer ( )
12
- // Attempt to decode each type
13
+
13
14
if let stringValue = try ? container. decode ( String . self) {
14
15
self = . string( stringValue)
15
16
} else if let intValue = try ? container. decode ( Int . self) {
@@ -20,8 +21,13 @@ enum QueryValue: Codable {
20
21
self = . bool( boolValue)
21
22
} else if let queryValue = try ? container. decode ( Query . self) {
22
23
self = . query( queryValue)
24
+ } else if let arrayValue = try ? container. decode ( [ QueryValue ] . self) {
25
+ self = . array( arrayValue)
23
26
} else {
24
- throw DecodingError . dataCorruptedError ( in: container, debugDescription: " QueryValue cannot be decoded " )
27
+ throw DecodingError . dataCorruptedError (
28
+ in: container,
29
+ debugDescription: " QueryValue cannot be decoded "
30
+ )
25
31
}
26
32
}
27
33
@@ -38,6 +44,8 @@ enum QueryValue: Codable {
38
44
try container. encode ( value)
39
45
case . query( let value) :
40
46
try container. encode ( value)
47
+ case . array( let value) :
48
+ try container. encode ( value)
41
49
}
42
50
}
43
51
}
@@ -85,6 +93,30 @@ public struct Query : Codable, CustomStringConvertible {
85
93
return [ . bool( boolValue) ]
86
94
case let queryValue as Query :
87
95
return [ . query( queryValue) ]
96
+ case let anyArray as [ Any ] :
97
+ // Handle nested arrays
98
+ let nestedValues = anyArray. compactMap { item -> QueryValue ? in
99
+ if let stringValue = item as? String {
100
+ return . string( stringValue)
101
+ } else if let intValue = item as? Int {
102
+ return . int( intValue)
103
+ } else if let doubleValue = item as? Double {
104
+ return . double( doubleValue)
105
+ } else if let boolValue = item as? Bool {
106
+ return . bool( boolValue)
107
+ } else if let queryValue = item as? Query {
108
+ return . query( queryValue)
109
+ } else if let nestedArray = item as? [ Any ] {
110
+ // Convert nested array to QueryValue.array
111
+ if let converted = convertToQueryValueArray ( nestedArray) {
112
+ return . array( converted)
113
+ }
114
+ return nil
115
+ }
116
+ return nil
117
+ }
118
+ return nestedValues. isEmpty ? nil : nestedValues
119
+
88
120
default :
89
121
return nil
90
122
}
@@ -354,6 +386,13 @@ public struct Query : Codable, CustomStringConvertible {
354
386
) . description
355
387
}
356
388
389
+ public static func createdBetween( _ start: String , _ end: String ) -> String {
390
+ return Query (
391
+ method: " createdBetween " ,
392
+ values: [ start, end]
393
+ ) . description
394
+ }
395
+
357
396
public static func updatedBefore( _ value: String ) -> String {
358
397
return Query (
359
398
method: " updatedBefore " ,
@@ -368,6 +407,13 @@ public struct Query : Codable, CustomStringConvertible {
368
407
) . description
369
408
}
370
409
410
+ public static func updatedBetween( _ start: String , _ end: String ) -> String {
411
+ return Query (
412
+ method: " updatedBetween " ,
413
+ values: [ start, end]
414
+ ) . description
415
+ }
416
+
371
417
public static func or( _ queries: [ String ] ) -> String {
372
418
let decoder = JSONDecoder ( )
373
419
let decodedQueries = queries. compactMap { queryStr -> Query ? in
@@ -398,6 +444,102 @@ public struct Query : Codable, CustomStringConvertible {
398
444
) . description
399
445
}
400
446
447
+ public static func distanceEqual( _ attribute: String , values: [ Any ] , distance: Double , meters: Bool = true ) -> String {
448
+ return Query (
449
+ method: " distanceEqual " ,
450
+ attribute: attribute,
451
+ values: [ [ values, distance, meters] ]
452
+ ) . description
453
+ }
454
+
455
+ public static func distanceNotEqual( _ attribute: String , values: [ Any ] , distance: Double , meters: Bool = true ) -> String {
456
+ return Query (
457
+ method: " distanceNotEqual " ,
458
+ attribute: attribute,
459
+ values: [ [ values, distance, meters] ]
460
+ ) . description
461
+ }
462
+
463
+ public static func distanceGreaterThan( _ attribute: String , values: [ Any ] , distance: Double , meters: Bool = true ) -> String {
464
+ return Query (
465
+ method: " distanceGreaterThan " ,
466
+ attribute: attribute,
467
+ values: [ [ values, distance, meters] ]
468
+ ) . description
469
+ }
470
+
471
+ public static func distanceLessThan( _ attribute: String , values: [ Any ] , distance: Double , meters: Bool = true ) -> String {
472
+ return Query (
473
+ method: " distanceLessThan " ,
474
+ attribute: attribute,
475
+ values: [ [ values, distance, meters] ]
476
+ ) . description
477
+ }
478
+
479
+ public static func intersects( _ attribute: String , values: [ Any ] ) -> String {
480
+ return Query (
481
+ method: " intersects " ,
482
+ attribute: attribute,
483
+ values: [ values]
484
+ ) . description
485
+ }
486
+
487
+ public static func notIntersects( _ attribute: String , values: [ Any ] ) -> String {
488
+ return Query (
489
+ method: " notIntersects " ,
490
+ attribute: attribute,
491
+ values: [ values]
492
+ ) . description
493
+ }
494
+
495
+ public static func crosses( _ attribute: String , values: [ Any ] ) -> String {
496
+ return Query (
497
+ method: " crosses " ,
498
+ attribute: attribute,
499
+ values: [ values]
500
+ ) . description
501
+ }
502
+
503
+ public static func notCrosses( _ attribute: String , values: [ Any ] ) -> String {
504
+ return Query (
505
+ method: " notCrosses " ,
506
+ attribute: attribute,
507
+ values: [ values]
508
+ ) . description
509
+ }
510
+
511
+ public static func overlaps( _ attribute: String , values: [ Any ] ) -> String {
512
+ return Query (
513
+ method: " overlaps " ,
514
+ attribute: attribute,
515
+ values: [ values]
516
+ ) . description
517
+ }
518
+
519
+ public static func notOverlaps( _ attribute: String , values: [ Any ] ) -> String {
520
+ return Query (
521
+ method: " notOverlaps " ,
522
+ attribute: attribute,
523
+ values: [ values]
524
+ ) . description
525
+ }
526
+
527
+ public static func touches( _ attribute: String , values: [ Any ] ) -> String {
528
+ return Query (
529
+ method: " touches " ,
530
+ attribute: attribute,
531
+ values: [ values]
532
+ ) . description
533
+ }
534
+
535
+ public static func notTouches( _ attribute: String , values: [ Any ] ) -> String {
536
+ return Query (
537
+ method: " notTouches " ,
538
+ attribute: attribute,
539
+ values: [ values]
540
+ ) . description
541
+ }
542
+
401
543
private static func parseValue( _ value: Any ) -> [ Any ] {
402
544
if let value = value as? [ Any ] {
403
545
return value
0 commit comments