Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "11.0.0"),
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "12.0.0"),
],
```

Expand Down
2 changes: 1 addition & 1 deletion Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "11.0.0",
"x-sdk-version": "12.0.0",
"x-appwrite-response-format": "1.8.0"
]

Expand Down
146 changes: 144 additions & 2 deletions Sources/Appwrite/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ enum QueryValue: Codable {
case double(Double)
case bool(Bool)
case query(Query)
case array([QueryValue]) // for nested arrays

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
// Attempt to decode each type

if let stringValue = try? container.decode(String.self) {
self = .string(stringValue)
} else if let intValue = try? container.decode(Int.self) {
Expand All @@ -20,8 +21,13 @@ enum QueryValue: Codable {
self = .bool(boolValue)
} else if let queryValue = try? container.decode(Query.self) {
self = .query(queryValue)
} else if let arrayValue = try? container.decode([QueryValue].self) {
self = .array(arrayValue)
} else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "QueryValue cannot be decoded")
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "QueryValue cannot be decoded"
)
}
}

Expand All @@ -38,6 +44,8 @@ enum QueryValue: Codable {
try container.encode(value)
case .query(let value):
try container.encode(value)
case .array(let value):
try container.encode(value)
}
}
}
Expand Down Expand Up @@ -85,6 +93,30 @@ public struct Query : Codable, CustomStringConvertible {
return [.bool(boolValue)]
case let queryValue as Query:
return [.query(queryValue)]
case let anyArray as [Any]:
// Handle nested arrays
let nestedValues = anyArray.compactMap { item -> QueryValue? in
if let stringValue = item as? String {
return .string(stringValue)
} else if let intValue = item as? Int {
return .int(intValue)
} else if let doubleValue = item as? Double {
return .double(doubleValue)
} else if let boolValue = item as? Bool {
return .bool(boolValue)
} else if let queryValue = item as? Query {
return .query(queryValue)
} else if let nestedArray = item as? [Any] {
// Convert nested array to QueryValue.array
if let converted = convertToQueryValueArray(nestedArray) {
return .array(converted)
}
return nil
}
return nil
}
return nestedValues.isEmpty ? nil : nestedValues

default:
return nil
}
Expand Down Expand Up @@ -354,6 +386,13 @@ public struct Query : Codable, CustomStringConvertible {
).description
}

public static func createdBetween(_ start: String, _ end: String) -> String {
return Query(
method: "createdBetween",
values: [start, end]
).description
}

public static func updatedBefore(_ value: String) -> String {
return Query(
method: "updatedBefore",
Expand All @@ -368,6 +407,13 @@ public struct Query : Codable, CustomStringConvertible {
).description
}

public static func updatedBetween(_ start: String, _ end: String) -> String {
return Query(
method: "updatedBetween",
values: [start, end]
).description
}

public static func or(_ queries: [String]) -> String {
let decoder = JSONDecoder()
let decodedQueries = queries.compactMap { queryStr -> Query? in
Expand Down Expand Up @@ -398,6 +444,102 @@ public struct Query : Codable, CustomStringConvertible {
).description
}

public static func distanceEqual(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
return Query(
method: "distanceEqual",
attribute: attribute,
values: [[values, distance, meters]]
).description
}

public static func distanceNotEqual(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
return Query(
method: "distanceNotEqual",
attribute: attribute,
values: [[values, distance, meters]]
).description
}

public static func distanceGreaterThan(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
return Query(
method: "distanceGreaterThan",
attribute: attribute,
values: [[values, distance, meters]]
).description
}

public static func distanceLessThan(_ attribute: String, values: [Any], distance: Double, meters: Bool = true) -> String {
return Query(
method: "distanceLessThan",
attribute: attribute,
values: [[values, distance, meters]]
).description
}

public static func intersects(_ attribute: String, values: [Any]) -> String {
return Query(
method: "intersects",
attribute: attribute,
values: [values]
).description
}

public static func notIntersects(_ attribute: String, values: [Any]) -> String {
return Query(
method: "notIntersects",
attribute: attribute,
values: [values]
).description
}

public static func crosses(_ attribute: String, values: [Any]) -> String {
return Query(
method: "crosses",
attribute: attribute,
values: [values]
).description
}

public static func notCrosses(_ attribute: String, values: [Any]) -> String {
return Query(
method: "notCrosses",
attribute: attribute,
values: [values]
).description
}

public static func overlaps(_ attribute: String, values: [Any]) -> String {
return Query(
method: "overlaps",
attribute: attribute,
values: [values]
).description
}

public static func notOverlaps(_ attribute: String, values: [Any]) -> String {
return Query(
method: "notOverlaps",
attribute: attribute,
values: [values]
).description
}

public static func touches(_ attribute: String, values: [Any]) -> String {
return Query(
method: "touches",
attribute: attribute,
values: [values]
).description
}

public static func notTouches(_ attribute: String, values: [Any]) -> String {
return Query(
method: "notTouches",
attribute: attribute,
values: [values]
).description
}

private static func parseValue(_ value: Any) -> [Any] {
if let value = value as? [Any] {
return value
Expand Down
4 changes: 2 additions & 2 deletions Sources/Appwrite/Services/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ open class Account: Service {
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Session
///
@available(*, deprecated, message: "This API has been deprecated.")
@available(*, deprecated, message: "This API has been deprecated since 1.6.0. Please use `Account.createSession` instead.")
open func updateMagicURLSession(
userId: String,
secret: String
Expand Down Expand Up @@ -1588,7 +1588,7 @@ open class Account: Service {
/// - Throws: Exception if the request fails
/// - Returns: AppwriteModels.Session
///
@available(*, deprecated, message: "This API has been deprecated.")
@available(*, deprecated, message: "This API has been deprecated since 1.6.0. Please use `Account.createSession` instead.")
open func updatePhoneSession(
userId: String,
secret: String
Expand Down
Loading