node-appwrite 11.1.1 → 12.0.0

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 (297) hide show
  1. package/.travis.yml +2 -2
  2. package/LICENSE +1 -1
  3. package/README.md +6 -6
  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-mfa-authenticator.md +12 -0
  10. package/docs/examples/account/create-mfa-challenge.md +11 -0
  11. package/docs/examples/account/create-mfa-recovery-codes.md +10 -0
  12. package/docs/examples/account/create-o-auth2token.md +14 -0
  13. package/docs/examples/account/create-phone-token.md +12 -0
  14. package/docs/examples/account/create-phone-verification.md +4 -14
  15. package/docs/examples/account/create-recovery.md +7 -14
  16. package/docs/examples/account/create-session.md +12 -0
  17. package/docs/examples/account/create-verification.md +6 -14
  18. package/docs/examples/account/create.md +14 -0
  19. package/docs/examples/account/delete-identity.md +6 -14
  20. package/docs/examples/account/delete-mfa-authenticator.md +13 -0
  21. package/docs/examples/account/delete-session.md +6 -14
  22. package/docs/examples/account/delete-sessions.md +4 -14
  23. package/docs/examples/account/get-mfa-recovery-codes.md +10 -0
  24. package/docs/examples/account/get-prefs.md +4 -14
  25. package/docs/examples/account/get-session.md +6 -14
  26. package/docs/examples/account/get.md +4 -14
  27. package/docs/examples/account/list-identities.md +6 -14
  28. package/docs/examples/account/list-logs.md +6 -14
  29. package/docs/examples/account/list-mfa-factors.md +10 -0
  30. package/docs/examples/account/list-sessions.md +4 -14
  31. package/docs/examples/account/update-email.md +7 -14
  32. package/docs/examples/account/update-m-f-a.md +12 -0
  33. package/docs/examples/account/update-magic-u-r-l-session.md +12 -0
  34. package/docs/examples/account/update-mfa-authenticator.md +13 -0
  35. package/docs/examples/account/update-mfa-challenge.md +13 -0
  36. package/docs/examples/account/update-mfa-recovery-codes.md +10 -0
  37. package/docs/examples/account/update-name.md +6 -14
  38. package/docs/examples/account/update-password.md +7 -14
  39. package/docs/examples/account/update-phone-session.md +12 -0
  40. package/docs/examples/account/update-phone-verification.md +7 -14
  41. package/docs/examples/account/update-phone.md +7 -14
  42. package/docs/examples/account/update-prefs.md +6 -14
  43. package/docs/examples/account/update-recovery.md +8 -14
  44. package/docs/examples/account/update-session.md +6 -14
  45. package/docs/examples/account/update-status.md +4 -14
  46. package/docs/examples/account/update-verification.md +7 -14
  47. package/docs/examples/avatars/get-browser.md +9 -14
  48. package/docs/examples/avatars/get-credit-card.md +9 -14
  49. package/docs/examples/avatars/get-favicon.md +6 -14
  50. package/docs/examples/avatars/get-flag.md +9 -14
  51. package/docs/examples/avatars/get-image.md +8 -14
  52. package/docs/examples/avatars/get-initials.md +9 -14
  53. package/docs/examples/avatars/get-q-r.md +9 -14
  54. package/docs/examples/databases/create-boolean-attribute.md +11 -14
  55. package/docs/examples/databases/create-collection.md +11 -14
  56. package/docs/examples/databases/create-datetime-attribute.md +11 -14
  57. package/docs/examples/databases/create-document.md +10 -14
  58. package/docs/examples/databases/create-email-attribute.md +11 -14
  59. package/docs/examples/databases/create-enum-attribute.md +12 -14
  60. package/docs/examples/databases/create-float-attribute.md +13 -14
  61. package/docs/examples/databases/create-index.md +11 -14
  62. package/docs/examples/databases/create-integer-attribute.md +13 -14
  63. package/docs/examples/databases/create-ip-attribute.md +11 -14
  64. package/docs/examples/databases/create-relationship-attribute.md +13 -14
  65. package/docs/examples/databases/create-string-attribute.md +13 -14
  66. package/docs/examples/databases/create-url-attribute.md +11 -14
  67. package/docs/examples/databases/create.md +8 -14
  68. package/docs/examples/databases/delete-attribute.md +8 -14
  69. package/docs/examples/databases/delete-collection.md +7 -14
  70. package/docs/examples/databases/delete-document.md +8 -14
  71. package/docs/examples/databases/delete-index.md +8 -14
  72. package/docs/examples/databases/delete.md +6 -14
  73. package/docs/examples/databases/get-attribute.md +8 -14
  74. package/docs/examples/databases/get-collection.md +7 -14
  75. package/docs/examples/databases/get-document.md +9 -14
  76. package/docs/examples/databases/get-index.md +8 -14
  77. package/docs/examples/databases/get.md +6 -14
  78. package/docs/examples/databases/list-attributes.md +8 -14
  79. package/docs/examples/databases/list-collections.md +8 -14
  80. package/docs/examples/databases/list-documents.md +8 -14
  81. package/docs/examples/databases/list-indexes.md +8 -14
  82. package/docs/examples/databases/list.md +7 -14
  83. package/docs/examples/databases/update-boolean-attribute.md +10 -14
  84. package/docs/examples/databases/update-collection.md +11 -14
  85. package/docs/examples/databases/update-datetime-attribute.md +10 -14
  86. package/docs/examples/databases/update-document.md +10 -14
  87. package/docs/examples/databases/update-email-attribute.md +10 -14
  88. package/docs/examples/databases/update-enum-attribute.md +11 -14
  89. package/docs/examples/databases/update-float-attribute.md +12 -14
  90. package/docs/examples/databases/update-integer-attribute.md +12 -14
  91. package/docs/examples/databases/update-ip-attribute.md +10 -14
  92. package/docs/examples/databases/update-relationship-attribute.md +9 -14
  93. package/docs/examples/databases/update-string-attribute.md +10 -14
  94. package/docs/examples/databases/update-url-attribute.md +10 -14
  95. package/docs/examples/databases/update.md +8 -14
  96. package/docs/examples/functions/create-build.md +8 -14
  97. package/docs/examples/functions/create-deployment.md +10 -14
  98. package/docs/examples/functions/create-execution.md +11 -14
  99. package/docs/examples/functions/create-variable.md +8 -14
  100. package/docs/examples/functions/create.md +25 -14
  101. package/docs/examples/functions/delete-deployment.md +7 -14
  102. package/docs/examples/functions/delete-variable.md +7 -14
  103. package/docs/examples/functions/delete.md +6 -14
  104. package/docs/examples/functions/download-deployment.md +7 -14
  105. package/docs/examples/functions/get-deployment.md +7 -14
  106. package/docs/examples/functions/get-execution.md +7 -14
  107. package/docs/examples/functions/get-variable.md +7 -14
  108. package/docs/examples/functions/get.md +6 -14
  109. package/docs/examples/functions/list-deployments.md +8 -14
  110. package/docs/examples/functions/list-executions.md +8 -14
  111. package/docs/examples/functions/list-runtimes.md +4 -14
  112. package/docs/examples/functions/list-variables.md +6 -14
  113. package/docs/examples/functions/list.md +7 -14
  114. package/docs/examples/functions/update-deployment.md +7 -14
  115. package/docs/examples/functions/update-variable.md +9 -14
  116. package/docs/examples/functions/update.md +21 -14
  117. package/docs/examples/graphql/mutation.md +6 -14
  118. package/docs/examples/graphql/query.md +6 -14
  119. package/docs/examples/health/get-antivirus.md +4 -14
  120. package/docs/examples/health/get-cache.md +4 -14
  121. package/docs/examples/health/get-certificate.md +12 -0
  122. package/docs/examples/health/get-d-b.md +4 -14
  123. package/docs/examples/health/get-failed-jobs.md +13 -0
  124. package/docs/examples/health/get-pub-sub.md +4 -14
  125. package/docs/examples/health/get-queue-builds.md +6 -14
  126. package/docs/examples/health/get-queue-certificates.md +6 -14
  127. package/docs/examples/health/get-queue-databases.md +7 -14
  128. package/docs/examples/health/get-queue-deletes.md +6 -14
  129. package/docs/examples/health/get-queue-functions.md +6 -14
  130. package/docs/examples/health/get-queue-logs.md +6 -14
  131. package/docs/examples/health/get-queue-mails.md +6 -14
  132. package/docs/examples/health/get-queue-messaging.md +6 -14
  133. package/docs/examples/health/get-queue-migrations.md +6 -14
  134. package/docs/examples/health/get-queue-usage-dump.md +12 -0
  135. package/docs/examples/health/get-queue-usage.md +12 -0
  136. package/docs/examples/health/get-queue-webhooks.md +6 -14
  137. package/docs/examples/health/get-queue.md +4 -14
  138. package/docs/examples/health/get-storage-local.md +4 -14
  139. package/docs/examples/health/get-storage.md +10 -0
  140. package/docs/examples/health/get-time.md +4 -14
  141. package/docs/examples/health/get.md +4 -14
  142. package/docs/examples/locale/get.md +4 -14
  143. package/docs/examples/locale/list-codes.md +4 -14
  144. package/docs/examples/locale/list-continents.md +4 -14
  145. package/docs/examples/locale/list-countries-e-u.md +4 -14
  146. package/docs/examples/locale/list-countries-phones.md +4 -14
  147. package/docs/examples/locale/list-countries.md +4 -14
  148. package/docs/examples/locale/list-currencies.md +4 -14
  149. package/docs/examples/locale/list-languages.md +4 -14
  150. package/docs/examples/messaging/create-apns-provider.md +19 -0
  151. package/docs/examples/messaging/create-email.md +23 -0
  152. package/docs/examples/messaging/create-fcm-provider.md +15 -0
  153. package/docs/examples/messaging/create-mailgun-provider.md +21 -0
  154. package/docs/examples/messaging/create-msg91provider.md +17 -0
  155. package/docs/examples/messaging/create-push.md +27 -0
  156. package/docs/examples/messaging/create-sendgrid-provider.md +19 -0
  157. package/docs/examples/messaging/create-sms.md +18 -0
  158. package/docs/examples/messaging/create-smtp-provider.md +25 -0
  159. package/docs/examples/messaging/create-subscriber.md +14 -0
  160. package/docs/examples/messaging/create-telesign-provider.md +17 -0
  161. package/docs/examples/messaging/create-textmagic-provider.md +17 -0
  162. package/docs/examples/messaging/create-topic.md +14 -0
  163. package/docs/examples/messaging/create-twilio-provider.md +17 -0
  164. package/docs/examples/messaging/create-vonage-provider.md +17 -0
  165. package/docs/examples/messaging/delete-provider.md +12 -0
  166. package/docs/examples/messaging/delete-subscriber.md +13 -0
  167. package/docs/examples/messaging/delete-topic.md +12 -0
  168. package/docs/examples/messaging/delete.md +12 -0
  169. package/docs/examples/messaging/get-message.md +12 -0
  170. package/docs/examples/messaging/get-provider.md +12 -0
  171. package/docs/examples/messaging/get-subscriber.md +13 -0
  172. package/docs/examples/messaging/get-topic.md +12 -0
  173. package/docs/examples/messaging/list-message-logs.md +13 -0
  174. package/docs/examples/messaging/list-messages.md +13 -0
  175. package/docs/examples/messaging/list-provider-logs.md +13 -0
  176. package/docs/examples/messaging/list-providers.md +13 -0
  177. package/docs/examples/messaging/list-subscriber-logs.md +13 -0
  178. package/docs/examples/messaging/list-subscribers.md +14 -0
  179. package/docs/examples/messaging/list-targets.md +13 -0
  180. package/docs/examples/messaging/list-topic-logs.md +13 -0
  181. package/docs/examples/messaging/list-topics.md +13 -0
  182. package/docs/examples/messaging/update-apns-provider.md +19 -0
  183. package/docs/examples/messaging/update-email.md +22 -0
  184. package/docs/examples/messaging/update-fcm-provider.md +15 -0
  185. package/docs/examples/messaging/update-mailgun-provider.md +21 -0
  186. package/docs/examples/messaging/update-msg91provider.md +17 -0
  187. package/docs/examples/messaging/update-push.md +27 -0
  188. package/docs/examples/messaging/update-sendgrid-provider.md +19 -0
  189. package/docs/examples/messaging/update-sms.md +18 -0
  190. package/docs/examples/messaging/update-smtp-provider.md +25 -0
  191. package/docs/examples/messaging/update-telesign-provider.md +17 -0
  192. package/docs/examples/messaging/update-textmagic-provider.md +17 -0
  193. package/docs/examples/messaging/update-topic.md +14 -0
  194. package/docs/examples/messaging/update-twilio-provider.md +17 -0
  195. package/docs/examples/messaging/update-vonage-provider.md +17 -0
  196. package/docs/examples/storage/create-bucket.md +15 -14
  197. package/docs/examples/storage/create-file.md +9 -14
  198. package/docs/examples/storage/delete-bucket.md +6 -14
  199. package/docs/examples/storage/delete-file.md +7 -14
  200. package/docs/examples/storage/get-bucket.md +6 -14
  201. package/docs/examples/storage/get-file-download.md +7 -14
  202. package/docs/examples/storage/get-file-preview.md +18 -14
  203. package/docs/examples/storage/get-file-view.md +7 -14
  204. package/docs/examples/storage/get-file.md +7 -14
  205. package/docs/examples/storage/list-buckets.md +7 -14
  206. package/docs/examples/storage/list-files.md +8 -14
  207. package/docs/examples/storage/update-bucket.md +15 -14
  208. package/docs/examples/storage/update-file.md +9 -14
  209. package/docs/examples/teams/create-membership.md +12 -14
  210. package/docs/examples/teams/create.md +8 -14
  211. package/docs/examples/teams/delete-membership.md +7 -14
  212. package/docs/examples/teams/delete.md +6 -14
  213. package/docs/examples/teams/get-membership.md +7 -14
  214. package/docs/examples/teams/get-prefs.md +6 -14
  215. package/docs/examples/teams/get.md +6 -14
  216. package/docs/examples/teams/list-memberships.md +8 -14
  217. package/docs/examples/teams/list.md +7 -14
  218. package/docs/examples/teams/update-membership-status.md +9 -14
  219. package/docs/examples/teams/update-membership.md +8 -14
  220. package/docs/examples/teams/update-name.md +7 -14
  221. package/docs/examples/teams/update-prefs.md +7 -14
  222. package/docs/examples/users/create-argon2user.md +9 -14
  223. package/docs/examples/users/create-bcrypt-user.md +9 -14
  224. package/docs/examples/users/create-m-d5user.md +9 -14
  225. package/docs/examples/users/create-mfa-recovery-codes.md +12 -0
  226. package/docs/examples/users/create-p-h-pass-user.md +9 -14
  227. package/docs/examples/users/create-s-h-a-user.md +10 -14
  228. package/docs/examples/users/create-scrypt-modified-user.md +12 -14
  229. package/docs/examples/users/create-scrypt-user.md +14 -14
  230. package/docs/examples/users/create-session.md +12 -0
  231. package/docs/examples/users/create-target.md +17 -0
  232. package/docs/examples/users/create-token.md +14 -0
  233. package/docs/examples/users/create.md +10 -14
  234. package/docs/examples/users/delete-identity.md +6 -14
  235. package/docs/examples/users/delete-mfa-authenticator.md +13 -0
  236. package/docs/examples/users/delete-session.md +7 -14
  237. package/docs/examples/users/delete-sessions.md +6 -14
  238. package/docs/examples/users/delete-target.md +13 -0
  239. package/docs/examples/users/delete.md +6 -14
  240. package/docs/examples/users/get-mfa-recovery-codes.md +12 -0
  241. package/docs/examples/users/get-prefs.md +6 -14
  242. package/docs/examples/users/get-target.md +13 -0
  243. package/docs/examples/users/get.md +6 -14
  244. package/docs/examples/users/list-identities.md +7 -14
  245. package/docs/examples/users/list-logs.md +7 -14
  246. package/docs/examples/users/list-memberships.md +6 -14
  247. package/docs/examples/users/list-mfa-factors.md +12 -0
  248. package/docs/examples/users/list-sessions.md +6 -14
  249. package/docs/examples/users/list-targets.md +13 -0
  250. package/docs/examples/users/list.md +7 -14
  251. package/docs/examples/users/update-email-verification.md +7 -14
  252. package/docs/examples/users/update-email.md +7 -14
  253. package/docs/examples/users/update-labels.md +7 -14
  254. package/docs/examples/users/update-mfa-recovery-codes.md +12 -0
  255. package/docs/examples/users/update-mfa.md +13 -0
  256. package/docs/examples/users/update-name.md +7 -14
  257. package/docs/examples/users/update-password.md +7 -14
  258. package/docs/examples/users/update-phone-verification.md +7 -14
  259. package/docs/examples/users/update-phone.md +7 -14
  260. package/docs/examples/users/update-prefs.md +7 -14
  261. package/docs/examples/users/update-status.md +7 -14
  262. package/docs/examples/users/update-target.md +16 -0
  263. package/index.d.ts +2164 -81
  264. package/index.js +38 -0
  265. package/lib/client.js +107 -65
  266. package/lib/enums/authentication-factor.js +8 -0
  267. package/lib/enums/authenticator-type.js +5 -0
  268. package/lib/enums/browser.js +18 -0
  269. package/lib/enums/compression.js +7 -0
  270. package/lib/enums/credit-card.js +20 -0
  271. package/lib/enums/execution-method.js +10 -0
  272. package/lib/enums/flag.js +198 -0
  273. package/lib/enums/image-format.js +9 -0
  274. package/lib/enums/image-gravity.js +13 -0
  275. package/lib/enums/index-type.js +7 -0
  276. package/lib/enums/messaging-provider-type.js +7 -0
  277. package/lib/enums/name.js +17 -0
  278. package/lib/enums/o-auth-provider.js +43 -0
  279. package/lib/enums/password-hash.js +15 -0
  280. package/lib/enums/relation-mutate.js +7 -0
  281. package/lib/enums/relationship-type.js +8 -0
  282. package/lib/enums/runtime.js +48 -0
  283. package/lib/enums/smtp-encryption.js +7 -0
  284. package/lib/inputFile.js +88 -16
  285. package/lib/query.js +56 -38
  286. package/lib/services/account.js +722 -16
  287. package/lib/services/avatars.js +5 -3
  288. package/lib/services/databases.js +34 -4
  289. package/lib/services/functions.js +51 -87
  290. package/lib/services/graphql.js +2 -0
  291. package/lib/services/health.js +118 -0
  292. package/lib/services/locale.js +2 -0
  293. package/lib/services/messaging.js +2218 -0
  294. package/lib/services/storage.js +52 -88
  295. package/lib/services/teams.js +2 -0
  296. package/lib/services/users.js +405 -3
  297. 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 Avatars extends Service {
10
12
 
@@ -28,7 +30,7 @@ class Avatars extends Service {
28
30
  * image at source quality. If dimensions are not specified, the default size
29
31
  * of image returned is 100x100px.
30
32
  *
31
- * @param {string} code
33
+ * @param {Browser} code
32
34
  * @param {number} width
33
35
  * @param {number} height
34
36
  * @param {number} quality
@@ -73,7 +75,7 @@ class Avatars extends Service {
73
75
  * of image returned is 100x100px.
74
76
  *
75
77
  *
76
- * @param {string} code
78
+ * @param {CreditCard} code
77
79
  * @param {number} width
78
80
  * @param {number} height
79
81
  * @param {number} quality
@@ -147,7 +149,7 @@ class Avatars extends Service {
147
149
  * of image returned is 100x100px.
148
150
  *
149
151
  *
150
- * @param {string} code
152
+ * @param {Flag} code
151
153
  * @param {number} width
152
154
  * @param {number} height
153
155
  * @param {number} quality
@@ -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 Databases extends Service {
10
12
 
@@ -366,6 +368,8 @@ class Databases extends Service {
366
368
  /**
367
369
  * List attributes
368
370
  *
371
+ * List attributes in the collection.
372
+ *
369
373
  * @param {string} databaseId
370
374
  * @param {string} collectionId
371
375
  * @param {string[]} queries
@@ -452,6 +456,9 @@ class Databases extends Service {
452
456
  /**
453
457
  * Update boolean attribute
454
458
  *
459
+ * Update a boolean attribute. Changing the `default` value will not update
460
+ * already existing documents.
461
+ *
455
462
  * @param {string} databaseId
456
463
  * @param {string} collectionId
457
464
  * @param {string} key
@@ -500,6 +507,8 @@ class Databases extends Service {
500
507
  /**
501
508
  * Create datetime attribute
502
509
  *
510
+ * Create a date time attribute according to the ISO 8601 standard.
511
+ *
503
512
  * @param {string} databaseId
504
513
  * @param {string} collectionId
505
514
  * @param {string} key
@@ -553,6 +562,9 @@ class Databases extends Service {
553
562
  /**
554
563
  * Update dateTime attribute
555
564
  *
565
+ * Update a date time attribute. Changing the `default` value will not update
566
+ * already existing documents.
567
+ *
556
568
  * @param {string} databaseId
557
569
  * @param {string} collectionId
558
570
  * @param {string} key
@@ -709,6 +721,10 @@ class Databases extends Service {
709
721
  /**
710
722
  * Create enum attribute
711
723
  *
724
+ * Create an enumeration attribute. The `elements` param acts as a white-list
725
+ * of accepted values for this attribute.
726
+ *
727
+ *
712
728
  * @param {string} databaseId
713
729
  * @param {string} collectionId
714
730
  * @param {string} key
@@ -1221,11 +1237,11 @@ class Databases extends Service {
1221
1237
  * @param {string} databaseId
1222
1238
  * @param {string} collectionId
1223
1239
  * @param {string} relatedCollectionId
1224
- * @param {string} type
1240
+ * @param {RelationshipType} type
1225
1241
  * @param {boolean} twoWay
1226
1242
  * @param {string} key
1227
1243
  * @param {string} twoWayKey
1228
- * @param {string} onDelete
1244
+ * @param {RelationMutate} onDelete
1229
1245
  * @throws {AppwriteException}
1230
1246
  * @returns {Promise}
1231
1247
  */
@@ -1511,6 +1527,8 @@ class Databases extends Service {
1511
1527
  /**
1512
1528
  * Get attribute
1513
1529
  *
1530
+ * Get attribute by ID.
1531
+ *
1514
1532
  * @param {string} databaseId
1515
1533
  * @param {string} collectionId
1516
1534
  * @param {string} key
@@ -1541,6 +1559,8 @@ class Databases extends Service {
1541
1559
  /**
1542
1560
  * Delete attribute
1543
1561
  *
1562
+ * Deletes an attribute.
1563
+ *
1544
1564
  * @param {string} databaseId
1545
1565
  * @param {string} collectionId
1546
1566
  * @param {string} key
@@ -1578,7 +1598,7 @@ class Databases extends Service {
1578
1598
  * @param {string} databaseId
1579
1599
  * @param {string} collectionId
1580
1600
  * @param {string} key
1581
- * @param {string} onDelete
1601
+ * @param {RelationMutate} onDelete
1582
1602
  * @throws {AppwriteException}
1583
1603
  * @returns {Promise}
1584
1604
  */
@@ -1809,6 +1829,8 @@ class Databases extends Service {
1809
1829
  /**
1810
1830
  * List indexes
1811
1831
  *
1832
+ * List indexes in the collection.
1833
+ *
1812
1834
  * @param {string} databaseId
1813
1835
  * @param {string} collectionId
1814
1836
  * @param {string[]} queries
@@ -1839,10 +1861,14 @@ class Databases extends Service {
1839
1861
  /**
1840
1862
  * Create index
1841
1863
  *
1864
+ * Creates an index on the attributes listed. Your index should include all
1865
+ * the attributes you will query in a single request.
1866
+ * Attributes can be `key`, `fulltext`, and `unique`.
1867
+ *
1842
1868
  * @param {string} databaseId
1843
1869
  * @param {string} collectionId
1844
1870
  * @param {string} key
1845
- * @param {string} type
1871
+ * @param {IndexType} type
1846
1872
  * @param {string[]} attributes
1847
1873
  * @param {string[]} orders
1848
1874
  * @throws {AppwriteException}
@@ -1896,6 +1922,8 @@ class Databases extends Service {
1896
1922
  /**
1897
1923
  * Get index
1898
1924
  *
1925
+ * Get index by ID.
1926
+ *
1899
1927
  * @param {string} databaseId
1900
1928
  * @param {string} collectionId
1901
1929
  * @param {string} key
@@ -1926,6 +1954,8 @@ class Databases extends Service {
1926
1954
  /**
1927
1955
  * Delete index
1928
1956
  *
1957
+ * Delete an index.
1958
+ *
1929
1959
  * @param {string} databaseId
1930
1960
  * @param {string} collectionId
1931
1961
  * @param {string} key
@@ -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
 
@@ -52,7 +54,7 @@ class Functions extends Service {
52
54
  *
53
55
  * @param {string} functionId
54
56
  * @param {string} name
55
- * @param {string} runtime
57
+ * @param {Runtime} runtime
56
58
  * @param {string[]} execute
57
59
  * @param {string[]} events
58
60
  * @param {string} schedule
@@ -220,7 +222,7 @@ class Functions extends Service {
220
222
  *
221
223
  * @param {string} functionId
222
224
  * @param {string} name
223
- * @param {string} runtime
225
+ * @param {Runtime} runtime
224
226
  * @param {string[]} execute
225
227
  * @param {string[]} events
226
228
  * @param {string} schedule
@@ -388,6 +390,7 @@ class Functions extends Service {
388
390
  * @param {boolean} activate
389
391
  * @param {string} entrypoint
390
392
  * @param {string} commands
393
+ * @param {CallableFunction} onProgress
391
394
  * @throws {AppwriteException}
392
395
  * @returns {Promise}
393
396
  */
@@ -423,8 +426,9 @@ class Functions extends Service {
423
426
  payload['activate'] = activate.toString();
424
427
  }
425
428
 
426
- const size = code.size;
427
429
 
430
+ const size = code.size;
431
+
428
432
  const apiHeaders = {
429
433
  'content-type': 'multipart/form-data',
430
434
  };
@@ -435,118 +439,78 @@ class Functions extends Service {
435
439
  let chunksUploaded = 0;
436
440
 
437
441
 
438
- let currentChunk = Buffer.from('');
439
- let currentChunkSize = 0;
440
- let currentChunkStart = 0;
441
-
442
- const selfClient = this.client;
442
+ let currentChunk = 1;
443
+ let currentPosition = 0;
444
+ let uploadableChunk = new Uint8Array(client.CHUNK_SIZE);
445
+
443
446
 
444
- async function uploadChunk(lastUpload = false) {
445
- if(chunksUploaded - 1 >= currentChunkStart / client.CHUNK_SIZE) {
447
+ const uploadChunk = async (lastUpload = false) => {
448
+ if(currentChunk <= chunksUploaded) {
446
449
  return;
447
450
  }
448
-
449
- const start = currentChunkStart;
450
- const end = currentChunkStart + currentChunkSize - 1;
451
451
 
452
- if(!lastUpload || currentChunkStart !== 0) {
452
+ const start = ((currentChunk - 1) * client.CHUNK_SIZE);
453
+ let end = start + currentPosition - 1;
454
+
455
+ if(!lastUpload || currentChunk !== 1) {
453
456
  apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
454
457
  }
455
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
+
456
470
  if (id) {
457
471
  apiHeaders['x-appwrite-id'] = id;
458
472
  }
459
473
 
460
- payload['code'] = {
461
- type: 'file',
462
- file: currentChunk,
463
- filename: code.filename,
464
- size: currentChunkSize
465
- };
474
+ payload['code'] = { type: 'file', file: new File([uploadableChunkTrimmed], code.filename), filename: code.filename };
466
475
 
467
- response = await selfClient.call('post', apiPath, apiHeaders, payload);
476
+ response = await this.client.call('post', apiPath, apiHeaders, payload);
468
477
 
469
478
  if (!id) {
470
479
  id = response['$id'];
471
480
  }
472
-
481
+
473
482
  if (onProgress !== null) {
474
483
  onProgress({
475
484
  $id: response['$id'],
476
- progress: Math.min((start+client.CHUNK_SIZE) * client.CHUNK_SIZE, size) / size * 100,
485
+ progress: Math.min((currentChunk) * client.CHUNK_SIZE, size) / size * 100,
477
486
  sizeUploaded: end+1,
478
487
  chunksTotal: response['chunksTotal'],
479
488
  chunksUploaded: response['chunksUploaded']
480
489
  });
481
490
  }
482
491
 
483
- currentChunkStart += client.CHUNK_SIZE;
484
- }
485
-
486
- return await new Promise((resolve, reject) => {
487
- const writeStream = new Stream.Writable();
488
- writeStream._write = async (mainChunk, encoding, callback) => {
489
- try {
490
- // Segment incoming chunk into up to 5MB chunks
491
- const mainChunkSize = Buffer.byteLength(mainChunk);
492
- const chunksCount = Math.ceil(mainChunkSize / client.CHUNK_SIZE);
493
- const chunks = [];
494
-
495
- for(let i = 0; i < chunksCount; i++) {
496
- const chunk = mainChunk.slice(i * client.CHUNK_SIZE, (i + 1) * client.CHUNK_SIZE);
497
- chunks.push(chunk);
498
- }
499
-
500
- for (const chunk of chunks) {
501
- const chunkSize = Buffer.byteLength(chunk);
502
-
503
- if(chunkSize + currentChunkSize == client.CHUNK_SIZE) {
504
- // Upload chunk
505
- currentChunk = Buffer.concat([currentChunk, chunk]);
506
- currentChunkSize = Buffer.byteLength(currentChunk);
507
- await uploadChunk();
508
- currentChunk = Buffer.from('');
509
- currentChunkSize = 0;
510
- } else if(chunkSize + currentChunkSize > client.CHUNK_SIZE) {
511
- // Upload chunk, put rest into next chunk
512
- const bytesToUpload = client.CHUNK_SIZE - currentChunkSize;
513
- const newChunkSection = chunk.slice(0, bytesToUpload);
514
- currentChunk = Buffer.concat([currentChunk, newChunkSection]);
515
- currentChunkSize = Buffer.byteLength(currentChunk);
516
- await uploadChunk();
517
- currentChunk = chunk.slice(bytesToUpload, undefined);
518
- currentChunkSize = chunkSize - bytesToUpload;
519
- } else {
520
- // Append into current chunk
521
- currentChunk = Buffer.concat([currentChunk, chunk]);
522
- currentChunkSize = chunkSize + currentChunkSize;
523
- }
524
- }
525
-
526
- callback();
527
- } catch (e) {
528
- 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;
529
505
  }
530
506
  }
507
+ }
531
508
 
532
- writeStream.on("finish", async () => {
533
- if(currentChunkSize > 0) {
534
- try {
535
- await uploadChunk(true);
536
- } catch (e) {
537
- reject(e);
538
- }
539
- }
540
-
541
- resolve(response);
542
- });
509
+ if (currentPosition > 0) { // Check if there's any remaining data for the last chunk
510
+ await uploadChunk(true);
511
+ }
543
512
 
544
- writeStream.on("error", (err) => {
545
- reject(err);
546
- });
547
-
548
- code.stream.pipe(writeStream);
549
- });
513
+ return response;
550
514
 
551
515
  }
552
516
 
@@ -739,7 +703,7 @@ class Functions extends Service {
739
703
  * @param {string} body
740
704
  * @param {boolean} async
741
705
  * @param {string} xpath
742
- * @param {string} method
706
+ * @param {ExecutionMethod} method
743
707
  * @param {object} headers
744
708
  * @throws {AppwriteException}
745
709
  * @returns {Promise}
@@ -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
 
@@ -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 Health extends Service {
10
12
 
@@ -66,6 +68,28 @@ class Health extends Service {
66
68
  }, payload);
67
69
  }
68
70
 
71
+ /**
72
+ * Get the SSL certificate for a domain
73
+ *
74
+ * Get the SSL certificate for a domain
75
+ *
76
+ * @param {string} domain
77
+ * @throws {AppwriteException}
78
+ * @returns {Promise}
79
+ */
80
+ async getCertificate(domain) {
81
+ const apiPath = '/health/certificate';
82
+ let payload = {};
83
+
84
+ if (typeof domain !== 'undefined') {
85
+ payload['domain'] = domain;
86
+ }
87
+
88
+ return await this.client.call('get', apiPath, {
89
+ 'content-type': 'application/json',
90
+ }, payload);
91
+ }
92
+
69
93
  /**
70
94
  * Get DB
71
95
  *
@@ -216,9 +240,40 @@ class Health extends Service {
216
240
  }, payload);
217
241
  }
218
242
 
243
+ /**
244
+ * Get number of failed queue jobs
245
+ *
246
+ * Returns the amount of failed jobs in a given queue.
247
+ *
248
+ *
249
+ * @param {Name} name
250
+ * @param {number} threshold
251
+ * @throws {AppwriteException}
252
+ * @returns {Promise}
253
+ */
254
+ async getFailedJobs(name, threshold) {
255
+ const apiPath = '/health/queue/failed/{name}'.replace('{name}', name);
256
+ let payload = {};
257
+ if (typeof name === 'undefined') {
258
+ throw new AppwriteException('Missing required parameter: "name"');
259
+ }
260
+
261
+
262
+ if (typeof threshold !== 'undefined') {
263
+ payload['threshold'] = threshold;
264
+ }
265
+
266
+ return await this.client.call('get', apiPath, {
267
+ 'content-type': 'application/json',
268
+ }, payload);
269
+ }
270
+
219
271
  /**
220
272
  * Get functions queue
221
273
  *
274
+ * Get the number of function executions that are waiting to be processed in
275
+ * the Appwrite internal queue server.
276
+ *
222
277
  * @param {number} threshold
223
278
  * @throws {AppwriteException}
224
279
  * @returns {Promise}
@@ -328,6 +383,52 @@ class Health extends Service {
328
383
  }, payload);
329
384
  }
330
385
 
386
+ /**
387
+ * Get usage queue
388
+ *
389
+ * Get the number of metrics that are waiting to be processed in the Appwrite
390
+ * internal queue server.
391
+ *
392
+ * @param {number} threshold
393
+ * @throws {AppwriteException}
394
+ * @returns {Promise}
395
+ */
396
+ async getQueueUsage(threshold) {
397
+ const apiPath = '/health/queue/usage';
398
+ let payload = {};
399
+
400
+ if (typeof threshold !== 'undefined') {
401
+ payload['threshold'] = threshold;
402
+ }
403
+
404
+ return await this.client.call('get', apiPath, {
405
+ 'content-type': 'application/json',
406
+ }, payload);
407
+ }
408
+
409
+ /**
410
+ * Get usage dump queue
411
+ *
412
+ * Get the number of projects containing metrics that are waiting to be
413
+ * processed in the Appwrite internal queue server.
414
+ *
415
+ * @param {number} threshold
416
+ * @throws {AppwriteException}
417
+ * @returns {Promise}
418
+ */
419
+ async getQueueUsageDump(threshold) {
420
+ const apiPath = '/health/queue/usage-dump';
421
+ let payload = {};
422
+
423
+ if (typeof threshold !== 'undefined') {
424
+ payload['threshold'] = threshold;
425
+ }
426
+
427
+ return await this.client.call('get', apiPath, {
428
+ 'content-type': 'application/json',
429
+ }, payload);
430
+ }
431
+
331
432
  /**
332
433
  * Get webhooks queue
333
434
  *
@@ -351,6 +452,23 @@ class Health extends Service {
351
452
  }, payload);
352
453
  }
353
454
 
455
+ /**
456
+ * Get storage
457
+ *
458
+ * Check the Appwrite storage device is up and connection is successful.
459
+ *
460
+ * @throws {AppwriteException}
461
+ * @returns {Promise}
462
+ */
463
+ async getStorage() {
464
+ const apiPath = '/health/storage';
465
+ let payload = {};
466
+
467
+ return await this.client.call('get', apiPath, {
468
+ 'content-type': 'application/json',
469
+ }, payload);
470
+ }
471
+
354
472
  /**
355
473
  * Get local storage
356
474
  *
@@ -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 Locale extends Service {
10
12