diff --git a/README.md b/README.md index 402cade..a6c1d21 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "8.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "9.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 87f1d3c..1255ec9 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -23,7 +23,7 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "8.0.0", + "x-sdk-version": "9.0.0", "x-appwrite-response-format": "1.6.0" ] @@ -345,7 +345,6 @@ open class Client { case 0..<400: if response.headers["Set-Cookie"].count > 0 { let domain = URL(string: request.url)!.host! - let existing = UserDefaults.standard.stringArray(forKey: domain) let new = response.headers["Set-Cookie"] UserDefaults.standard.set(new, forKey: domain) @@ -368,20 +367,24 @@ open class Client { default: var message = "" var type = "" + var responseString = "" do { let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] message = dict?["message"] as? String ?? response.status.reasonPhrase type = dict?["type"] as? String ?? "" + responseString = String(decoding: data.readableBytesView, as: UTF8.self) } catch { message = data.readString(length: data.readableBytes)! + responseString = message } throw AppwriteError( message: message, code: Int(response.status.code), - type: type + type: type, + response: responseString ) } } diff --git a/Sources/Appwrite/Models/AppwriteError.swift b/Sources/Appwrite/Models/AppwriteError.swift index a0e0963..4c79512 100644 --- a/Sources/Appwrite/Models/AppwriteError.swift +++ b/Sources/Appwrite/Models/AppwriteError.swift @@ -5,11 +5,13 @@ open class AppwriteError : Swift.Error, Decodable { public let message: String public let code: Int? public let type: String? + public let response: String - init(message: String, code: Int? = nil, type: String? = nil) { + init(message: String, code: Int? = nil, type: String? = nil, response: String = "") { self.message = message self.code = code self.type = type + self.response = response } } diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 6155931..817e9f4 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Account service allows you to authenticate and manage a user account. open class Account: Service { - /// - /// Get account /// /// Get the currently logged in user. /// @@ -40,8 +38,6 @@ open class Account: Service { ) } - /// - /// Get account /// /// Get the currently logged in user. /// @@ -55,8 +51,6 @@ open class Account: Service { ) } - /// - /// Create account /// /// Use this endpoint to allow a new user to register a new account in your /// project. After the user registration completes successfully, you can use @@ -106,8 +100,6 @@ open class Account: Service { ) } - /// - /// Create account /// /// Use this endpoint to allow a new user to register a new account in your /// project. After the user registration completes successfully, you can use @@ -139,8 +131,6 @@ open class Account: Service { ) } - /// - /// Update email /// /// Update currently logged in user account email address. After changing user /// address, the user confirmation status will get reset. A new confirmation @@ -185,8 +175,6 @@ open class Account: Service { ) } - /// - /// Update email /// /// Update currently logged in user account email address. After changing user /// address, the user confirmation status will get reset. A new confirmation @@ -213,8 +201,6 @@ open class Account: Service { ) } - /// - /// List identities /// /// Get the list of identities for the currently logged in user. /// @@ -248,8 +234,6 @@ open class Account: Service { ) } - /// - /// Delete identity /// /// Delete an identity by its unique ID. /// @@ -276,8 +260,6 @@ open class Account: Service { params: apiParams ) } - /// - /// Create JWT /// /// Use this endpoint to create a JSON Web Token. You can use the resulting JWT /// to authenticate on behalf of the current user when working with the @@ -311,8 +293,6 @@ open class Account: Service { ) } - /// - /// List logs /// /// Get the list of latest security activity logs for the currently logged in /// user. Each log returns user IP address, location and date and time of log. @@ -347,8 +327,6 @@ open class Account: Service { ) } - /// - /// Update MFA /// /// Enable or disable MFA on an account. /// @@ -383,8 +361,6 @@ open class Account: Service { ) } - /// - /// Update MFA /// /// Enable or disable MFA on an account. /// @@ -401,8 +377,6 @@ open class Account: Service { ) } - /// - /// Create authenticator /// /// Add an authenticator app to be used as an MFA factor. Verify the /// authenticator using the [verify @@ -438,8 +412,6 @@ open class Account: Service { ) } - /// - /// Verify authenticator /// /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) @@ -479,8 +451,6 @@ open class Account: Service { ) } - /// - /// Verify authenticator /// /// Verify an authenticator app after adding it using the [add /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) @@ -502,8 +472,6 @@ open class Account: Service { ) } - /// - /// Delete authenticator /// /// Delete an authenticator for a user by ID. /// @@ -530,8 +498,6 @@ open class Account: Service { params: apiParams ) } - /// - /// Create MFA challenge /// /// Begin the process of MFA verification after sign-in. Finish the flow with /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) @@ -567,8 +533,6 @@ open class Account: Service { ) } - /// - /// 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 @@ -609,8 +573,6 @@ open class Account: Service { ) } - /// - /// List factors /// /// List the factors available on the account to be used as a MFA challange. /// @@ -640,8 +602,6 @@ open class Account: Service { ) } - /// - /// Get MFA recovery codes /// /// Get recovery codes that can be used as backup for MFA flow. Before getting /// codes, they must be generated using @@ -674,8 +634,6 @@ open class Account: Service { ) } - /// - /// 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 @@ -709,8 +667,6 @@ open class Account: Service { ) } - /// - /// 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 @@ -743,8 +699,6 @@ open class Account: Service { ) } - /// - /// Update name /// /// Update currently logged in user account name. /// @@ -779,8 +733,6 @@ open class Account: Service { ) } - /// - /// Update name /// /// Update currently logged in user account name. /// @@ -797,8 +749,6 @@ open class Account: Service { ) } - /// - /// Update password /// /// Update currently logged in user password. For validation, user is required /// to pass in the new password, and the old password. For users created with @@ -838,8 +788,6 @@ open class Account: Service { ) } - /// - /// Update password /// /// Update currently logged in user password. For validation, user is required /// to pass in the new password, and the old password. For users created with @@ -861,8 +809,6 @@ open class Account: Service { ) } - /// - /// Update phone /// /// Update the currently logged in user's phone number. After updating the /// phone number, the phone verification status will be reset. A confirmation @@ -904,8 +850,6 @@ open class Account: Service { ) } - /// - /// Update phone /// /// Update the currently logged in user's phone number. After updating the /// phone number, the phone verification status will be reset. A confirmation @@ -929,8 +873,6 @@ open class Account: Service { ) } - /// - /// Get account preferences /// /// Get the preferences as a key-value object for the currently logged in user. /// @@ -961,8 +903,6 @@ open class Account: Service { ) } - /// - /// Get account preferences /// /// Get the preferences as a key-value object for the currently logged in user. /// @@ -976,8 +916,6 @@ open class Account: Service { ) } - /// - /// Update preferences /// /// Update currently logged in user account preferences. The object you pass is /// stored as is, and replaces any previous value. The maximum allowed prefs @@ -1014,8 +952,6 @@ open class Account: Service { ) } - /// - /// Update preferences /// /// Update currently logged in user account preferences. The object you pass is /// stored as is, and replaces any previous value. The maximum allowed prefs @@ -1034,8 +970,6 @@ open class Account: Service { ) } - /// - /// Create password recovery /// /// Sends the user an email with a temporary secret key for password reset. /// When the user clicks the confirmation link he is redirected back to your @@ -1079,8 +1013,6 @@ open class Account: Service { ) } - /// - /// Create password recovery (confirmation) /// /// Use this endpoint to complete the user account password reset. Both the /// **userId** and **secret** arguments will be passed as query parameters to @@ -1129,8 +1061,6 @@ open class Account: Service { ) } - /// - /// List sessions /// /// Get the list of active sessions across different devices for the currently /// logged in user. @@ -1161,8 +1091,6 @@ open class Account: Service { ) } - /// - /// Delete sessions /// /// Delete all sessions from the user account and remove any sessions cookies /// from the end client. @@ -1187,8 +1115,6 @@ open class Account: Service { params: apiParams ) } - /// - /// Create anonymous session /// /// Use this endpoint to allow a new user to register an anonymous account in /// your project. This route will also create a new session for the user. To @@ -1224,8 +1150,6 @@ open class Account: Service { ) } - /// - /// Create email password session /// /// Allow the user to login into their account by providing a valid email and /// password combination. This route will create a new session for the user. @@ -1267,8 +1191,6 @@ open class Account: Service { ) } - /// - /// Update magic URL session /// /// Use this endpoint to create a session from token. Provide the **userId** /// and **secret** parameters from the successful response of authentication @@ -1307,8 +1229,6 @@ open class Account: Service { ) } - /// - /// Create OAuth2 session /// /// Allow the user to login to their account using the OAuth2 provider of their /// choice. Each OAuth2 provider should be enabled from the Appwrite console @@ -1368,8 +1288,6 @@ open class Account: Service { } - /// - /// Update phone session /// /// Use this endpoint to create a session from token. Provide the **userId** /// and **secret** parameters from the successful response of authentication @@ -1408,8 +1326,6 @@ open class Account: Service { ) } - /// - /// Create session /// /// Use this endpoint to create a session from token. Provide the **userId** /// and **secret** parameters from the successful response of authentication @@ -1448,8 +1364,6 @@ open class Account: Service { ) } - /// - /// Get session /// /// Use this endpoint to get a logged in user's session using a Session ID. /// Inputting 'current' will return the current session being used. @@ -1483,8 +1397,6 @@ open class Account: Service { ) } - /// - /// Update session /// /// Use this endpoint to extend a session's length. Extending a session is /// useful when session expiry is short. If the session was created using an @@ -1519,8 +1431,6 @@ open class Account: Service { ) } - /// - /// Delete session /// /// Logout the user. Use 'current' as the session ID to logout on this device, /// use a session ID to logout on another device. If you're looking to logout @@ -1551,8 +1461,6 @@ open class Account: Service { params: apiParams ) } - /// - /// Update status /// /// Block the currently logged in user account. Behind the scene, the user /// record is not deleted but permanently blocked from any access. To @@ -1585,8 +1493,6 @@ open class Account: Service { ) } - /// - /// Update status /// /// Block the currently logged in user account. Behind the scene, the user /// record is not deleted but permanently blocked from any access. To @@ -1602,8 +1508,6 @@ open class Account: Service { ) } - /// - /// Create push target /// /// Use this endpoint to register a device for push notifications. Provide a /// target ID (custom or generated using ID.unique()), a device identifier @@ -1647,8 +1551,6 @@ open class Account: Service { ) } - /// - /// Update push target /// /// Update the currently logged in user's push notification target. You can /// modify the target's identifier (device token) and provider ID (token, @@ -1689,8 +1591,6 @@ open class Account: Service { ) } - /// - /// Delete push target /// /// Delete a push notification target for the currently logged in user. After /// deletion, the device will no longer receive push notifications. The target @@ -1719,8 +1619,6 @@ open class Account: Service { params: apiParams ) } - /// - /// Create email token (OTP) /// /// 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 @@ -1769,8 +1667,6 @@ open class Account: Service { ) } - /// - /// Create magic URL token /// /// Sends the user an email with a secret key for creating a session. If the /// provided user ID has not been registered, a new user will be created. When @@ -1826,8 +1722,6 @@ open class Account: Service { ) } - /// - /// Create OAuth2 token /// /// Allow the user to login to their account using the OAuth2 provider of their /// choice. Each OAuth2 provider should be enabled from the Appwrite console @@ -1885,8 +1779,6 @@ open class Account: Service { } - /// - /// Create phone token /// /// Sends the user an SMS 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 @@ -1932,8 +1824,6 @@ open class Account: Service { ) } - /// - /// Create email verification /// /// Use this endpoint to send a verification message to your user email address /// to confirm they are the valid owners of that address. Both the **userId** @@ -1981,8 +1871,6 @@ open class Account: Service { ) } - /// - /// Create email verification (confirmation) /// /// Use this endpoint to complete the user email verification process. Use both /// the **userId** and **secret** parameters that were attached to your app URL @@ -2022,8 +1910,6 @@ open class Account: Service { ) } - /// - /// Create phone verification /// /// Use this endpoint to send a verification SMS to the currently logged in /// user. This endpoint is meant for use after updating a user's phone number @@ -2060,8 +1946,6 @@ open class Account: Service { ) } - /// - /// Update phone verification (confirmation) /// /// Use this endpoint to complete the user phone verification process. Use the /// **userId** and **secret** that were sent to your user's phone number to diff --git a/Sources/Appwrite/Services/Avatars.swift b/Sources/Appwrite/Services/Avatars.swift index 2a1d2fa..ca9c52f 100644 --- a/Sources/Appwrite/Services/Avatars.swift +++ b/Sources/Appwrite/Services/Avatars.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Avatars service aims to help you complete everyday tasks related to your app image, icons, and avatars. open class Avatars: Service { - /// - /// Get browser icon /// /// You can use this endpoint to show different browser icons to your users. /// The code argument receives the browser code as it appears in your user [GET @@ -52,8 +50,6 @@ open class Avatars: Service { ) } - /// - /// Get credit card icon /// /// The credit card endpoint will return you the icon of the credit card /// provider you need. Use width, height and quality arguments to change the @@ -95,8 +91,6 @@ open class Avatars: Service { ) } - /// - /// Get favicon /// /// Use this endpoint to fetch the favorite icon (AKA favicon) of any remote /// website URL. @@ -124,8 +118,6 @@ open class Avatars: Service { ) } - /// - /// Get country flag /// /// You can use this endpoint to show different country flags icons to your /// users. The code argument receives the 2 letter country code. Use width, @@ -168,8 +160,6 @@ open class Avatars: Service { ) } - /// - /// Get image from URL /// /// Use this endpoint to fetch a remote image URL and crop it to any image size /// you want. This endpoint is very useful if you need to crop and display @@ -210,8 +200,6 @@ open class Avatars: Service { ) } - /// - /// Get user initials /// /// Use this endpoint to show your user initials avatar icon on your website or /// app. By default, this route will try to print your logged-in user name or @@ -260,8 +248,6 @@ open class Avatars: Service { ) } - /// - /// Get QR code /// /// Converts a given plain text to a QR code image. You can use the query /// parameters to change the size and style of the resulting image. diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 225028c..d7946b5 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Databases service allows you to create structured collections of documents, query and filter lists of documents open class Databases: Service { - /// - /// List documents /// /// Get a list of all the user's documents in a given collection. You can use /// the query params to filter your results. @@ -51,8 +49,6 @@ open class Databases: Service { ) } - /// - /// List documents /// /// Get a list of all the user's documents in a given collection. You can use /// the query params to filter your results. @@ -76,8 +72,6 @@ open class Databases: Service { ) } - /// - /// Create document /// /// Create a new Document. Before using this route, you should create a new /// collection resource using either a [server @@ -127,8 +121,6 @@ open class Databases: Service { ) } - /// - /// Create document /// /// Create a new Document. Before using this route, you should create a new /// collection resource using either a [server @@ -160,8 +152,6 @@ open class Databases: Service { ) } - /// - /// Get document /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. @@ -206,8 +196,6 @@ open class Databases: Service { ) } - /// - /// Get document /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. @@ -234,8 +222,6 @@ open class Databases: Service { ) } - /// - /// Update document /// /// Update a document by its unique ID. Using the patch method you can pass /// only specific fields that will get updated. @@ -283,8 +269,6 @@ open class Databases: Service { ) } - /// - /// Update document /// /// Update a document by its unique ID. Using the patch method you can pass /// only specific fields that will get updated. @@ -314,8 +298,6 @@ open class Databases: Service { ) } - /// - /// Delete document /// /// Delete a document by its unique ID. /// diff --git a/Sources/Appwrite/Services/Functions.swift b/Sources/Appwrite/Services/Functions.swift index ea1b37d..185f887 100644 --- a/Sources/Appwrite/Services/Functions.swift +++ b/Sources/Appwrite/Services/Functions.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Functions Service allows you view, create and manage your Cloud Functions. open class Functions: Service { - /// - /// List executions /// /// Get a list of all the current user function execution logs. You can use the /// query params to filter your results. @@ -50,8 +48,6 @@ open class Functions: Service { ) } - /// - /// Create execution /// /// Trigger a function execution. The returned object will return you the /// current execution status. You can ping the `Get Execution` endpoint to get @@ -106,8 +102,6 @@ open class Functions: Service { ) } - /// - /// Get execution /// /// Get a function execution log by its unique ID. /// diff --git a/Sources/Appwrite/Services/Graphql.swift b/Sources/Appwrite/Services/Graphql.swift index cc019c9..68c326f 100644 --- a/Sources/Appwrite/Services/Graphql.swift +++ b/Sources/Appwrite/Services/Graphql.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The GraphQL API allows you to query and mutate your Appwrite server using GraphQL. open class Graphql: Service { - /// - /// GraphQL endpoint /// /// Execute a GraphQL mutation. /// @@ -44,8 +42,6 @@ open class Graphql: Service { ) } - /// - /// GraphQL endpoint /// /// Execute a GraphQL mutation. /// diff --git a/Sources/Appwrite/Services/Locale.swift b/Sources/Appwrite/Services/Locale.swift index 170e11a..a15f09a 100644 --- a/Sources/Appwrite/Services/Locale.swift +++ b/Sources/Appwrite/Services/Locale.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Locale service allows you to customize your app based on your users' location. open class Locale: Service { - /// - /// Get user locale /// /// Get the current user location based on IP. Returns an object with user /// country code, country name, continent name, continent code, ip address and @@ -44,8 +42,6 @@ open class Locale: Service { ) } - /// - /// List locale codes /// /// List of all locale codes in [ISO /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). @@ -76,8 +72,6 @@ open class Locale: Service { ) } - /// - /// List continents /// /// List of all continents. You can use the locale header to get the data in a /// supported language. @@ -108,8 +102,6 @@ open class Locale: Service { ) } - /// - /// List countries /// /// List of all countries. You can use the locale header to get the data in a /// supported language. @@ -140,8 +132,6 @@ open class Locale: Service { ) } - /// - /// List EU countries /// /// List of all countries that are currently members of the EU. You can use the /// locale header to get the data in a supported language. @@ -172,8 +162,6 @@ open class Locale: Service { ) } - /// - /// List countries phone codes /// /// List of all countries phone codes. You can use the locale header to get the /// data in a supported language. @@ -204,8 +192,6 @@ open class Locale: Service { ) } - /// - /// List currencies /// /// List of all currencies, including currency symbol, name, plural, and /// decimal digits for all major and minor currencies. You can use the locale @@ -237,8 +223,6 @@ open class Locale: Service { ) } - /// - /// List languages /// /// List of all languages classified by ISO 639-1 including 2-letter code, name /// in English, and name in the respective language. diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index d329642..d5df05f 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Messaging service allows you to send messages to any provider type (SMTP, push notification, SMS, etc.). open class Messaging: Service { - /// - /// Create subscriber /// /// Create a new subscriber. /// @@ -49,8 +47,6 @@ open class Messaging: Service { ) } - /// - /// Delete subscriber /// /// Delete a subscriber by its unique ID. /// diff --git a/Sources/Appwrite/Services/Storage.swift b/Sources/Appwrite/Services/Storage.swift index 382ab83..3ad9e7e 100644 --- a/Sources/Appwrite/Services/Storage.swift +++ b/Sources/Appwrite/Services/Storage.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Storage service allows you to manage your project files. open class Storage: Service { - /// - /// List files /// /// Get a list of all the user files. You can use the query params to filter /// your results. @@ -50,8 +48,6 @@ open class Storage: Service { ) } - /// - /// Create file /// /// Create a new file. Before using this route, you should create a new bucket /// resource using either a [server @@ -116,8 +112,6 @@ open class Storage: Service { ) } - /// - /// Get file /// /// Get a file by its unique ID. This endpoint response returns a JSON object /// with the file metadata. @@ -154,8 +148,6 @@ open class Storage: Service { ) } - /// - /// Update file /// /// Update a file by its unique ID. Only users with write permissions have /// access to update this resource. @@ -199,8 +191,6 @@ open class Storage: Service { ) } - /// - /// Delete file /// /// Delete a file by its unique ID. Only users with write permissions have /// access to delete this resource. @@ -231,8 +221,6 @@ open class Storage: Service { params: apiParams ) } - /// - /// Get file for download /// /// Get a file content by its unique ID. The endpoint response return with a /// 'Content-Disposition: attachment' header that tells the browser to start @@ -260,8 +248,6 @@ open class Storage: Service { ) } - /// - /// Get file preview /// /// Get a file preview image. Currently, this method supports preview for image /// files (jpg, png, and gif), other supported formats, like pdf, docs, slides, @@ -326,8 +312,6 @@ open class Storage: Service { ) } - /// - /// Get file for view /// /// Get a file content by its unique ID. This endpoint is similar to the /// download method but returns with no 'Content-Disposition: attachment' diff --git a/Sources/Appwrite/Services/Teams.swift b/Sources/Appwrite/Services/Teams.swift index a4d3123..b20c3bd 100644 --- a/Sources/Appwrite/Services/Teams.swift +++ b/Sources/Appwrite/Services/Teams.swift @@ -8,8 +8,6 @@ import AppwriteModels /// The Teams service allows you to group users of your project and to enable them to share read and write access to your project resources open class Teams: Service { - /// - /// List teams /// /// Get a list of all the teams in which the current user is a member. You can /// use the parameters to filter your results. @@ -48,8 +46,6 @@ open class Teams: Service { ) } - /// - /// List teams /// /// Get a list of all the teams in which the current user is a member. You can /// use the parameters to filter your results. @@ -70,8 +66,6 @@ open class Teams: Service { ) } - /// - /// Create team /// /// Create a new team. The user who creates the team will automatically be /// assigned as the owner of the team. Only the users with the owner role can @@ -114,8 +108,6 @@ open class Teams: Service { ) } - /// - /// Create team /// /// Create a new team. The user who creates the team will automatically be /// assigned as the owner of the team. Only the users with the owner role can @@ -140,8 +132,6 @@ open class Teams: Service { ) } - /// - /// Get team /// /// Get a team by its ID. All team members have read access for this resource. /// @@ -175,8 +165,6 @@ open class Teams: Service { ) } - /// - /// Get team /// /// Get a team by its ID. All team members have read access for this resource. /// @@ -193,8 +181,6 @@ open class Teams: Service { ) } - /// - /// Update name /// /// Update the team's name by its unique ID. /// @@ -232,8 +218,6 @@ open class Teams: Service { ) } - /// - /// Update name /// /// Update the team's name by its unique ID. /// @@ -253,8 +237,6 @@ open class Teams: Service { ) } - /// - /// Delete team /// /// Delete a team using its ID. Only team members with the owner role can /// delete the team. @@ -282,8 +264,6 @@ open class Teams: Service { params: apiParams ) } - /// - /// 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. Hide sensitive attributes from @@ -325,8 +305,6 @@ open class Teams: Service { ) } - /// - /// Create team membership /// /// Invite a new member to join your team. Provide an ID for existing users, or /// invite unregistered users using an email or phone number. If initiated from @@ -398,8 +376,6 @@ 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. Hide sensitive attributes from the response by @@ -437,8 +413,6 @@ open class Teams: Service { ) } - /// - /// Update membership /// /// Modify the roles of a team member. Only team members with the owner role /// have access to this endpoint. Learn more about [roles and @@ -481,8 +455,6 @@ open class Teams: Service { ) } - /// - /// Delete team membership /// /// This endpoint allows a user to leave a team or for a team owner to delete /// the membership of any other team member. You can also use this endpoint to @@ -514,8 +486,6 @@ open class Teams: Service { params: apiParams ) } - /// - /// Update team membership status /// /// Use this endpoint to allow a user to accept an invitation to join a team /// after being redirected back to your app from the invitation email received @@ -564,8 +534,6 @@ open class Teams: Service { ) } - /// - /// Get team preferences /// /// Get the team's shared preferences by its unique ID. If a preference doesn't /// need to be shared by all team members, prefer storing them in [user @@ -601,8 +569,6 @@ open class Teams: Service { ) } - /// - /// Get team preferences /// /// Get the team's shared preferences by its unique ID. If a preference doesn't /// need to be shared by all team members, prefer storing them in [user @@ -621,8 +587,6 @@ open class Teams: Service { ) } - /// - /// Update preferences /// /// Update the team's preferences by its unique ID. The object you pass is /// stored as is and replaces any previous value. The maximum allowed prefs @@ -662,8 +626,6 @@ open class Teams: Service { ) } - /// - /// Update preferences /// /// Update the team's preferences by its unique ID. The object you pass is /// stored as is and replaces any previous value. The maximum allowed prefs diff --git a/Sources/AppwriteModels/AlgoArgon2.swift b/Sources/AppwriteModels/AlgoArgon2.swift index c93c034..fd88955 100644 --- a/Sources/AppwriteModels/AlgoArgon2.swift +++ b/Sources/AppwriteModels/AlgoArgon2.swift @@ -2,7 +2,14 @@ import Foundation import JSONCodable /// AlgoArgon2 -public class AlgoArgon2 { +open class AlgoArgon2: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + case memoryCost = "memoryCost" + case timeCost = "timeCost" + case threads = "threads" + } /// Algo type. public let type: String @@ -29,6 +36,24 @@ public class AlgoArgon2 { self.threads = threads } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + self.memoryCost = try container.decode(Int.self, forKey: .memoryCost) + self.timeCost = try container.decode(Int.self, forKey: .timeCost) + self.threads = try container.decode(Int.self, forKey: .threads) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + try container.encode(memoryCost, forKey: .memoryCost) + try container.encode(timeCost, forKey: .timeCost) + try container.encode(threads, forKey: .threads) + } + public func toMap() -> [String: Any] { return [ "type": type as Any, diff --git a/Sources/AppwriteModels/AlgoBcrypt.swift b/Sources/AppwriteModels/AlgoBcrypt.swift index 8d59f2d..b34095d 100644 --- a/Sources/AppwriteModels/AlgoBcrypt.swift +++ b/Sources/AppwriteModels/AlgoBcrypt.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// AlgoBcrypt -public class AlgoBcrypt { +open class AlgoBcrypt: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + } /// Algo type. public let type: String @@ -14,6 +18,18 @@ public class AlgoBcrypt { self.type = type } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + } + public func toMap() -> [String: Any] { return [ "type": type as Any diff --git a/Sources/AppwriteModels/AlgoMd5.swift b/Sources/AppwriteModels/AlgoMd5.swift index 050fe5c..72fbb8d 100644 --- a/Sources/AppwriteModels/AlgoMd5.swift +++ b/Sources/AppwriteModels/AlgoMd5.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// AlgoMD5 -public class AlgoMd5 { +open class AlgoMd5: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + } /// Algo type. public let type: String @@ -14,6 +18,18 @@ public class AlgoMd5 { self.type = type } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + } + public func toMap() -> [String: Any] { return [ "type": type as Any diff --git a/Sources/AppwriteModels/AlgoPhpass.swift b/Sources/AppwriteModels/AlgoPhpass.swift index 493463d..7bd0c99 100644 --- a/Sources/AppwriteModels/AlgoPhpass.swift +++ b/Sources/AppwriteModels/AlgoPhpass.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// AlgoPHPass -public class AlgoPhpass { +open class AlgoPhpass: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + } /// Algo type. public let type: String @@ -14,6 +18,18 @@ public class AlgoPhpass { self.type = type } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + } + public func toMap() -> [String: Any] { return [ "type": type as Any diff --git a/Sources/AppwriteModels/AlgoScrypt.swift b/Sources/AppwriteModels/AlgoScrypt.swift index 73254f2..03ce541 100644 --- a/Sources/AppwriteModels/AlgoScrypt.swift +++ b/Sources/AppwriteModels/AlgoScrypt.swift @@ -2,7 +2,15 @@ import Foundation import JSONCodable /// AlgoScrypt -public class AlgoScrypt { +open class AlgoScrypt: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + case costCpu = "costCpu" + case costMemory = "costMemory" + case costParallel = "costParallel" + case length = "length" + } /// Algo type. public let type: String @@ -34,6 +42,26 @@ public class AlgoScrypt { self.length = length } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + self.costCpu = try container.decode(Int.self, forKey: .costCpu) + self.costMemory = try container.decode(Int.self, forKey: .costMemory) + self.costParallel = try container.decode(Int.self, forKey: .costParallel) + self.length = try container.decode(Int.self, forKey: .length) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + try container.encode(costCpu, forKey: .costCpu) + try container.encode(costMemory, forKey: .costMemory) + try container.encode(costParallel, forKey: .costParallel) + try container.encode(length, forKey: .length) + } + public func toMap() -> [String: Any] { return [ "type": type as Any, diff --git a/Sources/AppwriteModels/AlgoScryptModified.swift b/Sources/AppwriteModels/AlgoScryptModified.swift index bc1fde5..0b2fa4e 100644 --- a/Sources/AppwriteModels/AlgoScryptModified.swift +++ b/Sources/AppwriteModels/AlgoScryptModified.swift @@ -2,7 +2,14 @@ import Foundation import JSONCodable /// AlgoScryptModified -public class AlgoScryptModified { +open class AlgoScryptModified: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + case salt = "salt" + case saltSeparator = "saltSeparator" + case signerKey = "signerKey" + } /// Algo type. public let type: String @@ -29,6 +36,24 @@ public class AlgoScryptModified { self.signerKey = signerKey } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + self.salt = try container.decode(String.self, forKey: .salt) + self.saltSeparator = try container.decode(String.self, forKey: .saltSeparator) + self.signerKey = try container.decode(String.self, forKey: .signerKey) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + try container.encode(salt, forKey: .salt) + try container.encode(saltSeparator, forKey: .saltSeparator) + try container.encode(signerKey, forKey: .signerKey) + } + public func toMap() -> [String: Any] { return [ "type": type as Any, diff --git a/Sources/AppwriteModels/AlgoSha.swift b/Sources/AppwriteModels/AlgoSha.swift index c0a0532..ffc0e05 100644 --- a/Sources/AppwriteModels/AlgoSha.swift +++ b/Sources/AppwriteModels/AlgoSha.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// AlgoSHA -public class AlgoSha { +open class AlgoSha: Codable { + + enum CodingKeys: String, CodingKey { + case type = "type" + } /// Algo type. public let type: String @@ -14,6 +18,18 @@ public class AlgoSha { self.type = type } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.type = try container.decode(String.self, forKey: .type) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(type, forKey: .type) + } + public func toMap() -> [String: Any] { return [ "type": type as Any diff --git a/Sources/AppwriteModels/Continent.swift b/Sources/AppwriteModels/Continent.swift index f181353..b8994d9 100644 --- a/Sources/AppwriteModels/Continent.swift +++ b/Sources/AppwriteModels/Continent.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Continent -public class Continent { +open class Continent: Codable { + + enum CodingKeys: String, CodingKey { + case name = "name" + case code = "code" + } /// Continent name. public let name: String @@ -19,6 +24,20 @@ public class Continent { self.code = code } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.name = try container.decode(String.self, forKey: .name) + self.code = try container.decode(String.self, forKey: .code) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(name, forKey: .name) + try container.encode(code, forKey: .code) + } + public func toMap() -> [String: Any] { return [ "name": name as Any, diff --git a/Sources/AppwriteModels/ContinentList.swift b/Sources/AppwriteModels/ContinentList.swift index 3cd7620..fa9a90f 100644 --- a/Sources/AppwriteModels/ContinentList.swift +++ b/Sources/AppwriteModels/ContinentList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Continents List -public class ContinentList { +open class ContinentList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case continents = "continents" + } /// Total number of continents documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class ContinentList { self.continents = continents } + 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.continents = try container.decode([Continent].self, forKey: .continents) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(continents, forKey: .continents) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Country.swift b/Sources/AppwriteModels/Country.swift index 3ce533b..c24f7e9 100644 --- a/Sources/AppwriteModels/Country.swift +++ b/Sources/AppwriteModels/Country.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Country -public class Country { +open class Country: Codable { + + enum CodingKeys: String, CodingKey { + case name = "name" + case code = "code" + } /// Country name. public let name: String @@ -19,6 +24,20 @@ public class Country { self.code = code } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.name = try container.decode(String.self, forKey: .name) + self.code = try container.decode(String.self, forKey: .code) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(name, forKey: .name) + try container.encode(code, forKey: .code) + } + public func toMap() -> [String: Any] { return [ "name": name as Any, diff --git a/Sources/AppwriteModels/CountryList.swift b/Sources/AppwriteModels/CountryList.swift index 8d120bd..865cc19 100644 --- a/Sources/AppwriteModels/CountryList.swift +++ b/Sources/AppwriteModels/CountryList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Countries List -public class CountryList { +open class CountryList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case countries = "countries" + } /// Total number of countries documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class CountryList { self.countries = countries } + 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.countries = try container.decode([Country].self, forKey: .countries) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(countries, forKey: .countries) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Currency.swift b/Sources/AppwriteModels/Currency.swift index d93ce0c..320337b 100644 --- a/Sources/AppwriteModels/Currency.swift +++ b/Sources/AppwriteModels/Currency.swift @@ -2,7 +2,17 @@ import Foundation import JSONCodable /// Currency -public class Currency { +open class Currency: Codable { + + enum CodingKeys: String, CodingKey { + case symbol = "symbol" + case name = "name" + case symbolNative = "symbolNative" + case decimalDigits = "decimalDigits" + case rounding = "rounding" + case code = "code" + case namePlural = "namePlural" + } /// Currency symbol. public let symbol: String @@ -44,6 +54,30 @@ public class Currency { self.namePlural = namePlural } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.symbol = try container.decode(String.self, forKey: .symbol) + self.name = try container.decode(String.self, forKey: .name) + self.symbolNative = try container.decode(String.self, forKey: .symbolNative) + self.decimalDigits = try container.decode(Int.self, forKey: .decimalDigits) + self.rounding = try container.decode(Double.self, forKey: .rounding) + self.code = try container.decode(String.self, forKey: .code) + self.namePlural = try container.decode(String.self, forKey: .namePlural) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(symbol, forKey: .symbol) + try container.encode(name, forKey: .name) + try container.encode(symbolNative, forKey: .symbolNative) + try container.encode(decimalDigits, forKey: .decimalDigits) + try container.encode(rounding, forKey: .rounding) + try container.encode(code, forKey: .code) + try container.encode(namePlural, forKey: .namePlural) + } + public func toMap() -> [String: Any] { return [ "symbol": symbol as Any, diff --git a/Sources/AppwriteModels/CurrencyList.swift b/Sources/AppwriteModels/CurrencyList.swift index a2e9f00..1e0dff9 100644 --- a/Sources/AppwriteModels/CurrencyList.swift +++ b/Sources/AppwriteModels/CurrencyList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Currencies List -public class CurrencyList { +open class CurrencyList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case currencies = "currencies" + } /// Total number of currencies documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class CurrencyList { self.currencies = currencies } + 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.currencies = try container.decode([Currency].self, forKey: .currencies) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(currencies, forKey: .currencies) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Document.swift b/Sources/AppwriteModels/Document.swift index c0c49c6..a1c0326 100644 --- a/Sources/AppwriteModels/Document.swift +++ b/Sources/AppwriteModels/Document.swift @@ -2,7 +2,17 @@ import Foundation import JSONCodable /// Document -public class Document { +open class Document: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case collectionId = "$collectionId" + case databaseId = "$databaseId" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case permissions = "$permissions" + case data + } /// Document ID. public let id: String @@ -43,6 +53,30 @@ public class Document { 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.collectionId = try container.decode(String.self, forKey: .collectionId) + 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(collectionId, forKey: .collectionId) + 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, diff --git a/Sources/AppwriteModels/DocumentList.swift b/Sources/AppwriteModels/DocumentList.swift index 4a573fe..a129182 100644 --- a/Sources/AppwriteModels/DocumentList.swift +++ b/Sources/AppwriteModels/DocumentList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Documents List -public class DocumentList { +open class DocumentList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case documents = "documents" + } /// Total number of documents documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class DocumentList { self.documents = documents } + 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.documents = try container.decode([Document].self, forKey: .documents) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(documents, forKey: .documents) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index d589342..f9a86e7 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -2,7 +2,27 @@ import Foundation import JSONCodable /// Execution -public class Execution { +open class Execution: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case permissions = "$permissions" + case functionId = "functionId" + case trigger = "trigger" + case status = "status" + case requestMethod = "requestMethod" + case requestPath = "requestPath" + case requestHeaders = "requestHeaders" + case responseStatusCode = "responseStatusCode" + case responseBody = "responseBody" + case responseHeaders = "responseHeaders" + case logs = "logs" + case errors = "errors" + case duration = "duration" + case scheduledAt = "scheduledAt" + } /// Execution ID. public let id: String @@ -94,6 +114,50 @@ public class Execution { self.scheduledAt = scheduledAt } + 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.functionId = try container.decode(String.self, forKey: .functionId) + 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) + self.requestPath = try container.decode(String.self, forKey: .requestPath) + self.requestHeaders = try container.decode([Headers].self, forKey: .requestHeaders) + self.responseStatusCode = try container.decode(Int.self, forKey: .responseStatusCode) + self.responseBody = try container.decode(String.self, forKey: .responseBody) + self.responseHeaders = try container.decode([Headers].self, forKey: .responseHeaders) + self.logs = try container.decode(String.self, forKey: .logs) + self.errors = try container.decode(String.self, forKey: .errors) + self.duration = try container.decode(Double.self, forKey: .duration) + self.scheduledAt = try container.decodeIfPresent(String.self, forKey: .scheduledAt) + } + + 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(functionId, forKey: .functionId) + try container.encode(trigger, forKey: .trigger) + try container.encode(status, forKey: .status) + try container.encode(requestMethod, forKey: .requestMethod) + try container.encode(requestPath, forKey: .requestPath) + try container.encode(requestHeaders, forKey: .requestHeaders) + try container.encode(responseStatusCode, forKey: .responseStatusCode) + try container.encode(responseBody, forKey: .responseBody) + try container.encode(responseHeaders, forKey: .responseHeaders) + try container.encode(logs, forKey: .logs) + try container.encode(errors, forKey: .errors) + try container.encode(duration, forKey: .duration) + try container.encodeIfPresent(scheduledAt, forKey: .scheduledAt) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/ExecutionList.swift b/Sources/AppwriteModels/ExecutionList.swift index 8a502d9..72d43a6 100644 --- a/Sources/AppwriteModels/ExecutionList.swift +++ b/Sources/AppwriteModels/ExecutionList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Executions List -public class ExecutionList { +open class ExecutionList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case executions = "executions" + } /// Total number of executions documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class ExecutionList { self.executions = executions } + 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.executions = try container.decode([Execution].self, forKey: .executions) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(executions, forKey: .executions) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/File.swift b/Sources/AppwriteModels/File.swift index db896ab..713c7ca 100644 --- a/Sources/AppwriteModels/File.swift +++ b/Sources/AppwriteModels/File.swift @@ -2,7 +2,21 @@ import Foundation import JSONCodable /// File -public class File { +open class File: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case bucketId = "bucketId" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case permissions = "$permissions" + case name = "name" + case signature = "signature" + case mimeType = "mimeType" + case sizeOriginal = "sizeOriginal" + case chunksTotal = "chunksTotal" + case chunksUploaded = "chunksUploaded" + } /// File ID. public let id: String @@ -64,6 +78,38 @@ public class File { self.chunksUploaded = chunksUploaded } + 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.bucketId = try container.decode(String.self, forKey: .bucketId) + 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.name = try container.decode(String.self, forKey: .name) + self.signature = try container.decode(String.self, forKey: .signature) + self.mimeType = try container.decode(String.self, forKey: .mimeType) + self.sizeOriginal = try container.decode(Int.self, forKey: .sizeOriginal) + self.chunksTotal = try container.decode(Int.self, forKey: .chunksTotal) + self.chunksUploaded = try container.decode(Int.self, forKey: .chunksUploaded) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(id, forKey: .id) + try container.encode(bucketId, forKey: .bucketId) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + try container.encode(permissions, forKey: .permissions) + try container.encode(name, forKey: .name) + try container.encode(signature, forKey: .signature) + try container.encode(mimeType, forKey: .mimeType) + try container.encode(sizeOriginal, forKey: .sizeOriginal) + try container.encode(chunksTotal, forKey: .chunksTotal) + try container.encode(chunksUploaded, forKey: .chunksUploaded) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/FileList.swift b/Sources/AppwriteModels/FileList.swift index 0d6ad88..bec7b76 100644 --- a/Sources/AppwriteModels/FileList.swift +++ b/Sources/AppwriteModels/FileList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Files List -public class FileList { +open class FileList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case files = "files" + } /// Total number of files documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class FileList { self.files = files } + 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.files = try container.decode([File].self, forKey: .files) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(files, forKey: .files) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Headers.swift b/Sources/AppwriteModels/Headers.swift index 6f554ac..ae468e5 100644 --- a/Sources/AppwriteModels/Headers.swift +++ b/Sources/AppwriteModels/Headers.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Headers -public class Headers { +open class Headers: Codable { + + enum CodingKeys: String, CodingKey { + case name = "name" + case value = "value" + } /// Header name. public let name: String @@ -19,6 +24,20 @@ public class Headers { self.value = value } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.name = try container.decode(String.self, forKey: .name) + self.value = try container.decode(String.self, forKey: .value) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(name, forKey: .name) + try container.encode(value, forKey: .value) + } + public func toMap() -> [String: Any] { return [ "name": name as Any, diff --git a/Sources/AppwriteModels/Identity.swift b/Sources/AppwriteModels/Identity.swift index fb54237..f93035d 100644 --- a/Sources/AppwriteModels/Identity.swift +++ b/Sources/AppwriteModels/Identity.swift @@ -2,7 +2,20 @@ import Foundation import JSONCodable /// Identity -public class Identity { +open class Identity: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case userId = "userId" + case provider = "provider" + case providerUid = "providerUid" + case providerEmail = "providerEmail" + case providerAccessToken = "providerAccessToken" + case providerAccessTokenExpiry = "providerAccessTokenExpiry" + case providerRefreshToken = "providerRefreshToken" + } /// Identity ID. public let id: String @@ -59,6 +72,36 @@ public class Identity { self.providerRefreshToken = providerRefreshToken } + 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.userId = try container.decode(String.self, forKey: .userId) + self.provider = try container.decode(String.self, forKey: .provider) + self.providerUid = try container.decode(String.self, forKey: .providerUid) + self.providerEmail = try container.decode(String.self, forKey: .providerEmail) + self.providerAccessToken = try container.decode(String.self, forKey: .providerAccessToken) + self.providerAccessTokenExpiry = try container.decode(String.self, forKey: .providerAccessTokenExpiry) + self.providerRefreshToken = try container.decode(String.self, forKey: .providerRefreshToken) + } + + 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(userId, forKey: .userId) + try container.encode(provider, forKey: .provider) + try container.encode(providerUid, forKey: .providerUid) + try container.encode(providerEmail, forKey: .providerEmail) + try container.encode(providerAccessToken, forKey: .providerAccessToken) + try container.encode(providerAccessTokenExpiry, forKey: .providerAccessTokenExpiry) + try container.encode(providerRefreshToken, forKey: .providerRefreshToken) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/IdentityList.swift b/Sources/AppwriteModels/IdentityList.swift index b068f4c..6065fad 100644 --- a/Sources/AppwriteModels/IdentityList.swift +++ b/Sources/AppwriteModels/IdentityList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Identities List -public class IdentityList { +open class IdentityList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case identities = "identities" + } /// Total number of identities documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class IdentityList { self.identities = identities } + 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.identities = try container.decode([Identity].self, forKey: .identities) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(identities, forKey: .identities) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Jwt.swift b/Sources/AppwriteModels/Jwt.swift index 5778435..fd7fb49 100644 --- a/Sources/AppwriteModels/Jwt.swift +++ b/Sources/AppwriteModels/Jwt.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// JWT -public class Jwt { +open class Jwt: Codable { + + enum CodingKeys: String, CodingKey { + case jwt = "jwt" + } /// JWT encoded string. public let jwt: String @@ -14,6 +18,18 @@ public class Jwt { self.jwt = jwt } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.jwt = try container.decode(String.self, forKey: .jwt) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(jwt, forKey: .jwt) + } + public func toMap() -> [String: Any] { return [ "jwt": jwt as Any diff --git a/Sources/AppwriteModels/Language.swift b/Sources/AppwriteModels/Language.swift index f385d5a..d1e1a15 100644 --- a/Sources/AppwriteModels/Language.swift +++ b/Sources/AppwriteModels/Language.swift @@ -2,7 +2,13 @@ import Foundation import JSONCodable /// Language -public class Language { +open class Language: Codable { + + enum CodingKeys: String, CodingKey { + case name = "name" + case code = "code" + case nativeName = "nativeName" + } /// Language name. public let name: String @@ -24,6 +30,22 @@ public class Language { self.nativeName = nativeName } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.name = try container.decode(String.self, forKey: .name) + self.code = try container.decode(String.self, forKey: .code) + self.nativeName = try container.decode(String.self, forKey: .nativeName) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(name, forKey: .name) + try container.encode(code, forKey: .code) + try container.encode(nativeName, forKey: .nativeName) + } + public func toMap() -> [String: Any] { return [ "name": name as Any, diff --git a/Sources/AppwriteModels/LanguageList.swift b/Sources/AppwriteModels/LanguageList.swift index b4515e3..13c6e4a 100644 --- a/Sources/AppwriteModels/LanguageList.swift +++ b/Sources/AppwriteModels/LanguageList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Languages List -public class LanguageList { +open class LanguageList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case languages = "languages" + } /// Total number of languages documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class LanguageList { self.languages = languages } + 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.languages = try container.decode([Language].self, forKey: .languages) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(languages, forKey: .languages) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Locale.swift b/Sources/AppwriteModels/Locale.swift index 7445776..4d034f4 100644 --- a/Sources/AppwriteModels/Locale.swift +++ b/Sources/AppwriteModels/Locale.swift @@ -2,7 +2,17 @@ import Foundation import JSONCodable /// Locale -public class Locale { +open class Locale: Codable { + + enum CodingKeys: String, CodingKey { + case ip = "ip" + case countryCode = "countryCode" + case country = "country" + case continentCode = "continentCode" + case continent = "continent" + case eu = "eu" + case currency = "currency" + } /// User IP address. public let ip: String @@ -44,6 +54,30 @@ public class Locale { self.currency = currency } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.ip = try container.decode(String.self, forKey: .ip) + self.countryCode = try container.decode(String.self, forKey: .countryCode) + self.country = try container.decode(String.self, forKey: .country) + self.continentCode = try container.decode(String.self, forKey: .continentCode) + self.continent = try container.decode(String.self, forKey: .continent) + self.eu = try container.decode(Bool.self, forKey: .eu) + self.currency = try container.decode(String.self, forKey: .currency) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(ip, forKey: .ip) + try container.encode(countryCode, forKey: .countryCode) + try container.encode(country, forKey: .country) + try container.encode(continentCode, forKey: .continentCode) + try container.encode(continent, forKey: .continent) + try container.encode(eu, forKey: .eu) + try container.encode(currency, forKey: .currency) + } + public func toMap() -> [String: Any] { return [ "ip": ip as Any, diff --git a/Sources/AppwriteModels/LocaleCode.swift b/Sources/AppwriteModels/LocaleCode.swift index 8e561c7..d2678bb 100644 --- a/Sources/AppwriteModels/LocaleCode.swift +++ b/Sources/AppwriteModels/LocaleCode.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// LocaleCode -public class LocaleCode { +open class LocaleCode: Codable { + + enum CodingKeys: String, CodingKey { + case code = "code" + case name = "name" + } /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) public let code: String @@ -19,6 +24,20 @@ public class LocaleCode { self.name = name } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.code = try container.decode(String.self, forKey: .code) + self.name = try container.decode(String.self, forKey: .name) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(code, forKey: .code) + try container.encode(name, forKey: .name) + } + public func toMap() -> [String: Any] { return [ "code": code as Any, diff --git a/Sources/AppwriteModels/LocaleCodeList.swift b/Sources/AppwriteModels/LocaleCodeList.swift index 895ef7d..5ef0653 100644 --- a/Sources/AppwriteModels/LocaleCodeList.swift +++ b/Sources/AppwriteModels/LocaleCodeList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Locale codes list -public class LocaleCodeList { +open class LocaleCodeList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case localeCodes = "localeCodes" + } /// Total number of localeCodes documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class LocaleCodeList { self.localeCodes = localeCodes } + 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.localeCodes = try container.decode([LocaleCode].self, forKey: .localeCodes) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(localeCodes, forKey: .localeCodes) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Log.swift b/Sources/AppwriteModels/Log.swift index df5464d..16c27ef 100644 --- a/Sources/AppwriteModels/Log.swift +++ b/Sources/AppwriteModels/Log.swift @@ -2,7 +2,31 @@ import Foundation import JSONCodable /// Log -public class Log { +open class Log: Codable { + + enum CodingKeys: String, CodingKey { + case event = "event" + case userId = "userId" + case userEmail = "userEmail" + case userName = "userName" + case mode = "mode" + case ip = "ip" + case time = "time" + case osCode = "osCode" + case osName = "osName" + case osVersion = "osVersion" + case clientType = "clientType" + case clientCode = "clientCode" + case clientName = "clientName" + case clientVersion = "clientVersion" + case clientEngine = "clientEngine" + case clientEngineVersion = "clientEngineVersion" + case deviceName = "deviceName" + case deviceBrand = "deviceBrand" + case deviceModel = "deviceModel" + case countryCode = "countryCode" + case countryName = "countryName" + } /// Event name. public let event: String @@ -114,6 +138,58 @@ public class Log { self.countryName = countryName } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.event = try container.decode(String.self, forKey: .event) + self.userId = try container.decode(String.self, forKey: .userId) + self.userEmail = try container.decode(String.self, forKey: .userEmail) + self.userName = try container.decode(String.self, forKey: .userName) + self.mode = try container.decode(String.self, forKey: .mode) + self.ip = try container.decode(String.self, forKey: .ip) + self.time = try container.decode(String.self, forKey: .time) + self.osCode = try container.decode(String.self, forKey: .osCode) + self.osName = try container.decode(String.self, forKey: .osName) + self.osVersion = try container.decode(String.self, forKey: .osVersion) + self.clientType = try container.decode(String.self, forKey: .clientType) + self.clientCode = try container.decode(String.self, forKey: .clientCode) + self.clientName = try container.decode(String.self, forKey: .clientName) + self.clientVersion = try container.decode(String.self, forKey: .clientVersion) + self.clientEngine = try container.decode(String.self, forKey: .clientEngine) + self.clientEngineVersion = try container.decode(String.self, forKey: .clientEngineVersion) + self.deviceName = try container.decode(String.self, forKey: .deviceName) + self.deviceBrand = try container.decode(String.self, forKey: .deviceBrand) + self.deviceModel = try container.decode(String.self, forKey: .deviceModel) + self.countryCode = try container.decode(String.self, forKey: .countryCode) + self.countryName = try container.decode(String.self, forKey: .countryName) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(event, forKey: .event) + try container.encode(userId, forKey: .userId) + try container.encode(userEmail, forKey: .userEmail) + try container.encode(userName, forKey: .userName) + try container.encode(mode, forKey: .mode) + try container.encode(ip, forKey: .ip) + try container.encode(time, forKey: .time) + try container.encode(osCode, forKey: .osCode) + try container.encode(osName, forKey: .osName) + try container.encode(osVersion, forKey: .osVersion) + try container.encode(clientType, forKey: .clientType) + try container.encode(clientCode, forKey: .clientCode) + try container.encode(clientName, forKey: .clientName) + try container.encode(clientVersion, forKey: .clientVersion) + try container.encode(clientEngine, forKey: .clientEngine) + try container.encode(clientEngineVersion, forKey: .clientEngineVersion) + try container.encode(deviceName, forKey: .deviceName) + try container.encode(deviceBrand, forKey: .deviceBrand) + try container.encode(deviceModel, forKey: .deviceModel) + try container.encode(countryCode, forKey: .countryCode) + try container.encode(countryName, forKey: .countryName) + } + public func toMap() -> [String: Any] { return [ "event": event as Any, diff --git a/Sources/AppwriteModels/LogList.swift b/Sources/AppwriteModels/LogList.swift index 2f99674..7ff2d07 100644 --- a/Sources/AppwriteModels/LogList.swift +++ b/Sources/AppwriteModels/LogList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Logs List -public class LogList { +open class LogList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case logs = "logs" + } /// Total number of logs documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class LogList { self.logs = logs } + 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.logs = try container.decode([Log].self, forKey: .logs) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(logs, forKey: .logs) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Membership.swift b/Sources/AppwriteModels/Membership.swift index 805cb47..8d26766 100644 --- a/Sources/AppwriteModels/Membership.swift +++ b/Sources/AppwriteModels/Membership.swift @@ -2,7 +2,23 @@ import Foundation import JSONCodable /// Membership -public class Membership { +open class Membership: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case userId = "userId" + case userName = "userName" + case userEmail = "userEmail" + case teamId = "teamId" + case teamName = "teamName" + case invited = "invited" + case joined = "joined" + case confirm = "confirm" + case mfa = "mfa" + case roles = "roles" + } /// Membership ID. public let id: String @@ -74,6 +90,42 @@ public class Membership { self.roles = roles } + 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.userId = try container.decode(String.self, forKey: .userId) + self.userName = try container.decode(String.self, forKey: .userName) + self.userEmail = try container.decode(String.self, forKey: .userEmail) + self.teamId = try container.decode(String.self, forKey: .teamId) + self.teamName = try container.decode(String.self, forKey: .teamName) + self.invited = try container.decode(String.self, forKey: .invited) + self.joined = try container.decode(String.self, forKey: .joined) + self.confirm = try container.decode(Bool.self, forKey: .confirm) + self.mfa = try container.decode(Bool.self, forKey: .mfa) + self.roles = try container.decode([String].self, forKey: .roles) + } + + 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(userId, forKey: .userId) + try container.encode(userName, forKey: .userName) + try container.encode(userEmail, forKey: .userEmail) + try container.encode(teamId, forKey: .teamId) + try container.encode(teamName, forKey: .teamName) + try container.encode(invited, forKey: .invited) + try container.encode(joined, forKey: .joined) + try container.encode(confirm, forKey: .confirm) + try container.encode(mfa, forKey: .mfa) + try container.encode(roles, forKey: .roles) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/MembershipList.swift b/Sources/AppwriteModels/MembershipList.swift index f27cc99..a7b0cd6 100644 --- a/Sources/AppwriteModels/MembershipList.swift +++ b/Sources/AppwriteModels/MembershipList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Memberships List -public class MembershipList { +open class MembershipList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case memberships = "memberships" + } /// Total number of memberships documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class MembershipList { self.memberships = memberships } + 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.memberships = try container.decode([Membership].self, forKey: .memberships) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(memberships, forKey: .memberships) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/MfaChallenge.swift b/Sources/AppwriteModels/MfaChallenge.swift index 5a1e874..c6b77a5 100644 --- a/Sources/AppwriteModels/MfaChallenge.swift +++ b/Sources/AppwriteModels/MfaChallenge.swift @@ -2,7 +2,14 @@ import Foundation import JSONCodable /// MFA Challenge -public class MfaChallenge { +open class MfaChallenge: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case userId = "userId" + case expire = "expire" + } /// Token ID. public let id: String @@ -29,6 +36,24 @@ public class MfaChallenge { self.expire = expire } + 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.userId = try container.decode(String.self, forKey: .userId) + self.expire = try container.decode(String.self, forKey: .expire) + } + + 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(userId, forKey: .userId) + try container.encode(expire, forKey: .expire) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/MfaFactors.swift b/Sources/AppwriteModels/MfaFactors.swift index 716c055..4291fab 100644 --- a/Sources/AppwriteModels/MfaFactors.swift +++ b/Sources/AppwriteModels/MfaFactors.swift @@ -2,7 +2,14 @@ import Foundation import JSONCodable /// MFAFactors -public class MfaFactors { +open class MfaFactors: Codable { + + enum CodingKeys: String, CodingKey { + case totp = "totp" + case phone = "phone" + case email = "email" + case recoveryCode = "recoveryCode" + } /// Can TOTP be used for MFA challenge for this account. public let totp: Bool @@ -29,6 +36,24 @@ public class MfaFactors { self.recoveryCode = recoveryCode } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.totp = try container.decode(Bool.self, forKey: .totp) + self.phone = try container.decode(Bool.self, forKey: .phone) + self.email = try container.decode(Bool.self, forKey: .email) + self.recoveryCode = try container.decode(Bool.self, forKey: .recoveryCode) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(totp, forKey: .totp) + try container.encode(phone, forKey: .phone) + try container.encode(email, forKey: .email) + try container.encode(recoveryCode, forKey: .recoveryCode) + } + public func toMap() -> [String: Any] { return [ "totp": totp as Any, diff --git a/Sources/AppwriteModels/MfaRecoveryCodes.swift b/Sources/AppwriteModels/MfaRecoveryCodes.swift index 314e11c..bd2968f 100644 --- a/Sources/AppwriteModels/MfaRecoveryCodes.swift +++ b/Sources/AppwriteModels/MfaRecoveryCodes.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// MFA Recovery Codes -public class MfaRecoveryCodes { +open class MfaRecoveryCodes: Codable { + + enum CodingKeys: String, CodingKey { + case recoveryCodes = "recoveryCodes" + } /// Recovery codes. public let recoveryCodes: [String] @@ -14,6 +18,18 @@ public class MfaRecoveryCodes { self.recoveryCodes = recoveryCodes } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.recoveryCodes = try container.decode([String].self, forKey: .recoveryCodes) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(recoveryCodes, forKey: .recoveryCodes) + } + public func toMap() -> [String: Any] { return [ "recoveryCodes": recoveryCodes as Any diff --git a/Sources/AppwriteModels/MfaType.swift b/Sources/AppwriteModels/MfaType.swift index 503134f..8646385 100644 --- a/Sources/AppwriteModels/MfaType.swift +++ b/Sources/AppwriteModels/MfaType.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// MFAType -public class MfaType { +open class MfaType: Codable { + + enum CodingKeys: String, CodingKey { + case secret = "secret" + case uri = "uri" + } /// Secret token used for TOTP factor. public let secret: String @@ -19,6 +24,20 @@ public class MfaType { self.uri = uri } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.secret = try container.decode(String.self, forKey: .secret) + self.uri = try container.decode(String.self, forKey: .uri) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(secret, forKey: .secret) + try container.encode(uri, forKey: .uri) + } + public func toMap() -> [String: Any] { return [ "secret": secret as Any, diff --git a/Sources/AppwriteModels/Phone.swift b/Sources/AppwriteModels/Phone.swift index 2e113b4..fc90d49 100644 --- a/Sources/AppwriteModels/Phone.swift +++ b/Sources/AppwriteModels/Phone.swift @@ -2,7 +2,13 @@ import Foundation import JSONCodable /// Phone -public class Phone { +open class Phone: Codable { + + enum CodingKeys: String, CodingKey { + case code = "code" + case countryCode = "countryCode" + case countryName = "countryName" + } /// Phone code. public let code: String @@ -24,6 +30,22 @@ public class Phone { self.countryName = countryName } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.code = try container.decode(String.self, forKey: .code) + self.countryCode = try container.decode(String.self, forKey: .countryCode) + self.countryName = try container.decode(String.self, forKey: .countryName) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(code, forKey: .code) + try container.encode(countryCode, forKey: .countryCode) + try container.encode(countryName, forKey: .countryName) + } + public func toMap() -> [String: Any] { return [ "code": code as Any, diff --git a/Sources/AppwriteModels/PhoneList.swift b/Sources/AppwriteModels/PhoneList.swift index 38a5a6f..6f3bee3 100644 --- a/Sources/AppwriteModels/PhoneList.swift +++ b/Sources/AppwriteModels/PhoneList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Phones List -public class PhoneList { +open class PhoneList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case phones = "phones" + } /// Total number of phones documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class PhoneList { self.phones = phones } + 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.phones = try container.decode([Phone].self, forKey: .phones) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(phones, forKey: .phones) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Preferences.swift b/Sources/AppwriteModels/Preferences.swift index 9904ccc..41f94e6 100644 --- a/Sources/AppwriteModels/Preferences.swift +++ b/Sources/AppwriteModels/Preferences.swift @@ -2,7 +2,11 @@ import Foundation import JSONCodable /// Preferences -public class Preferences { +open class Preferences: Codable { + + enum CodingKeys: String, CodingKey { + case data + } /// Additional properties public let data: T @@ -13,6 +17,18 @@ public class Preferences { self.data = data } + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + 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(data, forKey: .data) + } + public func toMap() -> [String: Any] { return [ "data": try! JSONEncoder().encode(data) diff --git a/Sources/AppwriteModels/Session.swift b/Sources/AppwriteModels/Session.swift index 86f4a7c..b5c25a6 100644 --- a/Sources/AppwriteModels/Session.swift +++ b/Sources/AppwriteModels/Session.swift @@ -2,7 +2,39 @@ import Foundation import JSONCodable /// Session -public class Session { +open class Session: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case userId = "userId" + case expire = "expire" + case provider = "provider" + case providerUid = "providerUid" + case providerAccessToken = "providerAccessToken" + case providerAccessTokenExpiry = "providerAccessTokenExpiry" + case providerRefreshToken = "providerRefreshToken" + case ip = "ip" + case osCode = "osCode" + case osName = "osName" + case osVersion = "osVersion" + case clientType = "clientType" + case clientCode = "clientCode" + case clientName = "clientName" + case clientVersion = "clientVersion" + case clientEngine = "clientEngine" + case clientEngineVersion = "clientEngineVersion" + case deviceName = "deviceName" + case deviceBrand = "deviceBrand" + case deviceModel = "deviceModel" + case countryCode = "countryCode" + case countryName = "countryName" + case current = "current" + case factors = "factors" + case secret = "secret" + case mfaUpdatedAt = "mfaUpdatedAt" + } /// Session ID. public let id: String @@ -154,6 +186,74 @@ public class Session { self.mfaUpdatedAt = mfaUpdatedAt } + 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.userId = try container.decode(String.self, forKey: .userId) + self.expire = try container.decode(String.self, forKey: .expire) + self.provider = try container.decode(String.self, forKey: .provider) + self.providerUid = try container.decode(String.self, forKey: .providerUid) + self.providerAccessToken = try container.decode(String.self, forKey: .providerAccessToken) + self.providerAccessTokenExpiry = try container.decode(String.self, forKey: .providerAccessTokenExpiry) + self.providerRefreshToken = try container.decode(String.self, forKey: .providerRefreshToken) + self.ip = try container.decode(String.self, forKey: .ip) + self.osCode = try container.decode(String.self, forKey: .osCode) + self.osName = try container.decode(String.self, forKey: .osName) + self.osVersion = try container.decode(String.self, forKey: .osVersion) + self.clientType = try container.decode(String.self, forKey: .clientType) + self.clientCode = try container.decode(String.self, forKey: .clientCode) + self.clientName = try container.decode(String.self, forKey: .clientName) + self.clientVersion = try container.decode(String.self, forKey: .clientVersion) + self.clientEngine = try container.decode(String.self, forKey: .clientEngine) + self.clientEngineVersion = try container.decode(String.self, forKey: .clientEngineVersion) + self.deviceName = try container.decode(String.self, forKey: .deviceName) + self.deviceBrand = try container.decode(String.self, forKey: .deviceBrand) + self.deviceModel = try container.decode(String.self, forKey: .deviceModel) + self.countryCode = try container.decode(String.self, forKey: .countryCode) + self.countryName = try container.decode(String.self, forKey: .countryName) + self.current = try container.decode(Bool.self, forKey: .current) + self.factors = try container.decode([String].self, forKey: .factors) + self.secret = try container.decode(String.self, forKey: .secret) + self.mfaUpdatedAt = try container.decode(String.self, forKey: .mfaUpdatedAt) + } + + 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(userId, forKey: .userId) + try container.encode(expire, forKey: .expire) + try container.encode(provider, forKey: .provider) + try container.encode(providerUid, forKey: .providerUid) + try container.encode(providerAccessToken, forKey: .providerAccessToken) + try container.encode(providerAccessTokenExpiry, forKey: .providerAccessTokenExpiry) + try container.encode(providerRefreshToken, forKey: .providerRefreshToken) + try container.encode(ip, forKey: .ip) + try container.encode(osCode, forKey: .osCode) + try container.encode(osName, forKey: .osName) + try container.encode(osVersion, forKey: .osVersion) + try container.encode(clientType, forKey: .clientType) + try container.encode(clientCode, forKey: .clientCode) + try container.encode(clientName, forKey: .clientName) + try container.encode(clientVersion, forKey: .clientVersion) + try container.encode(clientEngine, forKey: .clientEngine) + try container.encode(clientEngineVersion, forKey: .clientEngineVersion) + try container.encode(deviceName, forKey: .deviceName) + try container.encode(deviceBrand, forKey: .deviceBrand) + try container.encode(deviceModel, forKey: .deviceModel) + try container.encode(countryCode, forKey: .countryCode) + try container.encode(countryName, forKey: .countryName) + try container.encode(current, forKey: .current) + try container.encode(factors, forKey: .factors) + try container.encode(secret, forKey: .secret) + try container.encode(mfaUpdatedAt, forKey: .mfaUpdatedAt) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/SessionList.swift b/Sources/AppwriteModels/SessionList.swift index 409f72a..13b6b3d 100644 --- a/Sources/AppwriteModels/SessionList.swift +++ b/Sources/AppwriteModels/SessionList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Sessions List -public class SessionList { +open class SessionList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case sessions = "sessions" + } /// Total number of sessions documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class SessionList { self.sessions = sessions } + 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.sessions = try container.decode([Session].self, forKey: .sessions) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(sessions, forKey: .sessions) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Subscriber.swift b/Sources/AppwriteModels/Subscriber.swift index 5ab202d..ad6fa5d 100644 --- a/Sources/AppwriteModels/Subscriber.swift +++ b/Sources/AppwriteModels/Subscriber.swift @@ -2,7 +2,19 @@ import Foundation import JSONCodable /// Subscriber -public class Subscriber { +open class Subscriber: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case targetId = "targetId" + case target = "target" + case userId = "userId" + case userName = "userName" + case topicId = "topicId" + case providerType = "providerType" + } /// Subscriber ID. public let id: String @@ -54,6 +66,34 @@ public class Subscriber { self.providerType = providerType } + 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.targetId = try container.decode(String.self, forKey: .targetId) + self.target = try container.decode(Target.self, forKey: .target) + self.userId = try container.decode(String.self, forKey: .userId) + self.userName = try container.decode(String.self, forKey: .userName) + self.topicId = try container.decode(String.self, forKey: .topicId) + self.providerType = try container.decode(String.self, forKey: .providerType) + } + + 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(targetId, forKey: .targetId) + try container.encode(target, forKey: .target) + try container.encode(userId, forKey: .userId) + try container.encode(userName, forKey: .userName) + try container.encode(topicId, forKey: .topicId) + try container.encode(providerType, forKey: .providerType) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/Target.swift b/Sources/AppwriteModels/Target.swift index 2e81790..0581a61 100644 --- a/Sources/AppwriteModels/Target.swift +++ b/Sources/AppwriteModels/Target.swift @@ -2,7 +2,19 @@ import Foundation import JSONCodable /// Target -public class Target { +open class Target: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case name = "name" + case userId = "userId" + case providerId = "providerId" + case providerType = "providerType" + case identifier = "identifier" + case expired = "expired" + } /// Target ID. public let id: String @@ -54,6 +66,34 @@ public class Target { self.expired = expired } + 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.name = try container.decode(String.self, forKey: .name) + self.userId = try container.decode(String.self, forKey: .userId) + self.providerId = try container.decodeIfPresent(String.self, forKey: .providerId) + self.providerType = try container.decode(String.self, forKey: .providerType) + self.identifier = try container.decode(String.self, forKey: .identifier) + self.expired = try container.decode(Bool.self, forKey: .expired) + } + + 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(name, forKey: .name) + try container.encode(userId, forKey: .userId) + try container.encodeIfPresent(providerId, forKey: .providerId) + try container.encode(providerType, forKey: .providerType) + try container.encode(identifier, forKey: .identifier) + try container.encode(expired, forKey: .expired) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/Team.swift b/Sources/AppwriteModels/Team.swift index a44c305..9ca7307 100644 --- a/Sources/AppwriteModels/Team.swift +++ b/Sources/AppwriteModels/Team.swift @@ -2,7 +2,16 @@ import Foundation import JSONCodable /// Team -public class Team { +open class Team: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case name = "name" + case total = "total" + case prefs = "prefs" + } /// Team ID. public let id: String @@ -39,6 +48,28 @@ public class Team { self.prefs = prefs } + 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.name = try container.decode(String.self, forKey: .name) + self.total = try container.decode(Int.self, forKey: .total) + self.prefs = try container.decode(Preferences.self, forKey: .prefs) + } + + 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(name, forKey: .name) + try container.encode(total, forKey: .total) + try container.encode(prefs, forKey: .prefs) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/TeamList.swift b/Sources/AppwriteModels/TeamList.swift index ec7e0bd..384d9f6 100644 --- a/Sources/AppwriteModels/TeamList.swift +++ b/Sources/AppwriteModels/TeamList.swift @@ -2,7 +2,12 @@ import Foundation import JSONCodable /// Teams List -public class TeamList { +open class TeamList: Codable { + + enum CodingKeys: String, CodingKey { + case total = "total" + case teams = "teams" + } /// Total number of teams documents that matched your query. public let total: Int @@ -19,6 +24,20 @@ public class TeamList { self.teams = teams } + 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.teams = try container.decode([Team].self, forKey: .teams) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + + try container.encode(total, forKey: .total) + try container.encode(teams, forKey: .teams) + } + public func toMap() -> [String: Any] { return [ "total": total as Any, diff --git a/Sources/AppwriteModels/Token.swift b/Sources/AppwriteModels/Token.swift index 31d4b4a..f832402 100644 --- a/Sources/AppwriteModels/Token.swift +++ b/Sources/AppwriteModels/Token.swift @@ -2,7 +2,16 @@ import Foundation import JSONCodable /// Token -public class Token { +open class Token: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case userId = "userId" + case secret = "secret" + case expire = "expire" + case phrase = "phrase" + } /// Token ID. public let id: String @@ -39,6 +48,28 @@ public class Token { self.phrase = phrase } + 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.userId = try container.decode(String.self, forKey: .userId) + self.secret = try container.decode(String.self, forKey: .secret) + self.expire = try container.decode(String.self, forKey: .expire) + self.phrase = try container.decode(String.self, forKey: .phrase) + } + + 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(userId, forKey: .userId) + try container.encode(secret, forKey: .secret) + try container.encode(expire, forKey: .expire) + try container.encode(phrase, forKey: .phrase) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, diff --git a/Sources/AppwriteModels/User.swift b/Sources/AppwriteModels/User.swift index 0229dc5..6e972d3 100644 --- a/Sources/AppwriteModels/User.swift +++ b/Sources/AppwriteModels/User.swift @@ -2,7 +2,29 @@ import Foundation import JSONCodable /// User -public class User { +open class User: Codable { + + enum CodingKeys: String, CodingKey { + case id = "$id" + case createdAt = "$createdAt" + case updatedAt = "$updatedAt" + case name = "name" + case password = "password" + case hash = "hash" + case hashOptions = "hashOptions" + case registration = "registration" + case status = "status" + case labels = "labels" + case passwordUpdate = "passwordUpdate" + case email = "email" + case phone = "phone" + case emailVerification = "emailVerification" + case phoneVerification = "phoneVerification" + case mfa = "mfa" + case prefs = "prefs" + case targets = "targets" + case accessedAt = "accessedAt" + } /// User ID. public let id: String @@ -23,7 +45,7 @@ public class User { public let hash: String? /// Password hashing algorithm configuration. - public let hashOptions: Any? + public let hashOptions: [String: AnyCodable]? /// User registration date in ISO 8601 format. public let registration: String @@ -69,7 +91,7 @@ public class User { name: String, password: String?, hash: String?, - hashOptions: Any?, + hashOptions: [String: AnyCodable]?, registration: String, status: Bool, labels: [String], @@ -104,6 +126,54 @@ public class User { self.accessedAt = accessedAt } + 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.name = try container.decode(String.self, forKey: .name) + self.password = try container.decodeIfPresent(String.self, forKey: .password) + self.hash = try container.decodeIfPresent(String.self, forKey: .hash) + self.hashOptions = try container.decodeIfPresent([String: AnyCodable].self, forKey: .hashOptions) + self.registration = try container.decode(String.self, forKey: .registration) + self.status = try container.decode(Bool.self, forKey: .status) + self.labels = try container.decode([String].self, forKey: .labels) + self.passwordUpdate = try container.decode(String.self, forKey: .passwordUpdate) + self.email = try container.decode(String.self, forKey: .email) + self.phone = try container.decode(String.self, forKey: .phone) + self.emailVerification = try container.decode(Bool.self, forKey: .emailVerification) + self.phoneVerification = try container.decode(Bool.self, forKey: .phoneVerification) + self.mfa = try container.decode(Bool.self, forKey: .mfa) + self.prefs = try container.decode(Preferences.self, forKey: .prefs) + self.targets = try container.decode([Target].self, forKey: .targets) + self.accessedAt = try container.decode(String.self, forKey: .accessedAt) + } + + 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(name, forKey: .name) + try container.encodeIfPresent(password, forKey: .password) + try container.encodeIfPresent(hash, forKey: .hash) + try container.encodeIfPresent(hashOptions, forKey: .hashOptions) + try container.encode(registration, forKey: .registration) + try container.encode(status, forKey: .status) + try container.encode(labels, forKey: .labels) + try container.encode(passwordUpdate, forKey: .passwordUpdate) + try container.encode(email, forKey: .email) + try container.encode(phone, forKey: .phone) + try container.encode(emailVerification, forKey: .emailVerification) + try container.encode(phoneVerification, forKey: .phoneVerification) + try container.encode(mfa, forKey: .mfa) + try container.encode(prefs, forKey: .prefs) + try container.encode(targets, forKey: .targets) + try container.encode(accessedAt, forKey: .accessedAt) + } + public func toMap() -> [String: Any] { return [ "$id": id as Any, @@ -136,7 +206,7 @@ public class User { name: map["name"] as! String, password: map["password"] as? String, hash: map["hash"] as? String, - hashOptions: map["hashOptions"] as? Any, + hashOptions: map["hashOptions"] as? [String: AnyCodable], registration: map["registration"] as! String, status: map["status"] as! Bool, labels: map["labels"] as! [String],