appwrite-cli 12.0.1 → 13.0.0-rc.2

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 (801) hide show
  1. package/.github/workflows/build-verify.yml +71 -0
  2. package/.github/workflows/npm-publish.yml +41 -22
  3. package/CHANGELOG.md +108 -100
  4. package/LICENSE.md +1 -1
  5. package/README.md +58 -35
  6. package/bun.lock +625 -0
  7. package/dist/bundle.cjs +94853 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +145 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/lib/client.d.ts +88 -0
  13. package/dist/lib/client.d.ts.map +1 -0
  14. package/dist/lib/client.js +238 -0
  15. package/dist/lib/client.js.map +1 -0
  16. package/dist/lib/commands/generic.d.ts +17 -0
  17. package/dist/lib/commands/generic.d.ts.map +1 -0
  18. package/dist/lib/commands/generic.js +292 -0
  19. package/dist/lib/commands/generic.js.map +1 -0
  20. package/dist/lib/commands/init.d.ts +3 -0
  21. package/dist/lib/commands/init.d.ts.map +1 -0
  22. package/{lib → dist/lib}/commands/init.js +186 -270
  23. package/dist/lib/commands/init.js.map +1 -0
  24. package/dist/lib/commands/pull.d.ts +8 -0
  25. package/dist/lib/commands/pull.d.ts.map +1 -0
  26. package/{lib → dist/lib}/commands/pull.js +159 -280
  27. package/dist/lib/commands/pull.js.map +1 -0
  28. package/dist/lib/commands/push.d.ts +4 -0
  29. package/dist/lib/commands/push.d.ts.map +1 -0
  30. package/dist/lib/commands/push.js +2127 -0
  31. package/dist/lib/commands/push.js.map +1 -0
  32. package/dist/lib/commands/run.d.ts +3 -0
  33. package/dist/lib/commands/run.d.ts.map +1 -0
  34. package/{lib → dist/lib}/commands/run.js +146 -187
  35. package/dist/lib/commands/run.js.map +1 -0
  36. package/dist/lib/commands/services/account.d.ts +3 -0
  37. package/dist/lib/commands/services/account.d.ts.map +1 -0
  38. package/dist/lib/commands/services/account.js +306 -0
  39. package/dist/lib/commands/services/account.js.map +1 -0
  40. package/dist/lib/commands/services/avatars.d.ts +3 -0
  41. package/dist/lib/commands/services/avatars.d.ts.map +1 -0
  42. package/dist/lib/commands/services/avatars.js +118 -0
  43. package/dist/lib/commands/services/avatars.js.map +1 -0
  44. package/dist/lib/commands/services/console.d.ts +3 -0
  45. package/dist/lib/commands/services/console.d.ts.map +1 -0
  46. package/dist/lib/commands/services/console.js +41 -0
  47. package/dist/lib/commands/services/console.js.map +1 -0
  48. package/dist/lib/commands/services/databases.d.ts +3 -0
  49. package/dist/lib/commands/services/databases.d.ts.map +1 -0
  50. package/dist/lib/commands/services/databases.js +612 -0
  51. package/dist/lib/commands/services/databases.js.map +1 -0
  52. package/dist/lib/commands/services/functions.d.ts +3 -0
  53. package/dist/lib/commands/services/functions.d.ts.map +1 -0
  54. package/dist/lib/commands/services/functions.js +258 -0
  55. package/dist/lib/commands/services/functions.js.map +1 -0
  56. package/dist/lib/commands/services/graphql.d.ts +3 -0
  57. package/dist/lib/commands/services/graphql.d.ts.map +1 -0
  58. package/dist/lib/commands/services/graphql.js +28 -0
  59. package/dist/lib/commands/services/graphql.js.map +1 -0
  60. package/dist/lib/commands/services/health.d.ts +3 -0
  61. package/dist/lib/commands/services/health.d.ts.map +1 -0
  62. package/dist/lib/commands/services/health.js +123 -0
  63. package/dist/lib/commands/services/health.js.map +1 -0
  64. package/dist/lib/commands/services/locale.d.ts +3 -0
  65. package/dist/lib/commands/services/locale.d.ts.map +1 -0
  66. package/dist/lib/commands/services/locale.js +52 -0
  67. package/dist/lib/commands/services/locale.js.map +1 -0
  68. package/dist/lib/commands/services/messaging.d.ts +3 -0
  69. package/dist/lib/commands/services/messaging.d.ts.map +1 -0
  70. package/dist/lib/commands/services/messaging.js +505 -0
  71. package/dist/lib/commands/services/messaging.js.map +1 -0
  72. package/dist/lib/commands/services/migrations.d.ts +3 -0
  73. package/dist/lib/commands/services/migrations.d.ts.map +1 -0
  74. package/dist/lib/commands/services/migrations.js +135 -0
  75. package/dist/lib/commands/services/migrations.js.map +1 -0
  76. package/dist/lib/commands/services/project.d.ts +3 -0
  77. package/dist/lib/commands/services/project.d.ts.map +1 -0
  78. package/dist/lib/commands/services/project.js +54 -0
  79. package/dist/lib/commands/services/project.js.map +1 -0
  80. package/dist/lib/commands/services/projects.d.ts +3 -0
  81. package/dist/lib/commands/services/projects.d.ts.map +1 -0
  82. package/dist/lib/commands/services/projects.js +415 -0
  83. package/dist/lib/commands/services/projects.js.map +1 -0
  84. package/dist/lib/commands/services/proxy.d.ts +3 -0
  85. package/dist/lib/commands/services/proxy.d.ts.map +1 -0
  86. package/dist/lib/commands/services/proxy.js +68 -0
  87. package/dist/lib/commands/services/proxy.js.map +1 -0
  88. package/dist/lib/commands/services/sites.d.ts +3 -0
  89. package/dist/lib/commands/services/sites.d.ts.map +1 -0
  90. package/dist/lib/commands/services/sites.js +242 -0
  91. package/dist/lib/commands/services/sites.js.map +1 -0
  92. package/dist/lib/commands/services/storage.d.ts +3 -0
  93. package/dist/lib/commands/services/storage.d.ts.map +1 -0
  94. package/dist/lib/commands/services/storage.js +153 -0
  95. package/dist/lib/commands/services/storage.js.map +1 -0
  96. package/dist/lib/commands/services/tablesdb.d.ts +3 -0
  97. package/dist/lib/commands/services/tablesdb.d.ts.map +1 -0
  98. package/dist/lib/commands/services/tablesdb.js +605 -0
  99. package/dist/lib/commands/services/tablesdb.js.map +1 -0
  100. package/dist/lib/commands/services/teams.d.ts +3 -0
  101. package/dist/lib/commands/services/teams.d.ts.map +1 -0
  102. package/dist/lib/commands/services/teams.js +123 -0
  103. package/dist/lib/commands/services/teams.js.map +1 -0
  104. package/dist/lib/commands/services/tokens.d.ts +3 -0
  105. package/dist/lib/commands/services/tokens.d.ts.map +1 -0
  106. package/dist/lib/commands/services/tokens.js +49 -0
  107. package/dist/lib/commands/services/tokens.js.map +1 -0
  108. package/dist/lib/commands/services/users.d.ts +3 -0
  109. package/dist/lib/commands/services/users.d.ts.map +1 -0
  110. package/dist/lib/commands/services/users.js +312 -0
  111. package/dist/lib/commands/services/users.js.map +1 -0
  112. package/dist/lib/commands/services/vcs.d.ts +3 -0
  113. package/dist/lib/commands/services/vcs.d.ts.map +1 -0
  114. package/dist/lib/commands/services/vcs.js +87 -0
  115. package/dist/lib/commands/services/vcs.js.map +1 -0
  116. package/dist/lib/commands/types.d.ts +3 -0
  117. package/dist/lib/commands/types.d.ts.map +1 -0
  118. package/dist/lib/commands/types.js +151 -0
  119. package/dist/lib/commands/types.js.map +1 -0
  120. package/dist/lib/commands/update.d.ts +3 -0
  121. package/dist/lib/commands/update.d.ts.map +1 -0
  122. package/{lib → dist/lib}/commands/update.js +62 -79
  123. package/dist/lib/commands/update.js.map +1 -0
  124. package/dist/lib/config.d.ts +118 -0
  125. package/dist/lib/config.d.ts.map +1 -0
  126. package/{lib → dist/lib}/config.js +173 -232
  127. package/dist/lib/config.js.map +1 -0
  128. package/dist/lib/emulation/docker.d.ts +7 -0
  129. package/dist/lib/emulation/docker.d.ts.map +1 -0
  130. package/dist/lib/emulation/docker.js +224 -0
  131. package/dist/lib/emulation/docker.js.map +1 -0
  132. package/dist/lib/emulation/utils.d.ts +29 -0
  133. package/dist/lib/emulation/utils.d.ts.map +1 -0
  134. package/{lib → dist/lib}/emulation/utils.js +70 -91
  135. package/dist/lib/emulation/utils.js.map +1 -0
  136. package/dist/lib/id.d.ts +7 -0
  137. package/dist/lib/id.d.ts.map +1 -0
  138. package/{lib → dist/lib}/id.js +5 -8
  139. package/dist/lib/id.js.map +1 -0
  140. package/dist/lib/paginate.d.ts +9 -0
  141. package/dist/lib/paginate.d.ts.map +1 -0
  142. package/{lib → dist/lib}/paginate.js +10 -19
  143. package/dist/lib/paginate.js.map +1 -0
  144. package/dist/lib/parser.d.ts +18 -0
  145. package/dist/lib/parser.d.ts.map +1 -0
  146. package/dist/lib/parser.js +225 -0
  147. package/dist/lib/parser.js.map +1 -0
  148. package/dist/lib/questions.d.ts +59 -0
  149. package/dist/lib/questions.d.ts.map +1 -0
  150. package/{lib → dist/lib}/questions.js +393 -500
  151. package/dist/lib/questions.js.map +1 -0
  152. package/dist/lib/sdks.d.ts +4 -0
  153. package/dist/lib/sdks.d.ts.map +1 -0
  154. package/dist/lib/sdks.js +61 -0
  155. package/dist/lib/sdks.js.map +1 -0
  156. package/dist/lib/services.d.ts +13 -0
  157. package/dist/lib/services.d.ts.map +1 -0
  158. package/dist/lib/services.js +47 -0
  159. package/dist/lib/services.js.map +1 -0
  160. package/dist/lib/spinner.d.ts +28 -0
  161. package/dist/lib/spinner.d.ts.map +1 -0
  162. package/dist/lib/spinner.js +91 -0
  163. package/dist/lib/spinner.js.map +1 -0
  164. package/dist/lib/type-generation/attribute.d.ts +17 -0
  165. package/dist/lib/type-generation/attribute.d.ts.map +1 -0
  166. package/{lib → dist/lib}/type-generation/attribute.js +2 -5
  167. package/dist/lib/type-generation/attribute.js.map +1 -0
  168. package/dist/lib/type-generation/languages/csharp.d.ts +7 -0
  169. package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -0
  170. package/dist/lib/type-generation/languages/csharp.js +180 -0
  171. package/dist/lib/type-generation/languages/csharp.js.map +1 -0
  172. package/dist/lib/type-generation/languages/dart.d.ts +8 -0
  173. package/dist/lib/type-generation/languages/dart.d.ts.map +1 -0
  174. package/dist/lib/type-generation/languages/dart.js +197 -0
  175. package/dist/lib/type-generation/languages/dart.js.map +1 -0
  176. package/dist/lib/type-generation/languages/java.d.ts +7 -0
  177. package/dist/lib/type-generation/languages/java.d.ts.map +1 -0
  178. package/dist/lib/type-generation/languages/java.js +140 -0
  179. package/dist/lib/type-generation/languages/java.js.map +1 -0
  180. package/dist/lib/type-generation/languages/javascript.d.ts +9 -0
  181. package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -0
  182. package/dist/lib/type-generation/languages/javascript.js +109 -0
  183. package/dist/lib/type-generation/languages/javascript.js.map +1 -0
  184. package/dist/lib/type-generation/languages/kotlin.d.ts +7 -0
  185. package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -0
  186. package/dist/lib/type-generation/languages/kotlin.js +95 -0
  187. package/dist/lib/type-generation/languages/kotlin.js.map +1 -0
  188. package/dist/lib/type-generation/languages/language.d.ts +43 -0
  189. package/dist/lib/type-generation/languages/language.d.ts.map +1 -0
  190. package/dist/lib/type-generation/languages/language.js +77 -0
  191. package/dist/lib/type-generation/languages/language.js.map +1 -0
  192. package/dist/lib/type-generation/languages/php.d.ts +7 -0
  193. package/dist/lib/type-generation/languages/php.d.ts.map +1 -0
  194. package/dist/lib/type-generation/languages/php.js +116 -0
  195. package/dist/lib/type-generation/languages/php.js.map +1 -0
  196. package/dist/lib/type-generation/languages/swift.d.ts +7 -0
  197. package/dist/lib/type-generation/languages/swift.d.ts.map +1 -0
  198. package/dist/lib/type-generation/languages/swift.js +179 -0
  199. package/dist/lib/type-generation/languages/swift.js.map +1 -0
  200. package/dist/lib/type-generation/languages/typescript.d.ts +9 -0
  201. package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -0
  202. package/dist/lib/type-generation/languages/typescript.js +115 -0
  203. package/dist/lib/type-generation/languages/typescript.js.map +1 -0
  204. package/dist/lib/types.d.ts +277 -0
  205. package/dist/lib/types.d.ts.map +1 -0
  206. package/dist/lib/types.js +2 -0
  207. package/dist/lib/types.js.map +1 -0
  208. package/dist/lib/utils.d.ts +15 -0
  209. package/dist/lib/utils.d.ts.map +1 -0
  210. package/{lib → dist/lib}/utils.js +125 -167
  211. package/dist/lib/utils.js.map +1 -0
  212. package/dist/lib/validations.d.ts +2 -0
  213. package/dist/lib/validations.d.ts.map +1 -0
  214. package/dist/lib/validations.js +16 -0
  215. package/dist/lib/validations.js.map +1 -0
  216. package/dist/package.json +67 -0
  217. package/dist/scripts/generate-commands.d.ts +2 -0
  218. package/dist/scripts/generate-commands.d.ts.map +1 -0
  219. package/dist/scripts/generate-commands.js +398 -0
  220. package/dist/scripts/generate-commands.js.map +1 -0
  221. package/index.ts +168 -0
  222. package/install.ps1 +2 -5
  223. package/install.sh +1 -2
  224. package/lib/client.ts +292 -0
  225. package/lib/commands/generic.ts +440 -0
  226. package/lib/commands/init.ts +713 -0
  227. package/lib/commands/pull.ts +668 -0
  228. package/lib/commands/push.ts +3183 -0
  229. package/lib/commands/run.ts +416 -0
  230. package/lib/commands/services/account.ts +832 -0
  231. package/lib/commands/services/avatars.ts +400 -0
  232. package/lib/commands/services/console.ts +73 -0
  233. package/lib/commands/services/databases.ts +2080 -0
  234. package/lib/commands/services/functions.ts +855 -0
  235. package/lib/commands/services/graphql.ts +47 -0
  236. package/lib/commands/services/health.ts +322 -0
  237. package/lib/commands/services/locale.ts +99 -0
  238. package/lib/commands/services/messaging.ts +1871 -0
  239. package/lib/commands/services/migrations.ts +421 -0
  240. package/lib/commands/services/project.ts +116 -0
  241. package/lib/commands/services/projects.ts +1317 -0
  242. package/lib/commands/services/proxy.ts +163 -0
  243. package/lib/commands/services/sites.ts +777 -0
  244. package/lib/commands/services/storage.ts +547 -0
  245. package/lib/commands/services/tablesdb.ts +1928 -0
  246. package/lib/commands/services/teams.ts +294 -0
  247. package/lib/commands/services/tokens.ts +106 -0
  248. package/lib/commands/services/users.ts +886 -0
  249. package/lib/commands/services/vcs.ts +268 -0
  250. package/lib/commands/types.ts +220 -0
  251. package/lib/commands/update.ts +255 -0
  252. package/lib/config.ts +969 -0
  253. package/lib/emulation/docker.ts +312 -0
  254. package/lib/emulation/utils.ts +207 -0
  255. package/lib/id.ts +30 -0
  256. package/lib/paginate.ts +77 -0
  257. package/lib/parser.ts +264 -0
  258. package/lib/questions.ts +1167 -0
  259. package/lib/sdks.ts +84 -0
  260. package/lib/services.ts +72 -0
  261. package/lib/spinner.ts +131 -0
  262. package/lib/type-generation/attribute.ts +18 -0
  263. package/lib/type-generation/languages/{csharp.js → csharp.ts} +27 -14
  264. package/lib/type-generation/languages/{dart.js → dart.ts} +61 -46
  265. package/lib/type-generation/languages/{java.js → java.ts} +31 -18
  266. package/lib/type-generation/languages/{javascript.js → javascript.ts} +35 -24
  267. package/lib/type-generation/languages/{kotlin.js → kotlin.ts} +27 -14
  268. package/lib/type-generation/languages/{language.js → language.ts} +45 -43
  269. package/lib/type-generation/languages/{php.js → php.ts} +28 -15
  270. package/lib/type-generation/languages/{swift.js → swift.ts} +27 -14
  271. package/lib/type-generation/languages/{typescript.js → typescript.ts} +43 -26
  272. package/lib/types.ts +304 -0
  273. package/lib/utils.ts +352 -0
  274. package/lib/validations.ts +20 -0
  275. package/package.json +36 -19
  276. package/scoop/appwrite.config.json +19 -29
  277. package/scripts/generate-commands.ts +539 -0
  278. package/tsconfig.json +24 -0
  279. package/.github/workflows/autoclose.yml +0 -11
  280. package/docs/examples/account/create-anonymous-session.md +0 -1
  281. package/docs/examples/account/create-email-password-session.md +0 -3
  282. package/docs/examples/account/create-email-token.md +0 -3
  283. package/docs/examples/account/create-email-verification.md +0 -2
  284. package/docs/examples/account/create-jwt.md +0 -1
  285. package/docs/examples/account/create-magic-url-token.md +0 -3
  286. package/docs/examples/account/create-mfa-authenticator.md +0 -2
  287. package/docs/examples/account/create-mfa-challenge.md +0 -2
  288. package/docs/examples/account/create-mfa-recovery-codes.md +0 -1
  289. package/docs/examples/account/create-o-auth-2-session.md +0 -2
  290. package/docs/examples/account/create-o-auth-2-token.md +0 -2
  291. package/docs/examples/account/create-phone-token.md +0 -3
  292. package/docs/examples/account/create-phone-verification.md +0 -1
  293. package/docs/examples/account/create-push-target.md +0 -3
  294. package/docs/examples/account/create-recovery.md +0 -3
  295. package/docs/examples/account/create-session.md +0 -3
  296. package/docs/examples/account/create-verification.md +0 -2
  297. package/docs/examples/account/create.md +0 -4
  298. package/docs/examples/account/delete-identity.md +0 -2
  299. package/docs/examples/account/delete-mfa-authenticator.md +0 -2
  300. package/docs/examples/account/delete-push-target.md +0 -2
  301. package/docs/examples/account/delete-session.md +0 -2
  302. package/docs/examples/account/delete-sessions.md +0 -1
  303. package/docs/examples/account/delete.md +0 -1
  304. package/docs/examples/account/get-mfa-recovery-codes.md +0 -1
  305. package/docs/examples/account/get-prefs.md +0 -1
  306. package/docs/examples/account/get-session.md +0 -2
  307. package/docs/examples/account/get.md +0 -1
  308. package/docs/examples/account/list-identities.md +0 -1
  309. package/docs/examples/account/list-logs.md +0 -1
  310. package/docs/examples/account/list-mfa-factors.md +0 -1
  311. package/docs/examples/account/list-sessions.md +0 -1
  312. package/docs/examples/account/update-email-verification.md +0 -3
  313. package/docs/examples/account/update-email.md +0 -3
  314. package/docs/examples/account/update-magic-url-session.md +0 -3
  315. package/docs/examples/account/update-mfa-authenticator.md +0 -3
  316. package/docs/examples/account/update-mfa-challenge.md +0 -3
  317. package/docs/examples/account/update-mfa-recovery-codes.md +0 -1
  318. package/docs/examples/account/update-mfa.md +0 -2
  319. package/docs/examples/account/update-name.md +0 -2
  320. package/docs/examples/account/update-password.md +0 -2
  321. package/docs/examples/account/update-phone-session.md +0 -3
  322. package/docs/examples/account/update-phone-verification.md +0 -3
  323. package/docs/examples/account/update-phone.md +0 -3
  324. package/docs/examples/account/update-prefs.md +0 -2
  325. package/docs/examples/account/update-push-target.md +0 -3
  326. package/docs/examples/account/update-recovery.md +0 -4
  327. package/docs/examples/account/update-session.md +0 -2
  328. package/docs/examples/account/update-status.md +0 -1
  329. package/docs/examples/account/update-verification.md +0 -3
  330. package/docs/examples/console/get-resource.md +0 -3
  331. package/docs/examples/console/variables.md +0 -1
  332. package/docs/examples/databases/create-boolean-attribute.md +0 -5
  333. package/docs/examples/databases/create-collection.md +0 -4
  334. package/docs/examples/databases/create-datetime-attribute.md +0 -5
  335. package/docs/examples/databases/create-document.md +0 -5
  336. package/docs/examples/databases/create-documents.md +0 -4
  337. package/docs/examples/databases/create-email-attribute.md +0 -5
  338. package/docs/examples/databases/create-enum-attribute.md +0 -6
  339. package/docs/examples/databases/create-float-attribute.md +0 -5
  340. package/docs/examples/databases/create-index.md +0 -6
  341. package/docs/examples/databases/create-integer-attribute.md +0 -5
  342. package/docs/examples/databases/create-ip-attribute.md +0 -5
  343. package/docs/examples/databases/create-line-attribute.md +0 -5
  344. package/docs/examples/databases/create-operations.md +0 -2
  345. package/docs/examples/databases/create-point-attribute.md +0 -5
  346. package/docs/examples/databases/create-polygon-attribute.md +0 -5
  347. package/docs/examples/databases/create-relationship-attribute.md +0 -5
  348. package/docs/examples/databases/create-string-attribute.md +0 -6
  349. package/docs/examples/databases/create-transaction.md +0 -1
  350. package/docs/examples/databases/create-url-attribute.md +0 -5
  351. package/docs/examples/databases/create.md +0 -3
  352. package/docs/examples/databases/decrement-document-attribute.md +0 -5
  353. package/docs/examples/databases/delete-attribute.md +0 -4
  354. package/docs/examples/databases/delete-collection.md +0 -3
  355. package/docs/examples/databases/delete-document.md +0 -4
  356. package/docs/examples/databases/delete-documents.md +0 -3
  357. package/docs/examples/databases/delete-index.md +0 -4
  358. package/docs/examples/databases/delete-transaction.md +0 -2
  359. package/docs/examples/databases/delete.md +0 -2
  360. package/docs/examples/databases/get-attribute.md +0 -4
  361. package/docs/examples/databases/get-collection-usage.md +0 -3
  362. package/docs/examples/databases/get-collection.md +0 -3
  363. package/docs/examples/databases/get-document.md +0 -4
  364. package/docs/examples/databases/get-index.md +0 -4
  365. package/docs/examples/databases/get-transaction.md +0 -2
  366. package/docs/examples/databases/get-usage.md +0 -2
  367. package/docs/examples/databases/get.md +0 -2
  368. package/docs/examples/databases/increment-document-attribute.md +0 -5
  369. package/docs/examples/databases/list-attributes.md +0 -3
  370. package/docs/examples/databases/list-collection-logs.md +0 -3
  371. package/docs/examples/databases/list-collections.md +0 -2
  372. package/docs/examples/databases/list-document-logs.md +0 -4
  373. package/docs/examples/databases/list-documents.md +0 -3
  374. package/docs/examples/databases/list-indexes.md +0 -3
  375. package/docs/examples/databases/list-logs.md +0 -2
  376. package/docs/examples/databases/list-transactions.md +0 -1
  377. package/docs/examples/databases/list-usage.md +0 -1
  378. package/docs/examples/databases/list.md +0 -1
  379. package/docs/examples/databases/update-boolean-attribute.md +0 -6
  380. package/docs/examples/databases/update-collection.md +0 -4
  381. package/docs/examples/databases/update-datetime-attribute.md +0 -6
  382. package/docs/examples/databases/update-document.md +0 -4
  383. package/docs/examples/databases/update-documents.md +0 -3
  384. package/docs/examples/databases/update-email-attribute.md +0 -6
  385. package/docs/examples/databases/update-enum-attribute.md +0 -7
  386. package/docs/examples/databases/update-float-attribute.md +0 -6
  387. package/docs/examples/databases/update-integer-attribute.md +0 -6
  388. package/docs/examples/databases/update-ip-attribute.md +0 -6
  389. package/docs/examples/databases/update-line-attribute.md +0 -5
  390. package/docs/examples/databases/update-point-attribute.md +0 -5
  391. package/docs/examples/databases/update-polygon-attribute.md +0 -5
  392. package/docs/examples/databases/update-relationship-attribute.md +0 -4
  393. package/docs/examples/databases/update-string-attribute.md +0 -6
  394. package/docs/examples/databases/update-transaction.md +0 -2
  395. package/docs/examples/databases/update-url-attribute.md +0 -6
  396. package/docs/examples/databases/update.md +0 -3
  397. package/docs/examples/databases/upsert-document.md +0 -5
  398. package/docs/examples/databases/upsert-documents.md +0 -4
  399. package/docs/examples/functions/create-deployment.md +0 -4
  400. package/docs/examples/functions/create-duplicate-deployment.md +0 -3
  401. package/docs/examples/functions/create-execution.md +0 -2
  402. package/docs/examples/functions/create-template-deployment.md +0 -7
  403. package/docs/examples/functions/create-variable.md +0 -4
  404. package/docs/examples/functions/create-vcs-deployment.md +0 -4
  405. package/docs/examples/functions/create.md +0 -4
  406. package/docs/examples/functions/delete-deployment.md +0 -3
  407. package/docs/examples/functions/delete-execution.md +0 -3
  408. package/docs/examples/functions/delete-variable.md +0 -3
  409. package/docs/examples/functions/delete.md +0 -2
  410. package/docs/examples/functions/get-deployment-download.md +0 -3
  411. package/docs/examples/functions/get-deployment.md +0 -3
  412. package/docs/examples/functions/get-execution.md +0 -3
  413. package/docs/examples/functions/get-template.md +0 -2
  414. package/docs/examples/functions/get-usage.md +0 -2
  415. package/docs/examples/functions/get-variable.md +0 -3
  416. package/docs/examples/functions/get.md +0 -2
  417. package/docs/examples/functions/list-deployments.md +0 -2
  418. package/docs/examples/functions/list-executions.md +0 -2
  419. package/docs/examples/functions/list-runtimes.md +0 -1
  420. package/docs/examples/functions/list-specifications.md +0 -1
  421. package/docs/examples/functions/list-templates.md +0 -1
  422. package/docs/examples/functions/list-usage.md +0 -1
  423. package/docs/examples/functions/list-variables.md +0 -2
  424. package/docs/examples/functions/list.md +0 -1
  425. package/docs/examples/functions/update-deployment-status.md +0 -3
  426. package/docs/examples/functions/update-function-deployment.md +0 -3
  427. package/docs/examples/functions/update-variable.md +0 -4
  428. package/docs/examples/functions/update.md +0 -3
  429. package/docs/examples/graphql/mutation.md +0 -2
  430. package/docs/examples/graphql/query.md +0 -2
  431. package/docs/examples/health/get-antivirus.md +0 -1
  432. package/docs/examples/health/get-cache.md +0 -1
  433. package/docs/examples/health/get-certificate.md +0 -1
  434. package/docs/examples/health/get-db.md +0 -1
  435. package/docs/examples/health/get-failed-jobs.md +0 -2
  436. package/docs/examples/health/get-pub-sub.md +0 -1
  437. package/docs/examples/health/get-queue-builds.md +0 -1
  438. package/docs/examples/health/get-queue-certificates.md +0 -1
  439. package/docs/examples/health/get-queue-databases.md +0 -1
  440. package/docs/examples/health/get-queue-deletes.md +0 -1
  441. package/docs/examples/health/get-queue-functions.md +0 -1
  442. package/docs/examples/health/get-queue-logs.md +0 -1
  443. package/docs/examples/health/get-queue-mails.md +0 -1
  444. package/docs/examples/health/get-queue-messaging.md +0 -1
  445. package/docs/examples/health/get-queue-migrations.md +0 -1
  446. package/docs/examples/health/get-queue-stats-resources.md +0 -1
  447. package/docs/examples/health/get-queue-usage.md +0 -1
  448. package/docs/examples/health/get-queue-webhooks.md +0 -1
  449. package/docs/examples/health/get-storage-local.md +0 -1
  450. package/docs/examples/health/get-storage.md +0 -1
  451. package/docs/examples/health/get-time.md +0 -1
  452. package/docs/examples/health/get.md +0 -1
  453. package/docs/examples/locale/get.md +0 -1
  454. package/docs/examples/locale/list-codes.md +0 -1
  455. package/docs/examples/locale/list-continents.md +0 -1
  456. package/docs/examples/locale/list-countries-eu.md +0 -1
  457. package/docs/examples/locale/list-countries-phones.md +0 -1
  458. package/docs/examples/locale/list-countries.md +0 -1
  459. package/docs/examples/locale/list-currencies.md +0 -1
  460. package/docs/examples/locale/list-languages.md +0 -1
  461. package/docs/examples/messaging/create-apns-provider.md +0 -3
  462. package/docs/examples/messaging/create-email.md +0 -4
  463. package/docs/examples/messaging/create-fcm-provider.md +0 -3
  464. package/docs/examples/messaging/create-mailgun-provider.md +0 -3
  465. package/docs/examples/messaging/create-msg-91-provider.md +0 -3
  466. package/docs/examples/messaging/create-push.md +0 -2
  467. package/docs/examples/messaging/create-resend-provider.md +0 -3
  468. package/docs/examples/messaging/create-sendgrid-provider.md +0 -3
  469. package/docs/examples/messaging/create-sms.md +0 -3
  470. package/docs/examples/messaging/create-smtp-provider.md +0 -4
  471. package/docs/examples/messaging/create-subscriber.md +0 -4
  472. package/docs/examples/messaging/create-telesign-provider.md +0 -3
  473. package/docs/examples/messaging/create-textmagic-provider.md +0 -3
  474. package/docs/examples/messaging/create-topic.md +0 -3
  475. package/docs/examples/messaging/create-twilio-provider.md +0 -3
  476. package/docs/examples/messaging/create-vonage-provider.md +0 -3
  477. package/docs/examples/messaging/delete-provider.md +0 -2
  478. package/docs/examples/messaging/delete-subscriber.md +0 -3
  479. package/docs/examples/messaging/delete-topic.md +0 -2
  480. package/docs/examples/messaging/delete.md +0 -2
  481. package/docs/examples/messaging/get-message.md +0 -2
  482. package/docs/examples/messaging/get-provider.md +0 -2
  483. package/docs/examples/messaging/get-subscriber.md +0 -3
  484. package/docs/examples/messaging/get-topic.md +0 -2
  485. package/docs/examples/messaging/list-message-logs.md +0 -2
  486. package/docs/examples/messaging/list-messages.md +0 -1
  487. package/docs/examples/messaging/list-provider-logs.md +0 -2
  488. package/docs/examples/messaging/list-providers.md +0 -1
  489. package/docs/examples/messaging/list-subscriber-logs.md +0 -2
  490. package/docs/examples/messaging/list-subscribers.md +0 -2
  491. package/docs/examples/messaging/list-targets.md +0 -2
  492. package/docs/examples/messaging/list-topic-logs.md +0 -2
  493. package/docs/examples/messaging/list-topics.md +0 -1
  494. package/docs/examples/messaging/update-apns-provider.md +0 -2
  495. package/docs/examples/messaging/update-email.md +0 -2
  496. package/docs/examples/messaging/update-fcm-provider.md +0 -2
  497. package/docs/examples/messaging/update-mailgun-provider.md +0 -2
  498. package/docs/examples/messaging/update-msg-91-provider.md +0 -2
  499. package/docs/examples/messaging/update-push.md +0 -2
  500. package/docs/examples/messaging/update-resend-provider.md +0 -2
  501. package/docs/examples/messaging/update-sendgrid-provider.md +0 -2
  502. package/docs/examples/messaging/update-sms.md +0 -2
  503. package/docs/examples/messaging/update-smtp-provider.md +0 -2
  504. package/docs/examples/messaging/update-telesign-provider.md +0 -2
  505. package/docs/examples/messaging/update-textmagic-provider.md +0 -2
  506. package/docs/examples/messaging/update-topic.md +0 -2
  507. package/docs/examples/messaging/update-twilio-provider.md +0 -2
  508. package/docs/examples/messaging/update-vonage-provider.md +0 -2
  509. package/docs/examples/migrations/create-appwrite-migration.md +0 -5
  510. package/docs/examples/migrations/create-csv-export.md +0 -3
  511. package/docs/examples/migrations/create-csv-import.md +0 -4
  512. package/docs/examples/migrations/create-firebase-migration.md +0 -3
  513. package/docs/examples/migrations/create-n-host-migration.md +0 -8
  514. package/docs/examples/migrations/create-supabase-migration.md +0 -7
  515. package/docs/examples/migrations/delete.md +0 -2
  516. package/docs/examples/migrations/get-appwrite-report.md +0 -5
  517. package/docs/examples/migrations/get-firebase-report.md +0 -3
  518. package/docs/examples/migrations/get-n-host-report.md +0 -8
  519. package/docs/examples/migrations/get-supabase-report.md +0 -7
  520. package/docs/examples/migrations/get.md +0 -2
  521. package/docs/examples/migrations/list.md +0 -1
  522. package/docs/examples/migrations/retry.md +0 -2
  523. package/docs/examples/project/create-variable.md +0 -3
  524. package/docs/examples/project/delete-variable.md +0 -2
  525. package/docs/examples/project/get-usage.md +0 -3
  526. package/docs/examples/project/get-variable.md +0 -2
  527. package/docs/examples/project/list-variables.md +0 -1
  528. package/docs/examples/project/update-variable.md +0 -3
  529. package/docs/examples/projects/create-dev-key.md +0 -4
  530. package/docs/examples/projects/create-jwt.md +0 -3
  531. package/docs/examples/projects/create-key.md +0 -4
  532. package/docs/examples/projects/create-platform.md +0 -4
  533. package/docs/examples/projects/create-smtp-test.md +0 -6
  534. package/docs/examples/projects/create-webhook.md +0 -6
  535. package/docs/examples/projects/create.md +0 -4
  536. package/docs/examples/projects/delete-dev-key.md +0 -3
  537. package/docs/examples/projects/delete-email-template.md +0 -4
  538. package/docs/examples/projects/delete-key.md +0 -3
  539. package/docs/examples/projects/delete-platform.md +0 -3
  540. package/docs/examples/projects/delete-sms-template.md +0 -4
  541. package/docs/examples/projects/delete-webhook.md +0 -3
  542. package/docs/examples/projects/delete.md +0 -2
  543. package/docs/examples/projects/get-dev-key.md +0 -3
  544. package/docs/examples/projects/get-email-template.md +0 -4
  545. package/docs/examples/projects/get-key.md +0 -3
  546. package/docs/examples/projects/get-platform.md +0 -3
  547. package/docs/examples/projects/get-sms-template.md +0 -4
  548. package/docs/examples/projects/get-webhook.md +0 -3
  549. package/docs/examples/projects/get.md +0 -2
  550. package/docs/examples/projects/list-dev-keys.md +0 -2
  551. package/docs/examples/projects/list-keys.md +0 -2
  552. package/docs/examples/projects/list-platforms.md +0 -2
  553. package/docs/examples/projects/list-webhooks.md +0 -2
  554. package/docs/examples/projects/list.md +0 -1
  555. package/docs/examples/projects/update-api-status-all.md +0 -3
  556. package/docs/examples/projects/update-api-status.md +0 -4
  557. package/docs/examples/projects/update-auth-duration.md +0 -3
  558. package/docs/examples/projects/update-auth-limit.md +0 -3
  559. package/docs/examples/projects/update-auth-password-dictionary.md +0 -3
  560. package/docs/examples/projects/update-auth-password-history.md +0 -3
  561. package/docs/examples/projects/update-auth-sessions-limit.md +0 -3
  562. package/docs/examples/projects/update-auth-status.md +0 -4
  563. package/docs/examples/projects/update-dev-key.md +0 -5
  564. package/docs/examples/projects/update-email-template.md +0 -6
  565. package/docs/examples/projects/update-key.md +0 -5
  566. package/docs/examples/projects/update-memberships-privacy.md +0 -5
  567. package/docs/examples/projects/update-mock-numbers.md +0 -3
  568. package/docs/examples/projects/update-o-auth-2.md +0 -3
  569. package/docs/examples/projects/update-personal-data-check.md +0 -3
  570. package/docs/examples/projects/update-platform.md +0 -4
  571. package/docs/examples/projects/update-service-status-all.md +0 -3
  572. package/docs/examples/projects/update-service-status.md +0 -4
  573. package/docs/examples/projects/update-session-alerts.md +0 -3
  574. package/docs/examples/projects/update-session-invalidation.md +0 -3
  575. package/docs/examples/projects/update-sms-template.md +0 -5
  576. package/docs/examples/projects/update-smtp.md +0 -3
  577. package/docs/examples/projects/update-team.md +0 -3
  578. package/docs/examples/projects/update-webhook-signature.md +0 -3
  579. package/docs/examples/projects/update-webhook.md +0 -7
  580. package/docs/examples/projects/update.md +0 -3
  581. package/docs/examples/proxy/create-api-rule.md +0 -2
  582. package/docs/examples/proxy/create-function-rule.md +0 -3
  583. package/docs/examples/proxy/create-redirect-rule.md +0 -6
  584. package/docs/examples/proxy/create-site-rule.md +0 -3
  585. package/docs/examples/proxy/delete-rule.md +0 -2
  586. package/docs/examples/proxy/get-rule.md +0 -2
  587. package/docs/examples/proxy/list-rules.md +0 -1
  588. package/docs/examples/proxy/update-rule-verification.md +0 -2
  589. package/docs/examples/sites/create-deployment.md +0 -4
  590. package/docs/examples/sites/create-duplicate-deployment.md +0 -3
  591. package/docs/examples/sites/create-template-deployment.md +0 -7
  592. package/docs/examples/sites/create-variable.md +0 -4
  593. package/docs/examples/sites/create-vcs-deployment.md +0 -4
  594. package/docs/examples/sites/create.md +0 -5
  595. package/docs/examples/sites/delete-deployment.md +0 -3
  596. package/docs/examples/sites/delete-log.md +0 -3
  597. package/docs/examples/sites/delete-variable.md +0 -3
  598. package/docs/examples/sites/delete.md +0 -2
  599. package/docs/examples/sites/get-deployment-download.md +0 -3
  600. package/docs/examples/sites/get-deployment.md +0 -3
  601. package/docs/examples/sites/get-log.md +0 -3
  602. package/docs/examples/sites/get-template.md +0 -2
  603. package/docs/examples/sites/get-usage.md +0 -2
  604. package/docs/examples/sites/get-variable.md +0 -3
  605. package/docs/examples/sites/get.md +0 -2
  606. package/docs/examples/sites/list-deployments.md +0 -2
  607. package/docs/examples/sites/list-frameworks.md +0 -1
  608. package/docs/examples/sites/list-logs.md +0 -2
  609. package/docs/examples/sites/list-specifications.md +0 -1
  610. package/docs/examples/sites/list-templates.md +0 -1
  611. package/docs/examples/sites/list-usage.md +0 -1
  612. package/docs/examples/sites/list-variables.md +0 -2
  613. package/docs/examples/sites/list.md +0 -1
  614. package/docs/examples/sites/update-deployment-status.md +0 -3
  615. package/docs/examples/sites/update-site-deployment.md +0 -3
  616. package/docs/examples/sites/update-variable.md +0 -4
  617. package/docs/examples/sites/update.md +0 -4
  618. package/docs/examples/storage/create-bucket.md +0 -3
  619. package/docs/examples/storage/create-file.md +0 -4
  620. package/docs/examples/storage/delete-bucket.md +0 -2
  621. package/docs/examples/storage/delete-file.md +0 -3
  622. package/docs/examples/storage/get-bucket-usage.md +0 -2
  623. package/docs/examples/storage/get-bucket.md +0 -2
  624. package/docs/examples/storage/get-file-download.md +0 -3
  625. package/docs/examples/storage/get-file-preview.md +0 -3
  626. package/docs/examples/storage/get-file-view.md +0 -3
  627. package/docs/examples/storage/get-file.md +0 -3
  628. package/docs/examples/storage/get-usage.md +0 -1
  629. package/docs/examples/storage/list-buckets.md +0 -1
  630. package/docs/examples/storage/list-files.md +0 -2
  631. package/docs/examples/storage/update-bucket.md +0 -3
  632. package/docs/examples/storage/update-file.md +0 -3
  633. package/docs/examples/tablesdb/create-boolean-column.md +0 -5
  634. package/docs/examples/tablesdb/create-datetime-column.md +0 -5
  635. package/docs/examples/tablesdb/create-email-column.md +0 -5
  636. package/docs/examples/tablesdb/create-enum-column.md +0 -6
  637. package/docs/examples/tablesdb/create-float-column.md +0 -5
  638. package/docs/examples/tablesdb/create-index.md +0 -6
  639. package/docs/examples/tablesdb/create-integer-column.md +0 -5
  640. package/docs/examples/tablesdb/create-ip-column.md +0 -5
  641. package/docs/examples/tablesdb/create-line-column.md +0 -5
  642. package/docs/examples/tablesdb/create-operations.md +0 -2
  643. package/docs/examples/tablesdb/create-point-column.md +0 -5
  644. package/docs/examples/tablesdb/create-polygon-column.md +0 -5
  645. package/docs/examples/tablesdb/create-relationship-column.md +0 -5
  646. package/docs/examples/tablesdb/create-row.md +0 -5
  647. package/docs/examples/tablesdb/create-rows.md +0 -4
  648. package/docs/examples/tablesdb/create-string-column.md +0 -6
  649. package/docs/examples/tablesdb/create-table.md +0 -4
  650. package/docs/examples/tablesdb/create-transaction.md +0 -1
  651. package/docs/examples/tablesdb/create-url-column.md +0 -5
  652. package/docs/examples/tablesdb/create.md +0 -3
  653. package/docs/examples/tablesdb/decrement-row-column.md +0 -5
  654. package/docs/examples/tablesdb/delete-column.md +0 -4
  655. package/docs/examples/tablesdb/delete-index.md +0 -4
  656. package/docs/examples/tablesdb/delete-row.md +0 -4
  657. package/docs/examples/tablesdb/delete-rows.md +0 -3
  658. package/docs/examples/tablesdb/delete-table.md +0 -3
  659. package/docs/examples/tablesdb/delete-transaction.md +0 -2
  660. package/docs/examples/tablesdb/delete.md +0 -2
  661. package/docs/examples/tablesdb/get-column.md +0 -4
  662. package/docs/examples/tablesdb/get-index.md +0 -4
  663. package/docs/examples/tablesdb/get-row.md +0 -4
  664. package/docs/examples/tablesdb/get-table-usage.md +0 -3
  665. package/docs/examples/tablesdb/get-table.md +0 -3
  666. package/docs/examples/tablesdb/get-transaction.md +0 -2
  667. package/docs/examples/tablesdb/get-usage.md +0 -2
  668. package/docs/examples/tablesdb/get.md +0 -2
  669. package/docs/examples/tablesdb/increment-row-column.md +0 -5
  670. package/docs/examples/tablesdb/list-columns.md +0 -3
  671. package/docs/examples/tablesdb/list-indexes.md +0 -3
  672. package/docs/examples/tablesdb/list-row-logs.md +0 -4
  673. package/docs/examples/tablesdb/list-rows.md +0 -3
  674. package/docs/examples/tablesdb/list-table-logs.md +0 -3
  675. package/docs/examples/tablesdb/list-tables.md +0 -2
  676. package/docs/examples/tablesdb/list-transactions.md +0 -1
  677. package/docs/examples/tablesdb/list-usage.md +0 -1
  678. package/docs/examples/tablesdb/list.md +0 -1
  679. package/docs/examples/tablesdb/update-boolean-column.md +0 -6
  680. package/docs/examples/tablesdb/update-datetime-column.md +0 -6
  681. package/docs/examples/tablesdb/update-email-column.md +0 -6
  682. package/docs/examples/tablesdb/update-enum-column.md +0 -7
  683. package/docs/examples/tablesdb/update-float-column.md +0 -6
  684. package/docs/examples/tablesdb/update-integer-column.md +0 -6
  685. package/docs/examples/tablesdb/update-ip-column.md +0 -6
  686. package/docs/examples/tablesdb/update-line-column.md +0 -5
  687. package/docs/examples/tablesdb/update-point-column.md +0 -5
  688. package/docs/examples/tablesdb/update-polygon-column.md +0 -5
  689. package/docs/examples/tablesdb/update-relationship-column.md +0 -4
  690. package/docs/examples/tablesdb/update-row.md +0 -4
  691. package/docs/examples/tablesdb/update-rows.md +0 -3
  692. package/docs/examples/tablesdb/update-string-column.md +0 -6
  693. package/docs/examples/tablesdb/update-table.md +0 -4
  694. package/docs/examples/tablesdb/update-transaction.md +0 -2
  695. package/docs/examples/tablesdb/update-url-column.md +0 -6
  696. package/docs/examples/tablesdb/update.md +0 -3
  697. package/docs/examples/tablesdb/upsert-row.md +0 -4
  698. package/docs/examples/tablesdb/upsert-rows.md +0 -4
  699. package/docs/examples/teams/create-membership.md +0 -3
  700. package/docs/examples/teams/create.md +0 -3
  701. package/docs/examples/teams/delete-membership.md +0 -3
  702. package/docs/examples/teams/delete.md +0 -2
  703. package/docs/examples/teams/get-membership.md +0 -3
  704. package/docs/examples/teams/get-prefs.md +0 -2
  705. package/docs/examples/teams/get.md +0 -2
  706. package/docs/examples/teams/list-logs.md +0 -2
  707. package/docs/examples/teams/list-memberships.md +0 -2
  708. package/docs/examples/teams/list.md +0 -1
  709. package/docs/examples/teams/update-membership-status.md +0 -5
  710. package/docs/examples/teams/update-membership.md +0 -4
  711. package/docs/examples/teams/update-name.md +0 -3
  712. package/docs/examples/teams/update-prefs.md +0 -3
  713. package/docs/examples/tokens/create-file-token.md +0 -3
  714. package/docs/examples/tokens/delete.md +0 -2
  715. package/docs/examples/tokens/get.md +0 -2
  716. package/docs/examples/tokens/list.md +0 -3
  717. package/docs/examples/tokens/update.md +0 -2
  718. package/docs/examples/users/create-argon-2-user.md +0 -4
  719. package/docs/examples/users/create-bcrypt-user.md +0 -4
  720. package/docs/examples/users/create-jwt.md +0 -2
  721. package/docs/examples/users/create-md-5-user.md +0 -4
  722. package/docs/examples/users/create-mfa-recovery-codes.md +0 -2
  723. package/docs/examples/users/create-ph-pass-user.md +0 -4
  724. package/docs/examples/users/create-scrypt-modified-user.md +0 -7
  725. package/docs/examples/users/create-scrypt-user.md +0 -9
  726. package/docs/examples/users/create-session.md +0 -2
  727. package/docs/examples/users/create-sha-user.md +0 -4
  728. package/docs/examples/users/create-target.md +0 -5
  729. package/docs/examples/users/create-token.md +0 -2
  730. package/docs/examples/users/create.md +0 -2
  731. package/docs/examples/users/delete-identity.md +0 -2
  732. package/docs/examples/users/delete-mfa-authenticator.md +0 -3
  733. package/docs/examples/users/delete-session.md +0 -3
  734. package/docs/examples/users/delete-sessions.md +0 -2
  735. package/docs/examples/users/delete-target.md +0 -3
  736. package/docs/examples/users/delete.md +0 -2
  737. package/docs/examples/users/get-mfa-recovery-codes.md +0 -2
  738. package/docs/examples/users/get-prefs.md +0 -2
  739. package/docs/examples/users/get-target.md +0 -3
  740. package/docs/examples/users/get-usage.md +0 -1
  741. package/docs/examples/users/get.md +0 -2
  742. package/docs/examples/users/list-identities.md +0 -1
  743. package/docs/examples/users/list-logs.md +0 -2
  744. package/docs/examples/users/list-memberships.md +0 -2
  745. package/docs/examples/users/list-mfa-factors.md +0 -2
  746. package/docs/examples/users/list-sessions.md +0 -2
  747. package/docs/examples/users/list-targets.md +0 -2
  748. package/docs/examples/users/list.md +0 -1
  749. package/docs/examples/users/update-email-verification.md +0 -3
  750. package/docs/examples/users/update-email.md +0 -3
  751. package/docs/examples/users/update-labels.md +0 -3
  752. package/docs/examples/users/update-mfa-recovery-codes.md +0 -2
  753. package/docs/examples/users/update-mfa.md +0 -3
  754. package/docs/examples/users/update-name.md +0 -3
  755. package/docs/examples/users/update-password.md +0 -3
  756. package/docs/examples/users/update-phone-verification.md +0 -3
  757. package/docs/examples/users/update-phone.md +0 -3
  758. package/docs/examples/users/update-prefs.md +0 -3
  759. package/docs/examples/users/update-status.md +0 -3
  760. package/docs/examples/users/update-target.md +0 -3
  761. package/docs/examples/vcs/create-repository-detection.md +0 -4
  762. package/docs/examples/vcs/create-repository.md +0 -4
  763. package/docs/examples/vcs/delete-installation.md +0 -2
  764. package/docs/examples/vcs/get-installation.md +0 -2
  765. package/docs/examples/vcs/get-repository-contents.md +0 -3
  766. package/docs/examples/vcs/get-repository.md +0 -3
  767. package/docs/examples/vcs/list-installations.md +0 -1
  768. package/docs/examples/vcs/list-repositories.md +0 -3
  769. package/docs/examples/vcs/list-repository-branches.md +0 -3
  770. package/docs/examples/vcs/update-external-deployments.md +0 -4
  771. package/index.js +0 -147
  772. package/lib/client.js +0 -254
  773. package/lib/commands/account.js +0 -2121
  774. package/lib/commands/console.js +0 -127
  775. package/lib/commands/databases.js +0 -3590
  776. package/lib/commands/functions.js +0 -1732
  777. package/lib/commands/generic.js +0 -330
  778. package/lib/commands/graphql.js +0 -126
  779. package/lib/commands/health.js +0 -869
  780. package/lib/commands/locale.js +0 -316
  781. package/lib/commands/messaging.js +0 -3116
  782. package/lib/commands/migrations.js +0 -830
  783. package/lib/commands/organizations.js +0 -48
  784. package/lib/commands/project.js +0 -302
  785. package/lib/commands/projects.js +0 -2626
  786. package/lib/commands/proxy.js +0 -403
  787. package/lib/commands/push.js +0 -2570
  788. package/lib/commands/sites.js +0 -1654
  789. package/lib/commands/storage.js +0 -995
  790. package/lib/commands/tables-db.js +0 -3569
  791. package/lib/commands/teams.js +0 -683
  792. package/lib/commands/tokens.js +0 -261
  793. package/lib/commands/types.js +0 -191
  794. package/lib/commands/users.js +0 -2022
  795. package/lib/commands/vcs.js +0 -484
  796. package/lib/emulation/docker.js +0 -264
  797. package/lib/exception.js +0 -9
  798. package/lib/parser.js +0 -250
  799. package/lib/sdks.js +0 -60
  800. package/lib/spinner.js +0 -104
  801. package/lib/validations.js +0 -17
@@ -0,0 +1,2127 @@
1
+ import fs from "fs";
2
+ import { parse as parseDotenv } from "dotenv";
3
+ import chalk from "chalk";
4
+ import inquirer from "inquirer";
5
+ import { Command } from "commander";
6
+ import ID from "../id.js";
7
+ import { localConfig, globalConfig, KeysAttributes, KeysFunction, KeysSite, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection, KeysTable, } from "../config.js";
8
+ import { Spinner, SPINNER_ARC, SPINNER_DOTS } from "../spinner.js";
9
+ import { paginate } from "../paginate.js";
10
+ import { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsPushSites, questionsGetEntrypoint, questionsPushCollections, questionsPushTables, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources, } from "../questions.js";
11
+ import { cliConfig, actionRunner, success, warn, log, hint, error, commandDescriptions, drawTable, } from "../parser.js";
12
+ import { getProxyService, getConsoleService, getFunctionsService, getSitesService, getDatabasesService, getTablesDBService, getStorageService, getMessagingService, getTeamsService, getProjectsService, } from "../services.js";
13
+ import { checkDeployConditions } from "../utils.js";
14
+ const STEP_SIZE = 100; // Resources
15
+ const POLL_DEBOUNCE = 2000; // Milliseconds
16
+ const POLL_DEFAULT_VALUE = 30;
17
+ let pollMaxDebounces = POLL_DEFAULT_VALUE;
18
+ const changeableKeys = [
19
+ "status",
20
+ "required",
21
+ "xdefault",
22
+ "elements",
23
+ "min",
24
+ "max",
25
+ "default",
26
+ "error",
27
+ ];
28
+ const awaitPools = {
29
+ wipeAttributes: async (databaseId, collectionId, iteration = 1) => {
30
+ if (iteration > pollMaxDebounces) {
31
+ return false;
32
+ }
33
+ const databasesService = await getDatabasesService();
34
+ const response = await databasesService.listAttributes(databaseId, collectionId, [JSON.stringify({ method: "limit", values: [1] })]);
35
+ const { total } = response;
36
+ if (total === 0) {
37
+ return true;
38
+ }
39
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
40
+ let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
41
+ if (steps > 1 && iteration === 1) {
42
+ pollMaxDebounces *= steps;
43
+ log("Found a large number of attributes, increasing timeout to " +
44
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
45
+ " minutes");
46
+ }
47
+ }
48
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
49
+ return await awaitPools.wipeAttributes(databaseId, collectionId, iteration + 1);
50
+ },
51
+ wipeIndexes: async (databaseId, collectionId, iteration = 1) => {
52
+ if (iteration > pollMaxDebounces) {
53
+ return false;
54
+ }
55
+ const databasesService = await getDatabasesService();
56
+ const response = await databasesService.listIndexes(databaseId, collectionId, [JSON.stringify({ method: "limit", values: [1] })]);
57
+ const { total } = response;
58
+ if (total === 0) {
59
+ return true;
60
+ }
61
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
62
+ let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
63
+ if (steps > 1 && iteration === 1) {
64
+ pollMaxDebounces *= steps;
65
+ log("Found a large number of indexes, increasing timeout to " +
66
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
67
+ " minutes");
68
+ }
69
+ }
70
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
71
+ return await awaitPools.wipeIndexes(databaseId, collectionId, iteration + 1);
72
+ },
73
+ deleteAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
74
+ if (iteration > pollMaxDebounces) {
75
+ return false;
76
+ }
77
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
78
+ let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
79
+ if (steps > 1 && iteration === 1) {
80
+ pollMaxDebounces *= steps;
81
+ log("Found a large number of attributes to be deleted. Increasing timeout to " +
82
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
83
+ " minutes");
84
+ }
85
+ }
86
+ const { attributes } = await paginate(async (args) => {
87
+ const databasesService = await getDatabasesService();
88
+ return await databasesService.listAttributes(args.databaseId, args.collectionId, args.queries || []);
89
+ }, {
90
+ databaseId,
91
+ collectionId,
92
+ }, 100, "attributes");
93
+ const ready = attributeKeys.filter((attribute) => attributes.includes(attribute.key));
94
+ if (ready.length === 0) {
95
+ return true;
96
+ }
97
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
98
+ return await awaitPools.expectAttributes(databaseId, collectionId, attributeKeys, iteration + 1);
99
+ },
100
+ expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
101
+ if (iteration > pollMaxDebounces) {
102
+ return false;
103
+ }
104
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
105
+ let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
106
+ if (steps > 1 && iteration === 1) {
107
+ pollMaxDebounces *= steps;
108
+ log("Creating a large number of attributes, increasing timeout to " +
109
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
110
+ " minutes");
111
+ }
112
+ }
113
+ const { attributes } = await paginate(async (args) => {
114
+ const databasesService = await getDatabasesService();
115
+ return await databasesService.listAttributes(args.databaseId, args.collectionId, args.queries || []);
116
+ }, {
117
+ databaseId,
118
+ collectionId,
119
+ }, 100, "attributes");
120
+ const ready = attributes
121
+ .filter((attribute) => {
122
+ if (attributeKeys.includes(attribute.key)) {
123
+ if (["stuck", "failed"].includes(attribute.status)) {
124
+ throw new Error(`Attribute '${attribute.key}' failed!`);
125
+ }
126
+ return attribute.status === "available";
127
+ }
128
+ return false;
129
+ })
130
+ .map((attribute) => attribute.key);
131
+ if (ready.length === attributeKeys.length) {
132
+ return true;
133
+ }
134
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
135
+ return await awaitPools.expectAttributes(databaseId, collectionId, attributeKeys, iteration + 1);
136
+ },
137
+ deleteIndexes: async (databaseId, collectionId, indexesKeys, iteration = 1) => {
138
+ if (iteration > pollMaxDebounces) {
139
+ return false;
140
+ }
141
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
142
+ let steps = Math.max(1, Math.ceil(indexesKeys.length / STEP_SIZE));
143
+ if (steps > 1 && iteration === 1) {
144
+ pollMaxDebounces *= steps;
145
+ log("Found a large number of indexes to be deleted. Increasing timeout to " +
146
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
147
+ " minutes");
148
+ }
149
+ }
150
+ const { indexes } = await paginate(async (args) => {
151
+ const databasesService = await getDatabasesService();
152
+ return await databasesService.listIndexes(args.databaseId, args.collectionId, args.queries || []);
153
+ }, {
154
+ databaseId,
155
+ collectionId,
156
+ }, 100, "indexes");
157
+ const ready = indexesKeys.filter((index) => indexes.includes(index.key));
158
+ if (ready.length === 0) {
159
+ return true;
160
+ }
161
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
162
+ return await awaitPools.expectIndexes(databaseId, collectionId, indexesKeys, iteration + 1);
163
+ },
164
+ expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => {
165
+ if (iteration > pollMaxDebounces) {
166
+ return false;
167
+ }
168
+ if (pollMaxDebounces === POLL_DEFAULT_VALUE) {
169
+ let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
170
+ if (steps > 1 && iteration === 1) {
171
+ pollMaxDebounces *= steps;
172
+ log("Creating a large number of indexes, increasing timeout to " +
173
+ (pollMaxDebounces * POLL_DEBOUNCE) / 1000 / 60 +
174
+ " minutes");
175
+ }
176
+ }
177
+ const { indexes } = await paginate(async (args) => {
178
+ const databasesService = await getDatabasesService();
179
+ return await databasesService.listIndexes(args.databaseId, args.collectionId, args.queries || []);
180
+ }, {
181
+ databaseId,
182
+ collectionId,
183
+ }, 100, "indexes");
184
+ const ready = indexes
185
+ .filter((index) => {
186
+ if (indexKeys.includes(index.key)) {
187
+ if (["stuck", "failed"].includes(index.status)) {
188
+ throw new Error(`Index '${index.key}' failed!`);
189
+ }
190
+ return index.status === "available";
191
+ }
192
+ return false;
193
+ })
194
+ .map((index) => index.key);
195
+ if (ready.length >= indexKeys.length) {
196
+ return true;
197
+ }
198
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE));
199
+ return await awaitPools.expectIndexes(databaseId, collectionId, indexKeys, iteration + 1);
200
+ },
201
+ };
202
+ const getConfirmation = async () => {
203
+ if (cliConfig.force) {
204
+ return true;
205
+ }
206
+ async function fixConfirmation() {
207
+ const answers = await inquirer.prompt(questionPushChangesConfirmation);
208
+ if (answers.changes !== "YES" && answers.changes !== "NO") {
209
+ return await fixConfirmation();
210
+ }
211
+ return answers.changes;
212
+ }
213
+ let answers = await inquirer.prompt(questionPushChanges);
214
+ if (answers.changes !== "YES" && answers.changes !== "NO") {
215
+ answers.changes = await fixConfirmation();
216
+ }
217
+ if (answers.changes === "YES") {
218
+ return true;
219
+ }
220
+ warn("Skipping push action. Changes were not applied.");
221
+ return false;
222
+ };
223
+ const isEmpty = (value) => value === null ||
224
+ value === undefined ||
225
+ (typeof value === "string" && value.trim().length === 0) ||
226
+ (Array.isArray(value) && value.length === 0);
227
+ const approveChanges = async (resource, resourceGetFunction, keys, resourceName, resourcePlural, skipKeys = [], secondId = "", secondResourceName = "") => {
228
+ log("Checking for changes ...");
229
+ const changes = [];
230
+ await Promise.all(resource.map(async (localResource) => {
231
+ try {
232
+ const options = {
233
+ [resourceName]: localResource["$id"],
234
+ };
235
+ if (secondId !== "" && secondResourceName !== "") {
236
+ options[secondResourceName] = localResource[secondId];
237
+ }
238
+ const remoteResource = await resourceGetFunction(options);
239
+ for (let [key, value] of Object.entries(whitelistKeys(remoteResource, keys))) {
240
+ if (skipKeys.includes(key)) {
241
+ continue;
242
+ }
243
+ if (isEmpty(value) && isEmpty(localResource[key])) {
244
+ continue;
245
+ }
246
+ if (Array.isArray(value) && Array.isArray(localResource[key])) {
247
+ if (JSON.stringify(value) !== JSON.stringify(localResource[key])) {
248
+ changes.push({
249
+ id: localResource["$id"],
250
+ key,
251
+ remote: chalk.red(value.join("\n")),
252
+ local: chalk.green(localResource[key].join("\n")),
253
+ });
254
+ }
255
+ }
256
+ else if (value !== localResource[key]) {
257
+ changes.push({
258
+ id: localResource["$id"],
259
+ key,
260
+ remote: chalk.red(value),
261
+ local: chalk.green(localResource[key]),
262
+ });
263
+ }
264
+ }
265
+ }
266
+ catch (e) {
267
+ if (Number(e.code) !== 404) {
268
+ throw e;
269
+ }
270
+ }
271
+ }));
272
+ if (changes.length === 0) {
273
+ return true;
274
+ }
275
+ drawTable(changes);
276
+ if ((await getConfirmation()) === true) {
277
+ return true;
278
+ }
279
+ success(`Successfully pushed 0 ${resourcePlural}.`);
280
+ return false;
281
+ };
282
+ const getObjectChanges = (remote, local, index, what) => {
283
+ const changes = [];
284
+ const remoteNested = remote[index];
285
+ const localNested = local[index];
286
+ if (remoteNested &&
287
+ localNested &&
288
+ typeof remoteNested === "object" &&
289
+ !Array.isArray(remoteNested) &&
290
+ typeof localNested === "object" &&
291
+ !Array.isArray(localNested)) {
292
+ const remoteObj = remoteNested;
293
+ const localObj = localNested;
294
+ for (const [service, status] of Object.entries(remoteObj)) {
295
+ const localValue = localObj[service];
296
+ let valuesEqual = false;
297
+ if (Array.isArray(status) && Array.isArray(localValue)) {
298
+ valuesEqual = JSON.stringify(status) === JSON.stringify(localValue);
299
+ }
300
+ else {
301
+ valuesEqual = status === localValue;
302
+ }
303
+ if (!valuesEqual) {
304
+ changes.push({
305
+ group: what,
306
+ setting: service,
307
+ remote: chalk.red(String(status ?? "")),
308
+ local: chalk.green(String(localValue ?? "")),
309
+ });
310
+ }
311
+ }
312
+ }
313
+ return changes;
314
+ };
315
+ const createAttribute = async (databaseId, collectionId, attribute) => {
316
+ const databasesService = await getDatabasesService();
317
+ switch (attribute.type) {
318
+ case "string":
319
+ switch (attribute.format) {
320
+ case "email":
321
+ return databasesService.createEmailAttribute({
322
+ databaseId,
323
+ collectionId,
324
+ key: attribute.key,
325
+ required: attribute.required,
326
+ xdefault: attribute.default,
327
+ array: attribute.array,
328
+ });
329
+ case "url":
330
+ return databasesService.createUrlAttribute({
331
+ databaseId,
332
+ collectionId,
333
+ key: attribute.key,
334
+ required: attribute.required,
335
+ xdefault: attribute.default,
336
+ array: attribute.array,
337
+ });
338
+ case "ip":
339
+ return databasesService.createIpAttribute({
340
+ databaseId,
341
+ collectionId,
342
+ key: attribute.key,
343
+ required: attribute.required,
344
+ xdefault: attribute.default,
345
+ array: attribute.array,
346
+ });
347
+ case "enum":
348
+ return databasesService.createEnumAttribute({
349
+ databaseId,
350
+ collectionId,
351
+ key: attribute.key,
352
+ elements: attribute.elements,
353
+ required: attribute.required,
354
+ xdefault: attribute.default,
355
+ array: attribute.array,
356
+ });
357
+ default:
358
+ return databasesService.createStringAttribute({
359
+ databaseId,
360
+ collectionId,
361
+ key: attribute.key,
362
+ size: attribute.size,
363
+ required: attribute.required,
364
+ xdefault: attribute.default,
365
+ array: attribute.array,
366
+ encrypt: attribute.encrypt,
367
+ });
368
+ }
369
+ case "integer":
370
+ return databasesService.createIntegerAttribute({
371
+ databaseId,
372
+ collectionId,
373
+ key: attribute.key,
374
+ required: attribute.required,
375
+ min: attribute.min,
376
+ max: attribute.max,
377
+ xdefault: attribute.default,
378
+ array: attribute.array,
379
+ });
380
+ case "double":
381
+ return databasesService.createFloatAttribute({
382
+ databaseId,
383
+ collectionId,
384
+ key: attribute.key,
385
+ required: attribute.required,
386
+ min: attribute.min,
387
+ max: attribute.max,
388
+ xdefault: attribute.default,
389
+ array: attribute.array,
390
+ });
391
+ case "boolean":
392
+ return databasesService.createBooleanAttribute({
393
+ databaseId,
394
+ collectionId,
395
+ key: attribute.key,
396
+ required: attribute.required,
397
+ xdefault: attribute.default,
398
+ array: attribute.array,
399
+ });
400
+ case "datetime":
401
+ return databasesService.createDatetimeAttribute({
402
+ databaseId,
403
+ collectionId,
404
+ key: attribute.key,
405
+ required: attribute.required,
406
+ xdefault: attribute.default,
407
+ array: attribute.array,
408
+ });
409
+ case "relationship":
410
+ return databasesService.createRelationshipAttribute({
411
+ databaseId,
412
+ collectionId,
413
+ relatedCollectionId: attribute.relatedTable ?? attribute.relatedCollection,
414
+ type: attribute.relationType,
415
+ twoWay: attribute.twoWay,
416
+ key: attribute.key,
417
+ twoWayKey: attribute.twoWayKey,
418
+ onDelete: attribute.onDelete,
419
+ });
420
+ case "point":
421
+ return databasesService.createPointAttribute({
422
+ databaseId,
423
+ collectionId,
424
+ key: attribute.key,
425
+ required: attribute.required,
426
+ xdefault: attribute.default,
427
+ });
428
+ case "linestring":
429
+ return databasesService.createLineAttribute({
430
+ databaseId,
431
+ collectionId,
432
+ key: attribute.key,
433
+ required: attribute.required,
434
+ xdefault: attribute.default,
435
+ });
436
+ case "polygon":
437
+ return databasesService.createPolygonAttribute({
438
+ databaseId,
439
+ collectionId,
440
+ key: attribute.key,
441
+ required: attribute.required,
442
+ xdefault: attribute.default,
443
+ });
444
+ default:
445
+ throw new Error(`Unsupported attribute type: ${attribute.type}`);
446
+ }
447
+ };
448
+ const updateAttribute = async (databaseId, collectionId, attribute) => {
449
+ const databasesService = await getDatabasesService();
450
+ switch (attribute.type) {
451
+ case "string":
452
+ switch (attribute.format) {
453
+ case "email":
454
+ return databasesService.updateEmailAttribute({
455
+ databaseId,
456
+ collectionId,
457
+ key: attribute.key,
458
+ required: attribute.required,
459
+ xdefault: attribute.default,
460
+ });
461
+ case "url":
462
+ return databasesService.updateUrlAttribute({
463
+ databaseId,
464
+ collectionId,
465
+ key: attribute.key,
466
+ required: attribute.required,
467
+ xdefault: attribute.default,
468
+ });
469
+ case "ip":
470
+ return databasesService.updateIpAttribute({
471
+ databaseId,
472
+ collectionId,
473
+ key: attribute.key,
474
+ required: attribute.required,
475
+ xdefault: attribute.default,
476
+ });
477
+ case "enum":
478
+ return databasesService.updateEnumAttribute({
479
+ databaseId,
480
+ collectionId,
481
+ key: attribute.key,
482
+ elements: attribute.elements,
483
+ required: attribute.required,
484
+ xdefault: attribute.default,
485
+ });
486
+ default:
487
+ return databasesService.updateStringAttribute({
488
+ databaseId,
489
+ collectionId,
490
+ key: attribute.key,
491
+ required: attribute.required,
492
+ xdefault: attribute.default,
493
+ });
494
+ }
495
+ case "integer":
496
+ return databasesService.updateIntegerAttribute({
497
+ databaseId,
498
+ collectionId,
499
+ key: attribute.key,
500
+ required: attribute.required,
501
+ min: attribute.min,
502
+ max: attribute.max,
503
+ xdefault: attribute.default,
504
+ });
505
+ case "double":
506
+ return databasesService.updateFloatAttribute({
507
+ databaseId,
508
+ collectionId,
509
+ key: attribute.key,
510
+ required: attribute.required,
511
+ min: attribute.min,
512
+ max: attribute.max,
513
+ xdefault: attribute.default,
514
+ });
515
+ case "boolean":
516
+ return databasesService.updateBooleanAttribute({
517
+ databaseId,
518
+ collectionId,
519
+ key: attribute.key,
520
+ required: attribute.required,
521
+ xdefault: attribute.default,
522
+ });
523
+ case "datetime":
524
+ return databasesService.updateDatetimeAttribute({
525
+ databaseId,
526
+ collectionId,
527
+ key: attribute.key,
528
+ required: attribute.required,
529
+ xdefault: attribute.default,
530
+ });
531
+ case "relationship":
532
+ return databasesService.updateRelationshipAttribute({
533
+ databaseId,
534
+ collectionId,
535
+ key: attribute.key,
536
+ onDelete: attribute.onDelete,
537
+ });
538
+ case "point":
539
+ return databasesService.updatePointAttribute({
540
+ databaseId,
541
+ collectionId,
542
+ key: attribute.key,
543
+ required: attribute.required,
544
+ xdefault: attribute.default,
545
+ });
546
+ case "linestring":
547
+ return databasesService.updateLineAttribute({
548
+ databaseId,
549
+ collectionId,
550
+ key: attribute.key,
551
+ required: attribute.required,
552
+ xdefault: attribute.default,
553
+ });
554
+ case "polygon":
555
+ return databasesService.updatePolygonAttribute({
556
+ databaseId,
557
+ collectionId,
558
+ key: attribute.key,
559
+ required: attribute.required,
560
+ xdefault: attribute.default,
561
+ });
562
+ default:
563
+ throw new Error(`Unsupported attribute type: ${attribute.type}`);
564
+ }
565
+ };
566
+ const deleteAttribute = async (collection, attribute, isIndex = false) => {
567
+ log(`Deleting ${isIndex ? "index" : "attribute"} ${attribute.key} of ${collection.name} ( ${collection["$id"]} )`);
568
+ const databasesService = await getDatabasesService();
569
+ if (isIndex) {
570
+ await databasesService.deleteIndex(collection["databaseId"], collection["$id"], attribute.key);
571
+ return;
572
+ }
573
+ await databasesService.deleteAttribute(collection["databaseId"], collection["$id"], attribute.key);
574
+ };
575
+ const isEqual = (a, b) => {
576
+ if (a === b)
577
+ return true;
578
+ if (a && b && typeof a === "object" && typeof b === "object") {
579
+ if (a.constructor &&
580
+ a.constructor.name === "BigNumber" &&
581
+ b.constructor &&
582
+ b.constructor.name === "BigNumber") {
583
+ return a.eq(b);
584
+ }
585
+ if (typeof a.equals === "function") {
586
+ return a.equals(b);
587
+ }
588
+ if (typeof a.eq === "function") {
589
+ return a.eq(b);
590
+ }
591
+ }
592
+ if (typeof a === "number" && typeof b === "number") {
593
+ if (isNaN(a) && isNaN(b))
594
+ return true;
595
+ if (!isFinite(a) && !isFinite(b))
596
+ return a === b;
597
+ return Math.abs(a - b) < Number.EPSILON;
598
+ }
599
+ return false;
600
+ };
601
+ const compareAttribute = (remote, local, reason, key) => {
602
+ if (isEmpty(remote) && isEmpty(local)) {
603
+ return reason;
604
+ }
605
+ if (Array.isArray(remote) && Array.isArray(local)) {
606
+ if (JSON.stringify(remote) !== JSON.stringify(local)) {
607
+ const bol = reason === "" ? "" : "\n";
608
+ reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
609
+ }
610
+ }
611
+ else if (!isEqual(remote, local)) {
612
+ const bol = reason === "" ? "" : "\n";
613
+ reason += `${bol}${key} changed from ${chalk.red(remote)} to ${chalk.green(local)}`;
614
+ }
615
+ return reason;
616
+ };
617
+ /**
618
+ * Check if attribute non-changeable fields has been changed
619
+ * If so return the differences as an object.
620
+ */
621
+ const checkAttributeChanges = (remote, local, collection, recreating = true) => {
622
+ if (local === undefined) {
623
+ return undefined;
624
+ }
625
+ const keyName = `${chalk.yellow(local.key)} in ${collection.name} (${collection["$id"]})`;
626
+ const action = chalk.cyan(recreating ? "recreating" : "changing");
627
+ let reason = "";
628
+ let attribute = recreating ? remote : local;
629
+ for (let key of Object.keys(remote)) {
630
+ if (!KeysAttributes.has(key)) {
631
+ continue;
632
+ }
633
+ if (changeableKeys.includes(key)) {
634
+ if (!recreating) {
635
+ reason = compareAttribute(remote[key], local[key], reason, key);
636
+ }
637
+ continue;
638
+ }
639
+ if (!recreating) {
640
+ continue;
641
+ }
642
+ reason = compareAttribute(remote[key], local[key], reason, key);
643
+ }
644
+ return reason === ""
645
+ ? undefined
646
+ : { key: keyName, attribute, reason, action };
647
+ };
648
+ /**
649
+ * Check if attributes contain the given attribute
650
+ */
651
+ const attributesContains = (attribute, attributes) => attributes.find((attr) => attr.key === attribute.key);
652
+ const generateChangesObject = (attribute, collection, isAdding) => {
653
+ return {
654
+ key: `${chalk.yellow(attribute.key)} in ${collection.name} (${collection["$id"]})`,
655
+ attribute: attribute,
656
+ reason: isAdding
657
+ ? "Field isn't present on the remote server"
658
+ : "Field isn't present on the appwrite.config.json file",
659
+ action: isAdding ? chalk.green("adding") : chalk.red("deleting"),
660
+ };
661
+ };
662
+ /**
663
+ * Filter deleted and recreated attributes,
664
+ * return list of attributes to create
665
+ */
666
+ const attributesToCreate = async (remoteAttributes, localAttributes, collection, isIndex = false) => {
667
+ const deleting = remoteAttributes
668
+ .filter((attribute) => !attributesContains(attribute, localAttributes))
669
+ .map((attr) => generateChangesObject(attr, collection, false));
670
+ const adding = localAttributes
671
+ .filter((attribute) => !attributesContains(attribute, remoteAttributes))
672
+ .map((attr) => generateChangesObject(attr, collection, true));
673
+ const conflicts = remoteAttributes
674
+ .map((attribute) => checkAttributeChanges(attribute, attributesContains(attribute, localAttributes), collection))
675
+ .filter((attribute) => attribute !== undefined);
676
+ const changes = remoteAttributes
677
+ .map((attribute) => checkAttributeChanges(attribute, attributesContains(attribute, localAttributes), collection, false))
678
+ .filter((attribute) => attribute !== undefined)
679
+ .filter((attribute) => conflicts.filter((attr) => attribute.key === attr.key).length !== 1);
680
+ let changedAttributes = [];
681
+ const changing = [...deleting, ...adding, ...conflicts, ...changes];
682
+ if (changing.length === 0) {
683
+ return changedAttributes;
684
+ }
685
+ log(!cliConfig.force
686
+ ? "There are pending changes in your collection deployment"
687
+ : "List of applied changes");
688
+ drawTable(changing.map((change) => {
689
+ return { Key: change.key, Action: change.action, Reason: change.reason };
690
+ }));
691
+ if (!cliConfig.force) {
692
+ if (deleting.length > 0 && !isIndex) {
693
+ console.log(`${chalk.red("------------------------------------------------------")}`);
694
+ console.log(`${chalk.red("| WARNING: Attribute deletion may cause loss of data |")}`);
695
+ console.log(`${chalk.red("------------------------------------------------------")}`);
696
+ console.log();
697
+ }
698
+ if (conflicts.length > 0 && !isIndex) {
699
+ console.log(`${chalk.red("--------------------------------------------------------")}`);
700
+ console.log(`${chalk.red("| WARNING: Attribute recreation may cause loss of data |")}`);
701
+ console.log(`${chalk.red("--------------------------------------------------------")}`);
702
+ console.log();
703
+ }
704
+ if ((await getConfirmation()) !== true) {
705
+ return changedAttributes;
706
+ }
707
+ }
708
+ if (conflicts.length > 0) {
709
+ changedAttributes = conflicts.map((change) => change.attribute);
710
+ await Promise.all(changedAttributes.map((changed) => deleteAttribute(collection, changed, isIndex)));
711
+ remoteAttributes = remoteAttributes.filter((attribute) => !attributesContains(attribute, changedAttributes));
712
+ }
713
+ if (changes.length > 0) {
714
+ changedAttributes = changes.map((change) => change.attribute);
715
+ await Promise.all(changedAttributes.map((changed) => updateAttribute(collection["databaseId"], collection["$id"], changed)));
716
+ }
717
+ const deletingAttributes = deleting.map((change) => change.attribute);
718
+ await Promise.all(deletingAttributes.map((attribute) => deleteAttribute(collection, attribute, isIndex)));
719
+ const attributeKeys = [
720
+ ...remoteAttributes.map((attribute) => attribute.key),
721
+ ...deletingAttributes.map((attribute) => attribute.key),
722
+ ];
723
+ if (attributeKeys.length) {
724
+ const deleteAttributesPoolStatus = await awaitPools.deleteAttributes(collection["databaseId"], collection["$id"], attributeKeys);
725
+ if (!deleteAttributesPoolStatus) {
726
+ throw new Error("Attribute deletion timed out.");
727
+ }
728
+ }
729
+ return localAttributes.filter((attribute) => !attributesContains(attribute, remoteAttributes));
730
+ };
731
+ const createIndexes = async (indexes, collection) => {
732
+ log(`Creating indexes ...`);
733
+ const databasesService = await getDatabasesService();
734
+ for (let index of indexes) {
735
+ await databasesService.createIndex(collection["databaseId"], collection["$id"], index.key, index.type, index.columns ?? index.attributes, index.orders);
736
+ }
737
+ const result = await awaitPools.expectIndexes(collection["databaseId"], collection["$id"], indexes.map((index) => index.key));
738
+ if (!result) {
739
+ throw new Error("Index creation timed out.");
740
+ }
741
+ success(`Created ${indexes.length} indexes`);
742
+ };
743
+ const createAttributes = async (attributes, collection) => {
744
+ for (let attribute of attributes) {
745
+ if (attribute.side !== "child") {
746
+ await createAttribute(collection["databaseId"], collection["$id"], attribute);
747
+ }
748
+ }
749
+ const result = await awaitPools.expectAttributes(collection["databaseId"], collection["$id"], collection.attributes
750
+ .filter((attribute) => attribute.side !== "child")
751
+ .map((attribute) => attribute.key));
752
+ if (!result) {
753
+ throw new Error(`Attribute creation timed out.`);
754
+ }
755
+ success(`Created ${attributes.length} attributes`);
756
+ };
757
+ const createColumns = async (columns, table) => {
758
+ for (let column of columns) {
759
+ if (column.side !== "child") {
760
+ await createAttribute(table["databaseId"], table["$id"], column);
761
+ }
762
+ }
763
+ const result = await awaitPools.expectAttributes(table["databaseId"], table["$id"], table.columns
764
+ .filter((column) => column.side !== "child")
765
+ .map((column) => column.key));
766
+ if (!result) {
767
+ throw new Error(`Column creation timed out.`);
768
+ }
769
+ success(`Created ${columns.length} columns`);
770
+ };
771
+ const pushResources = async ({ skipDeprecated = false, } = {}) => {
772
+ const actions = {
773
+ settings: pushSettings,
774
+ functions: pushFunction,
775
+ sites: pushSite,
776
+ collections: pushCollection,
777
+ tables: pushTable,
778
+ buckets: pushBucket,
779
+ teams: pushTeam,
780
+ messages: pushMessagingTopic,
781
+ };
782
+ if (skipDeprecated) {
783
+ delete actions.collections;
784
+ }
785
+ if (cliConfig.all) {
786
+ for (let action of Object.values(actions)) {
787
+ await action();
788
+ }
789
+ }
790
+ else {
791
+ const answers = await inquirer.prompt(questionsPushResources);
792
+ const action = actions[answers.resource];
793
+ if (action !== undefined) {
794
+ await action();
795
+ }
796
+ }
797
+ };
798
+ const pushSettings = async () => {
799
+ checkDeployConditions(localConfig);
800
+ try {
801
+ const projectsService = await getProjectsService();
802
+ let response = await projectsService.get(localConfig.getProject().projectId);
803
+ const remoteSettings = localConfig.createSettingsObject(response ?? {});
804
+ const localSettings = localConfig.getProject().projectSettings ?? {};
805
+ log("Checking for changes ...");
806
+ const changes = [];
807
+ changes.push(...getObjectChanges(remoteSettings, localSettings, "services", "Service"));
808
+ changes.push(...getObjectChanges(remoteSettings["auth"] ?? {}, localSettings["auth"] ?? {}, "methods", "Auth method"));
809
+ changes.push(...getObjectChanges(remoteSettings["auth"] ?? {}, localSettings["auth"] ?? {}, "security", "Auth security"));
810
+ if (changes.length > 0) {
811
+ drawTable(changes);
812
+ if ((await getConfirmation()) !== true) {
813
+ success(`Successfully pushed 0 project settings.`);
814
+ return;
815
+ }
816
+ }
817
+ }
818
+ catch (e) { }
819
+ try {
820
+ log("Pushing project settings ...");
821
+ const projectsService = await getProjectsService();
822
+ const projectId = localConfig.getProject().projectId;
823
+ const projectName = localConfig.getProject().projectName;
824
+ const settings = localConfig.getProject().projectSettings ?? {};
825
+ if (projectName) {
826
+ log("Applying project name ...");
827
+ await projectsService.update(projectId, projectName);
828
+ }
829
+ if (settings.services) {
830
+ log("Applying service statuses ...");
831
+ for (let [service, status] of Object.entries(settings.services)) {
832
+ await projectsService.updateServiceStatus(projectId, service, status);
833
+ }
834
+ }
835
+ if (settings.auth) {
836
+ if (settings.auth.security) {
837
+ log("Applying auth security settings ...");
838
+ await projectsService.updateAuthDuration(projectId, settings.auth.security.duration);
839
+ await projectsService.updateAuthLimit(projectId, settings.auth.security.limit);
840
+ await projectsService.updateAuthSessionsLimit(projectId, settings.auth.security.sessionsLimit);
841
+ await projectsService.updateAuthPasswordDictionary(projectId, settings.auth.security.passwordDictionary);
842
+ await projectsService.updateAuthPasswordHistory(projectId, settings.auth.security.passwordHistory);
843
+ await projectsService.updatePersonalDataCheck(projectId, settings.auth.security.personalDataCheck);
844
+ await projectsService.updateSessionAlerts(projectId, settings.auth.security.sessionAlerts);
845
+ await projectsService.updateMockNumbers(projectId, settings.auth.security.mockNumbers);
846
+ }
847
+ if (settings.auth.methods) {
848
+ log("Applying auth methods statuses ...");
849
+ for (let [method, status] of Object.entries(settings.auth.methods)) {
850
+ await projectsService.updateAuthStatus(projectId, method, status);
851
+ }
852
+ }
853
+ }
854
+ success(`Successfully pushed ${chalk.bold("all")} project settings.`);
855
+ }
856
+ catch (e) {
857
+ throw e;
858
+ }
859
+ };
860
+ const pushSite = async ({ siteId, async: asyncDeploy, code, withVariables, } = {}) => {
861
+ process.chdir(localConfig.configDirectoryPath);
862
+ const siteIds = [];
863
+ if (siteId) {
864
+ siteIds.push(siteId);
865
+ }
866
+ else if (cliConfig.all) {
867
+ checkDeployConditions(localConfig);
868
+ const sites = localConfig.getSites();
869
+ siteIds.push(...sites.map((site) => {
870
+ return site.$id;
871
+ }));
872
+ }
873
+ if (siteIds.length <= 0) {
874
+ const answers = await inquirer.prompt(questionsPushSites);
875
+ if (answers.sites) {
876
+ siteIds.push(...answers.sites);
877
+ }
878
+ }
879
+ if (siteIds.length === 0) {
880
+ log("No sites found.");
881
+ hint("Use 'appwrite pull sites' to synchronize existing one, or use 'appwrite init site' to create a new one.");
882
+ return;
883
+ }
884
+ let sites = siteIds.map((id) => {
885
+ const sites = localConfig.getSites();
886
+ const site = sites.find((s) => s.$id === id);
887
+ if (!site) {
888
+ throw new Error("Site '" + id + "' not found.");
889
+ }
890
+ return site;
891
+ });
892
+ log("Validating sites ...");
893
+ // Validation is done BEFORE pushing so the deployment process can be run in async with progress update
894
+ for (let site of sites) {
895
+ if (!site.buildCommand) {
896
+ log(`Site ${site.name} is missing build command.`);
897
+ const answers = await inquirer.prompt(questionsGetEntrypoint);
898
+ site.buildCommand = answers.entrypoint;
899
+ localConfig.addSite(site);
900
+ }
901
+ }
902
+ if (!(await approveChanges(sites, async (args) => {
903
+ const sitesService = await getSitesService();
904
+ return await sitesService.get({ siteId: args.siteId });
905
+ }, KeysSite, "siteId", "sites", ["vars"]))) {
906
+ return;
907
+ }
908
+ log("Pushing sites ...");
909
+ Spinner.start(false);
910
+ let successfullyPushed = 0;
911
+ let successfullyDeployed = 0;
912
+ const failedDeployments = [];
913
+ const errors = [];
914
+ await Promise.all(sites.map(async (site) => {
915
+ let response = {};
916
+ const ignore = site.ignore ? "appwrite.config.json" : ".gitignore";
917
+ let siteExists = false;
918
+ let deploymentCreated = false;
919
+ const updaterRow = new Spinner({
920
+ status: "",
921
+ resource: site.name,
922
+ id: site["$id"],
923
+ end: `Ignoring using: ${ignore}`,
924
+ });
925
+ updaterRow.update({ status: "Getting" }).startSpinner(SPINNER_DOTS);
926
+ const sitesService = await getSitesService();
927
+ try {
928
+ response = await sitesService.get({ siteId: site["$id"] });
929
+ siteExists = true;
930
+ if (response.framework !== site.framework) {
931
+ updaterRow.fail({
932
+ errorMessage: `Framework mismatch! (local=${site.framework},remote=${response.framework}) Please delete remote site or update your appwrite.config.json`,
933
+ });
934
+ return;
935
+ }
936
+ updaterRow.update({ status: "Updating" }).replaceSpinner(SPINNER_ARC);
937
+ response = await sitesService.update({
938
+ siteId: site["$id"],
939
+ name: site.name,
940
+ framework: site.framework,
941
+ enabled: site.enabled,
942
+ logging: site.logging,
943
+ timeout: site.timeout,
944
+ installCommand: site.installCommand,
945
+ buildCommand: site.buildCommand,
946
+ outputDirectory: site.outputDirectory,
947
+ buildRuntime: site.buildRuntime,
948
+ adapter: site.adapter,
949
+ specification: site.specification,
950
+ });
951
+ }
952
+ catch (e) {
953
+ if (Number(e.code) === 404) {
954
+ siteExists = false;
955
+ }
956
+ else {
957
+ errors.push(e);
958
+ updaterRow.fail({
959
+ errorMessage: e.message ?? "General error occurs please try again",
960
+ });
961
+ return;
962
+ }
963
+ }
964
+ if (!siteExists) {
965
+ updaterRow.update({ status: "Creating" }).replaceSpinner(SPINNER_DOTS);
966
+ try {
967
+ response = await sitesService.create({
968
+ siteId: site.$id,
969
+ name: site.name,
970
+ framework: site.framework,
971
+ enabled: site.enabled,
972
+ logging: site.logging,
973
+ timeout: site.timeout,
974
+ installCommand: site.installCommand,
975
+ buildCommand: site.buildCommand,
976
+ outputDirectory: site.outputDirectory,
977
+ buildRuntime: site.buildRuntime,
978
+ adapter: site.adapter,
979
+ specification: site.specification,
980
+ });
981
+ let domain = "";
982
+ try {
983
+ const consoleService = await getConsoleService();
984
+ const variables = await consoleService.variables();
985
+ domain = ID.unique() + "." + variables["_APP_DOMAIN_SITES"];
986
+ }
987
+ catch (error) {
988
+ console.error("Error fetching console variables.");
989
+ throw error;
990
+ }
991
+ try {
992
+ const proxyService = await getProxyService();
993
+ const rule = await proxyService.createSiteRule(domain, site.$id);
994
+ }
995
+ catch (error) {
996
+ console.error("Error creating site rule.");
997
+ throw error;
998
+ }
999
+ updaterRow.update({ status: "Created" });
1000
+ }
1001
+ catch (e) {
1002
+ errors.push(e);
1003
+ updaterRow.fail({
1004
+ errorMessage: e.message ?? "General error occurs please try again",
1005
+ });
1006
+ return;
1007
+ }
1008
+ }
1009
+ if (withVariables) {
1010
+ updaterRow
1011
+ .update({ status: "Creating variables" })
1012
+ .replaceSpinner(SPINNER_ARC);
1013
+ const sitesService = await getSitesService();
1014
+ const { variables } = await paginate(async (args) => {
1015
+ return await sitesService.listVariables({ siteId: args.siteId });
1016
+ }, {
1017
+ siteId: site["$id"],
1018
+ }, 100, "variables");
1019
+ await Promise.all(variables.map(async (variable) => {
1020
+ const sitesService = await getSitesService();
1021
+ await sitesService.deleteVariable({
1022
+ siteId: site["$id"],
1023
+ variableId: variable["$id"],
1024
+ });
1025
+ }));
1026
+ const envFileLocation = `${site["path"]}/.env`;
1027
+ let envVariables = [];
1028
+ try {
1029
+ if (fs.existsSync(envFileLocation)) {
1030
+ const envObject = parseDotenv(fs.readFileSync(envFileLocation, "utf8"));
1031
+ envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
1032
+ }
1033
+ }
1034
+ catch (error) {
1035
+ // Handle parsing errors gracefully
1036
+ envVariables = [];
1037
+ }
1038
+ await Promise.all(envVariables.map(async (variable) => {
1039
+ const sitesService = await getSitesService();
1040
+ await sitesService.createVariable({
1041
+ siteId: site["$id"],
1042
+ key: variable.key,
1043
+ value: variable.value,
1044
+ secret: false,
1045
+ });
1046
+ }));
1047
+ }
1048
+ if (code === false) {
1049
+ successfullyPushed++;
1050
+ successfullyDeployed++;
1051
+ updaterRow.update({ status: "Pushed" });
1052
+ updaterRow.stopSpinner();
1053
+ return;
1054
+ }
1055
+ try {
1056
+ updaterRow.update({ status: "Pushing" }).replaceSpinner(SPINNER_ARC);
1057
+ const sitesService = await getSitesService();
1058
+ response = await sitesService.createDeployment({
1059
+ siteId: site["$id"],
1060
+ installCommand: site.installCommand,
1061
+ buildCommand: site.buildCommand,
1062
+ outputDirectory: site.outputDirectory,
1063
+ code: site.path,
1064
+ activate: true,
1065
+ });
1066
+ updaterRow.update({ status: "Pushed" });
1067
+ deploymentCreated = true;
1068
+ successfullyPushed++;
1069
+ }
1070
+ catch (e) {
1071
+ errors.push(e);
1072
+ switch (e.code) {
1073
+ case "ENOENT":
1074
+ updaterRow.fail({
1075
+ errorMessage: "Not found in the current directory. Skipping...",
1076
+ });
1077
+ break;
1078
+ default:
1079
+ updaterRow.fail({
1080
+ errorMessage: e.message ?? "An unknown error occurred. Please try again.",
1081
+ });
1082
+ }
1083
+ }
1084
+ if (deploymentCreated && !asyncDeploy) {
1085
+ try {
1086
+ const deploymentId = response["$id"];
1087
+ updaterRow.update({
1088
+ status: "Deploying",
1089
+ end: "Checking deployment status...",
1090
+ });
1091
+ let pollChecks = 0;
1092
+ while (true) {
1093
+ const sitesService = await getSitesService();
1094
+ response = await sitesService.getDeployment({
1095
+ siteId: site["$id"],
1096
+ deploymentId: deploymentId,
1097
+ });
1098
+ const status = response["status"];
1099
+ if (status === "ready") {
1100
+ successfullyDeployed++;
1101
+ let url = "";
1102
+ const proxyService = await getProxyService();
1103
+ const res = await proxyService.listRules([
1104
+ JSON.stringify({ method: "limit", values: [1] }),
1105
+ JSON.stringify({
1106
+ method: "equal",
1107
+ attribute: "deploymentResourceType",
1108
+ values: ["site"],
1109
+ }),
1110
+ JSON.stringify({
1111
+ method: "equal",
1112
+ attribute: "deploymentResourceId",
1113
+ values: [site["$id"]],
1114
+ }),
1115
+ JSON.stringify({
1116
+ method: "equal",
1117
+ attribute: "trigger",
1118
+ values: ["manual"],
1119
+ }),
1120
+ ]);
1121
+ if (Number(res.total) === 1) {
1122
+ url = res.rules[0].domain;
1123
+ }
1124
+ updaterRow.update({ status: "Deployed", end: url });
1125
+ break;
1126
+ }
1127
+ else if (status === "failed") {
1128
+ failedDeployments.push({
1129
+ name: site["name"],
1130
+ $id: site["$id"],
1131
+ deployment: response["$id"],
1132
+ });
1133
+ updaterRow.fail({ errorMessage: `Failed to deploy` });
1134
+ break;
1135
+ }
1136
+ else {
1137
+ updaterRow.update({
1138
+ status: "Deploying",
1139
+ end: `Current status: ${status}`,
1140
+ });
1141
+ }
1142
+ pollChecks++;
1143
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE * 1.5));
1144
+ }
1145
+ }
1146
+ catch (e) {
1147
+ errors.push(e);
1148
+ updaterRow.fail({
1149
+ errorMessage: e.message ?? "Unknown error occurred. Please try again",
1150
+ });
1151
+ }
1152
+ }
1153
+ updaterRow.stopSpinner();
1154
+ }));
1155
+ Spinner.stop();
1156
+ failedDeployments.forEach((failed) => {
1157
+ const { name, deployment, $id } = failed;
1158
+ const failUrl = `${globalConfig.getEndpoint().slice(0, -3)}/console/project-${localConfig.getProject().projectId}/sites/site-${$id}/deployments/deployment-${deployment}`;
1159
+ error(`Deployment of ${name} has failed. Check at ${failUrl} for more details\n`);
1160
+ });
1161
+ if (!asyncDeploy) {
1162
+ if (successfullyPushed === 0) {
1163
+ error("No sites were pushed.");
1164
+ }
1165
+ else if (successfullyDeployed !== successfullyPushed) {
1166
+ warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} sites`);
1167
+ }
1168
+ else {
1169
+ success(`Successfully pushed ${successfullyPushed} sites.`);
1170
+ }
1171
+ }
1172
+ else {
1173
+ success(`Successfully pushed ${successfullyPushed} sites.`);
1174
+ }
1175
+ if (cliConfig.verbose) {
1176
+ errors.forEach((e) => {
1177
+ console.error(e);
1178
+ });
1179
+ }
1180
+ };
1181
+ const pushFunction = async ({ functionId, async: asyncDeploy, code, withVariables, } = {}) => {
1182
+ process.chdir(localConfig.configDirectoryPath);
1183
+ const functionIds = [];
1184
+ if (functionId) {
1185
+ functionIds.push(functionId);
1186
+ }
1187
+ else if (cliConfig.all) {
1188
+ checkDeployConditions(localConfig);
1189
+ const functions = localConfig.getFunctions();
1190
+ functionIds.push(...functions.map((func) => {
1191
+ return func.$id;
1192
+ }));
1193
+ }
1194
+ if (functionIds.length <= 0) {
1195
+ const answers = await inquirer.prompt(questionsPushFunctions);
1196
+ if (answers.functions) {
1197
+ functionIds.push(...answers.functions);
1198
+ }
1199
+ }
1200
+ if (functionIds.length === 0) {
1201
+ log("No functions found.");
1202
+ hint("Use 'appwrite pull functions' to synchronize existing one, or use 'appwrite init function' to create a new one.");
1203
+ return;
1204
+ }
1205
+ let functions = functionIds.map((id) => {
1206
+ const functions = localConfig.getFunctions();
1207
+ const func = functions.find((f) => f.$id === id);
1208
+ if (!func) {
1209
+ throw new Error("Function '" + id + "' not found.");
1210
+ }
1211
+ return func;
1212
+ });
1213
+ log("Validating functions ...");
1214
+ // Validation is done BEFORE pushing so the deployment process can be run in async with progress update
1215
+ for (let func of functions) {
1216
+ if (!func.entrypoint) {
1217
+ log(`Function ${func.name} is missing an entrypoint.`);
1218
+ const answers = await inquirer.prompt(questionsGetEntrypoint);
1219
+ func.entrypoint = answers.entrypoint;
1220
+ localConfig.addFunction(func);
1221
+ }
1222
+ }
1223
+ if (!(await approveChanges(functions, async (args) => {
1224
+ const functionsService = await getFunctionsService();
1225
+ return await functionsService.get({ functionId: args.functionId });
1226
+ }, KeysFunction, "functionId", "functions", ["vars"]))) {
1227
+ return;
1228
+ }
1229
+ log("Pushing functions ...");
1230
+ Spinner.start(false);
1231
+ let successfullyPushed = 0;
1232
+ let successfullyDeployed = 0;
1233
+ const failedDeployments = [];
1234
+ const errors = [];
1235
+ await Promise.all(functions.map(async (func) => {
1236
+ let response = {};
1237
+ const ignore = func.ignore ? "appwrite.config.json" : ".gitignore";
1238
+ let functionExists = false;
1239
+ let deploymentCreated = false;
1240
+ const updaterRow = new Spinner({
1241
+ status: "",
1242
+ resource: func.name,
1243
+ id: func["$id"],
1244
+ end: `Ignoring using: ${ignore}`,
1245
+ });
1246
+ updaterRow.update({ status: "Getting" }).startSpinner(SPINNER_DOTS);
1247
+ const functionsService = await getFunctionsService();
1248
+ try {
1249
+ response = await functionsService.get({ functionId: func["$id"] });
1250
+ functionExists = true;
1251
+ if (response.runtime !== func.runtime) {
1252
+ updaterRow.fail({
1253
+ errorMessage: `Runtime mismatch! (local=${func.runtime},remote=${response.runtime}) Please delete remote function or update your appwrite.config.json`,
1254
+ });
1255
+ return;
1256
+ }
1257
+ updaterRow.update({ status: "Updating" }).replaceSpinner(SPINNER_ARC);
1258
+ response = await functionsService.update({
1259
+ functionId: func["$id"],
1260
+ name: func.name,
1261
+ runtime: func.runtime,
1262
+ execute: func.execute,
1263
+ events: func.events,
1264
+ schedule: func.schedule,
1265
+ timeout: func.timeout,
1266
+ enabled: func.enabled,
1267
+ logging: func.logging,
1268
+ entrypoint: func.entrypoint,
1269
+ commands: func.commands,
1270
+ scopes: func.scopes,
1271
+ specification: func.specification,
1272
+ });
1273
+ }
1274
+ catch (e) {
1275
+ if (Number(e.code) === 404) {
1276
+ functionExists = false;
1277
+ }
1278
+ else {
1279
+ errors.push(e);
1280
+ updaterRow.fail({
1281
+ errorMessage: e.message ?? "General error occurs please try again",
1282
+ });
1283
+ return;
1284
+ }
1285
+ }
1286
+ if (!functionExists) {
1287
+ updaterRow.update({ status: "Creating" }).replaceSpinner(SPINNER_DOTS);
1288
+ try {
1289
+ response = await functionsService.create({
1290
+ functionId: func.$id,
1291
+ name: func.name,
1292
+ runtime: func.runtime,
1293
+ execute: func.execute,
1294
+ events: func.events,
1295
+ schedule: func.schedule,
1296
+ timeout: func.timeout,
1297
+ enabled: func.enabled,
1298
+ logging: func.logging,
1299
+ entrypoint: func.entrypoint,
1300
+ commands: func.commands,
1301
+ scopes: func.scopes,
1302
+ specification: func.specification,
1303
+ });
1304
+ let domain = "";
1305
+ try {
1306
+ const consoleService = await getConsoleService();
1307
+ const variables = await consoleService.variables();
1308
+ domain = ID.unique() + "." + variables["_APP_DOMAIN_FUNCTIONS"];
1309
+ }
1310
+ catch (error) {
1311
+ console.error("Error fetching console variables.");
1312
+ throw error;
1313
+ }
1314
+ try {
1315
+ const proxyService = await getProxyService();
1316
+ const rule = await proxyService.createFunctionRule(domain, func.$id);
1317
+ }
1318
+ catch (error) {
1319
+ console.error("Error creating function rule.");
1320
+ throw error;
1321
+ }
1322
+ updaterRow.update({ status: "Created" });
1323
+ }
1324
+ catch (e) {
1325
+ errors.push(e);
1326
+ updaterRow.fail({
1327
+ errorMessage: e.message ?? "General error occurs please try again",
1328
+ });
1329
+ return;
1330
+ }
1331
+ }
1332
+ if (withVariables) {
1333
+ updaterRow
1334
+ .update({ status: "Updating variables" })
1335
+ .replaceSpinner(SPINNER_ARC);
1336
+ const functionsService = await getFunctionsService();
1337
+ const { variables } = await paginate(async (args) => {
1338
+ return await functionsService.listVariables({
1339
+ functionId: args.functionId,
1340
+ });
1341
+ }, {
1342
+ functionId: func["$id"],
1343
+ }, 100, "variables");
1344
+ await Promise.all(variables.map(async (variable) => {
1345
+ const functionsService = await getFunctionsService();
1346
+ await functionsService.deleteVariable({
1347
+ functionId: func["$id"],
1348
+ variableId: variable["$id"],
1349
+ });
1350
+ }));
1351
+ const envFileLocation = `${func["path"]}/.env`;
1352
+ let envVariables = [];
1353
+ try {
1354
+ if (fs.existsSync(envFileLocation)) {
1355
+ const envObject = parseDotenv(fs.readFileSync(envFileLocation, "utf8"));
1356
+ envVariables = Object.entries(envObject || {}).map(([key, value]) => ({ key, value }));
1357
+ }
1358
+ }
1359
+ catch (error) {
1360
+ // Handle parsing errors gracefully
1361
+ envVariables = [];
1362
+ }
1363
+ await Promise.all(envVariables.map(async (variable) => {
1364
+ const functionsService = await getFunctionsService();
1365
+ await functionsService.createVariable({
1366
+ functionId: func["$id"],
1367
+ key: variable.key,
1368
+ value: variable.value,
1369
+ secret: false,
1370
+ });
1371
+ }));
1372
+ }
1373
+ if (code === false) {
1374
+ successfullyPushed++;
1375
+ successfullyDeployed++;
1376
+ updaterRow.update({ status: "Pushed" });
1377
+ updaterRow.stopSpinner();
1378
+ return;
1379
+ }
1380
+ try {
1381
+ updaterRow.update({ status: "Pushing" }).replaceSpinner(SPINNER_ARC);
1382
+ const functionsService = await getFunctionsService();
1383
+ response = await functionsService.createDeployment({
1384
+ functionId: func["$id"],
1385
+ entrypoint: func.entrypoint,
1386
+ commands: func.commands,
1387
+ code: func.path,
1388
+ activate: true,
1389
+ });
1390
+ updaterRow.update({ status: "Pushed" });
1391
+ deploymentCreated = true;
1392
+ successfullyPushed++;
1393
+ }
1394
+ catch (e) {
1395
+ errors.push(e);
1396
+ switch (e.code) {
1397
+ case "ENOENT":
1398
+ updaterRow.fail({
1399
+ errorMessage: "Not found in the current directory. Skipping...",
1400
+ });
1401
+ break;
1402
+ default:
1403
+ updaterRow.fail({
1404
+ errorMessage: e.message ?? "An unknown error occurred. Please try again.",
1405
+ });
1406
+ }
1407
+ }
1408
+ if (deploymentCreated && !asyncDeploy) {
1409
+ try {
1410
+ const deploymentId = response["$id"];
1411
+ updaterRow.update({
1412
+ status: "Deploying",
1413
+ end: "Checking deployment status...",
1414
+ });
1415
+ let pollChecks = 0;
1416
+ while (true) {
1417
+ const functionsService = await getFunctionsService();
1418
+ response = await functionsService.getDeployment({
1419
+ functionId: func["$id"],
1420
+ deploymentId: deploymentId,
1421
+ });
1422
+ const status = response["status"];
1423
+ if (status === "ready") {
1424
+ successfullyDeployed++;
1425
+ let url = "";
1426
+ const proxyService = await getProxyService();
1427
+ const res = await proxyService.listRules([
1428
+ JSON.stringify({ method: "limit", values: [1] }),
1429
+ JSON.stringify({
1430
+ method: "equal",
1431
+ attribute: "deploymentResourceType",
1432
+ values: ["function"],
1433
+ }),
1434
+ JSON.stringify({
1435
+ method: "equal",
1436
+ attribute: "deploymentResourceId",
1437
+ values: [func["$id"]],
1438
+ }),
1439
+ JSON.stringify({
1440
+ method: "equal",
1441
+ attribute: "trigger",
1442
+ values: ["manual"],
1443
+ }),
1444
+ ]);
1445
+ if (Number(res.total) === 1) {
1446
+ url = res.rules[0].domain;
1447
+ }
1448
+ updaterRow.update({ status: "Deployed", end: url });
1449
+ break;
1450
+ }
1451
+ else if (status === "failed") {
1452
+ failedDeployments.push({
1453
+ name: func["name"],
1454
+ $id: func["$id"],
1455
+ deployment: response["$id"],
1456
+ });
1457
+ updaterRow.fail({ errorMessage: `Failed to deploy` });
1458
+ break;
1459
+ }
1460
+ else {
1461
+ updaterRow.update({
1462
+ status: "Deploying",
1463
+ end: `Current status: ${status}`,
1464
+ });
1465
+ }
1466
+ pollChecks++;
1467
+ await new Promise((resolve) => setTimeout(resolve, POLL_DEBOUNCE * 1.5));
1468
+ }
1469
+ }
1470
+ catch (e) {
1471
+ errors.push(e);
1472
+ updaterRow.fail({
1473
+ errorMessage: e.message ?? "Unknown error occurred. Please try again",
1474
+ });
1475
+ }
1476
+ }
1477
+ updaterRow.stopSpinner();
1478
+ }));
1479
+ Spinner.stop();
1480
+ failedDeployments.forEach((failed) => {
1481
+ const { name, deployment, $id } = failed;
1482
+ const failUrl = `${globalConfig.getEndpoint().slice(0, -3)}/console/project-${localConfig.getProject().projectId}/functions/function-${$id}/deployment-${deployment}`;
1483
+ error(`Deployment of ${name} has failed. Check at ${failUrl} for more details\n`);
1484
+ });
1485
+ if (!asyncDeploy) {
1486
+ if (successfullyPushed === 0) {
1487
+ error("No functions were pushed.");
1488
+ }
1489
+ else if (successfullyDeployed !== successfullyPushed) {
1490
+ warn(`Successfully pushed ${successfullyDeployed} of ${successfullyPushed} functions`);
1491
+ }
1492
+ else {
1493
+ success(`Successfully pushed ${successfullyPushed} functions.`);
1494
+ }
1495
+ }
1496
+ else {
1497
+ success(`Successfully pushed ${successfullyPushed} functions.`);
1498
+ }
1499
+ if (cliConfig.verbose) {
1500
+ errors.forEach((e) => {
1501
+ console.error(e);
1502
+ });
1503
+ }
1504
+ };
1505
+ const checkAndApplyTablesDBChanges = async () => {
1506
+ log("Checking for tablesDB changes ...");
1507
+ const localTablesDBs = localConfig.getTablesDBs();
1508
+ const { databases: remoteTablesDBs } = await paginate(async (args) => {
1509
+ const tablesDBService = await getTablesDBService();
1510
+ return await tablesDBService.list(args.queries || []);
1511
+ }, {}, 100, "databases");
1512
+ if (localTablesDBs.length === 0 && remoteTablesDBs.length === 0) {
1513
+ return { applied: false, resyncNeeded: false };
1514
+ }
1515
+ const changes = [];
1516
+ const toCreate = [];
1517
+ const toUpdate = [];
1518
+ const toDelete = [];
1519
+ // Check for deletions - remote DBs that aren't in local config
1520
+ for (const remoteDB of remoteTablesDBs) {
1521
+ const localDB = localTablesDBs.find((db) => db.$id === remoteDB.$id);
1522
+ if (!localDB) {
1523
+ toDelete.push(remoteDB);
1524
+ changes.push({
1525
+ id: remoteDB.$id,
1526
+ action: chalk.red("deleting"),
1527
+ key: "Database",
1528
+ remote: remoteDB.name,
1529
+ local: "(deleted locally)",
1530
+ });
1531
+ }
1532
+ }
1533
+ // Check for additions and updates
1534
+ for (const localDB of localTablesDBs) {
1535
+ const remoteDB = remoteTablesDBs.find((db) => db.$id === localDB.$id);
1536
+ if (!remoteDB) {
1537
+ toCreate.push(localDB);
1538
+ changes.push({
1539
+ id: localDB.$id,
1540
+ action: chalk.green("creating"),
1541
+ key: "Database",
1542
+ remote: "(does not exist)",
1543
+ local: localDB.name,
1544
+ });
1545
+ }
1546
+ else {
1547
+ let hasChanges = false;
1548
+ if (remoteDB.name !== localDB.name) {
1549
+ hasChanges = true;
1550
+ changes.push({
1551
+ id: localDB.$id,
1552
+ action: chalk.yellow("updating"),
1553
+ key: "Name",
1554
+ remote: remoteDB.name,
1555
+ local: localDB.name,
1556
+ });
1557
+ }
1558
+ if (remoteDB.enabled !== localDB.enabled) {
1559
+ hasChanges = true;
1560
+ changes.push({
1561
+ id: localDB.$id,
1562
+ action: chalk.yellow("updating"),
1563
+ key: "Enabled",
1564
+ remote: remoteDB.enabled,
1565
+ local: localDB.enabled,
1566
+ });
1567
+ }
1568
+ if (hasChanges) {
1569
+ toUpdate.push(localDB);
1570
+ }
1571
+ }
1572
+ }
1573
+ if (changes.length === 0) {
1574
+ return { applied: false, resyncNeeded: false };
1575
+ }
1576
+ log("Found changes in tablesDB resource:");
1577
+ drawTable(changes);
1578
+ if (toDelete.length > 0) {
1579
+ console.log(`${chalk.red("------------------------------------------------------------------")}`);
1580
+ console.log(`${chalk.red("| WARNING: Database deletion will also delete all related tables |")}`);
1581
+ console.log(`${chalk.red("------------------------------------------------------------------")}`);
1582
+ console.log();
1583
+ }
1584
+ if ((await getConfirmation()) !== true) {
1585
+ return { applied: false, resyncNeeded: false };
1586
+ }
1587
+ // Apply deletions first
1588
+ let needsResync = false;
1589
+ for (const db of toDelete) {
1590
+ try {
1591
+ log(`Deleting database ${db.name} ( ${db.$id} ) ...`);
1592
+ const tablesDBService = await getTablesDBService();
1593
+ await tablesDBService.delete(db.$id);
1594
+ success(`Deleted ${db.name} ( ${db.$id} )`);
1595
+ needsResync = true;
1596
+ }
1597
+ catch (e) {
1598
+ error(`Failed to delete database ${db.name} ( ${db.$id} ): ${e.message}`);
1599
+ throw new Error(`Database sync failed during deletion of ${db.$id}. Some changes may have been applied.`);
1600
+ }
1601
+ }
1602
+ // Apply creations
1603
+ for (const db of toCreate) {
1604
+ try {
1605
+ log(`Creating database ${db.name} ( ${db.$id} ) ...`);
1606
+ const tablesDBService = await getTablesDBService();
1607
+ await tablesDBService.create(db.$id, db.name, db.enabled);
1608
+ success(`Created ${db.name} ( ${db.$id} )`);
1609
+ }
1610
+ catch (e) {
1611
+ error(`Failed to create database ${db.name} ( ${db.$id} ): ${e.message}`);
1612
+ throw new Error(`Database sync failed during creation of ${db.$id}. Some changes may have been applied.`);
1613
+ }
1614
+ }
1615
+ // Apply updates
1616
+ for (const db of toUpdate) {
1617
+ try {
1618
+ log(`Updating database ${db.name} ( ${db.$id} ) ...`);
1619
+ const tablesDBService = await getTablesDBService();
1620
+ await tablesDBService.update(db.$id, db.name, db.enabled);
1621
+ success(`Updated ${db.name} ( ${db.$id} )`);
1622
+ }
1623
+ catch (e) {
1624
+ error(`Failed to update database ${db.name} ( ${db.$id} ): ${e.message}`);
1625
+ throw new Error(`Database sync failed during update of ${db.$id}. Some changes may have been applied.`);
1626
+ }
1627
+ }
1628
+ if (toDelete.length === 0) {
1629
+ console.log();
1630
+ }
1631
+ return { applied: true, resyncNeeded: needsResync };
1632
+ };
1633
+ const pushTable = async ({ attempts, } = {}) => {
1634
+ const tables = [];
1635
+ if (attempts) {
1636
+ pollMaxDebounces = attempts;
1637
+ }
1638
+ const { applied: tablesDBApplied, resyncNeeded } = await checkAndApplyTablesDBChanges();
1639
+ if (resyncNeeded) {
1640
+ log("Resyncing configuration due to tablesDB deletions ...");
1641
+ const remoteTablesDBs = (await paginate(async (args) => {
1642
+ const tablesDBService = await getTablesDBService();
1643
+ return await tablesDBService.list(args.queries || []);
1644
+ }, {}, 100, "databases")).databases;
1645
+ const localTablesDBs = localConfig.getTablesDBs();
1646
+ const remoteDatabaseIds = new Set(remoteTablesDBs.map((db) => db.$id));
1647
+ const localTables = localConfig.getTables();
1648
+ const validTables = localTables.filter((table) => remoteDatabaseIds.has(table.databaseId));
1649
+ localConfig.set("tables", validTables);
1650
+ const validTablesDBs = localTablesDBs.filter((db) => remoteDatabaseIds.has(db.$id));
1651
+ localConfig.set("tablesDB", validTablesDBs);
1652
+ success("Configuration resynced successfully.");
1653
+ console.log();
1654
+ }
1655
+ log("Checking for deleted tables ...");
1656
+ const localTablesDBs = localConfig.getTablesDBs();
1657
+ const localTables = localConfig.getTables();
1658
+ const tablesToDelete = [];
1659
+ for (const db of localTablesDBs) {
1660
+ try {
1661
+ const { tables: remoteTables } = await paginate(async (args) => {
1662
+ const tablesDBService = await getTablesDBService();
1663
+ return await tablesDBService.listTables(args.databaseId, args.queries || []);
1664
+ }, {
1665
+ databaseId: db.$id,
1666
+ }, 100, "tables");
1667
+ for (const remoteTable of remoteTables) {
1668
+ const localTable = localTables.find((t) => t.$id === remoteTable.$id && t.databaseId === db.$id);
1669
+ if (!localTable) {
1670
+ tablesToDelete.push({
1671
+ ...remoteTable,
1672
+ databaseId: db.$id,
1673
+ databaseName: db.name,
1674
+ });
1675
+ }
1676
+ }
1677
+ }
1678
+ catch (e) {
1679
+ // Skip if database doesn't exist or other errors
1680
+ }
1681
+ }
1682
+ if (tablesToDelete.length > 0) {
1683
+ log("Found tables that exist remotely but not locally:");
1684
+ const deletionChanges = tablesToDelete.map((table) => ({
1685
+ id: table.$id,
1686
+ action: chalk.red("deleting"),
1687
+ key: "Table",
1688
+ database: table.databaseName,
1689
+ remote: table.name,
1690
+ local: "(deleted locally)",
1691
+ }));
1692
+ drawTable(deletionChanges);
1693
+ if ((await getConfirmation()) === true) {
1694
+ for (const table of tablesToDelete) {
1695
+ try {
1696
+ log(`Deleting table ${table.name} ( ${table.$id} ) from database ${table.databaseName} ...`);
1697
+ const tablesDBService = await getTablesDBService();
1698
+ await tablesDBService.deleteTable(table.databaseId, table.$id);
1699
+ success(`Deleted ${table.name} ( ${table.$id} )`);
1700
+ }
1701
+ catch (e) {
1702
+ error(`Failed to delete table ${table.name} ( ${table.$id} ): ${e.message}`);
1703
+ }
1704
+ }
1705
+ }
1706
+ }
1707
+ if (cliConfig.all) {
1708
+ checkDeployConditions(localConfig);
1709
+ tables.push(...localConfig.getTables());
1710
+ }
1711
+ else {
1712
+ const answers = await inquirer.prompt(questionsPushTables);
1713
+ if (answers.tables) {
1714
+ const configTables = new Map();
1715
+ localConfig.getTables().forEach((c) => {
1716
+ configTables.set(`${c["databaseId"]}|${c["$id"]}`, c);
1717
+ });
1718
+ answers.tables.forEach((a) => {
1719
+ const table = configTables.get(a);
1720
+ tables.push(table);
1721
+ });
1722
+ }
1723
+ }
1724
+ if (tables.length === 0) {
1725
+ log("No tables found.");
1726
+ hint("Use 'appwrite pull tables' to synchronize existing one, or use 'appwrite init table' to create a new one.");
1727
+ return;
1728
+ }
1729
+ if (!(await approveChanges(tables, async (args) => {
1730
+ const tablesDBService = await getTablesDBService();
1731
+ return await tablesDBService.getTable(args.databaseId, args.tableId);
1732
+ }, KeysTable, "tableId", "tables", ["columns", "indexes"], "databaseId", "databaseId"))) {
1733
+ return;
1734
+ }
1735
+ let tablesChanged = new Set();
1736
+ // Parallel tables actions
1737
+ await Promise.all(tables.map(async (table) => {
1738
+ try {
1739
+ const tablesDBService = await getTablesDBService();
1740
+ const remoteTable = await tablesDBService.getTable(table["databaseId"], table["$id"]);
1741
+ const changes = [];
1742
+ if (remoteTable.name !== table.name)
1743
+ changes.push("name");
1744
+ if (remoteTable.rowSecurity !== table.rowSecurity)
1745
+ changes.push("rowSecurity");
1746
+ if (remoteTable.enabled !== table.enabled)
1747
+ changes.push("enabled");
1748
+ if (JSON.stringify(remoteTable["$permissions"]) !==
1749
+ JSON.stringify(table["$permissions"]))
1750
+ changes.push("permissions");
1751
+ if (changes.length > 0) {
1752
+ await tablesDBService.updateTable(table["databaseId"], table["$id"], table.name, table.rowSecurity, table["$permissions"]);
1753
+ success(`Updated ${table.name} ( ${table["$id"]} ) - ${changes.join(", ")}`);
1754
+ tablesChanged.add(table["$id"]);
1755
+ }
1756
+ table.remoteVersion = remoteTable;
1757
+ table.isExisted = true;
1758
+ }
1759
+ catch (e) {
1760
+ if (Number(e.code) === 404) {
1761
+ log(`Table ${table.name} does not exist in the project. Creating ... `);
1762
+ const tablesDBService = await getTablesDBService();
1763
+ await tablesDBService.createTable(table["databaseId"], table["$id"], table.name, table.rowSecurity, table["$permissions"]);
1764
+ success(`Created ${table.name} ( ${table["$id"]} )`);
1765
+ tablesChanged.add(table["$id"]);
1766
+ }
1767
+ else {
1768
+ throw e;
1769
+ }
1770
+ }
1771
+ }));
1772
+ // Serialize attribute actions
1773
+ for (let table of tables) {
1774
+ let columns = table.columns;
1775
+ let indexes = table.indexes;
1776
+ if (table.isExisted) {
1777
+ columns = await attributesToCreate(table.remoteVersion.columns, table.columns, table);
1778
+ indexes = await attributesToCreate(table.remoteVersion.indexes, table.indexes, table, true);
1779
+ if (Array.isArray(columns) &&
1780
+ columns.length <= 0 &&
1781
+ Array.isArray(indexes) &&
1782
+ indexes.length <= 0) {
1783
+ continue;
1784
+ }
1785
+ }
1786
+ log(`Pushing table ${table.name} ( ${table["databaseId"]} - ${table["$id"]} ) attributes`);
1787
+ try {
1788
+ await createColumns(columns, table);
1789
+ }
1790
+ catch (e) {
1791
+ throw e;
1792
+ }
1793
+ try {
1794
+ await createIndexes(indexes, table);
1795
+ }
1796
+ catch (e) {
1797
+ throw e;
1798
+ }
1799
+ tablesChanged.add(table["$id"]);
1800
+ success(`Successfully pushed ${table.name} ( ${table["$id"]} )`);
1801
+ }
1802
+ success(`Successfully pushed ${tablesChanged.size} tables`);
1803
+ };
1804
+ const pushCollection = async ({ attempts }) => {
1805
+ warn("appwrite push collection has been deprecated. Please consider using 'appwrite push tables' instead");
1806
+ const collections = [];
1807
+ if (attempts) {
1808
+ pollMaxDebounces = attempts;
1809
+ }
1810
+ if (cliConfig.all) {
1811
+ checkDeployConditions(localConfig);
1812
+ collections.push(...localConfig.getCollections());
1813
+ }
1814
+ else {
1815
+ const answers = await inquirer.prompt(questionsPushCollections);
1816
+ if (answers.collections) {
1817
+ const configCollections = new Map();
1818
+ localConfig.getCollections().forEach((c) => {
1819
+ configCollections.set(`${c["databaseId"]}|${c["$id"]}`, c);
1820
+ });
1821
+ answers.collections.forEach((a) => {
1822
+ const collection = configCollections.get(a);
1823
+ collections.push(collection);
1824
+ });
1825
+ }
1826
+ }
1827
+ if (collections.length === 0) {
1828
+ log("No collections found.");
1829
+ hint("Use 'appwrite pull collections' to synchronize existing one, or use 'appwrite init collection' to create a new one.");
1830
+ return;
1831
+ }
1832
+ const databases = Array.from(new Set(collections.map((collection) => collection["databaseId"])));
1833
+ // Parallel db actions
1834
+ await Promise.all(databases.map(async (databaseId) => {
1835
+ const localDatabase = localConfig.getDatabase(databaseId);
1836
+ const databasesService = await getDatabasesService();
1837
+ try {
1838
+ const database = await databasesService.get(databaseId);
1839
+ if (database.name !== (localDatabase.name ?? databaseId)) {
1840
+ await databasesService.update(databaseId, localDatabase.name ?? databaseId);
1841
+ success(`Updated ${localDatabase.name} ( ${databaseId} ) name`);
1842
+ }
1843
+ }
1844
+ catch (err) {
1845
+ log(`Database ${databaseId} not found. Creating it now ...`);
1846
+ await databasesService.create(databaseId, localDatabase.name ?? databaseId);
1847
+ }
1848
+ }));
1849
+ if (!(await approveChanges(collections, async (args) => {
1850
+ const databasesService = await getDatabasesService();
1851
+ return await databasesService.getCollection(args.databaseId, args.collectionId);
1852
+ }, KeysCollection, "collectionId", "collections", ["attributes", "indexes"], "databaseId", "databaseId"))) {
1853
+ return;
1854
+ }
1855
+ // Parallel collection actions
1856
+ await Promise.all(collections.map(async (collection) => {
1857
+ try {
1858
+ const databasesService = await getDatabasesService();
1859
+ const remoteCollection = await databasesService.getCollection(collection["databaseId"], collection["$id"]);
1860
+ if (remoteCollection.name !== collection.name) {
1861
+ await databasesService.updateCollection(collection["databaseId"], collection["$id"], collection.name);
1862
+ success(`Updated ${collection.name} ( ${collection["$id"]} ) name`);
1863
+ }
1864
+ collection.remoteVersion = remoteCollection;
1865
+ collection.isExisted = true;
1866
+ }
1867
+ catch (e) {
1868
+ if (Number(e.code) === 404) {
1869
+ log(`Collection ${collection.name} does not exist in the project. Creating ... `);
1870
+ const databasesService = await getDatabasesService();
1871
+ await databasesService.createCollection(collection["databaseId"], collection["$id"], collection.name, collection.documentSecurity, collection["$permissions"]);
1872
+ }
1873
+ else {
1874
+ throw e;
1875
+ }
1876
+ }
1877
+ }));
1878
+ let numberOfCollections = 0;
1879
+ // Serialize attribute actions
1880
+ for (let collection of collections) {
1881
+ let attributes = collection.attributes;
1882
+ let indexes = collection.indexes;
1883
+ if (collection.isExisted) {
1884
+ attributes = await attributesToCreate(collection.remoteVersion.attributes, collection.attributes, collection);
1885
+ indexes = await attributesToCreate(collection.remoteVersion.indexes, collection.indexes, collection, true);
1886
+ if (Array.isArray(attributes) &&
1887
+ attributes.length <= 0 &&
1888
+ Array.isArray(indexes) &&
1889
+ indexes.length <= 0) {
1890
+ continue;
1891
+ }
1892
+ }
1893
+ log(`Pushing collection ${collection.name} ( ${collection["databaseId"]} - ${collection["$id"]} ) attributes`);
1894
+ try {
1895
+ await createAttributes(attributes, collection);
1896
+ }
1897
+ catch (e) {
1898
+ throw e;
1899
+ }
1900
+ try {
1901
+ await createIndexes(indexes, collection);
1902
+ }
1903
+ catch (e) {
1904
+ throw e;
1905
+ }
1906
+ numberOfCollections++;
1907
+ success(`Successfully pushed ${collection.name} ( ${collection["$id"]} )`);
1908
+ }
1909
+ success(`Successfully pushed ${numberOfCollections} collections`);
1910
+ };
1911
+ const pushBucket = async () => {
1912
+ let response = {};
1913
+ let bucketIds = [];
1914
+ const configBuckets = localConfig.getBuckets();
1915
+ if (cliConfig.all) {
1916
+ checkDeployConditions(localConfig);
1917
+ bucketIds.push(...configBuckets.map((b) => b.$id));
1918
+ }
1919
+ if (bucketIds.length === 0) {
1920
+ const answers = await inquirer.prompt(questionsPushBuckets);
1921
+ if (answers.buckets) {
1922
+ bucketIds.push(...answers.buckets);
1923
+ }
1924
+ }
1925
+ if (bucketIds.length === 0) {
1926
+ log("No buckets found.");
1927
+ hint("Use 'appwrite pull buckets' to synchronize existing one, or use 'appwrite init bucket' to create a new one.");
1928
+ return;
1929
+ }
1930
+ let buckets = [];
1931
+ for (const bucketId of bucketIds) {
1932
+ const idBuckets = configBuckets.filter((b) => b.$id === bucketId);
1933
+ buckets.push(...idBuckets);
1934
+ }
1935
+ if (!(await approveChanges(buckets, async (args) => {
1936
+ const storageService = await getStorageService();
1937
+ return await storageService.getBucket(args.bucketId);
1938
+ }, KeysStorage, "bucketId", "buckets"))) {
1939
+ return;
1940
+ }
1941
+ log("Pushing buckets ...");
1942
+ for (let bucket of buckets) {
1943
+ log(`Pushing bucket ${chalk.bold(bucket["name"])} ...`);
1944
+ const storageService = await getStorageService();
1945
+ try {
1946
+ response = await storageService.getBucket(bucket["$id"]);
1947
+ await storageService.updateBucket(bucket["$id"], bucket.name, bucket["$permissions"], bucket.fileSecurity, bucket.enabled, bucket.maximumFileSize, bucket.allowedFileExtensions, bucket.encryption, bucket.antivirus, bucket.compression);
1948
+ }
1949
+ catch (e) {
1950
+ if (Number(e.code) === 404) {
1951
+ log(`Bucket ${bucket.name} does not exist in the project. Creating ... `);
1952
+ response = await storageService.createBucket(bucket["$id"], bucket.name, bucket["$permissions"], bucket.fileSecurity, bucket.enabled, bucket.maximumFileSize, bucket.allowedFileExtensions, bucket.compression, bucket.encryption, bucket.antivirus);
1953
+ }
1954
+ else {
1955
+ throw e;
1956
+ }
1957
+ }
1958
+ }
1959
+ success(`Successfully pushed ${buckets.length} buckets.`);
1960
+ };
1961
+ const pushTeam = async () => {
1962
+ let response = {};
1963
+ let teamIds = [];
1964
+ const configTeams = localConfig.getTeams();
1965
+ if (cliConfig.all) {
1966
+ checkDeployConditions(localConfig);
1967
+ teamIds.push(...configTeams.map((t) => t.$id));
1968
+ }
1969
+ if (teamIds.length === 0) {
1970
+ const answers = await inquirer.prompt(questionsPushTeams);
1971
+ if (answers.teams) {
1972
+ teamIds.push(...answers.teams);
1973
+ }
1974
+ }
1975
+ if (teamIds.length === 0) {
1976
+ log("No teams found.");
1977
+ hint("Use 'appwrite pull teams' to synchronize existing one, or use 'appwrite init team' to create a new one.");
1978
+ return;
1979
+ }
1980
+ let teams = [];
1981
+ for (const teamId of teamIds) {
1982
+ const idTeams = configTeams.filter((t) => t.$id === teamId);
1983
+ teams.push(...idTeams);
1984
+ }
1985
+ if (!(await approveChanges(teams, async (args) => {
1986
+ const teamsService = await getTeamsService();
1987
+ return await teamsService.get(args.teamId);
1988
+ }, KeysTeams, "teamId", "teams"))) {
1989
+ return;
1990
+ }
1991
+ log("Pushing teams ...");
1992
+ for (let team of teams) {
1993
+ log(`Pushing team ${chalk.bold(team["name"])} ...`);
1994
+ const teamsService = await getTeamsService();
1995
+ try {
1996
+ response = await teamsService.get(team["$id"]);
1997
+ await teamsService.updateName(team["$id"], team.name);
1998
+ }
1999
+ catch (e) {
2000
+ if (Number(e.code) === 404) {
2001
+ log(`Team ${team.name} does not exist in the project. Creating ... `);
2002
+ response = await teamsService.create(team["$id"], team.name);
2003
+ }
2004
+ else {
2005
+ throw e;
2006
+ }
2007
+ }
2008
+ }
2009
+ success(`Successfully pushed ${teams.length} teams.`);
2010
+ };
2011
+ const pushMessagingTopic = async () => {
2012
+ let response = {};
2013
+ let topicsIds = [];
2014
+ const configTopics = localConfig.getMessagingTopics();
2015
+ if (cliConfig.all) {
2016
+ checkDeployConditions(localConfig);
2017
+ topicsIds.push(...configTopics.map((b) => b.$id));
2018
+ }
2019
+ if (topicsIds.length === 0) {
2020
+ const answers = await inquirer.prompt(questionsPushMessagingTopics);
2021
+ if (answers.topics) {
2022
+ topicsIds.push(...answers.topics);
2023
+ }
2024
+ }
2025
+ if (topicsIds.length === 0) {
2026
+ log("No topics found.");
2027
+ hint("Use 'appwrite pull topics' to synchronize existing one, or use 'appwrite init topic' to create a new one.");
2028
+ return;
2029
+ }
2030
+ let topics = [];
2031
+ for (const topicId of topicsIds) {
2032
+ const idTopic = configTopics.filter((b) => b.$id === topicId);
2033
+ topics.push(...idTopic);
2034
+ }
2035
+ if (!(await approveChanges(topics, async (args) => {
2036
+ const messagingService = await getMessagingService();
2037
+ return await messagingService.getTopic(args.topicId);
2038
+ }, KeysTopics, "topicId", "topics"))) {
2039
+ return;
2040
+ }
2041
+ log("Pushing topics ...");
2042
+ for (let topic of topics) {
2043
+ log(`Pushing topic ${chalk.bold(topic["name"])} ...`);
2044
+ const messagingService = await getMessagingService();
2045
+ try {
2046
+ response = await messagingService.getTopic(topic["$id"]);
2047
+ log(`Topic ${topic.name} ( ${topic["$id"]} ) already exists.`);
2048
+ await messagingService.updateTopic(topic["$id"], topic.name, topic.subscribe);
2049
+ }
2050
+ catch (e) {
2051
+ if (Number(e.code) === 404) {
2052
+ log(`Topic ${topic.name} does not exist in the project. Creating ... `);
2053
+ response = await messagingService.createTopic(topic["$id"], topic.name, topic.subscribe);
2054
+ success(`Created ${topic.name} ( ${topic["$id"]} )`);
2055
+ }
2056
+ else {
2057
+ throw e;
2058
+ }
2059
+ }
2060
+ }
2061
+ success(`Successfully pushed ${topics.length} topics.`);
2062
+ };
2063
+ export const push = new Command("push")
2064
+ .description(commandDescriptions["push"])
2065
+ .action(actionRunner(() => pushResources({ skipDeprecated: true })));
2066
+ push
2067
+ .command("all")
2068
+ .description("Push all resource.")
2069
+ .action(actionRunner(() => {
2070
+ cliConfig.all = true;
2071
+ return pushResources({ skipDeprecated: true });
2072
+ }));
2073
+ push
2074
+ .command("settings")
2075
+ .description("Push project name, services and auth settings")
2076
+ .action(actionRunner(pushSettings));
2077
+ push
2078
+ .command("function")
2079
+ .alias("functions")
2080
+ .description("Push functions in the current directory.")
2081
+ .option(`-f, --function-id <function-id>`, `ID of function to run`)
2082
+ .option(`-A, --async`, `Don't wait for functions deployments status`)
2083
+ .option("--no-code", "Don't push the function's code")
2084
+ .option("--with-variables", `Push function variables.`)
2085
+ .action(actionRunner(pushFunction));
2086
+ push
2087
+ .command("site")
2088
+ .alias("sites")
2089
+ .description("Push sites in the current directory.")
2090
+ .option(`-f, --site-id <site-id>`, `ID of site to run`)
2091
+ .option(`-A, --async`, `Don't wait for sites deployments status`)
2092
+ .option("--no-code", "Don't push the site's code")
2093
+ .option("--with-variables", `Push site variables.`)
2094
+ .action(actionRunner(pushSite));
2095
+ push
2096
+ .command("collection")
2097
+ .alias("collections")
2098
+ .description("Push collections in the current project. (deprecated, please use 'push tables' instead)")
2099
+ .option(`-a, --attempts <numberOfAttempts>`, `Max number of attempts before timing out. default: 30.`)
2100
+ .action(actionRunner(pushCollection));
2101
+ push
2102
+ .command("table")
2103
+ .alias("tables")
2104
+ .description("Push tables in the current project.")
2105
+ .option(`-a, --attempts <numberOfAttempts>`, `Max number of attempts before timing out. default: 30.`)
2106
+ .action(actionRunner(pushTable));
2107
+ push
2108
+ .command("bucket")
2109
+ .alias("buckets")
2110
+ .description("Push buckets in the current project.")
2111
+ .action(actionRunner(pushBucket));
2112
+ push
2113
+ .command("team")
2114
+ .alias("teams")
2115
+ .description("Push teams in the current project.")
2116
+ .action(actionRunner(pushTeam));
2117
+ push
2118
+ .command("topic")
2119
+ .alias("topics")
2120
+ .description("Push messaging topics in the current project.")
2121
+ .action(actionRunner(pushMessagingTopic));
2122
+ export const deploy = new Command("deploy")
2123
+ .description("Removed. Use appwrite push instead")
2124
+ .action(actionRunner(async () => {
2125
+ warn("appwrite deploy has been removed. Please use 'appwrite push' instead");
2126
+ }));
2127
+ //# sourceMappingURL=push.js.map