diff --git a/README.md b/README.md index f18bc63..5655f98 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ ![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.8.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).** +**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).** > This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple) @@ -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: "10.2.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "11.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 6a21d52..1eb5a93 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,8 +21,8 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "10.2.0", - "x-appwrite-response-format": "1.7.0" + "x-sdk-version": "11.0.0", + "x-appwrite-response-format": "1.8.0" ] internal var config: [String: String] = [:] diff --git a/Sources/Appwrite/Query.swift b/Sources/Appwrite/Query.swift index 20c499e..1956cdd 100644 --- a/Sources/Appwrite/Query.swift +++ b/Sources/Appwrite/Query.swift @@ -284,6 +284,90 @@ public struct Query : Codable, CustomStringConvertible { ).description } + public static func notContains(_ attribute: String, value: Any) -> String { + return Query( + method: "notContains", + attribute: attribute, + values: Query.parseValue(value) + ).description + } + + public static func notSearch(_ attribute: String, value: String) -> String { + return Query( + method: "notSearch", + attribute: attribute, + values: [value] + ).description + } + + public static func notBetween(_ attribute: String, start: Int, end: Int) -> String { + return Query( + method: "notBetween", + attribute: attribute, + values: [start, end] + ).description + } + + public static func notBetween(_ attribute: String, start: Double, end: Double) -> String { + return Query( + method: "notBetween", + attribute: attribute, + values: [start, end] + ).description + } + + public static func notBetween(_ attribute: String, start: String, end: String) -> String { + return Query( + method: "notBetween", + attribute: attribute, + values: [start, end] + ).description + } + + public static func notStartsWith(_ attribute: String, value: String) -> String { + return Query( + method: "notStartsWith", + attribute: attribute, + values: [value] + ).description + } + + public static func notEndsWith(_ attribute: String, value: String) -> String { + return Query( + method: "notEndsWith", + attribute: attribute, + values: [value] + ).description + } + + public static func createdBefore(_ value: String) -> String { + return Query( + method: "createdBefore", + values: [value] + ).description + } + + public static func createdAfter(_ value: String) -> String { + return Query( + method: "createdAfter", + values: [value] + ).description + } + + public static func updatedBefore(_ value: String) -> String { + return Query( + method: "updatedBefore", + values: [value] + ).description + } + + public static func updatedAfter(_ value: String) -> String { + return Query( + method: "updatedAfter", + values: [value] + ).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 8e93bc4..b68ba76 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -391,6 +391,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaType /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.createMFAAuthenticator` instead.") open func createMfaAuthenticator( type: AppwriteEnums.AuthenticatorType ) async throws -> AppwriteModels.MfaType { @@ -416,6 +417,42 @@ open class Account: Service { ) } + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + /// + /// - Parameters: + /// - type: AppwriteEnums.AuthenticatorType + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaType + /// + open func createMFAAuthenticator( + type: AppwriteEnums.AuthenticatorType + ) async throws -> AppwriteModels.MfaType { + let apiPath: String = "/account/mfa/authenticators/{type}" + .replacingOccurrences(of: "{type}", with: type.rawValue) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaType = { response in + return AppwriteModels.MfaType.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) @@ -427,6 +464,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.User /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateMFAAuthenticator` instead.") open func updateMfaAuthenticator( type: AppwriteEnums.AuthenticatorType, otp: String, @@ -467,6 +505,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.User /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateMFAAuthenticator` instead.") open func updateMfaAuthenticator( type: AppwriteEnums.AuthenticatorType, otp: String @@ -478,6 +517,68 @@ open class Account: Service { ) } + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + /// + /// - Parameters: + /// - type: AppwriteEnums.AuthenticatorType + /// - otp: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.User + /// + open func updateMFAAuthenticator( + type: AppwriteEnums.AuthenticatorType, + otp: String, + nestedType: T.Type + ) async throws -> AppwriteModels.User { + let apiPath: String = "/account/mfa/authenticators/{type}" + .replacingOccurrences(of: "{type}", with: type.rawValue) + + let apiParams: [String: Any?] = [ + "otp": otp + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.User = { response in + return AppwriteModels.User.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + /// + /// - Parameters: + /// - type: AppwriteEnums.AuthenticatorType + /// - otp: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.User + /// + open func updateMFAAuthenticator( + type: AppwriteEnums.AuthenticatorType, + otp: String + ) async throws -> AppwriteModels.User<[String: AnyCodable]> { + return try await updateMFAAuthenticator( + type: type, + otp: otp, + nestedType: [String: AnyCodable].self + ) + } + /// /// Delete an authenticator for a user by ID. /// @@ -486,6 +587,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.deleteMFAAuthenticator` instead.") open func deleteMfaAuthenticator( type: AppwriteEnums.AuthenticatorType ) async throws -> Any { @@ -505,6 +607,33 @@ open class Account: Service { params: apiParams ) } + /// + /// Delete an authenticator for a user by ID. + /// + /// - Parameters: + /// - type: AppwriteEnums.AuthenticatorType + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteMFAAuthenticator( + type: AppwriteEnums.AuthenticatorType + ) async throws -> Any { + let apiPath: String = "/account/mfa/authenticators/{type}" + .replacingOccurrences(of: "{type}", with: type.rawValue) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + /// /// Begin the process of MFA verification after sign-in. Finish the flow with /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) @@ -515,6 +644,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaChallenge /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.createMFAChallenge` instead.") open func createMfaChallenge( factor: AppwriteEnums.AuthenticationFactor ) async throws -> AppwriteModels.MfaChallenge { @@ -541,6 +671,42 @@ open class Account: Service { ) } + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + /// + /// - Parameters: + /// - factor: AppwriteEnums.AuthenticationFactor + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaChallenge + /// + open func createMFAChallenge( + factor: AppwriteEnums.AuthenticationFactor + ) async throws -> AppwriteModels.MfaChallenge { + let apiPath: String = "/account/mfa/challenge" + + let apiParams: [String: Any?] = [ + "factor": factor + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaChallenge = { response in + return AppwriteModels.MfaChallenge.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Complete the MFA challenge by providing the one-time password. Finish the /// process of MFA verification by providing the one-time password. To begin @@ -554,6 +720,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Session /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateMFAChallenge` instead.") open func updateMfaChallenge( challengeId: String, otp: String @@ -582,12 +749,54 @@ open class Account: Service { ) } + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + /// + /// - Parameters: + /// - challengeId: String + /// - otp: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Session + /// + open func updateMFAChallenge( + challengeId: String, + otp: String + ) async throws -> AppwriteModels.Session { + let apiPath: String = "/account/mfa/challenge" + + let apiParams: [String: Any?] = [ + "challengeId": challengeId, + "otp": otp + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Session = { response in + return AppwriteModels.Session.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// List the factors available on the account to be used as a MFA challange. /// /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaFactors /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.listMFAFactors` instead.") open func listMfaFactors( ) async throws -> AppwriteModels.MfaFactors { let apiPath: String = "/account/mfa/factors" @@ -609,6 +818,33 @@ open class Account: Service { ) } + /// + /// List the factors available on the account to be used as a MFA challange. + /// + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaFactors + /// + open func listMFAFactors( + ) async throws -> AppwriteModels.MfaFactors { + let apiPath: String = "/account/mfa/factors" + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.MfaFactors = { response in + return AppwriteModels.MfaFactors.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Get recovery codes that can be used as backup for MFA flow. Before getting /// codes, they must be generated using @@ -618,6 +854,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.getMFARecoveryCodes` instead.") open func getMfaRecoveryCodes( ) async throws -> AppwriteModels.MfaRecoveryCodes { let apiPath: String = "/account/mfa/recovery-codes" @@ -639,6 +876,36 @@ open class Account: Service { ) } + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + /// + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func getMFARecoveryCodes( + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/account/mfa/recovery-codes" + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Generate recovery codes as backup for MFA flow. It's recommended to /// generate and show then immediately after user successfully adds their @@ -649,6 +916,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.createMFARecoveryCodes` instead.") open func createMfaRecoveryCodes( ) async throws -> AppwriteModels.MfaRecoveryCodes { let apiPath: String = "/account/mfa/recovery-codes" @@ -672,6 +940,39 @@ open class Account: Service { ) } + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + /// + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func createMFARecoveryCodes( + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/account/mfa/recovery-codes" + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Regenerate recovery codes that can be used as backup for MFA flow. Before /// regenerating codes, they must be first generated using @@ -681,6 +982,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateMFARecoveryCodes` instead.") open func updateMfaRecoveryCodes( ) async throws -> AppwriteModels.MfaRecoveryCodes { let apiPath: String = "/account/mfa/recovery-codes" @@ -704,6 +1006,38 @@ open class Account: Service { ) } + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + /// + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func updateMFARecoveryCodes( + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/account/mfa/recovery-codes" + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update currently logged in user account name. /// @@ -1214,6 +1548,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Session /// + @available(*, deprecated, message: "This API has been deprecated.") open func updateMagicURLSession( userId: String, secret: String @@ -1253,6 +1588,7 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Session /// + @available(*, deprecated, message: "This API has been deprecated.") open func updatePhoneSession( userId: String, secret: String @@ -1467,8 +1803,11 @@ open class Account: Service { /// /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST + /// email address has never been used, a **new account is created** using the + /// provided `userId`. Otherwise, if the email address is already attached to + /// an account, the **user ID is ignored**. Then, the user will receive an + /// email with the one-time password. Use the returned user ID and secret and + /// submit a request to the [POST /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) /// endpoint to complete the login process. The secret sent to the user's email /// is valid for 15 minutes. @@ -1476,6 +1815,7 @@ open class Account: Service { /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session /// limits](https://appwrite.io/docs/authentication-security#limits). + /// /// /// - Parameters: /// - userId: String diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 86e8362..12e0c8a 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -18,6 +18,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DatabaseList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.list` instead.") open func list( queries: [String]? = nil, search: String? = nil @@ -55,6 +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.") open func create( databaseId: String, name: String, @@ -94,6 +96,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.get` instead.") open func get( databaseId: String ) async throws -> AppwriteModels.Database { @@ -127,6 +130,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.update` instead.") open func update( databaseId: String, name: String, @@ -166,6 +170,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.delete` instead.") open func delete( databaseId: String ) async throws -> Any { @@ -196,6 +201,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.CollectionList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.listTables` instead.") open func listCollections( databaseId: String, queries: [String]? = nil, @@ -240,6 +246,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Collection /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createTable` instead.") open func createCollection( databaseId: String, collectionId: String, @@ -286,6 +293,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Collection /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.getTable` instead.") open func getCollection( databaseId: String, collectionId: String @@ -324,6 +332,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Collection /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateTable` instead.") open func updateCollection( databaseId: String, collectionId: String, @@ -370,6 +379,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteTable` instead.") open func deleteCollection( databaseId: String, collectionId: String @@ -401,6 +411,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.listColumns` instead.") open func listAttributes( databaseId: String, collectionId: String, @@ -443,6 +454,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeBoolean /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createBooleanColumn` instead.") open func createBooleanAttribute( databaseId: String, collectionId: String, @@ -493,6 +505,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeBoolean /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateBooleanColumn` instead.") open func updateBooleanAttribute( databaseId: String, collectionId: String, @@ -542,6 +555,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeDatetime /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createDatetimeColumn` instead.") open func createDatetimeAttribute( databaseId: String, collectionId: String, @@ -592,6 +606,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeDatetime /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateDatetimeColumn` instead.") open func updateDatetimeAttribute( databaseId: String, collectionId: String, @@ -642,6 +657,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeEmail /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createEmailColumn` instead.") open func createEmailAttribute( databaseId: String, collectionId: String, @@ -693,6 +709,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeEmail /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateEmailColumn` instead.") open func updateEmailAttribute( databaseId: String, collectionId: String, @@ -730,8 +747,8 @@ open class Databases: Service { } /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. + /// Create an enum attribute. The `elements` param acts as a white-list of + /// accepted values for this attribute. /// /// /// - Parameters: @@ -745,6 +762,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeEnum /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createEnumColumn` instead.") open func createEnumAttribute( databaseId: String, collectionId: String, @@ -799,6 +817,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeEnum /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateEnumColumn` instead.") open func updateEnumAttribute( databaseId: String, collectionId: String, @@ -854,6 +873,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeFloat /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createFloatColumn` instead.") open func createFloatAttribute( databaseId: String, collectionId: String, @@ -911,6 +931,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeFloat /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateFloatColumn` instead.") open func updateFloatAttribute( databaseId: String, collectionId: String, @@ -968,6 +989,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeInteger /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createIntegerColumn` instead.") open func createIntegerAttribute( databaseId: String, collectionId: String, @@ -1025,6 +1047,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeInteger /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateIntegerColumn` instead.") open func updateIntegerAttribute( databaseId: String, collectionId: String, @@ -1079,6 +1102,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeIp /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createIpColumn` instead.") open func createIpAttribute( databaseId: String, collectionId: String, @@ -1130,6 +1154,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeIp /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateIpColumn` instead.") open func updateIpAttribute( databaseId: String, collectionId: String, @@ -1183,6 +1208,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeRelationship /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createRelationshipColumn` instead.") open func createRelationshipAttribute( databaseId: String, collectionId: String, @@ -1239,6 +1265,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeString /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createStringColumn` instead.") open func createStringAttribute( databaseId: String, collectionId: String, @@ -1295,6 +1322,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeString /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateStringColumn` instead.") open func updateStringAttribute( databaseId: String, collectionId: String, @@ -1347,6 +1375,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeUrl /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createUrlColumn` instead.") open func createUrlAttribute( databaseId: String, collectionId: String, @@ -1398,6 +1427,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeUrl /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateUrlColumn` instead.") open func updateUrlAttribute( databaseId: String, collectionId: String, @@ -1444,6 +1474,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.getColumn` instead.") open func getAttribute( databaseId: String, collectionId: String, @@ -1475,6 +1506,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteColumn` instead.") open func deleteAttribute( databaseId: String, collectionId: String, @@ -1512,6 +1544,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.AttributeRelationship /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateRelationshipColumn` instead.") open func updateRelationshipAttribute( databaseId: String, collectionId: String, @@ -1557,6 +1590,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.") open func listDocuments( databaseId: String, collectionId: String, @@ -1597,6 +1631,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.listRows` instead.") open func listDocuments( databaseId: String, collectionId: String, @@ -1625,6 +1660,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createRow` instead.") open func createDocument( databaseId: String, collectionId: String, @@ -1675,6 +1711,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createRow` instead.") open func createDocument( databaseId: String, collectionId: String, @@ -1693,10 +1730,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create new Documents. Before using this route, you should create a new /// collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -1709,6 +1742,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createRows` instead.") open func createDocuments( databaseId: String, collectionId: String, @@ -1741,10 +1775,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create new Documents. Before using this route, you should create a new /// collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -1757,6 +1787,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createRows` instead.") open func createDocuments( databaseId: String, collectionId: String, @@ -1771,10 +1802,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create or update Documents. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -1788,6 +1815,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") open func upsertDocuments( databaseId: String, collectionId: String, @@ -1820,10 +1848,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create or update Documents. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -1837,6 +1861,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRows` instead.") open func upsertDocuments( databaseId: String, collectionId: String, @@ -1851,10 +1876,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Update all documents that match your queries, if no queries are submitted /// then all documents are updated. You can pass only specific fields to be /// updated. @@ -1867,6 +1888,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateRows` instead.") open func updateDocuments( databaseId: String, collectionId: String, @@ -1901,10 +1923,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Update all documents that match your queries, if no queries are submitted /// then all documents are updated. You can pass only specific fields to be /// updated. @@ -1917,6 +1935,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateRows` instead.") open func updateDocuments( databaseId: String, collectionId: String, @@ -1933,10 +1952,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Bulk delete documents using queries, if no queries are passed then all /// documents are deleted. /// @@ -1947,6 +1962,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRows` instead.") open func deleteDocuments( databaseId: String, collectionId: String, @@ -1979,10 +1995,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Bulk delete documents using queries, if no queries are passed then all /// documents are deleted. /// @@ -1993,6 +2005,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.DocumentList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRows` instead.") open func deleteDocuments( databaseId: String, collectionId: String, @@ -2018,6 +2031,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.getRow` instead.") open func getDocument( databaseId: String, collectionId: String, @@ -2061,6 +2075,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.getRow` instead.") open func getDocument( databaseId: String, collectionId: String, @@ -2077,10 +2092,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create or update a Document. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -2095,6 +2106,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead.") open func upsertDocument( databaseId: String, collectionId: String, @@ -2131,10 +2143,6 @@ open class Databases: Service { } /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// /// Create or update a Document. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -2149,6 +2157,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.upsertRow` instead.") open func upsertDocument( databaseId: String, collectionId: String, @@ -2179,6 +2188,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateRow` instead.") open func updateDocument( databaseId: String, collectionId: String, @@ -2227,6 +2237,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.updateRow` instead.") open func updateDocument( databaseId: String, collectionId: String, @@ -2254,6 +2265,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteRow` instead.") open func deleteDocument( databaseId: String, collectionId: String, @@ -2290,6 +2302,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.decrementRowColumn` instead.") open func decrementDocumentAttribute( databaseId: String, collectionId: String, @@ -2340,6 +2353,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.decrementRowColumn` instead.") open func decrementDocumentAttribute( databaseId: String, collectionId: String, @@ -2372,6 +2386,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.incrementRowColumn` instead.") open func incrementDocumentAttribute( databaseId: String, collectionId: String, @@ -2422,6 +2437,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Document /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.incrementRowColumn` instead.") open func incrementDocumentAttribute( databaseId: String, collectionId: String, @@ -2451,6 +2467,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.IndexList /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.listIndexes` instead.") open func listIndexes( databaseId: String, collectionId: String, @@ -2495,6 +2512,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Index /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.createIndex` instead.") open func createIndex( databaseId: String, collectionId: String, @@ -2543,6 +2561,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Index /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.getIndex` instead.") open func getIndex( databaseId: String, collectionId: String, @@ -2580,6 +2599,7 @@ open class Databases: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `TablesDB.deleteIndex` instead.") open func deleteIndex( databaseId: String, collectionId: String, diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index 5a97dfd..1b97c72 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -373,6 +373,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Message /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.createSMS` instead.") open func createSms( messageId: String, content: String, @@ -411,6 +412,58 @@ open class Messaging: Service { ) } + /// + /// Create a new SMS message. + /// + /// - Parameters: + /// - messageId: String + /// - content: String + /// - topics: [String] (optional) + /// - users: [String] (optional) + /// - targets: [String] (optional) + /// - draft: Bool (optional) + /// - scheduledAt: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Message + /// + open func createSMS( + messageId: String, + content: String, + topics: [String]? = nil, + users: [String]? = nil, + targets: [String]? = nil, + draft: Bool? = nil, + scheduledAt: String? = nil + ) async throws -> AppwriteModels.Message { + let apiPath: String = "/messaging/messages/sms" + + let apiParams: [String: Any?] = [ + "messageId": messageId, + "content": content, + "topics": topics, + "users": users, + "targets": targets, + "draft": draft, + "scheduledAt": scheduledAt + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Message = { response in + return AppwriteModels.Message.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update an SMS message by its unique ID. This endpoint only works on /// messages that are in draft status. Messages that are already processing, @@ -428,6 +481,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Message /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.updateSMS` instead.") open func updateSms( messageId: String, topics: [String]? = nil, @@ -466,6 +520,61 @@ open class Messaging: Service { ) } + /// + /// Update an SMS message by its unique ID. This endpoint only works on + /// messages that are in draft status. Messages that are already processing, + /// sent, or failed cannot be updated. + /// + /// + /// - Parameters: + /// - messageId: String + /// - topics: [String] (optional) + /// - users: [String] (optional) + /// - targets: [String] (optional) + /// - content: String (optional) + /// - draft: Bool (optional) + /// - scheduledAt: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Message + /// + open func updateSMS( + messageId: String, + topics: [String]? = nil, + users: [String]? = nil, + targets: [String]? = nil, + content: String? = nil, + draft: Bool? = nil, + scheduledAt: String? = nil + ) async throws -> AppwriteModels.Message { + let apiPath: String = "/messaging/messages/sms/{messageId}" + .replacingOccurrences(of: "{messageId}", with: messageId) + + let apiParams: [String: Any?] = [ + "topics": topics, + "users": users, + "targets": targets, + "content": content, + "draft": draft, + "scheduledAt": scheduledAt + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Message = { response in + return AppwriteModels.Message.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Get a message by its unique ID. /// @@ -646,6 +755,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.createAPNSProvider` instead.") open func createApnsProvider( providerId: String, name: String, @@ -686,6 +796,61 @@ open class Messaging: Service { ) } + /// + /// Create a new Apple Push Notification service provider. + /// + /// - Parameters: + /// - providerId: String + /// - name: String + /// - authKey: String (optional) + /// - authKeyId: String (optional) + /// - teamId: String (optional) + /// - bundleId: String (optional) + /// - sandbox: Bool (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func createAPNSProvider( + providerId: String, + name: String, + authKey: String? = nil, + authKeyId: String? = nil, + teamId: String? = nil, + bundleId: String? = nil, + sandbox: Bool? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/apns" + + let apiParams: [String: Any?] = [ + "providerId": providerId, + "name": name, + "authKey": authKey, + "authKeyId": authKeyId, + "teamId": teamId, + "bundleId": bundleId, + "sandbox": sandbox, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update a Apple Push Notification service provider by its unique ID. /// @@ -701,6 +866,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.updateAPNSProvider` instead.") open func updateApnsProvider( providerId: String, name: String? = nil, @@ -741,6 +907,61 @@ open class Messaging: Service { ) } + /// + /// Update a Apple Push Notification service provider by its unique ID. + /// + /// - Parameters: + /// - providerId: String + /// - name: String (optional) + /// - enabled: Bool (optional) + /// - authKey: String (optional) + /// - authKeyId: String (optional) + /// - teamId: String (optional) + /// - bundleId: String (optional) + /// - sandbox: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func updateAPNSProvider( + providerId: String, + name: String? = nil, + enabled: Bool? = nil, + authKey: String? = nil, + authKeyId: String? = nil, + teamId: String? = nil, + bundleId: String? = nil, + sandbox: Bool? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/apns/{providerId}" + .replacingOccurrences(of: "{providerId}", with: providerId) + + let apiParams: [String: Any?] = [ + "name": name, + "enabled": enabled, + "authKey": authKey, + "authKeyId": authKeyId, + "teamId": teamId, + "bundleId": bundleId, + "sandbox": sandbox + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Create a new Firebase Cloud Messaging provider. /// @@ -752,6 +973,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.createFCMProvider` instead.") open func createFcmProvider( providerId: String, name: String, @@ -784,6 +1006,49 @@ open class Messaging: Service { ) } + /// + /// Create a new Firebase Cloud Messaging provider. + /// + /// - Parameters: + /// - providerId: String + /// - name: String + /// - serviceAccountJSON: Any (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func createFCMProvider( + providerId: String, + name: String, + serviceAccountJSON: Any? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/fcm" + + let apiParams: [String: Any?] = [ + "providerId": providerId, + "name": name, + "serviceAccountJSON": serviceAccountJSON, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update a Firebase Cloud Messaging provider by its unique ID. /// @@ -795,6 +1060,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.updateFCMProvider` instead.") open func updateFcmProvider( providerId: String, name: String? = nil, @@ -827,6 +1093,49 @@ open class Messaging: Service { ) } + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + /// + /// - Parameters: + /// - providerId: String + /// - name: String (optional) + /// - enabled: Bool (optional) + /// - serviceAccountJSON: Any (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func updateFCMProvider( + providerId: String, + name: String? = nil, + enabled: Bool? = nil, + serviceAccountJSON: Any? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/fcm/{providerId}" + .replacingOccurrences(of: "{providerId}", with: providerId) + + let apiParams: [String: Any?] = [ + "name": name, + "enabled": enabled, + "serviceAccountJSON": serviceAccountJSON + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Create a new Mailgun provider. /// @@ -1178,6 +1487,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.createSMTPProvider` instead.") open func createSmtpProvider( providerId: String, name: String, @@ -1230,6 +1540,79 @@ open class Messaging: Service { ) } + /// + /// Create a new SMTP provider. + /// + /// - Parameters: + /// - providerId: String + /// - name: String + /// - host: String + /// - port: Int (optional) + /// - username: String (optional) + /// - password: String (optional) + /// - encryption: AppwriteEnums.SmtpEncryption (optional) + /// - autoTLS: Bool (optional) + /// - mailer: String (optional) + /// - fromName: String (optional) + /// - fromEmail: String (optional) + /// - replyToName: String (optional) + /// - replyToEmail: String (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func createSMTPProvider( + providerId: String, + name: String, + host: String, + port: Int? = nil, + username: String? = nil, + password: String? = nil, + encryption: AppwriteEnums.SmtpEncryption? = nil, + autoTLS: Bool? = nil, + mailer: String? = nil, + fromName: String? = nil, + fromEmail: String? = nil, + replyToName: String? = nil, + replyToEmail: String? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/smtp" + + let apiParams: [String: Any?] = [ + "providerId": providerId, + "name": name, + "host": host, + "port": port, + "username": username, + "password": password, + "encryption": encryption, + "autoTLS": autoTLS, + "mailer": mailer, + "fromName": fromName, + "fromEmail": fromEmail, + "replyToName": replyToName, + "replyToEmail": replyToEmail, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update a SMTP provider by its unique ID. /// @@ -1251,6 +1634,7 @@ open class Messaging: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Provider /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Messaging.updateSMTPProvider` instead.") open func updateSmtpProvider( providerId: String, name: String? = nil, @@ -1303,6 +1687,79 @@ open class Messaging: Service { ) } + /// + /// Update a SMTP provider by its unique ID. + /// + /// - Parameters: + /// - providerId: String + /// - name: String (optional) + /// - host: String (optional) + /// - port: Int (optional) + /// - username: String (optional) + /// - password: String (optional) + /// - encryption: AppwriteEnums.SmtpEncryption (optional) + /// - autoTLS: Bool (optional) + /// - mailer: String (optional) + /// - fromName: String (optional) + /// - fromEmail: String (optional) + /// - replyToName: String (optional) + /// - replyToEmail: String (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Provider + /// + open func updateSMTPProvider( + providerId: String, + name: String? = nil, + host: String? = nil, + port: Int? = nil, + username: String? = nil, + password: String? = nil, + encryption: AppwriteEnums.SmtpEncryption? = nil, + autoTLS: Bool? = nil, + mailer: String? = nil, + fromName: String? = nil, + fromEmail: String? = nil, + replyToName: String? = nil, + replyToEmail: String? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Provider { + let apiPath: String = "/messaging/providers/smtp/{providerId}" + .replacingOccurrences(of: "{providerId}", with: providerId) + + let apiParams: [String: Any?] = [ + "name": name, + "host": host, + "port": port, + "username": username, + "password": password, + "encryption": encryption, + "autoTLS": autoTLS, + "mailer": mailer, + "fromName": fromName, + "fromEmail": fromEmail, + "replyToName": replyToName, + "replyToEmail": replyToEmail, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Provider = { response in + return AppwriteModels.Provider.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Create a new Telesign provider. /// diff --git a/Sources/Appwrite/Services/TablesDb.swift b/Sources/Appwrite/Services/TablesDb.swift new file mode 100644 index 0000000..e1c3790 --- /dev/null +++ b/Sources/Appwrite/Services/TablesDb.swift @@ -0,0 +1,2564 @@ +import AsyncHTTPClient +import Foundation +import NIO +import JSONCodable +import AppwriteEnums +import AppwriteModels + +/// +open class TablesDB: Service { + + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + /// + /// - Parameters: + /// - queries: [String] (optional) + /// - search: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.DatabaseList + /// + open func list( + queries: [String]? = nil, + search: String? = nil + ) async throws -> AppwriteModels.DatabaseList { + let apiPath: String = "/tablesdb" + + let apiParams: [String: Any?] = [ + "queries": queries, + "search": search + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.DatabaseList = { response in + return AppwriteModels.DatabaseList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a new Database. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - name: String + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Database + /// + open func create( + databaseId: String, + name: String, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Database { + let apiPath: String = "/tablesdb" + + let apiParams: [String: Any?] = [ + "databaseId": databaseId, + "name": name, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Database = { response in + return AppwriteModels.Database.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + /// + /// - Parameters: + /// - databaseId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Database + /// + open func get( + databaseId: String + ) async throws -> AppwriteModels.Database { + let apiPath: String = "/tablesdb/{databaseId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Database = { response in + return AppwriteModels.Database.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a database by its unique ID. + /// + /// - Parameters: + /// - databaseId: String + /// - name: String + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Database + /// + open func update( + databaseId: String, + name: String, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Database { + let apiPath: String = "/tablesdb/{databaseId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + + let apiParams: [String: Any?] = [ + "name": name, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Database = { response in + return AppwriteModels.Database.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + /// + /// - Parameters: + /// - databaseId: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func delete( + databaseId: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Get a list of all tables that belong to the provided databaseId. You can + /// use the search parameter to filter your results. + /// + /// - Parameters: + /// - databaseId: String + /// - queries: [String] (optional) + /// - search: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.TableList + /// + open func listTables( + databaseId: String, + queries: [String]? = nil, + search: String? = nil + ) async throws -> AppwriteModels.TableList { + let apiPath: String = "/tablesdb/{databaseId}/tables" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + + let apiParams: [String: Any?] = [ + "queries": queries, + "search": search + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.TableList = { response in + return AppwriteModels.TableList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a new Table. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - name: String + /// - permissions: [String] (optional) + /// - rowSecurity: Bool (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Table + /// + open func createTable( + databaseId: String, + tableId: String, + name: String, + permissions: [String]? = nil, + rowSecurity: Bool? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Table { + let apiPath: String = "/tablesdb/{databaseId}/tables" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + + let apiParams: [String: Any?] = [ + "tableId": tableId, + "name": name, + "permissions": permissions, + "rowSecurity": rowSecurity, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Table = { response in + return AppwriteModels.Table.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a table by its unique ID. This endpoint response returns a JSON object + /// with the table metadata. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Table + /// + open func getTable( + databaseId: String, + tableId: String + ) async throws -> AppwriteModels.Table { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Table = { response in + return AppwriteModels.Table.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a table by its unique ID. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - name: String + /// - permissions: [String] (optional) + /// - rowSecurity: Bool (optional) + /// - enabled: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Table + /// + open func updateTable( + databaseId: String, + tableId: String, + name: String, + permissions: [String]? = nil, + rowSecurity: Bool? = nil, + enabled: Bool? = nil + ) async throws -> AppwriteModels.Table { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "name": name, + "permissions": permissions, + "rowSecurity": rowSecurity, + "enabled": enabled + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Table = { response in + return AppwriteModels.Table.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Delete a table by its unique ID. Only users with write permissions have + /// access to delete this resource. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteTable( + databaseId: String, + tableId: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// List columns in the table. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnList + /// + open func listColumns( + databaseId: String, + tableId: String, + queries: [String]? = nil + ) async throws -> AppwriteModels.ColumnList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.ColumnList = { response in + return AppwriteModels.ColumnList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a boolean column. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: Bool (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnBoolean + /// + open func createBooleanColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: Bool? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnBoolean { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/boolean" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnBoolean = { response in + return AppwriteModels.ColumnBoolean.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a boolean column. Changing the `default` value will not update + /// already existing rows. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: Bool (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnBoolean + /// + open func updateBooleanColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: Bool? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnBoolean { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/boolean/{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.ColumnBoolean = { response in + return AppwriteModels.ColumnBoolean.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a date time column according to the ISO 8601 standard. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnDatetime + /// + open func createDatetimeColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnDatetime { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/datetime" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnDatetime = { response in + return AppwriteModels.ColumnDatetime.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a date time column. Changing the `default` value will not update + /// already existing rows. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnDatetime + /// + open func updateDatetimeColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnDatetime { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/datetime/{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.ColumnDatetime = { response in + return AppwriteModels.ColumnDatetime.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create an email column. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnEmail + /// + open func createEmailColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnEmail { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/email" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnEmail = { response in + return AppwriteModels.ColumnEmail.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update an email column. Changing the `default` value will not update + /// already existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnEmail + /// + open func updateEmailColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnEmail { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/email/{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.ColumnEmail = { response in + return AppwriteModels.ColumnEmail.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create an enumeration column. The `elements` param acts as a white-list of + /// accepted values for this column. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - elements: [String] + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnEnum + /// + open func createEnumColumn( + databaseId: String, + tableId: String, + key: String, + elements: [String], + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnEnum { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/enum" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "elements": elements, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnEnum = { response in + return AppwriteModels.ColumnEnum.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update an enum column. Changing the `default` value will not update already + /// existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - elements: [String] + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnEnum + /// + open func updateEnumColumn( + databaseId: String, + tableId: String, + key: String, + elements: [String], + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnEnum { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/enum/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "elements": elements, + "required": `required`, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnEnum = { response in + return AppwriteModels.ColumnEnum.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a float column. Optionally, minimum and maximum values can be + /// provided. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - min: Double (optional) + /// - max: Double (optional) + /// - default: Double (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnFloat + /// + open func createFloatColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + min: Double? = nil, + max: Double? = nil, + `default`: Double? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnFloat { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/float" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "min": min, + "max": max, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnFloat = { response in + return AppwriteModels.ColumnFloat.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a float column. Changing the `default` value will not update already + /// existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: Double (optional) + /// - min: Double (optional) + /// - max: Double (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnFloat + /// + open func updateFloatColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: Double? = nil, + min: Double? = nil, + max: Double? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnFloat { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/float/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "min": min, + "max": max, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnFloat = { response in + return AppwriteModels.ColumnFloat.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create an integer column. Optionally, minimum and maximum values can be + /// provided. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - min: Int (optional) + /// - max: Int (optional) + /// - default: Int (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnInteger + /// + open func createIntegerColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + min: Int? = nil, + max: Int? = nil, + `default`: Int? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnInteger { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/integer" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "min": min, + "max": max, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnInteger = { response in + return AppwriteModels.ColumnInteger.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update an integer column. Changing the `default` value will not update + /// already existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: Int (optional) + /// - min: Int (optional) + /// - max: Int (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnInteger + /// + open func updateIntegerColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: Int? = nil, + min: Int? = nil, + max: Int? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnInteger { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/integer/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "min": min, + "max": max, + "default": `default`, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnInteger = { response in + return AppwriteModels.ColumnInteger.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create IP address column. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnIp + /// + open func createIpColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnIp { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/ip" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnIp = { response in + return AppwriteModels.ColumnIp.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update an ip column. Changing the `default` value will not update already + /// existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnIp + /// + open func updateIpColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnIp { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/ip/{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.ColumnIp = { response in + return AppwriteModels.ColumnIp.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). + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - relatedTableId: String + /// - type: AppwriteEnums.RelationshipType + /// - twoWay: Bool (optional) + /// - key: String (optional) + /// - twoWayKey: String (optional) + /// - onDelete: AppwriteEnums.RelationMutate (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnRelationship + /// + open func createRelationshipColumn( + databaseId: String, + tableId: String, + relatedTableId: String, + type: AppwriteEnums.RelationshipType, + twoWay: Bool? = nil, + key: String? = nil, + twoWayKey: String? = nil, + onDelete: AppwriteEnums.RelationMutate? = nil + ) async throws -> AppwriteModels.ColumnRelationship { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/relationship" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "relatedTableId": relatedTableId, + "type": type, + "twoWay": twoWay, + "key": key, + "twoWayKey": twoWayKey, + "onDelete": onDelete + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnRelationship = { response in + return AppwriteModels.ColumnRelationship.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a string column. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - size: Int + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - encrypt: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnString + /// + open func createStringColumn( + databaseId: String, + tableId: String, + key: String, + size: Int, + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil, + encrypt: Bool? = nil + ) async throws -> AppwriteModels.ColumnString { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/string" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "size": size, + "required": `required`, + "default": `default`, + "array": array, + "encrypt": encrypt + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnString = { response in + return AppwriteModels.ColumnString.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a string column. Changing the `default` value will not update + /// already existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - size: Int (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnString + /// + open func updateStringColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + size: Int? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnString { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/string/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "required": `required`, + "default": `default`, + "size": size, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnString = { response in + return AppwriteModels.ColumnString.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a URL column. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - array: Bool (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnUrl + /// + open func createUrlColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + array: Bool? = nil + ) async throws -> AppwriteModels.ColumnUrl { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/url" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "required": `required`, + "default": `default`, + "array": array + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnUrl = { response in + return AppwriteModels.ColumnUrl.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update an url column. Changing the `default` value will not update already + /// existing rows. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - required: Bool + /// - default: String (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnUrl + /// + open func updateUrlColumn( + databaseId: String, + tableId: String, + key: String, + `required`: Bool, + `default`: String? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnUrl { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/url/{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.ColumnUrl = { response in + return AppwriteModels.ColumnUrl.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get column by ID. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func getColumn( + databaseId: String, + tableId: String, + key: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Deletes a column. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteColumn( + databaseId: String, + tableId: String, + key: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Update relationship column. [Learn more about relationship + /// columns](https://appwrite.io/docs/databases-relationships#relationship-columns). + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - onDelete: AppwriteEnums.RelationMutate (optional) + /// - newKey: String (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnRelationship + /// + open func updateRelationshipColumn( + databaseId: String, + tableId: String, + key: String, + onDelete: AppwriteEnums.RelationMutate? = nil, + newKey: String? = nil + ) async throws -> AppwriteModels.ColumnRelationship { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/columns/{key}/relationship" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any?] = [ + "onDelete": onDelete, + "newKey": newKey + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnRelationship = { response in + return AppwriteModels.ColumnRelationship.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// List indexes on the table. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnIndexList + /// + open func listIndexes( + databaseId: String, + tableId: String, + queries: [String]? = nil + ) async throws -> AppwriteModels.ColumnIndexList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/indexes" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.ColumnIndexList = { response in + return AppwriteModels.ColumnIndexList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Creates an index on the columns listed. Your index should include all the + /// columns you will query in a single request. + /// Type can be `key`, `fulltext`, or `unique`. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - type: AppwriteEnums.IndexType + /// - columns: [String] + /// - orders: [String] (optional) + /// - lengths: [Int] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnIndex + /// + open func createIndex( + databaseId: String, + tableId: String, + key: String, + type: AppwriteEnums.IndexType, + columns: [String], + orders: [String]? = nil, + lengths: [Int]? = nil + ) async throws -> AppwriteModels.ColumnIndex { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/indexes" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "key": key, + "type": type, + "columns": columns, + "orders": orders, + "lengths": lengths + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.ColumnIndex = { response in + return AppwriteModels.ColumnIndex.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get index by ID. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.ColumnIndex + /// + open func getIndex( + databaseId: String, + tableId: String, + key: String + ) async throws -> AppwriteModels.ColumnIndex { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/indexes/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.ColumnIndex = { response in + return AppwriteModels.ColumnIndex.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Delete an index. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - key: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteIndex( + databaseId: String, + tableId: String, + key: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/indexes/{key}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{key}", with: key) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Get a list of all the user's rows in a given table. You can use the query + /// params to filter your results. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func listRows( + databaseId: String, + tableId: String, + queries: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.RowList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.RowList = { response in + return AppwriteModels.RowList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a list of all the user's rows in a given table. You can use the query + /// params to filter your results. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func listRows( + databaseId: String, + tableId: String, + queries: [String]? = nil + ) async throws -> AppwriteModels.RowList<[String: AnyCodable]> { + return try await listRows( + databaseId: databaseId, + tableId: tableId, + queries: queries, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Create a new Row. Before using this route, you should create a new table + /// resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func createRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any, + permissions: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "rowId": rowId, + "data": data, + "permissions": permissions + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create a new Row. Before using this route, you should create a new table + /// resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func createRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any, + permissions: [String]? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await createRow( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + data: data, + permissions: permissions, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Create new Rows. Before using this route, you should create a new table + /// resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rows: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func createRows( + databaseId: String, + tableId: String, + rows: [Any], + nestedType: T.Type + ) async throws -> AppwriteModels.RowList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "rows": rows + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.RowList = { response in + return AppwriteModels.RowList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create new Rows. Before using this route, you should create a new table + /// resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rows: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func createRows( + databaseId: String, + tableId: String, + rows: [Any] + ) async throws -> AppwriteModels.RowList<[String: AnyCodable]> { + return try await createRows( + databaseId: databaseId, + tableId: tableId, + rows: rows, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Create or update Rows. Before using this route, you should create a new + /// table resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rows: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func upsertRows( + databaseId: String, + tableId: String, + rows: [Any], + nestedType: T.Type + ) async throws -> AppwriteModels.RowList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "rows": rows + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.RowList = { response in + return AppwriteModels.RowList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create or update Rows. Before using this route, you should create a new + /// table resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rows: [Any] + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func upsertRows( + databaseId: String, + tableId: String, + rows: [Any] + ) async throws -> AppwriteModels.RowList<[String: AnyCodable]> { + return try await upsertRows( + databaseId: databaseId, + tableId: tableId, + rows: rows, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Update all rows that match your queries, if no queries are submitted then + /// all rows are updated. You can pass only specific fields to be updated. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - data: Any (optional) + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func updateRows( + databaseId: String, + tableId: String, + data: Any? = nil, + queries: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.RowList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "data": data, + "queries": queries + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.RowList = { response in + return AppwriteModels.RowList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update all rows that match your queries, if no queries are submitted then + /// all rows are updated. You can pass only specific fields to be updated. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - data: Any (optional) + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func updateRows( + databaseId: String, + tableId: String, + data: Any? = nil, + queries: [String]? = nil + ) async throws -> AppwriteModels.RowList<[String: AnyCodable]> { + return try await updateRows( + databaseId: databaseId, + tableId: tableId, + data: data, + queries: queries, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Bulk delete rows using queries, if no queries are passed then all rows are + /// deleted. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func deleteRows( + databaseId: String, + tableId: String, + queries: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.RowList { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.RowList = { response in + return AppwriteModels.RowList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Bulk delete rows using queries, if no queries are passed then all rows are + /// deleted. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.RowList + /// + open func deleteRows( + databaseId: String, + tableId: String, + queries: [String]? = nil + ) async throws -> AppwriteModels.RowList<[String: AnyCodable]> { + return try await deleteRows( + databaseId: databaseId, + tableId: tableId, + queries: queries, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Get a row by its unique ID. This endpoint response returns a JSON object + /// with the row data. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func getRow( + databaseId: String, + tableId: String, + rowId: String, + queries: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + + let apiParams: [String: Any?] = [ + "queries": queries + ] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Get a row by its unique ID. This endpoint response returns a JSON object + /// with the row data. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - queries: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func getRow( + databaseId: String, + tableId: String, + rowId: String, + queries: [String]? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await getRow( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + queries: queries, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Create or update a Row. Before using this route, you should create a new + /// table resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func upsertRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any? = nil, + permissions: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + + let apiParams: [String: Any?] = [ + "data": data, + "permissions": permissions + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Create or update a Row. Before using this route, you should create a new + /// table resource using either a [server + /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// API or directly from your database console. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func upsertRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any? = nil, + permissions: [String]? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await upsertRow( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + data: data, + permissions: permissions, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Update a row by its unique ID. Using the patch method you can pass only + /// specific fields that will get updated. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func updateRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any? = nil, + permissions: [String]? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + + let apiParams: [String: Any?] = [ + "data": data, + "permissions": permissions + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Update a row by its unique ID. Using the patch method you can pass only + /// specific fields that will get updated. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - data: Any (optional) + /// - permissions: [String] (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func updateRow( + databaseId: String, + tableId: String, + rowId: String, + data: Any? = nil, + permissions: [String]? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await updateRow( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + data: data, + permissions: permissions, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Delete a row by its unique ID. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteRow( + databaseId: String, + tableId: String, + rowId: String + ) async throws -> Any { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + + /// + /// Decrement a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - column: String + /// - value: Double (optional) + /// - min: Double (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func decrementRowColumn( + databaseId: String, + tableId: String, + rowId: String, + column: String, + value: Double? = nil, + min: Double? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/decrement" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + .replacingOccurrences(of: "{column}", with: column) + + let apiParams: [String: Any?] = [ + "value": value, + "min": min + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Decrement a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - column: String + /// - value: Double (optional) + /// - min: Double (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func decrementRowColumn( + databaseId: String, + tableId: String, + rowId: String, + column: String, + value: Double? = nil, + min: Double? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await decrementRowColumn( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + column: column, + value: value, + min: min, + nestedType: [String: AnyCodable].self + ) + } + + /// + /// Increment a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - column: String + /// - value: Double (optional) + /// - max: Double (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func incrementRowColumn( + databaseId: String, + tableId: String, + rowId: String, + column: String, + value: Double? = nil, + max: Double? = nil, + nestedType: T.Type + ) async throws -> AppwriteModels.Row { + let apiPath: String = "/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}/{column}/increment" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{tableId}", with: tableId) + .replacingOccurrences(of: "{rowId}", with: rowId) + .replacingOccurrences(of: "{column}", with: column) + + let apiParams: [String: Any?] = [ + "value": value, + "max": max + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Row = { response in + return AppwriteModels.Row.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Increment a specific column of a row by a given value. + /// + /// - Parameters: + /// - databaseId: String + /// - tableId: String + /// - rowId: String + /// - column: String + /// - value: Double (optional) + /// - max: Double (optional) + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Row + /// + open func incrementRowColumn( + databaseId: String, + tableId: String, + rowId: String, + column: String, + value: Double? = nil, + max: Double? = nil + ) async throws -> AppwriteModels.Row<[String: AnyCodable]> { + return try await incrementRowColumn( + databaseId: databaseId, + tableId: tableId, + rowId: rowId, + column: column, + value: value, + max: max, + nestedType: [String: AnyCodable].self + ) + } + + +} \ No newline at end of file diff --git a/Sources/Appwrite/Services/Users.swift b/Sources/Appwrite/Services/Users.swift index a2d3d6b..e1ea976 100644 --- a/Sources/Appwrite/Services/Users.swift +++ b/Sources/Appwrite/Services/Users.swift @@ -1123,6 +1123,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.User /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.updateMFA` instead.") open func updateMfa( userId: String, mfa: Bool, @@ -1161,6 +1162,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.User /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.updateMFA` instead.") open func updateMfa( userId: String, mfa: Bool @@ -1172,6 +1174,64 @@ open class Users: Service { ) } + /// + /// Enable or disable MFA on a user account. + /// + /// - Parameters: + /// - userId: String + /// - mfa: Bool + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.User + /// + open func updateMFA( + userId: String, + mfa: Bool, + nestedType: T.Type + ) async throws -> AppwriteModels.User { + let apiPath: String = "/users/{userId}/mfa" + .replacingOccurrences(of: "{userId}", with: userId) + + let apiParams: [String: Any?] = [ + "mfa": mfa + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.User = { response in + return AppwriteModels.User.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// Enable or disable MFA on a user account. + /// + /// - Parameters: + /// - userId: String + /// - mfa: Bool + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.User + /// + open func updateMFA( + userId: String, + mfa: Bool + ) async throws -> AppwriteModels.User<[String: AnyCodable]> { + return try await updateMFA( + userId: userId, + mfa: mfa, + nestedType: [String: AnyCodable].self + ) + } + /// /// Delete an authenticator app. /// @@ -1181,6 +1241,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: Any /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.deleteMFAAuthenticator` instead.") open func deleteMfaAuthenticator( userId: String, type: AppwriteEnums.AuthenticatorType @@ -1202,6 +1263,36 @@ open class Users: Service { params: apiParams ) } + /// + /// Delete an authenticator app. + /// + /// - Parameters: + /// - userId: String + /// - type: AppwriteEnums.AuthenticatorType + /// - Throws: Exception if the request fails + /// - Returns: Any + /// + open func deleteMFAAuthenticator( + userId: String, + type: AppwriteEnums.AuthenticatorType + ) async throws -> Any { + let apiPath: String = "/users/{userId}/mfa/authenticators/{type}" + .replacingOccurrences(of: "{userId}", with: userId) + .replacingOccurrences(of: "{type}", with: type.rawValue) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await client.call( + method: "DELETE", + path: apiPath, + headers: apiHeaders, + params: apiParams ) + } + /// /// List the factors available on the account to be used as a MFA challange. /// @@ -1210,6 +1301,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaFactors /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.listMFAFactors` instead.") open func listMfaFactors( userId: String ) async throws -> AppwriteModels.MfaFactors { @@ -1233,6 +1325,37 @@ open class Users: Service { ) } + /// + /// List the factors available on the account to be used as a MFA challange. + /// + /// - Parameters: + /// - userId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaFactors + /// + open func listMFAFactors( + userId: String + ) async throws -> AppwriteModels.MfaFactors { + let apiPath: String = "/users/{userId}/mfa/factors" + .replacingOccurrences(of: "{userId}", with: userId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.MfaFactors = { response in + return AppwriteModels.MfaFactors.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Get recovery codes that can be used as backup for MFA flow by User ID. /// Before getting codes, they must be generated using @@ -1244,6 +1367,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.getMFARecoveryCodes` instead.") open func getMfaRecoveryCodes( userId: String ) async throws -> AppwriteModels.MfaRecoveryCodes { @@ -1267,6 +1391,40 @@ open class Users: Service { ) } + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + /// + /// - Parameters: + /// - userId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func getMFARecoveryCodes( + userId: String + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/users/{userId}/mfa/recovery-codes" + .replacingOccurrences(of: "{userId}", with: userId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [:] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "GET", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Regenerate recovery codes that can be used as backup for MFA flow by User /// ID. Before regenerating codes, they must be first generated using @@ -1278,6 +1436,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.updateMFARecoveryCodes` instead.") open func updateMfaRecoveryCodes( userId: String ) async throws -> AppwriteModels.MfaRecoveryCodes { @@ -1303,6 +1462,42 @@ open class Users: Service { ) } + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + /// + /// - Parameters: + /// - userId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func updateMFARecoveryCodes( + userId: String + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/users/{userId}/mfa/recovery-codes" + .replacingOccurrences(of: "{userId}", with: userId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Generate recovery codes used as backup for MFA flow for User ID. Recovery /// codes can be used as a MFA verification type in @@ -1314,6 +1509,7 @@ open class Users: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.MfaRecoveryCodes /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Users.createMFARecoveryCodes` instead.") open func createMfaRecoveryCodes( userId: String ) async throws -> AppwriteModels.MfaRecoveryCodes { @@ -1339,6 +1535,42 @@ open class Users: Service { ) } + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + /// + /// - Parameters: + /// - userId: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.MfaRecoveryCodes + /// + open func createMFARecoveryCodes( + userId: String + ) async throws -> AppwriteModels.MfaRecoveryCodes { + let apiPath: String = "/users/{userId}/mfa/recovery-codes" + .replacingOccurrences(of: "{userId}", with: userId) + + let apiParams: [String: Any] = [:] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.MfaRecoveryCodes = { response in + return AppwriteModels.MfaRecoveryCodes.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PATCH", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + /// /// Update the user name by its unique ID. /// diff --git a/Sources/AppwriteModels/AttributeBoolean.swift b/Sources/AppwriteModels/AttributeBoolean.swift index feb0462..ffc9325 100644 --- a/Sources/AppwriteModels/AttributeBoolean.swift +++ b/Sources/AppwriteModels/AttributeBoolean.swift @@ -100,11 +100,11 @@ open class AttributeBoolean: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeDatetime.swift b/Sources/AppwriteModels/AttributeDatetime.swift index 6922821..1aca4c2 100644 --- a/Sources/AppwriteModels/AttributeDatetime.swift +++ b/Sources/AppwriteModels/AttributeDatetime.swift @@ -108,12 +108,12 @@ open class AttributeDatetime: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "format": format as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeEmail.swift b/Sources/AppwriteModels/AttributeEmail.swift index a8aa6d2..1b8bd3f 100644 --- a/Sources/AppwriteModels/AttributeEmail.swift +++ b/Sources/AppwriteModels/AttributeEmail.swift @@ -108,12 +108,12 @@ open class AttributeEmail: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "format": format as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeEnum.swift b/Sources/AppwriteModels/AttributeEnum.swift index e5f3482..7de4bc0 100644 --- a/Sources/AppwriteModels/AttributeEnum.swift +++ b/Sources/AppwriteModels/AttributeEnum.swift @@ -116,13 +116,13 @@ open class AttributeEnum: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "elements": elements as Any, "format": format as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeFloat.swift b/Sources/AppwriteModels/AttributeFloat.swift index fceef5f..e57a8c1 100644 --- a/Sources/AppwriteModels/AttributeFloat.swift +++ b/Sources/AppwriteModels/AttributeFloat.swift @@ -116,13 +116,13 @@ open class AttributeFloat: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "min": min as Any, "max": max as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeInteger.swift b/Sources/AppwriteModels/AttributeInteger.swift index acb5d36..f3251b7 100644 --- a/Sources/AppwriteModels/AttributeInteger.swift +++ b/Sources/AppwriteModels/AttributeInteger.swift @@ -116,13 +116,13 @@ open class AttributeInteger: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "min": min as Any, "max": max as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeIp.swift b/Sources/AppwriteModels/AttributeIp.swift index 47b46de..b4f628d 100644 --- a/Sources/AppwriteModels/AttributeIp.swift +++ b/Sources/AppwriteModels/AttributeIp.swift @@ -108,12 +108,12 @@ open class AttributeIp: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "format": format as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/AttributeRelationship.swift b/Sources/AppwriteModels/AttributeRelationship.swift index c7c38d7..6a973aa 100644 --- a/Sources/AppwriteModels/AttributeRelationship.swift +++ b/Sources/AppwriteModels/AttributeRelationship.swift @@ -140,7 +140,7 @@ open class AttributeRelationship: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, diff --git a/Sources/AppwriteModels/AttributeString.swift b/Sources/AppwriteModels/AttributeString.swift index b7da6a8..b9d352b 100644 --- a/Sources/AppwriteModels/AttributeString.swift +++ b/Sources/AppwriteModels/AttributeString.swift @@ -116,12 +116,12 @@ open class AttributeString: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "size": size as Any, - "`default`": `default` as Any, + "default": `default` as Any, "encrypt": encrypt as Any ] } diff --git a/Sources/AppwriteModels/AttributeUrl.swift b/Sources/AppwriteModels/AttributeUrl.swift index b45607b..b6a7a41 100644 --- a/Sources/AppwriteModels/AttributeUrl.swift +++ b/Sources/AppwriteModels/AttributeUrl.swift @@ -108,12 +108,12 @@ open class AttributeUrl: Codable { "type": type as Any, "status": status as Any, "error": error as Any, - "`required`": `required` as Any, + "required": `required` as Any, "array": array as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, "format": format as Any, - "`default`": `default` as Any + "default": `default` as Any ] } diff --git a/Sources/AppwriteModels/BucketList.swift b/Sources/AppwriteModels/BucketList.swift index 8fca4e4..b302f36 100644 --- a/Sources/AppwriteModels/BucketList.swift +++ b/Sources/AppwriteModels/BucketList.swift @@ -9,7 +9,7 @@ open class BucketList: Codable { case buckets = "buckets" } - /// Total number of buckets documents that matched your query. + /// Total number of buckets that matched your query. public let total: Int /// List of buckets. diff --git a/Sources/AppwriteModels/CollectionList.swift b/Sources/AppwriteModels/CollectionList.swift index f5f383f..b078619 100644 --- a/Sources/AppwriteModels/CollectionList.swift +++ b/Sources/AppwriteModels/CollectionList.swift @@ -9,7 +9,7 @@ open class CollectionList: Codable { case collections = "collections" } - /// Total number of collections documents that matched your query. + /// Total number of collections that matched your query. public let total: Int /// List of collections. diff --git a/Sources/AppwriteModels/ColumnBoolean.swift b/Sources/AppwriteModels/ColumnBoolean.swift new file mode 100644 index 0000000..8a73ca0 --- /dev/null +++ b/Sources/AppwriteModels/ColumnBoolean.swift @@ -0,0 +1,124 @@ +import Foundation +import JSONCodable + +/// ColumnBoolean +open class ColumnBoolean: 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`: Bool? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + `default`: Bool? + ) { + 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(Bool.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] ) -> ColumnBoolean { + return ColumnBoolean( + 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? Bool + ) + } +} diff --git a/Sources/AppwriteModels/ColumnDatetime.swift b/Sources/AppwriteModels/ColumnDatetime.swift new file mode 100644 index 0000000..00cdc6d --- /dev/null +++ b/Sources/AppwriteModels/ColumnDatetime.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// ColumnDatetime +open class ColumnDatetime: 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 format = "format" + 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 + + /// ISO 8601 format. + public let format: String + + /// Default value for column when not provided. Only null is optional + public let `default`: String? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + format: String, + `default`: String? + ) { + 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.format = format + 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.format = try container.decode(String.self, forKey: .format) + self.`default` = try container.decodeIfPresent(String.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.encode(format, forKey: .format) + 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, + "format": format as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnDatetime { + return ColumnDatetime( + 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, + format: map["format"] as! String, + default: map["default"] as? String + ) + } +} diff --git a/Sources/AppwriteModels/ColumnEmail.swift b/Sources/AppwriteModels/ColumnEmail.swift new file mode 100644 index 0000000..940062e --- /dev/null +++ b/Sources/AppwriteModels/ColumnEmail.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// ColumnEmail +open class ColumnEmail: 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 format = "format" + 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 + + /// String format. + public let format: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: String? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + format: String, + `default`: String? + ) { + 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.format = format + 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.format = try container.decode(String.self, forKey: .format) + self.`default` = try container.decodeIfPresent(String.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.encode(format, forKey: .format) + 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, + "format": format as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnEmail { + return ColumnEmail( + 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, + format: map["format"] as! String, + default: map["default"] as? String + ) + } +} diff --git a/Sources/AppwriteModels/ColumnEnum.swift b/Sources/AppwriteModels/ColumnEnum.swift new file mode 100644 index 0000000..ef78f80 --- /dev/null +++ b/Sources/AppwriteModels/ColumnEnum.swift @@ -0,0 +1,144 @@ +import Foundation +import JSONCodable + +/// ColumnEnum +open class ColumnEnum: 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 elements = "elements" + case format = "format" + 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 + + /// Array of elements in enumerated type. + public let elements: [String] + + /// String format. + public let format: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: String? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + elements: [String], + format: String, + `default`: String? + ) { + 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.elements = elements + self.format = format + 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.elements = try container.decode([String].self, forKey: .elements) + self.format = try container.decode(String.self, forKey: .format) + self.`default` = try container.decodeIfPresent(String.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.encode(elements, forKey: .elements) + try container.encode(format, forKey: .format) + 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, + "elements": elements as Any, + "format": format as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnEnum { + return ColumnEnum( + 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, + elements: map["elements"] as! [String], + format: map["format"] as! String, + default: map["default"] as? String + ) + } +} diff --git a/Sources/AppwriteModels/ColumnFloat.swift b/Sources/AppwriteModels/ColumnFloat.swift new file mode 100644 index 0000000..6cdd019 --- /dev/null +++ b/Sources/AppwriteModels/ColumnFloat.swift @@ -0,0 +1,144 @@ +import Foundation +import JSONCodable + +/// ColumnFloat +open class ColumnFloat: 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 min = "min" + case max = "max" + 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 + + /// Minimum value to enforce for new documents. + public let min: Double? + + /// Maximum value to enforce for new documents. + public let max: Double? + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: Double? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + min: Double?, + max: Double?, + `default`: Double? + ) { + 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.min = min + self.max = max + 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.min = try container.decodeIfPresent(Double.self, forKey: .min) + self.max = try container.decodeIfPresent(Double.self, forKey: .max) + self.`default` = try container.decodeIfPresent(Double.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(min, forKey: .min) + try container.encodeIfPresent(max, forKey: .max) + 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, + "min": min as Any, + "max": max as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnFloat { + return ColumnFloat( + 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, + min: map["min"] as? Double, + max: map["max"] as? Double, + default: map["default"] as? Double + ) + } +} diff --git a/Sources/AppwriteModels/ColumnIndex.swift b/Sources/AppwriteModels/ColumnIndex.swift new file mode 100644 index 0000000..c75fdb0 --- /dev/null +++ b/Sources/AppwriteModels/ColumnIndex.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// Index +open class ColumnIndex: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case key = "key" + case type = "type" + case status = "status" + case error = "error" + case columns = "columns" + case lengths = "lengths" + case orders = "orders" + } + + /// Index ID. + public let id: String + + /// Index creation date in ISO 8601 format. + public let createdAt: String + + /// Index update date in ISO 8601 format. + public let updatedAt: String + + /// Index Key. + public let key: String + + /// Index type. + public let type: String + + /// Index 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 index. + public let error: String + + /// Index columns. + public let columns: [String] + + /// Index columns length. + public let lengths: [Int] + + /// Index orders. + public let orders: [String]? + + + init( + id: String, + createdAt: String, + updatedAt: String, + key: String, + type: String, + status: String, + error: String, + columns: [String], + lengths: [Int], + orders: [String]? + ) { + self.id = id + self.createdAt = createdAt + self.updatedAt = updatedAt + self.key = key + self.type = type + self.status = status + self.error = error + self.columns = columns + self.lengths = lengths + self.orders = orders + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.id = try container.decode(String.self, forKey: .id) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + 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.columns = try container.decode([String].self, forKey: .columns) + self.lengths = try container.decode([Int].self, forKey: .lengths) + self.orders = try container.decodeIfPresent([String].self, forKey: .orders) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(id, forKey: .id) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + 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(columns, forKey: .columns) + try container.encode(lengths, forKey: .lengths) + try container.encodeIfPresent(orders, forKey: .orders) + } + + public func toMap() -> [String: Any] { + return [ + "$id": id as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "key": key as Any, + "type": type as Any, + "status": status as Any, + "error": error as Any, + "columns": columns as Any, + "lengths": lengths as Any, + "orders": orders as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnIndex { + return ColumnIndex( + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + key: map["key"] as! String, + type: map["type"] as! String, + status: map["status"] as! String, + error: map["error"] as! String, + columns: map["columns"] as! [String], + lengths: map["lengths"] as! [Int], + orders: map["orders"] as? [String] + ) + } +} diff --git a/Sources/AppwriteModels/ColumnIndexList.swift b/Sources/AppwriteModels/ColumnIndexList.swift new file mode 100644 index 0000000..476809c --- /dev/null +++ b/Sources/AppwriteModels/ColumnIndexList.swift @@ -0,0 +1,54 @@ +import Foundation +import JSONCodable + +/// Column Indexes List +open class ColumnIndexList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case indexes = "indexes" + } + + /// Total number of indexes that matched your query. + public let total: Int + + /// List of indexes. + public let indexes: [ColumnIndex] + + + init( + total: Int, + indexes: [ColumnIndex] + ) { + self.total = total + self.indexes = indexes + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.total = try container.decode(Int.self, forKey: .total) + self.indexes = try container.decode([ColumnIndex].self, forKey: .indexes) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(indexes, forKey: .indexes) + } + + public func toMap() -> [String: Any] { + return [ + "total": total as Any, + "indexes": indexes.map { $0.toMap() } as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnIndexList { + return ColumnIndexList( + total: map["total"] as! Int, + indexes: (map["indexes"] as! [[String: Any]]).map { ColumnIndex.from(map: $0) } + ) + } +} diff --git a/Sources/AppwriteModels/ColumnInteger.swift b/Sources/AppwriteModels/ColumnInteger.swift new file mode 100644 index 0000000..4451550 --- /dev/null +++ b/Sources/AppwriteModels/ColumnInteger.swift @@ -0,0 +1,144 @@ +import Foundation +import JSONCodable + +/// ColumnInteger +open class ColumnInteger: 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 min = "min" + case max = "max" + 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 + + /// Minimum value to enforce for new documents. + public let min: Int? + + /// Maximum value to enforce for new documents. + public let max: Int? + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: Int? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + min: Int?, + max: Int?, + `default`: Int? + ) { + 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.min = min + self.max = max + 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.min = try container.decodeIfPresent(Int.self, forKey: .min) + self.max = try container.decodeIfPresent(Int.self, forKey: .max) + self.`default` = try container.decodeIfPresent(Int.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(min, forKey: .min) + try container.encodeIfPresent(max, forKey: .max) + 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, + "min": min as Any, + "max": max as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnInteger { + return ColumnInteger( + 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, + min: map["min"] as? Int, + max: map["max"] as? Int, + default: map["default"] as? Int + ) + } +} diff --git a/Sources/AppwriteModels/ColumnIp.swift b/Sources/AppwriteModels/ColumnIp.swift new file mode 100644 index 0000000..43ddaee --- /dev/null +++ b/Sources/AppwriteModels/ColumnIp.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// ColumnIP +open class ColumnIp: 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 format = "format" + 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 + + /// String format. + public let format: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: String? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + format: String, + `default`: String? + ) { + 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.format = format + 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.format = try container.decode(String.self, forKey: .format) + self.`default` = try container.decodeIfPresent(String.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.encode(format, forKey: .format) + 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, + "format": format as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnIp { + return ColumnIp( + 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, + format: map["format"] as! String, + default: map["default"] as? String + ) + } +} diff --git a/Sources/AppwriteModels/ColumnList.swift b/Sources/AppwriteModels/ColumnList.swift new file mode 100644 index 0000000..dead6f0 --- /dev/null +++ b/Sources/AppwriteModels/ColumnList.swift @@ -0,0 +1,54 @@ +import Foundation +import JSONCodable + +/// Columns List +open class ColumnList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case columns = "columns" + } + + /// Total number of columns in the given table. + public let total: Int + + /// List of columns. + public let columns: [AnyCodable] + + + init( + total: Int, + columns: [AnyCodable] + ) { + self.total = total + self.columns = columns + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.total = try container.decode(Int.self, forKey: .total) + self.columns = try container.decode([AnyCodable].self, forKey: .columns) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(columns, forKey: .columns) + } + + public func toMap() -> [String: Any] { + return [ + "total": total as Any, + "columns": columns as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnList { + return ColumnList( + total: map["total"] as! Int, + columns: (map["columns"] as! [Any]).map { AnyCodable($0) } + ) + } +} diff --git a/Sources/AppwriteModels/ColumnRelationship.swift b/Sources/AppwriteModels/ColumnRelationship.swift new file mode 100644 index 0000000..b4c388c --- /dev/null +++ b/Sources/AppwriteModels/ColumnRelationship.swift @@ -0,0 +1,174 @@ +import Foundation +import JSONCodable + +/// ColumnRelationship +open class ColumnRelationship: 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 relatedTable = "relatedTable" + case relationType = "relationType" + case twoWay = "twoWay" + case twoWayKey = "twoWayKey" + case onDelete = "onDelete" + case side = "side" + } + + /// 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 + + /// The ID of the related table. + public let relatedTable: String + + /// The type of the relationship. + public let relationType: String + + /// Is the relationship two-way? + public let twoWay: Bool + + /// The key of the two-way relationship. + public let twoWayKey: String + + /// How deleting the parent document will propagate to child documents. + public let onDelete: String + + /// Whether this is the parent or child side of the relationship + public let side: String + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + relatedTable: String, + relationType: String, + twoWay: Bool, + twoWayKey: String, + onDelete: String, + side: String + ) { + 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.relatedTable = relatedTable + self.relationType = relationType + self.twoWay = twoWay + self.twoWayKey = twoWayKey + self.onDelete = onDelete + self.side = side + } + + 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.relatedTable = try container.decode(String.self, forKey: .relatedTable) + self.relationType = try container.decode(String.self, forKey: .relationType) + self.twoWay = try container.decode(Bool.self, forKey: .twoWay) + self.twoWayKey = try container.decode(String.self, forKey: .twoWayKey) + self.onDelete = try container.decode(String.self, forKey: .onDelete) + self.side = try container.decode(String.self, forKey: .side) + } + + 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.encode(relatedTable, forKey: .relatedTable) + try container.encode(relationType, forKey: .relationType) + try container.encode(twoWay, forKey: .twoWay) + try container.encode(twoWayKey, forKey: .twoWayKey) + try container.encode(onDelete, forKey: .onDelete) + try container.encode(side, forKey: .side) + } + + 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, + "relatedTable": relatedTable as Any, + "relationType": relationType as Any, + "twoWay": twoWay as Any, + "twoWayKey": twoWayKey as Any, + "onDelete": onDelete as Any, + "side": side as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnRelationship { + return ColumnRelationship( + 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, + relatedTable: map["relatedTable"] as! String, + relationType: map["relationType"] as! String, + twoWay: map["twoWay"] as! Bool, + twoWayKey: map["twoWayKey"] as! String, + onDelete: map["onDelete"] as! String, + side: map["side"] as! String + ) + } +} diff --git a/Sources/AppwriteModels/ColumnString.swift b/Sources/AppwriteModels/ColumnString.swift new file mode 100644 index 0000000..6dd146b --- /dev/null +++ b/Sources/AppwriteModels/ColumnString.swift @@ -0,0 +1,144 @@ +import Foundation +import JSONCodable + +/// ColumnString +open class ColumnString: 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 size = "size" + case `default` = "default" + case encrypt = "encrypt" + } + + /// 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 + + /// Column size. + public let size: Int + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: String? + + /// Defines whether this column is encrypted or not. + public let encrypt: Bool? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + size: Int, + `default`: String?, + encrypt: Bool? + ) { + 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.size = size + self.`default` = `default` + self.encrypt = encrypt + } + + 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.size = try container.decode(Int.self, forKey: .size) + self.`default` = try container.decodeIfPresent(String.self, forKey: .`default`) + self.encrypt = try container.decodeIfPresent(Bool.self, forKey: .encrypt) + } + + 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.encode(size, forKey: .size) + try container.encodeIfPresent(`default`, forKey: .`default`) + try container.encodeIfPresent(encrypt, forKey: .encrypt) + } + + 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, + "size": size as Any, + "default": `default` as Any, + "encrypt": encrypt as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnString { + return ColumnString( + 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, + size: map["size"] as! Int, + default: map["default"] as? String, + encrypt: map["encrypt"] as? Bool + ) + } +} diff --git a/Sources/AppwriteModels/ColumnUrl.swift b/Sources/AppwriteModels/ColumnUrl.swift new file mode 100644 index 0000000..29ef440 --- /dev/null +++ b/Sources/AppwriteModels/ColumnUrl.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// ColumnURL +open class ColumnUrl: 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 format = "format" + 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 + + /// String format. + public let format: String + + /// Default value for column when not provided. Cannot be set when column is required. + public let `default`: String? + + + init( + key: String, + type: String, + status: String, + error: String, + `required`: Bool, + array: Bool?, + createdAt: String, + updatedAt: String, + format: String, + `default`: String? + ) { + 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.format = format + 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.format = try container.decode(String.self, forKey: .format) + self.`default` = try container.decodeIfPresent(String.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.encode(format, forKey: .format) + 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, + "format": format as Any, + "default": `default` as Any + ] + } + + public static func from(map: [String: Any] ) -> ColumnUrl { + return ColumnUrl( + 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, + format: map["format"] as! String, + default: map["default"] as? String + ) + } +} diff --git a/Sources/AppwriteModels/ContinentList.swift b/Sources/AppwriteModels/ContinentList.swift index fa9a90f..0e697e7 100644 --- a/Sources/AppwriteModels/ContinentList.swift +++ b/Sources/AppwriteModels/ContinentList.swift @@ -9,7 +9,7 @@ open class ContinentList: Codable { case continents = "continents" } - /// Total number of continents documents that matched your query. + /// Total number of continents that matched your query. public let total: Int /// List of continents. diff --git a/Sources/AppwriteModels/CountryList.swift b/Sources/AppwriteModels/CountryList.swift index 865cc19..15a8d89 100644 --- a/Sources/AppwriteModels/CountryList.swift +++ b/Sources/AppwriteModels/CountryList.swift @@ -9,7 +9,7 @@ open class CountryList: Codable { case countries = "countries" } - /// Total number of countries documents that matched your query. + /// Total number of countries that matched your query. public let total: Int /// List of countries. diff --git a/Sources/AppwriteModels/CurrencyList.swift b/Sources/AppwriteModels/CurrencyList.swift index 1e0dff9..81d1c26 100644 --- a/Sources/AppwriteModels/CurrencyList.swift +++ b/Sources/AppwriteModels/CurrencyList.swift @@ -9,7 +9,7 @@ open class CurrencyList: Codable { case currencies = "currencies" } - /// Total number of currencies documents that matched your query. + /// Total number of currencies that matched your query. public let total: Int /// List of currencies. diff --git a/Sources/AppwriteModels/Database.swift b/Sources/AppwriteModels/Database.swift index c35c0b3..c3e5a10 100644 --- a/Sources/AppwriteModels/Database.swift +++ b/Sources/AppwriteModels/Database.swift @@ -10,6 +10,7 @@ open class Database: Codable { case createdAt = "$createdAt" case updatedAt = "$updatedAt" case enabled = "enabled" + case type = "type" } /// Database ID. @@ -27,19 +28,24 @@ open class Database: Codable { /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. public let enabled: Bool + /// Database type. + public let type: String + init( id: String, name: String, createdAt: String, updatedAt: String, - enabled: Bool + enabled: Bool, + type: String ) { self.id = id self.name = name self.createdAt = createdAt self.updatedAt = updatedAt self.enabled = enabled + self.type = type } public required init(from decoder: Decoder) throws { @@ -50,6 +56,7 @@ open class Database: Codable { self.createdAt = try container.decode(String.self, forKey: .createdAt) self.updatedAt = try container.decode(String.self, forKey: .updatedAt) self.enabled = try container.decode(Bool.self, forKey: .enabled) + self.type = try container.decode(String.self, forKey: .type) } public func encode(to encoder: Encoder) throws { @@ -60,6 +67,7 @@ open class Database: Codable { try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) try container.encode(enabled, forKey: .enabled) + try container.encode(type, forKey: .type) } public func toMap() -> [String: Any] { @@ -68,7 +76,8 @@ open class Database: Codable { "name": name as Any, "$createdAt": createdAt as Any, "$updatedAt": updatedAt as Any, - "enabled": enabled as Any + "enabled": enabled as Any, + "type": type as Any ] } @@ -78,7 +87,8 @@ open class Database: Codable { name: map["name"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - enabled: map["enabled"] as! Bool + enabled: map["enabled"] as! Bool, + type: map["type"] as! String ) } } diff --git a/Sources/AppwriteModels/DatabaseList.swift b/Sources/AppwriteModels/DatabaseList.swift index 588cbaa..57d9221 100644 --- a/Sources/AppwriteModels/DatabaseList.swift +++ b/Sources/AppwriteModels/DatabaseList.swift @@ -9,7 +9,7 @@ open class DatabaseList: Codable { case databases = "databases" } - /// Total number of databases documents that matched your query. + /// Total number of databases that matched your query. public let total: Int /// List of databases. diff --git a/Sources/AppwriteModels/DeploymentList.swift b/Sources/AppwriteModels/DeploymentList.swift index e218064..12b984b 100644 --- a/Sources/AppwriteModels/DeploymentList.swift +++ b/Sources/AppwriteModels/DeploymentList.swift @@ -9,7 +9,7 @@ open class DeploymentList: Codable { case deployments = "deployments" } - /// Total number of deployments documents that matched your query. + /// Total number of deployments that matched your query. public let total: Int /// List of deployments. diff --git a/Sources/AppwriteModels/DocumentList.swift b/Sources/AppwriteModels/DocumentList.swift index a129182..77f2679 100644 --- a/Sources/AppwriteModels/DocumentList.swift +++ b/Sources/AppwriteModels/DocumentList.swift @@ -9,7 +9,7 @@ open class DocumentList: Codable { case documents = "documents" } - /// Total number of documents documents that matched your query. + /// Total number of documents that matched your query. public let total: Int /// List of documents. diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index 6e81532..baaf71e 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -10,6 +10,7 @@ open class Execution: Codable { case updatedAt = "$updatedAt" case permissions = "$permissions" case functionId = "functionId" + case deploymentId = "deploymentId" case trigger = "trigger" case status = "status" case requestMethod = "requestMethod" @@ -30,7 +31,7 @@ open class Execution: Codable { /// Execution creation date in ISO 8601 format. public let createdAt: String - /// Execution upate date in ISO 8601 format. + /// Execution update date in ISO 8601 format. public let updatedAt: String /// Execution roles. @@ -39,6 +40,9 @@ open class Execution: Codable { /// Function ID. public let functionId: String + /// Function's deployment ID used to create the execution. + public let deploymentId: String + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. public let trigger: String @@ -82,6 +86,7 @@ open class Execution: Codable { updatedAt: String, permissions: [String], functionId: String, + deploymentId: String, trigger: String, status: String, requestMethod: String, @@ -100,6 +105,7 @@ open class Execution: Codable { self.updatedAt = updatedAt self.permissions = permissions self.functionId = functionId + self.deploymentId = deploymentId self.trigger = trigger self.status = status self.requestMethod = requestMethod @@ -122,6 +128,7 @@ open class Execution: Codable { self.updatedAt = try container.decode(String.self, forKey: .updatedAt) self.permissions = try container.decode([String].self, forKey: .permissions) self.functionId = try container.decode(String.self, forKey: .functionId) + self.deploymentId = try container.decode(String.self, forKey: .deploymentId) self.trigger = try container.decode(String.self, forKey: .trigger) self.status = try container.decode(String.self, forKey: .status) self.requestMethod = try container.decode(String.self, forKey: .requestMethod) @@ -144,6 +151,7 @@ open class Execution: Codable { try container.encode(updatedAt, forKey: .updatedAt) try container.encode(permissions, forKey: .permissions) try container.encode(functionId, forKey: .functionId) + try container.encode(deploymentId, forKey: .deploymentId) try container.encode(trigger, forKey: .trigger) try container.encode(status, forKey: .status) try container.encode(requestMethod, forKey: .requestMethod) @@ -165,6 +173,7 @@ open class Execution: Codable { "$updatedAt": updatedAt as Any, "$permissions": permissions as Any, "functionId": functionId as Any, + "deploymentId": deploymentId as Any, "trigger": trigger as Any, "status": status as Any, "requestMethod": requestMethod as Any, @@ -187,6 +196,7 @@ open class Execution: Codable { updatedAt: map["$updatedAt"] as! String, permissions: map["$permissions"] as! [String], functionId: map["functionId"] as! String, + deploymentId: map["deploymentId"] as! String, trigger: map["trigger"] as! String, status: map["status"] as! String, requestMethod: map["requestMethod"] as! String, diff --git a/Sources/AppwriteModels/ExecutionList.swift b/Sources/AppwriteModels/ExecutionList.swift index 72d43a6..c903b34 100644 --- a/Sources/AppwriteModels/ExecutionList.swift +++ b/Sources/AppwriteModels/ExecutionList.swift @@ -9,7 +9,7 @@ open class ExecutionList: Codable { case executions = "executions" } - /// Total number of executions documents that matched your query. + /// Total number of executions that matched your query. public let total: Int /// List of executions. diff --git a/Sources/AppwriteModels/FileList.swift b/Sources/AppwriteModels/FileList.swift index bec7b76..19d52a0 100644 --- a/Sources/AppwriteModels/FileList.swift +++ b/Sources/AppwriteModels/FileList.swift @@ -9,7 +9,7 @@ open class FileList: Codable { case files = "files" } - /// Total number of files documents that matched your query. + /// Total number of files that matched your query. public let total: Int /// List of files. diff --git a/Sources/AppwriteModels/FrameworkList.swift b/Sources/AppwriteModels/FrameworkList.swift index 7aa2ce7..cbe4ae3 100644 --- a/Sources/AppwriteModels/FrameworkList.swift +++ b/Sources/AppwriteModels/FrameworkList.swift @@ -9,7 +9,7 @@ open class FrameworkList: Codable { case frameworks = "frameworks" } - /// Total number of frameworks documents that matched your query. + /// Total number of frameworks that matched your query. public let total: Int /// List of frameworks. diff --git a/Sources/AppwriteModels/FunctionList.swift b/Sources/AppwriteModels/FunctionList.swift index c00badb..33604a5 100644 --- a/Sources/AppwriteModels/FunctionList.swift +++ b/Sources/AppwriteModels/FunctionList.swift @@ -9,7 +9,7 @@ open class FunctionList: Codable { case functions = "functions" } - /// Total number of functions documents that matched your query. + /// Total number of functions that matched your query. public let total: Int /// List of functions. diff --git a/Sources/AppwriteModels/IdentityList.swift b/Sources/AppwriteModels/IdentityList.swift index 6065fad..abcc362 100644 --- a/Sources/AppwriteModels/IdentityList.swift +++ b/Sources/AppwriteModels/IdentityList.swift @@ -9,7 +9,7 @@ open class IdentityList: Codable { case identities = "identities" } - /// Total number of identities documents that matched your query. + /// Total number of identities that matched your query. public let total: Int /// List of identities. diff --git a/Sources/AppwriteModels/Index.swift b/Sources/AppwriteModels/Index.swift index 7b5fb13..a2cc1c8 100644 --- a/Sources/AppwriteModels/Index.swift +++ b/Sources/AppwriteModels/Index.swift @@ -5,6 +5,9 @@ import JSONCodable open class Index: Codable { enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" case key = "key" case type = "type" case status = "status" @@ -12,11 +15,18 @@ open class Index: Codable { case attributes = "attributes" case lengths = "lengths" case orders = "orders" - case createdAt = "$createdAt" - case updatedAt = "$updatedAt" } - /// Index Key. + /// Index ID. + public let id: String + + /// Index creation date in ISO 8601 format. + public let createdAt: String + + /// Index update date in ISO 8601 format. + public let updatedAt: String + + /// Index key. public let key: String /// Index type. @@ -37,24 +47,22 @@ open class Index: Codable { /// Index orders. public let orders: [String]? - /// Index creation date in ISO 8601 format. - public let createdAt: String - - /// Index update date in ISO 8601 format. - public let updatedAt: String - init( + id: String, + createdAt: String, + updatedAt: String, key: String, type: String, status: String, error: String, attributes: [String], lengths: [Int], - orders: [String]?, - createdAt: String, - updatedAt: String + orders: [String]? ) { + self.id = id + self.createdAt = createdAt + self.updatedAt = updatedAt self.key = key self.type = type self.status = status @@ -62,13 +70,14 @@ open class Index: Codable { self.attributes = attributes self.lengths = lengths self.orders = orders - self.createdAt = createdAt - self.updatedAt = updatedAt } public required init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) + self.id = try container.decode(String.self, forKey: .id) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) 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) @@ -76,13 +85,14 @@ open class Index: Codable { self.attributes = try container.decode([String].self, forKey: .attributes) self.lengths = try container.decode([Int].self, forKey: .lengths) self.orders = try container.decodeIfPresent([String].self, forKey: .orders) - self.createdAt = try container.decode(String.self, forKey: .createdAt) - self.updatedAt = try container.decode(String.self, forKey: .updatedAt) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) try container.encode(key, forKey: .key) try container.encode(type, forKey: .type) try container.encode(status, forKey: .status) @@ -90,35 +100,35 @@ open class Index: Codable { try container.encode(attributes, forKey: .attributes) try container.encode(lengths, forKey: .lengths) try container.encodeIfPresent(orders, forKey: .orders) - try container.encode(createdAt, forKey: .createdAt) - try container.encode(updatedAt, forKey: .updatedAt) } public func toMap() -> [String: Any] { return [ + "$id": id as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, "key": key as Any, "type": type as Any, "status": status as Any, "error": error as Any, "attributes": attributes as Any, "lengths": lengths as Any, - "orders": orders as Any, - "$createdAt": createdAt as Any, - "$updatedAt": updatedAt as Any + "orders": orders as Any ] } public static func from(map: [String: Any] ) -> Index { return Index( + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, key: map["key"] as! String, type: map["type"] as! String, status: map["status"] as! String, error: map["error"] as! String, attributes: map["attributes"] as! [String], lengths: map["lengths"] as! [Int], - orders: map["orders"] as? [String], - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String + orders: map["orders"] as? [String] ) } } diff --git a/Sources/AppwriteModels/IndexList.swift b/Sources/AppwriteModels/IndexList.swift index 2f3ae30..52fa458 100644 --- a/Sources/AppwriteModels/IndexList.swift +++ b/Sources/AppwriteModels/IndexList.swift @@ -9,7 +9,7 @@ open class IndexList: Codable { case indexes = "indexes" } - /// Total number of indexes documents that matched your query. + /// Total number of indexes that matched your query. public let total: Int /// List of indexes. diff --git a/Sources/AppwriteModels/LanguageList.swift b/Sources/AppwriteModels/LanguageList.swift index 13c6e4a..2b1f03c 100644 --- a/Sources/AppwriteModels/LanguageList.swift +++ b/Sources/AppwriteModels/LanguageList.swift @@ -9,7 +9,7 @@ open class LanguageList: Codable { case languages = "languages" } - /// Total number of languages documents that matched your query. + /// Total number of languages that matched your query. public let total: Int /// List of languages. diff --git a/Sources/AppwriteModels/LocaleCodeList.swift b/Sources/AppwriteModels/LocaleCodeList.swift index 5ef0653..f1d1678 100644 --- a/Sources/AppwriteModels/LocaleCodeList.swift +++ b/Sources/AppwriteModels/LocaleCodeList.swift @@ -9,7 +9,7 @@ open class LocaleCodeList: Codable { case localeCodes = "localeCodes" } - /// Total number of localeCodes documents that matched your query. + /// Total number of localeCodes that matched your query. public let total: Int /// List of localeCodes. diff --git a/Sources/AppwriteModels/LogList.swift b/Sources/AppwriteModels/LogList.swift index 7ff2d07..ba76a8a 100644 --- a/Sources/AppwriteModels/LogList.swift +++ b/Sources/AppwriteModels/LogList.swift @@ -9,7 +9,7 @@ open class LogList: Codable { case logs = "logs" } - /// Total number of logs documents that matched your query. + /// Total number of logs that matched your query. public let total: Int /// List of logs. diff --git a/Sources/AppwriteModels/MembershipList.swift b/Sources/AppwriteModels/MembershipList.swift index a7b0cd6..7d6ffd1 100644 --- a/Sources/AppwriteModels/MembershipList.swift +++ b/Sources/AppwriteModels/MembershipList.swift @@ -9,7 +9,7 @@ open class MembershipList: Codable { case memberships = "memberships" } - /// Total number of memberships documents that matched your query. + /// Total number of memberships that matched your query. public let total: Int /// List of memberships. diff --git a/Sources/AppwriteModels/MessageList.swift b/Sources/AppwriteModels/MessageList.swift index f62fcaa..5030392 100644 --- a/Sources/AppwriteModels/MessageList.swift +++ b/Sources/AppwriteModels/MessageList.swift @@ -9,7 +9,7 @@ open class MessageList: Codable { case messages = "messages" } - /// Total number of messages documents that matched your query. + /// Total number of messages that matched your query. public let total: Int /// List of messages. diff --git a/Sources/AppwriteModels/PhoneList.swift b/Sources/AppwriteModels/PhoneList.swift index 6f3bee3..f09d239 100644 --- a/Sources/AppwriteModels/PhoneList.swift +++ b/Sources/AppwriteModels/PhoneList.swift @@ -9,7 +9,7 @@ open class PhoneList: Codable { case phones = "phones" } - /// Total number of phones documents that matched your query. + /// Total number of phones that matched your query. public let total: Int /// List of phones. diff --git a/Sources/AppwriteModels/ProviderList.swift b/Sources/AppwriteModels/ProviderList.swift index 76fd4eb..feefae6 100644 --- a/Sources/AppwriteModels/ProviderList.swift +++ b/Sources/AppwriteModels/ProviderList.swift @@ -9,7 +9,7 @@ open class ProviderList: Codable { case providers = "providers" } - /// Total number of providers documents that matched your query. + /// Total number of providers that matched your query. public let total: Int /// List of providers. diff --git a/Sources/AppwriteModels/ResourceTokenList.swift b/Sources/AppwriteModels/ResourceTokenList.swift index 6d894b6..938c1f8 100644 --- a/Sources/AppwriteModels/ResourceTokenList.swift +++ b/Sources/AppwriteModels/ResourceTokenList.swift @@ -9,7 +9,7 @@ open class ResourceTokenList: Codable { case tokens = "tokens" } - /// Total number of tokens documents that matched your query. + /// Total number of tokens that matched your query. public let total: Int /// List of tokens. diff --git a/Sources/AppwriteModels/Row.swift b/Sources/AppwriteModels/Row.swift new file mode 100644 index 0000000..6e94a9e --- /dev/null +++ b/Sources/AppwriteModels/Row.swift @@ -0,0 +1,113 @@ +import Foundation +import JSONCodable + +/// Row +open class Row: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case sequence = "$sequence" + case tableId = "$tableId" + case databaseId = "$databaseId" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case permissions = "$permissions" + case data + } + + /// Row ID. + public let id: String + + /// Row automatically incrementing ID. + public let sequence: Int + + /// Table ID. + public let tableId: String + + /// Database ID. + public let databaseId: String + + /// Row creation date in ISO 8601 format. + public let createdAt: String + + /// Row update date in ISO 8601 format. + public let updatedAt: String + + /// Row permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + public let permissions: [String] + + /// Additional properties + public let data: T + + init( + id: String, + sequence: Int, + tableId: String, + databaseId: String, + createdAt: String, + updatedAt: String, + permissions: [String], + data: T + ) { + self.id = id + self.sequence = sequence + self.tableId = tableId + self.databaseId = databaseId + self.createdAt = createdAt + self.updatedAt = updatedAt + self.permissions = permissions + self.data = data + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.id = try container.decode(String.self, forKey: .id) + self.sequence = try container.decode(Int.self, forKey: .sequence) + self.tableId = try container.decode(String.self, forKey: .tableId) + self.databaseId = try container.decode(String.self, forKey: .databaseId) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.permissions = try container.decode([String].self, forKey: .permissions) + self.data = try container.decode(T.self, forKey: .data) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(id, forKey: .id) + try container.encode(sequence, forKey: .sequence) + try container.encode(tableId, forKey: .tableId) + try container.encode(databaseId, forKey: .databaseId) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encode(permissions, forKey: .permissions) + try container.encode(data, forKey: .data) + } + + public func toMap() -> [String: Any] { + return [ + "$id": id as Any, + "$sequence": sequence as Any, + "$tableId": tableId as Any, + "$databaseId": databaseId as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "$permissions": permissions as Any, + "data": try! JSONEncoder().encode(data) + ] + } + + public static func from(map: [String: Any] ) -> Row { + return Row( + id: map["$id"] as! String, + sequence: map["$sequence"] as! Int, + tableId: map["$tableId"] as! String, + databaseId: map["$databaseId"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + permissions: map["$permissions"] as! [String], + data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) + ) + } +} diff --git a/Sources/AppwriteModels/RowList.swift b/Sources/AppwriteModels/RowList.swift new file mode 100644 index 0000000..c14c83b --- /dev/null +++ b/Sources/AppwriteModels/RowList.swift @@ -0,0 +1,54 @@ +import Foundation +import JSONCodable + +/// Rows List +open class RowList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case rows = "rows" + } + + /// Total number of rows that matched your query. + public let total: Int + + /// List of rows. + public let rows: [Row] + + + init( + total: Int, + rows: [Row] + ) { + self.total = total + self.rows = rows + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.total = try container.decode(Int.self, forKey: .total) + self.rows = try container.decode([Row].self, forKey: .rows) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(rows, forKey: .rows) + } + + public func toMap() -> [String: Any] { + return [ + "total": total as Any, + "rows": rows.map { $0.toMap() } as Any + ] + } + + public static func from(map: [String: Any] ) -> RowList { + return RowList( + total: map["total"] as! Int, + rows: (map["rows"] as! [[String: Any]]).map { Row.from(map: $0) } + ) + } +} diff --git a/Sources/AppwriteModels/RuntimeList.swift b/Sources/AppwriteModels/RuntimeList.swift index ab99ed1..26e9be6 100644 --- a/Sources/AppwriteModels/RuntimeList.swift +++ b/Sources/AppwriteModels/RuntimeList.swift @@ -9,7 +9,7 @@ open class RuntimeList: Codable { case runtimes = "runtimes" } - /// Total number of runtimes documents that matched your query. + /// Total number of runtimes that matched your query. public let total: Int /// List of runtimes. diff --git a/Sources/AppwriteModels/SessionList.swift b/Sources/AppwriteModels/SessionList.swift index 13b6b3d..c9c8394 100644 --- a/Sources/AppwriteModels/SessionList.swift +++ b/Sources/AppwriteModels/SessionList.swift @@ -9,7 +9,7 @@ open class SessionList: Codable { case sessions = "sessions" } - /// Total number of sessions documents that matched your query. + /// Total number of sessions that matched your query. public let total: Int /// List of sessions. diff --git a/Sources/AppwriteModels/SiteList.swift b/Sources/AppwriteModels/SiteList.swift index 6c37fae..60c1d89 100644 --- a/Sources/AppwriteModels/SiteList.swift +++ b/Sources/AppwriteModels/SiteList.swift @@ -9,7 +9,7 @@ open class SiteList: Codable { case sites = "sites" } - /// Total number of sites documents that matched your query. + /// Total number of sites that matched your query. public let total: Int /// List of sites. diff --git a/Sources/AppwriteModels/SpecificationList.swift b/Sources/AppwriteModels/SpecificationList.swift index f2b9766..fc13cd3 100644 --- a/Sources/AppwriteModels/SpecificationList.swift +++ b/Sources/AppwriteModels/SpecificationList.swift @@ -9,7 +9,7 @@ open class SpecificationList: Codable { case specifications = "specifications" } - /// Total number of specifications documents that matched your query. + /// Total number of specifications that matched your query. public let total: Int /// List of specifications. diff --git a/Sources/AppwriteModels/SubscriberList.swift b/Sources/AppwriteModels/SubscriberList.swift index 2d63f07..8d82866 100644 --- a/Sources/AppwriteModels/SubscriberList.swift +++ b/Sources/AppwriteModels/SubscriberList.swift @@ -9,7 +9,7 @@ open class SubscriberList: Codable { case subscribers = "subscribers" } - /// Total number of subscribers documents that matched your query. + /// Total number of subscribers that matched your query. public let total: Int /// List of subscribers. diff --git a/Sources/AppwriteModels/Table.swift b/Sources/AppwriteModels/Table.swift new file mode 100644 index 0000000..82bdd3d --- /dev/null +++ b/Sources/AppwriteModels/Table.swift @@ -0,0 +1,134 @@ +import Foundation +import JSONCodable + +/// Table +open class Table: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case permissions = "$permissions" + case databaseId = "databaseId" + case name = "name" + case enabled = "enabled" + case rowSecurity = "rowSecurity" + case columns = "columns" + case indexes = "indexes" + } + + /// Table ID. + public let id: String + + /// Table creation date in ISO 8601 format. + public let createdAt: String + + /// Table update date in ISO 8601 format. + public let updatedAt: String + + /// Table permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + public let permissions: [String] + + /// Database ID. + public let databaseId: String + + /// Table name. + public let name: String + + /// Table enabled. Can be 'enabled' or 'disabled'. When disabled, the table is inaccessible to users, but remains accessible to Server SDKs using API keys. + public let enabled: Bool + + /// Whether row-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + public let rowSecurity: Bool + + /// Table columns. + public let columns: [AnyCodable] + + /// Table indexes. + public let indexes: [ColumnIndex] + + + init( + id: String, + createdAt: String, + updatedAt: String, + permissions: [String], + databaseId: String, + name: String, + enabled: Bool, + rowSecurity: Bool, + columns: [AnyCodable], + indexes: [ColumnIndex] + ) { + self.id = id + self.createdAt = createdAt + self.updatedAt = updatedAt + self.permissions = permissions + self.databaseId = databaseId + self.name = name + self.enabled = enabled + self.rowSecurity = rowSecurity + self.columns = columns + self.indexes = indexes + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.id = try container.decode(String.self, forKey: .id) + self.createdAt = try container.decode(String.self, forKey: .createdAt) + self.updatedAt = try container.decode(String.self, forKey: .updatedAt) + self.permissions = try container.decode([String].self, forKey: .permissions) + self.databaseId = try container.decode(String.self, forKey: .databaseId) + self.name = try container.decode(String.self, forKey: .name) + self.enabled = try container.decode(Bool.self, forKey: .enabled) + self.rowSecurity = try container.decode(Bool.self, forKey: .rowSecurity) + self.columns = try container.decode([AnyCodable].self, forKey: .columns) + self.indexes = try container.decode([ColumnIndex].self, forKey: .indexes) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(id, forKey: .id) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encode(permissions, forKey: .permissions) + try container.encode(databaseId, forKey: .databaseId) + try container.encode(name, forKey: .name) + try container.encode(enabled, forKey: .enabled) + try container.encode(rowSecurity, forKey: .rowSecurity) + try container.encode(columns, forKey: .columns) + try container.encode(indexes, forKey: .indexes) + } + + public func toMap() -> [String: Any] { + return [ + "$id": id as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, + "$permissions": permissions as Any, + "databaseId": databaseId as Any, + "name": name as Any, + "enabled": enabled as Any, + "rowSecurity": rowSecurity as Any, + "columns": columns as Any, + "indexes": indexes.map { $0.toMap() } as Any + ] + } + + public static func from(map: [String: Any] ) -> Table { + return Table( + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + permissions: map["$permissions"] as! [String], + databaseId: map["databaseId"] as! String, + name: map["name"] as! String, + enabled: map["enabled"] as! Bool, + rowSecurity: map["rowSecurity"] as! Bool, + columns: (map["columns"] as! [Any]).map { AnyCodable($0) }, + indexes: (map["indexes"] as! [[String: Any]]).map { ColumnIndex.from(map: $0) } + ) + } +} diff --git a/Sources/AppwriteModels/TableList.swift b/Sources/AppwriteModels/TableList.swift new file mode 100644 index 0000000..d0c8059 --- /dev/null +++ b/Sources/AppwriteModels/TableList.swift @@ -0,0 +1,54 @@ +import Foundation +import JSONCodable + +/// Tables List +open class TableList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case tables = "tables" + } + + /// Total number of tables that matched your query. + public let total: Int + + /// List of tables. + public let tables: [Table] + + + init( + total: Int, + tables: [Table] + ) { + self.total = total + self.tables = tables + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.total = try container.decode(Int.self, forKey: .total) + self.tables = try container.decode([Table].self, forKey: .tables) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(tables, forKey: .tables) + } + + public func toMap() -> [String: Any] { + return [ + "total": total as Any, + "tables": tables.map { $0.toMap() } as Any + ] + } + + public static func from(map: [String: Any] ) -> TableList { + return TableList( + total: map["total"] as! Int, + tables: (map["tables"] as! [[String: Any]]).map { Table.from(map: $0) } + ) + } +} diff --git a/Sources/AppwriteModels/TargetList.swift b/Sources/AppwriteModels/TargetList.swift index 6c9f247..cc5557d 100644 --- a/Sources/AppwriteModels/TargetList.swift +++ b/Sources/AppwriteModels/TargetList.swift @@ -9,7 +9,7 @@ open class TargetList: Codable { case targets = "targets" } - /// Total number of targets documents that matched your query. + /// Total number of targets that matched your query. public let total: Int /// List of targets. diff --git a/Sources/AppwriteModels/TeamList.swift b/Sources/AppwriteModels/TeamList.swift index 384d9f6..2b789d9 100644 --- a/Sources/AppwriteModels/TeamList.swift +++ b/Sources/AppwriteModels/TeamList.swift @@ -9,7 +9,7 @@ open class TeamList: Codable { case teams = "teams" } - /// Total number of teams documents that matched your query. + /// Total number of teams that matched your query. public let total: Int /// List of teams. diff --git a/Sources/AppwriteModels/TopicList.swift b/Sources/AppwriteModels/TopicList.swift index 66eae2c..53cfd49 100644 --- a/Sources/AppwriteModels/TopicList.swift +++ b/Sources/AppwriteModels/TopicList.swift @@ -9,7 +9,7 @@ open class TopicList: Codable { case topics = "topics" } - /// Total number of topics documents that matched your query. + /// Total number of topics that matched your query. public let total: Int /// List of topics. diff --git a/Sources/AppwriteModels/UserList.swift b/Sources/AppwriteModels/UserList.swift index 7bf7413..445e9c9 100644 --- a/Sources/AppwriteModels/UserList.swift +++ b/Sources/AppwriteModels/UserList.swift @@ -9,7 +9,7 @@ open class UserList: Codable { case users = "users" } - /// Total number of users documents that matched your query. + /// Total number of users that matched your query. public let total: Int /// List of users. diff --git a/Sources/AppwriteModels/VariableList.swift b/Sources/AppwriteModels/VariableList.swift index 8345d0b..b97b1d0 100644 --- a/Sources/AppwriteModels/VariableList.swift +++ b/Sources/AppwriteModels/VariableList.swift @@ -9,7 +9,7 @@ open class VariableList: Codable { case variables = "variables" } - /// Total number of variables documents that matched your query. + /// Total number of variables that matched your query. public let total: Int /// List of variables. diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-jwt.md similarity index 100% rename from docs/examples/account/create-j-w-t.md rename to docs/examples/account/create-jwt.md diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-url-token.md similarity index 100% rename from docs/examples/account/create-magic-u-r-l-token.md rename to docs/examples/account/create-magic-url-token.md diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md index 4dd91d8..dd3a7d1 100644 --- a/docs/examples/account/create-mfa-authenticator.md +++ b/docs/examples/account/create-mfa-authenticator.md @@ -8,7 +8,7 @@ let client = Client() let account = Account(client) -let mfaType = try await account.createMfaAuthenticator( +let mfaType = try await account.createMFAAuthenticator( type: .totp ) diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 0b5d385..27f1bc1 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -7,7 +7,7 @@ let client = Client() let account = Account(client) -let mfaChallenge = try await account.createMfaChallenge( +let mfaChallenge = try await account.createMFAChallenge( factor: .email ) diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md index a73e4f6..3595cda 100644 --- a/docs/examples/account/create-mfa-recovery-codes.md +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -7,5 +7,5 @@ let client = Client() let account = Account(client) -let mfaRecoveryCodes = try await account.createMfaRecoveryCodes() +let mfaRecoveryCodes = try await account.createMFARecoveryCodes() diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth-2-token.md similarity index 100% rename from docs/examples/account/create-o-auth2token.md rename to docs/examples/account/create-o-auth-2-token.md diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index e4209a2..5a85cdc 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -8,7 +8,7 @@ let client = Client() let account = Account(client) -let result = try await account.deleteMfaAuthenticator( +let result = try await account.deleteMFAAuthenticator( type: .totp ) diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md index 69455f4..86c435d 100644 --- a/docs/examples/account/get-mfa-recovery-codes.md +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -7,5 +7,5 @@ let client = Client() let account = Account(client) -let mfaRecoveryCodes = try await account.getMfaRecoveryCodes() +let mfaRecoveryCodes = try await account.getMFARecoveryCodes() diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md index a63d4d0..be41b2b 100644 --- a/docs/examples/account/list-mfa-factors.md +++ b/docs/examples/account/list-mfa-factors.md @@ -7,5 +7,5 @@ let client = Client() let account = Account(client) -let mfaFactors = try await account.listMfaFactors() +let mfaFactors = try await account.listMFAFactors() diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-url-session.md similarity index 100% rename from docs/examples/account/update-magic-u-r-l-session.md rename to docs/examples/account/update-magic-url-session.md diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md index fedbc95..79f408e 100644 --- a/docs/examples/account/update-mfa-authenticator.md +++ b/docs/examples/account/update-mfa-authenticator.md @@ -8,7 +8,7 @@ let client = Client() let account = Account(client) -let user = try await account.updateMfaAuthenticator( +let user = try await account.updateMFAAuthenticator( type: .totp, otp: "" ) diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index 4edb1fb..c595f1e 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -7,7 +7,7 @@ let client = Client() let account = Account(client) -let session = try await account.updateMfaChallenge( +let session = try await account.updateMFAChallenge( challengeId: "", otp: "" ) diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md index d0a2b8c..ee6f9ac 100644 --- a/docs/examples/account/update-mfa-recovery-codes.md +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -7,5 +7,5 @@ let client = Client() let account = Account(client) -let mfaRecoveryCodes = try await account.updateMfaRecoveryCodes() +let mfaRecoveryCodes = try await account.updateMFARecoveryCodes() diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-mfa.md similarity index 100% rename from docs/examples/account/update-m-f-a.md rename to docs/examples/account/update-mfa.md diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-qr.md similarity index 100% rename from docs/examples/avatars/get-q-r.md rename to docs/examples/avatars/get-qr.md diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md index 88ba9ae..81516fa 100644 --- a/docs/examples/databases/decrement-document-attribute.md +++ b/docs/examples/databases/decrement-document-attribute.md @@ -3,7 +3,7 @@ import Appwrite let client = Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint .setProject("") // Your project ID - .setKey("") // Your secret API key + .setSession("") // The user session to authenticate with let databases = Databases(client) diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md index 452b200..64ba46b 100644 --- a/docs/examples/databases/increment-document-attribute.md +++ b/docs/examples/databases/increment-document-attribute.md @@ -3,7 +3,7 @@ import Appwrite let client = Client() .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint .setProject("") // Your project ID - .setKey("") // Your secret API key + .setSession("") // The user session to authenticate with let databases = Databases(client) diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index aae7a0f..46c9d69 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -15,6 +15,6 @@ let execution = try await functions.createExecution( path: "", // optional method: .gET, // optional headers: [:], // optional - scheduledAt: "" // optional + scheduledAt: "" // optional ) diff --git a/docs/examples/health/get-d-b.md b/docs/examples/health/get-db.md similarity index 100% rename from docs/examples/health/get-d-b.md rename to docs/examples/health/get-db.md diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-eu.md similarity index 100% rename from docs/examples/locale/list-countries-e-u.md rename to docs/examples/locale/list-countries-eu.md diff --git a/docs/examples/messaging/create-apns-provider.md b/docs/examples/messaging/create-apns-provider.md index 5e20018..772084d 100644 --- a/docs/examples/messaging/create-apns-provider.md +++ b/docs/examples/messaging/create-apns-provider.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.createApnsProvider( +let provider = try await messaging.createAPNSProvider( providerId: "", name: "", authKey: "", // optional diff --git a/docs/examples/messaging/create-fcm-provider.md b/docs/examples/messaging/create-fcm-provider.md index 0071e47..2b00450 100644 --- a/docs/examples/messaging/create-fcm-provider.md +++ b/docs/examples/messaging/create-fcm-provider.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.createFcmProvider( +let provider = try await messaging.createFCMProvider( providerId: "", name: "", serviceAccountJSON: [:], // optional diff --git a/docs/examples/messaging/create-msg91provider.md b/docs/examples/messaging/create-msg-91-provider.md similarity index 100% rename from docs/examples/messaging/create-msg91provider.md rename to docs/examples/messaging/create-msg-91-provider.md diff --git a/docs/examples/messaging/create-sms.md b/docs/examples/messaging/create-sms.md index 4f57931..28a6ba7 100644 --- a/docs/examples/messaging/create-sms.md +++ b/docs/examples/messaging/create-sms.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let message = try await messaging.createSms( +let message = try await messaging.createSMS( messageId: "", content: "", topics: [], // optional diff --git a/docs/examples/messaging/create-smtp-provider.md b/docs/examples/messaging/create-smtp-provider.md index 18d25df..ec9b92c 100644 --- a/docs/examples/messaging/create-smtp-provider.md +++ b/docs/examples/messaging/create-smtp-provider.md @@ -8,7 +8,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.createSmtpProvider( +let provider = try await messaging.createSMTPProvider( providerId: "", name: "", host: "", diff --git a/docs/examples/messaging/update-apns-provider.md b/docs/examples/messaging/update-apns-provider.md index 03afe55..bed92ba 100644 --- a/docs/examples/messaging/update-apns-provider.md +++ b/docs/examples/messaging/update-apns-provider.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.updateApnsProvider( +let provider = try await messaging.updateAPNSProvider( providerId: "", name: "", // optional enabled: false, // optional diff --git a/docs/examples/messaging/update-fcm-provider.md b/docs/examples/messaging/update-fcm-provider.md index c4548f6..efd7e1f 100644 --- a/docs/examples/messaging/update-fcm-provider.md +++ b/docs/examples/messaging/update-fcm-provider.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.updateFcmProvider( +let provider = try await messaging.updateFCMProvider( providerId: "", name: "", // optional enabled: false, // optional diff --git a/docs/examples/messaging/update-msg91provider.md b/docs/examples/messaging/update-msg-91-provider.md similarity index 100% rename from docs/examples/messaging/update-msg91provider.md rename to docs/examples/messaging/update-msg-91-provider.md diff --git a/docs/examples/messaging/update-sms.md b/docs/examples/messaging/update-sms.md index 46b225f..d6dc207 100644 --- a/docs/examples/messaging/update-sms.md +++ b/docs/examples/messaging/update-sms.md @@ -7,7 +7,7 @@ let client = Client() let messaging = Messaging(client) -let message = try await messaging.updateSms( +let message = try await messaging.updateSMS( messageId: "", topics: [], // optional users: [], // optional diff --git a/docs/examples/messaging/update-smtp-provider.md b/docs/examples/messaging/update-smtp-provider.md index 7ef8f2e..402c267 100644 --- a/docs/examples/messaging/update-smtp-provider.md +++ b/docs/examples/messaging/update-smtp-provider.md @@ -8,7 +8,7 @@ let client = Client() let messaging = Messaging(client) -let provider = try await messaging.updateSmtpProvider( +let provider = try await messaging.updateSMTPProvider( providerId: "", name: "", // optional host: "", // optional diff --git a/docs/examples/tablesdb/create-boolean-column.md b/docs/examples/tablesdb/create-boolean-column.md new file mode 100644 index 0000000..af4b7bd --- /dev/null +++ b/docs/examples/tablesdb/create-boolean-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 columnBoolean = try await tablesDB.createBooleanColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: false, // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-datetime-column.md b/docs/examples/tablesdb/create-datetime-column.md new file mode 100644 index 0000000..ee1945d --- /dev/null +++ b/docs/examples/tablesdb/create-datetime-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 columnDatetime = try await tablesDB.createDatetimeColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-email-column.md b/docs/examples/tablesdb/create-email-column.md new file mode 100644 index 0000000..4ca0fe7 --- /dev/null +++ b/docs/examples/tablesdb/create-email-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 columnEmail = try await tablesDB.createEmailColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "email@example.com", // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-enum-column.md b/docs/examples/tablesdb/create-enum-column.md new file mode 100644 index 0000000..ccddf52 --- /dev/null +++ b/docs/examples/tablesdb/create-enum-column.md @@ -0,0 +1,19 @@ +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 columnEnum = try await tablesDB.createEnumColumn( + databaseId: "", + tableId: "", + key: "", + elements: [], + required: false, + default: "", // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-float-column.md b/docs/examples/tablesdb/create-float-column.md new file mode 100644 index 0000000..c1c685b --- /dev/null +++ b/docs/examples/tablesdb/create-float-column.md @@ -0,0 +1,20 @@ +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 columnFloat = try await tablesDB.createFloatColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + min: 0, // optional + max: 0, // optional + default: 0, // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-index.md b/docs/examples/tablesdb/create-index.md new file mode 100644 index 0000000..3620c62 --- /dev/null +++ b/docs/examples/tablesdb/create-index.md @@ -0,0 +1,20 @@ +import Appwrite +import AppwriteEnums + +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 columnIndex = try await tablesDB.createIndex( + databaseId: "", + tableId: "", + key: "", + type: .key, + columns: [], + orders: [], // optional + lengths: [] // optional +) + diff --git a/docs/examples/tablesdb/create-integer-column.md b/docs/examples/tablesdb/create-integer-column.md new file mode 100644 index 0000000..52ad14a --- /dev/null +++ b/docs/examples/tablesdb/create-integer-column.md @@ -0,0 +1,20 @@ +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 columnInteger = try await tablesDB.createIntegerColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + min: 0, // optional + max: 0, // optional + default: 0, // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-ip-column.md b/docs/examples/tablesdb/create-ip-column.md new file mode 100644 index 0000000..d8801c5 --- /dev/null +++ b/docs/examples/tablesdb/create-ip-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 columnIp = try await tablesDB.createIpColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create-relationship-column.md b/docs/examples/tablesdb/create-relationship-column.md new file mode 100644 index 0000000..4c464b5 --- /dev/null +++ b/docs/examples/tablesdb/create-relationship-column.md @@ -0,0 +1,21 @@ +import Appwrite +import AppwriteEnums + +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 columnRelationship = try await tablesDB.createRelationshipColumn( + databaseId: "", + tableId: "", + relatedTableId: "", + type: .oneToOne, + twoWay: false, // optional + key: "", // optional + twoWayKey: "", // optional + onDelete: .cascade // optional +) + diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md new file mode 100644 index 0000000..31e0ea9 --- /dev/null +++ b/docs/examples/tablesdb/create-row.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.createRow( + databaseId: "", + tableId: "", + rowId: "", + data: [:], + permissions: ["read("any")"] // optional +) + diff --git a/docs/examples/tablesdb/create-rows.md b/docs/examples/tablesdb/create-rows.md new file mode 100644 index 0000000..25ea512 --- /dev/null +++ b/docs/examples/tablesdb/create-rows.md @@ -0,0 +1,15 @@ +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 rowList = try await tablesDB.createRows( + databaseId: "", + tableId: "", + rows: [] +) + diff --git a/docs/examples/tablesdb/create-string-column.md b/docs/examples/tablesdb/create-string-column.md new file mode 100644 index 0000000..e38dcb8 --- /dev/null +++ b/docs/examples/tablesdb/create-string-column.md @@ -0,0 +1,20 @@ +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 columnString = try await tablesDB.createStringColumn( + databaseId: "", + tableId: "", + key: "", + size: 1, + required: false, + default: "", // optional + array: false, // optional + encrypt: false // optional +) + diff --git a/docs/examples/tablesdb/create-table.md b/docs/examples/tablesdb/create-table.md new file mode 100644 index 0000000..11d14e1 --- /dev/null +++ b/docs/examples/tablesdb/create-table.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 table = try await tablesDB.createTable( + databaseId: "", + tableId: "", + name: "", + permissions: ["read("any")"], // optional + rowSecurity: false, // optional + enabled: false // optional +) + diff --git a/docs/examples/tablesdb/create-url-column.md b/docs/examples/tablesdb/create-url-column.md new file mode 100644 index 0000000..083556f --- /dev/null +++ b/docs/examples/tablesdb/create-url-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 columnUrl = try await tablesDB.createUrlColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "https://example.com", // optional + array: false // optional +) + diff --git a/docs/examples/tablesdb/create.md b/docs/examples/tablesdb/create.md new file mode 100644 index 0000000..be88b59 --- /dev/null +++ b/docs/examples/tablesdb/create.md @@ -0,0 +1,15 @@ +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 database = try await tablesDB.create( + databaseId: "", + name: "", + enabled: false // optional +) + diff --git a/docs/examples/tablesdb/decrement-row-column.md b/docs/examples/tablesdb/decrement-row-column.md new file mode 100644 index 0000000..196289e --- /dev/null +++ b/docs/examples/tablesdb/decrement-row-column.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.decrementRowColumn( + databaseId: "", + tableId: "", + rowId: "", + column: "", + value: 0, // optional + min: 0 // optional +) + diff --git a/docs/examples/tablesdb/delete-column.md b/docs/examples/tablesdb/delete-column.md new file mode 100644 index 0000000..f9f2c5c --- /dev/null +++ b/docs/examples/tablesdb/delete-column.md @@ -0,0 +1,15 @@ +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 result = try await tablesDB.deleteColumn( + databaseId: "", + tableId: "", + key: "" +) + diff --git a/docs/examples/tablesdb/delete-index.md b/docs/examples/tablesdb/delete-index.md new file mode 100644 index 0000000..0a413b6 --- /dev/null +++ b/docs/examples/tablesdb/delete-index.md @@ -0,0 +1,15 @@ +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 result = try await tablesDB.deleteIndex( + databaseId: "", + tableId: "", + key: "" +) + diff --git a/docs/examples/tablesdb/delete-row.md b/docs/examples/tablesdb/delete-row.md new file mode 100644 index 0000000..5449c74 --- /dev/null +++ b/docs/examples/tablesdb/delete-row.md @@ -0,0 +1,15 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let result = try await tablesDB.deleteRow( + databaseId: "", + tableId: "", + rowId: "" +) + diff --git a/docs/examples/tablesdb/delete-rows.md b/docs/examples/tablesdb/delete-rows.md new file mode 100644 index 0000000..85d8957 --- /dev/null +++ b/docs/examples/tablesdb/delete-rows.md @@ -0,0 +1,15 @@ +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 rowList = try await tablesDB.deleteRows( + databaseId: "", + tableId: "", + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/delete-table.md b/docs/examples/tablesdb/delete-table.md new file mode 100644 index 0000000..1986f3a --- /dev/null +++ b/docs/examples/tablesdb/delete-table.md @@ -0,0 +1,14 @@ +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 result = try await tablesDB.deleteTable( + databaseId: "", + tableId: "" +) + diff --git a/docs/examples/tablesdb/delete.md b/docs/examples/tablesdb/delete.md new file mode 100644 index 0000000..08e6ddc --- /dev/null +++ b/docs/examples/tablesdb/delete.md @@ -0,0 +1,13 @@ +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 result = try await tablesDB.delete( + databaseId: "" +) + diff --git a/docs/examples/tablesdb/get-column.md b/docs/examples/tablesdb/get-column.md new file mode 100644 index 0000000..2d88b03 --- /dev/null +++ b/docs/examples/tablesdb/get-column.md @@ -0,0 +1,15 @@ +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 result = try await tablesDB.getColumn( + databaseId: "", + tableId: "", + key: "" +) + diff --git a/docs/examples/tablesdb/get-index.md b/docs/examples/tablesdb/get-index.md new file mode 100644 index 0000000..6f65fdb --- /dev/null +++ b/docs/examples/tablesdb/get-index.md @@ -0,0 +1,15 @@ +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 columnIndex = try await tablesDB.getIndex( + databaseId: "", + tableId: "", + key: "" +) + diff --git a/docs/examples/tablesdb/get-row.md b/docs/examples/tablesdb/get-row.md new file mode 100644 index 0000000..17e6ccb --- /dev/null +++ b/docs/examples/tablesdb/get-row.md @@ -0,0 +1,16 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.getRow( + databaseId: "", + tableId: "", + rowId: "", + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/get-table.md b/docs/examples/tablesdb/get-table.md new file mode 100644 index 0000000..e9167d4 --- /dev/null +++ b/docs/examples/tablesdb/get-table.md @@ -0,0 +1,14 @@ +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 table = try await tablesDB.getTable( + databaseId: "", + tableId: "" +) + diff --git a/docs/examples/tablesdb/get.md b/docs/examples/tablesdb/get.md new file mode 100644 index 0000000..d670cf7 --- /dev/null +++ b/docs/examples/tablesdb/get.md @@ -0,0 +1,13 @@ +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 database = try await tablesDB.get( + databaseId: "" +) + diff --git a/docs/examples/tablesdb/increment-row-column.md b/docs/examples/tablesdb/increment-row-column.md new file mode 100644 index 0000000..38aa758 --- /dev/null +++ b/docs/examples/tablesdb/increment-row-column.md @@ -0,0 +1,18 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.incrementRowColumn( + databaseId: "", + tableId: "", + rowId: "", + column: "", + value: 0, // optional + max: 0 // optional +) + diff --git a/docs/examples/tablesdb/list-columns.md b/docs/examples/tablesdb/list-columns.md new file mode 100644 index 0000000..271a6d4 --- /dev/null +++ b/docs/examples/tablesdb/list-columns.md @@ -0,0 +1,15 @@ +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 columnList = try await tablesDB.listColumns( + databaseId: "", + tableId: "", + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/list-indexes.md b/docs/examples/tablesdb/list-indexes.md new file mode 100644 index 0000000..a8e2770 --- /dev/null +++ b/docs/examples/tablesdb/list-indexes.md @@ -0,0 +1,15 @@ +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 columnIndexList = try await tablesDB.listIndexes( + databaseId: "", + tableId: "", + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md new file mode 100644 index 0000000..7320147 --- /dev/null +++ b/docs/examples/tablesdb/list-rows.md @@ -0,0 +1,15 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let rowList = try await tablesDB.listRows( + databaseId: "", + tableId: "", + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/list-tables.md b/docs/examples/tablesdb/list-tables.md new file mode 100644 index 0000000..46fcdcf --- /dev/null +++ b/docs/examples/tablesdb/list-tables.md @@ -0,0 +1,15 @@ +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 tableList = try await tablesDB.listTables( + databaseId: "", + queries: [], // optional + search: "" // optional +) + diff --git a/docs/examples/tablesdb/list.md b/docs/examples/tablesdb/list.md new file mode 100644 index 0000000..6923d8a --- /dev/null +++ b/docs/examples/tablesdb/list.md @@ -0,0 +1,14 @@ +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 databaseList = try await tablesDB.list( + queries: [], // optional + search: "" // optional +) + diff --git a/docs/examples/tablesdb/update-boolean-column.md b/docs/examples/tablesdb/update-boolean-column.md new file mode 100644 index 0000000..c8ca0fc --- /dev/null +++ b/docs/examples/tablesdb/update-boolean-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 columnBoolean = try await tablesDB.updateBooleanColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: false, + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-datetime-column.md b/docs/examples/tablesdb/update-datetime-column.md new file mode 100644 index 0000000..67e411b --- /dev/null +++ b/docs/examples/tablesdb/update-datetime-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 columnDatetime = try await tablesDB.updateDatetimeColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-email-column.md b/docs/examples/tablesdb/update-email-column.md new file mode 100644 index 0000000..56a7d07 --- /dev/null +++ b/docs/examples/tablesdb/update-email-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 columnEmail = try await tablesDB.updateEmailColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "email@example.com", + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-enum-column.md b/docs/examples/tablesdb/update-enum-column.md new file mode 100644 index 0000000..a86d114 --- /dev/null +++ b/docs/examples/tablesdb/update-enum-column.md @@ -0,0 +1,19 @@ +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 columnEnum = try await tablesDB.updateEnumColumn( + databaseId: "", + tableId: "", + key: "", + elements: [], + required: false, + default: "", + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-float-column.md b/docs/examples/tablesdb/update-float-column.md new file mode 100644 index 0000000..10806aa --- /dev/null +++ b/docs/examples/tablesdb/update-float-column.md @@ -0,0 +1,20 @@ +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 columnFloat = try await tablesDB.updateFloatColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: 0, + min: 0, // optional + max: 0, // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-integer-column.md b/docs/examples/tablesdb/update-integer-column.md new file mode 100644 index 0000000..ba6bfa5 --- /dev/null +++ b/docs/examples/tablesdb/update-integer-column.md @@ -0,0 +1,20 @@ +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 columnInteger = try await tablesDB.updateIntegerColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: 0, + min: 0, // optional + max: 0, // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-ip-column.md b/docs/examples/tablesdb/update-ip-column.md new file mode 100644 index 0000000..5686e71 --- /dev/null +++ b/docs/examples/tablesdb/update-ip-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 columnIp = try await tablesDB.updateIpColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-relationship-column.md b/docs/examples/tablesdb/update-relationship-column.md new file mode 100644 index 0000000..0a021ff --- /dev/null +++ b/docs/examples/tablesdb/update-relationship-column.md @@ -0,0 +1,18 @@ +import Appwrite +import AppwriteEnums + +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 columnRelationship = try await tablesDB.updateRelationshipColumn( + databaseId: "", + tableId: "", + key: "", + onDelete: .cascade, // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md new file mode 100644 index 0000000..e06338b --- /dev/null +++ b/docs/examples/tablesdb/update-row.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.updateRow( + databaseId: "", + tableId: "", + rowId: "", + data: [:], // optional + permissions: ["read("any")"] // optional +) + diff --git a/docs/examples/tablesdb/update-rows.md b/docs/examples/tablesdb/update-rows.md new file mode 100644 index 0000000..58894f5 --- /dev/null +++ b/docs/examples/tablesdb/update-rows.md @@ -0,0 +1,16 @@ +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 rowList = try await tablesDB.updateRows( + databaseId: "", + tableId: "", + data: [:], // optional + queries: [] // optional +) + diff --git a/docs/examples/tablesdb/update-string-column.md b/docs/examples/tablesdb/update-string-column.md new file mode 100644 index 0000000..55efca1 --- /dev/null +++ b/docs/examples/tablesdb/update-string-column.md @@ -0,0 +1,19 @@ +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 columnString = try await tablesDB.updateStringColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "", + size: 1, // optional + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update-table.md b/docs/examples/tablesdb/update-table.md new file mode 100644 index 0000000..278d6e6 --- /dev/null +++ b/docs/examples/tablesdb/update-table.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 table = try await tablesDB.updateTable( + databaseId: "", + tableId: "", + name: "", + permissions: ["read("any")"], // optional + rowSecurity: false, // optional + enabled: false // optional +) + diff --git a/docs/examples/tablesdb/update-url-column.md b/docs/examples/tablesdb/update-url-column.md new file mode 100644 index 0000000..693fe52 --- /dev/null +++ b/docs/examples/tablesdb/update-url-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 columnUrl = try await tablesDB.updateUrlColumn( + databaseId: "", + tableId: "", + key: "", + required: false, + default: "https://example.com", + newKey: "" // optional +) + diff --git a/docs/examples/tablesdb/update.md b/docs/examples/tablesdb/update.md new file mode 100644 index 0000000..4a7dcc8 --- /dev/null +++ b/docs/examples/tablesdb/update.md @@ -0,0 +1,15 @@ +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 database = try await tablesDB.update( + databaseId: "", + name: "", + enabled: false // optional +) + diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md new file mode 100644 index 0000000..dc133f6 --- /dev/null +++ b/docs/examples/tablesdb/upsert-row.md @@ -0,0 +1,17 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let tablesDB = TablesDB(client) + +let row = try await tablesDB.upsertRow( + databaseId: "", + tableId: "", + rowId: "", + data: [:], // optional + permissions: ["read("any")"] // optional +) + diff --git a/docs/examples/tablesdb/upsert-rows.md b/docs/examples/tablesdb/upsert-rows.md new file mode 100644 index 0000000..fe35f0d --- /dev/null +++ b/docs/examples/tablesdb/upsert-rows.md @@ -0,0 +1,15 @@ +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 rowList = try await tablesDB.upsertRows( + databaseId: "", + tableId: "", + rows: [] +) + diff --git a/docs/examples/users/create-argon2user.md b/docs/examples/users/create-argon-2-user.md similarity index 100% rename from docs/examples/users/create-argon2user.md rename to docs/examples/users/create-argon-2-user.md diff --git a/docs/examples/users/create-j-w-t.md b/docs/examples/users/create-jwt.md similarity index 100% rename from docs/examples/users/create-j-w-t.md rename to docs/examples/users/create-jwt.md diff --git a/docs/examples/users/create-m-d5user.md b/docs/examples/users/create-md-5-user.md similarity index 100% rename from docs/examples/users/create-m-d5user.md rename to docs/examples/users/create-md-5-user.md diff --git a/docs/examples/users/create-mfa-recovery-codes.md b/docs/examples/users/create-mfa-recovery-codes.md index 577a533..5f073d1 100644 --- a/docs/examples/users/create-mfa-recovery-codes.md +++ b/docs/examples/users/create-mfa-recovery-codes.md @@ -7,7 +7,7 @@ let client = Client() let users = Users(client) -let mfaRecoveryCodes = try await users.createMfaRecoveryCodes( +let mfaRecoveryCodes = try await users.createMFARecoveryCodes( userId: "" ) diff --git a/docs/examples/users/create-p-h-pass-user.md b/docs/examples/users/create-ph-pass-user.md similarity index 100% rename from docs/examples/users/create-p-h-pass-user.md rename to docs/examples/users/create-ph-pass-user.md diff --git a/docs/examples/users/create-s-h-a-user.md b/docs/examples/users/create-sha-user.md similarity index 100% rename from docs/examples/users/create-s-h-a-user.md rename to docs/examples/users/create-sha-user.md diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md index da2b8e0..be9f395 100644 --- a/docs/examples/users/delete-mfa-authenticator.md +++ b/docs/examples/users/delete-mfa-authenticator.md @@ -8,7 +8,7 @@ let client = Client() let users = Users(client) -let result = try await users.deleteMfaAuthenticator( +let result = try await users.deleteMFAAuthenticator( userId: "", type: .totp ) diff --git a/docs/examples/users/get-mfa-recovery-codes.md b/docs/examples/users/get-mfa-recovery-codes.md index 1ae2851..874076c 100644 --- a/docs/examples/users/get-mfa-recovery-codes.md +++ b/docs/examples/users/get-mfa-recovery-codes.md @@ -7,7 +7,7 @@ let client = Client() let users = Users(client) -let mfaRecoveryCodes = try await users.getMfaRecoveryCodes( +let mfaRecoveryCodes = try await users.getMFARecoveryCodes( userId: "" ) diff --git a/docs/examples/users/list-mfa-factors.md b/docs/examples/users/list-mfa-factors.md index a5b5e38..4a58a07 100644 --- a/docs/examples/users/list-mfa-factors.md +++ b/docs/examples/users/list-mfa-factors.md @@ -7,7 +7,7 @@ let client = Client() let users = Users(client) -let mfaFactors = try await users.listMfaFactors( +let mfaFactors = try await users.listMFAFactors( userId: "" ) diff --git a/docs/examples/users/update-mfa-recovery-codes.md b/docs/examples/users/update-mfa-recovery-codes.md index a6169a7..7ebb34e 100644 --- a/docs/examples/users/update-mfa-recovery-codes.md +++ b/docs/examples/users/update-mfa-recovery-codes.md @@ -7,7 +7,7 @@ let client = Client() let users = Users(client) -let mfaRecoveryCodes = try await users.updateMfaRecoveryCodes( +let mfaRecoveryCodes = try await users.updateMFARecoveryCodes( userId: "" ) diff --git a/docs/examples/users/update-mfa.md b/docs/examples/users/update-mfa.md index ad010f3..ca442b3 100644 --- a/docs/examples/users/update-mfa.md +++ b/docs/examples/users/update-mfa.md @@ -7,7 +7,7 @@ let client = Client() let users = Users(client) -let user = try await users.updateMfa( +let user = try await users.updateMFA( userId: "", mfa: false )