@@ -8,6 +8,116 @@ import AppwriteModels
88/// The Functions Service allows you view, create and manage your Cloud Functions.
99open class Functions : Service {
1010
11+ ///
12+ /// List function templates
13+ ///
14+ /// List available function templates. You can use template details in
15+ /// [createFunction](/docs/references/cloud/server-nodejs/functions#create)
16+ /// method.
17+ ///
18+ /// @param [String] runtimes
19+ /// @param [String] useCases
20+ /// @param Int limit
21+ /// @param Int offset
22+ /// @throws Exception
23+ /// @return array
24+ ///
25+ open func listTemplates(
26+ runtimes: [ String ] ? = nil ,
27+ useCases: [ String ] ? = nil ,
28+ limit: Int ? = nil ,
29+ offset: Int ? = nil
30+ ) async throws -> AppwriteModels . TemplateFunctionList {
31+ let apiPath : String = " /functions/templates "
32+
33+ let apiParams : [ String : Any ? ] = [
34+ " runtimes " : runtimes,
35+ " useCases " : useCases,
36+ " limit " : limit,
37+ " offset " : offset
38+ ]
39+
40+ let apiHeaders : [ String : String ] = [
41+ " content-type " : " application/json "
42+ ]
43+
44+ let converter : ( Any ) -> AppwriteModels . TemplateFunctionList = { response in
45+ return AppwriteModels . TemplateFunctionList. from ( map: response as! [ String : Any ] )
46+ }
47+
48+ return try await client. call (
49+ method: " GET " ,
50+ path: apiPath,
51+ headers: apiHeaders,
52+ params: apiParams,
53+ converter: converter
54+ )
55+ }
56+
57+ ///
58+ /// Get function template
59+ ///
60+ /// Get a function template using ID. You can use template details in
61+ /// [createFunction](/docs/references/cloud/server-nodejs/functions#create)
62+ /// method.
63+ ///
64+ /// @param String templateId
65+ /// @throws Exception
66+ /// @return array
67+ ///
68+ open func getTemplate(
69+ templateId: String
70+ ) async throws -> AppwriteModels . TemplateFunction {
71+ let apiPath : String = " /functions/templates/{templateId} "
72+ . replacingOccurrences ( of: " {templateId} " , with: templateId)
73+
74+ let apiParams : [ String : Any ] = [ : ]
75+
76+ let apiHeaders : [ String : String ] = [
77+ " content-type " : " application/json "
78+ ]
79+
80+ let converter : ( Any ) -> AppwriteModels . TemplateFunction = { response in
81+ return AppwriteModels . TemplateFunction. from ( map: response as! [ String : Any ] )
82+ }
83+
84+ return try await client. call (
85+ method: " GET " ,
86+ path: apiPath,
87+ headers: apiHeaders,
88+ params: apiParams,
89+ converter: converter
90+ )
91+ }
92+
93+ ///
94+ /// Download deployment
95+ ///
96+ /// Get a Deployment's contents by its unique ID. This endpoint supports range
97+ /// requests for partial or streaming file download.
98+ ///
99+ /// @param String functionId
100+ /// @param String deploymentId
101+ /// @throws Exception
102+ /// @return array
103+ ///
104+ open func getDeploymentDownload(
105+ functionId: String ,
106+ deploymentId: String
107+ ) async throws -> ByteBuffer {
108+ let apiPath : String = " /functions/{functionId}/deployments/{deploymentId}/download "
109+ . replacingOccurrences ( of: " {functionId} " , with: functionId)
110+ . replacingOccurrences ( of: " {deploymentId} " , with: deploymentId)
111+
112+ let apiParams : [ String : Any ] = [ : ]
113+
114+ return try await client. call (
115+ method: " GET " ,
116+ path: apiPath,
117+ params: apiParams
118+ )
119+ }
120+
11121 ///
12122 /// List executions
13123 ///
@@ -75,12 +185,13 @@ open class Functions: Service {
75185 path: String ? = nil ,
76186 method: AppwriteEnums . ExecutionMethod ? = nil ,
77187 headers: Any ? = nil ,
78- scheduledAt: String ? = nil
188+ scheduledAt: String ? = nil ,
189+ onProgress: ( ( UploadProgress ) -> Void ) ? = nil
79190 ) async throws -> AppwriteModels . Execution {
80191 let apiPath : String = " /functions/{functionId}/executions "
81192 . replacingOccurrences ( of: " {functionId} " , with: functionId)
82193
83- let apiParams : [ String : Any ? ] = [
194+ var apiParams : [ String : Any ? ] = [
84195 " body " : body,
85196 " async " : async ,
86197 " path " : path,
@@ -89,20 +200,23 @@ open class Functions: Service {
89200 " scheduledAt " : scheduledAt
90201 ]
91202
92- let apiHeaders : [ String : String ] = [
93- " content-type " : " application/json "
203+ var apiHeaders : [ String : String ] = [
204+ " content-type " : " multipart/form-data "
94205 ]
95206
96207 let converter : ( Any ) -> AppwriteModels . Execution = { response in
97208 return AppwriteModels . Execution. from ( map: response as! [ String : Any ] )
98209 }
99210
100- return try await client . call (
101- method : " POST " ,
211+ let idParamName : String ? = nil
212+ return try await client . chunkedUpload (
102213 path: apiPath,
103- headers: apiHeaders,
104- params: apiParams,
105- converter: converter
214+ headers: & apiHeaders,
215+ params: & apiParams,
216+ paramName: paramName,
217+ idParamName: idParamName,
218+ converter: converter,
219+ onProgress: onProgress
106220 )
107221 }
108222
0 commit comments