forest-cli 3.0.11 → 3.0.12-beta.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 (490) hide show
  1. package/bin/run +1 -1
  2. package/dist/abstract-authenticated-command.d.ts +9 -0
  3. package/dist/abstract-authenticated-command.d.ts.map +1 -0
  4. package/dist/abstract-authenticated-command.js +40 -0
  5. package/dist/abstract-command.d.ts +15 -0
  6. package/dist/abstract-command.d.ts.map +1 -0
  7. package/dist/abstract-command.js +22 -0
  8. package/dist/commands/branch.d.ts +45 -0
  9. package/dist/commands/branch.d.ts.map +1 -0
  10. package/dist/commands/branch.js +124 -0
  11. package/dist/commands/deploy.d.ts +33 -0
  12. package/dist/commands/deploy.d.ts.map +1 -0
  13. package/dist/commands/deploy.js +80 -0
  14. package/dist/commands/environments/copy-layout.d.ts +24 -0
  15. package/dist/commands/environments/copy-layout.d.ts.map +1 -0
  16. package/dist/commands/environments/copy-layout.js +102 -0
  17. package/dist/commands/environments/create.d.ts +32 -0
  18. package/dist/commands/environments/create.d.ts.map +1 -0
  19. package/dist/commands/environments/create.js +58 -0
  20. package/dist/commands/environments/delete.d.ts +19 -0
  21. package/dist/commands/environments/delete.d.ts.map +1 -0
  22. package/dist/commands/environments/delete.js +73 -0
  23. package/dist/commands/environments/get.d.ts +35 -0
  24. package/dist/commands/environments/get.d.ts.map +1 -0
  25. package/dist/commands/environments/get.js +38 -0
  26. package/dist/commands/environments/reset.d.ts +15 -0
  27. package/dist/commands/environments/reset.d.ts.map +1 -0
  28. package/dist/commands/environments/reset.js +70 -0
  29. package/dist/commands/environments/update.d.ts +14 -0
  30. package/dist/commands/environments/update.d.ts.map +1 -0
  31. package/dist/commands/environments/update.js +42 -0
  32. package/dist/commands/environments.d.ts +31 -0
  33. package/dist/commands/environments.d.ts.map +1 -0
  34. package/dist/commands/environments.js +36 -0
  35. package/dist/commands/init.d.ts +22 -0
  36. package/dist/commands/init.d.ts.map +1 -0
  37. package/dist/commands/init.js +134 -0
  38. package/dist/commands/login.d.ts +15 -0
  39. package/dist/commands/login.d.ts.map +1 -0
  40. package/dist/commands/login.js +30 -0
  41. package/dist/commands/logout.d.ts +10 -0
  42. package/dist/commands/logout.d.ts.map +1 -0
  43. package/dist/commands/logout.js +15 -0
  44. package/dist/commands/projects/create.d.ts +73 -0
  45. package/dist/commands/projects/create.d.ts.map +1 -0
  46. package/dist/commands/projects/create.js +218 -0
  47. package/dist/commands/projects/get.d.ts +35 -0
  48. package/dist/commands/projects/get.d.ts.map +1 -0
  49. package/dist/commands/projects/get.js +42 -0
  50. package/dist/commands/projects.d.ts +30 -0
  51. package/dist/commands/projects.d.ts.map +1 -0
  52. package/dist/commands/projects.js +30 -0
  53. package/dist/commands/push.d.ts +16 -0
  54. package/dist/commands/push.d.ts.map +1 -0
  55. package/dist/commands/push.js +66 -0
  56. package/dist/commands/schema/apply.d.ts +17 -0
  57. package/dist/commands/schema/apply.d.ts.map +1 -0
  58. package/dist/commands/schema/apply.js +112 -0
  59. package/dist/commands/schema/update.d.ts +17 -0
  60. package/dist/commands/schema/update.d.ts.map +1 -0
  61. package/dist/commands/schema/update.js +54 -0
  62. package/dist/commands/set-origin.d.ts +19 -0
  63. package/dist/commands/set-origin.d.ts.map +1 -0
  64. package/dist/commands/set-origin.js +50 -0
  65. package/dist/commands/switch.d.ts +22 -0
  66. package/dist/commands/switch.d.ts.map +1 -0
  67. package/dist/commands/switch.js +99 -0
  68. package/dist/commands/user.d.ts +14 -0
  69. package/dist/commands/user.d.ts.map +1 -0
  70. package/dist/commands/user.js +34 -0
  71. package/dist/context/command-project-create-plan.d.ts +3 -0
  72. package/dist/context/command-project-create-plan.d.ts.map +1 -0
  73. package/dist/context/command-project-create-plan.js +12 -0
  74. package/dist/context/command-projects-common-plan.d.ts +3 -0
  75. package/dist/context/command-projects-common-plan.d.ts.map +1 -0
  76. package/dist/context/command-projects-common-plan.js +37 -0
  77. package/dist/context/command-schema-update-command-plan.d.ts +3 -0
  78. package/dist/context/command-schema-update-command-plan.d.ts.map +1 -0
  79. package/dist/context/command-schema-update-command-plan.js +5 -0
  80. package/dist/context/dependencies-plan.d.ts +3 -0
  81. package/dist/context/dependencies-plan.d.ts.map +1 -0
  82. package/dist/context/dependencies-plan.js +22 -0
  83. package/dist/context/env-plan.d.ts +3 -0
  84. package/dist/context/env-plan.d.ts.map +1 -0
  85. package/dist/context/env-plan.js +28 -0
  86. package/dist/context/plan.d.ts +3 -0
  87. package/dist/context/plan.d.ts.map +1 -0
  88. package/dist/context/plan.js +13 -0
  89. package/dist/context/process-plan.d.ts +3 -0
  90. package/dist/context/process-plan.d.ts.map +1 -0
  91. package/dist/context/process-plan.js +4 -0
  92. package/dist/context/renderers-plan.d.ts +3 -0
  93. package/dist/context/renderers-plan.d.ts.map +1 -0
  94. package/dist/context/renderers-plan.js +8 -0
  95. package/dist/context/serializers-plan.d.ts +3 -0
  96. package/dist/context/serializers-plan.d.ts.map +1 -0
  97. package/dist/context/serializers-plan.js +9 -0
  98. package/dist/context/services-plan.d.ts +3 -0
  99. package/dist/context/services-plan.d.ts.map +1 -0
  100. package/dist/context/services-plan.js +9 -0
  101. package/dist/context/static.d.ts +2 -0
  102. package/dist/context/static.d.ts.map +1 -0
  103. package/dist/context/static.js +15 -0
  104. package/dist/context/utils-plan.d.ts +3 -0
  105. package/dist/context/utils-plan.d.ts.map +1 -0
  106. package/dist/context/utils-plan.js +8 -0
  107. package/dist/deserializers/api-error.d.ts +5 -0
  108. package/dist/deserializers/api-error.d.ts.map +1 -0
  109. package/dist/deserializers/api-error.js +18 -0
  110. package/dist/deserializers/application-token.d.ts +18 -0
  111. package/dist/deserializers/application-token.d.ts.map +1 -0
  112. package/dist/deserializers/application-token.js +13 -0
  113. package/dist/deserializers/branch.d.ts +3 -0
  114. package/dist/deserializers/branch.d.ts.map +1 -0
  115. package/dist/deserializers/branch.js +8 -0
  116. package/dist/deserializers/environment.d.ts +3 -0
  117. package/dist/deserializers/environment.d.ts.map +1 -0
  118. package/dist/deserializers/environment.js +5 -0
  119. package/dist/deserializers/job.d.ts +3 -0
  120. package/dist/deserializers/job.d.ts.map +1 -0
  121. package/dist/deserializers/job.js +5 -0
  122. package/dist/deserializers/project.d.ts +3 -0
  123. package/dist/deserializers/project.d.ts.map +1 -0
  124. package/dist/deserializers/project.js +11 -0
  125. package/dist/errors/application-error.d.ts +5 -0
  126. package/dist/errors/application-error.d.ts.map +1 -0
  127. package/dist/errors/application-error.js +9 -0
  128. package/dist/errors/application-token/unable-to-create-application-token-error.d.ts +16 -0
  129. package/dist/errors/application-token/unable-to-create-application-token-error.d.ts.map +1 -0
  130. package/dist/errors/application-token/unable-to-create-application-token-error.js +15 -0
  131. package/dist/errors/database/empty-database-error.d.ts +5 -0
  132. package/dist/errors/database/empty-database-error.d.ts.map +1 -0
  133. package/dist/errors/database/empty-database-error.js +5 -0
  134. package/dist/errors/dumper/incompatible-liana-for-update-error.d.ts +13 -0
  135. package/dist/errors/dumper/incompatible-liana-for-update-error.d.ts.map +1 -0
  136. package/dist/errors/dumper/incompatible-liana-for-update-error.js +15 -0
  137. package/dist/errors/dumper/invalid-forest-cli-project-structure-error.d.ts +13 -0
  138. package/dist/errors/dumper/invalid-forest-cli-project-structure-error.d.ts.map +1 -0
  139. package/dist/errors/dumper/invalid-forest-cli-project-structure-error.js +15 -0
  140. package/dist/errors/forest-cli-error.d.ts +26 -0
  141. package/dist/errors/forest-cli-error.d.ts.map +1 -0
  142. package/dist/errors/forest-cli-error.js +26 -0
  143. package/dist/index.d.ts +3 -0
  144. package/dist/index.d.ts.map +1 -0
  145. package/dist/index.js +2 -0
  146. package/dist/renderers/branches.d.ts +14 -0
  147. package/dist/renderers/branches.d.ts.map +1 -0
  148. package/dist/renderers/branches.js +34 -0
  149. package/dist/renderers/defaults.d.ts +18 -0
  150. package/dist/renderers/defaults.d.ts.map +1 -0
  151. package/dist/renderers/defaults.js +20 -0
  152. package/dist/renderers/environment.d.ts +14 -0
  153. package/dist/renderers/environment.d.ts.map +1 -0
  154. package/dist/renderers/environment.js +32 -0
  155. package/dist/renderers/environments.d.ts +14 -0
  156. package/dist/renderers/environments.d.ts.map +1 -0
  157. package/dist/renderers/environments.js +40 -0
  158. package/dist/renderers/project.d.ts +14 -0
  159. package/dist/renderers/project.d.ts.map +1 -0
  160. package/dist/renderers/project.js +30 -0
  161. package/dist/renderers/projects.d.ts +14 -0
  162. package/dist/renderers/projects.d.ts.map +1 -0
  163. package/dist/renderers/projects.js +34 -0
  164. package/dist/serializers/application-token.d.ts +12 -0
  165. package/dist/serializers/application-token.d.ts.map +1 -0
  166. package/dist/serializers/application-token.js +9 -0
  167. package/dist/serializers/deployment-request.d.ts +3 -0
  168. package/dist/serializers/deployment-request.d.ts.map +1 -0
  169. package/dist/serializers/deployment-request.js +5 -0
  170. package/dist/serializers/environment.d.ts +3 -0
  171. package/dist/serializers/environment.d.ts.map +1 -0
  172. package/dist/serializers/environment.js +20 -0
  173. package/dist/serializers/job.d.ts +3 -0
  174. package/dist/serializers/job.d.ts.map +1 -0
  175. package/dist/serializers/job.js +5 -0
  176. package/dist/serializers/project.d.ts +3 -0
  177. package/dist/serializers/project.d.ts.map +1 -0
  178. package/dist/serializers/project.js +17 -0
  179. package/dist/serializers/schema.d.ts +31 -0
  180. package/dist/serializers/schema.d.ts.map +1 -0
  181. package/dist/serializers/schema.js +110 -0
  182. package/dist/services/api.d.ts +29 -0
  183. package/dist/services/api.d.ts.map +1 -0
  184. package/dist/services/api.js +92 -0
  185. package/dist/services/apimap-sorter.d.ts +7 -0
  186. package/dist/services/apimap-sorter.d.ts.map +1 -0
  187. package/dist/services/apimap-sorter.js +83 -0
  188. package/dist/services/application-token.d.ts +22 -0
  189. package/dist/services/application-token.d.ts.map +1 -0
  190. package/dist/services/application-token.js +51 -0
  191. package/dist/services/ask-for-environment.d.ts +3 -0
  192. package/dist/services/ask-for-environment.d.ts.map +1 -0
  193. package/dist/services/ask-for-environment.js +19 -0
  194. package/dist/services/authenticator.d.ts +43 -0
  195. package/dist/services/authenticator.d.ts.map +1 -0
  196. package/dist/services/authenticator.js +172 -0
  197. package/dist/services/branch-manager.d.ts +10 -0
  198. package/dist/services/branch-manager.d.ts.map +1 -0
  199. package/dist/services/branch-manager.js +125 -0
  200. package/dist/services/dumper/dumper.d.ts +62 -0
  201. package/dist/services/dumper/dumper.d.ts.map +1 -0
  202. package/dist/services/dumper/dumper.js +424 -0
  203. package/dist/services/dumper/handlebars/helpers/equal.d.ts +2 -0
  204. package/dist/services/dumper/handlebars/helpers/equal.d.ts.map +1 -0
  205. package/dist/services/dumper/handlebars/helpers/equal.js +3 -0
  206. package/dist/services/dumper/handlebars/helpers/indent.d.ts +2 -0
  207. package/dist/services/dumper/handlebars/helpers/indent.d.ts.map +1 -0
  208. package/dist/services/dumper/handlebars/helpers/indent.js +3 -0
  209. package/dist/services/dumper/handlebars/helpers/is-array.d.ts +2 -0
  210. package/dist/services/dumper/handlebars/helpers/is-array.d.ts.map +1 -0
  211. package/dist/services/dumper/handlebars/helpers/is-array.js +3 -0
  212. package/dist/services/dumper/handlebars/helpers/is-object.d.ts +2 -0
  213. package/dist/services/dumper/handlebars/helpers/is-object.d.ts.map +1 -0
  214. package/dist/services/dumper/handlebars/helpers/is-object.js +3 -0
  215. package/dist/services/dumper/handlebars/helpers/sum.d.ts +2 -0
  216. package/dist/services/dumper/handlebars/helpers/sum.d.ts.map +1 -0
  217. package/dist/services/dumper/handlebars/helpers/sum.js +3 -0
  218. package/dist/services/dumper/handlebars/helpers/wrap-quotes.d.ts +3 -0
  219. package/dist/services/dumper/handlebars/helpers/wrap-quotes.d.ts.map +1 -0
  220. package/dist/services/dumper/handlebars/helpers/wrap-quotes.js +5 -0
  221. package/dist/services/dumper/handlebars/loader.d.ts +2 -0
  222. package/dist/services/dumper/handlebars/loader.d.ts.map +1 -0
  223. package/dist/services/dumper/handlebars/loader.js +10 -0
  224. package/dist/services/dumper/handlebars/partials/render-nested.d.ts +2 -0
  225. package/dist/services/dumper/handlebars/partials/render-nested.d.ts.map +1 -0
  226. package/{src → dist}/services/dumper/handlebars/partials/render-nested.js +3 -7
  227. package/{src → dist}/services/dumper/templates/app/Dockerfile.hbs +0 -0
  228. package/{src → dist}/services/dumper/templates/app/app.hbs +0 -0
  229. package/{src → dist}/services/dumper/templates/app/config/databases.hbs +0 -0
  230. package/{src → dist}/services/dumper/templates/app/docker-compose.hbs +0 -0
  231. package/{src → dist}/services/dumper/templates/app/dockerignore.hbs +0 -0
  232. package/{src → dist}/services/dumper/templates/app/env.hbs +0 -0
  233. package/{src → dist}/services/dumper/templates/app/forest/collection.hbs +0 -0
  234. package/{src → dist}/services/dumper/templates/app/gitignore.hbs +0 -0
  235. package/{src → dist}/services/dumper/templates/app/middlewares/forestadmin.hbs +0 -0
  236. package/{src → dist}/services/dumper/templates/app/middlewares/welcome.hbs +0 -0
  237. package/{src → dist}/services/dumper/templates/app/models/index.hbs +0 -0
  238. package/{src → dist}/services/dumper/templates/app/models/mongo-model.hbs +0 -0
  239. package/{src → dist}/services/dumper/templates/app/models/sequelize-model.hbs +0 -0
  240. package/{src → dist}/services/dumper/templates/app/public/favicon.png +0 -0
  241. package/{src → dist}/services/dumper/templates/app/routes/route.hbs +0 -0
  242. package/{src → dist}/services/dumper/templates/app/server.hbs +0 -0
  243. package/{src → dist}/services/dumper/templates/app/views/index.hbs +0 -0
  244. package/dist/services/environment-manager.d.ts +19 -0
  245. package/dist/services/environment-manager.d.ts.map +1 -0
  246. package/dist/services/environment-manager.js +113 -0
  247. package/dist/services/init-manager.d.ts +8 -0
  248. package/dist/services/init-manager.d.ts.map +1 -0
  249. package/dist/services/init-manager.js +156 -0
  250. package/dist/services/job-state-checker.d.ts +7 -0
  251. package/dist/services/job-state-checker.d.ts.map +1 -0
  252. package/dist/services/job-state-checker.js +45 -0
  253. package/dist/services/logger.d.ts +36 -0
  254. package/dist/services/logger.d.ts.map +1 -0
  255. package/dist/services/logger.js +97 -0
  256. package/dist/services/oidc/authenticator.d.ts +37 -0
  257. package/dist/services/oidc/authenticator.d.ts.map +1 -0
  258. package/dist/services/oidc/authenticator.js +85 -0
  259. package/dist/services/oidc/error.d.ts +11 -0
  260. package/dist/services/oidc/error.d.ts.map +1 -0
  261. package/dist/services/oidc/error.js +28 -0
  262. package/dist/services/project-manager.d.ts +11 -0
  263. package/dist/services/project-manager.d.ts.map +1 -0
  264. package/dist/services/project-manager.js +72 -0
  265. package/dist/services/projects/create/command-generate-config-getter.d.ts +15 -0
  266. package/dist/services/projects/create/command-generate-config-getter.d.ts.map +1 -0
  267. package/dist/services/projects/create/command-generate-config-getter.js +51 -0
  268. package/dist/services/projects/create/project-creator.d.ts +108 -0
  269. package/dist/services/projects/create/project-creator.d.ts.map +1 -0
  270. package/dist/services/projects/create/project-creator.js +80 -0
  271. package/dist/services/prompter/abstract-prompter.d.ts +7 -0
  272. package/dist/services/prompter/abstract-prompter.d.ts.map +1 -0
  273. package/dist/services/prompter/abstract-prompter.js +13 -0
  274. package/dist/services/prompter/application-prompts.d.ts +12 -0
  275. package/dist/services/prompter/application-prompts.d.ts.map +1 -0
  276. package/dist/services/prompter/application-prompts.js +60 -0
  277. package/dist/services/prompter/database-prompts.d.ts +23 -0
  278. package/dist/services/prompter/database-prompts.d.ts.map +1 -0
  279. package/dist/services/prompter/database-prompts.js +193 -0
  280. package/dist/services/prompter/general-prompter.d.ts +17 -0
  281. package/dist/services/prompter/general-prompter.d.ts.map +1 -0
  282. package/dist/services/prompter/general-prompter.js +49 -0
  283. package/dist/services/prompter/project-prompts.d.ts +11 -0
  284. package/dist/services/prompter/project-prompts.d.ts.map +1 -0
  285. package/dist/services/prompter/project-prompts.js +39 -0
  286. package/dist/services/prompter/prompter-error.d.ts +8 -0
  287. package/dist/services/prompter/prompter-error.d.ts.map +1 -0
  288. package/dist/services/prompter/prompter-error.js +10 -0
  289. package/dist/services/schema/schema-service.d.ts +41 -0
  290. package/dist/services/schema/schema-service.d.ts.map +1 -0
  291. package/dist/services/schema/schema-service.js +123 -0
  292. package/dist/services/schema/update/analyzer/database-analyzer.d.ts +17 -0
  293. package/dist/services/schema/update/analyzer/database-analyzer.d.ts.map +1 -0
  294. package/dist/services/schema/update/analyzer/database-analyzer.js +53 -0
  295. package/dist/services/schema/update/analyzer/mongo-collections-analyzer.d.ts +78 -0
  296. package/dist/services/schema/update/analyzer/mongo-collections-analyzer.d.ts.map +1 -0
  297. package/dist/services/schema/update/analyzer/mongo-collections-analyzer.js +292 -0
  298. package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.d.ts +13 -0
  299. package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.d.ts.map +1 -0
  300. package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.js +183 -0
  301. package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.d.ts +3 -0
  302. package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.d.ts.map +1 -0
  303. package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.js +40 -0
  304. package/dist/services/schema/update/analyzer/mongo-references-analyzer.d.ts +3 -0
  305. package/dist/services/schema/update/analyzer/mongo-references-analyzer.d.ts.map +1 -0
  306. package/dist/services/schema/update/analyzer/mongo-references-analyzer.js +36 -0
  307. package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.d.ts +9 -0
  308. package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.d.ts.map +1 -0
  309. package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.js +54 -0
  310. package/dist/services/schema/update/analyzer/sequelize-column-type-getter.d.ts +8 -0
  311. package/dist/services/schema/update/analyzer/sequelize-column-type-getter.d.ts.map +1 -0
  312. package/dist/services/schema/update/analyzer/sequelize-column-type-getter.js +137 -0
  313. package/dist/services/schema/update/analyzer/sequelize-default-value.d.ts +18 -0
  314. package/dist/services/schema/update/analyzer/sequelize-default-value.d.ts.map +1 -0
  315. package/dist/services/schema/update/analyzer/sequelize-default-value.js +117 -0
  316. package/dist/services/schema/update/analyzer/sequelize-table-constraints-getter.d.ts +7 -0
  317. package/dist/services/schema/update/analyzer/sequelize-table-constraints-getter.d.ts.map +1 -0
  318. package/{src → dist}/services/schema/update/analyzer/sequelize-table-constraints-getter.js +28 -34
  319. package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.d.ts +3 -0
  320. package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.d.ts.map +1 -0
  321. package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.js +383 -0
  322. package/dist/services/schema/update/database.d.ts +23 -0
  323. package/dist/services/schema/update/database.d.ts.map +1 -0
  324. package/dist/services/schema/update/database.js +143 -0
  325. package/dist/services/schema-sender.d.ts +25 -0
  326. package/dist/services/schema-sender.d.ts.map +1 -0
  327. package/dist/services/schema-sender.js +56 -0
  328. package/dist/services/spinner.d.ts +35 -0
  329. package/dist/services/spinner.d.ts.map +1 -0
  330. package/dist/services/spinner.js +114 -0
  331. package/dist/services/with-current-project.d.ts +3 -0
  332. package/dist/services/with-current-project.d.ts.map +1 -0
  333. package/dist/services/with-current-project.js +39 -0
  334. package/dist/utils/database-url.d.ts +2 -0
  335. package/dist/utils/database-url.d.ts.map +1 -0
  336. package/dist/utils/database-url.js +28 -0
  337. package/dist/utils/directory-existence-checker.d.ts +7 -0
  338. package/dist/utils/directory-existence-checker.d.ts.map +1 -0
  339. package/dist/utils/directory-existence-checker.js +18 -0
  340. package/dist/utils/error-handler.d.ts +24 -0
  341. package/dist/utils/error-handler.d.ts.map +1 -0
  342. package/dist/utils/error-handler.js +55 -0
  343. package/dist/utils/error.d.ts +2 -0
  344. package/dist/utils/error.d.ts.map +1 -0
  345. package/dist/utils/error.js +20 -0
  346. package/dist/utils/event-sender.d.ts +17 -0
  347. package/dist/utils/event-sender.d.ts.map +1 -0
  348. package/dist/utils/event-sender.js +78 -0
  349. package/dist/utils/fields.d.ts +2 -0
  350. package/dist/utils/fields.d.ts.map +1 -0
  351. package/dist/utils/fields.js +13 -0
  352. package/dist/utils/key-generator.d.ts +11 -0
  353. package/dist/utils/key-generator.d.ts.map +1 -0
  354. package/dist/utils/key-generator.js +14 -0
  355. package/dist/utils/messages.d.ts +6 -0
  356. package/dist/utils/messages.d.ts.map +1 -0
  357. package/dist/utils/messages.js +8 -0
  358. package/dist/utils/mongo-collections.d.ts +5 -0
  359. package/dist/utils/mongo-collections.d.ts.map +1 -0
  360. package/dist/utils/mongo-collections.js +32 -0
  361. package/dist/utils/mongo-primitive-type.d.ts +14 -0
  362. package/dist/utils/mongo-primitive-type.d.ts.map +1 -0
  363. package/dist/utils/mongo-primitive-type.js +40 -0
  364. package/dist/utils/strings.d.ts +6 -0
  365. package/dist/utils/strings.d.ts.map +1 -0
  366. package/dist/utils/strings.js +44 -0
  367. package/dist/utils/terminator.d.ts +22 -0
  368. package/dist/utils/terminator.d.ts.map +1 -0
  369. package/dist/utils/terminator.js +33 -0
  370. package/dist/utils/to-valid-package-name.d.ts +3 -0
  371. package/dist/utils/to-valid-package-name.d.ts.map +1 -0
  372. package/dist/utils/to-valid-package-name.js +21 -0
  373. package/oclif.manifest.json +1 -1
  374. package/package.json +17 -8
  375. package/src/abstract-authenticated-command.js +0 -46
  376. package/src/abstract-command.js +0 -27
  377. package/src/commands/branch.js +0 -136
  378. package/src/commands/deploy.js +0 -90
  379. package/src/commands/environments/copy-layout.js +0 -116
  380. package/src/commands/environments/create.js +0 -62
  381. package/src/commands/environments/delete.js +0 -81
  382. package/src/commands/environments/get.js +0 -48
  383. package/src/commands/environments/reset.js +0 -76
  384. package/src/commands/environments/update.js +0 -46
  385. package/src/commands/environments.js +0 -41
  386. package/src/commands/init.js +0 -169
  387. package/src/commands/login.js +0 -34
  388. package/src/commands/logout.js +0 -18
  389. package/src/commands/projects/create.js +0 -262
  390. package/src/commands/projects/get.js +0 -53
  391. package/src/commands/projects.js +0 -36
  392. package/src/commands/push.js +0 -75
  393. package/src/commands/schema/apply.js +0 -140
  394. package/src/commands/schema/update.js +0 -70
  395. package/src/commands/set-origin.js +0 -59
  396. package/src/commands/switch.js +0 -117
  397. package/src/commands/user.js +0 -44
  398. package/src/context/command-project-create-plan.js +0 -11
  399. package/src/context/command-projects-common-plan.js +0 -65
  400. package/src/context/command-schema-update-command-plan.js +0 -4
  401. package/src/context/dependencies-plan.js +0 -21
  402. package/src/context/env-plan.js +0 -27
  403. package/src/context/plan.js +0 -12
  404. package/src/context/process-plan.js +0 -3
  405. package/src/context/renderers-plan.js +0 -7
  406. package/src/context/serializers-plan.js +0 -8
  407. package/src/context/services-plan.js +0 -8
  408. package/src/context/static.js +0 -19
  409. package/src/context/utils-plan.js +0 -7
  410. package/src/deserializers/api-error.js +0 -21
  411. package/src/deserializers/application-token.js +0 -15
  412. package/src/deserializers/branch.js +0 -8
  413. package/src/deserializers/environment.js +0 -5
  414. package/src/deserializers/job.js +0 -5
  415. package/src/deserializers/project.js +0 -11
  416. package/src/errors/application-error.js +0 -9
  417. package/src/errors/application-token/unable-to-create-application-token-error.js +0 -16
  418. package/src/errors/database/empty-database-error.js +0 -5
  419. package/src/errors/dumper/incompatible-liana-for-update-error.js +0 -16
  420. package/src/errors/dumper/invalid-forest-cli-project-structure-error.js +0 -16
  421. package/src/errors/forest-cli-error.js +0 -32
  422. package/src/index.js +0 -1
  423. package/src/renderers/branches.js +0 -45
  424. package/src/renderers/defaults.js +0 -19
  425. package/src/renderers/environment.js +0 -51
  426. package/src/renderers/environments.js +0 -51
  427. package/src/renderers/project.js +0 -45
  428. package/src/renderers/projects.js +0 -45
  429. package/src/serializers/application-token.js +0 -11
  430. package/src/serializers/deployment-request.js +0 -5
  431. package/src/serializers/environment.js +0 -20
  432. package/src/serializers/job.js +0 -5
  433. package/src/serializers/project.js +0 -17
  434. package/src/serializers/schema.js +0 -116
  435. package/src/services/api.js +0 -110
  436. package/src/services/apimap-sorter.js +0 -104
  437. package/src/services/application-token.js +0 -56
  438. package/src/services/ask-for-environment.js +0 -24
  439. package/src/services/authenticator.js +0 -187
  440. package/src/services/branch-manager.js +0 -169
  441. package/src/services/dumper/dumper.js +0 -503
  442. package/src/services/dumper/handlebars/helpers/equal.js +0 -3
  443. package/src/services/dumper/handlebars/helpers/indent.js +0 -3
  444. package/src/services/dumper/handlebars/helpers/is-array.js +0 -3
  445. package/src/services/dumper/handlebars/helpers/is-object.js +0 -3
  446. package/src/services/dumper/handlebars/helpers/sum.js +0 -3
  447. package/src/services/dumper/handlebars/helpers/wrap-quotes.js +0 -7
  448. package/src/services/dumper/handlebars/loader.js +0 -10
  449. package/src/services/environment-manager.js +0 -139
  450. package/src/services/init-manager.js +0 -183
  451. package/src/services/job-state-checker.js +0 -57
  452. package/src/services/logger.js +0 -125
  453. package/src/services/oidc/authenticator.js +0 -109
  454. package/src/services/oidc/error.js +0 -32
  455. package/src/services/project-manager.js +0 -89
  456. package/src/services/projects/create/command-generate-config-getter.js +0 -61
  457. package/src/services/projects/create/project-creator.js +0 -89
  458. package/src/services/prompter/abstract-prompter.js +0 -13
  459. package/src/services/prompter/application-prompts.js +0 -63
  460. package/src/services/prompter/database-prompts.js +0 -208
  461. package/src/services/prompter/general-prompter.js +0 -61
  462. package/src/services/prompter/project-prompts.js +0 -47
  463. package/src/services/prompter/prompter-error.js +0 -10
  464. package/src/services/schema/schema-service.js +0 -154
  465. package/src/services/schema/update/analyzer/database-analyzer.js +0 -64
  466. package/src/services/schema/update/analyzer/mongo-collections-analyzer.js +0 -344
  467. package/src/services/schema/update/analyzer/mongo-embedded-analyzer.js +0 -226
  468. package/src/services/schema/update/analyzer/mongo-hasmany-analyzer.js +0 -55
  469. package/src/services/schema/update/analyzer/mongo-references-analyzer.js +0 -51
  470. package/src/services/schema/update/analyzer/mysql-table-constraints-getter.js +0 -59
  471. package/src/services/schema/update/analyzer/sequelize-column-type-getter.js +0 -147
  472. package/src/services/schema/update/analyzer/sequelize-default-value.js +0 -122
  473. package/src/services/schema/update/analyzer/sequelize-tables-analyzer.js +0 -529
  474. package/src/services/schema/update/database.js +0 -160
  475. package/src/services/schema-sender.js +0 -55
  476. package/src/services/spinner.js +0 -130
  477. package/src/services/with-current-project.js +0 -41
  478. package/src/utils/database-url.js +0 -33
  479. package/src/utils/directory-existence-checker.js +0 -17
  480. package/src/utils/error-handler.js +0 -63
  481. package/src/utils/error.js +0 -21
  482. package/src/utils/event-sender.js +0 -80
  483. package/src/utils/fields.js +0 -14
  484. package/src/utils/key-generator.js +0 -18
  485. package/src/utils/messages.js +0 -7
  486. package/src/utils/mongo-collections.js +0 -35
  487. package/src/utils/mongo-primitive-type.js +0 -44
  488. package/src/utils/strings.js +0 -49
  489. package/src/utils/terminator.js +0 -38
  490. package/src/utils/to-valid-package-name.js +0 -24
@@ -1,64 +0,0 @@
1
- const EmptyDatabaseError = require('../../../../errors/database/empty-database-error');
2
-
3
- module.exports = class DatabaseAnalyzer {
4
- constructor({
5
- assertPresent,
6
- mongoAnalyzer,
7
- sequelizeAnalyzer,
8
- terminator,
9
- }) {
10
- assertPresent({
11
- mongoAnalyzer,
12
- sequelizeAnalyzer,
13
- terminator,
14
- });
15
- this.mongoAnalyzer = mongoAnalyzer;
16
- this.sequelizeAnalyzer = sequelizeAnalyzer;
17
- this.terminator = terminator;
18
- }
19
-
20
- async reportEmptyDatabase(orm, dialect) {
21
- const logs = [`Your database looks empty! Please create some ${orm === 'mongoose' ? 'collections' : 'tables'} before running the command.`];
22
- if (orm === 'sequelize') {
23
- logs.push('If not, check whether you are using a custom database schema (use in that case the --schema option).');
24
- }
25
- return this.terminator.terminate(1, {
26
- logs,
27
- errorCode: 'database_empty',
28
- errorMessage: 'Your database is empty.',
29
- context: {
30
- orm,
31
- dialect,
32
- },
33
- });
34
- }
35
-
36
- async _analyze(analyze, databaseConnection, config, allowWarning) {
37
- return analyze(databaseConnection, config, allowWarning)
38
- .catch((error) => {
39
- if (error instanceof EmptyDatabaseError) {
40
- return this.reportEmptyDatabase(error.details.orm, error.details.dialect);
41
- }
42
- throw error;
43
- });
44
- }
45
-
46
- async analyzeMongoDb(databaseConnection, config, allowWarning) {
47
- const analyze = this.mongoAnalyzer.analyzeMongoCollections.bind(this.mongoAnalyzer);
48
- return this._analyze(analyze, databaseConnection.db(), config, allowWarning);
49
- }
50
-
51
- async analyze(databaseConnection, config, allowWarning) {
52
- let analyze;
53
- if (config.dbDialect === 'mongodb') {
54
- analyze = this.mongoAnalyzer.analyzeMongoCollectionsWithoutProgressBar.bind(
55
- this.mongoAnalyzer,
56
- );
57
-
58
- databaseConnection = databaseConnection.db();
59
- } else {
60
- analyze = this.sequelizeAnalyzer;
61
- }
62
- return this._analyze(analyze, databaseConnection, config, allowWarning);
63
- }
64
- };
@@ -1,344 +0,0 @@
1
- const P = require('bluebird');
2
- const { ObjectId } = require('mongodb');
3
-
4
- const EmptyDatabaseError = require('../../../../errors/database/empty-database-error');
5
-
6
- const {
7
- getMongooseSchema,
8
- hasEmbeddedTypes,
9
- } = require('../../../../services/schema/update/analyzer/mongo-embedded-analyzer');
10
-
11
- const MAP_REDUCE_ERROR_STRING = 'MapReduceError';
12
-
13
- // NOTICE: This code runs on the MongoDB side (mapReduce feature) or locally
14
- // when the the JS is disabled.
15
- // The supported JS version is not the same than elsewhere.
16
- // The code used here must work with MongoDB lower version supported.
17
- /* eslint-disable vars-on-top, no-var, no-undef, no-restricted-syntax,
18
- sonarjs/cognitive-complexity, no-use-before-define */
19
- /* istanbul ignore next */
20
- function mapCollection(keys = this, emitFunction, store) {
21
- // this block is to inject the emit function when this code is running locally
22
- var emitAction;
23
- if (emitFunction && store) {
24
- emitAction = function emit(key, value) {
25
- emitFunction(key, value, store);
26
- };
27
- } else {
28
- // when the emit is defined by mongodb
29
- emitAction = emit;
30
- }
31
-
32
- function allItemsAreObjectIDs(array) {
33
- if (!array.length) return false;
34
- var itemToCheckCount = array.length > 3 ? 3 : array.length;
35
- var arrayOfObjectIDs = true;
36
- for (var i = 0; i < itemToCheckCount; i += 1) {
37
- if (!(array[i] instanceof ObjectId)) {
38
- arrayOfObjectIDs = false;
39
- break;
40
- }
41
- }
42
- return arrayOfObjectIDs;
43
- }
44
-
45
- for (var key in keys) {
46
- if (keys[key] instanceof ObjectId && key !== '_id') {
47
- emitAction(key, 'Mongoose.Schema.Types.ObjectId');
48
- } else if (keys[key] instanceof Date) {
49
- emitAction(key, 'Date');
50
- } else if (typeof keys[key] === 'boolean') {
51
- emitAction(key, 'Boolean');
52
- } else if (typeof keys[key] === 'string') {
53
- emitAction(key, 'String');
54
- } else if (typeof keys[key] === 'number' && key !== '__v') {
55
- emitAction(key, 'Number');
56
- } else if (typeof keys[key] === 'object') {
57
- if (Array.isArray(keys[key]) && allItemsAreObjectIDs(keys[key])) {
58
- emitAction(key, '[Mongoose.Schema.Types.ObjectId]');
59
- } else if (key !== '_id') {
60
- var analysis = getMongooseSchema(keys[key]);
61
- if (analysis) {
62
- // Notice: Wrap the analysis of embedded in a recognizable object for further treatment
63
- emitAction(key, { type: 'embedded', schema: analysis });
64
- }
65
- }
66
- }
67
- }
68
- }
69
- /* eslint-enable */
70
-
71
- /* istanbul ignore next */
72
- function reduceCollection(key, analyses) {
73
- if (hasEmbeddedTypes(analyses)) {
74
- const formattedAnalysis = { type: 'embedded', schemas: [] };
75
- analyses.forEach((analysis) => {
76
- if (analysis.type === 'embedded') {
77
- formattedAnalysis.schemas.push(analysis.schema);
78
- } else {
79
- formattedAnalysis.schemas.push(analysis);
80
- }
81
- });
82
- return formattedAnalysis;
83
- }
84
-
85
- return analyses.length ? analyses[0] : null;
86
- }
87
-
88
- /* eslint-disable no-shadow */
89
- class MongoCollectionsAnalyzer {
90
- constructor({
91
- assertPresent, logger, detectReferences,
92
- applyReferences, detectHasMany, applyHasMany,
93
- isUnderscored, getMongooseTypeFromValue,
94
- isOfMongooseType, getMongooseArraySchema,
95
- getMongooseEmbeddedSchema, getMongooseSchema,
96
- haveSameEmbeddedType, hasEmbeddedTypes,
97
- mergeAnalyzedSchemas, isSystemCollection,
98
- getCollectionName, mapCollection, reduceCollection,
99
- makeProgressBar,
100
- }) {
101
- assertPresent({
102
- logger,
103
- detectReferences,
104
- applyReferences,
105
- detectHasMany,
106
- applyHasMany,
107
- isUnderscored,
108
- getMongooseTypeFromValue,
109
- isOfMongooseType,
110
- getMongooseArraySchema,
111
- getMongooseEmbeddedSchema,
112
- getMongooseSchema,
113
- haveSameEmbeddedType,
114
- hasEmbeddedTypes,
115
- mergeAnalyzedSchemas,
116
- isSystemCollection,
117
- getCollectionName,
118
- mapCollection,
119
- reduceCollection,
120
- makeProgressBar,
121
- });
122
-
123
- this.logger = logger;
124
- this.detectReferences = detectReferences;
125
- this.applyReferences = applyReferences;
126
- this.detectHasMany = detectHasMany;
127
- this.applyHasMany = applyHasMany;
128
- this.isUnderscored = isUnderscored;
129
- this.getCollectionName = getCollectionName;
130
- this.isSystemCollection = isSystemCollection;
131
- this.mergeAnalyzedSchemas = mergeAnalyzedSchemas;
132
- this.mapCollection = mapCollection;
133
- this.reduceCollection = reduceCollection;
134
- this.makeProgressBar = makeProgressBar;
135
-
136
- this.restoreDefaultState();
137
-
138
- this.mapReduceOptions = {
139
- out: { inline: 1 },
140
- limit: 100,
141
- scope: {
142
- getMongooseArraySchema,
143
- getMongooseEmbeddedSchema,
144
- getMongooseSchema,
145
- getMongooseTypeFromValue,
146
- haveSameEmbeddedType,
147
- hasEmbeddedTypes,
148
- isOfMongooseType,
149
- },
150
- };
151
- }
152
-
153
- restoreDefaultState() {
154
- this.isProgressBarDisplay = true;
155
- }
156
-
157
- mergeField(field) {
158
- if (field.value && field.value.type === 'embedded') {
159
- const schemas = field.value.schemas ? field.value.schemas : [field.value.schema];
160
- const mergedSchema = this.mergeAnalyzedSchemas(schemas);
161
-
162
- return {
163
- name: field._id,
164
- type: mergedSchema,
165
- };
166
- }
167
- return {
168
- name: field._id,
169
- type: field.value,
170
- };
171
- }
172
-
173
- mapReduceErrors(resolve, reject) {
174
- return (err, results) => {
175
- if (err) {
176
- if (err.message && (err.message.startsWith('CMD_NOT_ALLOWED') || err.message.startsWith('MapReduce'))) {
177
- return resolve(MAP_REDUCE_ERROR_STRING);
178
- }
179
- if (err.codeName && err.codeName === 'CommandNotSupportedOnView') {
180
- // NOTICE: Silently ignore views errors (e.g do not import views).
181
- // See: https://github.com/ForestAdmin/lumber/issues/265
182
- return resolve([]);
183
- }
184
- return reject(err);
185
- }
186
-
187
- return resolve(results.map((result) => this.mergeField(result)));
188
- };
189
- }
190
-
191
- static emit(attributeName, attributesType, fieldsTypes) {
192
- if (fieldsTypes[attributeName]) {
193
- fieldsTypes[attributeName].push(attributesType);
194
- } else {
195
- fieldsTypes[attributeName] = [attributesType];
196
- }
197
- }
198
-
199
- getFields(fieldWithTypes) {
200
- const keys = Object.keys(fieldWithTypes);
201
- return keys.reduce((fields, key) => {
202
- const field = this.mergeField({
203
- _id: key,
204
- value: this.reduceCollection(key, fieldWithTypes[key]),
205
- });
206
- fields.push(field);
207
- return fields;
208
- }, []);
209
- }
210
-
211
- // M0 free clusters and M2/M5 shared clusters do not support server-side JavaScript.
212
- // Also, JS can be disabled on the mongodb instance.
213
- // https://docs.atlas.mongodb.com/reference/free-shared-limitations/
214
- // https://docs.mongodb.com/manual/core/server-side-javascript/
215
- async analyzeMongoCollectionLocally(databaseConnection, collectionName) {
216
- const collection = databaseConnection.collection(collectionName);
217
- const analyze = await this.analyzeCollectionAndDisplayProgressBarIfIsAllow(
218
- collection, collectionName,
219
- );
220
- return this.getFields(analyze);
221
- }
222
-
223
- analyzeMongoCollectionRemotely(databaseConnection, collectionName) {
224
- return new Promise((resolve, reject) => {
225
- databaseConnection.collection(collectionName).mapReduce(
226
- this.mapCollection,
227
- this.reduceCollection,
228
- this.mapReduceOptions,
229
- this.mapReduceErrors(resolve, reject),
230
- );
231
- });
232
- }
233
-
234
- buildSchema(fields) {
235
- return {
236
- fields,
237
- references: [],
238
- primaryKeys: ['_id'],
239
- options: {
240
- timestamps: this.isUnderscored(fields),
241
- },
242
- };
243
- }
244
-
245
- async applyRelationships(databaseConnection, fields, collectionName) {
246
- const references = await this.detectReferences(databaseConnection, fields, collectionName);
247
- this.applyReferences(fields, references);
248
- const hasMany = await this.detectHasMany(databaseConnection, fields, collectionName);
249
- this.applyHasMany(fields, hasMany);
250
- return fields;
251
- }
252
-
253
- fetchByChunkFunction(collection, numberOfDocumentAllowed) {
254
- return async (fieldsTypes, index) => {
255
- const minIndex = index * numberOfDocumentAllowed;
256
- const options = { minIndex, limit: numberOfDocumentAllowed };
257
- const documents = await collection.find({}, options).toArray();
258
- documents.map((document) =>
259
- this.mapCollection(document, MongoCollectionsAnalyzer.emit, fieldsTypes));
260
- return fieldsTypes;
261
- };
262
- }
263
-
264
- async analyzeCollectionAndDisplayProgressBarIfIsAllow(collection, collectionName) {
265
- const countDocuments = await collection.countDocuments();
266
- if (countDocuments === 0) {
267
- return {};
268
- }
269
-
270
- const numberOfDocumentAllowed = 50;
271
- const countIterations = Math.ceil(countDocuments / numberOfDocumentAllowed);
272
-
273
- let fetchFunction = this.fetchByChunkFunction(collection, numberOfDocumentAllowed);
274
- if (this.isProgressBarDisplay) {
275
- const bar = this.makeProgressBar(
276
- `Analysing the **${collectionName}** collection`,
277
- countIterations,
278
- );
279
- bar.update(0);
280
-
281
- fetchFunction = async (fieldTypes, index) => {
282
- const wrapper = this.fetchByChunkFunction(collection, numberOfDocumentAllowed);
283
- await wrapper(fieldTypes, index);
284
- bar.tick();
285
- return fieldTypes;
286
- };
287
- }
288
-
289
- const iterations = [...Array(countIterations).keys()];
290
- return P.reduce(iterations, fetchFunction, {});
291
- }
292
-
293
- async analyzeMongoCollectionsWithoutProgressBar(databaseConnection) {
294
- this.isProgressBarDisplay = false;
295
- return this.analyzeMongoCollections(databaseConnection);
296
- }
297
-
298
- async analyzeMongoCollections(databaseConnection) {
299
- const collections = await databaseConnection.collections();
300
- if (collections.length === 0) {
301
- this.restoreDefaultState();
302
- throw new EmptyDatabaseError('no collections found', {
303
- orm: 'mongoose',
304
- dialect: 'mongodb',
305
- });
306
- }
307
- const collectionsInfos = await databaseConnection.listCollections().toArray();
308
- const isView = (name) => collectionsInfos.find(
309
- (info) => !!info.options.viewOn && name === info.name,
310
- );
311
-
312
- let isMongodbInstanceSupportJs = true;
313
- const schema = await P.reduce(collections, async (schema, collection) => {
314
- const collectionName = this.getCollectionName(collection);
315
-
316
- // Ignore system collections and collection without a valid name.
317
- if (!collectionName || this.isSystemCollection(collection)) {
318
- return schema;
319
- }
320
- let analysis = [];
321
- if (isMongodbInstanceSupportJs && !isView(collectionName)) {
322
- analysis = await this.analyzeMongoCollectionRemotely(databaseConnection, collectionName);
323
- if (analysis === MAP_REDUCE_ERROR_STRING) {
324
- isMongodbInstanceSupportJs = false;
325
- this.logger.warn('The analysis is running locally instead of in the db instance because your instance does not support javascript.'
326
- + ' This action can takes a bit of time because it fetches all the collections.');
327
- }
328
- }
329
-
330
- if (!isMongodbInstanceSupportJs && !isView(collectionName)) {
331
- analysis = await this.analyzeMongoCollectionLocally(databaseConnection, collectionName);
332
- }
333
-
334
- analysis = await this.applyRelationships(databaseConnection, analysis, collectionName);
335
- schema[collectionName] = this.buildSchema(analysis);
336
- return schema;
337
- }, {});
338
-
339
- this.restoreDefaultState();
340
- return schema;
341
- }
342
- }
343
-
344
- module.exports = { MongoCollectionsAnalyzer, mapCollection, reduceCollection };
@@ -1,226 +0,0 @@
1
- const {
2
- getMongooseTypeFromValue,
3
- isOfMongooseType,
4
- } = require('../../../../utils/mongo-primitive-type');
5
-
6
- /* eslint-disable vars-on-top, no-var, no-use-before-define, no-param-reassign */
7
- /* istanbul ignore next */
8
- function getMongooseEmbeddedSchema(embeddedObject, handleId = false) {
9
- if (!embeddedObject) {
10
- return null;
11
- }
12
-
13
- const schema = {};
14
- var keysToAnalyse = Object.keys(embeddedObject);
15
-
16
- if (!handleId) {
17
- keysToAnalyse = keysToAnalyse.filter((value) => value !== '_id');
18
- }
19
-
20
- keysToAnalyse.forEach((key) => {
21
- const analysis = getMongooseSchema(embeddedObject[key]);
22
-
23
- if (analysis) {
24
- schema[key] = analysis;
25
- }
26
- });
27
-
28
- if (Object.keys(schema).length === 0) {
29
- return null;
30
- }
31
-
32
- return schema;
33
- }
34
-
35
- /* istanbul ignore next */
36
- function getMongooseArraySchema(arrayValue) {
37
- if (!arrayValue || arrayValue.length === 0 || !Array.isArray(arrayValue)) {
38
- return null;
39
- }
40
-
41
- const analyses = [];
42
-
43
- arrayValue.forEach((value) => {
44
- const analysis = getMongooseSchema(value, true);
45
-
46
- if (analysis) {
47
- analyses.push(analysis);
48
- }
49
- });
50
-
51
- return analyses.length ? analyses : null;
52
- }
53
-
54
- /* istanbul ignore next */
55
- function getMongooseSchema(value, handleId = false) {
56
- if (isOfMongooseType(value)) {
57
- return getMongooseTypeFromValue(value);
58
- }
59
-
60
- if (Array.isArray(value)) {
61
- return getMongooseArraySchema(value);
62
- }
63
-
64
- if (typeof value === 'object') {
65
- return getMongooseEmbeddedSchema(value, handleId);
66
- }
67
-
68
- return null;
69
- }
70
-
71
- /* istanbul ignore next */
72
- function hasEmbeddedTypes(analyses) {
73
- if (!analyses || !analyses.length) {
74
- return false;
75
- }
76
- return analyses.filter((analysis) => analysis.type === 'embedded').length > 0;
77
- }
78
-
79
- function haveSameEmbeddedType(type1, type2) {
80
- return typeof type1 === typeof type2
81
- && Array.isArray(type1) === Array.isArray(type2);
82
- }
83
-
84
- function areSchemaTypesMixed(type1, type2) {
85
- if (type1 === 'Object' || type2 === 'Object') {
86
- return true;
87
- }
88
-
89
- if (type1 == null || type2 == null) {
90
- return false;
91
- }
92
-
93
- if (typeof type1 === 'object' || typeof type2 === 'object') {
94
- return !haveSameEmbeddedType(type1, type2);
95
- }
96
-
97
- return type1 !== type2;
98
- }
99
-
100
- function areAnalysesSameEmbeddedType(arrayOfAnalysis) {
101
- if (!Array.isArray(arrayOfAnalysis) || !arrayOfAnalysis.length) {
102
- return false;
103
- }
104
-
105
- const firstAnalysis = arrayOfAnalysis[0];
106
-
107
- for (var i = 1; i < arrayOfAnalysis.length; i += 1) {
108
- if (!haveSameEmbeddedType(arrayOfAnalysis[i], firstAnalysis)) {
109
- return false;
110
- }
111
- }
112
-
113
- return true;
114
- }
115
-
116
- function addMongooseType(type, schema, currentKey) {
117
- if (!schema[currentKey]) {
118
- schema[currentKey] = type;
119
- } else if (areSchemaTypesMixed(type, schema[currentKey])) {
120
- schema[currentKey] = 'Object';
121
- }
122
- }
123
-
124
- function detectSubDocumentsIdUsage(schema1, schema2) {
125
- if (schema1._id === 'ambiguous' || schema2._id === 'ambiguous') {
126
- return 'ambiguous';
127
- }
128
-
129
- if (schema1._id && schema2._id) {
130
- return true;
131
- }
132
-
133
- if (!schema1._id && !schema2._id) {
134
- return false;
135
- }
136
-
137
- return 'ambiguous';
138
- }
139
-
140
- function iterateOnTypeKeysToAddNestedSchemas(type, schema, isArray) {
141
- Object.keys(type).forEach((key) => {
142
- addNestedSchemaToParentSchema(type[key], schema, isArray ? 0 : key);
143
- });
144
- }
145
-
146
- function setIdToSchema(type, schema) {
147
- const idUsage = detectSubDocumentsIdUsage(schema, type);
148
-
149
- if (['ambiguous', false].includes(idUsage)) {
150
- schema._id = idUsage;
151
- delete type._id;
152
- }
153
- }
154
-
155
- function addObjectSchema(type, parentSchema, currentKey) {
156
- const isTypeAnArray = Array.isArray(type);
157
-
158
- if (parentSchema[currentKey] !== undefined) {
159
- if (areSchemaTypesMixed(parentSchema[currentKey], type)) {
160
- parentSchema[currentKey] = 'Object';
161
- } else {
162
- // NOTICE: Checking subDocuments id usage for array of subDocuments.
163
- if (Array.isArray(parentSchema)) {
164
- setIdToSchema(type, parentSchema[currentKey]);
165
- }
166
-
167
- iterateOnTypeKeysToAddNestedSchemas(type, parentSchema[currentKey], isTypeAnArray);
168
- }
169
- } else {
170
- parentSchema[currentKey] = isTypeAnArray ? [] : {};
171
-
172
- // NOTICE: Init id usage for the first subDocument.
173
- if (!isTypeAnArray && Array.isArray(parentSchema)) {
174
- type._id = type._id || false;
175
- }
176
-
177
- iterateOnTypeKeysToAddNestedSchemas(type, parentSchema[currentKey], isTypeAnArray);
178
- }
179
- }
180
-
181
- function addNestedSchemaToParentSchema(type, schema, currentKey) {
182
- if (typeof type === 'object') {
183
- addObjectSchema(type, schema, currentKey);
184
- } else {
185
- addMongooseType(type, schema, currentKey);
186
- }
187
- }
188
-
189
- function mergeAnalyzedSchemas(keyAnalyses) {
190
- if (!areAnalysesSameEmbeddedType(keyAnalyses)) {
191
- return 'Object';
192
- }
193
-
194
- const firstAnalysis = keyAnalyses[0];
195
- var schema;
196
- var isNestedArray;
197
-
198
- if (Array.isArray(firstAnalysis)) {
199
- schema = [];
200
- isNestedArray = true;
201
- } else {
202
- schema = {};
203
- isNestedArray = false;
204
- }
205
-
206
- keyAnalyses.forEach((keyAnalysis) => {
207
- iterateOnTypeKeysToAddNestedSchemas(keyAnalysis, schema, isNestedArray);
208
- });
209
-
210
- return schema;
211
- }
212
-
213
- module.exports = {
214
- addMongooseType,
215
- addNestedSchemaToParentSchema,
216
- addObjectSchema,
217
- areAnalysesSameEmbeddedType,
218
- areSchemaTypesMixed,
219
- detectSubDocumentsIdUsage,
220
- getMongooseArraySchema,
221
- getMongooseEmbeddedSchema,
222
- getMongooseSchema,
223
- haveSameEmbeddedType,
224
- hasEmbeddedTypes,
225
- mergeAnalyzedSchemas,
226
- };
@@ -1,55 +0,0 @@
1
- const _ = require('lodash');
2
- const P = require('bluebird');
3
- const {
4
- findCollectionMatchingSamples,
5
- filterReferenceCollection,
6
- } = require('../../../../utils/mongo-collections');
7
-
8
- const OBJECT_ID_ARRAY = '[Mongoose.Schema.Types.ObjectId]';
9
- const SAMPLE_COUNT_TO_FETCH = 10;
10
- const SAMPLE_COUNT_TO_FETCH_ARRAY = 5;
11
-
12
- const pickSampleValues = (databaseConnection, collectionName, field) =>
13
- databaseConnection.collection(collectionName)
14
- .aggregate([
15
- { $project: { [field.name]: { $slice: [`$${field.name}`, SAMPLE_COUNT_TO_FETCH_ARRAY] } } },
16
- { $match: { [field.name]: { $ne: null } } },
17
- { $sample: { size: SAMPLE_COUNT_TO_FETCH } },
18
- { $unwind: `$${field.name}` },
19
- { $project: { _id: false, value: `$${field.name}` } },
20
- ])
21
- .toArray()
22
- .then((samples) => _.map(samples, 'value'));
23
-
24
- const buildReference = (collectionName, referencedCollection, field) => {
25
- if (referencedCollection) {
26
- return {
27
- from: { collectionName, fieldName: field.name },
28
- to: { collectionName: referencedCollection },
29
- };
30
- }
31
- return null;
32
- };
33
-
34
- const detectReference = (databaseConnection, field, collectionName) =>
35
- pickSampleValues(databaseConnection, collectionName, field)
36
- .then((samples) => findCollectionMatchingSamples(databaseConnection, samples))
37
- .then((matches) => filterReferenceCollection(matches))
38
- .then((referencedCollection) => buildReference(collectionName, referencedCollection, field));
39
-
40
- const detectHasMany = (databaseConnection, fields, collectionName) => {
41
- const objectIdFields = fields.filter((field) => field.type === OBJECT_ID_ARRAY);
42
- return P.mapSeries(
43
- objectIdFields,
44
- (objectIdField) => detectReference(databaseConnection, objectIdField, collectionName),
45
- ).then((references) => references.filter((reference) => reference));
46
- };
47
-
48
- const applyHasMany = (fields, references) =>
49
- references.forEach((reference) => {
50
- const field = _.find(fields, { name: reference.from.fieldName });
51
- field.ref = reference.to.collectionName;
52
- field.hasMany = true;
53
- });
54
-
55
- module.exports = { detectHasMany, applyHasMany };