appwrite-cli 13.0.0-rc.2 → 13.0.0-rc.3

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 (718) hide show
  1. package/.github/workflows/{npm-publish.yml → publish.yml} +1 -1
  2. package/CHANGELOG.md +106 -101
  3. package/LICENSE.md +2 -2
  4. package/README.md +36 -59
  5. package/cli.ts +152 -0
  6. package/dist/bundle.cjs +4613 -3653
  7. package/dist/cli.d.ts +3 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +145 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/index.d.ts +10 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -142
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib/client.d.ts.map +1 -1
  16. package/dist/lib/client.js +7 -6
  17. package/dist/lib/client.js.map +1 -1
  18. package/dist/lib/commands/config.d.ts +562 -0
  19. package/dist/lib/commands/config.d.ts.map +1 -0
  20. package/dist/lib/commands/config.js +416 -0
  21. package/dist/lib/commands/config.js.map +1 -0
  22. package/dist/lib/commands/db.d.ts +34 -0
  23. package/dist/lib/commands/db.d.ts.map +1 -0
  24. package/dist/lib/commands/db.js +247 -0
  25. package/dist/lib/commands/db.js.map +1 -0
  26. package/dist/lib/commands/errors.d.ts +68 -0
  27. package/dist/lib/commands/errors.d.ts.map +1 -0
  28. package/dist/lib/commands/errors.js +72 -0
  29. package/dist/lib/commands/errors.js.map +1 -0
  30. package/dist/lib/commands/init.d.ts.map +1 -1
  31. package/dist/lib/commands/init.js +15 -14
  32. package/dist/lib/commands/init.js.map +1 -1
  33. package/dist/lib/commands/pull.d.ts +104 -2
  34. package/dist/lib/commands/pull.d.ts.map +1 -1
  35. package/dist/lib/commands/pull.js +470 -281
  36. package/dist/lib/commands/pull.js.map +1 -1
  37. package/dist/lib/commands/push.d.ts +106 -0
  38. package/dist/lib/commands/push.d.ts.map +1 -1
  39. package/dist/lib/commands/push.js +1257 -1628
  40. package/dist/lib/commands/push.js.map +1 -1
  41. package/dist/lib/commands/run.js +1 -1
  42. package/dist/lib/commands/run.js.map +1 -1
  43. package/dist/lib/commands/schema.d.ts +59 -0
  44. package/dist/lib/commands/schema.d.ts.map +1 -0
  45. package/dist/lib/commands/schema.js +86 -0
  46. package/dist/lib/commands/schema.js.map +1 -0
  47. package/dist/lib/commands/services/account.d.ts.map +1 -1
  48. package/dist/lib/commands/services/account.js +86 -64
  49. package/dist/lib/commands/services/account.js.map +1 -1
  50. package/dist/lib/commands/services/console.d.ts.map +1 -1
  51. package/dist/lib/commands/services/console.js +4 -17
  52. package/dist/lib/commands/services/console.js.map +1 -1
  53. package/dist/lib/commands/services/databases.d.ts.map +1 -1
  54. package/dist/lib/commands/services/databases.js +160 -152
  55. package/dist/lib/commands/services/databases.js.map +1 -1
  56. package/dist/lib/commands/services/functions.d.ts.map +1 -1
  57. package/dist/lib/commands/services/functions.js +41 -33
  58. package/dist/lib/commands/services/functions.js.map +1 -1
  59. package/dist/lib/commands/services/graphql.d.ts.map +1 -1
  60. package/dist/lib/commands/services/graphql.js +3 -3
  61. package/dist/lib/commands/services/graphql.js.map +1 -1
  62. package/dist/lib/commands/services/health.d.ts.map +1 -1
  63. package/dist/lib/commands/services/health.js +24 -24
  64. package/dist/lib/commands/services/health.js.map +1 -1
  65. package/dist/lib/commands/services/locale.d.ts.map +1 -1
  66. package/dist/lib/commands/services/locale.js +9 -9
  67. package/dist/lib/commands/services/locale.js.map +1 -1
  68. package/dist/lib/commands/services/messaging.d.ts.map +1 -1
  69. package/dist/lib/commands/services/messaging.js +59 -59
  70. package/dist/lib/commands/services/messaging.js.map +1 -1
  71. package/dist/lib/commands/services/migrations.d.ts.map +1 -1
  72. package/dist/lib/commands/services/migrations.js +19 -19
  73. package/dist/lib/commands/services/migrations.js.map +1 -1
  74. package/dist/lib/commands/services/project.d.ts.map +1 -1
  75. package/dist/lib/commands/services/project.js +8 -8
  76. package/dist/lib/commands/services/project.js.map +1 -1
  77. package/dist/lib/commands/services/projects.d.ts.map +1 -1
  78. package/dist/lib/commands/services/projects.js +64 -64
  79. package/dist/lib/commands/services/projects.js.map +1 -1
  80. package/dist/lib/commands/services/proxy.d.ts.map +1 -1
  81. package/dist/lib/commands/services/proxy.js +11 -11
  82. package/dist/lib/commands/services/proxy.js.map +1 -1
  83. package/dist/lib/commands/services/sites.d.ts.map +1 -1
  84. package/dist/lib/commands/services/sites.js +41 -33
  85. package/dist/lib/commands/services/sites.js.map +1 -1
  86. package/dist/lib/commands/services/storage.d.ts.map +1 -1
  87. package/dist/lib/commands/services/storage.js +38 -16
  88. package/dist/lib/commands/services/storage.js.map +1 -1
  89. package/dist/lib/commands/services/tables-db.d.ts +3 -0
  90. package/dist/lib/commands/services/tables-db.d.ts.map +1 -0
  91. package/dist/lib/commands/services/{tablesdb.js → tables-db.js} +171 -163
  92. package/dist/lib/commands/services/tables-db.js.map +1 -0
  93. package/dist/lib/commands/services/teams.d.ts.map +1 -1
  94. package/dist/lib/commands/services/teams.js +16 -16
  95. package/dist/lib/commands/services/teams.js.map +1 -1
  96. package/dist/lib/commands/services/tokens.d.ts.map +1 -1
  97. package/dist/lib/commands/services/tokens.js +6 -6
  98. package/dist/lib/commands/services/tokens.js.map +1 -1
  99. package/dist/lib/commands/services/users.d.ts.map +1 -1
  100. package/dist/lib/commands/services/users.js +54 -54
  101. package/dist/lib/commands/services/users.js.map +1 -1
  102. package/dist/lib/commands/services/vcs.d.ts.map +1 -1
  103. package/dist/lib/commands/services/vcs.js +13 -13
  104. package/dist/lib/commands/services/vcs.js.map +1 -1
  105. package/dist/lib/commands/types.d.ts.map +1 -1
  106. package/dist/lib/commands/types.js +1 -1
  107. package/dist/lib/commands/types.js.map +1 -1
  108. package/dist/lib/commands/update.d.ts.map +1 -1
  109. package/dist/lib/commands/update.js +9 -8
  110. package/dist/lib/commands/update.js.map +1 -1
  111. package/dist/lib/commands/utils/attributes.d.ts +47 -0
  112. package/dist/lib/commands/utils/attributes.d.ts.map +1 -0
  113. package/dist/lib/commands/utils/attributes.js +514 -0
  114. package/dist/lib/commands/utils/attributes.js.map +1 -0
  115. package/dist/lib/commands/utils/change-approval.d.ts +25 -0
  116. package/dist/lib/commands/utils/change-approval.d.ts.map +1 -0
  117. package/dist/lib/commands/utils/change-approval.js +129 -0
  118. package/dist/lib/commands/utils/change-approval.js.map +1 -0
  119. package/dist/lib/commands/utils/database-sync.d.ts +10 -0
  120. package/dist/lib/commands/utils/database-sync.d.ts.map +1 -0
  121. package/dist/lib/commands/utils/database-sync.js +136 -0
  122. package/dist/lib/commands/utils/database-sync.js.map +1 -0
  123. package/dist/lib/commands/utils/deployment.d.ts +34 -0
  124. package/dist/lib/commands/utils/deployment.d.ts.map +1 -0
  125. package/dist/lib/commands/utils/deployment.js +109 -0
  126. package/dist/lib/commands/utils/deployment.js.map +1 -0
  127. package/dist/lib/commands/utils/error-formatter.d.ts +19 -0
  128. package/dist/lib/commands/utils/error-formatter.d.ts.map +1 -0
  129. package/dist/lib/commands/utils/error-formatter.js +333 -0
  130. package/dist/lib/commands/utils/error-formatter.js.map +1 -0
  131. package/dist/lib/commands/utils/pools.d.ts +16 -0
  132. package/dist/lib/commands/utils/pools.d.ts.map +1 -0
  133. package/dist/lib/commands/utils/pools.js +198 -0
  134. package/dist/lib/commands/utils/pools.js.map +1 -0
  135. package/dist/lib/config.d.ts +27 -26
  136. package/dist/lib/config.d.ts.map +1 -1
  137. package/dist/lib/config.js +8 -45
  138. package/dist/lib/config.js.map +1 -1
  139. package/dist/lib/constants.d.ts +14 -0
  140. package/dist/lib/constants.d.ts.map +1 -0
  141. package/dist/lib/constants.js +19 -0
  142. package/dist/lib/constants.js.map +1 -0
  143. package/dist/lib/emulation/docker.d.ts +4 -4
  144. package/dist/lib/emulation/docker.d.ts.map +1 -1
  145. package/dist/lib/emulation/docker.js +80 -67
  146. package/dist/lib/emulation/docker.js.map +1 -1
  147. package/dist/lib/parser.d.ts.map +1 -1
  148. package/dist/lib/parser.js +11 -10
  149. package/dist/lib/parser.js.map +1 -1
  150. package/dist/lib/questions.d.ts.map +1 -1
  151. package/dist/lib/questions.js +20 -20
  152. package/dist/lib/questions.js.map +1 -1
  153. package/dist/lib/sdks.d.ts.map +1 -1
  154. package/dist/lib/sdks.js +10 -11
  155. package/dist/lib/sdks.js.map +1 -1
  156. package/dist/lib/types.d.ts +0 -214
  157. package/dist/lib/types.d.ts.map +1 -1
  158. package/dist/lib/utils.d.ts +3 -0
  159. package/dist/lib/utils.d.ts.map +1 -1
  160. package/dist/lib/utils.js +42 -2
  161. package/dist/lib/utils.js.map +1 -1
  162. package/dist/package.json +12 -11
  163. package/docs/examples/account/create-anonymous-session.md +1 -0
  164. package/docs/examples/account/create-email-password-session.md +3 -0
  165. package/docs/examples/account/create-email-token.md +3 -0
  166. package/docs/examples/account/create-email-verification.md +2 -0
  167. package/docs/examples/account/create-jwt.md +1 -0
  168. package/docs/examples/account/create-magic-url-token.md +3 -0
  169. package/docs/examples/account/create-mfa-authenticator.md +2 -0
  170. package/docs/examples/account/create-mfa-challenge.md +2 -0
  171. package/docs/examples/account/create-mfa-recovery-codes.md +1 -0
  172. package/docs/examples/account/create-o-auth-2-session.md +2 -0
  173. package/docs/examples/account/create-o-auth-2-token.md +2 -0
  174. package/docs/examples/account/create-phone-token.md +3 -0
  175. package/docs/examples/account/create-phone-verification.md +1 -0
  176. package/docs/examples/account/create-push-target.md +3 -0
  177. package/docs/examples/account/create-recovery.md +3 -0
  178. package/docs/examples/account/create-session.md +3 -0
  179. package/docs/examples/account/create-verification.md +2 -0
  180. package/docs/examples/account/create.md +4 -0
  181. package/docs/examples/account/delete-identity.md +2 -0
  182. package/docs/examples/account/delete-mfa-authenticator.md +2 -0
  183. package/docs/examples/account/delete-push-target.md +2 -0
  184. package/docs/examples/account/delete-session.md +2 -0
  185. package/docs/examples/account/delete-sessions.md +1 -0
  186. package/docs/examples/account/delete.md +1 -0
  187. package/docs/examples/account/get-mfa-recovery-codes.md +1 -0
  188. package/docs/examples/account/get-prefs.md +1 -0
  189. package/docs/examples/account/get-session.md +2 -0
  190. package/docs/examples/account/get.md +1 -0
  191. package/docs/examples/account/list-identities.md +1 -0
  192. package/docs/examples/account/list-logs.md +1 -0
  193. package/docs/examples/account/list-mfa-factors.md +1 -0
  194. package/docs/examples/account/list-sessions.md +1 -0
  195. package/docs/examples/account/update-email-verification.md +3 -0
  196. package/docs/examples/account/update-email.md +3 -0
  197. package/docs/examples/account/update-magic-url-session.md +3 -0
  198. package/docs/examples/account/update-mfa-authenticator.md +3 -0
  199. package/docs/examples/account/update-mfa-challenge.md +3 -0
  200. package/docs/examples/account/update-mfa-recovery-codes.md +1 -0
  201. package/docs/examples/account/update-mfa.md +2 -0
  202. package/docs/examples/account/update-name.md +2 -0
  203. package/docs/examples/account/update-password.md +2 -0
  204. package/docs/examples/account/update-phone-session.md +3 -0
  205. package/docs/examples/account/update-phone-verification.md +3 -0
  206. package/docs/examples/account/update-phone.md +3 -0
  207. package/docs/examples/account/update-prefs.md +2 -0
  208. package/docs/examples/account/update-push-target.md +3 -0
  209. package/docs/examples/account/update-recovery.md +4 -0
  210. package/docs/examples/account/update-session.md +2 -0
  211. package/docs/examples/account/update-status.md +1 -0
  212. package/docs/examples/account/update-verification.md +3 -0
  213. package/docs/examples/console/get-resource.md +3 -0
  214. package/docs/examples/console/variables.md +1 -0
  215. package/docs/examples/databases/create-boolean-attribute.md +5 -0
  216. package/docs/examples/databases/create-collection.md +4 -0
  217. package/docs/examples/databases/create-datetime-attribute.md +5 -0
  218. package/docs/examples/databases/create-document.md +5 -0
  219. package/docs/examples/databases/create-documents.md +4 -0
  220. package/docs/examples/databases/create-email-attribute.md +5 -0
  221. package/docs/examples/databases/create-enum-attribute.md +6 -0
  222. package/docs/examples/databases/create-float-attribute.md +5 -0
  223. package/docs/examples/databases/create-index.md +6 -0
  224. package/docs/examples/databases/create-integer-attribute.md +5 -0
  225. package/docs/examples/databases/create-ip-attribute.md +5 -0
  226. package/docs/examples/databases/create-line-attribute.md +5 -0
  227. package/docs/examples/databases/create-operations.md +2 -0
  228. package/docs/examples/databases/create-point-attribute.md +5 -0
  229. package/docs/examples/databases/create-polygon-attribute.md +5 -0
  230. package/docs/examples/databases/create-relationship-attribute.md +5 -0
  231. package/docs/examples/databases/create-string-attribute.md +6 -0
  232. package/docs/examples/databases/create-transaction.md +1 -0
  233. package/docs/examples/databases/create-url-attribute.md +5 -0
  234. package/docs/examples/databases/create.md +3 -0
  235. package/docs/examples/databases/decrement-document-attribute.md +5 -0
  236. package/docs/examples/databases/delete-attribute.md +4 -0
  237. package/docs/examples/databases/delete-collection.md +3 -0
  238. package/docs/examples/databases/delete-document.md +4 -0
  239. package/docs/examples/databases/delete-documents.md +3 -0
  240. package/docs/examples/databases/delete-index.md +4 -0
  241. package/docs/examples/databases/delete-transaction.md +2 -0
  242. package/docs/examples/databases/delete.md +2 -0
  243. package/docs/examples/databases/get-attribute.md +4 -0
  244. package/docs/examples/databases/get-collection-usage.md +3 -0
  245. package/docs/examples/databases/get-collection.md +3 -0
  246. package/docs/examples/databases/get-document.md +4 -0
  247. package/docs/examples/databases/get-index.md +4 -0
  248. package/docs/examples/databases/get-transaction.md +2 -0
  249. package/docs/examples/databases/get-usage.md +2 -0
  250. package/docs/examples/databases/get.md +2 -0
  251. package/docs/examples/databases/increment-document-attribute.md +5 -0
  252. package/docs/examples/databases/list-attributes.md +3 -0
  253. package/docs/examples/databases/list-collection-logs.md +3 -0
  254. package/docs/examples/databases/list-collections.md +2 -0
  255. package/docs/examples/databases/list-document-logs.md +4 -0
  256. package/docs/examples/databases/list-documents.md +3 -0
  257. package/docs/examples/databases/list-indexes.md +3 -0
  258. package/docs/examples/databases/list-logs.md +2 -0
  259. package/docs/examples/databases/list-transactions.md +1 -0
  260. package/docs/examples/databases/list-usage.md +1 -0
  261. package/docs/examples/databases/list.md +1 -0
  262. package/docs/examples/databases/update-boolean-attribute.md +6 -0
  263. package/docs/examples/databases/update-collection.md +4 -0
  264. package/docs/examples/databases/update-datetime-attribute.md +6 -0
  265. package/docs/examples/databases/update-document.md +4 -0
  266. package/docs/examples/databases/update-documents.md +3 -0
  267. package/docs/examples/databases/update-email-attribute.md +6 -0
  268. package/docs/examples/databases/update-enum-attribute.md +7 -0
  269. package/docs/examples/databases/update-float-attribute.md +6 -0
  270. package/docs/examples/databases/update-integer-attribute.md +6 -0
  271. package/docs/examples/databases/update-ip-attribute.md +6 -0
  272. package/docs/examples/databases/update-line-attribute.md +5 -0
  273. package/docs/examples/databases/update-point-attribute.md +5 -0
  274. package/docs/examples/databases/update-polygon-attribute.md +5 -0
  275. package/docs/examples/databases/update-relationship-attribute.md +4 -0
  276. package/docs/examples/databases/update-string-attribute.md +6 -0
  277. package/docs/examples/databases/update-transaction.md +2 -0
  278. package/docs/examples/databases/update-url-attribute.md +6 -0
  279. package/docs/examples/databases/update.md +3 -0
  280. package/docs/examples/databases/upsert-document.md +4 -0
  281. package/docs/examples/databases/upsert-documents.md +4 -0
  282. package/docs/examples/functions/create-deployment.md +4 -0
  283. package/docs/examples/functions/create-duplicate-deployment.md +3 -0
  284. package/docs/examples/functions/create-execution.md +2 -0
  285. package/docs/examples/functions/create-template-deployment.md +7 -0
  286. package/docs/examples/functions/create-variable.md +4 -0
  287. package/docs/examples/functions/create-vcs-deployment.md +4 -0
  288. package/docs/examples/functions/create.md +4 -0
  289. package/docs/examples/functions/delete-deployment.md +3 -0
  290. package/docs/examples/functions/delete-execution.md +3 -0
  291. package/docs/examples/functions/delete-variable.md +3 -0
  292. package/docs/examples/functions/delete.md +2 -0
  293. package/docs/examples/functions/get-deployment-download.md +3 -0
  294. package/docs/examples/functions/get-deployment.md +3 -0
  295. package/docs/examples/functions/get-execution.md +3 -0
  296. package/docs/examples/functions/get-template.md +2 -0
  297. package/docs/examples/functions/get-usage.md +2 -0
  298. package/docs/examples/functions/get-variable.md +3 -0
  299. package/docs/examples/functions/get.md +2 -0
  300. package/docs/examples/functions/list-deployments.md +2 -0
  301. package/docs/examples/functions/list-executions.md +2 -0
  302. package/docs/examples/functions/list-runtimes.md +1 -0
  303. package/docs/examples/functions/list-specifications.md +1 -0
  304. package/docs/examples/functions/list-templates.md +1 -0
  305. package/docs/examples/functions/list-usage.md +1 -0
  306. package/docs/examples/functions/list-variables.md +2 -0
  307. package/docs/examples/functions/list.md +1 -0
  308. package/docs/examples/functions/update-deployment-status.md +3 -0
  309. package/docs/examples/functions/update-function-deployment.md +3 -0
  310. package/docs/examples/functions/update-variable.md +4 -0
  311. package/docs/examples/functions/update.md +3 -0
  312. package/docs/examples/graphql/mutation.md +2 -0
  313. package/docs/examples/graphql/query.md +2 -0
  314. package/docs/examples/health/get-antivirus.md +1 -0
  315. package/docs/examples/health/get-cache.md +1 -0
  316. package/docs/examples/health/get-certificate.md +1 -0
  317. package/docs/examples/health/get-db.md +1 -0
  318. package/docs/examples/health/get-failed-jobs.md +2 -0
  319. package/docs/examples/health/get-pub-sub.md +1 -0
  320. package/docs/examples/health/get-queue-builds.md +1 -0
  321. package/docs/examples/health/get-queue-certificates.md +1 -0
  322. package/docs/examples/health/get-queue-databases.md +1 -0
  323. package/docs/examples/health/get-queue-deletes.md +1 -0
  324. package/docs/examples/health/get-queue-functions.md +1 -0
  325. package/docs/examples/health/get-queue-logs.md +1 -0
  326. package/docs/examples/health/get-queue-mails.md +1 -0
  327. package/docs/examples/health/get-queue-messaging.md +1 -0
  328. package/docs/examples/health/get-queue-migrations.md +1 -0
  329. package/docs/examples/health/get-queue-stats-resources.md +1 -0
  330. package/docs/examples/health/get-queue-usage.md +1 -0
  331. package/docs/examples/health/get-queue-webhooks.md +1 -0
  332. package/docs/examples/health/get-storage-local.md +1 -0
  333. package/docs/examples/health/get-storage.md +1 -0
  334. package/docs/examples/health/get-time.md +1 -0
  335. package/docs/examples/health/get.md +1 -0
  336. package/docs/examples/locale/get.md +1 -0
  337. package/docs/examples/locale/list-codes.md +1 -0
  338. package/docs/examples/locale/list-continents.md +1 -0
  339. package/docs/examples/locale/list-countries-eu.md +1 -0
  340. package/docs/examples/locale/list-countries-phones.md +1 -0
  341. package/docs/examples/locale/list-countries.md +1 -0
  342. package/docs/examples/locale/list-currencies.md +1 -0
  343. package/docs/examples/locale/list-languages.md +1 -0
  344. package/docs/examples/messaging/create-apns-provider.md +3 -0
  345. package/docs/examples/messaging/create-email.md +4 -0
  346. package/docs/examples/messaging/create-fcm-provider.md +3 -0
  347. package/docs/examples/messaging/create-mailgun-provider.md +3 -0
  348. package/docs/examples/messaging/create-msg-91-provider.md +3 -0
  349. package/docs/examples/messaging/create-push.md +2 -0
  350. package/docs/examples/messaging/create-resend-provider.md +3 -0
  351. package/docs/examples/messaging/create-sendgrid-provider.md +3 -0
  352. package/docs/examples/messaging/create-sms.md +3 -0
  353. package/docs/examples/messaging/create-smtp-provider.md +4 -0
  354. package/docs/examples/messaging/create-subscriber.md +4 -0
  355. package/docs/examples/messaging/create-telesign-provider.md +3 -0
  356. package/docs/examples/messaging/create-textmagic-provider.md +3 -0
  357. package/docs/examples/messaging/create-topic.md +3 -0
  358. package/docs/examples/messaging/create-twilio-provider.md +3 -0
  359. package/docs/examples/messaging/create-vonage-provider.md +3 -0
  360. package/docs/examples/messaging/delete-provider.md +2 -0
  361. package/docs/examples/messaging/delete-subscriber.md +3 -0
  362. package/docs/examples/messaging/delete-topic.md +2 -0
  363. package/docs/examples/messaging/delete.md +2 -0
  364. package/docs/examples/messaging/get-message.md +2 -0
  365. package/docs/examples/messaging/get-provider.md +2 -0
  366. package/docs/examples/messaging/get-subscriber.md +3 -0
  367. package/docs/examples/messaging/get-topic.md +2 -0
  368. package/docs/examples/messaging/list-message-logs.md +2 -0
  369. package/docs/examples/messaging/list-messages.md +1 -0
  370. package/docs/examples/messaging/list-provider-logs.md +2 -0
  371. package/docs/examples/messaging/list-providers.md +1 -0
  372. package/docs/examples/messaging/list-subscriber-logs.md +2 -0
  373. package/docs/examples/messaging/list-subscribers.md +2 -0
  374. package/docs/examples/messaging/list-targets.md +2 -0
  375. package/docs/examples/messaging/list-topic-logs.md +2 -0
  376. package/docs/examples/messaging/list-topics.md +1 -0
  377. package/docs/examples/messaging/update-apns-provider.md +2 -0
  378. package/docs/examples/messaging/update-email.md +2 -0
  379. package/docs/examples/messaging/update-fcm-provider.md +2 -0
  380. package/docs/examples/messaging/update-mailgun-provider.md +2 -0
  381. package/docs/examples/messaging/update-msg-91-provider.md +2 -0
  382. package/docs/examples/messaging/update-push.md +2 -0
  383. package/docs/examples/messaging/update-resend-provider.md +2 -0
  384. package/docs/examples/messaging/update-sendgrid-provider.md +2 -0
  385. package/docs/examples/messaging/update-sms.md +2 -0
  386. package/docs/examples/messaging/update-smtp-provider.md +2 -0
  387. package/docs/examples/messaging/update-telesign-provider.md +2 -0
  388. package/docs/examples/messaging/update-textmagic-provider.md +2 -0
  389. package/docs/examples/messaging/update-topic.md +2 -0
  390. package/docs/examples/messaging/update-twilio-provider.md +2 -0
  391. package/docs/examples/messaging/update-vonage-provider.md +2 -0
  392. package/docs/examples/migrations/create-appwrite-migration.md +5 -0
  393. package/docs/examples/migrations/create-csv-export.md +3 -0
  394. package/docs/examples/migrations/create-csv-import.md +4 -0
  395. package/docs/examples/migrations/create-firebase-migration.md +3 -0
  396. package/docs/examples/migrations/create-n-host-migration.md +8 -0
  397. package/docs/examples/migrations/create-supabase-migration.md +7 -0
  398. package/docs/examples/migrations/delete.md +2 -0
  399. package/docs/examples/migrations/get-appwrite-report.md +5 -0
  400. package/docs/examples/migrations/get-firebase-report.md +3 -0
  401. package/docs/examples/migrations/get-n-host-report.md +8 -0
  402. package/docs/examples/migrations/get-supabase-report.md +7 -0
  403. package/docs/examples/migrations/get.md +2 -0
  404. package/docs/examples/migrations/list.md +1 -0
  405. package/docs/examples/migrations/retry.md +2 -0
  406. package/docs/examples/project/create-variable.md +3 -0
  407. package/docs/examples/project/delete-variable.md +2 -0
  408. package/docs/examples/project/get-usage.md +3 -0
  409. package/docs/examples/project/get-variable.md +2 -0
  410. package/docs/examples/project/list-variables.md +1 -0
  411. package/docs/examples/project/update-variable.md +3 -0
  412. package/docs/examples/projects/create-dev-key.md +4 -0
  413. package/docs/examples/projects/create-jwt.md +3 -0
  414. package/docs/examples/projects/create-key.md +4 -0
  415. package/docs/examples/projects/create-platform.md +4 -0
  416. package/docs/examples/projects/create-smtp-test.md +6 -0
  417. package/docs/examples/projects/create-webhook.md +6 -0
  418. package/docs/examples/projects/create.md +4 -0
  419. package/docs/examples/projects/delete-dev-key.md +3 -0
  420. package/docs/examples/projects/delete-email-template.md +4 -0
  421. package/docs/examples/projects/delete-key.md +3 -0
  422. package/docs/examples/projects/delete-platform.md +3 -0
  423. package/docs/examples/projects/delete-sms-template.md +4 -0
  424. package/docs/examples/projects/delete-webhook.md +3 -0
  425. package/docs/examples/projects/delete.md +2 -0
  426. package/docs/examples/projects/get-dev-key.md +3 -0
  427. package/docs/examples/projects/get-email-template.md +4 -0
  428. package/docs/examples/projects/get-key.md +3 -0
  429. package/docs/examples/projects/get-platform.md +3 -0
  430. package/docs/examples/projects/get-sms-template.md +4 -0
  431. package/docs/examples/projects/get-webhook.md +3 -0
  432. package/docs/examples/projects/get.md +2 -0
  433. package/docs/examples/projects/list-dev-keys.md +2 -0
  434. package/docs/examples/projects/list-keys.md +2 -0
  435. package/docs/examples/projects/list-platforms.md +2 -0
  436. package/docs/examples/projects/list-webhooks.md +2 -0
  437. package/docs/examples/projects/list.md +1 -0
  438. package/docs/examples/projects/update-api-status-all.md +3 -0
  439. package/docs/examples/projects/update-api-status.md +4 -0
  440. package/docs/examples/projects/update-auth-duration.md +3 -0
  441. package/docs/examples/projects/update-auth-limit.md +3 -0
  442. package/docs/examples/projects/update-auth-password-dictionary.md +3 -0
  443. package/docs/examples/projects/update-auth-password-history.md +3 -0
  444. package/docs/examples/projects/update-auth-sessions-limit.md +3 -0
  445. package/docs/examples/projects/update-auth-status.md +4 -0
  446. package/docs/examples/projects/update-dev-key.md +5 -0
  447. package/docs/examples/projects/update-email-template.md +6 -0
  448. package/docs/examples/projects/update-key.md +5 -0
  449. package/docs/examples/projects/update-memberships-privacy.md +5 -0
  450. package/docs/examples/projects/update-mock-numbers.md +3 -0
  451. package/docs/examples/projects/update-o-auth-2.md +3 -0
  452. package/docs/examples/projects/update-personal-data-check.md +3 -0
  453. package/docs/examples/projects/update-platform.md +4 -0
  454. package/docs/examples/projects/update-service-status-all.md +3 -0
  455. package/docs/examples/projects/update-service-status.md +4 -0
  456. package/docs/examples/projects/update-session-alerts.md +3 -0
  457. package/docs/examples/projects/update-session-invalidation.md +3 -0
  458. package/docs/examples/projects/update-sms-template.md +5 -0
  459. package/docs/examples/projects/update-smtp.md +3 -0
  460. package/docs/examples/projects/update-team.md +3 -0
  461. package/docs/examples/projects/update-webhook-signature.md +3 -0
  462. package/docs/examples/projects/update-webhook.md +7 -0
  463. package/docs/examples/projects/update.md +3 -0
  464. package/docs/examples/proxy/create-api-rule.md +2 -0
  465. package/docs/examples/proxy/create-function-rule.md +3 -0
  466. package/docs/examples/proxy/create-redirect-rule.md +6 -0
  467. package/docs/examples/proxy/create-site-rule.md +3 -0
  468. package/docs/examples/proxy/delete-rule.md +2 -0
  469. package/docs/examples/proxy/get-rule.md +2 -0
  470. package/docs/examples/proxy/list-rules.md +1 -0
  471. package/docs/examples/proxy/update-rule-verification.md +2 -0
  472. package/docs/examples/sites/create-deployment.md +4 -0
  473. package/docs/examples/sites/create-duplicate-deployment.md +3 -0
  474. package/docs/examples/sites/create-template-deployment.md +7 -0
  475. package/docs/examples/sites/create-variable.md +4 -0
  476. package/docs/examples/sites/create-vcs-deployment.md +4 -0
  477. package/docs/examples/sites/create.md +5 -0
  478. package/docs/examples/sites/delete-deployment.md +3 -0
  479. package/docs/examples/sites/delete-log.md +3 -0
  480. package/docs/examples/sites/delete-variable.md +3 -0
  481. package/docs/examples/sites/delete.md +2 -0
  482. package/docs/examples/sites/get-deployment-download.md +3 -0
  483. package/docs/examples/sites/get-deployment.md +3 -0
  484. package/docs/examples/sites/get-log.md +3 -0
  485. package/docs/examples/sites/get-template.md +2 -0
  486. package/docs/examples/sites/get-usage.md +2 -0
  487. package/docs/examples/sites/get-variable.md +3 -0
  488. package/docs/examples/sites/get.md +2 -0
  489. package/docs/examples/sites/list-deployments.md +2 -0
  490. package/docs/examples/sites/list-frameworks.md +1 -0
  491. package/docs/examples/sites/list-logs.md +2 -0
  492. package/docs/examples/sites/list-specifications.md +1 -0
  493. package/docs/examples/sites/list-templates.md +1 -0
  494. package/docs/examples/sites/list-usage.md +1 -0
  495. package/docs/examples/sites/list-variables.md +2 -0
  496. package/docs/examples/sites/list.md +1 -0
  497. package/docs/examples/sites/update-deployment-status.md +3 -0
  498. package/docs/examples/sites/update-site-deployment.md +3 -0
  499. package/docs/examples/sites/update-variable.md +4 -0
  500. package/docs/examples/sites/update.md +4 -0
  501. package/docs/examples/storage/create-bucket.md +3 -0
  502. package/docs/examples/storage/create-file.md +4 -0
  503. package/docs/examples/storage/delete-bucket.md +2 -0
  504. package/docs/examples/storage/delete-file.md +3 -0
  505. package/docs/examples/storage/get-bucket-usage.md +2 -0
  506. package/docs/examples/storage/get-bucket.md +2 -0
  507. package/docs/examples/storage/get-file-download.md +3 -0
  508. package/docs/examples/storage/get-file-preview.md +3 -0
  509. package/docs/examples/storage/get-file-view.md +3 -0
  510. package/docs/examples/storage/get-file.md +3 -0
  511. package/docs/examples/storage/get-usage.md +1 -0
  512. package/docs/examples/storage/list-buckets.md +1 -0
  513. package/docs/examples/storage/list-files.md +2 -0
  514. package/docs/examples/storage/update-bucket.md +3 -0
  515. package/docs/examples/storage/update-file.md +3 -0
  516. package/docs/examples/tablesdb/create-boolean-column.md +5 -0
  517. package/docs/examples/tablesdb/create-datetime-column.md +5 -0
  518. package/docs/examples/tablesdb/create-email-column.md +5 -0
  519. package/docs/examples/tablesdb/create-enum-column.md +6 -0
  520. package/docs/examples/tablesdb/create-float-column.md +5 -0
  521. package/docs/examples/tablesdb/create-index.md +6 -0
  522. package/docs/examples/tablesdb/create-integer-column.md +5 -0
  523. package/docs/examples/tablesdb/create-ip-column.md +5 -0
  524. package/docs/examples/tablesdb/create-line-column.md +5 -0
  525. package/docs/examples/tablesdb/create-operations.md +2 -0
  526. package/docs/examples/tablesdb/create-point-column.md +5 -0
  527. package/docs/examples/tablesdb/create-polygon-column.md +5 -0
  528. package/docs/examples/tablesdb/create-relationship-column.md +5 -0
  529. package/docs/examples/tablesdb/create-row.md +5 -0
  530. package/docs/examples/tablesdb/create-rows.md +4 -0
  531. package/docs/examples/tablesdb/create-string-column.md +6 -0
  532. package/docs/examples/tablesdb/create-table.md +4 -0
  533. package/docs/examples/tablesdb/create-transaction.md +1 -0
  534. package/docs/examples/tablesdb/create-url-column.md +5 -0
  535. package/docs/examples/tablesdb/create.md +3 -0
  536. package/docs/examples/tablesdb/decrement-row-column.md +5 -0
  537. package/docs/examples/tablesdb/delete-column.md +4 -0
  538. package/docs/examples/tablesdb/delete-index.md +4 -0
  539. package/docs/examples/tablesdb/delete-row.md +4 -0
  540. package/docs/examples/tablesdb/delete-rows.md +3 -0
  541. package/docs/examples/tablesdb/delete-table.md +3 -0
  542. package/docs/examples/tablesdb/delete-transaction.md +2 -0
  543. package/docs/examples/tablesdb/delete.md +2 -0
  544. package/docs/examples/tablesdb/get-column.md +4 -0
  545. package/docs/examples/tablesdb/get-index.md +4 -0
  546. package/docs/examples/tablesdb/get-row.md +4 -0
  547. package/docs/examples/tablesdb/get-table-usage.md +3 -0
  548. package/docs/examples/tablesdb/get-table.md +3 -0
  549. package/docs/examples/tablesdb/get-transaction.md +2 -0
  550. package/docs/examples/tablesdb/get-usage.md +2 -0
  551. package/docs/examples/tablesdb/get.md +2 -0
  552. package/docs/examples/tablesdb/increment-row-column.md +5 -0
  553. package/docs/examples/tablesdb/list-columns.md +3 -0
  554. package/docs/examples/tablesdb/list-indexes.md +3 -0
  555. package/docs/examples/tablesdb/list-row-logs.md +4 -0
  556. package/docs/examples/tablesdb/list-rows.md +3 -0
  557. package/docs/examples/tablesdb/list-table-logs.md +3 -0
  558. package/docs/examples/tablesdb/list-tables.md +2 -0
  559. package/docs/examples/tablesdb/list-transactions.md +1 -0
  560. package/docs/examples/tablesdb/list-usage.md +1 -0
  561. package/docs/examples/tablesdb/list.md +1 -0
  562. package/docs/examples/tablesdb/update-boolean-column.md +6 -0
  563. package/docs/examples/tablesdb/update-datetime-column.md +6 -0
  564. package/docs/examples/tablesdb/update-email-column.md +6 -0
  565. package/docs/examples/tablesdb/update-enum-column.md +7 -0
  566. package/docs/examples/tablesdb/update-float-column.md +6 -0
  567. package/docs/examples/tablesdb/update-integer-column.md +6 -0
  568. package/docs/examples/tablesdb/update-ip-column.md +6 -0
  569. package/docs/examples/tablesdb/update-line-column.md +5 -0
  570. package/docs/examples/tablesdb/update-point-column.md +5 -0
  571. package/docs/examples/tablesdb/update-polygon-column.md +5 -0
  572. package/docs/examples/tablesdb/update-relationship-column.md +4 -0
  573. package/docs/examples/tablesdb/update-row.md +4 -0
  574. package/docs/examples/tablesdb/update-rows.md +3 -0
  575. package/docs/examples/tablesdb/update-string-column.md +6 -0
  576. package/docs/examples/tablesdb/update-table.md +4 -0
  577. package/docs/examples/tablesdb/update-transaction.md +2 -0
  578. package/docs/examples/tablesdb/update-url-column.md +6 -0
  579. package/docs/examples/tablesdb/update.md +3 -0
  580. package/docs/examples/tablesdb/upsert-row.md +4 -0
  581. package/docs/examples/tablesdb/upsert-rows.md +4 -0
  582. package/docs/examples/teams/create-membership.md +3 -0
  583. package/docs/examples/teams/create.md +3 -0
  584. package/docs/examples/teams/delete-membership.md +3 -0
  585. package/docs/examples/teams/delete.md +2 -0
  586. package/docs/examples/teams/get-membership.md +3 -0
  587. package/docs/examples/teams/get-prefs.md +2 -0
  588. package/docs/examples/teams/get.md +2 -0
  589. package/docs/examples/teams/list-logs.md +2 -0
  590. package/docs/examples/teams/list-memberships.md +2 -0
  591. package/docs/examples/teams/list.md +1 -0
  592. package/docs/examples/teams/update-membership-status.md +5 -0
  593. package/docs/examples/teams/update-membership.md +4 -0
  594. package/docs/examples/teams/update-name.md +3 -0
  595. package/docs/examples/teams/update-prefs.md +3 -0
  596. package/docs/examples/tokens/create-file-token.md +3 -0
  597. package/docs/examples/tokens/delete.md +2 -0
  598. package/docs/examples/tokens/get.md +2 -0
  599. package/docs/examples/tokens/list.md +3 -0
  600. package/docs/examples/tokens/update.md +2 -0
  601. package/docs/examples/users/create-argon-2-user.md +4 -0
  602. package/docs/examples/users/create-bcrypt-user.md +4 -0
  603. package/docs/examples/users/create-jwt.md +2 -0
  604. package/docs/examples/users/create-md-5-user.md +4 -0
  605. package/docs/examples/users/create-mfa-recovery-codes.md +2 -0
  606. package/docs/examples/users/create-ph-pass-user.md +4 -0
  607. package/docs/examples/users/create-scrypt-modified-user.md +7 -0
  608. package/docs/examples/users/create-scrypt-user.md +9 -0
  609. package/docs/examples/users/create-session.md +2 -0
  610. package/docs/examples/users/create-sha-user.md +4 -0
  611. package/docs/examples/users/create-target.md +5 -0
  612. package/docs/examples/users/create-token.md +2 -0
  613. package/docs/examples/users/create.md +2 -0
  614. package/docs/examples/users/delete-identity.md +2 -0
  615. package/docs/examples/users/delete-mfa-authenticator.md +3 -0
  616. package/docs/examples/users/delete-session.md +3 -0
  617. package/docs/examples/users/delete-sessions.md +2 -0
  618. package/docs/examples/users/delete-target.md +3 -0
  619. package/docs/examples/users/delete.md +2 -0
  620. package/docs/examples/users/get-mfa-recovery-codes.md +2 -0
  621. package/docs/examples/users/get-prefs.md +2 -0
  622. package/docs/examples/users/get-target.md +3 -0
  623. package/docs/examples/users/get-usage.md +1 -0
  624. package/docs/examples/users/get.md +2 -0
  625. package/docs/examples/users/list-identities.md +1 -0
  626. package/docs/examples/users/list-logs.md +2 -0
  627. package/docs/examples/users/list-memberships.md +2 -0
  628. package/docs/examples/users/list-mfa-factors.md +2 -0
  629. package/docs/examples/users/list-sessions.md +2 -0
  630. package/docs/examples/users/list-targets.md +2 -0
  631. package/docs/examples/users/list.md +1 -0
  632. package/docs/examples/users/update-email-verification.md +3 -0
  633. package/docs/examples/users/update-email.md +3 -0
  634. package/docs/examples/users/update-labels.md +3 -0
  635. package/docs/examples/users/update-mfa-recovery-codes.md +2 -0
  636. package/docs/examples/users/update-mfa.md +3 -0
  637. package/docs/examples/users/update-name.md +3 -0
  638. package/docs/examples/users/update-password.md +3 -0
  639. package/docs/examples/users/update-phone-verification.md +3 -0
  640. package/docs/examples/users/update-phone.md +3 -0
  641. package/docs/examples/users/update-prefs.md +3 -0
  642. package/docs/examples/users/update-status.md +3 -0
  643. package/docs/examples/users/update-target.md +3 -0
  644. package/docs/examples/vcs/create-repository-detection.md +4 -0
  645. package/docs/examples/vcs/create-repository.md +4 -0
  646. package/docs/examples/vcs/delete-installation.md +2 -0
  647. package/docs/examples/vcs/get-installation.md +2 -0
  648. package/docs/examples/vcs/get-repository-contents.md +3 -0
  649. package/docs/examples/vcs/get-repository.md +3 -0
  650. package/docs/examples/vcs/list-installations.md +1 -0
  651. package/docs/examples/vcs/list-repositories.md +3 -0
  652. package/docs/examples/vcs/list-repository-branches.md +3 -0
  653. package/docs/examples/vcs/update-external-deployments.md +4 -0
  654. package/index.ts +25 -165
  655. package/install.ps1 +2 -2
  656. package/install.sh +1 -1
  657. package/lib/client.ts +14 -6
  658. package/lib/commands/config.ts +494 -0
  659. package/lib/commands/db.ts +324 -0
  660. package/lib/commands/errors.ts +93 -0
  661. package/lib/commands/init.ts +25 -14
  662. package/lib/commands/pull.ts +683 -420
  663. package/lib/commands/push.ts +1677 -2404
  664. package/lib/commands/run.ts +1 -1
  665. package/lib/commands/schema.ts +122 -0
  666. package/lib/commands/services/account.ts +200 -385
  667. package/lib/commands/services/console.ts +13 -34
  668. package/lib/commands/services/databases.ts +298 -1215
  669. package/lib/commands/services/functions.ts +115 -434
  670. package/lib/commands/services/graphql.ts +5 -2
  671. package/lib/commands/services/health.ts +87 -149
  672. package/lib/commands/services/locale.ts +36 -33
  673. package/lib/commands/services/messaging.ts +180 -999
  674. package/lib/commands/services/migrations.ts +54 -226
  675. package/lib/commands/services/project.ts +19 -23
  676. package/lib/commands/services/projects.ts +182 -714
  677. package/lib/commands/services/proxy.ts +30 -58
  678. package/lib/commands/services/sites.ts +107 -379
  679. package/lib/commands/services/storage.ts +93 -302
  680. package/lib/commands/services/tables-db.ts +1150 -0
  681. package/lib/commands/services/teams.ts +48 -110
  682. package/lib/commands/services/tokens.ts +16 -28
  683. package/lib/commands/services/users.ts +133 -403
  684. package/lib/commands/services/vcs.ts +48 -151
  685. package/lib/commands/types.ts +1 -1
  686. package/lib/commands/update.ts +13 -22
  687. package/lib/commands/utils/attributes.ts +719 -0
  688. package/lib/commands/utils/change-approval.ts +186 -0
  689. package/lib/commands/utils/database-sync.ts +180 -0
  690. package/lib/commands/utils/deployment.ts +184 -0
  691. package/lib/commands/utils/error-formatter.ts +417 -0
  692. package/lib/commands/utils/pools.ts +355 -0
  693. package/lib/config.ts +46 -82
  694. package/lib/constants.ts +22 -0
  695. package/lib/emulation/docker.ts +101 -87
  696. package/lib/parser.ts +16 -11
  697. package/lib/questions.ts +20 -21
  698. package/lib/sdks.ts +15 -11
  699. package/lib/types.ts +0 -229
  700. package/lib/utils.ts +45 -4
  701. package/package.json +12 -11
  702. package/scoop/appwrite.config.json +29 -19
  703. package/.github/workflows/build-verify.yml +0 -71
  704. package/bun.lock +0 -625
  705. package/dist/lib/commands/services/avatars.d.ts +0 -3
  706. package/dist/lib/commands/services/avatars.d.ts.map +0 -1
  707. package/dist/lib/commands/services/avatars.js +0 -118
  708. package/dist/lib/commands/services/avatars.js.map +0 -1
  709. package/dist/lib/commands/services/tablesdb.d.ts +0 -3
  710. package/dist/lib/commands/services/tablesdb.d.ts.map +0 -1
  711. package/dist/lib/commands/services/tablesdb.js.map +0 -1
  712. package/dist/scripts/generate-commands.d.ts +0 -2
  713. package/dist/scripts/generate-commands.d.ts.map +0 -1
  714. package/dist/scripts/generate-commands.js +0 -398
  715. package/dist/scripts/generate-commands.js.map +0 -1
  716. package/lib/commands/services/avatars.ts +0 -400
  717. package/lib/commands/services/tablesdb.ts +0 -1928
  718. package/scripts/generate-commands.ts +0 -539
@@ -1,22 +1,26 @@
1
1
  import fs from "fs";
2
+ import path from "path";
2
3
  import chalk from "chalk";
3
- import tar from "tar";
4
4
  import { Command } from "commander";
5
5
  import inquirer from "inquirer";
6
6
  import {
7
- getMessagingService,
8
- getTeamsService,
9
- getProjectsService,
10
- getFunctionsService,
11
- getSitesService,
12
- getDatabasesService,
13
- getTablesDBService,
14
- getStorageService,
15
- } from "../services.js";
7
+ Databases,
8
+ Functions,
9
+ Messaging,
10
+ Projects,
11
+ Sites,
12
+ Storage,
13
+ TablesDB,
14
+ Teams,
15
+ Client,
16
+ Query,
17
+ Models,
18
+ } from "@appwrite.io/console";
19
+ import { getFunctionsService, getSitesService } from "../services.js";
20
+ import { sdkForProject, sdkForConsole } from "../sdks.js";
16
21
  import { localConfig } from "../config.js";
17
22
  import { paginate } from "../paginate.js";
18
23
  import {
19
- questionsPullCollection,
20
24
  questionsPullFunctions,
21
25
  questionsPullFunctionsCode,
22
26
  questionsPullSites,
@@ -32,573 +36,832 @@ import {
32
36
  actionRunner,
33
37
  commandDescriptions,
34
38
  } from "../parser.js";
35
-
36
- interface PullResourcesOptions {
39
+ import type { ConfigType } from "./config.js";
40
+ import { createSettingsObject } from "../utils.js";
41
+ import { ProjectNotInitializedError } from "./errors.js";
42
+ import type { SettingsType, FunctionType, SiteType } from "./config.js";
43
+ import { downloadDeploymentCode } from "./utils/deployment.js";
44
+
45
+ export interface PullOptions {
46
+ all?: boolean;
47
+ settings?: boolean;
48
+ functions?: boolean;
49
+ sites?: boolean;
50
+ collections?: boolean;
51
+ tables?: boolean;
52
+ buckets?: boolean;
53
+ teams?: boolean;
54
+ topics?: boolean;
37
55
  skipDeprecated?: boolean;
56
+ withVariables?: boolean;
57
+ noCode?: boolean;
38
58
  }
39
59
 
40
60
  interface PullFunctionsOptions {
41
61
  code?: boolean;
42
62
  withVariables?: boolean;
63
+ functionIds?: string[];
43
64
  }
44
65
 
45
66
  interface PullSitesOptions {
46
67
  code?: boolean;
47
68
  withVariables?: boolean;
69
+ siteIds?: string[];
48
70
  }
49
71
 
50
- export const pullResources = async ({
51
- skipDeprecated = false,
52
- }: PullResourcesOptions = {}): Promise<void> => {
53
- const project = localConfig.getProject();
54
- if (!project.projectId) {
55
- error(
56
- "Project configuration not found. Please run 'appwrite init project' to initialize your project first.",
57
- );
58
- process.exit(1);
72
+ export interface PullSettingsResult {
73
+ projectName: string;
74
+ settings: SettingsType;
75
+ project: Models.Project;
76
+ }
77
+
78
+ async function createPullInstance(): Promise<Pull> {
79
+ const projectClient = await sdkForProject();
80
+ const consoleClient = await sdkForConsole();
81
+ const pullInstance = new Pull(projectClient, consoleClient);
82
+
83
+ pullInstance.setConfigDirectoryPath(localConfig.configDirectoryPath);
84
+ return pullInstance;
85
+ }
86
+
87
+ export class Pull {
88
+ private projectClient: Client;
89
+ private consoleClient: Client;
90
+ private configDirectoryPath: string;
91
+ private silent: boolean;
92
+
93
+ constructor(projectClient: Client, consoleClient: Client, silent = false) {
94
+ this.projectClient = projectClient;
95
+ this.consoleClient = consoleClient;
96
+ this.configDirectoryPath = process.cwd();
97
+ this.silent = silent;
59
98
  }
60
99
 
61
- const actions: Record<string, (options?: any) => Promise<void>> = {
62
- settings: pullSettings,
63
- functions: pullFunctions,
64
- sites: pullSites,
65
- collections: pullCollection,
66
- tables: pullTable,
67
- buckets: pullBucket,
68
- teams: pullTeam,
69
- messages: pullMessagingTopic,
70
- };
100
+ /**
101
+ * Set the base directory path for config files and resources
102
+ */
103
+ public setConfigDirectoryPath(path: string): void {
104
+ this.configDirectoryPath = path;
105
+ }
71
106
 
72
- if (skipDeprecated) {
73
- delete actions.collections;
107
+ /**
108
+ * Log a message (respects silent mode)
109
+ */
110
+ private log(message: string): void {
111
+ if (!this.silent) {
112
+ log(message);
113
+ }
74
114
  }
75
115
 
76
- if (cliConfig.all) {
77
- for (let action of Object.values(actions)) {
78
- cliConfig.all = true;
79
- await action({ returnOnZero: true });
116
+ /**
117
+ * Log a success message (respects silent mode)
118
+ */
119
+ private success(message: string): void {
120
+ if (!this.silent) {
121
+ success(message);
80
122
  }
81
- } else {
82
- const answers = await inquirer.prompt([questionsPullResources[0]]);
123
+ }
83
124
 
84
- const action = actions[answers.resource];
85
- if (action !== undefined) {
86
- await action({ returnOnZero: true });
125
+ /**
126
+ * Log a warning message (respects silent mode)
127
+ */
128
+ private warn(message: string): void {
129
+ if (!this.silent) {
130
+ warn(message);
87
131
  }
88
132
  }
89
- };
90
133
 
91
- const pullSettings = async (): Promise<void> => {
92
- log("Pulling project settings ...");
134
+ /**
135
+ * Pull resources from Appwrite project and return updated config
136
+ *
137
+ * @param config - Current configuration object
138
+ * @param options - Pull options specifying which resources to pull
139
+ * @returns Updated configuration object with pulled resources
140
+ */
141
+ public async pullResources(
142
+ config: ConfigType,
143
+ options: PullOptions = { all: true, skipDeprecated: true },
144
+ ): Promise<ConfigType> {
145
+ const { skipDeprecated = true } = options;
146
+ if (!config.projectId) {
147
+ throw new ProjectNotInitializedError();
148
+ }
93
149
 
94
- try {
95
- const projectsService = await getProjectsService();
96
- let response = await projectsService.get(
97
- localConfig.getProject().projectId,
98
- );
150
+ const updatedConfig: ConfigType = { ...config };
151
+ const shouldPullAll = options.all === true;
99
152
 
100
- localConfig.setProject(response.$id, response.name, response);
153
+ if (shouldPullAll || options.settings) {
154
+ const settings = await this.pullSettings(config.projectId);
155
+ updatedConfig.settings = settings.settings;
156
+ updatedConfig.projectName = settings.projectName;
157
+ }
101
158
 
102
- success(`Successfully pulled ${chalk.bold("all")} project settings.`);
103
- } catch (e) {
104
- throw e;
105
- }
106
- };
159
+ if (shouldPullAll || options.functions) {
160
+ const functions = await this.pullFunctions({
161
+ code: options.noCode === true ? false : true,
162
+ withVariables: options.withVariables,
163
+ });
164
+ updatedConfig.functions = functions;
165
+ }
107
166
 
108
- const pullFunctions = async ({
109
- code,
110
- withVariables,
111
- }: PullFunctionsOptions = {}): Promise<void> => {
112
- process.chdir(localConfig.configDirectoryPath);
167
+ if (shouldPullAll || options.sites) {
168
+ const sites = await this.pullSites({
169
+ code: options.noCode === true ? false : true,
170
+ withVariables: options.withVariables,
171
+ });
172
+ updatedConfig.sites = sites;
173
+ }
113
174
 
114
- log("Fetching functions ...");
115
- let total = 0;
175
+ if (shouldPullAll || options.tables) {
176
+ const { databases, tables } = await this.pullTables();
177
+ updatedConfig.databases = databases;
178
+ updatedConfig.tables = tables;
179
+ }
116
180
 
117
- const functionsService = await getFunctionsService();
118
- const fetchResponse = await functionsService.list([
119
- JSON.stringify({ method: "limit", values: [1] }),
120
- ]);
121
- if (fetchResponse["functions"].length <= 0) {
122
- log("No functions found.");
123
- success(`Successfully pulled ${chalk.bold(total)} functions.`);
124
- return;
181
+ if (options.collections || (shouldPullAll && !skipDeprecated)) {
182
+ const { databases, collections } = await this.pullCollections();
183
+ updatedConfig.databases = databases;
184
+ updatedConfig.collections = collections;
185
+ }
186
+
187
+ if (shouldPullAll || options.buckets) {
188
+ const buckets = await this.pullBuckets();
189
+ updatedConfig.buckets = buckets;
190
+ }
191
+
192
+ if (shouldPullAll || options.teams) {
193
+ const teams = await this.pullTeams();
194
+ updatedConfig.teams = teams;
195
+ }
196
+
197
+ if (shouldPullAll || options.topics) {
198
+ const topics = await this.pullMessagingTopics();
199
+ updatedConfig.topics = topics;
200
+ }
201
+
202
+ return updatedConfig;
125
203
  }
126
204
 
127
- const functions = cliConfig.all
128
- ? (
129
- await paginate(
130
- async () => (await getFunctionsService()).list(),
131
- {},
132
- 100,
133
- "functions",
134
- )
135
- ).functions
136
- : (await inquirer.prompt(questionsPullFunctions)).functions;
205
+ /**
206
+ * Pull project settings
207
+ */
208
+ public async pullSettings(projectId: string): Promise<PullSettingsResult> {
209
+ this.log("Pulling project settings ...");
137
210
 
138
- let allowCodePull: boolean | null = cliConfig.force === true ? true : null;
211
+ const projectsService = new Projects(this.consoleClient);
212
+ const project = await projectsService.get({ projectId: projectId });
139
213
 
140
- for (let func of functions) {
141
- total++;
142
- log(`Pulling function ${chalk.bold(func["name"])} ...`);
214
+ this.success(`Successfully pulled ${chalk.bold("all")} project settings.`);
143
215
 
144
- const localFunction = localConfig.getFunction(func.$id);
216
+ return {
217
+ projectName: project.name,
218
+ settings: createSettingsObject(project),
219
+ project,
220
+ };
221
+ }
145
222
 
146
- func["path"] = localFunction["path"];
147
- if (!localFunction["path"]) {
148
- func["path"] = `functions/${func.name}`;
149
- }
150
- const holdingVars = func["vars"];
151
- // We don't save var in to the config
152
- delete func["vars"];
153
- localConfig.addFunction(func);
223
+ /**
224
+ * Pull functions from the project
225
+ */
226
+ public async pullFunctions(
227
+ options: PullFunctionsOptions = {},
228
+ ): Promise<FunctionType[]> {
229
+ this.log("Fetching functions ...");
230
+
231
+ const functionsService = new Functions(this.projectClient);
232
+ let functions: Models.Function[];
233
+
234
+ if (options.functionIds && options.functionIds.length > 0) {
235
+ functions = await Promise.all(
236
+ options.functionIds.map((id) =>
237
+ functionsService.get({
238
+ functionId: id,
239
+ }),
240
+ ),
241
+ );
242
+ } else {
243
+ const fetchResponse = await functionsService.list({
244
+ queries: [Query.limit(1)],
245
+ });
154
246
 
155
- if (!fs.existsSync(func["path"])) {
156
- fs.mkdirSync(func["path"], { recursive: true });
157
- }
247
+ if (fetchResponse["functions"].length <= 0) {
248
+ this.log("No functions found.");
249
+ this.success(`Successfully pulled ${chalk.bold(0)} functions.`);
250
+ return [];
251
+ }
158
252
 
159
- if (code === false) {
160
- warn("Source code download skipped.");
161
- continue;
253
+ const { functions: allFunctions } = await paginate(
254
+ async () => new Functions(this.projectClient).list(),
255
+ {},
256
+ 100,
257
+ "functions",
258
+ );
259
+ functions = allFunctions;
162
260
  }
163
261
 
164
- if (allowCodePull === null) {
165
- const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
166
- allowCodePull = codeAnswer.override;
262
+ const result: FunctionType[] = [];
263
+
264
+ for (const func of functions) {
265
+ this.log(`Pulling function ${chalk.bold(func.name)} ...`);
266
+
267
+ const funcPath = `functions/${func.name}`;
268
+ const absoluteFuncPath = path.resolve(this.configDirectoryPath, funcPath);
269
+ const holdingVars = func.vars || [];
270
+
271
+ const functionConfig: FunctionType = {
272
+ $id: func.$id,
273
+ name: func.name,
274
+ runtime: func.runtime,
275
+ path: funcPath,
276
+ entrypoint: func.entrypoint,
277
+ execute: func.execute,
278
+ enabled: func.enabled,
279
+ logging: func.logging,
280
+ events: func.events,
281
+ schedule: func.schedule,
282
+ timeout: func.timeout,
283
+ commands: func.commands,
284
+ scopes: func.scopes,
285
+ specification: func.specification,
286
+ };
287
+
288
+ result.push(functionConfig);
289
+
290
+ if (!fs.existsSync(absoluteFuncPath)) {
291
+ fs.mkdirSync(absoluteFuncPath, { recursive: true });
292
+ }
293
+
294
+ if (options.code !== false) {
295
+ await downloadDeploymentCode({
296
+ resourceId: func["$id"],
297
+ resourcePath: absoluteFuncPath,
298
+ holdingVars,
299
+ withVariables: options.withVariables,
300
+ listDeployments: () =>
301
+ functionsService.listDeployments({
302
+ functionId: func["$id"],
303
+ queries: [Query.limit(1), Query.orderDesc("$id")],
304
+ }),
305
+ getDownloadUrl: (deploymentId) =>
306
+ functionsService.getDeploymentDownload({
307
+ functionId: func["$id"],
308
+ deploymentId,
309
+ }),
310
+ projectClient: this.projectClient,
311
+ });
312
+ }
167
313
  }
168
314
 
169
- if (!allowCodePull) {
170
- continue;
315
+ if (options.code === false) {
316
+ this.warn("Source code download skipped.");
171
317
  }
172
318
 
173
- let deploymentId: string | null = null;
319
+ this.success(`Successfully pulled ${chalk.bold(result.length)} functions.`);
320
+ return result;
321
+ }
174
322
 
175
- try {
176
- const fetchResponse = await functionsService.listDeployments({
177
- functionId: func["$id"],
178
- queries: [
179
- JSON.stringify({ method: "limit", values: [1] }),
180
- JSON.stringify({ method: "orderDesc", values: ["$id"] }),
181
- ],
323
+ /**
324
+ * Pull sites from the project
325
+ */
326
+ public async pullSites(options: PullSitesOptions = {}): Promise<SiteType[]> {
327
+ this.log("Fetching sites ...");
328
+
329
+ const sitesService = new Sites(this.projectClient);
330
+ let sites: Models.Site[];
331
+
332
+ if (options.siteIds && options.siteIds.length > 0) {
333
+ sites = await Promise.all(
334
+ options.siteIds.map((id) =>
335
+ sitesService.get({
336
+ siteId: id,
337
+ }),
338
+ ),
339
+ );
340
+ } else {
341
+ const fetchResponse = await sitesService.list({
342
+ queries: [Query.limit(1)],
182
343
  });
183
344
 
184
- if (fetchResponse["total"] > 0) {
185
- deploymentId = fetchResponse["deployments"][0]["$id"];
345
+ if (fetchResponse["sites"].length <= 0) {
346
+ this.log("No sites found.");
347
+ this.success(`Successfully pulled ${chalk.bold(0)} sites.`);
348
+ return [];
186
349
  }
187
- } catch {}
188
350
 
189
- if (deploymentId === null) {
190
- log(
191
- "Source code download skipped because function doesn't have any available deployment",
351
+ const { sites: fetchedSites } = await paginate(
352
+ async () => new Sites(this.projectClient).list(),
353
+ {},
354
+ 100,
355
+ "sites",
192
356
  );
193
- continue;
357
+ sites = fetchedSites;
194
358
  }
195
359
 
196
- log("Pulling latest deployment code ...");
360
+ const result: SiteType[] = [];
361
+
362
+ for (const site of sites) {
363
+ this.log(`Pulling site ${chalk.bold(site.name)} ...`);
364
+
365
+ const sitePath = `sites/${site.name}`;
366
+ const absoluteSitePath = path.resolve(this.configDirectoryPath, sitePath);
367
+ const holdingVars = site.vars || [];
368
+
369
+ const siteConfig: SiteType = {
370
+ $id: site.$id,
371
+ name: site.name,
372
+ path: sitePath,
373
+ framework: site.framework,
374
+ enabled: site.enabled,
375
+ logging: site.logging,
376
+ timeout: site.timeout,
377
+ buildRuntime: site.buildRuntime,
378
+ adapter: site.adapter,
379
+ installCommand: site.installCommand,
380
+ buildCommand: site.buildCommand,
381
+ outputDirectory: site.outputDirectory,
382
+ fallbackFile: site.fallbackFile,
383
+ specification: site.specification,
384
+ };
385
+
386
+ result.push(siteConfig);
387
+
388
+ if (!fs.existsSync(absoluteSitePath)) {
389
+ fs.mkdirSync(absoluteSitePath, { recursive: true });
390
+ }
197
391
 
198
- const compressedFileName = `${func["$id"]}-${+new Date()}.tar.gz`;
199
- const downloadUrl = functionsService.getDeploymentDownload({
200
- functionId: func["$id"],
201
- deploymentId: deploymentId,
202
- });
392
+ if (options.code !== false) {
393
+ await downloadDeploymentCode({
394
+ resourceId: site["$id"],
395
+ resourcePath: absoluteSitePath,
396
+ holdingVars,
397
+ withVariables: options.withVariables,
398
+ listDeployments: () =>
399
+ sitesService.listDeployments({
400
+ siteId: site["$id"],
401
+ queries: [Query.limit(1), Query.orderDesc("$id")],
402
+ }),
403
+ getDownloadUrl: (deploymentId) =>
404
+ sitesService.getDeploymentDownload({
405
+ siteId: site["$id"],
406
+ deploymentId,
407
+ }),
408
+ projectClient: this.projectClient,
409
+ });
410
+ }
411
+ }
203
412
 
204
- const client = (await getFunctionsService()).client;
205
- const downloadBuffer = await client.call(
206
- "get",
207
- new URL(downloadUrl),
208
- {},
209
- {},
210
- "arrayBuffer",
413
+ if (options.code === false) {
414
+ this.warn("Source code download skipped.");
415
+ }
416
+
417
+ this.success(`Successfully pulled ${chalk.bold(result.length)} sites.`);
418
+ return result;
419
+ }
420
+
421
+ /**
422
+ * Pull collections from the project (deprecated)
423
+ */
424
+ public async pullCollections(): Promise<{
425
+ databases: any[];
426
+ collections: any[];
427
+ }> {
428
+ this.warn(
429
+ "appwrite pull collection has been deprecated. Please consider using 'appwrite pull tables' instead",
211
430
  );
431
+ this.log("Fetching collections ...");
212
432
 
213
- fs.writeFileSync(compressedFileName, Buffer.from(downloadBuffer as any));
433
+ const databasesService = new Databases(this.projectClient);
214
434
 
215
- tar.extract({
216
- sync: true,
217
- cwd: func["path"],
218
- file: compressedFileName,
219
- strict: false,
220
- });
435
+ const fetchResponse = await databasesService.list([Query.limit(1)]);
221
436
 
222
- fs.rmSync(compressedFileName);
437
+ if (fetchResponse["databases"].length <= 0) {
438
+ this.log("No collections found.");
439
+ this.success(
440
+ `Successfully pulled ${chalk.bold(0)} collections from ${chalk.bold(0)} databases.`,
441
+ );
442
+ return { databases: [], collections: [] };
443
+ }
223
444
 
224
- if (withVariables) {
225
- const envFileLocation = `${func["path"]}/.env`;
226
- try {
227
- fs.rmSync(envFileLocation);
228
- } catch {}
445
+ const { databases } = await paginate(
446
+ async () => new Databases(this.projectClient).list(),
447
+ {},
448
+ 100,
449
+ "databases",
450
+ );
229
451
 
230
- fs.writeFileSync(
231
- envFileLocation,
232
- holdingVars.map((r: any) => `${r.key}=${r.value}\n`).join(""),
452
+ const allDatabases: any[] = [];
453
+ const allCollections: any[] = [];
454
+
455
+ for (const database of databases) {
456
+ this.log(
457
+ `Pulling all collections from ${chalk.bold(database.name)} database ...`,
458
+ );
459
+ allDatabases.push(database);
460
+
461
+ const { collections } = await paginate(
462
+ async () =>
463
+ new Databases(this.projectClient).listCollections(database.$id),
464
+ {},
465
+ 100,
466
+ "collections",
233
467
  );
468
+
469
+ for (const collection of collections) {
470
+ allCollections.push({
471
+ ...collection,
472
+ $createdAt: undefined,
473
+ $updatedAt: undefined,
474
+ });
475
+ }
234
476
  }
477
+
478
+ this.success(
479
+ `Successfully pulled ${chalk.bold(allCollections.length)} collections from ${chalk.bold(allDatabases.length)} databases.`,
480
+ );
481
+
482
+ return {
483
+ databases: allDatabases,
484
+ collections: allCollections,
485
+ };
235
486
  }
236
487
 
237
- success(`Successfully pulled ${chalk.bold(total)} functions.`);
238
- };
488
+ /**
489
+ * Pull tables from the project
490
+ */
491
+ public async pullTables(): Promise<{
492
+ databases: any[];
493
+ tables: any[];
494
+ }> {
495
+ this.log("Fetching tables ...");
239
496
 
240
- const pullSites = async ({
241
- code,
242
- withVariables,
243
- }: PullSitesOptions = {}): Promise<void> => {
244
- process.chdir(localConfig.configDirectoryPath);
497
+ const tablesDBService = new TablesDB(this.projectClient);
245
498
 
246
- log("Fetching sites ...");
247
- let total = 0;
499
+ const fetchResponse = await tablesDBService.list({
500
+ queries: [Query.limit(1)],
501
+ });
248
502
 
249
- const sitesService = await getSitesService();
250
- const fetchResponse = await sitesService.list([
251
- JSON.stringify({ method: "limit", values: [1] }),
252
- ]);
253
- if (fetchResponse["sites"].length <= 0) {
254
- log("No sites found.");
255
- success(`Successfully pulled ${chalk.bold(total)} sites.`);
256
- return;
257
- }
503
+ if (fetchResponse["databases"].length <= 0) {
504
+ this.log("No tables found.");
505
+ this.success(
506
+ `Successfully pulled ${chalk.bold(0)} tables from ${chalk.bold(0)} tableDBs.`,
507
+ );
508
+ return { databases: [], tables: [] };
509
+ }
258
510
 
259
- const sites = cliConfig.all
260
- ? (
261
- await paginate(
262
- async () => (await getSitesService()).list(),
263
- {},
264
- 100,
265
- "sites",
266
- )
267
- ).sites
268
- : (await inquirer.prompt(questionsPullSites)).sites;
511
+ const { databases } = await paginate(
512
+ async () => new TablesDB(this.projectClient).list(),
513
+ {},
514
+ 100,
515
+ "databases",
516
+ );
269
517
 
270
- let allowCodePull: boolean | null = cliConfig.force === true ? true : null;
518
+ const allDatabases: any[] = [];
519
+ const allTables: any[] = [];
271
520
 
272
- for (let site of sites) {
273
- total++;
274
- log(`Pulling site ${chalk.bold(site["name"])} ...`);
521
+ for (const database of databases) {
522
+ this.log(
523
+ `Pulling all tables from ${chalk.bold(database.name)} database ...`,
524
+ );
525
+ allDatabases.push(database);
275
526
 
276
- const localSite = localConfig.getSite(site.$id);
527
+ const { tables } = await paginate(
528
+ async () => new TablesDB(this.projectClient).listTables(database.$id),
529
+ {},
530
+ 100,
531
+ "tables",
532
+ );
277
533
 
278
- site["path"] = localSite["path"];
279
- if (!localSite["path"]) {
280
- site["path"] = `sites/${site.name}`;
534
+ for (const table of tables) {
535
+ allTables.push({
536
+ ...table,
537
+ $createdAt: undefined,
538
+ $updatedAt: undefined,
539
+ });
540
+ }
281
541
  }
282
- const holdingVars = site["vars"];
283
- // We don't save var in to the config
284
- delete site["vars"];
285
- localConfig.addSite(site);
286
542
 
287
- if (!fs.existsSync(site["path"])) {
288
- fs.mkdirSync(site["path"], { recursive: true });
289
- }
543
+ this.success(
544
+ `Successfully pulled ${chalk.bold(allTables.length)} tables from ${chalk.bold(allDatabases.length)} tableDBs.`,
545
+ );
290
546
 
291
- if (code === false) {
292
- warn("Source code download skipped.");
293
- continue;
294
- }
547
+ return {
548
+ databases: allDatabases,
549
+ tables: allTables,
550
+ };
551
+ }
552
+
553
+ /**
554
+ * Pull storage buckets from the project
555
+ */
556
+ public async pullBuckets(): Promise<any[]> {
557
+ this.log("Fetching buckets ...");
558
+
559
+ const storageService = new Storage(this.projectClient);
295
560
 
296
- if (allowCodePull === null) {
297
- const codeAnswer = await inquirer.prompt(questionsPullSitesCode);
298
- allowCodePull = codeAnswer.override;
561
+ const fetchResponse = await storageService.listBuckets({
562
+ queries: [Query.limit(1)],
563
+ });
564
+
565
+ if (fetchResponse["buckets"].length <= 0) {
566
+ this.log("No buckets found.");
567
+ this.success(`Successfully pulled ${chalk.bold(0)} buckets.`);
568
+ return [];
299
569
  }
300
570
 
301
- if (!allowCodePull) {
302
- continue;
571
+ const { buckets } = await paginate(
572
+ async () => new Storage(this.projectClient).listBuckets(),
573
+ {},
574
+ 100,
575
+ "buckets",
576
+ );
577
+
578
+ for (const bucket of buckets) {
579
+ this.log(`Pulling bucket ${chalk.bold(bucket.name)} ...`);
303
580
  }
304
581
 
305
- let deploymentId: string | null = null;
582
+ this.success(`Successfully pulled ${chalk.bold(buckets.length)} buckets.`);
306
583
 
307
- try {
308
- const fetchResponse = await sitesService.listDeployments({
309
- siteId: site["$id"],
310
- queries: [
311
- JSON.stringify({ method: "limit", values: [1] }),
312
- JSON.stringify({ method: "orderDesc", values: ["$id"] }),
313
- ],
314
- });
584
+ return buckets;
585
+ }
315
586
 
316
- if (fetchResponse["total"] > 0) {
317
- deploymentId = fetchResponse["deployments"][0]["$id"];
318
- }
319
- } catch {}
587
+ /**
588
+ * Pull teams from the project
589
+ */
590
+ public async pullTeams(): Promise<any[]> {
591
+ this.log("Fetching teams ...");
320
592
 
321
- if (deploymentId === null) {
322
- log(
323
- "Source code download skipped because site doesn't have any available deployment",
324
- );
325
- continue;
593
+ const teamsService = new Teams(this.projectClient);
594
+
595
+ const fetchResponse = await teamsService.list({
596
+ queries: [Query.limit(1)],
597
+ });
598
+
599
+ if (fetchResponse["teams"].length <= 0) {
600
+ this.log("No teams found.");
601
+ this.success(`Successfully pulled ${chalk.bold(0)} teams.`);
602
+ return [];
603
+ }
604
+
605
+ const { teams } = await paginate(
606
+ async () => new Teams(this.projectClient).list(),
607
+ {},
608
+ 100,
609
+ "teams",
610
+ );
611
+
612
+ for (const team of teams) {
613
+ this.log(`Pulling team ${chalk.bold(team.name)} ...`);
326
614
  }
327
615
 
328
- log("Pulling latest deployment code ...");
616
+ this.success(`Successfully pulled ${chalk.bold(teams.length)} teams.`);
329
617
 
330
- const compressedFileName = `${site["$id"]}-${+new Date()}.tar.gz`;
331
- const downloadUrl = sitesService.getDeploymentDownload({
332
- siteId: site["$id"],
333
- deploymentId: deploymentId,
618
+ return teams;
619
+ }
620
+
621
+ /**
622
+ * Pull messaging topics from the project
623
+ */
624
+ public async pullMessagingTopics(): Promise<any[]> {
625
+ this.log("Fetching topics ...");
626
+
627
+ const messagingService = new Messaging(this.projectClient);
628
+
629
+ const fetchResponse = await messagingService.listTopics({
630
+ queries: [Query.limit(1)],
334
631
  });
335
632
 
336
- const client = (await getSitesService()).client;
337
- const downloadBuffer = await client.call(
338
- "get",
339
- new URL(downloadUrl),
340
- {},
633
+ if (fetchResponse["topics"].length <= 0) {
634
+ this.log("No topics found.");
635
+ this.success(`Successfully pulled ${chalk.bold(0)} topics.`);
636
+ return [];
637
+ }
638
+
639
+ const { topics } = await paginate(
640
+ async () => new Messaging(this.projectClient).listTopics(),
341
641
  {},
342
- "arrayBuffer",
642
+ 100,
643
+ "topics",
343
644
  );
344
645
 
345
- fs.writeFileSync(compressedFileName, Buffer.from(downloadBuffer as any));
646
+ for (const topic of topics) {
647
+ this.log(`Pulling topic ${chalk.bold(topic.name)} ...`);
648
+ }
346
649
 
347
- tar.extract({
348
- sync: true,
349
- cwd: site["path"],
350
- file: compressedFileName,
351
- strict: false,
352
- });
650
+ this.success(`Successfully pulled ${chalk.bold(topics.length)} topics.`);
353
651
 
354
- fs.rmSync(compressedFileName);
652
+ return topics;
653
+ }
654
+ }
355
655
 
356
- if (withVariables) {
357
- const envFileLocation = `${site["path"]}/.env`;
358
- try {
359
- fs.rmSync(envFileLocation);
360
- } catch {}
656
+ /** Helper methods for CLI commands */
361
657
 
362
- fs.writeFileSync(
363
- envFileLocation,
364
- holdingVars.map((r: any) => `${r.key}=${r.value}\n`).join(""),
365
- );
658
+ export const pullResources = async ({
659
+ skipDeprecated = true,
660
+ }: {
661
+ skipDeprecated?: boolean;
662
+ } = {}): Promise<void> => {
663
+ const project = localConfig.getProject();
664
+ if (!project.projectId) {
665
+ error(
666
+ "Project configuration not found. Please run 'appwrite init project' to initialize your project first.",
667
+ );
668
+ process.exit(1);
669
+ }
670
+
671
+ const actions: Record<string, (options?: any) => Promise<void>> = {
672
+ settings: pullSettings,
673
+ functions: pullFunctions,
674
+ sites: pullSites,
675
+ collections: pullCollection,
676
+ tables: pullTable,
677
+ buckets: pullBucket,
678
+ teams: pullTeam,
679
+ messages: pullMessagingTopic,
680
+ };
681
+
682
+ if (skipDeprecated) {
683
+ delete actions.collections;
684
+ }
685
+
686
+ if (cliConfig.all) {
687
+ for (let action of Object.values(actions)) {
688
+ cliConfig.all = true;
689
+ await action({ returnOnZero: true });
690
+ }
691
+ } else {
692
+ const answers = await inquirer.prompt([questionsPullResources[0]]);
693
+
694
+ const action = actions[answers.resource];
695
+ if (action !== undefined) {
696
+ await action({ returnOnZero: true });
366
697
  }
367
698
  }
699
+ };
700
+
701
+ const pullSettings = async (): Promise<void> => {
702
+ const pullInstance = await createPullInstance();
703
+ const projectId = localConfig.getProject().projectId;
704
+ const settings = await pullInstance.pullSettings(projectId);
368
705
 
369
- success(`Successfully pulled ${chalk.bold(total)} sites.`);
706
+ localConfig.setProject(projectId, settings.projectName, settings.project);
370
707
  };
371
708
 
372
- const pullCollection = async (): Promise<void> => {
373
- warn(
374
- "appwrite pull collection has been deprecated. Please consider using 'appwrite pull tables' instead",
375
- );
376
- log("Fetching collections ...");
377
- let totalDatabases = 0;
378
- let totalCollections = 0;
379
-
380
- const databasesService = await getDatabasesService();
381
- const fetchResponse = await databasesService.list([
382
- JSON.stringify({ method: "limit", values: [1] }),
383
- ]);
384
- if (fetchResponse["databases"].length <= 0) {
385
- log("No collections found.");
386
- success(
387
- `Successfully pulled ${chalk.bold(totalCollections)} collections from ${chalk.bold(totalDatabases)} databases.`,
388
- );
709
+ const pullFunctions = async ({
710
+ code,
711
+ withVariables,
712
+ }: PullFunctionsOptions = {}): Promise<void> => {
713
+ const functionsService = await getFunctionsService();
714
+ const fetchResponse = await functionsService.list([Query.limit(1)]);
715
+ if (fetchResponse["functions"].length <= 0) {
716
+ log("No functions found.");
717
+ success(`Successfully pulled ${chalk.bold(0)} functions.`);
389
718
  return;
390
719
  }
391
720
 
392
- let databases: string[] = cliConfig.ids;
393
-
394
- if (databases.length === 0) {
395
- if (cliConfig.all) {
396
- databases = (
721
+ const functionsToCheck = cliConfig.all
722
+ ? (
397
723
  await paginate(
398
- async () => (await getDatabasesService()).list(),
724
+ async () => (await getFunctionsService()).list(),
399
725
  {},
400
726
  100,
401
- "databases",
727
+ "functions",
402
728
  )
403
- ).databases.map((database: any) => database.$id);
404
- } else {
405
- databases = (await inquirer.prompt(questionsPullCollection)).databases;
406
- }
407
- }
408
-
409
- for (const databaseId of databases) {
410
- const database = await databasesService.get(databaseId);
729
+ ).functions
730
+ : (await inquirer.prompt(questionsPullFunctions)).functions;
411
731
 
412
- totalDatabases++;
413
- log(
414
- `Pulling all collections from ${chalk.bold(database["name"])} database ...`,
415
- );
732
+ let allowCodePull: boolean | null = cliConfig.force === true ? true : null;
733
+ if (code !== false && allowCodePull === null) {
734
+ const codeAnswer = await inquirer.prompt(questionsPullFunctionsCode);
735
+ allowCodePull = codeAnswer.override;
736
+ }
416
737
 
417
- localConfig.addDatabase(database);
738
+ const shouldPullCode = code !== false && allowCodePull === true;
739
+ const selectedFunctionIds = functionsToCheck.map((f: any) => f.$id);
418
740
 
419
- const { collections } = await paginate(
420
- async () => (await getDatabasesService()).listCollections(databaseId),
421
- {},
422
- 100,
423
- "collections",
424
- );
741
+ const pullInstance = await createPullInstance();
742
+ const functions = await pullInstance.pullFunctions({
743
+ code: shouldPullCode,
744
+ withVariables,
745
+ functionIds: selectedFunctionIds,
746
+ });
425
747
 
426
- for (const collection of collections) {
427
- totalCollections++;
428
- localConfig.addCollection({
429
- ...collection,
430
- $createdAt: undefined,
431
- $updatedAt: undefined,
432
- });
433
- }
748
+ for (const func of functions) {
749
+ const localFunction = localConfig.getFunction(func.$id);
750
+ func["path"] = localFunction["path"] || func["path"];
751
+ localConfig.addFunction(func);
434
752
  }
435
-
436
- success(
437
- `Successfully pulled ${chalk.bold(totalCollections)} collections from ${chalk.bold(totalDatabases)} databases.`,
438
- );
439
753
  };
440
754
 
441
- const pullTable = async (): Promise<void> => {
442
- log("Fetching tables ...");
443
- let totalTablesDBs = 0;
444
- let totalTables = 0;
445
-
446
- const tablesDBService = await getTablesDBService();
447
- const fetchResponse = await tablesDBService.list([
448
- JSON.stringify({ method: "limit", values: [1] }),
449
- ]);
450
- if (fetchResponse["databases"].length <= 0) {
451
- log("No tables found.");
452
- success(
453
- `Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tableDBs.`,
454
- );
755
+ const pullSites = async ({
756
+ code,
757
+ withVariables,
758
+ }: PullSitesOptions = {}): Promise<void> => {
759
+ const sitesService = await getSitesService();
760
+ const fetchResponse = await sitesService.list({
761
+ queries: [Query.limit(1)],
762
+ });
763
+ if (fetchResponse["sites"].length <= 0) {
764
+ log("No sites found.");
765
+ success(`Successfully pulled ${chalk.bold(0)} sites.`);
455
766
  return;
456
767
  }
457
768
 
458
- let databases: string[] = cliConfig.ids;
459
-
460
- if (databases.length === 0) {
461
- if (cliConfig.all) {
462
- databases = (
769
+ const sitesToCheck = cliConfig.all
770
+ ? (
463
771
  await paginate(
464
- async () => (await getTablesDBService()).list(),
772
+ async () => (await getSitesService()).list(),
465
773
  {},
466
774
  100,
467
- "databases",
775
+ "sites",
468
776
  )
469
- ).databases.map((database: any) => database.$id);
470
- } else {
471
- databases = (await inquirer.prompt(questionsPullCollection)).databases;
472
- }
777
+ ).sites
778
+ : (await inquirer.prompt(questionsPullSites)).sites;
779
+
780
+ let allowCodePull: boolean | null = cliConfig.force === true ? true : null;
781
+ if (code !== false && allowCodePull === null) {
782
+ const codeAnswer = await inquirer.prompt(questionsPullSitesCode);
783
+ allowCodePull = codeAnswer.override;
473
784
  }
474
785
 
475
- for (const databaseId of databases) {
476
- const database = await tablesDBService.get(databaseId);
786
+ const shouldPullCode = code !== false && allowCodePull === true;
787
+ const selectedSiteIds = sitesToCheck.map((s: any) => s.$id);
477
788
 
478
- totalTablesDBs++;
479
- log(`Pulling all tables from ${chalk.bold(database["name"])} database ...`);
789
+ const pullInstance = await createPullInstance();
790
+ const sites = await pullInstance.pullSites({
791
+ code: shouldPullCode,
792
+ withVariables,
793
+ siteIds: selectedSiteIds,
794
+ });
480
795
 
481
- localConfig.addTablesDB(database);
796
+ for (const site of sites) {
797
+ const localSite = localConfig.getSite(site.$id);
798
+ site["path"] = localSite["path"] || site["path"];
799
+ localConfig.addSite(site);
800
+ }
801
+ };
482
802
 
483
- const { tables } = await paginate(
484
- async () => (await getTablesDBService()).listTables(databaseId),
485
- {},
486
- 100,
487
- "tables",
488
- );
803
+ const pullCollection = async (): Promise<void> => {
804
+ const pullInstance = await createPullInstance();
805
+ const { databases, collections } = await pullInstance.pullCollections();
489
806
 
490
- for (const table of tables) {
491
- totalTables++;
492
- localConfig.addTable({
493
- ...table,
494
- $createdAt: undefined,
495
- $updatedAt: undefined,
496
- });
497
- }
807
+ for (const database of databases) {
808
+ localConfig.addDatabase(database);
498
809
  }
499
810
 
500
- success(
501
- `Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tableDBs.`,
502
- );
811
+ for (const collection of collections) {
812
+ localConfig.addCollection(collection);
813
+ }
503
814
  };
504
815
 
505
- const pullBucket = async (): Promise<void> => {
506
- log("Fetching buckets ...");
507
- let total = 0;
508
-
509
- const storageService = await getStorageService();
510
- const fetchResponse = await storageService.listBuckets([
511
- JSON.stringify({ method: "limit", values: [1] }),
512
- ]);
513
- if (fetchResponse["buckets"].length <= 0) {
514
- log("No buckets found.");
515
- success(`Successfully pulled ${chalk.bold(total)} buckets.`);
516
- return;
816
+ const pullTable = async (): Promise<void> => {
817
+ const pullInstance = await createPullInstance();
818
+ const { databases, tables } = await pullInstance.pullTables();
819
+
820
+ for (const database of databases) {
821
+ localConfig.addTablesDB(database);
517
822
  }
518
823
 
519
- const { buckets } = await paginate(
520
- async () => (await getStorageService()).listBuckets(),
521
- {},
522
- 100,
523
- "buckets",
524
- );
824
+ for (const table of tables) {
825
+ localConfig.addTable(table);
826
+ }
827
+ };
828
+
829
+ const pullBucket = async (): Promise<void> => {
830
+ const pullInstance = await createPullInstance();
831
+ const buckets = await pullInstance.pullBuckets();
525
832
 
526
833
  for (const bucket of buckets) {
527
- total++;
528
- log(`Pulling bucket ${chalk.bold(bucket["name"])} ...`);
529
834
  localConfig.addBucket(bucket);
530
835
  }
531
-
532
- success(`Successfully pulled ${chalk.bold(total)} buckets.`);
533
836
  };
534
837
 
535
838
  const pullTeam = async (): Promise<void> => {
536
- log("Fetching teams ...");
537
- let total = 0;
538
-
539
- const teamsService = await getTeamsService();
540
- const fetchResponse = await teamsService.list([
541
- JSON.stringify({ method: "limit", values: [1] }),
542
- ]);
543
- if (fetchResponse["teams"].length <= 0) {
544
- log("No teams found.");
545
- success(`Successfully pulled ${chalk.bold(total)} teams.`);
546
- return;
547
- }
548
-
549
- const { teams } = await paginate(
550
- async () => (await getTeamsService()).list(),
551
- {},
552
- 100,
553
- "teams",
554
- );
839
+ const pullInstance = await createPullInstance();
840
+ const teams = await pullInstance.pullTeams();
555
841
 
556
842
  for (const team of teams) {
557
- total++;
558
- log(`Pulling team ${chalk.bold(team["name"])} ...`);
559
843
  localConfig.addTeam(team);
560
844
  }
561
-
562
- success(`Successfully pulled ${chalk.bold(total)} teams.`);
563
845
  };
564
846
 
565
847
  const pullMessagingTopic = async (): Promise<void> => {
566
- log("Fetching topics ...");
567
- let total = 0;
568
-
569
- const messagingService = await getMessagingService();
570
- const fetchResponse = await messagingService.listTopics([
571
- JSON.stringify({ method: "limit", values: [1] }),
572
- ]);
573
- if (fetchResponse["topics"].length <= 0) {
574
- log("No topics found.");
575
- success(`Successfully pulled ${chalk.bold(total)} topics.`);
576
- return;
577
- }
578
-
579
- const { topics } = await paginate(
580
- async () => (await getMessagingService()).listTopics(),
581
- {},
582
- 100,
583
- "topics",
584
- );
848
+ const pullInstance = await createPullInstance();
849
+ const topics = await pullInstance.pullMessagingTopics();
585
850
 
586
851
  for (const topic of topics) {
587
- total++;
588
- log(`Pulling topic ${chalk.bold(topic["name"])} ...`);
589
852
  localConfig.addMessagingTopic(topic);
590
853
  }
591
-
592
- success(`Successfully pulled ${chalk.bold(total)} topics.`);
593
854
  };
594
855
 
856
+ /** Commander.js exports */
857
+
595
858
  export const pull = new Command("pull")
596
859
  .description(commandDescriptions["pull"])
597
860
  .action(actionRunner(() => pullResources({ skipDeprecated: true })));
598
861
 
599
862
  pull
600
863
  .command("all")
601
- .description("Pull all resource.")
864
+ .description("Pull all resources")
602
865
  .action(
603
866
  actionRunner(() => {
604
867
  cliConfig.all = true;