From cb2595dec12c3a35a734d60070d4b9311cc4318f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:29:25 +0100 Subject: [PATCH 1/5] fix: multipart testing --- Sources/Appwrite/Services/Account.swift | 22 ++++++++--------- Sources/Appwrite/Services/Functions.swift | 26 ++++++++++++--------- Sources/Appwrite/Services/Locale.swift | 2 +- Sources/Appwrite/Services/Storage.swift | 2 +- Sources/Appwrite/Services/Users.swift | 22 ++++++++--------- Sources/AppwriteEnums/Runtime.swift | 3 +++ Sources/AppwriteModels/Execution.swift | 6 ++--- docs/examples/functions/create-execution.md | 2 +- 8 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 06dbc35..fabfe82 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -214,7 +214,7 @@ open class Account: Service { } /// - /// List Identities + /// List identities /// /// Get the list of identities for the currently logged in user. /// @@ -402,7 +402,7 @@ open class Account: Service { } /// - /// Create Authenticator + /// Create authenticator /// /// Add an authenticator app to be used as an MFA factor. Verify the /// authenticator using the [verify @@ -439,7 +439,7 @@ open class Account: Service { } /// - /// Verify Authenticator + /// Verify authenticator /// /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) @@ -480,7 +480,7 @@ open class Account: Service { } /// - /// Verify Authenticator + /// Verify authenticator /// /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) @@ -503,7 +503,7 @@ open class Account: Service { } /// - /// Delete Authenticator + /// Delete authenticator /// /// Delete an authenticator for a user by ID. /// @@ -531,7 +531,7 @@ open class Account: Service { } /// - /// Create MFA Challenge + /// Create MFA challenge /// /// Begin the process of MFA verification after sign-in. Finish the flow with /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) @@ -568,7 +568,7 @@ open class Account: Service { } /// - /// Create MFA Challenge (confirmation) + /// Create MFA challenge (confirmation) /// /// Complete the MFA challenge by providing the one-time password. Finish the /// process of MFA verification by providing the one-time password. To begin @@ -604,7 +604,7 @@ open class Account: Service { } /// - /// List Factors + /// List factors /// /// List the factors available on the account to be used as a MFA challange. /// @@ -635,7 +635,7 @@ open class Account: Service { } /// - /// Get MFA Recovery Codes + /// Get MFA recovery codes /// /// Get recovery codes that can be used as backup for MFA flow. Before getting /// codes, they must be generated using @@ -669,7 +669,7 @@ open class Account: Service { } /// - /// Create MFA Recovery Codes + /// Create MFA recovery codes /// /// Generate recovery codes as backup for MFA flow. It's recommended to /// generate and show then immediately after user successfully adds their @@ -704,7 +704,7 @@ open class Account: Service { } /// - /// Regenerate MFA Recovery Codes + /// Regenerate MFA recovery codes /// /// Regenerate recovery codes that can be used as backup for MFA flow. Before /// regenerating codes, they must be first generated using diff --git a/Sources/Appwrite/Services/Functions.swift b/Sources/Appwrite/Services/Functions.swift index ba39620..f855c59 100644 --- a/Sources/Appwrite/Services/Functions.swift +++ b/Sources/Appwrite/Services/Functions.swift @@ -720,7 +720,7 @@ open class Functions: Service { /// function execution process will start asynchronously. /// /// @param String functionId - /// @param String body + /// @param payload body /// @param Bool async /// @param String path /// @param AppwriteEnums.ExecutionMethod method @@ -731,17 +731,18 @@ open class Functions: Service { /// open func createExecution( functionId: String, - body: String? = nil, + body: payload? = nil, async: Bool? = nil, path: String? = nil, method: AppwriteEnums.ExecutionMethod? = nil, headers: Any? = nil, - scheduledAt: String? = nil + scheduledAt: String? = nil, + onProgress: ((UploadProgress) -> Void)? = nil ) async throws -> AppwriteModels.Execution { let apiPath: String = "/functions/{functionId}/executions" .replacingOccurrences(of: "{functionId}", with: functionId) - let apiParams: [String: Any?] = [ + var apiParams: [String: Any?] = [ "body": body, "async": async, "path": path, @@ -750,20 +751,23 @@ open class Functions: Service { "scheduledAt": scheduledAt ] - let apiHeaders: [String: String] = [ - "content-type": "application/json" + var apiHeaders: [String: String] = [ + "content-type": "multipart/form-data" ] let converter: (Any) -> AppwriteModels.Execution = { response in return AppwriteModels.Execution.from(map: response as! [String: Any]) } - return try await client.call( - method: "POST", + let idParamName: String? = nil + return try await client.chunkedUpload( path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter + headers: &apiHeaders, + params: &apiParams, + paramName: paramName, + idParamName: idParamName, + converter: converter, + onProgress: onProgress ) } diff --git a/Sources/Appwrite/Services/Locale.swift b/Sources/Appwrite/Services/Locale.swift index 3ad37de..170e11a 100644 --- a/Sources/Appwrite/Services/Locale.swift +++ b/Sources/Appwrite/Services/Locale.swift @@ -45,7 +45,7 @@ open class Locale: Service { } /// - /// List Locale Codes + /// List locale codes /// /// List of all locale codes in [ISO /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). diff --git a/Sources/Appwrite/Services/Storage.swift b/Sources/Appwrite/Services/Storage.swift index 28f602a..c3454aa 100644 --- a/Sources/Appwrite/Services/Storage.swift +++ b/Sources/Appwrite/Services/Storage.swift @@ -426,7 +426,7 @@ open class Storage: Service { } /// - /// Delete File + /// Delete file /// /// Delete a file by its unique ID. Only users with write permissions have /// access to delete this resource. diff --git a/Sources/Appwrite/Services/Users.swift b/Sources/Appwrite/Services/Users.swift index 62d2fc6..f9e7361 100644 --- a/Sources/Appwrite/Services/Users.swift +++ b/Sources/Appwrite/Services/Users.swift @@ -305,7 +305,7 @@ open class Users: Service { } /// - /// List Identities + /// List identities /// /// Get identities for all users. /// @@ -1208,7 +1208,7 @@ open class Users: Service { } /// - /// Delete Authenticator + /// Delete authenticator /// /// Delete an authenticator app. /// @@ -1246,7 +1246,7 @@ open class Users: Service { } /// - /// Delete Authenticator + /// Delete authenticator /// /// Delete an authenticator app. /// @@ -1267,7 +1267,7 @@ open class Users: Service { } /// - /// List Factors + /// List factors /// /// List the factors available on the account to be used as a MFA challange. /// @@ -1301,7 +1301,7 @@ open class Users: Service { } /// - /// Get MFA Recovery Codes + /// Get MFA recovery codes /// /// Get recovery codes that can be used as backup for MFA flow by User ID. /// Before getting codes, they must be generated using @@ -1338,7 +1338,7 @@ open class Users: Service { } /// - /// Regenerate MFA Recovery Codes + /// Regenerate MFA recovery codes /// /// Regenerate recovery codes that can be used as backup for MFA flow by User /// ID. Before regenerating codes, they must be first generated using @@ -1375,7 +1375,7 @@ open class Users: Service { } /// - /// Create MFA Recovery Codes + /// Create MFA recovery codes /// /// Generate recovery codes used as backup for MFA flow for User ID. Recovery /// codes can be used as a MFA verification type in @@ -1903,7 +1903,7 @@ open class Users: Service { } /// - /// List User Targets + /// List user targets /// /// List the messaging targets that are associated with a user. /// @@ -1941,7 +1941,7 @@ open class Users: Service { } /// - /// Create User Target + /// Create user target /// /// Create a messaging target. /// @@ -1991,7 +1991,7 @@ open class Users: Service { } /// - /// Get User Target + /// Get user target /// /// Get a user's push notification target by ID. /// @@ -2028,7 +2028,7 @@ open class Users: Service { } /// - /// Update User target + /// Update user target /// /// Update a messaging target. /// diff --git a/Sources/AppwriteEnums/Runtime.swift b/Sources/AppwriteEnums/Runtime.swift index 12abf93..688209b 100644 --- a/Sources/AppwriteEnums/Runtime.swift +++ b/Sources/AppwriteEnums/Runtime.swift @@ -21,6 +21,9 @@ public enum Runtime: String, Codable { case python311 = "python-3.11" case python312 = "python-3.12" case pythonMl311 = "python-ml-3.11" + case deno121 = "deno-1.21" + case deno124 = "deno-1.24" + case deno135 = "deno-1.35" case deno140 = "deno-1.40" case dart215 = "dart-2.15" case dart216 = "dart-2.16" diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index 0f04430..87739ab 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -38,7 +38,7 @@ public class Execution { public let responseStatusCode: Int /// HTTP response body. This will return empty unless execution is created as synchronous. - public let responseBody: String + public let responseBody: payload /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. public let responseHeaders: [Headers] @@ -68,7 +68,7 @@ public class Execution { requestPath: String, requestHeaders: [Headers], responseStatusCode: Int, - responseBody: String, + responseBody: payload, responseHeaders: [Headers], logs: String, errors: String, @@ -129,7 +129,7 @@ public class Execution { requestPath: map["requestPath"] as! String, requestHeaders: (map["requestHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, responseStatusCode: map["responseStatusCode"] as! Int, - responseBody: map["responseBody"] as! String, + responseBody: map["responseBody"] as! payload, responseHeaders: (map["responseHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, logs: map["logs"] as! String, errors: map["errors"] as! String, diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 560f1a9..c7e9d80 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -10,7 +10,7 @@ let functions = Functions(client) let execution = try await functions.createExecution( functionId: "", - body: "", // optional + body: , // optional async: false, // optional path: "", // optional method: .gET, // optional From a03ac7989671f74e7db6dfb94f57de1080b375e9 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:22:40 +0100 Subject: [PATCH 2/5] feat: multipart --- Sources/AppwriteEnums/ImageFormat.swift | 1 + Sources/AppwriteModels/AttributeBoolean.swift | 14 +++++++++++++ .../AppwriteModels/AttributeDatetime.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeEmail.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeEnum.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeFloat.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeInteger.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeIp.swift | 14 +++++++++++++ .../AttributeRelationship.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeString.swift | 14 +++++++++++++ Sources/AppwriteModels/AttributeUrl.swift | 14 +++++++++++++ Sources/AppwriteModels/Index.swift | 20 ++++++++++++++++--- 12 files changed, 158 insertions(+), 3 deletions(-) diff --git a/Sources/AppwriteEnums/ImageFormat.swift b/Sources/AppwriteEnums/ImageFormat.swift index f4f49ee..c09183d 100644 --- a/Sources/AppwriteEnums/ImageFormat.swift +++ b/Sources/AppwriteEnums/ImageFormat.swift @@ -6,6 +6,7 @@ public enum ImageFormat: String, Codable { case gif = "gif" case png = "png" case webp = "webp" + case avif = "avif" public func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() diff --git a/Sources/AppwriteModels/AttributeBoolean.swift b/Sources/AppwriteModels/AttributeBoolean.swift index 11bb89c..f8373c4 100644 --- a/Sources/AppwriteModels/AttributeBoolean.swift +++ b/Sources/AppwriteModels/AttributeBoolean.swift @@ -22,6 +22,12 @@ public class AttributeBoolean { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// Default value for attribute when not provided. Cannot be set when attribute is required. public let `default`: Bool? @@ -33,6 +39,8 @@ public class AttributeBoolean { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, `default`: Bool? ) { self.key = key @@ -41,6 +49,8 @@ public class AttributeBoolean { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.`default` = `default` } @@ -52,6 +62,8 @@ public class AttributeBoolean { "error": error as Any, "`required`": `required` as Any, "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, "`default`": `default` as Any ] } @@ -64,6 +76,8 @@ public class AttributeBoolean { 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/AttributeDatetime.swift b/Sources/AppwriteModels/AttributeDatetime.swift index 24beb48..260e978 100644 --- a/Sources/AppwriteModels/AttributeDatetime.swift +++ b/Sources/AppwriteModels/AttributeDatetime.swift @@ -22,6 +22,12 @@ public class AttributeDatetime { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// ISO 8601 format. public let format: String @@ -36,6 +42,8 @@ public class AttributeDatetime { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, format: String, `default`: String? ) { @@ -45,6 +53,8 @@ public class AttributeDatetime { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.format = format self.`default` = `default` } @@ -57,6 +67,8 @@ public class AttributeDatetime { "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 ] @@ -70,6 +82,8 @@ public class AttributeDatetime { 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/AttributeEmail.swift b/Sources/AppwriteModels/AttributeEmail.swift index f6a7098..9223060 100644 --- a/Sources/AppwriteModels/AttributeEmail.swift +++ b/Sources/AppwriteModels/AttributeEmail.swift @@ -22,6 +22,12 @@ public class AttributeEmail { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// String format. public let format: String @@ -36,6 +42,8 @@ public class AttributeEmail { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, format: String, `default`: String? ) { @@ -45,6 +53,8 @@ public class AttributeEmail { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.format = format self.`default` = `default` } @@ -57,6 +67,8 @@ public class AttributeEmail { "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 ] @@ -70,6 +82,8 @@ public class AttributeEmail { 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/AttributeEnum.swift b/Sources/AppwriteModels/AttributeEnum.swift index 003f961..c856a0d 100644 --- a/Sources/AppwriteModels/AttributeEnum.swift +++ b/Sources/AppwriteModels/AttributeEnum.swift @@ -22,6 +22,12 @@ public class AttributeEnum { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// Array of elements in enumerated type. public let elements: [Any] @@ -39,6 +45,8 @@ public class AttributeEnum { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, elements: [Any], format: String, `default`: String? @@ -49,6 +57,8 @@ public class AttributeEnum { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.elements = elements self.format = format self.`default` = `default` @@ -62,6 +72,8 @@ public class AttributeEnum { "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 @@ -76,6 +88,8 @@ public class AttributeEnum { 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! [Any], format: map["format"] as! String, `default`: map["default"] as? String diff --git a/Sources/AppwriteModels/AttributeFloat.swift b/Sources/AppwriteModels/AttributeFloat.swift index 27869a1..72d2353 100644 --- a/Sources/AppwriteModels/AttributeFloat.swift +++ b/Sources/AppwriteModels/AttributeFloat.swift @@ -22,6 +22,12 @@ public class AttributeFloat { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// Minimum value to enforce for new documents. public let min: Double? @@ -39,6 +45,8 @@ public class AttributeFloat { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, min: Double?, max: Double?, `default`: Double? @@ -49,6 +57,8 @@ public class AttributeFloat { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.min = min self.max = max self.`default` = `default` @@ -62,6 +72,8 @@ public class AttributeFloat { "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 @@ -76,6 +88,8 @@ public class AttributeFloat { 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/AttributeInteger.swift b/Sources/AppwriteModels/AttributeInteger.swift index bf85a88..eaca8ac 100644 --- a/Sources/AppwriteModels/AttributeInteger.swift +++ b/Sources/AppwriteModels/AttributeInteger.swift @@ -22,6 +22,12 @@ public class AttributeInteger { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// Minimum value to enforce for new documents. public let min: Int? @@ -39,6 +45,8 @@ public class AttributeInteger { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, min: Int?, max: Int?, `default`: Int? @@ -49,6 +57,8 @@ public class AttributeInteger { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.min = min self.max = max self.`default` = `default` @@ -62,6 +72,8 @@ public class AttributeInteger { "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 @@ -76,6 +88,8 @@ public class AttributeInteger { 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/AttributeIp.swift b/Sources/AppwriteModels/AttributeIp.swift index 5bce92e..39bd657 100644 --- a/Sources/AppwriteModels/AttributeIp.swift +++ b/Sources/AppwriteModels/AttributeIp.swift @@ -22,6 +22,12 @@ public class AttributeIp { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// String format. public let format: String @@ -36,6 +42,8 @@ public class AttributeIp { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, format: String, `default`: String? ) { @@ -45,6 +53,8 @@ public class AttributeIp { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.format = format self.`default` = `default` } @@ -57,6 +67,8 @@ public class AttributeIp { "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 ] @@ -70,6 +82,8 @@ public class AttributeIp { 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/AttributeRelationship.swift b/Sources/AppwriteModels/AttributeRelationship.swift index b1246a7..8d8c8d0 100644 --- a/Sources/AppwriteModels/AttributeRelationship.swift +++ b/Sources/AppwriteModels/AttributeRelationship.swift @@ -22,6 +22,12 @@ public class AttributeRelationship { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// The ID of the related collection. public let relatedCollection: String @@ -48,6 +54,8 @@ public class AttributeRelationship { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, relatedCollection: String, relationType: String, twoWay: Bool, @@ -61,6 +69,8 @@ public class AttributeRelationship { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.relatedCollection = relatedCollection self.relationType = relationType self.twoWay = twoWay @@ -77,6 +87,8 @@ public class AttributeRelationship { "error": error as Any, "`required`": `required` as Any, "array": array as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any, "relatedCollection": relatedCollection as Any, "relationType": relationType as Any, "twoWay": twoWay as Any, @@ -94,6 +106,8 @@ public class AttributeRelationship { 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, relatedCollection: map["relatedCollection"] as! String, relationType: map["relationType"] as! String, twoWay: map["twoWay"] as! Bool, diff --git a/Sources/AppwriteModels/AttributeString.swift b/Sources/AppwriteModels/AttributeString.swift index c6b0f6e..d609b0a 100644 --- a/Sources/AppwriteModels/AttributeString.swift +++ b/Sources/AppwriteModels/AttributeString.swift @@ -22,6 +22,12 @@ public class AttributeString { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// Attribute size. public let size: Int @@ -36,6 +42,8 @@ public class AttributeString { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, size: Int, `default`: String? ) { @@ -45,6 +53,8 @@ public class AttributeString { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.size = size self.`default` = `default` } @@ -57,6 +67,8 @@ public class AttributeString { "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 ] @@ -70,6 +82,8 @@ public class AttributeString { 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 ) diff --git a/Sources/AppwriteModels/AttributeUrl.swift b/Sources/AppwriteModels/AttributeUrl.swift index 0853bd6..952d990 100644 --- a/Sources/AppwriteModels/AttributeUrl.swift +++ b/Sources/AppwriteModels/AttributeUrl.swift @@ -22,6 +22,12 @@ public class AttributeUrl { /// Is attribute an array? public let array: Bool? + /// Attribute creation date in ISO 8601 format. + public let createdAt: String + + /// Attribute update date in ISO 8601 format. + public let updatedAt: String + /// String format. public let format: String @@ -36,6 +42,8 @@ public class AttributeUrl { error: String, `required`: Bool, array: Bool?, + createdAt: String, + updatedAt: String, format: String, `default`: String? ) { @@ -45,6 +53,8 @@ public class AttributeUrl { self.error = error self.`required` = `required` self.array = array + self.createdAt = createdAt + self.updatedAt = updatedAt self.format = format self.`default` = `default` } @@ -57,6 +67,8 @@ public class AttributeUrl { "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 ] @@ -70,6 +82,8 @@ public class AttributeUrl { 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/Index.swift b/Sources/AppwriteModels/Index.swift index c878e39..c728323 100644 --- a/Sources/AppwriteModels/Index.swift +++ b/Sources/AppwriteModels/Index.swift @@ -22,6 +22,12 @@ public class Index { /// Index orders. public let orders: [Any]? + /// Index creation date in ISO 8601 format. + public let createdAt: String + + /// Index update date in ISO 8601 format. + public let updatedAt: String + init( key: String, @@ -29,7 +35,9 @@ public class Index { status: String, error: String, attributes: [Any], - orders: [Any]? + orders: [Any]?, + createdAt: String, + updatedAt: String ) { self.key = key self.type = type @@ -37,6 +45,8 @@ public class Index { self.error = error self.attributes = attributes self.orders = orders + self.createdAt = createdAt + self.updatedAt = updatedAt } public func toMap() -> [String: Any] { @@ -46,7 +56,9 @@ public class Index { "status": status as Any, "error": error as Any, "attributes": attributes as Any, - "orders": orders as Any + "orders": orders as Any, + "$createdAt": createdAt as Any, + "$updatedAt": updatedAt as Any ] } @@ -57,7 +69,9 @@ public class Index { status: map["status"] as! String, error: map["error"] as! String, attributes: map["attributes"] as! [Any], - orders: map["orders"] as? [Any] + orders: map["orders"] as? [Any], + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String ) } } From f62348c3c0ce05c88fb990545e90137beade549e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 11 Dec 2024 00:36:47 +1300 Subject: [PATCH 3/5] Add new push message parameters --- README.md | 4 +-- Sources/Appwrite/Client.swift | 16 ++++----- Sources/Appwrite/Services/Account.swift | 4 +-- Sources/Appwrite/Services/Functions.swift | 26 ++++++-------- Sources/Appwrite/Services/Messaging.swift | 34 ++++++++++++++----- Sources/Appwrite/Services/Teams.swift | 6 ++-- .../AppwriteEnums/AuthenticationFactor.swift | 7 ++-- Sources/AppwriteEnums/AuthenticatorType.swift | 7 ++-- Sources/AppwriteEnums/Browser.swift | 7 ++-- Sources/AppwriteEnums/Compression.swift | 7 ++-- Sources/AppwriteEnums/CreditCard.swift | 7 ++-- Sources/AppwriteEnums/ExecutionMethod.swift | 7 ++-- Sources/AppwriteEnums/Flag.swift | 7 ++-- Sources/AppwriteEnums/ImageFormat.swift | 7 ++-- Sources/AppwriteEnums/ImageGravity.swift | 7 ++-- Sources/AppwriteEnums/IndexType.swift | 7 ++-- Sources/AppwriteEnums/MessagePriority.swift | 10 ++++++ .../AppwriteEnums/MessagingProviderType.swift | 7 ++-- Sources/AppwriteEnums/Name.swift | 7 ++-- Sources/AppwriteEnums/OAuthProvider.swift | 7 ++-- Sources/AppwriteEnums/PasswordHash.swift | 7 ++-- Sources/AppwriteEnums/RelationMutate.swift | 7 ++-- Sources/AppwriteEnums/RelationshipType.swift | 7 ++-- Sources/AppwriteEnums/Runtime.swift | 19 ++++++++--- Sources/AppwriteEnums/SmtpEncryption.swift | 7 ++-- Sources/AppwriteModels/AttributeEnum.swift | 6 ++-- Sources/AppwriteModels/Bucket.swift | 12 +++---- Sources/AppwriteModels/Collection.swift | 6 ++-- Sources/AppwriteModels/Document.swift | 6 ++-- Sources/AppwriteModels/Execution.swift | 12 +++---- Sources/AppwriteModels/File.swift | 6 ++-- Sources/AppwriteModels/Function.swift | 20 +++++------ Sources/AppwriteModels/Index.swift | 12 +++---- Sources/AppwriteModels/Membership.swift | 12 +++---- Sources/AppwriteModels/Message.swift | 24 ++++++------- Sources/AppwriteModels/MfaRecoveryCodes.swift | 6 ++-- Sources/AppwriteModels/Runtime.swift | 6 ++-- Sources/AppwriteModels/Session.swift | 6 ++-- Sources/AppwriteModels/Target.swift | 13 +++++-- Sources/AppwriteModels/Topic.swift | 6 ++-- Sources/AppwriteModels/User.swift | 6 ++-- .../databases/update-string-attribute.md | 2 +- docs/examples/functions/create-execution.md | 2 +- docs/examples/messaging/create-push.md | 12 ++++--- docs/examples/messaging/update-push.md | 6 +++- 45 files changed, 225 insertions(+), 194 deletions(-) create mode 100644 Sources/AppwriteEnums/MessagePriority.swift diff --git a/README.md b/README.md index 426c314..c670df4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![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.6.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.1-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) @@ -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: "6.1.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "6.2.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 4d6ae63..ecd48cd 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,7 +21,7 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "6.1.0", + "x-sdk-version": "6.2.0", "x-appwrite-response-format": "1.6.0" ] @@ -530,23 +530,23 @@ open class Client { if param is String || param is Int || param is Float + || param is Double || param is Bool || param is [String] || param is [Int] || param is [Float] + || param is [Double] || param is [Bool] || param is [String: Any] || param is [Int: Any] || param is [Float: Any] + || param is [Double: Any] || param is [Bool: Any] { encodedParams[key] = param - } else { - let value = try! (param as! Encodable).toJson() - - let range = value.index(value.startIndex, offsetBy: 1).. Void)? = nil + scheduledAt: String? = nil ) async throws -> AppwriteModels.Execution { let apiPath: String = "/functions/{functionId}/executions" .replacingOccurrences(of: "{functionId}", with: functionId) - var apiParams: [String: Any?] = [ + let apiParams: [String: Any?] = [ "body": body, "async": async, "path": path, @@ -751,23 +750,20 @@ open class Functions: Service { "scheduledAt": scheduledAt ] - var apiHeaders: [String: String] = [ - "content-type": "multipart/form-data" + let apiHeaders: [String: String] = [ + "content-type": "application/json" ] let converter: (Any) -> AppwriteModels.Execution = { response in return AppwriteModels.Execution.from(map: response as! [String: Any]) } - let idParamName: String? = nil - return try await client.chunkedUpload( + return try await client.call( + method: "POST", path: apiPath, - headers: &apiHeaders, - params: &apiParams, - paramName: paramName, - idParamName: idParamName, - converter: converter, - onProgress: onProgress + headers: apiHeaders, + params: apiParams, + converter: converter ) } diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index b1f2c8f..e785a42 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -201,16 +201,19 @@ open class Messaging: Service { /// @param String sound /// @param String color /// @param String tag - /// @param String badge + /// @param Int badge /// @param Bool draft /// @param String scheduledAt + /// @param Bool contentAvailable + /// @param Bool critical + /// @param AppwriteEnums.MessagePriority priority /// @throws Exception /// @return array /// open func createPush( messageId: String, - title: String, - body: String, + title: String? = nil, + body: String? = nil, topics: [String]? = nil, users: [String]? = nil, targets: [String]? = nil, @@ -221,9 +224,12 @@ open class Messaging: Service { sound: String? = nil, color: String? = nil, tag: String? = nil, - badge: String? = nil, + badge: Int? = nil, draft: Bool? = nil, - scheduledAt: String? = nil + scheduledAt: String? = nil, + contentAvailable: Bool? = nil, + critical: Bool? = nil, + priority: AppwriteEnums.MessagePriority? = nil ) async throws -> AppwriteModels.Message { let apiPath: String = "/messaging/messages/push" @@ -243,7 +249,10 @@ open class Messaging: Service { "tag": tag, "badge": badge, "draft": draft, - "scheduledAt": scheduledAt + "scheduledAt": scheduledAt, + "contentAvailable": contentAvailable, + "critical": critical, + "priority": priority ] let apiHeaders: [String: String] = [ @@ -285,6 +294,9 @@ open class Messaging: Service { /// @param Int badge /// @param Bool draft /// @param String scheduledAt + /// @param Bool contentAvailable + /// @param Bool critical + /// @param AppwriteEnums.MessagePriority priority /// @throws Exception /// @return array /// @@ -304,7 +316,10 @@ open class Messaging: Service { tag: String? = nil, badge: Int? = nil, draft: Bool? = nil, - scheduledAt: String? = nil + scheduledAt: String? = nil, + contentAvailable: Bool? = nil, + critical: Bool? = nil, + priority: AppwriteEnums.MessagePriority? = nil ) async throws -> AppwriteModels.Message { let apiPath: String = "/messaging/messages/push/{messageId}" .replacingOccurrences(of: "{messageId}", with: messageId) @@ -324,7 +339,10 @@ open class Messaging: Service { "tag": tag, "badge": badge, "draft": draft, - "scheduledAt": scheduledAt + "scheduledAt": scheduledAt, + "contentAvailable": contentAvailable, + "critical": critical, + "priority": priority ] let apiHeaders: [String: String] = [ diff --git a/Sources/Appwrite/Services/Teams.swift b/Sources/Appwrite/Services/Teams.swift index b926efd..a4d3123 100644 --- a/Sources/Appwrite/Services/Teams.swift +++ b/Sources/Appwrite/Services/Teams.swift @@ -286,7 +286,8 @@ open class Teams: Service { /// List team memberships /// /// Use this endpoint to list a team's members using the team's ID. All team - /// members have read access to this endpoint. + /// members have read access to this endpoint. Hide sensitive attributes from + /// the response by toggling membership privacy in the Console. /// /// @param String teamId /// @param [String] queries @@ -401,7 +402,8 @@ open class Teams: Service { /// Get team membership /// /// Get a team member by the membership unique id. All team members have read - /// access for this resource. + /// access for this resource. Hide sensitive attributes from the response by + /// toggling membership privacy in the Console. /// /// @param String teamId /// @param String membershipId diff --git a/Sources/AppwriteEnums/AuthenticationFactor.swift b/Sources/AppwriteEnums/AuthenticationFactor.swift index c8f0559..1768544 100644 --- a/Sources/AppwriteEnums/AuthenticationFactor.swift +++ b/Sources/AppwriteEnums/AuthenticationFactor.swift @@ -1,13 +1,12 @@ import Foundation -public enum AuthenticationFactor: String, Codable { +public enum AuthenticationFactor: String, CustomStringConvertible { case email = "email" case phone = "phone" case totp = "totp" case recoverycode = "recoverycode" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/AuthenticatorType.swift b/Sources/AppwriteEnums/AuthenticatorType.swift index fd516fd..066e377 100644 --- a/Sources/AppwriteEnums/AuthenticatorType.swift +++ b/Sources/AppwriteEnums/AuthenticatorType.swift @@ -1,10 +1,9 @@ import Foundation -public enum AuthenticatorType: String, Codable { +public enum AuthenticatorType: String, CustomStringConvertible { case totp = "totp" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/Browser.swift b/Sources/AppwriteEnums/Browser.swift index dbc88fc..f1fd1d2 100644 --- a/Sources/AppwriteEnums/Browser.swift +++ b/Sources/AppwriteEnums/Browser.swift @@ -1,6 +1,6 @@ import Foundation -public enum Browser: String, Codable { +public enum Browser: String, CustomStringConvertible { case avantBrowser = "aa" case androidWebViewBeta = "an" case googleChrome = "ch" @@ -16,8 +16,7 @@ public enum Browser: String, Codable { case opera = "op" case operaNext = "on" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/Compression.swift b/Sources/AppwriteEnums/Compression.swift index a9256c5..054e1ad 100644 --- a/Sources/AppwriteEnums/Compression.swift +++ b/Sources/AppwriteEnums/Compression.swift @@ -1,12 +1,11 @@ import Foundation -public enum Compression: String, Codable { +public enum Compression: String, CustomStringConvertible { case `none` = "none" case gzip = "gzip" case zstd = "zstd" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/CreditCard.swift b/Sources/AppwriteEnums/CreditCard.swift index 3720b54..0922fbc 100644 --- a/Sources/AppwriteEnums/CreditCard.swift +++ b/Sources/AppwriteEnums/CreditCard.swift @@ -1,6 +1,6 @@ import Foundation -public enum CreditCard: String, Codable { +public enum CreditCard: String, CustomStringConvertible { case americanExpress = "amex" case argencard = "argencard" case cabal = "cabal" @@ -18,8 +18,7 @@ public enum CreditCard: String, Codable { case mIR = "mir" case maestro = "maestro" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/ExecutionMethod.swift b/Sources/AppwriteEnums/ExecutionMethod.swift index b03f856..85111a6 100644 --- a/Sources/AppwriteEnums/ExecutionMethod.swift +++ b/Sources/AppwriteEnums/ExecutionMethod.swift @@ -1,6 +1,6 @@ import Foundation -public enum ExecutionMethod: String, Codable { +public enum ExecutionMethod: String, CustomStringConvertible { case gET = "GET" case pOST = "POST" case pUT = "PUT" @@ -8,8 +8,7 @@ public enum ExecutionMethod: String, Codable { case dELETE = "DELETE" case oPTIONS = "OPTIONS" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/Flag.swift b/Sources/AppwriteEnums/Flag.swift index c577fcf..53ebf33 100644 --- a/Sources/AppwriteEnums/Flag.swift +++ b/Sources/AppwriteEnums/Flag.swift @@ -1,6 +1,6 @@ import Foundation -public enum Flag: String, Codable { +public enum Flag: String, CustomStringConvertible { case afghanistan = "af" case angola = "ao" case albania = "al" @@ -197,8 +197,7 @@ public enum Flag: String, Codable { case zambia = "zm" case zimbabwe = "zw" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/ImageFormat.swift b/Sources/AppwriteEnums/ImageFormat.swift index c09183d..2081ed0 100644 --- a/Sources/AppwriteEnums/ImageFormat.swift +++ b/Sources/AppwriteEnums/ImageFormat.swift @@ -1,6 +1,6 @@ import Foundation -public enum ImageFormat: String, Codable { +public enum ImageFormat: String, CustomStringConvertible { case jpg = "jpg" case jpeg = "jpeg" case gif = "gif" @@ -8,8 +8,7 @@ public enum ImageFormat: String, Codable { case webp = "webp" case avif = "avif" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/ImageGravity.swift b/Sources/AppwriteEnums/ImageGravity.swift index 1997ace..386f93d 100644 --- a/Sources/AppwriteEnums/ImageGravity.swift +++ b/Sources/AppwriteEnums/ImageGravity.swift @@ -1,6 +1,6 @@ import Foundation -public enum ImageGravity: String, Codable { +public enum ImageGravity: String, CustomStringConvertible { case center = "center" case topLeft = "top-left" case top = "top" @@ -11,8 +11,7 @@ public enum ImageGravity: String, Codable { case bottom = "bottom" case bottomRight = "bottom-right" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/IndexType.swift b/Sources/AppwriteEnums/IndexType.swift index a6ff794..9687f08 100644 --- a/Sources/AppwriteEnums/IndexType.swift +++ b/Sources/AppwriteEnums/IndexType.swift @@ -1,12 +1,11 @@ import Foundation -public enum IndexType: String, Codable { +public enum IndexType: String, CustomStringConvertible { case key = "key" case fulltext = "fulltext" case unique = "unique" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/MessagePriority.swift b/Sources/AppwriteEnums/MessagePriority.swift new file mode 100644 index 0000000..59ad9c6 --- /dev/null +++ b/Sources/AppwriteEnums/MessagePriority.swift @@ -0,0 +1,10 @@ +import Foundation + +public enum MessagePriority: String, CustomStringConvertible { + case normal = "normal" + case high = "high" + + public var description: String { + return rawValue + } +} diff --git a/Sources/AppwriteEnums/MessagingProviderType.swift b/Sources/AppwriteEnums/MessagingProviderType.swift index e6c8332..6ea6f37 100644 --- a/Sources/AppwriteEnums/MessagingProviderType.swift +++ b/Sources/AppwriteEnums/MessagingProviderType.swift @@ -1,12 +1,11 @@ import Foundation -public enum MessagingProviderType: String, Codable { +public enum MessagingProviderType: String, CustomStringConvertible { case email = "email" case sms = "sms" case push = "push" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/Name.swift b/Sources/AppwriteEnums/Name.swift index f792c31..3db0d91 100644 --- a/Sources/AppwriteEnums/Name.swift +++ b/Sources/AppwriteEnums/Name.swift @@ -1,6 +1,6 @@ import Foundation -public enum Name: String, Codable { +public enum Name: String, CustomStringConvertible { case v1Database = "v1-database" case v1Deletes = "v1-deletes" case v1Audits = "v1-audits" @@ -14,8 +14,7 @@ public enum Name: String, Codable { case v1Messaging = "v1-messaging" case v1Migrations = "v1-migrations" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/OAuthProvider.swift b/Sources/AppwriteEnums/OAuthProvider.swift index 3414684..e00ba46 100644 --- a/Sources/AppwriteEnums/OAuthProvider.swift +++ b/Sources/AppwriteEnums/OAuthProvider.swift @@ -1,6 +1,6 @@ import Foundation -public enum OAuthProvider: String, Codable { +public enum OAuthProvider: String, CustomStringConvertible { case amazon = "amazon" case apple = "apple" case auth0 = "auth0" @@ -41,8 +41,7 @@ public enum OAuthProvider: String, Codable { case zoom = "zoom" case mock = "mock" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/PasswordHash.swift b/Sources/AppwriteEnums/PasswordHash.swift index 5b6845f..078ad8a 100644 --- a/Sources/AppwriteEnums/PasswordHash.swift +++ b/Sources/AppwriteEnums/PasswordHash.swift @@ -1,6 +1,6 @@ import Foundation -public enum PasswordHash: String, Codable { +public enum PasswordHash: String, CustomStringConvertible { case sha1 = "sha1" case sha224 = "sha224" case sha256 = "sha256" @@ -13,8 +13,7 @@ public enum PasswordHash: String, Codable { case sha3384 = "sha3-384" case sha3512 = "sha3-512" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/RelationMutate.swift b/Sources/AppwriteEnums/RelationMutate.swift index 174e3bf..86ec10f 100644 --- a/Sources/AppwriteEnums/RelationMutate.swift +++ b/Sources/AppwriteEnums/RelationMutate.swift @@ -1,12 +1,11 @@ import Foundation -public enum RelationMutate: String, Codable { +public enum RelationMutate: String, CustomStringConvertible { case cascade = "cascade" case restrict = "restrict" case setNull = "setNull" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/RelationshipType.swift b/Sources/AppwriteEnums/RelationshipType.swift index 5c5efbe..a02c161 100644 --- a/Sources/AppwriteEnums/RelationshipType.swift +++ b/Sources/AppwriteEnums/RelationshipType.swift @@ -1,13 +1,12 @@ import Foundation -public enum RelationshipType: String, Codable { +public enum RelationshipType: String, CustomStringConvertible { case oneToOne = "oneToOne" case manyToOne = "manyToOne" case manyToMany = "manyToMany" case oneToMany = "oneToMany" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/Runtime.swift b/Sources/AppwriteEnums/Runtime.swift index 688209b..6fbf901 100644 --- a/Sources/AppwriteEnums/Runtime.swift +++ b/Sources/AppwriteEnums/Runtime.swift @@ -1,12 +1,13 @@ import Foundation -public enum Runtime: String, Codable { +public enum Runtime: String, CustomStringConvertible { case node145 = "node-14.5" case node160 = "node-16.0" case node180 = "node-18.0" case node190 = "node-19.0" case node200 = "node-20.0" case node210 = "node-21.0" + case node22 = "node-22" case php80 = "php-8.0" case php81 = "php-8.1" case php82 = "php-8.2" @@ -25,6 +26,8 @@ public enum Runtime: String, Codable { case deno124 = "deno-1.24" case deno135 = "deno-1.35" case deno140 = "deno-1.40" + case deno146 = "deno-1.46" + case deno20 = "deno-2.0" case dart215 = "dart-2.15" case dart216 = "dart-2.16" case dart217 = "dart-2.17" @@ -32,27 +35,33 @@ public enum Runtime: String, Codable { case dart30 = "dart-3.0" case dart31 = "dart-3.1" case dart33 = "dart-3.3" - case dotnet31 = "dotnet-3.1" + case dart35 = "dart-3.5" case dotnet60 = "dotnet-6.0" case dotnet70 = "dotnet-7.0" + case dotnet80 = "dotnet-8.0" case java80 = "java-8.0" case java110 = "java-11.0" case java170 = "java-17.0" case java180 = "java-18.0" case java210 = "java-21.0" + case java22 = "java-22" case swift55 = "swift-5.5" case swift58 = "swift-5.8" case swift59 = "swift-5.9" + case swift510 = "swift-5.10" case kotlin16 = "kotlin-1.6" case kotlin18 = "kotlin-1.8" case kotlin19 = "kotlin-1.9" + case kotlin20 = "kotlin-2.0" case cpp17 = "cpp-17" case cpp20 = "cpp-20" case bun10 = "bun-1.0" + case bun11 = "bun-1.1" case go123 = "go-1.23" + case static1 = "static-1" + case flutter324 = "flutter-3.24" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteEnums/SmtpEncryption.swift b/Sources/AppwriteEnums/SmtpEncryption.swift index 6c23257..d3f8e92 100644 --- a/Sources/AppwriteEnums/SmtpEncryption.swift +++ b/Sources/AppwriteEnums/SmtpEncryption.swift @@ -1,12 +1,11 @@ import Foundation -public enum SmtpEncryption: String, Codable { +public enum SmtpEncryption: String, CustomStringConvertible { case `none` = "none" case ssl = "ssl" case tls = "tls" - public func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - try container.encode(rawValue) + public var description: String { + return rawValue } } diff --git a/Sources/AppwriteModels/AttributeEnum.swift b/Sources/AppwriteModels/AttributeEnum.swift index c856a0d..8694823 100644 --- a/Sources/AppwriteModels/AttributeEnum.swift +++ b/Sources/AppwriteModels/AttributeEnum.swift @@ -29,7 +29,7 @@ public class AttributeEnum { public let updatedAt: String /// Array of elements in enumerated type. - public let elements: [Any] + public let elements: [String] /// String format. public let format: String @@ -47,7 +47,7 @@ public class AttributeEnum { array: Bool?, createdAt: String, updatedAt: String, - elements: [Any], + elements: [String], format: String, `default`: String? ) { @@ -90,7 +90,7 @@ public class AttributeEnum { array: map["array"] as? Bool, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - elements: map["elements"] as! [Any], + elements: map["elements"] as! [String], format: map["format"] as! String, `default`: map["default"] as? String ) diff --git a/Sources/AppwriteModels/Bucket.swift b/Sources/AppwriteModels/Bucket.swift index 9986ae6..d10f6a8 100644 --- a/Sources/AppwriteModels/Bucket.swift +++ b/Sources/AppwriteModels/Bucket.swift @@ -14,7 +14,7 @@ public class Bucket { public let updatedAt: String /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - public let permissions: [Any] + public let permissions: [String] /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). public let fileSecurity: Bool @@ -29,7 +29,7 @@ public class Bucket { public let maximumFileSize: Int /// Allowed file extensions. - public let allowedFileExtensions: [Any] + public let allowedFileExtensions: [String] /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). public let compression: String @@ -45,12 +45,12 @@ public class Bucket { id: String, createdAt: String, updatedAt: String, - permissions: [Any], + permissions: [String], fileSecurity: Bool, name: String, enabled: Bool, maximumFileSize: Int, - allowedFileExtensions: [Any], + allowedFileExtensions: [String], compression: String, encryption: Bool, antivirus: Bool @@ -91,12 +91,12 @@ public class Bucket { id: map["$id"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [Any], + permissions: map["$permissions"] as! [String], fileSecurity: map["fileSecurity"] as! Bool, name: map["name"] as! String, enabled: map["enabled"] as! Bool, maximumFileSize: map["maximumFileSize"] as! Int, - allowedFileExtensions: map["allowedFileExtensions"] as! [Any], + allowedFileExtensions: map["allowedFileExtensions"] as! [String], compression: map["compression"] as! String, encryption: map["encryption"] as! Bool, antivirus: map["antivirus"] as! Bool diff --git a/Sources/AppwriteModels/Collection.swift b/Sources/AppwriteModels/Collection.swift index 7ff6243..7b609ad 100644 --- a/Sources/AppwriteModels/Collection.swift +++ b/Sources/AppwriteModels/Collection.swift @@ -14,7 +14,7 @@ public class Collection { public let updatedAt: String /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - public let permissions: [Any] + public let permissions: [String] /// Database ID. public let databaseId: String @@ -39,7 +39,7 @@ public class Collection { id: String, createdAt: String, updatedAt: String, - permissions: [Any], + permissions: [String], databaseId: String, name: String, enabled: Bool, @@ -79,7 +79,7 @@ public class Collection { id: map["$id"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [Any], + permissions: map["$permissions"] as! [String], databaseId: map["databaseId"] as! String, name: map["name"] as! String, enabled: map["enabled"] as! Bool, diff --git a/Sources/AppwriteModels/Document.swift b/Sources/AppwriteModels/Document.swift index 94069f9..c0c49c6 100644 --- a/Sources/AppwriteModels/Document.swift +++ b/Sources/AppwriteModels/Document.swift @@ -20,7 +20,7 @@ public class Document { public let updatedAt: String /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - public let permissions: [Any] + public let permissions: [String] /// Additional properties public let data: T @@ -31,7 +31,7 @@ public class Document { databaseId: String, createdAt: String, updatedAt: String, - permissions: [Any], + permissions: [String], data: T ) { self.id = id @@ -62,7 +62,7 @@ public class Document { databaseId: map["$databaseId"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [Any], + permissions: map["$permissions"] as! [String], data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) ) } diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index 87739ab..d589342 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -14,7 +14,7 @@ public class Execution { public let updatedAt: String /// Execution roles. - public let permissions: [Any] + public let permissions: [String] /// Function ID. public let functionId: String @@ -38,7 +38,7 @@ public class Execution { public let responseStatusCode: Int /// HTTP response body. This will return empty unless execution is created as synchronous. - public let responseBody: payload + public let responseBody: String /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. public let responseHeaders: [Headers] @@ -60,7 +60,7 @@ public class Execution { id: String, createdAt: String, updatedAt: String, - permissions: [Any], + permissions: [String], functionId: String, trigger: String, status: String, @@ -68,7 +68,7 @@ public class Execution { requestPath: String, requestHeaders: [Headers], responseStatusCode: Int, - responseBody: payload, + responseBody: String, responseHeaders: [Headers], logs: String, errors: String, @@ -121,7 +121,7 @@ public class Execution { id: map["$id"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [Any], + permissions: map["$permissions"] as! [String], functionId: map["functionId"] as! String, trigger: map["trigger"] as! String, status: map["status"] as! String, @@ -129,7 +129,7 @@ public class Execution { requestPath: map["requestPath"] as! String, requestHeaders: (map["requestHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, responseStatusCode: map["responseStatusCode"] as! Int, - responseBody: map["responseBody"] as! payload, + responseBody: map["responseBody"] as! String, responseHeaders: (map["responseHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, logs: map["logs"] as! String, errors: map["errors"] as! String, diff --git a/Sources/AppwriteModels/File.swift b/Sources/AppwriteModels/File.swift index 04a5b89..db896ab 100644 --- a/Sources/AppwriteModels/File.swift +++ b/Sources/AppwriteModels/File.swift @@ -17,7 +17,7 @@ public class File { public let updatedAt: String /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - public let permissions: [Any] + public let permissions: [String] /// File name. public let name: String @@ -43,7 +43,7 @@ public class File { bucketId: String, createdAt: String, updatedAt: String, - permissions: [Any], + permissions: [String], name: String, signature: String, mimeType: String, @@ -86,7 +86,7 @@ public class File { bucketId: map["bucketId"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [Any], + permissions: map["$permissions"] as! [String], name: map["name"] as! String, signature: map["signature"] as! String, mimeType: map["mimeType"] as! String, diff --git a/Sources/AppwriteModels/Function.swift b/Sources/AppwriteModels/Function.swift index 2eb3f97..c91ce93 100644 --- a/Sources/AppwriteModels/Function.swift +++ b/Sources/AppwriteModels/Function.swift @@ -14,7 +14,7 @@ public class Function { public let updatedAt: String /// Execution permissions. - public let execute: [Any] + public let execute: [String] /// Function name. public let name: String @@ -35,15 +35,15 @@ public class Function { public let deployment: String /// Allowed permission scopes. - public let scopes: [Any] + public let scopes: [String] /// Function variables. public let vars: [Variable] /// Function trigger events. - public let events: [Any] + public let events: [String] - /// Function execution schedult in CRON format. + /// Function execution schedule in CRON format. public let schedule: String /// Function execution timeout in seconds. @@ -81,16 +81,16 @@ public class Function { id: String, createdAt: String, updatedAt: String, - execute: [Any], + execute: [String], name: String, enabled: Bool, live: Bool, logging: Bool, runtime: String, deployment: String, - scopes: [Any], + scopes: [String], vars: [Variable], - events: [Any], + events: [String], schedule: String, timeout: Int, entrypoint: String, @@ -163,16 +163,16 @@ public class Function { id: map["$id"] as! String, createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, - execute: map["execute"] as! [Any], + execute: map["execute"] as! [String], name: map["name"] as! String, enabled: map["enabled"] as! Bool, live: map["live"] as! Bool, logging: map["logging"] as! Bool, runtime: map["runtime"] as! String, deployment: map["deployment"] as! String, - scopes: map["scopes"] as! [Any], + scopes: map["scopes"] as! [String], vars: (map["vars"] as! [[String: Any]]).map { Variable.from(map: $0) }, - events: map["events"] as! [Any], + events: map["events"] as! [String], schedule: map["schedule"] as! String, timeout: map["timeout"] as! Int, entrypoint: map["entrypoint"] as! String, diff --git a/Sources/AppwriteModels/Index.swift b/Sources/AppwriteModels/Index.swift index c728323..019ec28 100644 --- a/Sources/AppwriteModels/Index.swift +++ b/Sources/AppwriteModels/Index.swift @@ -17,10 +17,10 @@ public class Index { public let error: String /// Index attributes. - public let attributes: [Any] + public let attributes: [String] /// Index orders. - public let orders: [Any]? + public let orders: [String]? /// Index creation date in ISO 8601 format. public let createdAt: String @@ -34,8 +34,8 @@ public class Index { type: String, status: String, error: String, - attributes: [Any], - orders: [Any]?, + attributes: [String], + orders: [String]?, createdAt: String, updatedAt: String ) { @@ -68,8 +68,8 @@ public class Index { type: map["type"] as! String, status: map["status"] as! String, error: map["error"] as! String, - attributes: map["attributes"] as! [Any], - orders: map["orders"] as? [Any], + attributes: map["attributes"] as! [String], + orders: map["orders"] as? [String], createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String ) diff --git a/Sources/AppwriteModels/Membership.swift b/Sources/AppwriteModels/Membership.swift index 55fb199..805cb47 100644 --- a/Sources/AppwriteModels/Membership.swift +++ b/Sources/AppwriteModels/Membership.swift @@ -16,10 +16,10 @@ public class Membership { /// User ID. public let userId: String - /// User name. + /// User name. Hide this attribute by toggling membership privacy in the Console. public let userName: String - /// User email address. + /// User email address. Hide this attribute by toggling membership privacy in the Console. public let userEmail: String /// Team ID. @@ -37,11 +37,11 @@ public class Membership { /// User confirmation status, true if the user has joined the team or false otherwise. public let confirm: Bool - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. public let mfa: Bool /// User list of roles - public let roles: [Any] + public let roles: [String] init( @@ -57,7 +57,7 @@ public class Membership { joined: String, confirm: Bool, mfa: Bool, - roles: [Any] + roles: [String] ) { self.id = id self.createdAt = createdAt @@ -106,7 +106,7 @@ public class Membership { joined: map["joined"] as! String, confirm: map["confirm"] as! Bool, mfa: map["mfa"] as! Bool, - roles: map["roles"] as! [Any] + roles: map["roles"] as! [String] ) } } diff --git a/Sources/AppwriteModels/Message.swift b/Sources/AppwriteModels/Message.swift index 32e8897..1bbe9f9 100644 --- a/Sources/AppwriteModels/Message.swift +++ b/Sources/AppwriteModels/Message.swift @@ -17,13 +17,13 @@ public class Message { public let providerType: String /// Topic IDs set as recipients. - public let topics: [Any] + public let topics: [String] /// User IDs set as recipients. - public let users: [Any] + public let users: [String] /// Target IDs set as recipients. - public let targets: [Any] + public let targets: [String] /// The scheduled time for message. public let scheduledAt: String? @@ -32,7 +32,7 @@ public class Message { public let deliveredAt: String? /// Delivery errors if any. - public let deliveryErrors: [Any]? + public let deliveryErrors: [String]? /// Number of recipients the message was delivered to. public let deliveredTotal: Int @@ -49,12 +49,12 @@ public class Message { createdAt: String, updatedAt: String, providerType: String, - topics: [Any], - users: [Any], - targets: [Any], + topics: [String], + users: [String], + targets: [String], scheduledAt: String?, deliveredAt: String?, - deliveryErrors: [Any]?, + deliveryErrors: [String]?, deliveredTotal: Int, data: Any, status: String @@ -98,12 +98,12 @@ public class Message { createdAt: map["$createdAt"] as! String, updatedAt: map["$updatedAt"] as! String, providerType: map["providerType"] as! String, - topics: map["topics"] as! [Any], - users: map["users"] as! [Any], - targets: map["targets"] as! [Any], + topics: map["topics"] as! [String], + users: map["users"] as! [String], + targets: map["targets"] as! [String], scheduledAt: map["scheduledAt"] as? String, deliveredAt: map["deliveredAt"] as? String, - deliveryErrors: map["deliveryErrors"] as? [Any], + deliveryErrors: map["deliveryErrors"] as? [String], deliveredTotal: map["deliveredTotal"] as! Int, data: map["data"] as! Any, status: map["status"] as! String diff --git a/Sources/AppwriteModels/MfaRecoveryCodes.swift b/Sources/AppwriteModels/MfaRecoveryCodes.swift index 8dd063b..314e11c 100644 --- a/Sources/AppwriteModels/MfaRecoveryCodes.swift +++ b/Sources/AppwriteModels/MfaRecoveryCodes.swift @@ -5,11 +5,11 @@ import JSONCodable public class MfaRecoveryCodes { /// Recovery codes. - public let recoveryCodes: [Any] + public let recoveryCodes: [String] init( - recoveryCodes: [Any] + recoveryCodes: [String] ) { self.recoveryCodes = recoveryCodes } @@ -22,7 +22,7 @@ public class MfaRecoveryCodes { public static func from(map: [String: Any] ) -> MfaRecoveryCodes { return MfaRecoveryCodes( - recoveryCodes: map["recoveryCodes"] as! [Any] + recoveryCodes: map["recoveryCodes"] as! [String] ) } } diff --git a/Sources/AppwriteModels/Runtime.swift b/Sources/AppwriteModels/Runtime.swift index 66906e1..01ea4c4 100644 --- a/Sources/AppwriteModels/Runtime.swift +++ b/Sources/AppwriteModels/Runtime.swift @@ -26,7 +26,7 @@ public class Runtime { public let logo: String /// List of supported architectures. - public let supports: [Any] + public let supports: [String] init( @@ -37,7 +37,7 @@ public class Runtime { base: String, image: String, logo: String, - supports: [Any] + supports: [String] ) { self.id = id self.key = key @@ -71,7 +71,7 @@ public class Runtime { base: map["base"] as! String, image: map["image"] as! String, logo: map["logo"] as! String, - supports: map["supports"] as! [Any] + supports: map["supports"] as! [String] ) } } diff --git a/Sources/AppwriteModels/Session.swift b/Sources/AppwriteModels/Session.swift index 7214468..86f4a7c 100644 --- a/Sources/AppwriteModels/Session.swift +++ b/Sources/AppwriteModels/Session.swift @@ -83,7 +83,7 @@ public class Session { public let current: Bool /// Returns a list of active session factors. - public let factors: [Any] + public let factors: [String] /// Secret used to authenticate the user. Only included if the request was made with an API key public let secret: String @@ -119,7 +119,7 @@ public class Session { countryCode: String, countryName: String, current: Bool, - factors: [Any], + factors: [String], secret: String, mfaUpdatedAt: String ) { @@ -216,7 +216,7 @@ public class Session { countryCode: map["countryCode"] as! String, countryName: map["countryName"] as! String, current: map["current"] as! Bool, - factors: map["factors"] as! [Any], + factors: map["factors"] as! [String], secret: map["secret"] as! String, mfaUpdatedAt: map["mfaUpdatedAt"] as! String ) diff --git a/Sources/AppwriteModels/Target.swift b/Sources/AppwriteModels/Target.swift index 087eca6..2e81790 100644 --- a/Sources/AppwriteModels/Target.swift +++ b/Sources/AppwriteModels/Target.swift @@ -28,6 +28,9 @@ public class Target { /// The target identifier. public let identifier: String + /// Is the target expired. + public let expired: Bool + init( id: String, @@ -37,7 +40,8 @@ public class Target { userId: String, providerId: String?, providerType: String, - identifier: String + identifier: String, + expired: Bool ) { self.id = id self.createdAt = createdAt @@ -47,6 +51,7 @@ public class Target { self.providerId = providerId self.providerType = providerType self.identifier = identifier + self.expired = expired } public func toMap() -> [String: Any] { @@ -58,7 +63,8 @@ public class Target { "userId": userId as Any, "providerId": providerId as Any, "providerType": providerType as Any, - "identifier": identifier as Any + "identifier": identifier as Any, + "expired": expired as Any ] } @@ -71,7 +77,8 @@ public class Target { userId: map["userId"] as! String, providerId: map["providerId"] as? String, providerType: map["providerType"] as! String, - identifier: map["identifier"] as! String + identifier: map["identifier"] as! String, + expired: map["expired"] as! Bool ) } } diff --git a/Sources/AppwriteModels/Topic.swift b/Sources/AppwriteModels/Topic.swift index c8398e6..bc89a07 100644 --- a/Sources/AppwriteModels/Topic.swift +++ b/Sources/AppwriteModels/Topic.swift @@ -26,7 +26,7 @@ public class Topic { public let pushTotal: Int /// Subscribe permissions. - public let subscribe: [Any] + public let subscribe: [String] init( @@ -37,7 +37,7 @@ public class Topic { emailTotal: Int, smsTotal: Int, pushTotal: Int, - subscribe: [Any] + subscribe: [String] ) { self.id = id self.createdAt = createdAt @@ -71,7 +71,7 @@ public class Topic { emailTotal: map["emailTotal"] as! Int, smsTotal: map["smsTotal"] as! Int, pushTotal: map["pushTotal"] as! Int, - subscribe: map["subscribe"] as! [Any] + subscribe: map["subscribe"] as! [String] ) } } diff --git a/Sources/AppwriteModels/User.swift b/Sources/AppwriteModels/User.swift index d12c343..0229dc5 100644 --- a/Sources/AppwriteModels/User.swift +++ b/Sources/AppwriteModels/User.swift @@ -32,7 +32,7 @@ public class User { public let status: Bool /// Labels for the user. - public let labels: [Any] + public let labels: [String] /// Password update time in ISO 8601 format. public let passwordUpdate: String @@ -72,7 +72,7 @@ public class User { hashOptions: Any?, registration: String, status: Bool, - labels: [Any], + labels: [String], passwordUpdate: String, email: String, phone: String, @@ -139,7 +139,7 @@ public class User { hashOptions: map["hashOptions"] as? Any, registration: map["registration"] as! String, status: map["status"] as! Bool, - labels: map["labels"] as! [Any], + labels: map["labels"] as! [String], passwordUpdate: map["passwordUpdate"] as! String, email: map["email"] as! String, phone: map["phone"] as! String, diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md index 5fafd5e..d3129dc 100644 --- a/docs/examples/databases/update-string-attribute.md +++ b/docs/examples/databases/update-string-attribute.md @@ -13,7 +13,7 @@ let attributeString = try await databases.updateStringAttribute( key: "", required: false, default: "", - size: 0, // optional + size: 1, // optional newKey: "" // optional ) diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index c7e9d80..560f1a9 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -10,7 +10,7 @@ let functions = Functions(client) let execution = try await functions.createExecution( functionId: "", - body: , // optional + body: "", // optional async: false, // optional path: "", // optional method: .gET, // optional diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md index dbc7bf0..42f48dd 100644 --- a/docs/examples/messaging/create-push.md +++ b/docs/examples/messaging/create-push.md @@ -1,4 +1,5 @@ import Appwrite +import AppwriteEnums let client = Client() .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -9,8 +10,8 @@ let messaging = Messaging(client) let message = try await messaging.createPush( messageId: "", - title: "", - body: "<BODY>", + title: "<TITLE>", // optional + body: "<BODY>", // optional topics: [], // optional users: [], // optional targets: [], // optional @@ -21,8 +22,11 @@ let message = try await messaging.createPush( sound: "<SOUND>", // optional color: "<COLOR>", // optional tag: "<TAG>", // optional - badge: "<BADGE>", // optional + badge: 0, // optional draft: false, // optional - scheduledAt: "" // optional + scheduledAt: "", // optional + contentAvailable: false, // optional + critical: false, // optional + priority: .normal // optional ) diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md index 40ce34b..02893a1 100644 --- a/docs/examples/messaging/update-push.md +++ b/docs/examples/messaging/update-push.md @@ -1,4 +1,5 @@ import Appwrite +import AppwriteEnums let client = Client() .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint @@ -23,6 +24,9 @@ let message = try await messaging.updatePush( tag: "<TAG>", // optional badge: 0, // optional draft: false, // optional - scheduledAt: "" // optional + scheduledAt: "", // optional + contentAvailable: false, // optional + critical: false, // optional + priority: .normal // optional ) From 456310cdbe80bcbacf1109bd075c599d518c3729 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:31:13 +0000 Subject: [PATCH 4/5] fix: pong response & chunked upload --- LICENSE | 2 +- README.md | 2 +- Sources/Appwrite/Client.swift | 32 ++++++++++++++--- Sources/Appwrite/Services/Account.swift | 10 ++++-- Sources/Appwrite/Services/Functions.swift | 12 +++++++ Sources/Appwrite/Services/Messaging.swift | 2 +- Sources/Appwrite/Services/Users.swift | 36 +++---------------- Sources/AppwriteEnums/ImageFormat.swift | 1 + docs/examples/account/update-mfa-challenge.md | 2 +- .../users/delete-mfa-authenticator.md | 2 +- 10 files changed, 57 insertions(+), 44 deletions(-) diff --git a/LICENSE b/LICENSE index 5479bb8..c1602fc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index c670df4..e02db02 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "6.2.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "6.2.1"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index ecd48cd..c9b3d10 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,7 +21,7 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "6.2.0", + "x-sdk-version": "6.2.1", "x-appwrite-response-format": "1.6.0" ] @@ -257,6 +257,26 @@ open class Client { ) ?? "" } + /// + /// Sends a "ping" request to Appwrite to verify connectivity. + /// + /// @return String + /// @throws Exception + /// + open func ping() async throws -> String { + let apiPath: String = "/ping" + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await call( + method: "GET", + path: apiPath, + headers: apiHeaders + ) + } + /// /// Make an API call /// @@ -392,15 +412,18 @@ open class Client { } } + var data = try await response.body.collect(upTo: Int.max) + switch response.status.code { case 0..<400: switch T.self { case is Bool.Type: return true as! T + case is String.Type: + return (data.readString(length: data.readableBytes) ?? "") as! T case is ByteBuffer.Type: - return try await response.body.collect(upTo: Int.max) as! T + return data as! T default: - let data = try await response.body.collect(upTo: Int.max) if data.readableBytes == 0 { return true as! T } @@ -410,7 +433,6 @@ open class Client { } default: var message = "" - var data = try await response.body.collect(upTo: Int.max) var type = "" do { @@ -466,7 +488,7 @@ open class Client { var offset = 0 var result = [String:Any]() - if idParamName != nil && params[idParamName!] as! String != "unique()" { + if idParamName != nil { // Make a request to check if a file already exists do { let map = try await call( diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 2bf91c7..cce7e89 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -584,7 +584,7 @@ open class Account: Service { open func updateMfaChallenge( challengeId: String, otp: String - ) async throws -> Any { + ) async throws -> AppwriteModels.Session { let apiPath: String = "/account/mfa/challenge" let apiParams: [String: Any?] = [ @@ -596,11 +596,17 @@ open class Account: Service { "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 ) + params: apiParams, + converter: converter + ) } /// diff --git a/Sources/Appwrite/Services/Functions.swift b/Sources/Appwrite/Services/Functions.swift index ba39620..28d5963 100644 --- a/Sources/Appwrite/Services/Functions.swift +++ b/Sources/Appwrite/Services/Functions.swift @@ -572,6 +572,12 @@ open class Functions: Service { /// /// Rebuild deployment /// + /// Create a new build for an existing function deployment. This endpoint + /// allows you to rebuild a deployment with the updated function configuration, + /// including its entrypoint and build commands if they have been modified The + /// build process will be queued and executed asynchronously. The original + /// deployment's code will be preserved and used for the new build. + /// /// @param String functionId /// @param String deploymentId /// @param String buildId @@ -605,6 +611,12 @@ open class Functions: Service { /// /// Cancel deployment /// + /// Cancel an ongoing function deployment build. If the build is already in + /// progress, it will be stopped and marked as canceled. If the build hasn't + /// started yet, it will be marked as canceled without executing. You cannot + /// cancel builds that have already completed (status 'ready') or failed. The + /// response includes the final build status and details. + /// /// @param String functionId /// @param String deploymentId /// @throws Exception diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index e785a42..636fbe1 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -418,7 +418,7 @@ open class Messaging: Service { /// /// Update SMS /// - /// Update an email message by its unique ID. + /// Update an SMS message by its unique ID. /// /// /// @param String messageId diff --git a/Sources/Appwrite/Services/Users.swift b/Sources/Appwrite/Services/Users.swift index f9e7361..3b78b8a 100644 --- a/Sources/Appwrite/Services/Users.swift +++ b/Sources/Appwrite/Services/Users.swift @@ -1217,11 +1217,10 @@ open class Users: Service { /// @throws Exception /// @return array /// - open func deleteMfaAuthenticator<T>( + open func deleteMfaAuthenticator( userId: String, - type: AppwriteEnums.AuthenticatorType, - nestedType: T.Type - ) async throws -> AppwriteModels.User<T> { + 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) @@ -1232,38 +1231,11 @@ open class Users: Service { "content-type": "application/json" ] - let converter: (Any) -> AppwriteModels.User<T> = { response in - return AppwriteModels.User.from(map: response as! [String: Any]) - } - return try await client.call( method: "DELETE", path: apiPath, headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Delete authenticator - /// - /// Delete an authenticator app. - /// - /// @param String userId - /// @param AppwriteEnums.AuthenticatorType type - /// @throws Exception - /// @return array - /// - open func deleteMfaAuthenticator( - userId: String, - type: AppwriteEnums.AuthenticatorType - ) async throws -> AppwriteModels.User<[String: AnyCodable]> { - return try await deleteMfaAuthenticator( - userId: userId, - type: type, - nestedType: [String: AnyCodable].self - ) + params: apiParams ) } /// diff --git a/Sources/AppwriteEnums/ImageFormat.swift b/Sources/AppwriteEnums/ImageFormat.swift index 2081ed0..c31fb47 100644 --- a/Sources/AppwriteEnums/ImageFormat.swift +++ b/Sources/AppwriteEnums/ImageFormat.swift @@ -6,6 +6,7 @@ public enum ImageFormat: String, CustomStringConvertible { case gif = "gif" case png = "png" case webp = "webp" + case heic = "heic" case avif = "avif" public var description: String { diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index eed3bfa..fee76bf 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 result = try await account.updateMfaChallenge( +let session = try await account.updateMfaChallenge( challengeId: "<CHALLENGE_ID>", otp: "<OTP>" ) diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md index 902d0c9..5f1d6a0 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 user = try await users.deleteMfaAuthenticator( +let result = try await users.deleteMfaAuthenticator( userId: "<USER_ID>", type: .totp ) From cda8a0ca3421684cf478b6cf68593b7558baa37c Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 29 Jan 2025 08:05:05 +0000 Subject: [PATCH 5/5] chore: bump versions --- README.md | 2 +- Sources/Appwrite/Client.swift | 2 +- Sources/Appwrite/Services/Users.swift | 25 +------------------------ 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e02db02..160afa8 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "6.2.1"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "7.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index c9b3d10..1b39b35 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,7 +21,7 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "6.2.1", + "x-sdk-version": "7.0.0", "x-appwrite-response-format": "1.6.0" ] diff --git a/Sources/Appwrite/Services/Users.swift b/Sources/Appwrite/Services/Users.swift index e7818c0..3b78b8a 100644 --- a/Sources/Appwrite/Services/Users.swift +++ b/Sources/Appwrite/Services/Users.swift @@ -1235,30 +1235,7 @@ open class Users: Service { method: "DELETE", path: apiPath, headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Delete authenticator - /// - /// Delete an authenticator app. - /// - /// @param String userId - /// @param AppwriteEnums.AuthenticatorType type - /// @throws Exception - /// @return array - /// - open func deleteMfaAuthenticator( - userId: String, - type: AppwriteEnums.AuthenticatorType - ) async throws -> AppwriteModels.User<[String: AnyCodable]> { - return try await deleteMfaAuthenticator( - userId: userId, - type: type, - nestedType: [String: AnyCodable].self - ) + params: apiParams ) } ///