Skip to content

Commit e6ded53

Browse files
Merge pull request #35 from appwrite/dev
chore: regenerate sdk
2 parents 3208c17 + f545e49 commit e6ded53

File tree

9 files changed

+155
-16
lines changed

9 files changed

+155
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
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)
@@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:
3333

3434
```swift
3535
dependencies: [
36-
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "10.0.0"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "10.1.0"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class Client {
2121
"x-sdk-name": "Swift",
2222
"x-sdk-platform": "server",
2323
"x-sdk-language": "swift",
24-
"x-sdk-version": "10.0.0",
24+
"x-sdk-version": "10.1.0",
2525
"x-appwrite-response-format": "1.7.0"
2626
]
2727

@@ -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/AttributeList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ open class AttributeList: Codable {
4848
public static func from(map: [String: Any] ) -> AttributeList {
4949
return AttributeList(
5050
total: map["total"] as! Int,
51-
attributes: map["attributes"] as! [AnyCodable]
51+
attributes: (map["attributes"] as! [Any]).map { AnyCodable($0) }
5252
)
5353
}
5454
}

Sources/AppwriteModels/AttributeString.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ open class AttributeString: Codable {
1515
case updatedAt = "$updatedAt"
1616
case size = "size"
1717
case `default` = "default"
18+
case encrypt = "encrypt"
1819
}
1920

2021
/// Attribute Key.
@@ -47,6 +48,9 @@ open class AttributeString: Codable {
4748
/// Default value for attribute when not provided. Cannot be set when attribute is required.
4849
public let `default`: String?
4950

51+
/// Defines whether this attribute is encrypted or not.
52+
public let encrypt: Bool?
53+
5054

5155
init(
5256
key: String,
@@ -58,7 +62,8 @@ open class AttributeString: Codable {
5862
createdAt: String,
5963
updatedAt: String,
6064
size: Int,
61-
`default`: String?
65+
`default`: String?,
66+
encrypt: Bool?
6267
) {
6368
self.key = key
6469
self.type = type
@@ -70,6 +75,7 @@ open class AttributeString: Codable {
7075
self.updatedAt = updatedAt
7176
self.size = size
7277
self.`default` = `default`
78+
self.encrypt = encrypt
7379
}
7480

7581
public required init(from decoder: Decoder) throws {
@@ -85,6 +91,7 @@ open class AttributeString: Codable {
8591
self.updatedAt = try container.decode(String.self, forKey: .updatedAt)
8692
self.size = try container.decode(Int.self, forKey: .size)
8793
self.`default` = try container.decodeIfPresent(String.self, forKey: .`default`)
94+
self.encrypt = try container.decodeIfPresent(Bool.self, forKey: .encrypt)
8895
}
8996

9097
public func encode(to encoder: Encoder) throws {
@@ -100,6 +107,7 @@ open class AttributeString: Codable {
100107
try container.encode(updatedAt, forKey: .updatedAt)
101108
try container.encode(size, forKey: .size)
102109
try container.encodeIfPresent(`default`, forKey: .`default`)
110+
try container.encodeIfPresent(encrypt, forKey: .encrypt)
103111
}
104112

105113
public func toMap() -> [String: Any] {
@@ -113,7 +121,8 @@ open class AttributeString: Codable {
113121
"$createdAt": createdAt as Any,
114122
"$updatedAt": updatedAt as Any,
115123
"size": size as Any,
116-
"`default`": `default` as Any
124+
"`default`": `default` as Any,
125+
"encrypt": encrypt as Any
117126
]
118127
}
119128

@@ -128,7 +137,8 @@ open class AttributeString: Codable {
128137
createdAt: map["$createdAt"] as! String,
129138
updatedAt: map["$updatedAt"] as! String,
130139
size: map["size"] as! Int,
131-
`default`: map["default"] as? String
140+
`default`: map["default"] as? String,
141+
encrypt: map["encrypt"] as? Bool
132142
)
133143
}
134144
}

Sources/AppwriteModels/Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ open class Collection: Codable {
127127
name: map["name"] as! String,
128128
enabled: map["enabled"] as! Bool,
129129
documentSecurity: map["documentSecurity"] as! Bool,
130-
attributes: map["attributes"] as! [AnyCodable],
130+
attributes: (map["attributes"] as! [Any]).map { AnyCodable($0) },
131131
indexes: (map["indexes"] as! [[String: Any]]).map { Index.from(map: $0) }
132132
)
133133
}

Sources/AppwriteModels/Document.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ open class Document<T : Codable>: Codable {
9191

9292
public static func from(map: [String: Any] ) -> Document {
9393
return Document(
94-
id: map["$id"] as! String,
95-
collectionId: map["$collectionId"] as! String,
96-
databaseId: map["$databaseId"] as! String,
97-
createdAt: map["$createdAt"] as! String,
98-
updatedAt: map["$updatedAt"] as! String,
99-
permissions: map["$permissions"] as! [String],
94+
id: map["$id"] as? String ?? "",
95+
collectionId: map["$collectionId"] as? String ?? "",
96+
databaseId: map["$databaseId"] as? String ?? "",
97+
createdAt: map["$createdAt"] as? String ?? "",
98+
updatedAt: map["$updatedAt"] as? String ?? "",
99+
permissions: map["$permissions"] as? [String] ?? [],
100100
data: try! JSONDecoder().decode(T.self, from: JSONSerialization.data(withJSONObject: map, options: []))
101101
)
102102
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Appwrite
2+
3+
let client = Client()
4+
.setEndpoint("https://<REGION>.cloud.appwrite.io/v1") // Your API Endpoint
5+
.setProject("<YOUR_PROJECT_ID>") // Your project ID
6+
.setSession("") // The user session to authenticate with
7+
8+
let databases = Databases(client)
9+
10+
let document = try await databases.upsertDocument(
11+
databaseId: "<DATABASE_ID>",
12+
collectionId: "<COLLECTION_ID>",
13+
documentId: "<DOCUMENT_ID>",
14+
data: [:],
15+
permissions: ["read("any")"] // optional
16+
)
17+

0 commit comments

Comments
 (0)