Skip to content

Commit 778d3f4

Browse files
committed
chore: update SDKs to new RC version
1 parent 1672cb0 commit 778d3f4

File tree

9 files changed

+162
-24
lines changed

9 files changed

+162
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: "6.0.0-rc.1"),
36+
.package(url: "[email protected]:appwrite/sdk-for-swift.git", from: "6.0.0-rc.2"),
3737
],
3838
```
3939

Sources/Appwrite/Client.swift

Lines changed: 1 addition & 1 deletion
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": "6.0.0-rc.1",
24+
"x-sdk-version": "6.0.0-rc.2",
2525
"x-appwrite-response-format": "1.6.0"
2626
]
2727

Sources/Appwrite/Services/Functions.swift

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ open class Functions: Service {
7676
/// @param String templateOwner
7777
/// @param String templateRootDirectory
7878
/// @param String templateVersion
79+
/// @param String specification
7980
/// @throws Exception
8081
/// @return array
8182
///
@@ -100,7 +101,8 @@ open class Functions: Service {
100101
templateRepository: String? = nil,
101102
templateOwner: String? = nil,
102103
templateRootDirectory: String? = nil,
103-
templateVersion: String? = nil
104+
templateVersion: String? = nil,
105+
specification: String? = nil
104106
) async throws -> AppwriteModels.Function {
105107
let apiPath: String = "/functions"
106108

@@ -125,7 +127,8 @@ open class Functions: Service {
125127
"templateRepository": templateRepository,
126128
"templateOwner": templateOwner,
127129
"templateRootDirectory": templateRootDirectory,
128-
"templateVersion": templateVersion
130+
"templateVersion": templateVersion,
131+
"specification": specification
129132
]
130133

131134
let apiHeaders: [String: String] = [
@@ -176,6 +179,38 @@ open class Functions: Service {
176179
)
177180
}
178181

182+
///
183+
/// List available function runtime specifications
184+
///
185+
/// List allowed function specifications for this instance.
186+
///
187+
///
188+
/// @throws Exception
189+
/// @return array
190+
///
191+
open func listSpecifications(
192+
) async throws -> AppwriteModels.SpecificationList {
193+
let apiPath: String = "/functions/specifications"
194+
195+
let apiParams: [String: Any] = [:]
196+
197+
let apiHeaders: [String: String] = [
198+
"content-type": "application/json"
199+
]
200+
201+
let converter: (Any) -> AppwriteModels.SpecificationList = { response in
202+
return AppwriteModels.SpecificationList.from(map: response as! [String: Any])
203+
}
204+
205+
return try await client.call(
206+
method: "GET",
207+
path: apiPath,
208+
headers: apiHeaders,
209+
params: apiParams,
210+
converter: converter
211+
)
212+
}
213+
179214
///
180215
/// List function templates
181216
///
@@ -314,6 +349,7 @@ open class Functions: Service {
314349
/// @param String providerBranch
315350
/// @param Bool providerSilentMode
316351
/// @param String providerRootDirectory
352+
/// @param String specification
317353
/// @throws Exception
318354
/// @return array
319355
///
@@ -334,7 +370,8 @@ open class Functions: Service {
334370
providerRepositoryId: String? = nil,
335371
providerBranch: String? = nil,
336372
providerSilentMode: Bool? = nil,
337-
providerRootDirectory: String? = nil
373+
providerRootDirectory: String? = nil,
374+
specification: String? = nil
338375
) async throws -> AppwriteModels.Function {
339376
let apiPath: String = "/functions/{functionId}"
340377
.replacingOccurrences(of: "{functionId}", with: functionId)
@@ -355,7 +392,8 @@ open class Functions: Service {
355392
"providerRepositoryId": providerRepositoryId,
356393
"providerBranch": providerBranch,
357394
"providerSilentMode": providerSilentMode,
358-
"providerRootDirectory": providerRootDirectory
395+
"providerRootDirectory": providerRootDirectory,
396+
"specification": specification
359397
]
360398

361399
let apiHeaders: [String: String] = [
@@ -780,13 +818,12 @@ open class Functions: Service {
780818
path: String? = nil,
781819
method: AppwriteEnums.ExecutionMethod? = nil,
782820
headers: Any? = nil,
783-
scheduledAt: String? = nil,
784-
onProgress: ((UploadProgress) -> Void)? = nil
821+
scheduledAt: String? = nil
785822
) async throws -> AppwriteModels.Execution {
786823
let apiPath: String = "/functions/{functionId}/executions"
787824
.replacingOccurrences(of: "{functionId}", with: functionId)
788825

789-
var apiParams: [String: Any?] = [
826+
let apiParams: [String: Any?] = [
790827
"body": body,
791828
"async": async,
792829
"path": path,
@@ -795,23 +832,20 @@ open class Functions: Service {
795832
"scheduledAt": scheduledAt
796833
]
797834

798-
var apiHeaders: [String: String] = [
799-
"content-type": "multipart/form-data"
835+
let apiHeaders: [String: String] = [
836+
"content-type": "application/json"
800837
]
801838

802839
let converter: (Any) -> AppwriteModels.Execution = { response in
803840
return AppwriteModels.Execution.from(map: response as! [String: Any])
804841
}
805842

806-
let idParamName: String? = nil
807-
return try await client.chunkedUpload(
843+
return try await client.call(
844+
method: "POST",
808845
path: apiPath,
809-
headers: &apiHeaders,
810-
params: &apiParams,
811-
paramName: paramName,
812-
idParamName: idParamName,
813-
converter: converter,
814-
onProgress: onProgress
846+
headers: apiHeaders,
847+
params: apiParams,
848+
converter: converter
815849
)
816850
}
817851

Sources/AppwriteModels/Function.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class Function {
7373
/// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests
7474
public let providerSilentMode: Bool
7575

76+
/// Machine specification for builds and executions.
77+
public let specification: String
78+
7679

7780
init(
7881
id: String,
@@ -97,7 +100,8 @@ public class Function {
97100
providerRepositoryId: String,
98101
providerBranch: String,
99102
providerRootDirectory: String,
100-
providerSilentMode: Bool
103+
providerSilentMode: Bool,
104+
specification: String
101105
) {
102106
self.id = id
103107
self.createdAt = createdAt
@@ -122,6 +126,7 @@ public class Function {
122126
self.providerBranch = providerBranch
123127
self.providerRootDirectory = providerRootDirectory
124128
self.providerSilentMode = providerSilentMode
129+
self.specification = specification
125130
}
126131

127132
public func toMap() -> [String: Any] {
@@ -148,7 +153,8 @@ public class Function {
148153
"providerRepositoryId": providerRepositoryId as Any,
149154
"providerBranch": providerBranch as Any,
150155
"providerRootDirectory": providerRootDirectory as Any,
151-
"providerSilentMode": providerSilentMode as Any
156+
"providerSilentMode": providerSilentMode as Any,
157+
"specification": specification as Any
152158
]
153159
}
154160

@@ -176,7 +182,8 @@ public class Function {
176182
providerRepositoryId: map["providerRepositoryId"] as! String,
177183
providerBranch: map["providerBranch"] as! String,
178184
providerRootDirectory: map["providerRootDirectory"] as! String,
179-
providerSilentMode: map["providerSilentMode"] as! Bool
185+
providerSilentMode: map["providerSilentMode"] as! Bool,
186+
specification: map["specification"] as! String
180187
)
181188
}
182189
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Foundation
2+
import JSONCodable
3+
4+
/// Specification
5+
public class Specification {
6+
7+
/// Memory size in MB.
8+
public let memory: Int
9+
10+
/// Number of CPUs.
11+
public let cpus: Double
12+
13+
/// Is size enabled.
14+
public let enabled: Bool
15+
16+
/// Size slug.
17+
public let slug: String
18+
19+
20+
init(
21+
memory: Int,
22+
cpus: Double,
23+
enabled: Bool,
24+
slug: String
25+
) {
26+
self.memory = memory
27+
self.cpus = cpus
28+
self.enabled = enabled
29+
self.slug = slug
30+
}
31+
32+
public func toMap() -> [String: Any] {
33+
return [
34+
"memory": memory as Any,
35+
"cpus": cpus as Any,
36+
"enabled": enabled as Any,
37+
"slug": slug as Any
38+
]
39+
}
40+
41+
public static func from(map: [String: Any] ) -> Specification {
42+
return Specification(
43+
memory: map["memory"] as! Int,
44+
cpus: map["cpus"] as! Double,
45+
enabled: map["enabled"] as! Bool,
46+
slug: map["slug"] as! String
47+
)
48+
}
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Foundation
2+
import JSONCodable
3+
4+
/// Specifications List
5+
public class SpecificationList {
6+
7+
/// Total number of specifications documents that matched your query.
8+
public let total: Int
9+
10+
/// List of specifications.
11+
public let specifications: [Specification]
12+
13+
14+
init(
15+
total: Int,
16+
specifications: [Specification]
17+
) {
18+
self.total = total
19+
self.specifications = specifications
20+
}
21+
22+
public func toMap() -> [String: Any] {
23+
return [
24+
"total": total as Any,
25+
"specifications": specifications.map { $0.toMap() } as Any
26+
]
27+
}
28+
29+
public static func from(map: [String: Any] ) -> SpecificationList {
30+
return SpecificationList(
31+
total: map["total"] as! Int,
32+
specifications: (map["specifications"] as! [[String: Any]]).map { Specification.from(map: $0) }
33+
)
34+
}
35+
}

docs/examples/functions/create.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let function = try await functions.create(
2929
templateRepository: "<TEMPLATE_REPOSITORY>", // optional
3030
templateOwner: "<TEMPLATE_OWNER>", // optional
3131
templateRootDirectory: "<TEMPLATE_ROOT_DIRECTORY>", // optional
32-
templateVersion: "<TEMPLATE_VERSION>" // optional
32+
templateVersion: "<TEMPLATE_VERSION>", // optional
33+
specification: "" // optional
3334
)
3435

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Appwrite
2+
3+
let client = Client()
4+
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
5+
.setProject("&lt;YOUR_PROJECT_ID&gt;") // Your project ID
6+
.setKey("&lt;YOUR_API_KEY&gt;") // Your secret API key
7+
8+
let functions = Functions(client)
9+
10+
let specificationList = try await functions.listSpecifications()
11+

docs/examples/functions/update.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let function = try await functions.update(
2525
providerRepositoryId: "<PROVIDER_REPOSITORY_ID>", // optional
2626
providerBranch: "<PROVIDER_BRANCH>", // optional
2727
providerSilentMode: false, // optional
28-
providerRootDirectory: "<PROVIDER_ROOT_DIRECTORY>" // optional
28+
providerRootDirectory: "<PROVIDER_ROOT_DIRECTORY>", // optional
29+
specification: "" // optional
2930
)
3031

0 commit comments

Comments
 (0)