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.
- package/bin/run +1 -1
- package/dist/abstract-authenticated-command.d.ts +9 -0
- package/dist/abstract-authenticated-command.d.ts.map +1 -0
- package/dist/abstract-authenticated-command.js +40 -0
- package/dist/abstract-command.d.ts +15 -0
- package/dist/abstract-command.d.ts.map +1 -0
- package/dist/abstract-command.js +22 -0
- package/dist/commands/branch.d.ts +45 -0
- package/dist/commands/branch.d.ts.map +1 -0
- package/dist/commands/branch.js +124 -0
- package/dist/commands/deploy.d.ts +33 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +80 -0
- package/dist/commands/environments/copy-layout.d.ts +24 -0
- package/dist/commands/environments/copy-layout.d.ts.map +1 -0
- package/dist/commands/environments/copy-layout.js +102 -0
- package/dist/commands/environments/create.d.ts +32 -0
- package/dist/commands/environments/create.d.ts.map +1 -0
- package/dist/commands/environments/create.js +58 -0
- package/dist/commands/environments/delete.d.ts +19 -0
- package/dist/commands/environments/delete.d.ts.map +1 -0
- package/dist/commands/environments/delete.js +73 -0
- package/dist/commands/environments/get.d.ts +35 -0
- package/dist/commands/environments/get.d.ts.map +1 -0
- package/dist/commands/environments/get.js +38 -0
- package/dist/commands/environments/reset.d.ts +15 -0
- package/dist/commands/environments/reset.d.ts.map +1 -0
- package/dist/commands/environments/reset.js +70 -0
- package/dist/commands/environments/update.d.ts +14 -0
- package/dist/commands/environments/update.d.ts.map +1 -0
- package/dist/commands/environments/update.js +42 -0
- package/dist/commands/environments.d.ts +31 -0
- package/dist/commands/environments.d.ts.map +1 -0
- package/dist/commands/environments.js +36 -0
- package/dist/commands/init.d.ts +22 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +134 -0
- package/dist/commands/login.d.ts +15 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +30 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +15 -0
- package/dist/commands/projects/create.d.ts +73 -0
- package/dist/commands/projects/create.d.ts.map +1 -0
- package/dist/commands/projects/create.js +218 -0
- package/dist/commands/projects/get.d.ts +35 -0
- package/dist/commands/projects/get.d.ts.map +1 -0
- package/dist/commands/projects/get.js +42 -0
- package/dist/commands/projects.d.ts +30 -0
- package/dist/commands/projects.d.ts.map +1 -0
- package/dist/commands/projects.js +30 -0
- package/dist/commands/push.d.ts +16 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +66 -0
- package/dist/commands/schema/apply.d.ts +17 -0
- package/dist/commands/schema/apply.d.ts.map +1 -0
- package/dist/commands/schema/apply.js +112 -0
- package/dist/commands/schema/update.d.ts +17 -0
- package/dist/commands/schema/update.d.ts.map +1 -0
- package/dist/commands/schema/update.js +54 -0
- package/dist/commands/set-origin.d.ts +19 -0
- package/dist/commands/set-origin.d.ts.map +1 -0
- package/dist/commands/set-origin.js +50 -0
- package/dist/commands/switch.d.ts +22 -0
- package/dist/commands/switch.d.ts.map +1 -0
- package/dist/commands/switch.js +99 -0
- package/dist/commands/user.d.ts +14 -0
- package/dist/commands/user.d.ts.map +1 -0
- package/dist/commands/user.js +34 -0
- package/dist/context/command-project-create-plan.d.ts +3 -0
- package/dist/context/command-project-create-plan.d.ts.map +1 -0
- package/dist/context/command-project-create-plan.js +12 -0
- package/dist/context/command-projects-common-plan.d.ts +3 -0
- package/dist/context/command-projects-common-plan.d.ts.map +1 -0
- package/dist/context/command-projects-common-plan.js +37 -0
- package/dist/context/command-schema-update-command-plan.d.ts +3 -0
- package/dist/context/command-schema-update-command-plan.d.ts.map +1 -0
- package/dist/context/command-schema-update-command-plan.js +5 -0
- package/dist/context/dependencies-plan.d.ts +3 -0
- package/dist/context/dependencies-plan.d.ts.map +1 -0
- package/dist/context/dependencies-plan.js +22 -0
- package/dist/context/env-plan.d.ts +3 -0
- package/dist/context/env-plan.d.ts.map +1 -0
- package/dist/context/env-plan.js +28 -0
- package/dist/context/plan.d.ts +3 -0
- package/dist/context/plan.d.ts.map +1 -0
- package/dist/context/plan.js +13 -0
- package/dist/context/process-plan.d.ts +3 -0
- package/dist/context/process-plan.d.ts.map +1 -0
- package/dist/context/process-plan.js +4 -0
- package/dist/context/renderers-plan.d.ts +3 -0
- package/dist/context/renderers-plan.d.ts.map +1 -0
- package/dist/context/renderers-plan.js +8 -0
- package/dist/context/serializers-plan.d.ts +3 -0
- package/dist/context/serializers-plan.d.ts.map +1 -0
- package/dist/context/serializers-plan.js +9 -0
- package/dist/context/services-plan.d.ts +3 -0
- package/dist/context/services-plan.d.ts.map +1 -0
- package/dist/context/services-plan.js +9 -0
- package/dist/context/static.d.ts +2 -0
- package/dist/context/static.d.ts.map +1 -0
- package/dist/context/static.js +15 -0
- package/dist/context/utils-plan.d.ts +3 -0
- package/dist/context/utils-plan.d.ts.map +1 -0
- package/dist/context/utils-plan.js +8 -0
- package/dist/deserializers/api-error.d.ts +5 -0
- package/dist/deserializers/api-error.d.ts.map +1 -0
- package/dist/deserializers/api-error.js +18 -0
- package/dist/deserializers/application-token.d.ts +18 -0
- package/dist/deserializers/application-token.d.ts.map +1 -0
- package/dist/deserializers/application-token.js +13 -0
- package/dist/deserializers/branch.d.ts +3 -0
- package/dist/deserializers/branch.d.ts.map +1 -0
- package/dist/deserializers/branch.js +8 -0
- package/dist/deserializers/environment.d.ts +3 -0
- package/dist/deserializers/environment.d.ts.map +1 -0
- package/dist/deserializers/environment.js +5 -0
- package/dist/deserializers/job.d.ts +3 -0
- package/dist/deserializers/job.d.ts.map +1 -0
- package/dist/deserializers/job.js +5 -0
- package/dist/deserializers/project.d.ts +3 -0
- package/dist/deserializers/project.d.ts.map +1 -0
- package/dist/deserializers/project.js +11 -0
- package/dist/errors/application-error.d.ts +5 -0
- package/dist/errors/application-error.d.ts.map +1 -0
- package/dist/errors/application-error.js +9 -0
- package/dist/errors/application-token/unable-to-create-application-token-error.d.ts +16 -0
- package/dist/errors/application-token/unable-to-create-application-token-error.d.ts.map +1 -0
- package/dist/errors/application-token/unable-to-create-application-token-error.js +15 -0
- package/dist/errors/database/empty-database-error.d.ts +5 -0
- package/dist/errors/database/empty-database-error.d.ts.map +1 -0
- package/dist/errors/database/empty-database-error.js +5 -0
- package/dist/errors/dumper/incompatible-liana-for-update-error.d.ts +13 -0
- package/dist/errors/dumper/incompatible-liana-for-update-error.d.ts.map +1 -0
- package/dist/errors/dumper/incompatible-liana-for-update-error.js +15 -0
- package/dist/errors/dumper/invalid-forest-cli-project-structure-error.d.ts +13 -0
- package/dist/errors/dumper/invalid-forest-cli-project-structure-error.d.ts.map +1 -0
- package/dist/errors/dumper/invalid-forest-cli-project-structure-error.js +15 -0
- package/dist/errors/forest-cli-error.d.ts +26 -0
- package/dist/errors/forest-cli-error.d.ts.map +1 -0
- package/dist/errors/forest-cli-error.js +26 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/renderers/branches.d.ts +14 -0
- package/dist/renderers/branches.d.ts.map +1 -0
- package/dist/renderers/branches.js +34 -0
- package/dist/renderers/defaults.d.ts +18 -0
- package/dist/renderers/defaults.d.ts.map +1 -0
- package/dist/renderers/defaults.js +20 -0
- package/dist/renderers/environment.d.ts +14 -0
- package/dist/renderers/environment.d.ts.map +1 -0
- package/dist/renderers/environment.js +32 -0
- package/dist/renderers/environments.d.ts +14 -0
- package/dist/renderers/environments.d.ts.map +1 -0
- package/dist/renderers/environments.js +40 -0
- package/dist/renderers/project.d.ts +14 -0
- package/dist/renderers/project.d.ts.map +1 -0
- package/dist/renderers/project.js +30 -0
- package/dist/renderers/projects.d.ts +14 -0
- package/dist/renderers/projects.d.ts.map +1 -0
- package/dist/renderers/projects.js +34 -0
- package/dist/serializers/application-token.d.ts +12 -0
- package/dist/serializers/application-token.d.ts.map +1 -0
- package/dist/serializers/application-token.js +9 -0
- package/dist/serializers/deployment-request.d.ts +3 -0
- package/dist/serializers/deployment-request.d.ts.map +1 -0
- package/dist/serializers/deployment-request.js +5 -0
- package/dist/serializers/environment.d.ts +3 -0
- package/dist/serializers/environment.d.ts.map +1 -0
- package/dist/serializers/environment.js +20 -0
- package/dist/serializers/job.d.ts +3 -0
- package/dist/serializers/job.d.ts.map +1 -0
- package/dist/serializers/job.js +5 -0
- package/dist/serializers/project.d.ts +3 -0
- package/dist/serializers/project.d.ts.map +1 -0
- package/dist/serializers/project.js +17 -0
- package/dist/serializers/schema.d.ts +31 -0
- package/dist/serializers/schema.d.ts.map +1 -0
- package/dist/serializers/schema.js +110 -0
- package/dist/services/api.d.ts +29 -0
- package/dist/services/api.d.ts.map +1 -0
- package/dist/services/api.js +92 -0
- package/dist/services/apimap-sorter.d.ts +7 -0
- package/dist/services/apimap-sorter.d.ts.map +1 -0
- package/dist/services/apimap-sorter.js +83 -0
- package/dist/services/application-token.d.ts +22 -0
- package/dist/services/application-token.d.ts.map +1 -0
- package/dist/services/application-token.js +51 -0
- package/dist/services/ask-for-environment.d.ts +3 -0
- package/dist/services/ask-for-environment.d.ts.map +1 -0
- package/dist/services/ask-for-environment.js +19 -0
- package/dist/services/authenticator.d.ts +43 -0
- package/dist/services/authenticator.d.ts.map +1 -0
- package/dist/services/authenticator.js +172 -0
- package/dist/services/branch-manager.d.ts +10 -0
- package/dist/services/branch-manager.d.ts.map +1 -0
- package/dist/services/branch-manager.js +125 -0
- package/dist/services/dumper/dumper.d.ts +62 -0
- package/dist/services/dumper/dumper.d.ts.map +1 -0
- package/dist/services/dumper/dumper.js +424 -0
- package/dist/services/dumper/handlebars/helpers/equal.d.ts +2 -0
- package/dist/services/dumper/handlebars/helpers/equal.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/equal.js +3 -0
- package/dist/services/dumper/handlebars/helpers/indent.d.ts +2 -0
- package/dist/services/dumper/handlebars/helpers/indent.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/indent.js +3 -0
- package/dist/services/dumper/handlebars/helpers/is-array.d.ts +2 -0
- package/dist/services/dumper/handlebars/helpers/is-array.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/is-array.js +3 -0
- package/dist/services/dumper/handlebars/helpers/is-object.d.ts +2 -0
- package/dist/services/dumper/handlebars/helpers/is-object.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/is-object.js +3 -0
- package/dist/services/dumper/handlebars/helpers/sum.d.ts +2 -0
- package/dist/services/dumper/handlebars/helpers/sum.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/sum.js +3 -0
- package/dist/services/dumper/handlebars/helpers/wrap-quotes.d.ts +3 -0
- package/dist/services/dumper/handlebars/helpers/wrap-quotes.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/helpers/wrap-quotes.js +5 -0
- package/dist/services/dumper/handlebars/loader.d.ts +2 -0
- package/dist/services/dumper/handlebars/loader.d.ts.map +1 -0
- package/dist/services/dumper/handlebars/loader.js +10 -0
- package/dist/services/dumper/handlebars/partials/render-nested.d.ts +2 -0
- package/dist/services/dumper/handlebars/partials/render-nested.d.ts.map +1 -0
- package/{src → dist}/services/dumper/handlebars/partials/render-nested.js +3 -7
- package/{src → dist}/services/dumper/templates/app/Dockerfile.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/app.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/config/databases.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/docker-compose.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/dockerignore.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/env.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/forest/collection.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/gitignore.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/middlewares/forestadmin.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/middlewares/welcome.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/models/index.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/models/mongo-model.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/models/sequelize-model.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/public/favicon.png +0 -0
- package/{src → dist}/services/dumper/templates/app/routes/route.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/server.hbs +0 -0
- package/{src → dist}/services/dumper/templates/app/views/index.hbs +0 -0
- package/dist/services/environment-manager.d.ts +19 -0
- package/dist/services/environment-manager.d.ts.map +1 -0
- package/dist/services/environment-manager.js +113 -0
- package/dist/services/init-manager.d.ts +8 -0
- package/dist/services/init-manager.d.ts.map +1 -0
- package/dist/services/init-manager.js +156 -0
- package/dist/services/job-state-checker.d.ts +7 -0
- package/dist/services/job-state-checker.d.ts.map +1 -0
- package/dist/services/job-state-checker.js +45 -0
- package/dist/services/logger.d.ts +36 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +97 -0
- package/dist/services/oidc/authenticator.d.ts +37 -0
- package/dist/services/oidc/authenticator.d.ts.map +1 -0
- package/dist/services/oidc/authenticator.js +85 -0
- package/dist/services/oidc/error.d.ts +11 -0
- package/dist/services/oidc/error.d.ts.map +1 -0
- package/dist/services/oidc/error.js +28 -0
- package/dist/services/project-manager.d.ts +11 -0
- package/dist/services/project-manager.d.ts.map +1 -0
- package/dist/services/project-manager.js +72 -0
- package/dist/services/projects/create/command-generate-config-getter.d.ts +15 -0
- package/dist/services/projects/create/command-generate-config-getter.d.ts.map +1 -0
- package/dist/services/projects/create/command-generate-config-getter.js +51 -0
- package/dist/services/projects/create/project-creator.d.ts +108 -0
- package/dist/services/projects/create/project-creator.d.ts.map +1 -0
- package/dist/services/projects/create/project-creator.js +80 -0
- package/dist/services/prompter/abstract-prompter.d.ts +7 -0
- package/dist/services/prompter/abstract-prompter.d.ts.map +1 -0
- package/dist/services/prompter/abstract-prompter.js +13 -0
- package/dist/services/prompter/application-prompts.d.ts +12 -0
- package/dist/services/prompter/application-prompts.d.ts.map +1 -0
- package/dist/services/prompter/application-prompts.js +60 -0
- package/dist/services/prompter/database-prompts.d.ts +23 -0
- package/dist/services/prompter/database-prompts.d.ts.map +1 -0
- package/dist/services/prompter/database-prompts.js +193 -0
- package/dist/services/prompter/general-prompter.d.ts +17 -0
- package/dist/services/prompter/general-prompter.d.ts.map +1 -0
- package/dist/services/prompter/general-prompter.js +49 -0
- package/dist/services/prompter/project-prompts.d.ts +11 -0
- package/dist/services/prompter/project-prompts.d.ts.map +1 -0
- package/dist/services/prompter/project-prompts.js +39 -0
- package/dist/services/prompter/prompter-error.d.ts +8 -0
- package/dist/services/prompter/prompter-error.d.ts.map +1 -0
- package/dist/services/prompter/prompter-error.js +10 -0
- package/dist/services/schema/schema-service.d.ts +41 -0
- package/dist/services/schema/schema-service.d.ts.map +1 -0
- package/dist/services/schema/schema-service.js +123 -0
- package/dist/services/schema/update/analyzer/database-analyzer.d.ts +17 -0
- package/dist/services/schema/update/analyzer/database-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/database-analyzer.js +53 -0
- package/dist/services/schema/update/analyzer/mongo-collections-analyzer.d.ts +78 -0
- package/dist/services/schema/update/analyzer/mongo-collections-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/mongo-collections-analyzer.js +292 -0
- package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.d.ts +13 -0
- package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/mongo-embedded-analyzer.js +183 -0
- package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.d.ts +3 -0
- package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/mongo-hasmany-analyzer.js +40 -0
- package/dist/services/schema/update/analyzer/mongo-references-analyzer.d.ts +3 -0
- package/dist/services/schema/update/analyzer/mongo-references-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/mongo-references-analyzer.js +36 -0
- package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.d.ts +9 -0
- package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/mysql-table-constraints-getter.js +54 -0
- package/dist/services/schema/update/analyzer/sequelize-column-type-getter.d.ts +8 -0
- package/dist/services/schema/update/analyzer/sequelize-column-type-getter.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/sequelize-column-type-getter.js +137 -0
- package/dist/services/schema/update/analyzer/sequelize-default-value.d.ts +18 -0
- package/dist/services/schema/update/analyzer/sequelize-default-value.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/sequelize-default-value.js +117 -0
- package/dist/services/schema/update/analyzer/sequelize-table-constraints-getter.d.ts +7 -0
- package/dist/services/schema/update/analyzer/sequelize-table-constraints-getter.d.ts.map +1 -0
- package/{src → dist}/services/schema/update/analyzer/sequelize-table-constraints-getter.js +28 -34
- package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.d.ts +3 -0
- package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.d.ts.map +1 -0
- package/dist/services/schema/update/analyzer/sequelize-tables-analyzer.js +383 -0
- package/dist/services/schema/update/database.d.ts +23 -0
- package/dist/services/schema/update/database.d.ts.map +1 -0
- package/dist/services/schema/update/database.js +143 -0
- package/dist/services/schema-sender.d.ts +25 -0
- package/dist/services/schema-sender.d.ts.map +1 -0
- package/dist/services/schema-sender.js +56 -0
- package/dist/services/spinner.d.ts +35 -0
- package/dist/services/spinner.d.ts.map +1 -0
- package/dist/services/spinner.js +114 -0
- package/dist/services/with-current-project.d.ts +3 -0
- package/dist/services/with-current-project.d.ts.map +1 -0
- package/dist/services/with-current-project.js +39 -0
- package/dist/utils/database-url.d.ts +2 -0
- package/dist/utils/database-url.d.ts.map +1 -0
- package/dist/utils/database-url.js +28 -0
- package/dist/utils/directory-existence-checker.d.ts +7 -0
- package/dist/utils/directory-existence-checker.d.ts.map +1 -0
- package/dist/utils/directory-existence-checker.js +18 -0
- package/dist/utils/error-handler.d.ts +24 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +55 -0
- package/dist/utils/error.d.ts +2 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +20 -0
- package/dist/utils/event-sender.d.ts +17 -0
- package/dist/utils/event-sender.d.ts.map +1 -0
- package/dist/utils/event-sender.js +78 -0
- package/dist/utils/fields.d.ts +2 -0
- package/dist/utils/fields.d.ts.map +1 -0
- package/dist/utils/fields.js +13 -0
- package/dist/utils/key-generator.d.ts +11 -0
- package/dist/utils/key-generator.d.ts.map +1 -0
- package/dist/utils/key-generator.js +14 -0
- package/dist/utils/messages.d.ts +6 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +8 -0
- package/dist/utils/mongo-collections.d.ts +5 -0
- package/dist/utils/mongo-collections.d.ts.map +1 -0
- package/dist/utils/mongo-collections.js +32 -0
- package/dist/utils/mongo-primitive-type.d.ts +14 -0
- package/dist/utils/mongo-primitive-type.d.ts.map +1 -0
- package/dist/utils/mongo-primitive-type.js +40 -0
- package/dist/utils/strings.d.ts +6 -0
- package/dist/utils/strings.d.ts.map +1 -0
- package/dist/utils/strings.js +44 -0
- package/dist/utils/terminator.d.ts +22 -0
- package/dist/utils/terminator.d.ts.map +1 -0
- package/dist/utils/terminator.js +33 -0
- package/dist/utils/to-valid-package-name.d.ts +3 -0
- package/dist/utils/to-valid-package-name.d.ts.map +1 -0
- package/dist/utils/to-valid-package-name.js +21 -0
- package/oclif.manifest.json +1 -1
- package/package.json +17 -8
- package/src/abstract-authenticated-command.js +0 -46
- package/src/abstract-command.js +0 -27
- package/src/commands/branch.js +0 -136
- package/src/commands/deploy.js +0 -90
- package/src/commands/environments/copy-layout.js +0 -116
- package/src/commands/environments/create.js +0 -62
- package/src/commands/environments/delete.js +0 -81
- package/src/commands/environments/get.js +0 -48
- package/src/commands/environments/reset.js +0 -76
- package/src/commands/environments/update.js +0 -46
- package/src/commands/environments.js +0 -41
- package/src/commands/init.js +0 -169
- package/src/commands/login.js +0 -34
- package/src/commands/logout.js +0 -18
- package/src/commands/projects/create.js +0 -262
- package/src/commands/projects/get.js +0 -53
- package/src/commands/projects.js +0 -36
- package/src/commands/push.js +0 -75
- package/src/commands/schema/apply.js +0 -140
- package/src/commands/schema/update.js +0 -70
- package/src/commands/set-origin.js +0 -59
- package/src/commands/switch.js +0 -117
- package/src/commands/user.js +0 -44
- package/src/context/command-project-create-plan.js +0 -11
- package/src/context/command-projects-common-plan.js +0 -65
- package/src/context/command-schema-update-command-plan.js +0 -4
- package/src/context/dependencies-plan.js +0 -21
- package/src/context/env-plan.js +0 -27
- package/src/context/plan.js +0 -12
- package/src/context/process-plan.js +0 -3
- package/src/context/renderers-plan.js +0 -7
- package/src/context/serializers-plan.js +0 -8
- package/src/context/services-plan.js +0 -8
- package/src/context/static.js +0 -19
- package/src/context/utils-plan.js +0 -7
- package/src/deserializers/api-error.js +0 -21
- package/src/deserializers/application-token.js +0 -15
- package/src/deserializers/branch.js +0 -8
- package/src/deserializers/environment.js +0 -5
- package/src/deserializers/job.js +0 -5
- package/src/deserializers/project.js +0 -11
- package/src/errors/application-error.js +0 -9
- package/src/errors/application-token/unable-to-create-application-token-error.js +0 -16
- package/src/errors/database/empty-database-error.js +0 -5
- package/src/errors/dumper/incompatible-liana-for-update-error.js +0 -16
- package/src/errors/dumper/invalid-forest-cli-project-structure-error.js +0 -16
- package/src/errors/forest-cli-error.js +0 -32
- package/src/index.js +0 -1
- package/src/renderers/branches.js +0 -45
- package/src/renderers/defaults.js +0 -19
- package/src/renderers/environment.js +0 -51
- package/src/renderers/environments.js +0 -51
- package/src/renderers/project.js +0 -45
- package/src/renderers/projects.js +0 -45
- package/src/serializers/application-token.js +0 -11
- package/src/serializers/deployment-request.js +0 -5
- package/src/serializers/environment.js +0 -20
- package/src/serializers/job.js +0 -5
- package/src/serializers/project.js +0 -17
- package/src/serializers/schema.js +0 -116
- package/src/services/api.js +0 -110
- package/src/services/apimap-sorter.js +0 -104
- package/src/services/application-token.js +0 -56
- package/src/services/ask-for-environment.js +0 -24
- package/src/services/authenticator.js +0 -187
- package/src/services/branch-manager.js +0 -169
- package/src/services/dumper/dumper.js +0 -503
- package/src/services/dumper/handlebars/helpers/equal.js +0 -3
- package/src/services/dumper/handlebars/helpers/indent.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-array.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-object.js +0 -3
- package/src/services/dumper/handlebars/helpers/sum.js +0 -3
- package/src/services/dumper/handlebars/helpers/wrap-quotes.js +0 -7
- package/src/services/dumper/handlebars/loader.js +0 -10
- package/src/services/environment-manager.js +0 -139
- package/src/services/init-manager.js +0 -183
- package/src/services/job-state-checker.js +0 -57
- package/src/services/logger.js +0 -125
- package/src/services/oidc/authenticator.js +0 -109
- package/src/services/oidc/error.js +0 -32
- package/src/services/project-manager.js +0 -89
- package/src/services/projects/create/command-generate-config-getter.js +0 -61
- package/src/services/projects/create/project-creator.js +0 -89
- package/src/services/prompter/abstract-prompter.js +0 -13
- package/src/services/prompter/application-prompts.js +0 -63
- package/src/services/prompter/database-prompts.js +0 -208
- package/src/services/prompter/general-prompter.js +0 -61
- package/src/services/prompter/project-prompts.js +0 -47
- package/src/services/prompter/prompter-error.js +0 -10
- package/src/services/schema/schema-service.js +0 -154
- package/src/services/schema/update/analyzer/database-analyzer.js +0 -64
- package/src/services/schema/update/analyzer/mongo-collections-analyzer.js +0 -344
- package/src/services/schema/update/analyzer/mongo-embedded-analyzer.js +0 -226
- package/src/services/schema/update/analyzer/mongo-hasmany-analyzer.js +0 -55
- package/src/services/schema/update/analyzer/mongo-references-analyzer.js +0 -51
- package/src/services/schema/update/analyzer/mysql-table-constraints-getter.js +0 -59
- package/src/services/schema/update/analyzer/sequelize-column-type-getter.js +0 -147
- package/src/services/schema/update/analyzer/sequelize-default-value.js +0 -122
- package/src/services/schema/update/analyzer/sequelize-tables-analyzer.js +0 -529
- package/src/services/schema/update/database.js +0 -160
- package/src/services/schema-sender.js +0 -55
- package/src/services/spinner.js +0 -130
- package/src/services/with-current-project.js +0 -41
- package/src/utils/database-url.js +0 -33
- package/src/utils/directory-existence-checker.js +0 -17
- package/src/utils/error-handler.js +0 -63
- package/src/utils/error.js +0 -21
- package/src/utils/event-sender.js +0 -80
- package/src/utils/fields.js +0 -14
- package/src/utils/key-generator.js +0 -18
- package/src/utils/messages.js +0 -7
- package/src/utils/mongo-collections.js +0 -35
- package/src/utils/mongo-primitive-type.js +0 -44
- package/src/utils/strings.js +0 -49
- package/src/utils/terminator.js +0 -38
- 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 };
|