@@ -6,10 +6,11 @@ enum QueryValue: Codable {
66 case double( Double )
77 case bool( Bool )
88 case query( Query )
9+ case array( [ QueryValue ] ) // for nested arrays
910
1011 init ( from decoder: Decoder ) throws {
1112 let container = try decoder. singleValueContainer ( )
12- // Attempt to decode each type
13+
1314 if let stringValue = try ? container. decode ( String . self) {
1415 self = . string( stringValue)
1516 } else if let intValue = try ? container. decode ( Int . self) {
@@ -20,8 +21,13 @@ enum QueryValue: Codable {
2021 self = . bool( boolValue)
2122 } else if let queryValue = try ? container. decode ( Query . self) {
2223 self = . query( queryValue)
24+ } else if let arrayValue = try ? container. decode ( [ QueryValue ] . self) {
25+ self = . array( arrayValue)
2326 } 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+ )
2531 }
2632 }
2733
@@ -38,6 +44,8 @@ enum QueryValue: Codable {
3844 try container. encode ( value)
3945 case . query( let value) :
4046 try container. encode ( value)
47+ case . array( let value) :
48+ try container. encode ( value)
4149 }
4250 }
4351}
@@ -85,6 +93,30 @@ public struct Query : Codable, CustomStringConvertible {
8593 return [ . bool( boolValue) ]
8694 case let queryValue as Query :
8795 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+
88120 default :
89121 return nil
90122 }
@@ -412,6 +444,102 @@ public struct Query : Codable, CustomStringConvertible {
412444 ) . description
413445 }
414446
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+
415543 private static func parseValue( _ value: Any ) -> [ Any ] {
416544 if let value = value as? [ Any ] {
417545 return value
0 commit comments