node-appwrite 11.0.0 → 12.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +2 -2
  3. package/docs/examples/account/add-authenticator.md +12 -0
  4. package/docs/examples/account/create-anonymous-session.md +9 -0
  5. package/docs/examples/account/create-email-password-session.md +12 -0
  6. package/docs/examples/account/create-email-token.md +13 -0
  7. package/docs/examples/account/create-j-w-t.md +9 -0
  8. package/docs/examples/account/create-magic-u-r-l-token.md +14 -0
  9. package/docs/examples/account/create-o-auth2session.md +15 -0
  10. package/docs/examples/account/create-phone-token.md +12 -0
  11. package/docs/examples/account/create-phone-verification.md +4 -14
  12. package/docs/examples/account/create-recovery.md +7 -14
  13. package/docs/examples/account/create-session.md +12 -0
  14. package/docs/examples/account/create-verification.md +6 -14
  15. package/docs/examples/account/create.md +14 -0
  16. package/docs/examples/account/create2f-a-challenge.md +11 -0
  17. package/docs/examples/account/delete-authenticator.md +13 -0
  18. package/docs/examples/account/delete-identity.md +6 -14
  19. package/docs/examples/account/delete-session.md +6 -14
  20. package/docs/examples/account/delete-sessions.md +4 -14
  21. package/docs/examples/account/get-prefs.md +4 -14
  22. package/docs/examples/account/get-session.md +6 -14
  23. package/docs/examples/account/get.md +4 -14
  24. package/docs/examples/account/list-factors.md +10 -0
  25. package/docs/examples/account/list-identities.md +6 -14
  26. package/docs/examples/account/list-logs.md +6 -14
  27. package/docs/examples/account/list-sessions.md +4 -14
  28. package/docs/examples/account/update-challenge.md +13 -0
  29. package/docs/examples/account/update-email.md +7 -14
  30. package/docs/examples/account/update-m-f-a.md +12 -0
  31. package/docs/examples/account/update-magic-u-r-l-session.md +12 -0
  32. package/docs/examples/account/update-name.md +6 -14
  33. package/docs/examples/account/update-password.md +7 -14
  34. package/docs/examples/account/update-phone-verification.md +7 -14
  35. package/docs/examples/account/update-phone.md +7 -14
  36. package/docs/examples/account/update-prefs.md +6 -14
  37. package/docs/examples/account/update-recovery.md +8 -14
  38. package/docs/examples/account/update-session.md +6 -14
  39. package/docs/examples/account/update-status.md +4 -14
  40. package/docs/examples/account/update-verification.md +7 -14
  41. package/docs/examples/account/verify-authenticator.md +13 -0
  42. package/docs/examples/avatars/get-browser.md +9 -14
  43. package/docs/examples/avatars/get-credit-card.md +9 -14
  44. package/docs/examples/avatars/get-favicon.md +6 -14
  45. package/docs/examples/avatars/get-flag.md +9 -14
  46. package/docs/examples/avatars/get-image.md +8 -14
  47. package/docs/examples/avatars/get-initials.md +9 -14
  48. package/docs/examples/avatars/get-q-r.md +9 -14
  49. package/docs/examples/databases/create-boolean-attribute.md +11 -14
  50. package/docs/examples/databases/create-collection.md +11 -14
  51. package/docs/examples/databases/create-datetime-attribute.md +11 -14
  52. package/docs/examples/databases/create-document.md +10 -14
  53. package/docs/examples/databases/create-email-attribute.md +11 -14
  54. package/docs/examples/databases/create-enum-attribute.md +12 -14
  55. package/docs/examples/databases/create-float-attribute.md +13 -14
  56. package/docs/examples/databases/create-index.md +11 -14
  57. package/docs/examples/databases/create-integer-attribute.md +13 -14
  58. package/docs/examples/databases/create-ip-attribute.md +11 -14
  59. package/docs/examples/databases/create-relationship-attribute.md +13 -14
  60. package/docs/examples/databases/create-string-attribute.md +13 -14
  61. package/docs/examples/databases/create-url-attribute.md +11 -14
  62. package/docs/examples/databases/create.md +8 -14
  63. package/docs/examples/databases/delete-attribute.md +8 -14
  64. package/docs/examples/databases/delete-collection.md +7 -14
  65. package/docs/examples/databases/delete-document.md +8 -14
  66. package/docs/examples/databases/delete-index.md +8 -14
  67. package/docs/examples/databases/delete.md +6 -14
  68. package/docs/examples/databases/get-attribute.md +8 -14
  69. package/docs/examples/databases/get-collection.md +7 -14
  70. package/docs/examples/databases/get-document.md +9 -14
  71. package/docs/examples/databases/get-index.md +8 -14
  72. package/docs/examples/databases/get.md +6 -14
  73. package/docs/examples/databases/list-attributes.md +8 -14
  74. package/docs/examples/databases/list-collections.md +8 -14
  75. package/docs/examples/databases/list-documents.md +8 -14
  76. package/docs/examples/databases/list-indexes.md +8 -14
  77. package/docs/examples/databases/list.md +7 -14
  78. package/docs/examples/databases/update-boolean-attribute.md +10 -14
  79. package/docs/examples/databases/update-collection.md +11 -14
  80. package/docs/examples/databases/update-datetime-attribute.md +10 -14
  81. package/docs/examples/databases/update-document.md +10 -14
  82. package/docs/examples/databases/update-email-attribute.md +10 -14
  83. package/docs/examples/databases/update-enum-attribute.md +11 -14
  84. package/docs/examples/databases/update-float-attribute.md +12 -14
  85. package/docs/examples/databases/update-integer-attribute.md +12 -14
  86. package/docs/examples/databases/update-ip-attribute.md +10 -14
  87. package/docs/examples/databases/update-relationship-attribute.md +9 -14
  88. package/docs/examples/databases/update-string-attribute.md +10 -14
  89. package/docs/examples/databases/update-url-attribute.md +10 -14
  90. package/docs/examples/databases/update.md +8 -14
  91. package/docs/examples/functions/create-build.md +8 -14
  92. package/docs/examples/functions/create-deployment.md +10 -14
  93. package/docs/examples/functions/create-execution.md +11 -14
  94. package/docs/examples/functions/create-variable.md +8 -14
  95. package/docs/examples/functions/create.md +25 -14
  96. package/docs/examples/functions/delete-deployment.md +7 -14
  97. package/docs/examples/functions/delete-variable.md +7 -14
  98. package/docs/examples/functions/delete.md +6 -14
  99. package/docs/examples/functions/download-deployment.md +7 -14
  100. package/docs/examples/functions/get-deployment.md +7 -14
  101. package/docs/examples/functions/get-execution.md +7 -14
  102. package/docs/examples/functions/get-variable.md +7 -14
  103. package/docs/examples/functions/get.md +6 -14
  104. package/docs/examples/functions/list-deployments.md +8 -14
  105. package/docs/examples/functions/list-executions.md +8 -14
  106. package/docs/examples/functions/list-runtimes.md +4 -14
  107. package/docs/examples/functions/list-variables.md +6 -14
  108. package/docs/examples/functions/list.md +7 -14
  109. package/docs/examples/functions/update-deployment.md +7 -14
  110. package/docs/examples/functions/update-variable.md +9 -14
  111. package/docs/examples/functions/update.md +21 -14
  112. package/docs/examples/graphql/mutation.md +6 -14
  113. package/docs/examples/graphql/query.md +6 -14
  114. package/docs/examples/health/get-antivirus.md +4 -14
  115. package/docs/examples/health/get-cache.md +4 -14
  116. package/docs/examples/health/get-certificate.md +12 -0
  117. package/docs/examples/health/get-d-b.md +4 -14
  118. package/docs/examples/health/get-failed-jobs.md +13 -0
  119. package/docs/examples/health/get-pub-sub.md +4 -14
  120. package/docs/examples/health/get-queue-builds.md +12 -0
  121. package/docs/examples/health/get-queue-certificates.md +6 -14
  122. package/docs/examples/health/get-queue-databases.md +13 -0
  123. package/docs/examples/health/get-queue-deletes.md +12 -0
  124. package/docs/examples/health/get-queue-functions.md +6 -14
  125. package/docs/examples/health/get-queue-logs.md +6 -14
  126. package/docs/examples/health/get-queue-mails.md +12 -0
  127. package/docs/examples/health/get-queue-messaging.md +12 -0
  128. package/docs/examples/health/get-queue-migrations.md +12 -0
  129. package/docs/examples/health/get-queue-webhooks.md +6 -14
  130. package/docs/examples/health/get-queue.md +4 -14
  131. package/docs/examples/health/get-storage-local.md +4 -14
  132. package/docs/examples/health/get-time.md +4 -14
  133. package/docs/examples/health/get.md +4 -14
  134. package/docs/examples/locale/get.md +4 -14
  135. package/docs/examples/locale/list-codes.md +4 -14
  136. package/docs/examples/locale/list-continents.md +4 -14
  137. package/docs/examples/locale/list-countries-e-u.md +4 -14
  138. package/docs/examples/locale/list-countries-phones.md +4 -14
  139. package/docs/examples/locale/list-countries.md +4 -14
  140. package/docs/examples/locale/list-currencies.md +4 -14
  141. package/docs/examples/locale/list-languages.md +4 -14
  142. package/docs/examples/messaging/create-apns-provider.md +18 -0
  143. package/docs/examples/messaging/create-email.md +23 -0
  144. package/docs/examples/messaging/create-fcm-provider.md +15 -0
  145. package/docs/examples/messaging/create-mailgun-provider.md +21 -0
  146. package/docs/examples/messaging/create-msg91provider.md +17 -0
  147. package/docs/examples/messaging/create-push.md +27 -0
  148. package/docs/examples/messaging/create-sendgrid-provider.md +19 -0
  149. package/docs/examples/messaging/create-sms.md +18 -0
  150. package/docs/examples/messaging/create-smtp-provider.md +25 -0
  151. package/docs/examples/messaging/create-subscriber.md +14 -0
  152. package/docs/examples/messaging/create-telesign-provider.md +17 -0
  153. package/docs/examples/messaging/create-textmagic-provider.md +17 -0
  154. package/docs/examples/messaging/create-topic.md +14 -0
  155. package/docs/examples/messaging/create-twilio-provider.md +17 -0
  156. package/docs/examples/messaging/create-vonage-provider.md +17 -0
  157. package/docs/examples/messaging/delete-provider.md +12 -0
  158. package/docs/examples/messaging/delete-subscriber.md +13 -0
  159. package/docs/examples/messaging/delete-topic.md +12 -0
  160. package/docs/examples/messaging/delete.md +12 -0
  161. package/docs/examples/messaging/get-message.md +12 -0
  162. package/docs/examples/messaging/get-provider.md +12 -0
  163. package/docs/examples/messaging/get-subscriber.md +13 -0
  164. package/docs/examples/messaging/get-topic.md +12 -0
  165. package/docs/examples/messaging/list-message-logs.md +13 -0
  166. package/docs/examples/messaging/list-messages.md +13 -0
  167. package/docs/examples/messaging/list-provider-logs.md +13 -0
  168. package/docs/examples/messaging/list-providers.md +13 -0
  169. package/docs/examples/messaging/list-subscriber-logs.md +13 -0
  170. package/docs/examples/messaging/list-subscribers.md +14 -0
  171. package/docs/examples/messaging/list-targets.md +13 -0
  172. package/docs/examples/messaging/list-topic-logs.md +13 -0
  173. package/docs/examples/messaging/list-topics.md +13 -0
  174. package/docs/examples/messaging/update-a-p-n-s-provider.md +18 -0
  175. package/docs/examples/messaging/update-email.md +22 -0
  176. package/docs/examples/messaging/update-f-c-m-provider.md +15 -0
  177. package/docs/examples/messaging/update-mailgun-provider.md +21 -0
  178. package/docs/examples/messaging/update-msg91provider.md +17 -0
  179. package/docs/examples/messaging/update-push.md +27 -0
  180. package/docs/examples/messaging/update-sendgrid-provider.md +19 -0
  181. package/docs/examples/messaging/update-sms.md +18 -0
  182. package/docs/examples/messaging/update-smtp-provider.md +25 -0
  183. package/docs/examples/messaging/update-telesign-provider.md +17 -0
  184. package/docs/examples/messaging/update-textmagic-provider.md +17 -0
  185. package/docs/examples/messaging/update-topic.md +13 -0
  186. package/docs/examples/messaging/update-twilio-provider.md +17 -0
  187. package/docs/examples/messaging/update-vonage-provider.md +17 -0
  188. package/docs/examples/storage/create-bucket.md +15 -14
  189. package/docs/examples/storage/create-file.md +9 -14
  190. package/docs/examples/storage/delete-bucket.md +6 -14
  191. package/docs/examples/storage/delete-file.md +7 -14
  192. package/docs/examples/storage/get-bucket.md +6 -14
  193. package/docs/examples/storage/get-file-download.md +7 -14
  194. package/docs/examples/storage/get-file-preview.md +18 -14
  195. package/docs/examples/storage/get-file-view.md +7 -14
  196. package/docs/examples/storage/get-file.md +7 -14
  197. package/docs/examples/storage/list-buckets.md +7 -14
  198. package/docs/examples/storage/list-files.md +8 -14
  199. package/docs/examples/storage/update-bucket.md +15 -14
  200. package/docs/examples/storage/update-file.md +9 -14
  201. package/docs/examples/teams/create-membership.md +12 -14
  202. package/docs/examples/teams/create.md +8 -14
  203. package/docs/examples/teams/delete-membership.md +7 -14
  204. package/docs/examples/teams/delete.md +6 -14
  205. package/docs/examples/teams/get-membership.md +7 -14
  206. package/docs/examples/teams/get-prefs.md +6 -14
  207. package/docs/examples/teams/get.md +6 -14
  208. package/docs/examples/teams/list-memberships.md +8 -14
  209. package/docs/examples/teams/list.md +7 -14
  210. package/docs/examples/teams/update-membership-status.md +9 -14
  211. package/docs/examples/teams/update-membership.md +8 -14
  212. package/docs/examples/teams/update-name.md +7 -14
  213. package/docs/examples/teams/update-prefs.md +7 -14
  214. package/docs/examples/users/create-argon2user.md +9 -14
  215. package/docs/examples/users/create-bcrypt-user.md +9 -14
  216. package/docs/examples/users/create-m-d5user.md +9 -14
  217. package/docs/examples/users/create-p-h-pass-user.md +9 -14
  218. package/docs/examples/users/create-s-h-a-user.md +10 -14
  219. package/docs/examples/users/create-scrypt-modified-user.md +12 -14
  220. package/docs/examples/users/create-scrypt-user.md +14 -14
  221. package/docs/examples/users/create-session.md +12 -0
  222. package/docs/examples/users/create-target.md +17 -0
  223. package/docs/examples/users/create-token.md +14 -0
  224. package/docs/examples/users/create.md +10 -14
  225. package/docs/examples/users/delete-authenticator.md +14 -0
  226. package/docs/examples/users/delete-identity.md +6 -14
  227. package/docs/examples/users/delete-session.md +7 -14
  228. package/docs/examples/users/delete-sessions.md +6 -14
  229. package/docs/examples/users/delete-target.md +13 -0
  230. package/docs/examples/users/delete.md +6 -14
  231. package/docs/examples/users/get-prefs.md +6 -14
  232. package/docs/examples/users/get-target.md +13 -0
  233. package/docs/examples/users/get.md +6 -14
  234. package/docs/examples/users/list-factors.md +12 -0
  235. package/docs/examples/users/list-identities.md +7 -14
  236. package/docs/examples/users/list-logs.md +7 -14
  237. package/docs/examples/users/list-memberships.md +6 -14
  238. package/docs/examples/users/list-sessions.md +6 -14
  239. package/docs/examples/users/list-targets.md +13 -0
  240. package/docs/examples/users/list.md +7 -14
  241. package/docs/examples/users/update-email-verification.md +7 -14
  242. package/docs/examples/users/update-email.md +7 -14
  243. package/docs/examples/users/update-labels.md +7 -14
  244. package/docs/examples/users/update-mfa.md +13 -0
  245. package/docs/examples/users/update-name.md +7 -14
  246. package/docs/examples/users/update-password.md +7 -14
  247. package/docs/examples/users/update-phone-verification.md +7 -14
  248. package/docs/examples/users/update-phone.md +7 -14
  249. package/docs/examples/users/update-prefs.md +7 -14
  250. package/docs/examples/users/update-status.md +7 -14
  251. package/docs/examples/users/update-target.md +16 -0
  252. package/index.d.ts +2280 -309
  253. package/index.js +40 -0
  254. package/lib/client.js +122 -65
  255. package/lib/enums/authentication-factor.js +7 -0
  256. package/lib/enums/authenticator-type.js +5 -0
  257. package/lib/enums/browser.js +18 -0
  258. package/lib/enums/compression.js +7 -0
  259. package/lib/enums/credit-card.js +20 -0
  260. package/lib/enums/encryption.js +7 -0
  261. package/lib/enums/execution-method.js +10 -0
  262. package/lib/enums/flag.js +198 -0
  263. package/lib/enums/image-format.js +9 -0
  264. package/lib/enums/image-gravity.js +13 -0
  265. package/lib/enums/index-type.js +8 -0
  266. package/lib/enums/message-status.js +7 -0
  267. package/lib/enums/messaging-provider-type.js +7 -0
  268. package/lib/enums/name.js +16 -0
  269. package/lib/enums/o-auth-provider.js +43 -0
  270. package/lib/enums/password-hash.js +15 -0
  271. package/lib/enums/relation-mutate.js +7 -0
  272. package/lib/enums/relationship-type.js +8 -0
  273. package/lib/enums/runtime.js +40 -0
  274. package/lib/inputFile.js +88 -16
  275. package/lib/query.js +56 -38
  276. package/lib/services/account.js +639 -46
  277. package/lib/services/avatars.js +16 -13
  278. package/lib/services/databases.js +54 -52
  279. package/lib/services/functions.js +77 -109
  280. package/lib/services/graphql.js +4 -2
  281. package/lib/services/health.js +229 -14
  282. package/lib/services/locale.js +9 -7
  283. package/lib/services/messaging.js +2198 -0
  284. package/lib/services/storage.js +64 -100
  285. package/lib/services/teams.js +19 -17
  286. package/lib/services/users.js +367 -45
  287. package/package.json +2 -3
@@ -5,6 +5,8 @@ const client = require('../client.js');
5
5
  const Stream = require('stream');
6
6
  const { promisify } = require('util');
7
7
  const fs = require('fs');
8
+ const { File } = require('undici');
9
+ const Query = require('../query.js');
8
10
 
9
11
  class Functions extends Service {
10
12
 
@@ -15,7 +17,7 @@ class Functions extends Service {
15
17
 
16
18
 
17
19
  /**
18
- * List Functions
20
+ * List functions
19
21
  *
20
22
  * Get a list of all the project's functions. You can use the query params to
21
23
  * filter your results.
@@ -43,15 +45,16 @@ class Functions extends Service {
43
45
  }
44
46
 
45
47
  /**
46
- * Create Function
48
+ * Create function
47
49
  *
48
50
  * Create a new function. You can pass a list of
49
- * [permissions](/docs/permissions) to allow different project users or team
50
- * with access to execute the function using the client API.
51
+ * [permissions](https://appwrite.io/docs/permissions) to allow different
52
+ * project users or team with access to execute the function using the client
53
+ * API.
51
54
  *
52
55
  * @param {string} functionId
53
56
  * @param {string} name
54
- * @param {string} runtime
57
+ * @param {Runtime} runtime
55
58
  * @param {string[]} execute
56
59
  * @param {string[]} events
57
60
  * @param {string} schedule
@@ -191,7 +194,7 @@ class Functions extends Service {
191
194
  }
192
195
 
193
196
  /**
194
- * Get Function
197
+ * Get function
195
198
  *
196
199
  * Get a function by its unique ID.
197
200
  *
@@ -213,13 +216,13 @@ class Functions extends Service {
213
216
  }
214
217
 
215
218
  /**
216
- * Update Function
219
+ * Update function
217
220
  *
218
221
  * Update function by its unique ID.
219
222
  *
220
223
  * @param {string} functionId
221
224
  * @param {string} name
222
- * @param {string} runtime
225
+ * @param {Runtime} runtime
223
226
  * @param {string[]} execute
224
227
  * @param {string[]} events
225
228
  * @param {string} schedule
@@ -314,7 +317,7 @@ class Functions extends Service {
314
317
  }
315
318
 
316
319
  /**
317
- * Delete Function
320
+ * Delete function
318
321
  *
319
322
  * Delete a function by its unique ID.
320
323
  *
@@ -336,7 +339,7 @@ class Functions extends Service {
336
339
  }
337
340
 
338
341
  /**
339
- * List Deployments
342
+ * List deployments
340
343
  *
341
344
  * Get a list of all the project's code deployments. You can use the query
342
345
  * params to filter your results.
@@ -369,7 +372,7 @@ class Functions extends Service {
369
372
  }
370
373
 
371
374
  /**
372
- * Create Deployment
375
+ * Create deployment
373
376
  *
374
377
  * Create a new function code deployment. Use this endpoint to upload a new
375
378
  * version of your code function. To execute your newly uploaded code, you'll
@@ -378,7 +381,7 @@ class Functions extends Service {
378
381
  * This endpoint accepts a tar.gz file compressed with your code. Make sure to
379
382
  * include any dependencies your code has within the compressed file. You can
380
383
  * learn more about code packaging in the [Appwrite Cloud Functions
381
- * tutorial](/docs/functions).
384
+ * tutorial](https://appwrite.io/docs/functions).
382
385
  *
383
386
  * Use the "command" param to set the entrypoint used to execute your code.
384
387
  *
@@ -387,6 +390,7 @@ class Functions extends Service {
387
390
  * @param {boolean} activate
388
391
  * @param {string} entrypoint
389
392
  * @param {string} commands
393
+ * @param {CallableFunction} onProgress
390
394
  * @throws {AppwriteException}
391
395
  * @returns {Promise}
392
396
  */
@@ -422,8 +426,9 @@ class Functions extends Service {
422
426
  payload['activate'] = activate.toString();
423
427
  }
424
428
 
425
- const size = code.size;
426
429
 
430
+ const size = code.size;
431
+
427
432
  const apiHeaders = {
428
433
  'content-type': 'multipart/form-data',
429
434
  };
@@ -434,123 +439,83 @@ class Functions extends Service {
434
439
  let chunksUploaded = 0;
435
440
 
436
441
 
437
- let currentChunk = Buffer.from('');
438
- let currentChunkSize = 0;
439
- let currentChunkStart = 0;
440
-
441
- const selfClient = this.client;
442
+ let currentChunk = 1;
443
+ let currentPosition = 0;
444
+ let uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
445
+
442
446
 
443
- async function uploadChunk(lastUpload = false) {
444
- if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
447
+ const uploadChunk = async (lastUpload = false) => {
448
+ if(currentChunk <= chunksUploaded) {
445
449
  return;
446
450
  }
447
-
448
- const start = currentChunkStart;
449
- const end = currentChunkStart + currentChunkSize - 1;
450
451
 
451
- if(!lastUpload || currentChunkStart !== 0) {
452
+ const start = ((currentChunk - 1) * client.CHUNK_SIZE);
453
+ let end = start + currentPosition - 1;
454
+
455
+ if(!lastUpload || currentChunk !== 1) {
452
456
  apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
453
457
  }
454
458
 
459
+ let uploadableChunkTrimmed;
460
+
461
+ if(currentPosition + 1 >= client.CHUNK_SIZE) {
462
+ uploadableChunkTrimmed = uploadableChunk;
463
+ } else {
464
+ uploadableChunkTrimmed = new Uint8Array(currentPosition);
465
+ for(let i = 0; i <= currentPosition; i++) {
466
+ uploadableChunkTrimmed[i] = uploadableChunk[i];
467
+ }
468
+ }
469
+
455
470
  if (id) {
456
471
  apiHeaders['x-appwrite-id'] = id;
457
472
  }
458
473
 
459
- payload['code'] = {
460
- type: 'file',
461
- file: currentChunk,
462
- filename: code.filename,
463
- size: currentChunkSize
464
- };
474
+ payload['code'] = { type: 'file', file: new File([uploadableChunkTrimmed], code.filename), filename: code.filename };
465
475
 
466
- response = await selfClient.call('post', apiPath, apiHeaders, payload);
476
+ response = await this.client.call('post', apiPath, apiHeaders, payload);
467
477
 
468
478
  if (!id) {
469
479
  id = response['$id'];
470
480
  }
471
-
481
+
472
482
  if (onProgress !== null) {
473
483
  onProgress({
474
484
  $id: response['$id'],
475
- progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
485
+ progress: Math.min((currentChunk) * client.CHUNK_SIZE, size) / size * 100,
476
486
  sizeUploaded: end+1,
477
487
  chunksTotal: response['chunksTotal'],
478
488
  chunksUploaded: response['chunksUploaded']
479
489
  });
480
490
  }
481
491
 
482
- currentChunkStart += client.CHUNK_SIZE;
483
- }
484
-
485
- return await new Promise((resolve, reject) => {
486
- const writeStream = new Stream.Writable();
487
- writeStream._write = async (mainChunk, encoding, callback) => {
488
- try {
489
- // Segment incoming chunk into up to 5MB chunks
490
- const mainChunkSize = Buffer.byteLength(mainChunk);
491
- const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
492
- const chunks = [];
493
-
494
- for(let i = 0; i < chunksCount; i++) {
495
- const chunk = mainChunk.slice(i * client.CHUNK_SIZE, (i + 1) * client.CHUNK_SIZE);
496
- chunks.push(chunk);
497
- }
498
-
499
- for (const chunk of chunks) {
500
- const chunkSize = Buffer.byteLength(chunk);
501
-
502
- if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
503
- // Upload chunk
504
- currentChunk = Buffer.concat([currentChunk, chunk]);
505
- currentChunkSize = Buffer.byteLength(currentChunk);
506
- await uploadChunk();
507
- currentChunk = Buffer.from('');
508
- currentChunkSize = 0;
509
- } else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
510
- // Upload chunk, put rest into next chunk
511
- const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
512
- const newChunkSection = chunk.slice(0, bytesToUpload);
513
- currentChunk = Buffer.concat([currentChunk, newChunkSection]);
514
- currentChunkSize = Buffer.byteLength(currentChunk);
515
- await uploadChunk();
516
- currentChunk = chunk.slice(bytesToUpload, undefined);
517
- currentChunkSize = chunkSize - bytesToUpload;
518
- } else {
519
- // Append into current chunk
520
- currentChunk = Buffer.concat([currentChunk, chunk]);
521
- currentChunkSize = chunkSize + currentChunkSize;
522
- }
523
- }
524
-
525
- callback();
526
- } catch (e) {
527
- callback(e);
492
+ uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
493
+ currentChunk++;
494
+ currentPosition = 0;
495
+ }
496
+
497
+ for await (const chunk of code.stream) {
498
+ for(const b of chunk) {
499
+ uploadableChunk[currentPosition] = b;
500
+
501
+ currentPosition++;
502
+ if(currentPosition >= client.CHUNK_SIZE) {
503
+ await uploadChunk();
504
+ currentPosition = 0;
528
505
  }
529
506
  }
507
+ }
530
508
 
531
- writeStream.on("finish", async () => {
532
- if(currentChunkSize > 0) {
533
- try {
534
- await uploadChunk(true);
535
- } catch (e) {
536
- reject(e);
537
- }
538
- }
539
-
540
- resolve(response);
541
- });
509
+ if (currentPosition > 0) { // Check if there's any remaining data for the last chunk
510
+ await uploadChunk(true);
511
+ }
542
512
 
543
- writeStream.on("error", (err) => {
544
- reject(err);
545
- });
546
-
547
- code.stream.pipe(writeStream);
548
- });
513
+ return response;
549
514
 
550
515
  }
551
516
 
552
517
  /**
553
- * Get Deployment
518
+ * Get deployment
554
519
  *
555
520
  * Get a code deployment by its unique ID.
556
521
  *
@@ -577,7 +542,7 @@ class Functions extends Service {
577
542
  }
578
543
 
579
544
  /**
580
- * Update Function Deployment
545
+ * Update function deployment
581
546
  *
582
547
  * Update the function code deployment ID using the unique function ID. Use
583
548
  * this endpoint to switch the code deployment that should be executed by the
@@ -606,7 +571,7 @@ class Functions extends Service {
606
571
  }
607
572
 
608
573
  /**
609
- * Delete Deployment
574
+ * Delete deployment
610
575
  *
611
576
  * Delete a code deployment by its unique ID.
612
577
  *
@@ -633,7 +598,7 @@ class Functions extends Service {
633
598
  }
634
599
 
635
600
  /**
636
- * Create Build
601
+ * Create build
637
602
  *
638
603
  * Create a new build for an Appwrite Function deployment. This endpoint can
639
604
  * be used to retry a failed build.
@@ -668,6 +633,9 @@ class Functions extends Service {
668
633
  /**
669
634
  * Download Deployment
670
635
  *
636
+ * Get a Deployment's contents by its unique ID. This endpoint supports range
637
+ * requests for partial or streaming file download.
638
+ *
671
639
  * @param {string} functionId
672
640
  * @param {string} deploymentId
673
641
  * @throws {AppwriteException}
@@ -691,7 +659,7 @@ class Functions extends Service {
691
659
  }
692
660
 
693
661
  /**
694
- * List Executions
662
+ * List executions
695
663
  *
696
664
  * Get a list of all the current user function execution logs. You can use the
697
665
  * query params to filter your results.
@@ -724,7 +692,7 @@ class Functions extends Service {
724
692
  }
725
693
 
726
694
  /**
727
- * Create Execution
695
+ * Create execution
728
696
  *
729
697
  * Trigger a function execution. The returned object will return you the
730
698
  * current execution status. You can ping the `Get Execution` endpoint to get
@@ -735,7 +703,7 @@ class Functions extends Service {
735
703
  * @param {string} body
736
704
  * @param {boolean} async
737
705
  * @param {string} xpath
738
- * @param {string} method
706
+ * @param {ExecutionMethod} method
739
707
  * @param {object} headers
740
708
  * @throws {AppwriteException}
741
709
  * @returns {Promise}
@@ -774,7 +742,7 @@ class Functions extends Service {
774
742
  }
775
743
 
776
744
  /**
777
- * Get Execution
745
+ * Get execution
778
746
  *
779
747
  * Get a function execution log by its unique ID.
780
748
  *
@@ -801,7 +769,7 @@ class Functions extends Service {
801
769
  }
802
770
 
803
771
  /**
804
- * List Variables
772
+ * List variables
805
773
  *
806
774
  * Get a list of all variables of a specific function.
807
775
  *
@@ -823,7 +791,7 @@ class Functions extends Service {
823
791
  }
824
792
 
825
793
  /**
826
- * Create Variable
794
+ * Create variable
827
795
  *
828
796
  * Create a new function environment variable. These variables can be accessed
829
797
  * in the function at runtime as environment variables.
@@ -864,7 +832,7 @@ class Functions extends Service {
864
832
  }
865
833
 
866
834
  /**
867
- * Get Variable
835
+ * Get variable
868
836
  *
869
837
  * Get a variable by its unique ID.
870
838
  *
@@ -891,7 +859,7 @@ class Functions extends Service {
891
859
  }
892
860
 
893
861
  /**
894
- * Update Variable
862
+ * Update variable
895
863
  *
896
864
  * Update variable by its unique ID.
897
865
  *
@@ -932,7 +900,7 @@ class Functions extends Service {
932
900
  }
933
901
 
934
902
  /**
935
- * Delete Variable
903
+ * Delete variable
936
904
  *
937
905
  * Delete a variable by its unique ID.
938
906
  *
@@ -5,6 +5,8 @@ const client = require('../client.js');
5
5
  const Stream = require('stream');
6
6
  const { promisify } = require('util');
7
7
  const fs = require('fs');
8
+ const { File } = require('undici');
9
+ const Query = require('../query.js');
8
10
 
9
11
  class Graphql extends Service {
10
12
 
@@ -15,7 +17,7 @@ class Graphql extends Service {
15
17
 
16
18
 
17
19
  /**
18
- * GraphQL Endpoint
20
+ * GraphQL endpoint
19
21
  *
20
22
  * Execute a GraphQL mutation.
21
23
  *
@@ -42,7 +44,7 @@ class Graphql extends Service {
42
44
  }
43
45
 
44
46
  /**
45
- * GraphQL Endpoint
47
+ * GraphQL endpoint
46
48
  *
47
49
  * Execute a GraphQL mutation.
48
50
  *