Skip to content

Commit 5d226b0

Browse files
committed
fix: enhance model property handling for array types
1 parent dddb2a1 commit 5d226b0

File tree

102 files changed

+701
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+701
-562
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.7.4-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ open class Client {
257257

258258
return output.addingPercentEncoding(
259259
withAllowedCharacters: .urlHostAllowed
260-
) ?? ""
260+
)?.replacingOccurrences(of: "+", with: "%2B") ?? "" // since urlHostAllowed doesn't include +
261261
}
262262

263263
///

Sources/Appwrite/Services/Databases.swift

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,10 @@ open class Databases: Service {
16561656
}
16571657

16581658
///
1659+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1660+
/// yet officially supported. It may be subject to breaking changes or removal
1661+
/// in future versions.
1662+
///
16591663
/// Create new Documents. Before using this route, you should create a new
16601664
/// collection resource using either a [server
16611665
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
@@ -1699,6 +1703,10 @@ open class Databases: Service {
16991703
}
17001704

17011705
///
1706+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1707+
/// yet officially supported. It may be subject to breaking changes or removal
1708+
/// in future versions.
1709+
///
17021710
/// Create new Documents. Before using this route, you should create a new
17031711
/// collection resource using either a [server
17041712
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
@@ -1724,6 +1732,10 @@ open class Databases: Service {
17241732
}
17251733

17261734
///
1735+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1736+
/// yet officially supported. It may be subject to breaking changes or removal
1737+
/// in future versions.
1738+
///
17271739
/// Create or update Documents. Before using this route, you should create a
17281740
/// new collection resource using either a [server
17291741
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
@@ -1768,6 +1780,10 @@ open class Databases: Service {
17681780
}
17691781

17701782
///
1783+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1784+
/// yet officially supported. It may be subject to breaking changes or removal
1785+
/// in future versions.
1786+
///
17711787
/// Create or update Documents. Before using this route, you should create a
17721788
/// new collection resource using either a [server
17731789
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
@@ -1866,6 +1882,10 @@ open class Databases: Service {
18661882
}
18671883

18681884
///
1885+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1886+
/// yet officially supported. It may be subject to breaking changes or removal
1887+
/// in future versions.
1888+
///
18691889
/// Bulk delete documents using queries, if no queries are passed then all
18701890
/// documents are deleted.
18711891
///
@@ -1907,6 +1927,10 @@ open class Databases: Service {
19071927
}
19081928

19091929
///
1930+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
1931+
/// yet officially supported. It may be subject to breaking changes or removal
1932+
/// in future versions.
1933+
///
19101934
/// Bulk delete documents using queries, if no queries are passed then all
19111935
/// documents are deleted.
19121936
///
@@ -1997,6 +2021,94 @@ open class Databases: Service {
19972021
)
19982022
}
19992023

2024+
///
2025+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
2026+
/// yet officially supported. It may be subject to breaking changes or removal
2027+
/// in future versions.
2028+
///
2029+
/// Create or update a Document. Before using this route, you should create a
2030+
/// new collection resource using either a [server
2031+
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
2032+
/// API or directly from your database console.
2033+
///
2034+
/// @param String databaseId
2035+
/// @param String collectionId
2036+
/// @param String documentId
2037+
/// @param Any data
2038+
/// @param [String] permissions
2039+
/// @throws Exception
2040+
/// @return array
2041+
///
2042+
open func upsertDocument<T>(
2043+
databaseId: String,
2044+
collectionId: String,
2045+
documentId: String,
2046+
data: Any,
2047+
permissions: [String]? = nil,
2048+
nestedType: T.Type
2049+
) async throws -> AppwriteModels.Document<T> {
2050+
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}"
2051+
.replacingOccurrences(of: "{databaseId}", with: databaseId)
2052+
.replacingOccurrences(of: "{collectionId}", with: collectionId)
2053+
.replacingOccurrences(of: "{documentId}", with: documentId)
2054+
2055+
let apiParams: [String: Any?] = [
2056+
"data": data,
2057+
"permissions": permissions
2058+
]
2059+
2060+
let apiHeaders: [String: String] = [
2061+
"content-type": "application/json"
2062+
]
2063+
2064+
let converter: (Any) -> AppwriteModels.Document<T> = { response in
2065+
return AppwriteModels.Document.from(map: response as! [String: Any])
2066+
}
2067+
2068+
return try await client.call(
2069+
method: "PUT",
2070+
path: apiPath,
2071+
headers: apiHeaders,
2072+
params: apiParams,
2073+
converter: converter
2074+
)
2075+
}
2076+
2077+
///
2078+
/// **WARNING: Experimental Feature** - This endpoint is experimental and not
2079+
/// yet officially supported. It may be subject to breaking changes or removal
2080+
/// in future versions.
2081+
///
2082+
/// Create or update a Document. Before using this route, you should create a
2083+
/// new collection resource using either a [server
2084+
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
2085+
/// API or directly from your database console.
2086+
///
2087+
/// @param String databaseId
2088+
/// @param String collectionId
2089+
/// @param String documentId
2090+
/// @param Any data
2091+
/// @param [String] permissions
2092+
/// @throws Exception
2093+
/// @return array
2094+
///
2095+
open func upsertDocument(
2096+
databaseId: String,
2097+
collectionId: String,
2098+
documentId: String,
2099+
data: Any,
2100+
permissions: [String]? = nil
2101+
) async throws -> AppwriteModels.Document<[String: AnyCodable]> {
2102+
return try await upsertDocument(
2103+
databaseId: databaseId,
2104+
collectionId: collectionId,
2105+
documentId: documentId,
2106+
data: data,
2107+
permissions: permissions,
2108+
nestedType: [String: AnyCodable].self
2109+
)
2110+
}
2111+
20002112
///
20012113
/// Update a document by its unique ID. Using the patch method you can pass
20022114
/// only specific fields that will get updated.

Sources/Appwrite/Services/Tokens.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ open class Tokens: Service {
4848

4949
///
5050
/// Create a new token. A token is linked to a file. Token can be passed as a
51-
/// header or request get parameter.
51+
/// request URL search parameter.
5252
///
5353
/// @param String bucketId
5454
/// @param String fileId

Sources/AppwriteModels/AlgoArgon2.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ open class AlgoArgon2: Codable {
6565

6666
public static func from(map: [String: Any] ) -> AlgoArgon2 {
6767
return AlgoArgon2(
68-
type: map["type"] as! String,
69-
memoryCost: map["memoryCost"] as! Int,
70-
timeCost: map["timeCost"] as! Int,
71-
threads: map["threads"] as! Int
68+
type: map["type"] as? String ?? "",
69+
memoryCost: map["memoryCost"] as? Int ?? 0,
70+
timeCost: map["timeCost"] as? Int ?? 0,
71+
threads: map["threads"] as? Int ?? 0
7272
)
7373
}
7474
}

Sources/AppwriteModels/AlgoBcrypt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class AlgoBcrypt: Codable {
3838

3939
public static func from(map: [String: Any] ) -> AlgoBcrypt {
4040
return AlgoBcrypt(
41-
type: map["type"] as! String
41+
type: map["type"] as? String ?? ""
4242
)
4343
}
4444
}

Sources/AppwriteModels/AlgoMd5.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class AlgoMd5: Codable {
3838

3939
public static func from(map: [String: Any] ) -> AlgoMd5 {
4040
return AlgoMd5(
41-
type: map["type"] as! String
41+
type: map["type"] as? String ?? ""
4242
)
4343
}
4444
}

Sources/AppwriteModels/AlgoPhpass.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ open class AlgoPhpass: Codable {
3838

3939
public static func from(map: [String: Any] ) -> AlgoPhpass {
4040
return AlgoPhpass(
41-
type: map["type"] as! String
41+
type: map["type"] as? String ?? ""
4242
)
4343
}
4444
}

Sources/AppwriteModels/AlgoScrypt.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ open class AlgoScrypt: Codable {
7474

7575
public static func from(map: [String: Any] ) -> AlgoScrypt {
7676
return AlgoScrypt(
77-
type: map["type"] as! String,
78-
costCpu: map["costCpu"] as! Int,
79-
costMemory: map["costMemory"] as! Int,
80-
costParallel: map["costParallel"] as! Int,
81-
length: map["length"] as! Int
77+
type: map["type"] as? String ?? "",
78+
costCpu: map["costCpu"] as? Int ?? 0,
79+
costMemory: map["costMemory"] as? Int ?? 0,
80+
costParallel: map["costParallel"] as? Int ?? 0,
81+
length: map["length"] as? Int ?? 0
8282
)
8383
}
8484
}

Sources/AppwriteModels/AlgoScryptModified.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ open class AlgoScryptModified: Codable {
6565

6666
public static func from(map: [String: Any] ) -> AlgoScryptModified {
6767
return AlgoScryptModified(
68-
type: map["type"] as! String,
69-
salt: map["salt"] as! String,
70-
saltSeparator: map["saltSeparator"] as! String,
71-
signerKey: map["signerKey"] as! String
68+
type: map["type"] as? String ?? "",
69+
salt: map["salt"] as? String ?? "",
70+
saltSeparator: map["saltSeparator"] as? String ?? "",
71+
signerKey: map["signerKey"] as? String ?? ""
7272
)
7373
}
7474
}

0 commit comments

Comments
 (0)