From 24f1750ca55700f00759f9fb7064c79efe221c44 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Jun 2025 05:57:02 +0000 Subject: [PATCH 1/3] chore: regenerate sdk --- README.md | 4 +- Sources/Appwrite/Client.swift | 4 +- Sources/Appwrite/Services/Databases.swift | 84 +++++++++++++++++++ Sources/AppwriteModels/AlgoArgon2.swift | 8 +- Sources/AppwriteModels/AlgoBcrypt.swift | 2 +- Sources/AppwriteModels/AlgoMd5.swift | 2 +- Sources/AppwriteModels/AlgoPhpass.swift | 2 +- Sources/AppwriteModels/AlgoScrypt.swift | 10 +-- .../AppwriteModels/AlgoScryptModified.swift | 8 +- Sources/AppwriteModels/AlgoSha.swift | 2 +- Sources/AppwriteModels/Continent.swift | 4 +- Sources/AppwriteModels/ContinentList.swift | 4 +- Sources/AppwriteModels/Country.swift | 4 +- Sources/AppwriteModels/CountryList.swift | 4 +- Sources/AppwriteModels/Currency.swift | 14 ++-- Sources/AppwriteModels/CurrencyList.swift | 4 +- Sources/AppwriteModels/Document.swift | 14 ++-- Sources/AppwriteModels/DocumentList.swift | 4 +- Sources/AppwriteModels/Execution.swift | 32 +++---- Sources/AppwriteModels/ExecutionList.swift | 4 +- Sources/AppwriteModels/File.swift | 22 ++--- Sources/AppwriteModels/FileList.swift | 4 +- Sources/AppwriteModels/Headers.swift | 4 +- Sources/AppwriteModels/Identity.swift | 20 ++--- Sources/AppwriteModels/IdentityList.swift | 4 +- Sources/AppwriteModels/Jwt.swift | 2 +- Sources/AppwriteModels/Language.swift | 6 +- Sources/AppwriteModels/LanguageList.swift | 4 +- Sources/AppwriteModels/Locale.swift | 14 ++-- Sources/AppwriteModels/LocaleCode.swift | 4 +- Sources/AppwriteModels/LocaleCodeList.swift | 4 +- Sources/AppwriteModels/Log.swift | 42 +++++----- Sources/AppwriteModels/LogList.swift | 4 +- Sources/AppwriteModels/Membership.swift | 26 +++--- Sources/AppwriteModels/MembershipList.swift | 4 +- Sources/AppwriteModels/MfaChallenge.swift | 8 +- Sources/AppwriteModels/MfaFactors.swift | 8 +- Sources/AppwriteModels/MfaRecoveryCodes.swift | 2 +- Sources/AppwriteModels/MfaType.swift | 4 +- Sources/AppwriteModels/Phone.swift | 6 +- Sources/AppwriteModels/PhoneList.swift | 4 +- Sources/AppwriteModels/Preferences.swift | 2 +- Sources/AppwriteModels/Session.swift | 58 ++++++------- Sources/AppwriteModels/SessionList.swift | 4 +- Sources/AppwriteModels/Subscriber.swift | 18 ++-- Sources/AppwriteModels/Target.swift | 16 ++-- Sources/AppwriteModels/Team.swift | 12 +-- Sources/AppwriteModels/TeamList.swift | 4 +- Sources/AppwriteModels/Token.swift | 12 +-- Sources/AppwriteModels/User.swift | 32 +++---- docs/examples/databases/create-documents.md | 14 ++++ 51 files changed, 340 insertions(+), 242 deletions(-) create mode 100644 docs/examples/databases/create-documents.md diff --git a/README.md b/README.md index 172967b..499f325 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) @@ -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: "10.1.0"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "10.1.1"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 55ebf0e..5365b44 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": "10.1.0", + "x-sdk-version": "10.1.1", "x-appwrite-response-format": "1.7.0" ] @@ -265,7 +265,7 @@ open class Client { return output.addingPercentEncoding( withAllowedCharacters: .urlHostAllowed - ) ?? "" + )?.replacingOccurrences(of: "+", with: "%2B") ?? "" // since urlHostAllowed doesn't include + } /// diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 239f4bc..017c1c9 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -150,6 +150,82 @@ open class Databases: Service { ) } + /// + /// **WARNING: Experimental Feature** - This endpoint is experimental and not + /// yet officially supported. It may be subject to breaking changes or removal + /// in future versions. + /// + /// Create new Documents. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + /// + /// @param String databaseId + /// @param String collectionId + /// @param [Any] documents + /// @throws Exception + /// @return array + /// + open func createDocuments( + databaseId: String, + collectionId: String, + documents: [Any], + nestedType: T.Type + ) async throws -> AppwriteModels.DocumentList { + let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents" + .replacingOccurrences(of: "{databaseId}", with: databaseId) + .replacingOccurrences(of: "{collectionId}", with: collectionId) + + let apiParams: [String: Any?] = [ + "documents": documents + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.DocumentList = { response in + return AppwriteModels.DocumentList.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: converter + ) + } + + /// + /// **WARNING: Experimental Feature** - This endpoint is experimental and not + /// yet officially supported. It may be subject to breaking changes or removal + /// in future versions. + /// + /// Create new Documents. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + /// + /// @param String databaseId + /// @param String collectionId + /// @param [Any] documents + /// @throws Exception + /// @return array + /// + open func createDocuments( + databaseId: String, + collectionId: String, + documents: [Any] + ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { + return try await createDocuments( + databaseId: databaseId, + collectionId: collectionId, + documents: documents, + nestedType: [String: AnyCodable].self + ) + } + /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. @@ -219,6 +295,10 @@ open class Databases: Service { } /// + /// **WARNING: Experimental Feature** - This endpoint is experimental and not + /// yet officially supported. It may be subject to breaking changes or removal + /// in future versions. + /// /// Create or update a Document. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) @@ -268,6 +348,10 @@ open class Databases: Service { } /// + /// **WARNING: Experimental Feature** - This endpoint is experimental and not + /// yet officially supported. It may be subject to breaking changes or removal + /// in future versions. + /// /// Create or update a Document. Before using this route, you should create a /// new collection resource using either a [server /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) diff --git a/Sources/AppwriteModels/AlgoArgon2.swift b/Sources/AppwriteModels/AlgoArgon2.swift index fd88955..5411998 100644 --- a/Sources/AppwriteModels/AlgoArgon2.swift +++ b/Sources/AppwriteModels/AlgoArgon2.swift @@ -65,10 +65,10 @@ open class AlgoArgon2: Codable { public static func from(map: [String: Any] ) -> AlgoArgon2 { return AlgoArgon2( - type: map["type"] as! String, - memoryCost: map["memoryCost"] as! Int, - timeCost: map["timeCost"] as! Int, - threads: map["threads"] as! Int + type: map["type"] as? String ?? "", + memoryCost: map["memoryCost"] as? Int ?? 0, + timeCost: map["timeCost"] as? Int ?? 0, + threads: map["threads"] as? Int ?? 0 ) } } diff --git a/Sources/AppwriteModels/AlgoBcrypt.swift b/Sources/AppwriteModels/AlgoBcrypt.swift index b34095d..3bd7061 100644 --- a/Sources/AppwriteModels/AlgoBcrypt.swift +++ b/Sources/AppwriteModels/AlgoBcrypt.swift @@ -38,7 +38,7 @@ open class AlgoBcrypt: Codable { public static func from(map: [String: Any] ) -> AlgoBcrypt { return AlgoBcrypt( - type: map["type"] as! String + type: map["type"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/AlgoMd5.swift b/Sources/AppwriteModels/AlgoMd5.swift index 72fbb8d..2d8b6f5 100644 --- a/Sources/AppwriteModels/AlgoMd5.swift +++ b/Sources/AppwriteModels/AlgoMd5.swift @@ -38,7 +38,7 @@ open class AlgoMd5: Codable { public static func from(map: [String: Any] ) -> AlgoMd5 { return AlgoMd5( - type: map["type"] as! String + type: map["type"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/AlgoPhpass.swift b/Sources/AppwriteModels/AlgoPhpass.swift index 7bd0c99..20d70c1 100644 --- a/Sources/AppwriteModels/AlgoPhpass.swift +++ b/Sources/AppwriteModels/AlgoPhpass.swift @@ -38,7 +38,7 @@ open class AlgoPhpass: Codable { public static func from(map: [String: Any] ) -> AlgoPhpass { return AlgoPhpass( - type: map["type"] as! String + type: map["type"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/AlgoScrypt.swift b/Sources/AppwriteModels/AlgoScrypt.swift index 03ce541..21500cb 100644 --- a/Sources/AppwriteModels/AlgoScrypt.swift +++ b/Sources/AppwriteModels/AlgoScrypt.swift @@ -74,11 +74,11 @@ open class AlgoScrypt: Codable { public static func from(map: [String: Any] ) -> AlgoScrypt { return AlgoScrypt( - type: map["type"] as! String, - costCpu: map["costCpu"] as! Int, - costMemory: map["costMemory"] as! Int, - costParallel: map["costParallel"] as! Int, - length: map["length"] as! Int + type: map["type"] as? String ?? "", + costCpu: map["costCpu"] as? Int ?? 0, + costMemory: map["costMemory"] as? Int ?? 0, + costParallel: map["costParallel"] as? Int ?? 0, + length: map["length"] as? Int ?? 0 ) } } diff --git a/Sources/AppwriteModels/AlgoScryptModified.swift b/Sources/AppwriteModels/AlgoScryptModified.swift index 0b2fa4e..bede143 100644 --- a/Sources/AppwriteModels/AlgoScryptModified.swift +++ b/Sources/AppwriteModels/AlgoScryptModified.swift @@ -65,10 +65,10 @@ open class AlgoScryptModified: Codable { public static func from(map: [String: Any] ) -> AlgoScryptModified { return AlgoScryptModified( - type: map["type"] as! String, - salt: map["salt"] as! String, - saltSeparator: map["saltSeparator"] as! String, - signerKey: map["signerKey"] as! String + type: map["type"] as? String ?? "", + salt: map["salt"] as? String ?? "", + saltSeparator: map["saltSeparator"] as? String ?? "", + signerKey: map["signerKey"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/AlgoSha.swift b/Sources/AppwriteModels/AlgoSha.swift index ffc0e05..6a3be42 100644 --- a/Sources/AppwriteModels/AlgoSha.swift +++ b/Sources/AppwriteModels/AlgoSha.swift @@ -38,7 +38,7 @@ open class AlgoSha: Codable { public static func from(map: [String: Any] ) -> AlgoSha { return AlgoSha( - type: map["type"] as! String + type: map["type"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/Continent.swift b/Sources/AppwriteModels/Continent.swift index b8994d9..64836ae 100644 --- a/Sources/AppwriteModels/Continent.swift +++ b/Sources/AppwriteModels/Continent.swift @@ -47,8 +47,8 @@ open class Continent: Codable { public static func from(map: [String: Any] ) -> Continent { return Continent( - name: map["name"] as! String, - code: map["code"] as! String + name: map["name"] as? String ?? "", + code: map["code"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/ContinentList.swift b/Sources/AppwriteModels/ContinentList.swift index fa9a90f..a924595 100644 --- a/Sources/AppwriteModels/ContinentList.swift +++ b/Sources/AppwriteModels/ContinentList.swift @@ -47,8 +47,8 @@ open class ContinentList: Codable { public static func from(map: [String: Any] ) -> ContinentList { return ContinentList( - total: map["total"] as! Int, - continents: (map["continents"] as! [[String: Any]]).map { Continent.from(map: $0) } + total: map["total"] as? Int ?? 0, + continents: (map["continents"] as? [[String: Any]] ?? []).map { Continent.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Country.swift b/Sources/AppwriteModels/Country.swift index c24f7e9..353da83 100644 --- a/Sources/AppwriteModels/Country.swift +++ b/Sources/AppwriteModels/Country.swift @@ -47,8 +47,8 @@ open class Country: Codable { public static func from(map: [String: Any] ) -> Country { return Country( - name: map["name"] as! String, - code: map["code"] as! String + name: map["name"] as? String ?? "", + code: map["code"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/CountryList.swift b/Sources/AppwriteModels/CountryList.swift index 865cc19..c6526fa 100644 --- a/Sources/AppwriteModels/CountryList.swift +++ b/Sources/AppwriteModels/CountryList.swift @@ -47,8 +47,8 @@ open class CountryList: Codable { public static func from(map: [String: Any] ) -> CountryList { return CountryList( - total: map["total"] as! Int, - countries: (map["countries"] as! [[String: Any]]).map { Country.from(map: $0) } + total: map["total"] as? Int ?? 0, + countries: (map["countries"] as? [[String: Any]] ?? []).map { Country.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Currency.swift b/Sources/AppwriteModels/Currency.swift index 320337b..dc67525 100644 --- a/Sources/AppwriteModels/Currency.swift +++ b/Sources/AppwriteModels/Currency.swift @@ -92,13 +92,13 @@ open class Currency: Codable { public static func from(map: [String: Any] ) -> Currency { return Currency( - symbol: map["symbol"] as! String, - name: map["name"] as! String, - symbolNative: map["symbolNative"] as! String, - decimalDigits: map["decimalDigits"] as! Int, - rounding: map["rounding"] as! Double, - code: map["code"] as! String, - namePlural: map["namePlural"] as! String + symbol: map["symbol"] as? String ?? "", + name: map["name"] as? String ?? "", + symbolNative: map["symbolNative"] as? String ?? "", + decimalDigits: map["decimalDigits"] as? Int ?? 0, + rounding: map["rounding"] as? Double ?? 0.0, + code: map["code"] as? String ?? "", + namePlural: map["namePlural"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/CurrencyList.swift b/Sources/AppwriteModels/CurrencyList.swift index 1e0dff9..6c81124 100644 --- a/Sources/AppwriteModels/CurrencyList.swift +++ b/Sources/AppwriteModels/CurrencyList.swift @@ -47,8 +47,8 @@ open class CurrencyList: Codable { public static func from(map: [String: Any] ) -> CurrencyList { return CurrencyList( - total: map["total"] as! Int, - currencies: (map["currencies"] as! [[String: Any]]).map { Currency.from(map: $0) } + total: map["total"] as? Int ?? 0, + currencies: (map["currencies"] as? [[String: Any]] ?? []).map { Currency.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Document.swift b/Sources/AppwriteModels/Document.swift index a1c0326..8bd3416 100644 --- a/Sources/AppwriteModels/Document.swift +++ b/Sources/AppwriteModels/Document.swift @@ -91,13 +91,13 @@ open class Document: Codable { public static func from(map: [String: Any] ) -> Document { return Document( - id: map["$id"] as! String, - collectionId: map["$collectionId"] as! String, - databaseId: map["$databaseId"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [String], - data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) + id: map["$id"] as? String ?? "", + collectionId: map["$collectionId"] as? String ?? "", + databaseId: map["$databaseId"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + permissions: map["$permissions"] as? [String] ?? [], + data: map["data"] != nil ? try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"]!, options: [])) : try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) ) } } diff --git a/Sources/AppwriteModels/DocumentList.swift b/Sources/AppwriteModels/DocumentList.swift index a129182..93fc41d 100644 --- a/Sources/AppwriteModels/DocumentList.swift +++ b/Sources/AppwriteModels/DocumentList.swift @@ -47,8 +47,8 @@ open class DocumentList: Codable { public static func from(map: [String: Any] ) -> DocumentList { return DocumentList( - total: map["total"] as! Int, - documents: (map["documents"] as! [[String: Any]]).map { Document.from(map: $0) } + total: map["total"] as? Int ?? 0, + documents: (map["documents"] as? [[String: Any]] ?? []).map { Document.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index 6e81532..59017e4 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -182,22 +182,22 @@ open class Execution: Codable { public static func from(map: [String: Any] ) -> Execution { return Execution( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [String], - functionId: map["functionId"] as! String, - trigger: map["trigger"] as! String, - status: map["status"] as! String, - requestMethod: map["requestMethod"] as! String, - requestPath: map["requestPath"] as! String, - requestHeaders: (map["requestHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, - responseStatusCode: map["responseStatusCode"] as! Int, - responseBody: map["responseBody"] as! String, - responseHeaders: (map["responseHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, - logs: map["logs"] as! String, - errors: map["errors"] as! String, - duration: map["duration"] as! Double, + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + permissions: map["$permissions"] as? [String] ?? [], + functionId: map["functionId"] as? String ?? "", + trigger: map["trigger"] as? String ?? "", + status: map["status"] as? String ?? "", + requestMethod: map["requestMethod"] as? String ?? "", + requestPath: map["requestPath"] as? String ?? "", + requestHeaders: (map["requestHeaders"] as? [[String: Any]] ?? []).map { Headers.from(map: $0) }, + responseStatusCode: map["responseStatusCode"] as? Int ?? 0, + responseBody: map["responseBody"] as? String ?? "", + responseHeaders: (map["responseHeaders"] as? [[String: Any]] ?? []).map { Headers.from(map: $0) }, + logs: map["logs"] as? String ?? "", + errors: map["errors"] as? String ?? "", + duration: map["duration"] as? Double ?? 0.0, scheduledAt: map["scheduledAt"] as? String ) } diff --git a/Sources/AppwriteModels/ExecutionList.swift b/Sources/AppwriteModels/ExecutionList.swift index 72d43a6..8b7559d 100644 --- a/Sources/AppwriteModels/ExecutionList.swift +++ b/Sources/AppwriteModels/ExecutionList.swift @@ -47,8 +47,8 @@ open class ExecutionList: Codable { public static func from(map: [String: Any] ) -> ExecutionList { return ExecutionList( - total: map["total"] as! Int, - executions: (map["executions"] as! [[String: Any]]).map { Execution.from(map: $0) } + total: map["total"] as? Int ?? 0, + executions: (map["executions"] as? [[String: Any]] ?? []).map { Execution.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/File.swift b/Sources/AppwriteModels/File.swift index 713c7ca..c68b701 100644 --- a/Sources/AppwriteModels/File.swift +++ b/Sources/AppwriteModels/File.swift @@ -128,17 +128,17 @@ open class File: Codable { public static func from(map: [String: Any] ) -> File { return File( - id: map["$id"] as! String, - bucketId: map["bucketId"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - permissions: map["$permissions"] as! [String], - name: map["name"] as! String, - signature: map["signature"] as! String, - mimeType: map["mimeType"] as! String, - sizeOriginal: map["sizeOriginal"] as! Int, - chunksTotal: map["chunksTotal"] as! Int, - chunksUploaded: map["chunksUploaded"] as! Int + id: map["$id"] as? String ?? "", + bucketId: map["bucketId"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + permissions: map["$permissions"] as? [String] ?? [], + name: map["name"] as? String ?? "", + signature: map["signature"] as? String ?? "", + mimeType: map["mimeType"] as? String ?? "", + sizeOriginal: map["sizeOriginal"] as? Int ?? 0, + chunksTotal: map["chunksTotal"] as? Int ?? 0, + chunksUploaded: map["chunksUploaded"] as? Int ?? 0 ) } } diff --git a/Sources/AppwriteModels/FileList.swift b/Sources/AppwriteModels/FileList.swift index bec7b76..a20ba7a 100644 --- a/Sources/AppwriteModels/FileList.swift +++ b/Sources/AppwriteModels/FileList.swift @@ -47,8 +47,8 @@ open class FileList: Codable { public static func from(map: [String: Any] ) -> FileList { return FileList( - total: map["total"] as! Int, - files: (map["files"] as! [[String: Any]]).map { File.from(map: $0) } + total: map["total"] as? Int ?? 0, + files: (map["files"] as? [[String: Any]] ?? []).map { File.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Headers.swift b/Sources/AppwriteModels/Headers.swift index ae468e5..c09d36e 100644 --- a/Sources/AppwriteModels/Headers.swift +++ b/Sources/AppwriteModels/Headers.swift @@ -47,8 +47,8 @@ open class Headers: Codable { public static func from(map: [String: Any] ) -> Headers { return Headers( - name: map["name"] as! String, - value: map["value"] as! String + name: map["name"] as? String ?? "", + value: map["value"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/Identity.swift b/Sources/AppwriteModels/Identity.swift index f93035d..3f211b3 100644 --- a/Sources/AppwriteModels/Identity.swift +++ b/Sources/AppwriteModels/Identity.swift @@ -119,16 +119,16 @@ open class Identity: Codable { public static func from(map: [String: Any] ) -> Identity { return Identity( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - userId: map["userId"] as! String, - provider: map["provider"] as! String, - providerUid: map["providerUid"] as! String, - providerEmail: map["providerEmail"] as! String, - providerAccessToken: map["providerAccessToken"] as! String, - providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as! String, - providerRefreshToken: map["providerRefreshToken"] as! String + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + userId: map["userId"] as? String ?? "", + provider: map["provider"] as? String ?? "", + providerUid: map["providerUid"] as? String ?? "", + providerEmail: map["providerEmail"] as? String ?? "", + providerAccessToken: map["providerAccessToken"] as? String ?? "", + providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as? String ?? "", + providerRefreshToken: map["providerRefreshToken"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/IdentityList.swift b/Sources/AppwriteModels/IdentityList.swift index 6065fad..8665233 100644 --- a/Sources/AppwriteModels/IdentityList.swift +++ b/Sources/AppwriteModels/IdentityList.swift @@ -47,8 +47,8 @@ open class IdentityList: Codable { public static func from(map: [String: Any] ) -> IdentityList { return IdentityList( - total: map["total"] as! Int, - identities: (map["identities"] as! [[String: Any]]).map { Identity.from(map: $0) } + total: map["total"] as? Int ?? 0, + identities: (map["identities"] as? [[String: Any]] ?? []).map { Identity.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Jwt.swift b/Sources/AppwriteModels/Jwt.swift index fd7fb49..65e28af 100644 --- a/Sources/AppwriteModels/Jwt.swift +++ b/Sources/AppwriteModels/Jwt.swift @@ -38,7 +38,7 @@ open class Jwt: Codable { public static func from(map: [String: Any] ) -> Jwt { return Jwt( - jwt: map["jwt"] as! String + jwt: map["jwt"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/Language.swift b/Sources/AppwriteModels/Language.swift index d1e1a15..cb01df3 100644 --- a/Sources/AppwriteModels/Language.swift +++ b/Sources/AppwriteModels/Language.swift @@ -56,9 +56,9 @@ open class Language: Codable { public static func from(map: [String: Any] ) -> Language { return Language( - name: map["name"] as! String, - code: map["code"] as! String, - nativeName: map["nativeName"] as! String + name: map["name"] as? String ?? "", + code: map["code"] as? String ?? "", + nativeName: map["nativeName"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/LanguageList.swift b/Sources/AppwriteModels/LanguageList.swift index 13c6e4a..46d99a2 100644 --- a/Sources/AppwriteModels/LanguageList.swift +++ b/Sources/AppwriteModels/LanguageList.swift @@ -47,8 +47,8 @@ open class LanguageList: Codable { public static func from(map: [String: Any] ) -> LanguageList { return LanguageList( - total: map["total"] as! Int, - languages: (map["languages"] as! [[String: Any]]).map { Language.from(map: $0) } + total: map["total"] as? Int ?? 0, + languages: (map["languages"] as? [[String: Any]] ?? []).map { Language.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Locale.swift b/Sources/AppwriteModels/Locale.swift index 4d034f4..406c6b4 100644 --- a/Sources/AppwriteModels/Locale.swift +++ b/Sources/AppwriteModels/Locale.swift @@ -92,13 +92,13 @@ open class Locale: Codable { public static func from(map: [String: Any] ) -> Locale { return Locale( - ip: map["ip"] as! String, - countryCode: map["countryCode"] as! String, - country: map["country"] as! String, - continentCode: map["continentCode"] as! String, - continent: map["continent"] as! String, - eu: map["eu"] as! Bool, - currency: map["currency"] as! String + ip: map["ip"] as? String ?? "", + countryCode: map["countryCode"] as? String ?? "", + country: map["country"] as? String ?? "", + continentCode: map["continentCode"] as? String ?? "", + continent: map["continent"] as? String ?? "", + eu: map["eu"] as? Bool ?? false, + currency: map["currency"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/LocaleCode.swift b/Sources/AppwriteModels/LocaleCode.swift index d2678bb..0b645f6 100644 --- a/Sources/AppwriteModels/LocaleCode.swift +++ b/Sources/AppwriteModels/LocaleCode.swift @@ -47,8 +47,8 @@ open class LocaleCode: Codable { public static func from(map: [String: Any] ) -> LocaleCode { return LocaleCode( - code: map["code"] as! String, - name: map["name"] as! String + code: map["code"] as? String ?? "", + name: map["name"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/LocaleCodeList.swift b/Sources/AppwriteModels/LocaleCodeList.swift index 5ef0653..c91540f 100644 --- a/Sources/AppwriteModels/LocaleCodeList.swift +++ b/Sources/AppwriteModels/LocaleCodeList.swift @@ -47,8 +47,8 @@ open class LocaleCodeList: Codable { public static func from(map: [String: Any] ) -> LocaleCodeList { return LocaleCodeList( - total: map["total"] as! Int, - localeCodes: (map["localeCodes"] as! [[String: Any]]).map { LocaleCode.from(map: $0) } + total: map["total"] as? Int ?? 0, + localeCodes: (map["localeCodes"] as? [[String: Any]] ?? []).map { LocaleCode.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Log.swift b/Sources/AppwriteModels/Log.swift index 16c27ef..b2b1216 100644 --- a/Sources/AppwriteModels/Log.swift +++ b/Sources/AppwriteModels/Log.swift @@ -218,27 +218,27 @@ open class Log: Codable { public static func from(map: [String: Any] ) -> Log { return Log( - event: map["event"] as! String, - userId: map["userId"] as! String, - userEmail: map["userEmail"] as! String, - userName: map["userName"] as! String, - mode: map["mode"] as! String, - ip: map["ip"] as! String, - time: map["time"] as! String, - osCode: map["osCode"] as! String, - osName: map["osName"] as! String, - osVersion: map["osVersion"] as! String, - clientType: map["clientType"] as! String, - clientCode: map["clientCode"] as! String, - clientName: map["clientName"] as! String, - clientVersion: map["clientVersion"] as! String, - clientEngine: map["clientEngine"] as! String, - clientEngineVersion: map["clientEngineVersion"] as! String, - deviceName: map["deviceName"] as! String, - deviceBrand: map["deviceBrand"] as! String, - deviceModel: map["deviceModel"] as! String, - countryCode: map["countryCode"] as! String, - countryName: map["countryName"] as! String + event: map["event"] as? String ?? "", + userId: map["userId"] as? String ?? "", + userEmail: map["userEmail"] as? String ?? "", + userName: map["userName"] as? String ?? "", + mode: map["mode"] as? String ?? "", + ip: map["ip"] as? String ?? "", + time: map["time"] as? String ?? "", + osCode: map["osCode"] as? String ?? "", + osName: map["osName"] as? String ?? "", + osVersion: map["osVersion"] as? String ?? "", + clientType: map["clientType"] as? String ?? "", + clientCode: map["clientCode"] as? String ?? "", + clientName: map["clientName"] as? String ?? "", + clientVersion: map["clientVersion"] as? String ?? "", + clientEngine: map["clientEngine"] as? String ?? "", + clientEngineVersion: map["clientEngineVersion"] as? String ?? "", + deviceName: map["deviceName"] as? String ?? "", + deviceBrand: map["deviceBrand"] as? String ?? "", + deviceModel: map["deviceModel"] as? String ?? "", + countryCode: map["countryCode"] as? String ?? "", + countryName: map["countryName"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/LogList.swift b/Sources/AppwriteModels/LogList.swift index 7ff2d07..8e40eb5 100644 --- a/Sources/AppwriteModels/LogList.swift +++ b/Sources/AppwriteModels/LogList.swift @@ -47,8 +47,8 @@ open class LogList: Codable { public static func from(map: [String: Any] ) -> LogList { return LogList( - total: map["total"] as! Int, - logs: (map["logs"] as! [[String: Any]]).map { Log.from(map: $0) } + total: map["total"] as? Int ?? 0, + logs: (map["logs"] as? [[String: Any]] ?? []).map { Log.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Membership.swift b/Sources/AppwriteModels/Membership.swift index 8d26766..1886000 100644 --- a/Sources/AppwriteModels/Membership.swift +++ b/Sources/AppwriteModels/Membership.swift @@ -146,19 +146,19 @@ open class Membership: Codable { public static func from(map: [String: Any] ) -> Membership { return Membership( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - userId: map["userId"] as! String, - userName: map["userName"] as! String, - userEmail: map["userEmail"] as! String, - teamId: map["teamId"] as! String, - teamName: map["teamName"] as! String, - invited: map["invited"] as! String, - joined: map["joined"] as! String, - confirm: map["confirm"] as! Bool, - mfa: map["mfa"] as! Bool, - roles: map["roles"] as! [String] + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + userId: map["userId"] as? String ?? "", + userName: map["userName"] as? String ?? "", + userEmail: map["userEmail"] as? String ?? "", + teamId: map["teamId"] as? String ?? "", + teamName: map["teamName"] as? String ?? "", + invited: map["invited"] as? String ?? "", + joined: map["joined"] as? String ?? "", + confirm: map["confirm"] as? Bool ?? false, + mfa: map["mfa"] as? Bool ?? false, + roles: map["roles"] as? [String] ?? [] ) } } diff --git a/Sources/AppwriteModels/MembershipList.swift b/Sources/AppwriteModels/MembershipList.swift index a7b0cd6..abaa881 100644 --- a/Sources/AppwriteModels/MembershipList.swift +++ b/Sources/AppwriteModels/MembershipList.swift @@ -47,8 +47,8 @@ open class MembershipList: Codable { public static func from(map: [String: Any] ) -> MembershipList { return MembershipList( - total: map["total"] as! Int, - memberships: (map["memberships"] as! [[String: Any]]).map { Membership.from(map: $0) } + total: map["total"] as? Int ?? 0, + memberships: (map["memberships"] as? [[String: Any]] ?? []).map { Membership.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/MfaChallenge.swift b/Sources/AppwriteModels/MfaChallenge.swift index c6b77a5..7550cce 100644 --- a/Sources/AppwriteModels/MfaChallenge.swift +++ b/Sources/AppwriteModels/MfaChallenge.swift @@ -65,10 +65,10 @@ open class MfaChallenge: Codable { public static func from(map: [String: Any] ) -> MfaChallenge { return MfaChallenge( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - userId: map["userId"] as! String, - expire: map["expire"] as! String + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + userId: map["userId"] as? String ?? "", + expire: map["expire"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/MfaFactors.swift b/Sources/AppwriteModels/MfaFactors.swift index 4291fab..9fb46b5 100644 --- a/Sources/AppwriteModels/MfaFactors.swift +++ b/Sources/AppwriteModels/MfaFactors.swift @@ -65,10 +65,10 @@ open class MfaFactors: Codable { public static func from(map: [String: Any] ) -> MfaFactors { return MfaFactors( - totp: map["totp"] as! Bool, - phone: map["phone"] as! Bool, - email: map["email"] as! Bool, - recoveryCode: map["recoveryCode"] as! Bool + totp: map["totp"] as? Bool ?? false, + phone: map["phone"] as? Bool ?? false, + email: map["email"] as? Bool ?? false, + recoveryCode: map["recoveryCode"] as? Bool ?? false ) } } diff --git a/Sources/AppwriteModels/MfaRecoveryCodes.swift b/Sources/AppwriteModels/MfaRecoveryCodes.swift index bd2968f..ac67444 100644 --- a/Sources/AppwriteModels/MfaRecoveryCodes.swift +++ b/Sources/AppwriteModels/MfaRecoveryCodes.swift @@ -38,7 +38,7 @@ open class MfaRecoveryCodes: Codable { public static func from(map: [String: Any] ) -> MfaRecoveryCodes { return MfaRecoveryCodes( - recoveryCodes: map["recoveryCodes"] as! [String] + recoveryCodes: map["recoveryCodes"] as? [String] ?? [] ) } } diff --git a/Sources/AppwriteModels/MfaType.swift b/Sources/AppwriteModels/MfaType.swift index 8646385..fdcd119 100644 --- a/Sources/AppwriteModels/MfaType.swift +++ b/Sources/AppwriteModels/MfaType.swift @@ -47,8 +47,8 @@ open class MfaType: Codable { public static func from(map: [String: Any] ) -> MfaType { return MfaType( - secret: map["secret"] as! String, - uri: map["uri"] as! String + secret: map["secret"] as? String ?? "", + uri: map["uri"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/Phone.swift b/Sources/AppwriteModels/Phone.swift index fc90d49..2510956 100644 --- a/Sources/AppwriteModels/Phone.swift +++ b/Sources/AppwriteModels/Phone.swift @@ -56,9 +56,9 @@ open class Phone: Codable { public static func from(map: [String: Any] ) -> Phone { return Phone( - code: map["code"] as! String, - countryCode: map["countryCode"] as! String, - countryName: map["countryName"] as! String + code: map["code"] as? String ?? "", + countryCode: map["countryCode"] as? String ?? "", + countryName: map["countryName"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/PhoneList.swift b/Sources/AppwriteModels/PhoneList.swift index 6f3bee3..adf5287 100644 --- a/Sources/AppwriteModels/PhoneList.swift +++ b/Sources/AppwriteModels/PhoneList.swift @@ -47,8 +47,8 @@ open class PhoneList: Codable { public static func from(map: [String: Any] ) -> PhoneList { return PhoneList( - total: map["total"] as! Int, - phones: (map["phones"] as! [[String: Any]]).map { Phone.from(map: $0) } + total: map["total"] as? Int ?? 0, + phones: (map["phones"] as? [[String: Any]] ?? []).map { Phone.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Preferences.swift b/Sources/AppwriteModels/Preferences.swift index 41f94e6..707297d 100644 --- a/Sources/AppwriteModels/Preferences.swift +++ b/Sources/AppwriteModels/Preferences.swift @@ -37,7 +37,7 @@ open class Preferences: Codable { public static func from(map: [String: Any] ) -> Preferences { return Preferences( - data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) + data: map["data"] != nil ? try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"]!, options: [])) : try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) ) } } diff --git a/Sources/AppwriteModels/Session.swift b/Sources/AppwriteModels/Session.swift index b5c25a6..1ee01a4 100644 --- a/Sources/AppwriteModels/Session.swift +++ b/Sources/AppwriteModels/Session.swift @@ -290,35 +290,35 @@ open class Session: Codable { public static func from(map: [String: Any] ) -> Session { return Session( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - userId: map["userId"] as! String, - expire: map["expire"] as! String, - provider: map["provider"] as! String, - providerUid: map["providerUid"] as! String, - providerAccessToken: map["providerAccessToken"] as! String, - providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as! String, - providerRefreshToken: map["providerRefreshToken"] as! String, - ip: map["ip"] as! String, - osCode: map["osCode"] as! String, - osName: map["osName"] as! String, - osVersion: map["osVersion"] as! String, - clientType: map["clientType"] as! String, - clientCode: map["clientCode"] as! String, - clientName: map["clientName"] as! String, - clientVersion: map["clientVersion"] as! String, - clientEngine: map["clientEngine"] as! String, - clientEngineVersion: map["clientEngineVersion"] as! String, - deviceName: map["deviceName"] as! String, - deviceBrand: map["deviceBrand"] as! String, - deviceModel: map["deviceModel"] as! String, - countryCode: map["countryCode"] as! String, - countryName: map["countryName"] as! String, - current: map["current"] as! Bool, - factors: map["factors"] as! [String], - secret: map["secret"] as! String, - mfaUpdatedAt: map["mfaUpdatedAt"] as! String + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + userId: map["userId"] as? String ?? "", + expire: map["expire"] as? String ?? "", + provider: map["provider"] as? String ?? "", + providerUid: map["providerUid"] as? String ?? "", + providerAccessToken: map["providerAccessToken"] as? String ?? "", + providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as? String ?? "", + providerRefreshToken: map["providerRefreshToken"] as? String ?? "", + ip: map["ip"] as? String ?? "", + osCode: map["osCode"] as? String ?? "", + osName: map["osName"] as? String ?? "", + osVersion: map["osVersion"] as? String ?? "", + clientType: map["clientType"] as? String ?? "", + clientCode: map["clientCode"] as? String ?? "", + clientName: map["clientName"] as? String ?? "", + clientVersion: map["clientVersion"] as? String ?? "", + clientEngine: map["clientEngine"] as? String ?? "", + clientEngineVersion: map["clientEngineVersion"] as? String ?? "", + deviceName: map["deviceName"] as? String ?? "", + deviceBrand: map["deviceBrand"] as? String ?? "", + deviceModel: map["deviceModel"] as? String ?? "", + countryCode: map["countryCode"] as? String ?? "", + countryName: map["countryName"] as? String ?? "", + current: map["current"] as? Bool ?? false, + factors: map["factors"] as? [String] ?? [], + secret: map["secret"] as? String ?? "", + mfaUpdatedAt: map["mfaUpdatedAt"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/SessionList.swift b/Sources/AppwriteModels/SessionList.swift index 13b6b3d..2dd724b 100644 --- a/Sources/AppwriteModels/SessionList.swift +++ b/Sources/AppwriteModels/SessionList.swift @@ -47,8 +47,8 @@ open class SessionList: Codable { public static func from(map: [String: Any] ) -> SessionList { return SessionList( - total: map["total"] as! Int, - sessions: (map["sessions"] as! [[String: Any]]).map { Session.from(map: $0) } + total: map["total"] as? Int ?? 0, + sessions: (map["sessions"] as? [[String: Any]] ?? []).map { Session.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Subscriber.swift b/Sources/AppwriteModels/Subscriber.swift index ad6fa5d..f0a399c 100644 --- a/Sources/AppwriteModels/Subscriber.swift +++ b/Sources/AppwriteModels/Subscriber.swift @@ -110,15 +110,15 @@ open class Subscriber: Codable { public static func from(map: [String: Any] ) -> Subscriber { return Subscriber( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - targetId: map["targetId"] as! String, - target: Target.from(map: map["target"] as! [String: Any]), - userId: map["userId"] as! String, - userName: map["userName"] as! String, - topicId: map["topicId"] as! String, - providerType: map["providerType"] as! String + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + targetId: map["targetId"] as? String ?? "", + target: map["target"] != nil ? Target.from(map: map["target"] as! [String: Any]) : Target(), + userId: map["userId"] as? String ?? "", + userName: map["userName"] as? String ?? "", + topicId: map["topicId"] as? String ?? "", + providerType: map["providerType"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/Target.swift b/Sources/AppwriteModels/Target.swift index 0581a61..6e34abd 100644 --- a/Sources/AppwriteModels/Target.swift +++ b/Sources/AppwriteModels/Target.swift @@ -110,15 +110,15 @@ open class Target: Codable { public static func from(map: [String: Any] ) -> Target { return Target( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - name: map["name"] as! String, - userId: map["userId"] as! String, + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + name: map["name"] as? String ?? "", + userId: map["userId"] as? String ?? "", providerId: map["providerId"] as? String, - providerType: map["providerType"] as! String, - identifier: map["identifier"] as! String, - expired: map["expired"] as! Bool + providerType: map["providerType"] as? String ?? "", + identifier: map["identifier"] as? String ?? "", + expired: map["expired"] as? Bool ?? false ) } } diff --git a/Sources/AppwriteModels/Team.swift b/Sources/AppwriteModels/Team.swift index 9ca7307..052debe 100644 --- a/Sources/AppwriteModels/Team.swift +++ b/Sources/AppwriteModels/Team.swift @@ -83,12 +83,12 @@ open class Team: Codable { public static func from(map: [String: Any] ) -> Team { return Team( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - name: map["name"] as! String, - total: map["total"] as! Int, - prefs: Preferences.from(map: map["prefs"] as! [String: Any]) + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + name: map["name"] as? String ?? "", + total: map["total"] as? Int ?? 0, + prefs: map["prefs"] != nil ? Preferences.from(map: map["prefs"] as! [String: Any]) : Preferences() ) } } diff --git a/Sources/AppwriteModels/TeamList.swift b/Sources/AppwriteModels/TeamList.swift index 384d9f6..aaa02af 100644 --- a/Sources/AppwriteModels/TeamList.swift +++ b/Sources/AppwriteModels/TeamList.swift @@ -47,8 +47,8 @@ open class TeamList: Codable { public static func from(map: [String: Any] ) -> TeamList { return TeamList( - total: map["total"] as! Int, - teams: (map["teams"] as! [[String: Any]]).map { Team.from(map: $0) } + total: map["total"] as? Int ?? 0, + teams: (map["teams"] as? [[String: Any]] ?? []).map { Team.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Token.swift b/Sources/AppwriteModels/Token.swift index f832402..1ded551 100644 --- a/Sources/AppwriteModels/Token.swift +++ b/Sources/AppwriteModels/Token.swift @@ -83,12 +83,12 @@ open class Token: Codable { public static func from(map: [String: Any] ) -> Token { return Token( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - userId: map["userId"] as! String, - secret: map["secret"] as! String, - expire: map["expire"] as! String, - phrase: map["phrase"] as! String + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + userId: map["userId"] as? String ?? "", + secret: map["secret"] as? String ?? "", + expire: map["expire"] as? String ?? "", + phrase: map["phrase"] as? String ?? "" ) } } diff --git a/Sources/AppwriteModels/User.swift b/Sources/AppwriteModels/User.swift index 6e972d3..a519c76 100644 --- a/Sources/AppwriteModels/User.swift +++ b/Sources/AppwriteModels/User.swift @@ -200,25 +200,25 @@ open class User: Codable { public static func from(map: [String: Any] ) -> User { return User( - id: map["$id"] as! String, - createdAt: map["$createdAt"] as! String, - updatedAt: map["$updatedAt"] as! String, - name: map["name"] as! String, + id: map["$id"] as? String ?? "", + createdAt: map["$createdAt"] as? String ?? "", + updatedAt: map["$updatedAt"] as? String ?? "", + name: map["name"] as? String ?? "", password: map["password"] as? String, hash: map["hash"] as? String, hashOptions: map["hashOptions"] as? [String: AnyCodable], - registration: map["registration"] as! String, - status: map["status"] as! Bool, - labels: map["labels"] as! [String], - passwordUpdate: map["passwordUpdate"] as! String, - email: map["email"] as! String, - phone: map["phone"] as! String, - emailVerification: map["emailVerification"] as! Bool, - phoneVerification: map["phoneVerification"] as! Bool, - mfa: map["mfa"] as! Bool, - prefs: Preferences.from(map: map["prefs"] as! [String: Any]), - targets: (map["targets"] as! [[String: Any]]).map { Target.from(map: $0) }, - accessedAt: map["accessedAt"] as! String + registration: map["registration"] as? String ?? "", + status: map["status"] as? Bool ?? false, + labels: map["labels"] as? [String] ?? [], + passwordUpdate: map["passwordUpdate"] as? String ?? "", + email: map["email"] as? String ?? "", + phone: map["phone"] as? String ?? "", + emailVerification: map["emailVerification"] as? Bool ?? false, + phoneVerification: map["phoneVerification"] as? Bool ?? false, + mfa: map["mfa"] as? Bool ?? false, + prefs: map["prefs"] != nil ? Preferences.from(map: map["prefs"] as! [String: Any]) : Preferences(), + targets: (map["targets"] as? [[String: Any]] ?? []).map { Target.from(map: $0) }, + accessedAt: map["accessedAt"] as? String ?? "" ) } } diff --git a/docs/examples/databases/create-documents.md b/docs/examples/databases/create-documents.md new file mode 100644 index 0000000..b47247a --- /dev/null +++ b/docs/examples/databases/create-documents.md @@ -0,0 +1,14 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setKey("") // + +let databases = Databases(client) + +let documentList = try await databases.createDocuments( + databaseId: "", + collectionId: "", + documents: [] +) + From b1d2a6b016d143f186ad7869e3a7a312d0e9b793 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Jun 2025 06:00:50 +0000 Subject: [PATCH 2/3] chore: regenerate sdk --- Sources/Appwrite/Services/Databases.swift | 76 --------------------- docs/examples/databases/create-documents.md | 14 ---- 2 files changed, 90 deletions(-) delete mode 100644 docs/examples/databases/create-documents.md diff --git a/Sources/Appwrite/Services/Databases.swift b/Sources/Appwrite/Services/Databases.swift index 017c1c9..fc44585 100644 --- a/Sources/Appwrite/Services/Databases.swift +++ b/Sources/Appwrite/Services/Databases.swift @@ -150,82 +150,6 @@ open class Databases: Service { ) } - /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// - /// Create new Documents. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - /// - /// @param String databaseId - /// @param String collectionId - /// @param [Any] documents - /// @throws Exception - /// @return array - /// - open func createDocuments( - databaseId: String, - collectionId: String, - documents: [Any], - nestedType: T.Type - ) async throws -> AppwriteModels.DocumentList { - let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents" - .replacingOccurrences(of: "{databaseId}", with: databaseId) - .replacingOccurrences(of: "{collectionId}", with: collectionId) - - let apiParams: [String: Any?] = [ - "documents": documents - ] - - let apiHeaders: [String: String] = [ - "content-type": "application/json" - ] - - let converter: (Any) -> AppwriteModels.DocumentList = { response in - return AppwriteModels.DocumentList.from(map: response as! [String: Any]) - } - - return try await client.call( - method: "POST", - path: apiPath, - headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// **WARNING: Experimental Feature** - This endpoint is experimental and not - /// yet officially supported. It may be subject to breaking changes or removal - /// in future versions. - /// - /// Create new Documents. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - /// - /// @param String databaseId - /// @param String collectionId - /// @param [Any] documents - /// @throws Exception - /// @return array - /// - open func createDocuments( - databaseId: String, - collectionId: String, - documents: [Any] - ) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> { - return try await createDocuments( - databaseId: databaseId, - collectionId: collectionId, - documents: documents, - nestedType: [String: AnyCodable].self - ) - } - /// /// Get a document by its unique ID. This endpoint response returns a JSON /// object with the document data. diff --git a/docs/examples/databases/create-documents.md b/docs/examples/databases/create-documents.md deleted file mode 100644 index b47247a..0000000 --- a/docs/examples/databases/create-documents.md +++ /dev/null @@ -1,14 +0,0 @@ -import Appwrite - -let client = Client() - .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint - .setKey("") // - -let databases = Databases(client) - -let documentList = try await databases.createDocuments( - databaseId: "", - collectionId: "", - documents: [] -) - From 86d394b3db4321586b2953c23ee8c748cb7232fd Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Jun 2025 06:44:42 +0000 Subject: [PATCH 3/3] chore: regenerate sdk --- Sources/AppwriteModels/AlgoArgon2.swift | 8 +-- Sources/AppwriteModels/AlgoBcrypt.swift | 2 +- Sources/AppwriteModels/AlgoMd5.swift | 2 +- Sources/AppwriteModels/AlgoPhpass.swift | 2 +- Sources/AppwriteModels/AlgoScrypt.swift | 10 ++-- .../AppwriteModels/AlgoScryptModified.swift | 8 +-- Sources/AppwriteModels/AlgoSha.swift | 2 +- Sources/AppwriteModels/Continent.swift | 4 +- Sources/AppwriteModels/ContinentList.swift | 4 +- Sources/AppwriteModels/Country.swift | 4 +- Sources/AppwriteModels/CountryList.swift | 4 +- Sources/AppwriteModels/Currency.swift | 14 ++--- Sources/AppwriteModels/CurrencyList.swift | 4 +- Sources/AppwriteModels/Document.swift | 2 +- Sources/AppwriteModels/DocumentList.swift | 4 +- Sources/AppwriteModels/Execution.swift | 32 +++++----- Sources/AppwriteModels/ExecutionList.swift | 4 +- Sources/AppwriteModels/File.swift | 22 +++---- Sources/AppwriteModels/FileList.swift | 4 +- Sources/AppwriteModels/Headers.swift | 4 +- Sources/AppwriteModels/Identity.swift | 20 +++---- Sources/AppwriteModels/IdentityList.swift | 4 +- Sources/AppwriteModels/Jwt.swift | 2 +- Sources/AppwriteModels/Language.swift | 6 +- Sources/AppwriteModels/LanguageList.swift | 4 +- Sources/AppwriteModels/Locale.swift | 14 ++--- Sources/AppwriteModels/LocaleCode.swift | 4 +- Sources/AppwriteModels/LocaleCodeList.swift | 4 +- Sources/AppwriteModels/Log.swift | 42 +++++++------- Sources/AppwriteModels/LogList.swift | 4 +- Sources/AppwriteModels/Membership.swift | 26 ++++----- Sources/AppwriteModels/MembershipList.swift | 4 +- Sources/AppwriteModels/MfaChallenge.swift | 8 +-- Sources/AppwriteModels/MfaFactors.swift | 8 +-- Sources/AppwriteModels/MfaRecoveryCodes.swift | 2 +- Sources/AppwriteModels/MfaType.swift | 4 +- Sources/AppwriteModels/Phone.swift | 6 +- Sources/AppwriteModels/PhoneList.swift | 4 +- Sources/AppwriteModels/Preferences.swift | 2 +- Sources/AppwriteModels/Session.swift | 58 +++++++++---------- Sources/AppwriteModels/SessionList.swift | 4 +- Sources/AppwriteModels/Subscriber.swift | 18 +++--- Sources/AppwriteModels/Target.swift | 16 ++--- Sources/AppwriteModels/Team.swift | 12 ++-- Sources/AppwriteModels/TeamList.swift | 4 +- Sources/AppwriteModels/Token.swift | 12 ++-- Sources/AppwriteModels/User.swift | 32 +++++----- 47 files changed, 232 insertions(+), 232 deletions(-) diff --git a/Sources/AppwriteModels/AlgoArgon2.swift b/Sources/AppwriteModels/AlgoArgon2.swift index 5411998..fd88955 100644 --- a/Sources/AppwriteModels/AlgoArgon2.swift +++ b/Sources/AppwriteModels/AlgoArgon2.swift @@ -65,10 +65,10 @@ open class AlgoArgon2: Codable { public static func from(map: [String: Any] ) -> AlgoArgon2 { return AlgoArgon2( - type: map["type"] as? String ?? "", - memoryCost: map["memoryCost"] as? Int ?? 0, - timeCost: map["timeCost"] as? Int ?? 0, - threads: map["threads"] as? Int ?? 0 + type: map["type"] as! String, + memoryCost: map["memoryCost"] as! Int, + timeCost: map["timeCost"] as! Int, + threads: map["threads"] as! Int ) } } diff --git a/Sources/AppwriteModels/AlgoBcrypt.swift b/Sources/AppwriteModels/AlgoBcrypt.swift index 3bd7061..b34095d 100644 --- a/Sources/AppwriteModels/AlgoBcrypt.swift +++ b/Sources/AppwriteModels/AlgoBcrypt.swift @@ -38,7 +38,7 @@ open class AlgoBcrypt: Codable { public static func from(map: [String: Any] ) -> AlgoBcrypt { return AlgoBcrypt( - type: map["type"] as? String ?? "" + type: map["type"] as! String ) } } diff --git a/Sources/AppwriteModels/AlgoMd5.swift b/Sources/AppwriteModels/AlgoMd5.swift index 2d8b6f5..72fbb8d 100644 --- a/Sources/AppwriteModels/AlgoMd5.swift +++ b/Sources/AppwriteModels/AlgoMd5.swift @@ -38,7 +38,7 @@ open class AlgoMd5: Codable { public static func from(map: [String: Any] ) -> AlgoMd5 { return AlgoMd5( - type: map["type"] as? String ?? "" + type: map["type"] as! String ) } } diff --git a/Sources/AppwriteModels/AlgoPhpass.swift b/Sources/AppwriteModels/AlgoPhpass.swift index 20d70c1..7bd0c99 100644 --- a/Sources/AppwriteModels/AlgoPhpass.swift +++ b/Sources/AppwriteModels/AlgoPhpass.swift @@ -38,7 +38,7 @@ open class AlgoPhpass: Codable { public static func from(map: [String: Any] ) -> AlgoPhpass { return AlgoPhpass( - type: map["type"] as? String ?? "" + type: map["type"] as! String ) } } diff --git a/Sources/AppwriteModels/AlgoScrypt.swift b/Sources/AppwriteModels/AlgoScrypt.swift index 21500cb..03ce541 100644 --- a/Sources/AppwriteModels/AlgoScrypt.swift +++ b/Sources/AppwriteModels/AlgoScrypt.swift @@ -74,11 +74,11 @@ open class AlgoScrypt: Codable { public static func from(map: [String: Any] ) -> AlgoScrypt { return AlgoScrypt( - type: map["type"] as? String ?? "", - costCpu: map["costCpu"] as? Int ?? 0, - costMemory: map["costMemory"] as? Int ?? 0, - costParallel: map["costParallel"] as? Int ?? 0, - length: map["length"] as? Int ?? 0 + type: map["type"] as! String, + costCpu: map["costCpu"] as! Int, + costMemory: map["costMemory"] as! Int, + costParallel: map["costParallel"] as! Int, + length: map["length"] as! Int ) } } diff --git a/Sources/AppwriteModels/AlgoScryptModified.swift b/Sources/AppwriteModels/AlgoScryptModified.swift index bede143..0b2fa4e 100644 --- a/Sources/AppwriteModels/AlgoScryptModified.swift +++ b/Sources/AppwriteModels/AlgoScryptModified.swift @@ -65,10 +65,10 @@ open class AlgoScryptModified: Codable { public static func from(map: [String: Any] ) -> AlgoScryptModified { return AlgoScryptModified( - type: map["type"] as? String ?? "", - salt: map["salt"] as? String ?? "", - saltSeparator: map["saltSeparator"] as? String ?? "", - signerKey: map["signerKey"] as? String ?? "" + type: map["type"] as! String, + salt: map["salt"] as! String, + saltSeparator: map["saltSeparator"] as! String, + signerKey: map["signerKey"] as! String ) } } diff --git a/Sources/AppwriteModels/AlgoSha.swift b/Sources/AppwriteModels/AlgoSha.swift index 6a3be42..ffc0e05 100644 --- a/Sources/AppwriteModels/AlgoSha.swift +++ b/Sources/AppwriteModels/AlgoSha.swift @@ -38,7 +38,7 @@ open class AlgoSha: Codable { public static func from(map: [String: Any] ) -> AlgoSha { return AlgoSha( - type: map["type"] as? String ?? "" + type: map["type"] as! String ) } } diff --git a/Sources/AppwriteModels/Continent.swift b/Sources/AppwriteModels/Continent.swift index 64836ae..b8994d9 100644 --- a/Sources/AppwriteModels/Continent.swift +++ b/Sources/AppwriteModels/Continent.swift @@ -47,8 +47,8 @@ open class Continent: Codable { public static func from(map: [String: Any] ) -> Continent { return Continent( - name: map["name"] as? String ?? "", - code: map["code"] as? String ?? "" + name: map["name"] as! String, + code: map["code"] as! String ) } } diff --git a/Sources/AppwriteModels/ContinentList.swift b/Sources/AppwriteModels/ContinentList.swift index a924595..fa9a90f 100644 --- a/Sources/AppwriteModels/ContinentList.swift +++ b/Sources/AppwriteModels/ContinentList.swift @@ -47,8 +47,8 @@ open class ContinentList: Codable { public static func from(map: [String: Any] ) -> ContinentList { return ContinentList( - total: map["total"] as? Int ?? 0, - continents: (map["continents"] as? [[String: Any]] ?? []).map { Continent.from(map: $0) } + total: map["total"] as! Int, + continents: (map["continents"] as! [[String: Any]]).map { Continent.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Country.swift b/Sources/AppwriteModels/Country.swift index 353da83..c24f7e9 100644 --- a/Sources/AppwriteModels/Country.swift +++ b/Sources/AppwriteModels/Country.swift @@ -47,8 +47,8 @@ open class Country: Codable { public static func from(map: [String: Any] ) -> Country { return Country( - name: map["name"] as? String ?? "", - code: map["code"] as? String ?? "" + name: map["name"] as! String, + code: map["code"] as! String ) } } diff --git a/Sources/AppwriteModels/CountryList.swift b/Sources/AppwriteModels/CountryList.swift index c6526fa..865cc19 100644 --- a/Sources/AppwriteModels/CountryList.swift +++ b/Sources/AppwriteModels/CountryList.swift @@ -47,8 +47,8 @@ open class CountryList: Codable { public static func from(map: [String: Any] ) -> CountryList { return CountryList( - total: map["total"] as? Int ?? 0, - countries: (map["countries"] as? [[String: Any]] ?? []).map { Country.from(map: $0) } + total: map["total"] as! Int, + countries: (map["countries"] as! [[String: Any]]).map { Country.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Currency.swift b/Sources/AppwriteModels/Currency.swift index dc67525..320337b 100644 --- a/Sources/AppwriteModels/Currency.swift +++ b/Sources/AppwriteModels/Currency.swift @@ -92,13 +92,13 @@ open class Currency: Codable { public static func from(map: [String: Any] ) -> Currency { return Currency( - symbol: map["symbol"] as? String ?? "", - name: map["name"] as? String ?? "", - symbolNative: map["symbolNative"] as? String ?? "", - decimalDigits: map["decimalDigits"] as? Int ?? 0, - rounding: map["rounding"] as? Double ?? 0.0, - code: map["code"] as? String ?? "", - namePlural: map["namePlural"] as? String ?? "" + symbol: map["symbol"] as! String, + name: map["name"] as! String, + symbolNative: map["symbolNative"] as! String, + decimalDigits: map["decimalDigits"] as! Int, + rounding: map["rounding"] as! Double, + code: map["code"] as! String, + namePlural: map["namePlural"] as! String ) } } diff --git a/Sources/AppwriteModels/CurrencyList.swift b/Sources/AppwriteModels/CurrencyList.swift index 6c81124..1e0dff9 100644 --- a/Sources/AppwriteModels/CurrencyList.swift +++ b/Sources/AppwriteModels/CurrencyList.swift @@ -47,8 +47,8 @@ open class CurrencyList: Codable { public static func from(map: [String: Any] ) -> CurrencyList { return CurrencyList( - total: map["total"] as? Int ?? 0, - currencies: (map["currencies"] as? [[String: Any]] ?? []).map { Currency.from(map: $0) } + total: map["total"] as! Int, + currencies: (map["currencies"] as! [[String: Any]]).map { Currency.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Document.swift b/Sources/AppwriteModels/Document.swift index 8bd3416..744a03e 100644 --- a/Sources/AppwriteModels/Document.swift +++ b/Sources/AppwriteModels/Document.swift @@ -97,7 +97,7 @@ open class Document: Codable { createdAt: map["$createdAt"] as? String ?? "", updatedAt: map["$updatedAt"] as? String ?? "", permissions: map["$permissions"] as? [String] ?? [], - data: map["data"] != nil ? try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"]!, options: [])) : try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) + data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) ) } } diff --git a/Sources/AppwriteModels/DocumentList.swift b/Sources/AppwriteModels/DocumentList.swift index 93fc41d..a129182 100644 --- a/Sources/AppwriteModels/DocumentList.swift +++ b/Sources/AppwriteModels/DocumentList.swift @@ -47,8 +47,8 @@ open class DocumentList: Codable { public static func from(map: [String: Any] ) -> DocumentList { return DocumentList( - total: map["total"] as? Int ?? 0, - documents: (map["documents"] as? [[String: Any]] ?? []).map { Document.from(map: $0) } + total: map["total"] as! Int, + documents: (map["documents"] as! [[String: Any]]).map { Document.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Execution.swift b/Sources/AppwriteModels/Execution.swift index 59017e4..6e81532 100644 --- a/Sources/AppwriteModels/Execution.swift +++ b/Sources/AppwriteModels/Execution.swift @@ -182,22 +182,22 @@ open class Execution: Codable { public static func from(map: [String: Any] ) -> Execution { return Execution( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - permissions: map["$permissions"] as? [String] ?? [], - functionId: map["functionId"] as? String ?? "", - trigger: map["trigger"] as? String ?? "", - status: map["status"] as? String ?? "", - requestMethod: map["requestMethod"] as? String ?? "", - requestPath: map["requestPath"] as? String ?? "", - requestHeaders: (map["requestHeaders"] as? [[String: Any]] ?? []).map { Headers.from(map: $0) }, - responseStatusCode: map["responseStatusCode"] as? Int ?? 0, - responseBody: map["responseBody"] as? String ?? "", - responseHeaders: (map["responseHeaders"] as? [[String: Any]] ?? []).map { Headers.from(map: $0) }, - logs: map["logs"] as? String ?? "", - errors: map["errors"] as? String ?? "", - duration: map["duration"] as? Double ?? 0.0, + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + permissions: map["$permissions"] as! [String], + functionId: map["functionId"] as! String, + trigger: map["trigger"] as! String, + status: map["status"] as! String, + requestMethod: map["requestMethod"] as! String, + requestPath: map["requestPath"] as! String, + requestHeaders: (map["requestHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, + responseStatusCode: map["responseStatusCode"] as! Int, + responseBody: map["responseBody"] as! String, + responseHeaders: (map["responseHeaders"] as! [[String: Any]]).map { Headers.from(map: $0) }, + logs: map["logs"] as! String, + errors: map["errors"] as! String, + duration: map["duration"] as! Double, scheduledAt: map["scheduledAt"] as? String ) } diff --git a/Sources/AppwriteModels/ExecutionList.swift b/Sources/AppwriteModels/ExecutionList.swift index 8b7559d..72d43a6 100644 --- a/Sources/AppwriteModels/ExecutionList.swift +++ b/Sources/AppwriteModels/ExecutionList.swift @@ -47,8 +47,8 @@ open class ExecutionList: Codable { public static func from(map: [String: Any] ) -> ExecutionList { return ExecutionList( - total: map["total"] as? Int ?? 0, - executions: (map["executions"] as? [[String: Any]] ?? []).map { Execution.from(map: $0) } + total: map["total"] as! Int, + executions: (map["executions"] as! [[String: Any]]).map { Execution.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/File.swift b/Sources/AppwriteModels/File.swift index c68b701..713c7ca 100644 --- a/Sources/AppwriteModels/File.swift +++ b/Sources/AppwriteModels/File.swift @@ -128,17 +128,17 @@ open class File: Codable { public static func from(map: [String: Any] ) -> File { return File( - id: map["$id"] as? String ?? "", - bucketId: map["bucketId"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - permissions: map["$permissions"] as? [String] ?? [], - name: map["name"] as? String ?? "", - signature: map["signature"] as? String ?? "", - mimeType: map["mimeType"] as? String ?? "", - sizeOriginal: map["sizeOriginal"] as? Int ?? 0, - chunksTotal: map["chunksTotal"] as? Int ?? 0, - chunksUploaded: map["chunksUploaded"] as? Int ?? 0 + id: map["$id"] as! String, + bucketId: map["bucketId"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + permissions: map["$permissions"] as! [String], + name: map["name"] as! String, + signature: map["signature"] as! String, + mimeType: map["mimeType"] as! String, + sizeOriginal: map["sizeOriginal"] as! Int, + chunksTotal: map["chunksTotal"] as! Int, + chunksUploaded: map["chunksUploaded"] as! Int ) } } diff --git a/Sources/AppwriteModels/FileList.swift b/Sources/AppwriteModels/FileList.swift index a20ba7a..bec7b76 100644 --- a/Sources/AppwriteModels/FileList.swift +++ b/Sources/AppwriteModels/FileList.swift @@ -47,8 +47,8 @@ open class FileList: Codable { public static func from(map: [String: Any] ) -> FileList { return FileList( - total: map["total"] as? Int ?? 0, - files: (map["files"] as? [[String: Any]] ?? []).map { File.from(map: $0) } + total: map["total"] as! Int, + files: (map["files"] as! [[String: Any]]).map { File.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Headers.swift b/Sources/AppwriteModels/Headers.swift index c09d36e..ae468e5 100644 --- a/Sources/AppwriteModels/Headers.swift +++ b/Sources/AppwriteModels/Headers.swift @@ -47,8 +47,8 @@ open class Headers: Codable { public static func from(map: [String: Any] ) -> Headers { return Headers( - name: map["name"] as? String ?? "", - value: map["value"] as? String ?? "" + name: map["name"] as! String, + value: map["value"] as! String ) } } diff --git a/Sources/AppwriteModels/Identity.swift b/Sources/AppwriteModels/Identity.swift index 3f211b3..f93035d 100644 --- a/Sources/AppwriteModels/Identity.swift +++ b/Sources/AppwriteModels/Identity.swift @@ -119,16 +119,16 @@ open class Identity: Codable { public static func from(map: [String: Any] ) -> Identity { return Identity( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - userId: map["userId"] as? String ?? "", - provider: map["provider"] as? String ?? "", - providerUid: map["providerUid"] as? String ?? "", - providerEmail: map["providerEmail"] as? String ?? "", - providerAccessToken: map["providerAccessToken"] as? String ?? "", - providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as? String ?? "", - providerRefreshToken: map["providerRefreshToken"] as? String ?? "" + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + userId: map["userId"] as! String, + provider: map["provider"] as! String, + providerUid: map["providerUid"] as! String, + providerEmail: map["providerEmail"] as! String, + providerAccessToken: map["providerAccessToken"] as! String, + providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as! String, + providerRefreshToken: map["providerRefreshToken"] as! String ) } } diff --git a/Sources/AppwriteModels/IdentityList.swift b/Sources/AppwriteModels/IdentityList.swift index 8665233..6065fad 100644 --- a/Sources/AppwriteModels/IdentityList.swift +++ b/Sources/AppwriteModels/IdentityList.swift @@ -47,8 +47,8 @@ open class IdentityList: Codable { public static func from(map: [String: Any] ) -> IdentityList { return IdentityList( - total: map["total"] as? Int ?? 0, - identities: (map["identities"] as? [[String: Any]] ?? []).map { Identity.from(map: $0) } + total: map["total"] as! Int, + identities: (map["identities"] as! [[String: Any]]).map { Identity.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Jwt.swift b/Sources/AppwriteModels/Jwt.swift index 65e28af..fd7fb49 100644 --- a/Sources/AppwriteModels/Jwt.swift +++ b/Sources/AppwriteModels/Jwt.swift @@ -38,7 +38,7 @@ open class Jwt: Codable { public static func from(map: [String: Any] ) -> Jwt { return Jwt( - jwt: map["jwt"] as? String ?? "" + jwt: map["jwt"] as! String ) } } diff --git a/Sources/AppwriteModels/Language.swift b/Sources/AppwriteModels/Language.swift index cb01df3..d1e1a15 100644 --- a/Sources/AppwriteModels/Language.swift +++ b/Sources/AppwriteModels/Language.swift @@ -56,9 +56,9 @@ open class Language: Codable { public static func from(map: [String: Any] ) -> Language { return Language( - name: map["name"] as? String ?? "", - code: map["code"] as? String ?? "", - nativeName: map["nativeName"] as? String ?? "" + name: map["name"] as! String, + code: map["code"] as! String, + nativeName: map["nativeName"] as! String ) } } diff --git a/Sources/AppwriteModels/LanguageList.swift b/Sources/AppwriteModels/LanguageList.swift index 46d99a2..13c6e4a 100644 --- a/Sources/AppwriteModels/LanguageList.swift +++ b/Sources/AppwriteModels/LanguageList.swift @@ -47,8 +47,8 @@ open class LanguageList: Codable { public static func from(map: [String: Any] ) -> LanguageList { return LanguageList( - total: map["total"] as? Int ?? 0, - languages: (map["languages"] as? [[String: Any]] ?? []).map { Language.from(map: $0) } + total: map["total"] as! Int, + languages: (map["languages"] as! [[String: Any]]).map { Language.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Locale.swift b/Sources/AppwriteModels/Locale.swift index 406c6b4..4d034f4 100644 --- a/Sources/AppwriteModels/Locale.swift +++ b/Sources/AppwriteModels/Locale.swift @@ -92,13 +92,13 @@ open class Locale: Codable { public static func from(map: [String: Any] ) -> Locale { return Locale( - ip: map["ip"] as? String ?? "", - countryCode: map["countryCode"] as? String ?? "", - country: map["country"] as? String ?? "", - continentCode: map["continentCode"] as? String ?? "", - continent: map["continent"] as? String ?? "", - eu: map["eu"] as? Bool ?? false, - currency: map["currency"] as? String ?? "" + ip: map["ip"] as! String, + countryCode: map["countryCode"] as! String, + country: map["country"] as! String, + continentCode: map["continentCode"] as! String, + continent: map["continent"] as! String, + eu: map["eu"] as! Bool, + currency: map["currency"] as! String ) } } diff --git a/Sources/AppwriteModels/LocaleCode.swift b/Sources/AppwriteModels/LocaleCode.swift index 0b645f6..d2678bb 100644 --- a/Sources/AppwriteModels/LocaleCode.swift +++ b/Sources/AppwriteModels/LocaleCode.swift @@ -47,8 +47,8 @@ open class LocaleCode: Codable { public static func from(map: [String: Any] ) -> LocaleCode { return LocaleCode( - code: map["code"] as? String ?? "", - name: map["name"] as? String ?? "" + code: map["code"] as! String, + name: map["name"] as! String ) } } diff --git a/Sources/AppwriteModels/LocaleCodeList.swift b/Sources/AppwriteModels/LocaleCodeList.swift index c91540f..5ef0653 100644 --- a/Sources/AppwriteModels/LocaleCodeList.swift +++ b/Sources/AppwriteModels/LocaleCodeList.swift @@ -47,8 +47,8 @@ open class LocaleCodeList: Codable { public static func from(map: [String: Any] ) -> LocaleCodeList { return LocaleCodeList( - total: map["total"] as? Int ?? 0, - localeCodes: (map["localeCodes"] as? [[String: Any]] ?? []).map { LocaleCode.from(map: $0) } + total: map["total"] as! Int, + localeCodes: (map["localeCodes"] as! [[String: Any]]).map { LocaleCode.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Log.swift b/Sources/AppwriteModels/Log.swift index b2b1216..16c27ef 100644 --- a/Sources/AppwriteModels/Log.swift +++ b/Sources/AppwriteModels/Log.swift @@ -218,27 +218,27 @@ open class Log: Codable { public static func from(map: [String: Any] ) -> Log { return Log( - event: map["event"] as? String ?? "", - userId: map["userId"] as? String ?? "", - userEmail: map["userEmail"] as? String ?? "", - userName: map["userName"] as? String ?? "", - mode: map["mode"] as? String ?? "", - ip: map["ip"] as? String ?? "", - time: map["time"] as? String ?? "", - osCode: map["osCode"] as? String ?? "", - osName: map["osName"] as? String ?? "", - osVersion: map["osVersion"] as? String ?? "", - clientType: map["clientType"] as? String ?? "", - clientCode: map["clientCode"] as? String ?? "", - clientName: map["clientName"] as? String ?? "", - clientVersion: map["clientVersion"] as? String ?? "", - clientEngine: map["clientEngine"] as? String ?? "", - clientEngineVersion: map["clientEngineVersion"] as? String ?? "", - deviceName: map["deviceName"] as? String ?? "", - deviceBrand: map["deviceBrand"] as? String ?? "", - deviceModel: map["deviceModel"] as? String ?? "", - countryCode: map["countryCode"] as? String ?? "", - countryName: map["countryName"] as? String ?? "" + event: map["event"] as! String, + userId: map["userId"] as! String, + userEmail: map["userEmail"] as! String, + userName: map["userName"] as! String, + mode: map["mode"] as! String, + ip: map["ip"] as! String, + time: map["time"] as! String, + osCode: map["osCode"] as! String, + osName: map["osName"] as! String, + osVersion: map["osVersion"] as! String, + clientType: map["clientType"] as! String, + clientCode: map["clientCode"] as! String, + clientName: map["clientName"] as! String, + clientVersion: map["clientVersion"] as! String, + clientEngine: map["clientEngine"] as! String, + clientEngineVersion: map["clientEngineVersion"] as! String, + deviceName: map["deviceName"] as! String, + deviceBrand: map["deviceBrand"] as! String, + deviceModel: map["deviceModel"] as! String, + countryCode: map["countryCode"] as! String, + countryName: map["countryName"] as! String ) } } diff --git a/Sources/AppwriteModels/LogList.swift b/Sources/AppwriteModels/LogList.swift index 8e40eb5..7ff2d07 100644 --- a/Sources/AppwriteModels/LogList.swift +++ b/Sources/AppwriteModels/LogList.swift @@ -47,8 +47,8 @@ open class LogList: Codable { public static func from(map: [String: Any] ) -> LogList { return LogList( - total: map["total"] as? Int ?? 0, - logs: (map["logs"] as? [[String: Any]] ?? []).map { Log.from(map: $0) } + total: map["total"] as! Int, + logs: (map["logs"] as! [[String: Any]]).map { Log.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Membership.swift b/Sources/AppwriteModels/Membership.swift index 1886000..8d26766 100644 --- a/Sources/AppwriteModels/Membership.swift +++ b/Sources/AppwriteModels/Membership.swift @@ -146,19 +146,19 @@ open class Membership: Codable { public static func from(map: [String: Any] ) -> Membership { return Membership( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - userId: map["userId"] as? String ?? "", - userName: map["userName"] as? String ?? "", - userEmail: map["userEmail"] as? String ?? "", - teamId: map["teamId"] as? String ?? "", - teamName: map["teamName"] as? String ?? "", - invited: map["invited"] as? String ?? "", - joined: map["joined"] as? String ?? "", - confirm: map["confirm"] as? Bool ?? false, - mfa: map["mfa"] as? Bool ?? false, - roles: map["roles"] as? [String] ?? [] + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + userId: map["userId"] as! String, + userName: map["userName"] as! String, + userEmail: map["userEmail"] as! String, + teamId: map["teamId"] as! String, + teamName: map["teamName"] as! String, + invited: map["invited"] as! String, + joined: map["joined"] as! String, + confirm: map["confirm"] as! Bool, + mfa: map["mfa"] as! Bool, + roles: map["roles"] as! [String] ) } } diff --git a/Sources/AppwriteModels/MembershipList.swift b/Sources/AppwriteModels/MembershipList.swift index abaa881..a7b0cd6 100644 --- a/Sources/AppwriteModels/MembershipList.swift +++ b/Sources/AppwriteModels/MembershipList.swift @@ -47,8 +47,8 @@ open class MembershipList: Codable { public static func from(map: [String: Any] ) -> MembershipList { return MembershipList( - total: map["total"] as? Int ?? 0, - memberships: (map["memberships"] as? [[String: Any]] ?? []).map { Membership.from(map: $0) } + total: map["total"] as! Int, + memberships: (map["memberships"] as! [[String: Any]]).map { Membership.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/MfaChallenge.swift b/Sources/AppwriteModels/MfaChallenge.swift index 7550cce..c6b77a5 100644 --- a/Sources/AppwriteModels/MfaChallenge.swift +++ b/Sources/AppwriteModels/MfaChallenge.swift @@ -65,10 +65,10 @@ open class MfaChallenge: Codable { public static func from(map: [String: Any] ) -> MfaChallenge { return MfaChallenge( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - userId: map["userId"] as? String ?? "", - expire: map["expire"] as? String ?? "" + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + userId: map["userId"] as! String, + expire: map["expire"] as! String ) } } diff --git a/Sources/AppwriteModels/MfaFactors.swift b/Sources/AppwriteModels/MfaFactors.swift index 9fb46b5..4291fab 100644 --- a/Sources/AppwriteModels/MfaFactors.swift +++ b/Sources/AppwriteModels/MfaFactors.swift @@ -65,10 +65,10 @@ open class MfaFactors: Codable { public static func from(map: [String: Any] ) -> MfaFactors { return MfaFactors( - totp: map["totp"] as? Bool ?? false, - phone: map["phone"] as? Bool ?? false, - email: map["email"] as? Bool ?? false, - recoveryCode: map["recoveryCode"] as? Bool ?? false + totp: map["totp"] as! Bool, + phone: map["phone"] as! Bool, + email: map["email"] as! Bool, + recoveryCode: map["recoveryCode"] as! Bool ) } } diff --git a/Sources/AppwriteModels/MfaRecoveryCodes.swift b/Sources/AppwriteModels/MfaRecoveryCodes.swift index ac67444..bd2968f 100644 --- a/Sources/AppwriteModels/MfaRecoveryCodes.swift +++ b/Sources/AppwriteModels/MfaRecoveryCodes.swift @@ -38,7 +38,7 @@ open class MfaRecoveryCodes: Codable { public static func from(map: [String: Any] ) -> MfaRecoveryCodes { return MfaRecoveryCodes( - recoveryCodes: map["recoveryCodes"] as? [String] ?? [] + recoveryCodes: map["recoveryCodes"] as! [String] ) } } diff --git a/Sources/AppwriteModels/MfaType.swift b/Sources/AppwriteModels/MfaType.swift index fdcd119..8646385 100644 --- a/Sources/AppwriteModels/MfaType.swift +++ b/Sources/AppwriteModels/MfaType.swift @@ -47,8 +47,8 @@ open class MfaType: Codable { public static func from(map: [String: Any] ) -> MfaType { return MfaType( - secret: map["secret"] as? String ?? "", - uri: map["uri"] as? String ?? "" + secret: map["secret"] as! String, + uri: map["uri"] as! String ) } } diff --git a/Sources/AppwriteModels/Phone.swift b/Sources/AppwriteModels/Phone.swift index 2510956..fc90d49 100644 --- a/Sources/AppwriteModels/Phone.swift +++ b/Sources/AppwriteModels/Phone.swift @@ -56,9 +56,9 @@ open class Phone: Codable { public static func from(map: [String: Any] ) -> Phone { return Phone( - code: map["code"] as? String ?? "", - countryCode: map["countryCode"] as? String ?? "", - countryName: map["countryName"] as? String ?? "" + code: map["code"] as! String, + countryCode: map["countryCode"] as! String, + countryName: map["countryName"] as! String ) } } diff --git a/Sources/AppwriteModels/PhoneList.swift b/Sources/AppwriteModels/PhoneList.swift index adf5287..6f3bee3 100644 --- a/Sources/AppwriteModels/PhoneList.swift +++ b/Sources/AppwriteModels/PhoneList.swift @@ -47,8 +47,8 @@ open class PhoneList: Codable { public static func from(map: [String: Any] ) -> PhoneList { return PhoneList( - total: map["total"] as? Int ?? 0, - phones: (map["phones"] as? [[String: Any]] ?? []).map { Phone.from(map: $0) } + total: map["total"] as! Int, + phones: (map["phones"] as! [[String: Any]]).map { Phone.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Preferences.swift b/Sources/AppwriteModels/Preferences.swift index 707297d..41f94e6 100644 --- a/Sources/AppwriteModels/Preferences.swift +++ b/Sources/AppwriteModels/Preferences.swift @@ -37,7 +37,7 @@ open class Preferences: Codable { public static func from(map: [String: Any] ) -> Preferences { return Preferences( - data: map["data"] != nil ? try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map["data"]!, options: [])) : try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) + data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: [])) ) } } diff --git a/Sources/AppwriteModels/Session.swift b/Sources/AppwriteModels/Session.swift index 1ee01a4..b5c25a6 100644 --- a/Sources/AppwriteModels/Session.swift +++ b/Sources/AppwriteModels/Session.swift @@ -290,35 +290,35 @@ open class Session: Codable { public static func from(map: [String: Any] ) -> Session { return Session( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - userId: map["userId"] as? String ?? "", - expire: map["expire"] as? String ?? "", - provider: map["provider"] as? String ?? "", - providerUid: map["providerUid"] as? String ?? "", - providerAccessToken: map["providerAccessToken"] as? String ?? "", - providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as? String ?? "", - providerRefreshToken: map["providerRefreshToken"] as? String ?? "", - ip: map["ip"] as? String ?? "", - osCode: map["osCode"] as? String ?? "", - osName: map["osName"] as? String ?? "", - osVersion: map["osVersion"] as? String ?? "", - clientType: map["clientType"] as? String ?? "", - clientCode: map["clientCode"] as? String ?? "", - clientName: map["clientName"] as? String ?? "", - clientVersion: map["clientVersion"] as? String ?? "", - clientEngine: map["clientEngine"] as? String ?? "", - clientEngineVersion: map["clientEngineVersion"] as? String ?? "", - deviceName: map["deviceName"] as? String ?? "", - deviceBrand: map["deviceBrand"] as? String ?? "", - deviceModel: map["deviceModel"] as? String ?? "", - countryCode: map["countryCode"] as? String ?? "", - countryName: map["countryName"] as? String ?? "", - current: map["current"] as? Bool ?? false, - factors: map["factors"] as? [String] ?? [], - secret: map["secret"] as? String ?? "", - mfaUpdatedAt: map["mfaUpdatedAt"] as? String ?? "" + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + userId: map["userId"] as! String, + expire: map["expire"] as! String, + provider: map["provider"] as! String, + providerUid: map["providerUid"] as! String, + providerAccessToken: map["providerAccessToken"] as! String, + providerAccessTokenExpiry: map["providerAccessTokenExpiry"] as! String, + providerRefreshToken: map["providerRefreshToken"] as! String, + ip: map["ip"] as! String, + osCode: map["osCode"] as! String, + osName: map["osName"] as! String, + osVersion: map["osVersion"] as! String, + clientType: map["clientType"] as! String, + clientCode: map["clientCode"] as! String, + clientName: map["clientName"] as! String, + clientVersion: map["clientVersion"] as! String, + clientEngine: map["clientEngine"] as! String, + clientEngineVersion: map["clientEngineVersion"] as! String, + deviceName: map["deviceName"] as! String, + deviceBrand: map["deviceBrand"] as! String, + deviceModel: map["deviceModel"] as! String, + countryCode: map["countryCode"] as! String, + countryName: map["countryName"] as! String, + current: map["current"] as! Bool, + factors: map["factors"] as! [String], + secret: map["secret"] as! String, + mfaUpdatedAt: map["mfaUpdatedAt"] as! String ) } } diff --git a/Sources/AppwriteModels/SessionList.swift b/Sources/AppwriteModels/SessionList.swift index 2dd724b..13b6b3d 100644 --- a/Sources/AppwriteModels/SessionList.swift +++ b/Sources/AppwriteModels/SessionList.swift @@ -47,8 +47,8 @@ open class SessionList: Codable { public static func from(map: [String: Any] ) -> SessionList { return SessionList( - total: map["total"] as? Int ?? 0, - sessions: (map["sessions"] as? [[String: Any]] ?? []).map { Session.from(map: $0) } + total: map["total"] as! Int, + sessions: (map["sessions"] as! [[String: Any]]).map { Session.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Subscriber.swift b/Sources/AppwriteModels/Subscriber.swift index f0a399c..ad6fa5d 100644 --- a/Sources/AppwriteModels/Subscriber.swift +++ b/Sources/AppwriteModels/Subscriber.swift @@ -110,15 +110,15 @@ open class Subscriber: Codable { public static func from(map: [String: Any] ) -> Subscriber { return Subscriber( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - targetId: map["targetId"] as? String ?? "", - target: map["target"] != nil ? Target.from(map: map["target"] as! [String: Any]) : Target(), - userId: map["userId"] as? String ?? "", - userName: map["userName"] as? String ?? "", - topicId: map["topicId"] as? String ?? "", - providerType: map["providerType"] as? String ?? "" + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + targetId: map["targetId"] as! String, + target: Target.from(map: map["target"] as! [String: Any]), + userId: map["userId"] as! String, + userName: map["userName"] as! String, + topicId: map["topicId"] as! String, + providerType: map["providerType"] as! String ) } } diff --git a/Sources/AppwriteModels/Target.swift b/Sources/AppwriteModels/Target.swift index 6e34abd..0581a61 100644 --- a/Sources/AppwriteModels/Target.swift +++ b/Sources/AppwriteModels/Target.swift @@ -110,15 +110,15 @@ open class Target: Codable { public static func from(map: [String: Any] ) -> Target { return Target( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - name: map["name"] as? String ?? "", - userId: map["userId"] as? String ?? "", + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + name: map["name"] as! String, + userId: map["userId"] as! String, providerId: map["providerId"] as? String, - providerType: map["providerType"] as? String ?? "", - identifier: map["identifier"] as? String ?? "", - expired: map["expired"] as? Bool ?? false + providerType: map["providerType"] as! String, + identifier: map["identifier"] as! String, + expired: map["expired"] as! Bool ) } } diff --git a/Sources/AppwriteModels/Team.swift b/Sources/AppwriteModels/Team.swift index 052debe..9ca7307 100644 --- a/Sources/AppwriteModels/Team.swift +++ b/Sources/AppwriteModels/Team.swift @@ -83,12 +83,12 @@ open class Team: Codable { public static func from(map: [String: Any] ) -> Team { return Team( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - name: map["name"] as? String ?? "", - total: map["total"] as? Int ?? 0, - prefs: map["prefs"] != nil ? Preferences.from(map: map["prefs"] as! [String: Any]) : Preferences() + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + name: map["name"] as! String, + total: map["total"] as! Int, + prefs: Preferences.from(map: map["prefs"] as! [String: Any]) ) } } diff --git a/Sources/AppwriteModels/TeamList.swift b/Sources/AppwriteModels/TeamList.swift index aaa02af..384d9f6 100644 --- a/Sources/AppwriteModels/TeamList.swift +++ b/Sources/AppwriteModels/TeamList.swift @@ -47,8 +47,8 @@ open class TeamList: Codable { public static func from(map: [String: Any] ) -> TeamList { return TeamList( - total: map["total"] as? Int ?? 0, - teams: (map["teams"] as? [[String: Any]] ?? []).map { Team.from(map: $0) } + total: map["total"] as! Int, + teams: (map["teams"] as! [[String: Any]]).map { Team.from(map: $0) } ) } } diff --git a/Sources/AppwriteModels/Token.swift b/Sources/AppwriteModels/Token.swift index 1ded551..f832402 100644 --- a/Sources/AppwriteModels/Token.swift +++ b/Sources/AppwriteModels/Token.swift @@ -83,12 +83,12 @@ open class Token: Codable { public static func from(map: [String: Any] ) -> Token { return Token( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - userId: map["userId"] as? String ?? "", - secret: map["secret"] as? String ?? "", - expire: map["expire"] as? String ?? "", - phrase: map["phrase"] as? String ?? "" + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + userId: map["userId"] as! String, + secret: map["secret"] as! String, + expire: map["expire"] as! String, + phrase: map["phrase"] as! String ) } } diff --git a/Sources/AppwriteModels/User.swift b/Sources/AppwriteModels/User.swift index a519c76..6e972d3 100644 --- a/Sources/AppwriteModels/User.swift +++ b/Sources/AppwriteModels/User.swift @@ -200,25 +200,25 @@ open class User: Codable { public static func from(map: [String: Any] ) -> User { return User( - id: map["$id"] as? String ?? "", - createdAt: map["$createdAt"] as? String ?? "", - updatedAt: map["$updatedAt"] as? String ?? "", - name: map["name"] as? String ?? "", + id: map["$id"] as! String, + createdAt: map["$createdAt"] as! String, + updatedAt: map["$updatedAt"] as! String, + name: map["name"] as! String, password: map["password"] as? String, hash: map["hash"] as? String, hashOptions: map["hashOptions"] as? [String: AnyCodable], - registration: map["registration"] as? String ?? "", - status: map["status"] as? Bool ?? false, - labels: map["labels"] as? [String] ?? [], - passwordUpdate: map["passwordUpdate"] as? String ?? "", - email: map["email"] as? String ?? "", - phone: map["phone"] as? String ?? "", - emailVerification: map["emailVerification"] as? Bool ?? false, - phoneVerification: map["phoneVerification"] as? Bool ?? false, - mfa: map["mfa"] as? Bool ?? false, - prefs: map["prefs"] != nil ? Preferences.from(map: map["prefs"] as! [String: Any]) : Preferences(), - targets: (map["targets"] as? [[String: Any]] ?? []).map { Target.from(map: $0) }, - accessedAt: map["accessedAt"] as? String ?? "" + registration: map["registration"] as! String, + status: map["status"] as! Bool, + labels: map["labels"] as! [String], + passwordUpdate: map["passwordUpdate"] as! String, + email: map["email"] as! String, + phone: map["phone"] as! String, + emailVerification: map["emailVerification"] as! Bool, + phoneVerification: map["phoneVerification"] as! Bool, + mfa: map["mfa"] as! Bool, + prefs: Preferences.from(map: map["prefs"] as! [String: Any]), + targets: (map["targets"] as! [[String: Any]]).map { Target.from(map: $0) }, + accessedAt: map["accessedAt"] as! String ) } }