From 573eb00ccdc8923fcba740bee8bf0e1948b56bff Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 5 Sep 2025 01:32:44 +1200 Subject: [PATCH 1/6] Add time between queries --- README.md | 2 +- Sources/Appwrite/Client.swift | 2 +- Sources/Appwrite/Query.swift | 14 + Sources/Appwrite/Services/Account.swift | 4 +- Sources/Appwrite/Services/Databases.swift | 296 +++++++++++++++++- Sources/Appwrite/Services/TablesDb.swift | 288 +++++++++++++++++ Sources/AppwriteEnums/CreditCard.swift | 2 +- Sources/AppwriteEnums/ExecutionMethod.swift | 1 + Sources/AppwriteEnums/IndexType.swift | 1 + Sources/AppwriteModels/AttributeLine.swift | 124 ++++++++ Sources/AppwriteModels/AttributePoint.swift | 124 ++++++++ Sources/AppwriteModels/AttributePolygon.swift | 124 ++++++++ Sources/AppwriteModels/ColumnLine.swift | 124 ++++++++ Sources/AppwriteModels/ColumnPoint.swift | 124 ++++++++ Sources/AppwriteModels/ColumnPolygon.swift | 124 ++++++++ .../databases/create-line-attribute.md | 17 + .../databases/create-point-attribute.md | 17 + .../databases/create-polygon-attribute.md | 17 + .../databases/update-line-attribute.md | 18 ++ .../databases/update-point-attribute.md | 18 ++ .../databases/update-polygon-attribute.md | 18 ++ docs/examples/tablesdb/create-line-column.md | 17 + docs/examples/tablesdb/create-point-column.md | 17 + .../tablesdb/create-polygon-column.md | 17 + docs/examples/tablesdb/update-line-column.md | 18 ++ docs/examples/tablesdb/update-point-column.md | 18 ++ .../tablesdb/update-polygon-column.md | 18 ++ 27 files changed, 1558 insertions(+), 6 deletions(-) create mode 100644 Sources/AppwriteModels/AttributeLine.swift create mode 100644 Sources/AppwriteModels/AttributePoint.swift create mode 100644 Sources/AppwriteModels/AttributePolygon.swift create mode 100644 Sources/AppwriteModels/ColumnLine.swift create mode 100644 Sources/AppwriteModels/ColumnPoint.swift create mode 100644 Sources/AppwriteModels/ColumnPolygon.swift create mode 100644 docs/examples/databases/create-line-attribute.md create mode 100644 docs/examples/databases/create-point-attribute.md create mode 100644 docs/examples/databases/create-polygon-attribute.md create mode 100644 docs/examples/databases/update-line-attribute.md create mode 100644 docs/examples/databases/update-point-attribute.md create mode 100644 docs/examples/databases/update-polygon-attribute.md create mode 100644 docs/examples/tablesdb/create-line-column.md create mode 100644 docs/examples/tablesdb/create-point-column.md create mode 100644 docs/examples/tablesdb/create-polygon-column.md create mode 100644 docs/examples/tablesdb/update-line-column.md create mode 100644 docs/examples/tablesdb/update-point-column.md create mode 100644 docs/examples/tablesdb/update-polygon-column.md diff --git a/README.md b/README.md index 5655f98..9e1c1f9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "11.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "11.1.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 1eb5a93..5d3b660 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -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": "11.1.0", "x-appwrite-response-format": "1.8.0" ] diff --git a/Sources/Appwrite/Query.swift b/Sources/Appwrite/Query.swift index 1956cdd..f811973 100644 --- a/Sources/Appwrite/Query.swift +++ b/Sources/Appwrite/Query.swift @@ -354,6 +354,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", @@ -368,6 +375,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 diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index b68ba76..2505dd3 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -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 @@ -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 diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 12e0c8a..08b55c1 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -56,7 +56,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Database /// - @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createDatabase` instead.") + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.create` instead.") open func create( databaseId: String, name: String, @@ -1191,6 +1191,300 @@ open class Databases: Service { ) } + /// + /// Create a geometric line attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributeLine + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createLineColumn` instead.") + open func createLineAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.AttributeLine { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/line" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributeLine = { response in + return AppwriteModels.AttributeLine.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a line attribute. Changing the `default` value will not update + /// already existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributeLine + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateLineColumn` instead.") + open func updateLineAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.AttributeLine { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/line/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributeLine = { response in + return AppwriteModels.AttributeLine.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a geometric 2d point attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributePoint + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createPointColumn` instead.") + open func createPointAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.AttributePoint { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/point" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributePoint = { response in + return AppwriteModels.AttributePoint.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a point attribute. Changing the `default` value will not update + /// already existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributePoint + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updatePointColumn` instead.") + open func updatePointAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.AttributePoint { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/point/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributePoint = { response in + return AppwriteModels.AttributePoint.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a geometric polygon attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributePolygon + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createPolygonColumn` instead.") + open func createPolygonAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.AttributePolygon { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/polygon" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributePolygon = { response in + return AppwriteModels.AttributePolygon.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a polygon attribute. Changing the `default` value will not update + /// already existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - collectionId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.AttributePolygon + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updatePolygonColumn` instead.") + open func updatePolygonAttribute( + databaseId: String, + collectionId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.AttributePolygon { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/polygon/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.AttributePolygon = { response in + return AppwriteModels.AttributePolygon.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Create relationship attribute. [Learn more about relationship /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). diff --git a/Sources/Appwrite/Services/TablesDb.swift b/Sources/Appwrite/Services/TablesDb.swift index e1c3790..5bb1a46 100644 --- a/Sources/Appwrite/Services/TablesDb.swift +++ b/Sources/Appwrite/Services/TablesDb.swift @@ -1165,6 +1165,294 @@ open class TablesDB: Service { ) } + /// + /// Create a geometric line attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnLine + /// + open func createLineColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.ColumnLine { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/line" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnLine = { response in + return AppwriteModels.ColumnLine.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a line column. Changing the `default` value will not update already + /// existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnLine + /// + open func updateLineColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnLine { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/line/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnLine = { response in + return AppwriteModels.ColumnLine.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a geometric point attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnPoint + /// + open func createPointColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.ColumnPoint { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/point" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnPoint = { response in + return AppwriteModels.ColumnPoint.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a point column. Changing the `default` value will not update already + /// existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnPoint + /// + open func updatePointColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnPoint { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/point/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnPoint = { response in + return AppwriteModels.ColumnPoint.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a geometric polygon attribute. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnPolygon + /// + open func createPolygonColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil + ) async throws -> AppwriteModels.ColumnPolygon { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/polygon" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default` + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnPolygon = { response in + return AppwriteModels.ColumnPolygon.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a polygon column. Changing the `default` value will not update + /// already existing documents. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnPolygon + /// + open func updatePolygonColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnPolygon { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/polygon/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnPolygon = { response in + return AppwriteModels.ColumnPolygon.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Create relationship column. [Learn more about relationship /// columns](https://appwrite.io/docs/databases-relationships#relationship-columns). diff --git a/Sources/AppwriteEnums/CreditCard.swift b/Sources/AppwriteEnums/CreditCard.swift index 688c5a4..df6079c 100644 --- a/Sources/AppwriteEnums/CreditCard.swift +++ b/Sources/AppwriteEnums/CreditCard.swift @@ -13,7 +13,7 @@ public enum CreditCard: String, CustomStringConvertible { case mastercard = "mastercard" case naranja = "naranja" case tarjetaShopping = "targeta-shopping" - case unionChinaPay = "union-china-pay" + case unionPay = "unionpay" case visa = "visa" case mIR = "mir" case maestro = "maestro" diff --git a/Sources/AppwriteEnums/ExecutionMethod.swift b/Sources/AppwriteEnums/ExecutionMethod.swift index 85111a6..d2153d2 100644 --- a/Sources/AppwriteEnums/ExecutionMethod.swift +++ b/Sources/AppwriteEnums/ExecutionMethod.swift @@ -7,6 +7,7 @@ public enum ExecutionMethod: String, CustomStringConvertible { case pATCH = "PATCH" case dELETE = "DELETE" case oPTIONS = "OPTIONS" + case hEAD = "HEAD" public var description: String { return rawValue diff --git a/Sources/AppwriteEnums/IndexType.swift b/Sources/AppwriteEnums/IndexType.swift index 9687f08..a69096e 100644 --- a/Sources/AppwriteEnums/IndexType.swift +++ b/Sources/AppwriteEnums/IndexType.swift @@ -4,6 +4,7 @@ public enum IndexType: String, CustomStringConvertible { case key = "key" case fulltext = "fulltext" case unique = "unique" + case spatial = "spatial" public var description: String { return rawValue diff --git a/Sources/AppwriteModels/AttributeLine.swift b/Sources/AppwriteModels/AttributeLine.swift new file mode 100644 index 0000000..b1dc0ca --- /dev/null +++ b/Sources/AppwriteModels/AttributeLine.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// AttributeLine +open class AttributeLine: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Attribute Key. + public let key: String + + /// Attribute type. + public let type: String + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + public let error: String + + /// Is attribute required? + public let `required`: Bool + + /// Is attribute an array? + public let array: Bool? + + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> AttributeLine { + return AttributeLine( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/Sources/AppwriteModels/AttributePoint.swift b/Sources/AppwriteModels/AttributePoint.swift new file mode 100644 index 0000000..41110ac --- /dev/null +++ b/Sources/AppwriteModels/AttributePoint.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// AttributePoint +open class AttributePoint: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Attribute Key. + public let key: String + + /// Attribute type. + public let type: String + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + public let error: String + + /// Is attribute required? + public let `required`: Bool + + /// Is attribute an array? + public let array: Bool? + + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> AttributePoint { + return AttributePoint( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/Sources/AppwriteModels/AttributePolygon.swift b/Sources/AppwriteModels/AttributePolygon.swift new file mode 100644 index 0000000..769d669 --- /dev/null +++ b/Sources/AppwriteModels/AttributePolygon.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// AttributePolygon +open class AttributePolygon: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Attribute Key. + public let key: String + + /// Attribute type. + public let type: String + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + public let error: String + + /// Is attribute required? + public let `required`: Bool + + /// Is attribute an array? + public let array: Bool? + + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> AttributePolygon { + return AttributePolygon( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/Sources/AppwriteModels/ColumnLine.swift b/Sources/AppwriteModels/ColumnLine.swift new file mode 100644 index 0000000..b860062 --- /dev/null +++ b/Sources/AppwriteModels/ColumnLine.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// ColumnLine +open class ColumnLine: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Column Key. + public let key: String + + /// Column type. + public let type: String + + /// Column status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an column. + public let error: String + + /// Is column required? + public let `required`: Bool + + /// Is column an array? + public let array: Bool? + + /// Column creation date in ISO 8601 format. + public let createdAt: String + + /// Column update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnLine { + return ColumnLine( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/Sources/AppwriteModels/ColumnPoint.swift b/Sources/AppwriteModels/ColumnPoint.swift new file mode 100644 index 0000000..06353f6 --- /dev/null +++ b/Sources/AppwriteModels/ColumnPoint.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// ColumnPoint +open class ColumnPoint: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Column Key. + public let key: String + + /// Column type. + public let type: String + + /// Column status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an column. + public let error: String + + /// Is column required? + public let `required`: Bool + + /// Is column an array? + public let array: Bool? + + /// Column creation date in ISO 8601 format. + public let createdAt: String + + /// Column update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnPoint { + return ColumnPoint( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/Sources/AppwriteModels/ColumnPolygon.swift b/Sources/AppwriteModels/ColumnPolygon.swift new file mode 100644 index 0000000..3164cab --- /dev/null +++ b/Sources/AppwriteModels/ColumnPolygon.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// ColumnPolygon +open class ColumnPolygon: Codable { + + enum CodingKeys: String, CodingKey { + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case `required` = "required" + case array = "array" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case `default` = "default" + } + + /// Column Key. + public let key: String + + /// Column type. + public let type: String + + /// Column status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + public let status: String + + /// Error message. Displays error generated on failure of creating or deleting an column. + public let error: String + + /// Is column required? + public let `required`: Bool + + /// Is column an array? + public let array: Bool? + + /// Column creation date in ISO 8601 format. + public let createdAt: String + + /// Column update date in ISO 8601 format. + public let updatedAt: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: [String: AnyCodable]? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: [String: AnyCodable]? + ) { + self.key = key + self.type = type + self.status = status + self.error = error + self.`required` = `required` + self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt + self.`default` = `default` + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.key = try container.decode(String.self, forKey: .key) + self.type = try container.decode(String.self, forKey: .type) + self.status = try container.decode(String.self, forKey: .status) + self.error = try container.decode(String.self, forKey: .error) + self.`required` = try container.decode(Bool.self, forKey: .`required`) + self.array = try container.decodeIfPresent(Bool.self, forKey: .array) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(key, forKey: .key) + try container.encode(type, forKey: .type) + try container.encode(status, forKey: .status) + try container.encode(error, forKey: .error) + try container.encode(`required`, forKey: .`required`) + try container.encodeIfPresent(array, forKey: .array) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encodeIfPresent(`default`, forKey: .`default`) + } + + public func toMap() -> [String: Any] { + return [ + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "required": `required` as Any, + "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnPolygon { + return ColumnPolygon( + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + required: map["required"] as! Bool, + array: map["array"] as? Bool, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + default: map["default"] as? [String: AnyCodable] + ) + } +} diff --git a/docs/examples/databases/create-line-attribute.md b/docs/examples/databases/create-line-attribute.md new file mode 100644 index 0000000..38e7a7d --- /dev/null +++ b/docs/examples/databases/create-line-attribute.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributeLine = try await databases.createLineAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/databases/create-point-attribute.md b/docs/examples/databases/create-point-attribute.md new file mode 100644 index 0000000..bd20407 --- /dev/null +++ b/docs/examples/databases/create-point-attribute.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributePoint = try await databases.createPointAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/databases/create-polygon-attribute.md b/docs/examples/databases/create-polygon-attribute.md new file mode 100644 index 0000000..9799c08 --- /dev/null +++ b/docs/examples/databases/create-polygon-attribute.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributePolygon = try await databases.createPolygonAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/databases/update-line-attribute.md b/docs/examples/databases/update-line-attribute.md new file mode 100644 index 0000000..d7e7612 --- /dev/null +++ b/docs/examples/databases/update-line-attribute.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributeLine = try await databases.updateLineAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + diff --git a/docs/examples/databases/update-point-attribute.md b/docs/examples/databases/update-point-attribute.md new file mode 100644 index 0000000..8907cd0 --- /dev/null +++ b/docs/examples/databases/update-point-attribute.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributePoint = try await databases.updatePointAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + diff --git a/docs/examples/databases/update-polygon-attribute.md b/docs/examples/databases/update-polygon-attribute.md new file mode 100644 index 0000000..35da75b --- /dev/null +++ b/docs/examples/databases/update-polygon-attribute.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let databases = Databases(client) + +let attributePolygon = try await databases.updatePolygonAttribute( + databaseId: "", + collectionId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/create-line-column.md b/docs/examples/tablesdb/create-line-column.md new file mode 100644 index 0000000..6d776f9 --- /dev/null +++ b/docs/examples/tablesdb/create-line-column.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnLine = try await tablesDB.createLineColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/tablesdb/create-point-column.md b/docs/examples/tablesdb/create-point-column.md new file mode 100644 index 0000000..53ed8b4 --- /dev/null +++ b/docs/examples/tablesdb/create-point-column.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnPoint = try await tablesDB.createPointColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/tablesdb/create-polygon-column.md b/docs/examples/tablesdb/create-polygon-column.md new file mode 100644 index 0000000..1c692be --- /dev/null +++ b/docs/examples/tablesdb/create-polygon-column.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnPolygon = try await tablesDB.createPolygonColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "" // optional +) + diff --git a/docs/examples/tablesdb/update-line-column.md b/docs/examples/tablesdb/update-line-column.md new file mode 100644 index 0000000..b04fd74 --- /dev/null +++ b/docs/examples/tablesdb/update-line-column.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnLine = try await tablesDB.updateLineColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-point-column.md b/docs/examples/tablesdb/update-point-column.md new file mode 100644 index 0000000..b2885de --- /dev/null +++ b/docs/examples/tablesdb/update-point-column.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnPoint = try await tablesDB.updatePointColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-polygon-column.md b/docs/examples/tablesdb/update-polygon-column.md new file mode 100644 index 0000000..8ce6d20 --- /dev/null +++ b/docs/examples/tablesdb/update-polygon-column.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setKey("") // Your secret API key + +let tablesDB = TablesDB(client) + +let columnPolygon = try await tablesDB.updatePolygonColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", // optional + newKey: "" // optional +) + From 66e178cc3098281dd491756d89cd31e0965efa2e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 5 Sep 2025 02:16:40 +1200 Subject: [PATCH 2/6] Update version --- README.md | 2 +- Sources/Appwrite/Client.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e1c1f9..1d8bc8b 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "11.1.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "12.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 5d3b660..a1dd6e3 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,7 +21,7 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "11.1.0", + "x-sdk-version": "12.0.0", "x-appwrite-response-format": "1.8.0" ] From 7db522a383ea7e162b35980fe1103a0e62ab5576 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 5 Sep 2025 21:43:10 +1200 Subject: [PATCH 3/6] Add spatial queries --- Sources/Appwrite/Query.swift | 132 ++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 2 deletions(-) diff --git a/Sources/Appwrite/Query.swift b/Sources/Appwrite/Query.swift index f811973..6e42df3 100644 --- a/Sources/Appwrite/Query.swift +++ b/Sources/Appwrite/Query.swift @@ -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) { @@ -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" + ) } } @@ -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) } } } @@ -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 } @@ -412,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 From 867b58ff9c2bd7ec24c66860eef00f9cc9509b45 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 5 Sep 2025 22:03:14 +1200 Subject: [PATCH 4/6] Fix refs --- Sources/Appwrite/Services/Databases.swift | 2 +- Sources/Appwrite/Services/TablesDb.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 08b55c1..44aad57 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -1290,7 +1290,7 @@ open class Databases: Service { } /// - /// Create a geometric 2d point attribute. + /// Create a geometric point attribute. /// /// - Parameters: /// - databaseId: String diff --git a/Sources/Appwrite/Services/TablesDb.swift b/Sources/Appwrite/Services/TablesDb.swift index 5bb1a46..3d61038 100644 --- a/Sources/Appwrite/Services/TablesDb.swift +++ b/Sources/Appwrite/Services/TablesDb.swift @@ -1166,7 +1166,7 @@ open class TablesDB: Service { } /// - /// Create a geometric line attribute. + /// Create a geometric line column. /// /// - Parameters: /// - databaseId: String @@ -1213,7 +1213,7 @@ open class TablesDB: Service { /// /// Update a line column. Changing the `default` value will not update already - /// existing documents. + /// existing rows. /// /// - Parameters: /// - databaseId: String @@ -1262,7 +1262,7 @@ open class TablesDB: Service { } /// - /// Create a geometric point attribute. + /// Create a geometric point column. /// /// - Parameters: /// - databaseId: String @@ -1309,7 +1309,7 @@ open class TablesDB: Service { /// /// Update a point column. Changing the `default` value will not update already - /// existing documents. + /// existing rows. /// /// - Parameters: /// - databaseId: String @@ -1358,7 +1358,7 @@ open class TablesDB: Service { } /// - /// Create a geometric polygon attribute. + /// Create a geometric polygon column. /// /// - Parameters: /// - databaseId: String @@ -1405,7 +1405,7 @@ open class TablesDB: Service { /// /// Update a polygon column. Changing the `default` value will not update - /// already existing documents. + /// already existing rows. /// /// - Parameters: /// - databaseId: String From d7998046c9718ab858518fab74e13d3edd288fcb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 6 Sep 2025 04:59:32 +1200 Subject: [PATCH 5/6] Fix spatial default --- Sources/Appwrite/Services/Databases.swift | 24 +++++++++---------- Sources/Appwrite/Services/TablesDb.swift | 24 +++++++++---------- Sources/AppwriteModels/AttributeLine.swift | 8 +++---- Sources/AppwriteModels/AttributePoint.swift | 8 +++---- Sources/AppwriteModels/AttributePolygon.swift | 8 +++---- Sources/AppwriteModels/ColumnLine.swift | 8 +++---- Sources/AppwriteModels/ColumnPoint.swift | 8 +++---- Sources/AppwriteModels/ColumnPolygon.swift | 8 +++---- docs/examples/account/update-prefs.md | 6 ++++- docs/examples/databases/create-document.md | 8 ++++++- .../databases/create-line-attribute.md | 2 +- .../databases/create-point-attribute.md | 2 +- .../databases/create-polygon-attribute.md | 2 +- .../databases/update-line-attribute.md | 2 +- .../databases/update-point-attribute.md | 2 +- .../databases/update-polygon-attribute.md | 2 +- docs/examples/tablesdb/create-line-column.md | 2 +- docs/examples/tablesdb/create-point-column.md | 2 +- .../tablesdb/create-polygon-column.md | 2 +- docs/examples/tablesdb/create-row.md | 8 ++++++- docs/examples/tablesdb/update-line-column.md | 2 +- docs/examples/tablesdb/update-point-column.md | 2 +- .../tablesdb/update-polygon-column.md | 2 +- 23 files changed, 79 insertions(+), 63 deletions(-) diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 44aad57..03c7f4a 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -1199,7 +1199,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeLine /// @@ -1209,7 +1209,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.AttributeLine { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/line" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1247,7 +1247,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeLine @@ -1258,7 +1258,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.AttributeLine { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/line/{key}" @@ -1297,7 +1297,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributePoint /// @@ -1307,7 +1307,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.AttributePoint { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/point" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1345,7 +1345,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributePoint @@ -1356,7 +1356,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.AttributePoint { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/point/{key}" @@ -1395,7 +1395,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributePolygon /// @@ -1405,7 +1405,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.AttributePolygon { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/polygon" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1443,7 +1443,7 @@ open class Databases: Service { /// - collectionId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributePolygon @@ -1454,7 +1454,7 @@ open class Databases: Service { collectionId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.AttributePolygon { let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/attributes/polygon/{key}" diff --git a/Sources/Appwrite/Services/TablesDb.swift b/Sources/Appwrite/Services/TablesDb.swift index 3d61038..8bbbf4c 100644 --- a/Sources/Appwrite/Services/TablesDb.swift +++ b/Sources/Appwrite/Services/TablesDb.swift @@ -1173,7 +1173,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnLine /// @@ -1182,7 +1182,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.ColumnLine { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/line" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1220,7 +1220,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnLine @@ -1230,7 +1230,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.ColumnLine { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/line/{key}" @@ -1269,7 +1269,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnPoint /// @@ -1278,7 +1278,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.ColumnPoint { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/point" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1316,7 +1316,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnPoint @@ -1326,7 +1326,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.ColumnPoint { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/point/{key}" @@ -1365,7 +1365,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnPolygon /// @@ -1374,7 +1374,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil + `default`: [AnyCodable]? = nil ) async throws -> AppwriteModels.ColumnPolygon { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/polygon" .replacingOccurrences(of: "{databaseId}", with: databaseId) @@ -1412,7 +1412,7 @@ open class TablesDB: Service { /// - tableId: String /// - key: String /// - required: Bool - /// - default: String (optional) + /// - default: [AnyCodable] (optional) /// - newKey: String (optional) /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.ColumnPolygon @@ -1422,7 +1422,7 @@ open class TablesDB: Service { tableId: String, key: String, `required`: Bool, - `default`: String? = nil, + `default`: [AnyCodable]? = nil, newKey: String? = nil ) async throws -> AppwriteModels.ColumnPolygon { let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/polygon/{key}" diff --git a/Sources/AppwriteModels/AttributeLine.swift b/Sources/AppwriteModels/AttributeLine.swift index b1dc0ca..8457304 100644 --- a/Sources/AppwriteModels/AttributeLine.swift +++ b/Sources/AppwriteModels/AttributeLine.swift @@ -41,7 +41,7 @@ open class AttributeLine: Codable { public let updatedAt: String /// Default value for attribute when not provided. Cannot be set when attribute is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class AttributeLine: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class AttributeLine: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class AttributeLine: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/Sources/AppwriteModels/AttributePoint.swift b/Sources/AppwriteModels/AttributePoint.swift index 41110ac..7c5fc2b 100644 --- a/Sources/AppwriteModels/AttributePoint.swift +++ b/Sources/AppwriteModels/AttributePoint.swift @@ -41,7 +41,7 @@ open class AttributePoint: Codable { public let updatedAt: String /// Default value for attribute when not provided. Cannot be set when attribute is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class AttributePoint: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class AttributePoint: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class AttributePoint: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/Sources/AppwriteModels/AttributePolygon.swift b/Sources/AppwriteModels/AttributePolygon.swift index 769d669..14cb7fd 100644 --- a/Sources/AppwriteModels/AttributePolygon.swift +++ b/Sources/AppwriteModels/AttributePolygon.swift @@ -41,7 +41,7 @@ open class AttributePolygon: Codable { public let updatedAt: String /// Default value for attribute when not provided. Cannot be set when attribute is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class AttributePolygon: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class AttributePolygon: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class AttributePolygon: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/Sources/AppwriteModels/ColumnLine.swift b/Sources/AppwriteModels/ColumnLine.swift index b860062..09c0543 100644 --- a/Sources/AppwriteModels/ColumnLine.swift +++ b/Sources/AppwriteModels/ColumnLine.swift @@ -41,7 +41,7 @@ open class ColumnLine: Codable { public let updatedAt: String /// Default value for column when not provided. Cannot be set when column is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class ColumnLine: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class ColumnLine: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class ColumnLine: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/Sources/AppwriteModels/ColumnPoint.swift b/Sources/AppwriteModels/ColumnPoint.swift index 06353f6..96b1f65 100644 --- a/Sources/AppwriteModels/ColumnPoint.swift +++ b/Sources/AppwriteModels/ColumnPoint.swift @@ -41,7 +41,7 @@ open class ColumnPoint: Codable { public let updatedAt: String /// Default value for column when not provided. Cannot be set when column is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class ColumnPoint: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class ColumnPoint: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class ColumnPoint: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/Sources/AppwriteModels/ColumnPolygon.swift b/Sources/AppwriteModels/ColumnPolygon.swift index 3164cab..0f64db7 100644 --- a/Sources/AppwriteModels/ColumnPolygon.swift +++ b/Sources/AppwriteModels/ColumnPolygon.swift @@ -41,7 +41,7 @@ open class ColumnPolygon: Codable { public let updatedAt: String /// Default value for column when not provided. Cannot be set when column is required. - public let `default`: [String: AnyCodable]? + public let `default`: [AnyCodable]? init( @@ -53,7 +53,7 @@ open class ColumnPolygon: Codable { array: Bool?, createdAt: String, updatedAt: String, - `default`: [String: AnyCodable]? + `default`: [AnyCodable]? ) { self.key = key self.type = type @@ -77,7 +77,7 @@ open class ColumnPolygon: Codable { self.array = try container.decodeIfPresent(Bool.self, forKey: .array) self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) - self.`default` = try container.decodeIfPresent([String: AnyCodable].self, forKey: .`default`) + self.`default` = try container.decodeIfPresent([AnyCodable].self, forKey: .`default`) } public func encode(to encoder: Encoder) throws { @@ -118,7 +118,7 @@ open class ColumnPolygon: Codable { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - default: map["default"] as? [String: AnyCodable] + default: (map["default"] as? [Any] ?? []).map { AnyCodable($0) } ) } } diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 53bf623..cc7b5e6 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -8,6 +8,10 @@ let client = Client() let account = Account(client) let user = try await account.updatePrefs( - prefs: [:] + prefs: [ + "language": "en", + "timezone": "UTC", + "darkTheme": true + ] ) diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index daeaf14..cc25fd8 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -11,7 +11,13 @@ let document = try await databases.createDocument( databaseId: "", collectionId: "", documentId: "", - data: [:], + data: [ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + ], permissions: ["read("any")"] // optional ) diff --git a/docs/examples/databases/create-line-attribute.md b/docs/examples/databases/create-line-attribute.md index 38e7a7d..6683ba3 100644 --- a/docs/examples/databases/create-line-attribute.md +++ b/docs/examples/databases/create-line-attribute.md @@ -12,6 +12,6 @@ let attributeLine = try await databases.createLineAttribute( collectionId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/databases/create-point-attribute.md b/docs/examples/databases/create-point-attribute.md index bd20407..62d95f8 100644 --- a/docs/examples/databases/create-point-attribute.md +++ b/docs/examples/databases/create-point-attribute.md @@ -12,6 +12,6 @@ let attributePoint = try await databases.createPointAttribute( collectionId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/databases/create-polygon-attribute.md b/docs/examples/databases/create-polygon-attribute.md index 9799c08..6f7c2d2 100644 --- a/docs/examples/databases/create-polygon-attribute.md +++ b/docs/examples/databases/create-polygon-attribute.md @@ -12,6 +12,6 @@ let attributePolygon = try await databases.createPolygonAttribute( collectionId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/databases/update-line-attribute.md b/docs/examples/databases/update-line-attribute.md index d7e7612..c71bffd 100644 --- a/docs/examples/databases/update-line-attribute.md +++ b/docs/examples/databases/update-line-attribute.md @@ -12,7 +12,7 @@ let attributeLine = try await databases.updateLineAttribute( collectionId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) diff --git a/docs/examples/databases/update-point-attribute.md b/docs/examples/databases/update-point-attribute.md index 8907cd0..7fc8c11 100644 --- a/docs/examples/databases/update-point-attribute.md +++ b/docs/examples/databases/update-point-attribute.md @@ -12,7 +12,7 @@ let attributePoint = try await databases.updatePointAttribute( collectionId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) diff --git a/docs/examples/databases/update-polygon-attribute.md b/docs/examples/databases/update-polygon-attribute.md index 35da75b..5ceeacb 100644 --- a/docs/examples/databases/update-polygon-attribute.md +++ b/docs/examples/databases/update-polygon-attribute.md @@ -12,7 +12,7 @@ let attributePolygon = try await databases.updatePolygonAttribute( collectionId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) diff --git a/docs/examples/tablesdb/create-line-column.md b/docs/examples/tablesdb/create-line-column.md index 6d776f9..31a09d9 100644 --- a/docs/examples/tablesdb/create-line-column.md +++ b/docs/examples/tablesdb/create-line-column.md @@ -12,6 +12,6 @@ let columnLine = try await tablesDB.createLineColumn( tableId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/tablesdb/create-point-column.md b/docs/examples/tablesdb/create-point-column.md index 53ed8b4..81e5fe9 100644 --- a/docs/examples/tablesdb/create-point-column.md +++ b/docs/examples/tablesdb/create-point-column.md @@ -12,6 +12,6 @@ let columnPoint = try await tablesDB.createPointColumn( tableId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/tablesdb/create-polygon-column.md b/docs/examples/tablesdb/create-polygon-column.md index 1c692be..d336faa 100644 --- a/docs/examples/tablesdb/create-polygon-column.md +++ b/docs/examples/tablesdb/create-polygon-column.md @@ -12,6 +12,6 @@ let columnPolygon = try await tablesDB.createPolygonColumn( tableId: "", key: "", required: false, - default: "" // optional + default: [[1,2], [3, 4]] // optional ) diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md index 31e0ea9..0c59a65 100644 --- a/docs/examples/tablesdb/create-row.md +++ b/docs/examples/tablesdb/create-row.md @@ -11,7 +11,13 @@ let row = try await tablesDB.createRow( databaseId: "", tableId: "", rowId: "", - data: [:], + data: [ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + ], permissions: ["read("any")"] // optional ) diff --git a/docs/examples/tablesdb/update-line-column.md b/docs/examples/tablesdb/update-line-column.md index b04fd74..86a8959 100644 --- a/docs/examples/tablesdb/update-line-column.md +++ b/docs/examples/tablesdb/update-line-column.md @@ -12,7 +12,7 @@ let columnLine = try await tablesDB.updateLineColumn( tableId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) diff --git a/docs/examples/tablesdb/update-point-column.md b/docs/examples/tablesdb/update-point-column.md index b2885de..1ebfcfa 100644 --- a/docs/examples/tablesdb/update-point-column.md +++ b/docs/examples/tablesdb/update-point-column.md @@ -12,7 +12,7 @@ let columnPoint = try await tablesDB.updatePointColumn( tableId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) diff --git a/docs/examples/tablesdb/update-polygon-column.md b/docs/examples/tablesdb/update-polygon-column.md index 8ce6d20..d05f886 100644 --- a/docs/examples/tablesdb/update-polygon-column.md +++ b/docs/examples/tablesdb/update-polygon-column.md @@ -12,7 +12,7 @@ let columnPolygon = try await tablesDB.updatePolygonColumn( tableId: "", key: "", required: false, - default: "", // optional + default: [[1,2], [3, 4]], // optional newKey: "" // optional ) From 8550541446e5a991d768e9d95cc23f8e5690de9f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 8 Sep 2025 21:44:03 +1200 Subject: [PATCH 6/6] Update spatial queries --- Sources/Appwrite/Query.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Appwrite/Query.swift b/Sources/Appwrite/Query.swift index 6e42df3..5af7f4a 100644 --- a/Sources/Appwrite/Query.swift +++ b/Sources/Appwrite/Query.swift @@ -448,7 +448,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "distanceEqual", attribute: attribute, - values: [values, distance, meters] + values: [[values, distance, meters]] ).description } @@ -456,7 +456,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "distanceNotEqual", attribute: attribute, - values: [values, distance, meters] + values: [[values, distance, meters]] ).description } @@ -464,7 +464,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "distanceGreaterThan", attribute: attribute, - values: [values, distance, meters] + values: [[values, distance, meters]] ).description } @@ -472,7 +472,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "distanceLessThan", attribute: attribute, - values: [values, distance, meters] + values: [[values, distance, meters]] ).description } @@ -480,7 +480,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "intersects", attribute: attribute, - values: values + values: [values] ).description } @@ -488,7 +488,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "notIntersects", attribute: attribute, - values: values + values: [values] ).description } @@ -496,7 +496,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "crosses", attribute: attribute, - values: values + values: [values] ).description } @@ -504,7 +504,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "notCrosses", attribute: attribute, - values: values + values: [values] ).description } @@ -512,7 +512,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "overlaps", attribute: attribute, - values: values + values: [values] ).description } @@ -520,7 +520,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "notOverlaps", attribute: attribute, - values: values + values: [values] ).description } @@ -528,7 +528,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "touches", attribute: attribute, - values: values + values: [values] ).description } @@ -536,7 +536,7 @@ public struct Query : Codable, CustomStringConvertible { return Query( method: "notTouches", attribute: attribute, - values: values + values: [values] ).description }