@koalarx/nest 3.1.50 → 4.0.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/README.md +126 -439
- package/cli/commands/add/index.js +97 -0
- package/cli/commands/help.js +44 -0
- package/cli/commands/new/configure-test-runner.js +13 -0
- package/cli/commands/new/create-ddd-structure.js +52 -0
- package/cli/commands/new/create-empty-nest-project.js +58 -0
- package/cli/commands/new/fix-lint-config.js +24 -0
- package/cli/commands/new/index.js +202 -0
- package/cli/commands/version.js +5 -0
- package/cli/constants/auth-strategy-artifacts.js +56 -0
- package/cli/constants/auth-strategy-checklist.js +314 -0
- package/cli/constants/cli-commands.js +24 -0
- package/cli/constants/cli-project-checklist.js +289 -0
- package/cli/constants/core-packages.js +34 -0
- package/cli/constants/domain.js +171 -0
- package/cli/constants/package-manager.js +5 -0
- package/cli/constants/version.js +5 -0
- package/cli/index.js +55 -0
- package/cli/types/index.js +0 -0
- package/cli/utils/add-project-features.js +170 -0
- package/cli/utils/apply-optional-features.js +48 -0
- package/cli/utils/auth-strategy-validation.js +179 -0
- package/cli/utils/cancel.js +8 -0
- package/cli/utils/cli-options.js +27 -0
- package/cli/utils/cli-project-validation.js +157 -0
- package/cli/utils/detect-project-state.js +131 -0
- package/cli/utils/format-code.js +9 -0
- package/cli/utils/get-package-manager.js +12 -0
- package/cli/utils/get-package-root.js +19 -0
- package/cli/utils/get-source-code-path.js +15 -0
- package/cli/utils/install-module.js +258 -0
- package/cli/utils/normalize-add-args.js +25 -0
- package/cli/utils/parse-new-args.js +127 -0
- package/cli/utils/patch-auth-install.js +224 -0
- package/cli/utils/patch-define-documentation.js +222 -0
- package/cli/utils/patch-env.js +106 -0
- package/cli/utils/patch-generated-project.js +21 -0
- package/cli/utils/patch-health-module.js +80 -0
- package/cli/utils/patch-infra-module.js +62 -0
- package/cli/utils/patch-jobs-module.js +103 -0
- package/cli/utils/patch-main.js +15 -0
- package/cli/utils/patch-person-features.js +127 -0
- package/cli/utils/project-files.js +11 -0
- package/cli/utils/prune-auth-strategies.js +116 -0
- package/cli/utils/prune-core-auth.js +17 -0
- package/cli/utils/remove-sample-parts.js +203 -0
- package/cli/utils/resolve-project-path.js +19 -0
- package/cli/utils/restore-person-features.js +64 -0
- package/cli/utils/run-command.js +31 -0
- package/cli/utils/sync-auth-strategy-files.js +63 -0
- package/koala-nest/.env.example +34 -0
- package/koala-nest/.prettierrc +4 -0
- package/koala-nest/README.md +51 -0
- package/koala-nest/bunfig.toml +7 -0
- package/koala-nest/eslint.config.mjs +55 -0
- package/koala-nest/nest-cli.json +9 -0
- package/koala-nest/package.json +79 -0
- package/koala-nest/src/application/auth/common/auth-token.response.ts +15 -0
- package/koala-nest/src/application/auth/common/user-claims.ts +6 -0
- package/koala-nest/src/application/auth/login/login.handler.ts +42 -0
- package/koala-nest/src/application/auth/login/login.request.ts +9 -0
- package/koala-nest/src/application/auth/login/login.response.ts +3 -0
- package/koala-nest/src/application/auth/login/login.validator.ts +12 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.handler.ts +24 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.request.ts +10 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.response.ts +6 -0
- package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.validator.ts +12 -0
- package/koala-nest/src/application/auth/oauth2/callback/oauth-callback.response.ts +10 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.handler.ts +73 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.request.ts +16 -0
- package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.validator.ts +14 -0
- package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-oauth-token.handler.ts +35 -0
- package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-token.types.ts +1 -0
- package/koala-nest/src/application/auth/refresh-token/refresh-token.handler.ts +26 -0
- package/koala-nest/src/application/auth/user-info/user-info.handler.ts +30 -0
- package/koala-nest/src/application/auth/user-info/user-info.response.ts +20 -0
- package/koala-nest/src/application/common/created-registre.response.ts +20 -0
- package/koala-nest/src/application/common/pagination.request.ts +41 -0
- package/koala-nest/src/application/common/request-handler.base.ts +3 -0
- package/koala-nest/src/application/common/request-validator.base.ts +33 -0
- package/koala-nest/src/application/mapping/mapping.provider.ts +9 -0
- package/koala-nest/src/application/mapping/person.mapper.ts +44 -0
- package/koala-nest/src/application/person/create/create-person.handler.ts +34 -0
- package/koala-nest/src/application/person/create/create-person.request.ts +29 -0
- package/koala-nest/src/application/person/create/create-person.response.ts +3 -0
- package/koala-nest/src/application/person/create/create-person.validator.ts +9 -0
- package/koala-nest/src/application/person/delete/delete-person.handler.ts +22 -0
- package/koala-nest/src/application/person/find-person-or-throw.ts +16 -0
- package/koala-nest/src/application/person/jobs/cron/create-person.job.ts +58 -0
- package/koala-nest/src/application/person/jobs/cron/delete-inactive.job.ts +57 -0
- package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.event.ts +4 -0
- package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts +54 -0
- package/koala-nest/src/application/person/jobs/events/person/person-event.job.ts +19 -0
- package/koala-nest/src/application/person/person.schemas.ts +21 -0
- package/koala-nest/src/application/person/read/read-person.handler.ts +22 -0
- package/koala-nest/src/application/person/read/read-person.response.ts +44 -0
- package/koala-nest/src/application/person/read-many/read-many-person.handler.ts +63 -0
- package/koala-nest/src/application/person/read-many/read-many-person.request.ts +13 -0
- package/koala-nest/src/application/person/read-many/read-many-person.response.ts +30 -0
- package/koala-nest/src/application/person/read-many/read-many-person.validator.ts +15 -0
- package/koala-nest/src/application/person/update/update-person.handler.ts +51 -0
- package/koala-nest/src/application/person/update/update-person.request.ts +41 -0
- package/koala-nest/src/application/person/update/update-person.validator.ts +9 -0
- package/koala-nest/src/core/auth/assert-user-active.ts +18 -0
- package/koala-nest/src/core/auth/auth-profile.enum.ts +7 -0
- package/koala-nest/src/core/auth/auth-routes.ts +5 -0
- package/koala-nest/src/core/auth/auth.constants.ts +6 -0
- package/koala-nest/src/core/auth/jwt-claims.ts +23 -0
- package/koala-nest/src/core/auth/oauth-provider.registry.ts +94 -0
- package/koala-nest/src/core/auth/parse-jwt-expires-in.ts +30 -0
- package/koala-nest/src/core/auth/parse-oauth2-provider-env.ts +56 -0
- package/koala-nest/src/core/auth/resolve-refresh-token.ts +40 -0
- package/koala-nest/src/core/background-services/cron-service/cron-job.handler.base.ts +65 -0
- package/koala-nest/src/core/background-services/event-service/event-class.ts +5 -0
- package/koala-nest/src/core/background-services/event-service/event-handler.base.ts +17 -0
- package/koala-nest/src/core/background-services/event-service/event-job.ts +31 -0
- package/koala-nest/src/core/background-services/event-service/event-queue.ts +107 -0
- package/koala-nest/src/core/base/entity.base.ts +3 -0
- package/koala-nest/src/core/base/object-class.ts +14 -0
- package/koala-nest/src/core/constants/cache.constants.ts +16 -0
- package/koala-nest/src/core/constants/cron.constants.ts +14 -0
- package/koala-nest/src/core/constants/query-params.ts +7 -0
- package/koala-nest/src/core/env.ts +42 -0
- package/koala-nest/src/core/schemas/boolean.schema.ts +24 -0
- package/koala-nest/src/core/schemas/document-number-mask.ts +22 -0
- package/koala-nest/src/core/schemas/document-number.schema.ts +21 -0
- package/koala-nest/src/core/schemas/document-number.utils.ts +15 -0
- package/koala-nest/src/core/schemas/email.schema.ts +13 -0
- package/koala-nest/src/core/schemas/index.ts +6 -0
- package/koala-nest/src/core/schemas/list-query.schema.ts +18 -0
- package/koala-nest/src/core/schemas/native-enum.schema.ts +36 -0
- package/koala-nest/src/core/tools/mapping/auto-map.ts +14 -0
- package/koala-nest/src/core/tools/mapping/auto-mapper.ts +102 -0
- package/koala-nest/src/core/tools/mapping/create-map.ts +11 -0
- package/koala-nest/src/core/tools/mapping/for-member.ts +16 -0
- package/koala-nest/src/core/tools/mapping/index.ts +4 -0
- package/koala-nest/src/core/tools/mapping/mapping-store.ts +121 -0
- package/koala-nest/src/core/types/auth-provider-config-response.type.ts +5 -0
- package/koala-nest/src/core/types/index.ts +5 -0
- package/koala-nest/src/core/utils/build-list-cache-key.ts +19 -0
- package/koala-nest/src/core/utils/cron-expression-to-boolean.ts +65 -0
- package/koala-nest/src/core/utils/env.config.ts +17 -0
- package/koala-nest/src/core/utils/filter-request-params.ts +29 -0
- package/koala-nest/src/core/utils/format-typeorm-error.ts +173 -0
- package/koala-nest/src/core/utils/format-zod-error.ts +201 -0
- package/koala-nest/src/core/utils/hash-password.ts +5 -0
- package/koala-nest/src/core/utils/icomparable.ts +1 -0
- package/koala-nest/src/core/utils/is-provider-registered.ts +40 -0
- package/koala-nest/src/core/utils/name-to-login.ts +25 -0
- package/koala-nest/src/core/utils/person-list-cache.ts +7 -0
- package/koala-nest/src/core/utils/report-error.ts +18 -0
- package/koala-nest/src/core/utils/resolve-api-host.ts +8 -0
- package/koala-nest/src/core/utils/time.constants.ts +5 -0
- package/koala-nest/src/domain/auth/dtos/auth-provider-config.dto.ts +12 -0
- package/koala-nest/src/domain/auth/dtos/oauth-user-info.dto.ts +9 -0
- package/koala-nest/src/domain/auth/services/iauth.service.ts +37 -0
- package/koala-nest/src/domain/common/icache.service.ts +11 -0
- package/koala-nest/src/domain/common/ilogging.service.ts +9 -0
- package/koala-nest/src/domain/common/ired-lock.service.ts +4 -0
- package/koala-nest/src/domain/dtos/logged-user-info.dto.ts +30 -0
- package/koala-nest/src/domain/dtos/pagination.dto.ts +35 -0
- package/koala-nest/src/domain/dtos/person-query.dto.ts +10 -0
- package/koala-nest/src/domain/entities/person/person-address.ts +14 -0
- package/koala-nest/src/domain/entities/person/person-contact.ts +28 -0
- package/koala-nest/src/domain/entities/person/person.ts +44 -0
- package/koala-nest/src/domain/entities/user/enums/user-status.enum.ts +6 -0
- package/koala-nest/src/domain/entities/user/user.ts +49 -0
- package/koala-nest/src/domain/repositories/iperson.repository.ts +10 -0
- package/koala-nest/src/domain/repositories/iuser.repository.ts +8 -0
- package/koala-nest/src/domain/services/ilogged-user-info.service.ts +5 -0
- package/koala-nest/src/host/app.module.ts +27 -0
- package/koala-nest/src/host/controllers/auth/auth.module.ts +38 -0
- package/koala-nest/src/host/controllers/auth/login.controller.ts +41 -0
- package/koala-nest/src/host/controllers/auth/refresh-token.controller.ts +24 -0
- package/koala-nest/src/host/controllers/auth/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/auth/user-info.controller.ts +19 -0
- package/koala-nest/src/host/controllers/common/controller.base.ts +9 -0
- package/koala-nest/src/host/controllers/common/controller.module.ts +10 -0
- package/koala-nest/src/host/controllers/common/router-config.base.ts +14 -0
- package/koala-nest/src/host/controllers/health-check/health-check.controller.ts +29 -0
- package/koala-nest/src/host/controllers/health-check/health-check.module.ts +22 -0
- package/koala-nest/src/host/controllers/oauth2/auth-link.controller.ts +29 -0
- package/koala-nest/src/host/controllers/oauth2/exchange-code.controller.ts +29 -0
- package/koala-nest/src/host/controllers/oauth2/oauth-callback.controller.ts +28 -0
- package/koala-nest/src/host/controllers/oauth2/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/oauth2/scalar-token.controller.ts +16 -0
- package/koala-nest/src/host/controllers/person/create-person.controller.ts +23 -0
- package/koala-nest/src/host/controllers/person/delete-person.controller.ts +23 -0
- package/koala-nest/src/host/controllers/person/person.module.ts +39 -0
- package/koala-nest/src/host/controllers/person/read-many-person.controller.ts +24 -0
- package/koala-nest/src/host/controllers/person/read-person.controller.ts +21 -0
- package/koala-nest/src/host/controllers/person/router.config.ts +9 -0
- package/koala-nest/src/host/controllers/person/update-person.controller.ts +22 -0
- package/koala-nest/src/host/decorators/api-exclude-endpoint-diff-develop.decorator.ts +9 -0
- package/koala-nest/src/host/decorators/api-property-enum.decorator.ts +49 -0
- package/koala-nest/src/host/decorators/api-property-only-develop.decorator.ts +19 -0
- package/koala-nest/src/host/decorators/controller.decorator.ts +10 -0
- package/koala-nest/src/host/decorators/is-public.decorator.ts +82 -0
- package/koala-nest/src/host/decorators/restriction-by-profile.decorator.ts +13 -0
- package/koala-nest/src/host/decorators/scalar-token-endpoint.decorator.ts +14 -0
- package/koala-nest/src/host/filters/errors.filter.ts +99 -0
- package/koala-nest/src/host/jobs/jobs-bootstrap.service.ts +61 -0
- package/koala-nest/src/host/jobs/jobs.module.ts +41 -0
- package/koala-nest/src/host/jobs/jobs.tokens.ts +2 -0
- package/koala-nest/src/host/main.ts +43 -0
- package/koala-nest/src/host/open-api/define-documentation.ts +210 -0
- package/koala-nest/src/host/security/guards/auth.guard.ts +107 -0
- package/koala-nest/src/host/security/guards/profiles.guard.ts +32 -0
- package/koala-nest/src/host/security/security.module.ts +62 -0
- package/koala-nest/src/host/security/strategies/jwt.strategy.ts +61 -0
- package/koala-nest/src/infra/auth/jwt-token.service.ts +48 -0
- package/koala-nest/src/infra/auth/oauth2-auth.service.ts +208 -0
- package/koala-nest/src/infra/common/cache-service.provider.ts +47 -0
- package/koala-nest/src/infra/common/env.service.ts +12 -0
- package/koala-nest/src/infra/common/in-memory-cache.service.ts +71 -0
- package/koala-nest/src/infra/common/logging.service.ts +19 -0
- package/koala-nest/src/infra/common/red-lock.service.ts +44 -0
- package/koala-nest/src/infra/common/redis-cache.service.ts +72 -0
- package/koala-nest/src/infra/database/data-source-factory.ts +23 -0
- package/koala-nest/src/infra/database/database.module.ts +19 -0
- package/koala-nest/src/infra/database/migrations/1781281330533-Init.ts +67 -0
- package/koala-nest/src/infra/database/migrations/generate-migration.ts +26 -0
- package/koala-nest/src/infra/database/migrations/migration-datasource.ts +14 -0
- package/koala-nest/src/infra/infra.module.ts +29 -0
- package/koala-nest/src/infra/repositories/person.repository.ts +49 -0
- package/koala-nest/src/infra/repositories/repository.base.ts +20 -0
- package/koala-nest/src/infra/repositories/repository.module.ts +16 -0
- package/koala-nest/src/infra/repositories/user.repository.ts +38 -0
- package/koala-nest/src/infra/services/database.indicator.service.ts +17 -0
- package/koala-nest/src/infra/services/logged-user-info.service.ts +32 -0
- package/koala-nest/src/infra/services/redis.indicator.service.ts +66 -0
- package/koala-nest/src/test/app-auth-test.module.ts +32 -0
- package/koala-nest/src/test/app-test.module.ts +22 -0
- package/koala-nest/src/test/application/auth-link.handler.spec.ts +22 -0
- package/koala-nest/src/test/application/create-person.handler.spec.ts +39 -0
- package/koala-nest/src/test/application/create-person.job.spec.ts +55 -0
- package/koala-nest/src/test/application/delete-inactive.job.spec.ts +35 -0
- package/koala-nest/src/test/application/delete-person.handler.spec.ts +46 -0
- package/koala-nest/src/test/application/exchange-code.handler.spec.ts +67 -0
- package/koala-nest/src/test/application/inactive-person.handler.spec.ts +48 -0
- package/koala-nest/src/test/application/login.handler.spec.ts +55 -0
- package/koala-nest/src/test/application/read-many-person.handler.spec.ts +64 -0
- package/koala-nest/src/test/application/read-person.handler.spec.ts +44 -0
- package/koala-nest/src/test/application/refresh-token.handler.spec.ts +34 -0
- package/koala-nest/src/test/application/scalar-oauth-token.handler.spec.ts +63 -0
- package/koala-nest/src/test/application/update-person.handler.spec.ts +78 -0
- package/koala-nest/src/test/bun-test-globals.d.ts +1 -0
- package/koala-nest/src/test/core/auth.guard.spec.ts +77 -0
- package/koala-nest/src/test/core/build-list-cache-key.spec.ts +29 -0
- package/koala-nest/src/test/core/cron-expression-to-boolean.spec.ts +22 -0
- package/koala-nest/src/test/core/cron-job.handler.spec.ts +40 -0
- package/koala-nest/src/test/core/env.config.spec.ts +14 -0
- package/koala-nest/src/test/core/env.spec.ts +61 -0
- package/koala-nest/src/test/core/event-queue.spec.ts +53 -0
- package/koala-nest/src/test/core/format-typeorm-error.spec.ts +42 -0
- package/koala-nest/src/test/core/format-zod-error.spec.ts +38 -0
- package/koala-nest/src/test/core/is-provider-registered.spec.ts +35 -0
- package/koala-nest/src/test/core/jwt.strategy.spec.ts +38 -0
- package/koala-nest/src/test/core/mapping.spec.ts +177 -0
- package/koala-nest/src/test/core/oauth-provider.registry.spec.ts +79 -0
- package/koala-nest/src/test/core/profiles.guard.spec.ts +42 -0
- package/koala-nest/src/test/core/resolve-api-host.spec.ts +20 -0
- package/koala-nest/src/test/core/schemas.spec.ts +95 -0
- package/koala-nest/src/test/create-auth-e2e-test-app.ts +22 -0
- package/koala-nest/src/test/create-e2e-test-app.ts +14 -0
- package/koala-nest/src/test/e2e-context.ts +7 -0
- package/koala-nest/src/test/host/controllers/auth/auth.controller.e2e.spec.ts +87 -0
- package/koala-nest/src/test/host/controllers/person/lazy-loading.e2e.spec.ts +181 -0
- package/koala-nest/src/test/host/controllers/person/person.controller.e2e.spec.ts +148 -0
- package/koala-nest/src/test/host/errors.filter.spec.ts +75 -0
- package/koala-nest/src/test/host/is-public-open-api.spec.ts +60 -0
- package/koala-nest/src/test/host/oauth-callback.controller.spec.ts +18 -0
- package/koala-nest/src/test/infra/cache-service.provider.spec.ts +21 -0
- package/koala-nest/src/test/infra/in-memory-cache.service.spec.ts +49 -0
- package/koala-nest/src/test/infra/jwt-token.service.spec.ts +28 -0
- package/koala-nest/src/test/infra/logged-user-info.service.spec.ts +33 -0
- package/koala-nest/src/test/infra/oauth2-auth.service.spec.ts +112 -0
- package/koala-nest/src/test/infra/red-lock.service.spec.ts +43 -0
- package/koala-nest/src/test/infra/redis-cache.service.spec.ts +100 -0
- package/koala-nest/src/test/infra/redis-indicator.service.spec.ts +75 -0
- package/koala-nest/src/test/mockup/person/person.entities.ts +35 -0
- package/koala-nest/src/test/mockup/person/person.requests.ts +23 -0
- package/koala-nest/src/test/mockup/person/person.responses.ts +31 -0
- package/koala-nest/src/test/services/cache.stub.ts +41 -0
- package/koala-nest/src/test/services/fake-logging.service.ts +13 -0
- package/koala-nest/src/test/services/fake-red-lock.service.ts +11 -0
- package/koala-nest/src/test/services/logged-user-info.fake-service.ts +18 -0
- package/koala-nest/src/test/setup-e2e.ts +66 -0
- package/koala-nest/src/test/setup.ts +1 -0
- package/koala-nest/src/test/utils/configure-test-app.ts +24 -0
- package/koala-nest/src/test/utils/create-e2e-database.ts +50 -0
- package/koala-nest/src/test/utils/e2e-database-client.ts +9 -0
- package/koala-nest/src/test/utils/guard-test-context.ts +28 -0
- package/koala-nest/src/test/utils/jwt-test-keys.ts +27 -0
- package/koala-nest/tsconfig.build.json +8 -0
- package/koala-nest/tsconfig.json +36 -0
- package/koala-nest/tsconfig.spec.json +11 -0
- package/package.json +19 -29
- package/core/backgroud-services/cron-service/cron-job.handler.base.d.ts +0 -16
- package/core/backgroud-services/cron-service/cron-job.handler.base.js +0 -49
- package/core/backgroud-services/event-service/event-class.d.ts +0 -5
- package/core/backgroud-services/event-service/event-class.js +0 -11
- package/core/backgroud-services/event-service/event-handler.base.d.ts +0 -8
- package/core/backgroud-services/event-service/event-handler.base.js +0 -14
- package/core/backgroud-services/event-service/event-is-trigger.d.ts +0 -3
- package/core/backgroud-services/event-service/event-is-trigger.js +0 -7
- package/core/backgroud-services/event-service/event-job.d.ts +0 -13
- package/core/backgroud-services/event-service/event-job.js +0 -21
- package/core/backgroud-services/event-service/event-queue.d.ts +0 -18
- package/core/backgroud-services/event-service/event-queue.js +0 -65
- package/core/constants/query-params.d.ts +0 -6
- package/core/constants/query-params.js +0 -8
- package/core/controllers/base.controller.d.ts +0 -4
- package/core/controllers/base.controller.js +0 -6
- package/core/controllers/controller.decorator.d.ts +0 -2
- package/core/controllers/controller.decorator.js +0 -11
- package/core/controllers/created-registre-response.base.d.ts +0 -10
- package/core/controllers/created-registre-response.base.js +0 -35
- package/core/controllers/list-response.base.d.ts +0 -4
- package/core/controllers/list-response.base.js +0 -21
- package/core/controllers/pagination.request.d.ts +0 -10
- package/core/controllers/pagination.request.js +0 -56
- package/core/controllers/router-config.base.d.ts +0 -7
- package/core/controllers/router-config.base.js +0 -18
- package/core/controllers/schemas/boolean.schema.d.ts +0 -2
- package/core/controllers/schemas/boolean.schema.js +0 -12
- package/core/controllers/schemas/document-number.schema.d.ts +0 -1
- package/core/controllers/schemas/document-number.schema.js +0 -26
- package/core/controllers/schemas/email.schema.d.ts +0 -1
- package/core/controllers/schemas/email.schema.js +0 -13
- package/core/controllers/schemas/list-query.schema.d.ts +0 -17
- package/core/controllers/schemas/list-query.schema.js +0 -19
- package/core/controllers/schemas/native-enum.schema.d.ts +0 -7
- package/core/controllers/schemas/native-enum.schema.js +0 -28
- package/core/controllers/schemas/set-mask-document-number.schema.d.ts +0 -1
- package/core/controllers/schemas/set-mask-document-number.schema.js +0 -13
- package/core/database/entity.base.d.ts +0 -27
- package/core/database/entity.base.js +0 -145
- package/core/database/entity.decorator.d.ts +0 -12
- package/core/database/entity.decorator.js +0 -37
- package/core/database/prisma-client-with-custom-transaction.interface.d.ts +0 -8
- package/core/database/prisma-client-with-custom-transaction.interface.js +0 -2
- package/core/database/prisma-resolver.d.ts +0 -2
- package/core/database/prisma-resolver.js +0 -74
- package/core/database/prisma-transactional-client.d.ts +0 -11
- package/core/database/prisma-transactional-client.js +0 -25
- package/core/database/prisma.service.d.ts +0 -24
- package/core/database/prisma.service.js +0 -104
- package/core/database/repository.base.d.ts +0 -83
- package/core/database/repository.base.js +0 -668
- package/core/dtos/pagination.dto.d.ts +0 -9
- package/core/dtos/pagination.dto.js +0 -49
- package/core/errors/bad-request.error.d.ts +0 -5
- package/core/errors/bad-request.error.js +0 -10
- package/core/errors/conflict.error.d.ts +0 -4
- package/core/errors/conflict.error.js +0 -10
- package/core/errors/error.base.d.ts +0 -4
- package/core/errors/error.base.js +0 -11
- package/core/errors/no-content.error.d.ts +0 -5
- package/core/errors/no-content.error.js +0 -10
- package/core/errors/not-allowed.error.d.ts +0 -5
- package/core/errors/not-allowed.error.js +0 -10
- package/core/errors/resource-not-found.error.d.ts +0 -5
- package/core/errors/resource-not-found.error.js +0 -10
- package/core/errors/use-case-error.d.ts +0 -3
- package/core/errors/use-case-error.js +0 -2
- package/core/errors/user-already-exist.error.d.ts +0 -4
- package/core/errors/user-already-exist.error.js +0 -10
- package/core/errors/wrong-credentials.error.d.ts +0 -4
- package/core/errors/wrong-credentials.error.js +0 -10
- package/core/health-check/health-check.controller.d.ts +0 -5
- package/core/health-check/health-check.controller.js +0 -32
- package/core/health-check/health-check.module.d.ts +0 -2
- package/core/health-check/health-check.module.js +0 -19
- package/core/index.d.ts +0 -18
- package/core/index.js +0 -7
- package/core/koala-app.d.ts +0 -64
- package/core/koala-app.js +0 -258
- package/core/koala-global-vars.d.ts +0 -7
- package/core/koala-global-vars.js +0 -9
- package/core/koala-nest-database.module.d.ts +0 -16
- package/core/koala-nest-database.module.js +0 -52
- package/core/koala-nest-http.module.d.ts +0 -13
- package/core/koala-nest-http.module.js +0 -37
- package/core/koala-nest.module.d.ts +0 -17
- package/core/koala-nest.module.js +0 -66
- package/core/mapping/auto-mapping-class-context.d.ts +0 -16
- package/core/mapping/auto-mapping-class-context.js +0 -18
- package/core/mapping/auto-mapping-context.d.ts +0 -11
- package/core/mapping/auto-mapping-context.js +0 -24
- package/core/mapping/auto-mapping-list.d.ts +0 -28
- package/core/mapping/auto-mapping-list.js +0 -99
- package/core/mapping/auto-mapping-profile.d.ts +0 -3
- package/core/mapping/auto-mapping-profile.js +0 -6
- package/core/mapping/auto-mapping.decorator.d.ts +0 -9
- package/core/mapping/auto-mapping.decorator.js +0 -27
- package/core/mapping/auto-mapping.module.d.ts +0 -5
- package/core/mapping/auto-mapping.module.js +0 -29
- package/core/mapping/auto-mapping.service.d.ts +0 -20
- package/core/mapping/auto-mapping.service.js +0 -197
- package/core/mapping/create-map.d.ts +0 -3
- package/core/mapping/create-map.js +0 -7
- package/core/mapping/for-member.d.ts +0 -5
- package/core/mapping/for-member.js +0 -8
- package/core/request-overflow/request-handler.base.d.ts +0 -4
- package/core/request-overflow/request-handler.base.js +0 -6
- package/core/request-overflow/request-result.d.ts +0 -15
- package/core/request-overflow/request-result.js +0 -37
- package/core/request-overflow/request-validator.base.d.ts +0 -7
- package/core/request-overflow/request-validator.base.js +0 -26
- package/core/security/strategies/api-key.strategy.d.ts +0 -16
- package/core/security/strategies/api-key.strategy.js +0 -31
- package/core/utils/assing-object.d.ts +0 -5
- package/core/utils/assing-object.js +0 -6
- package/core/utils/automap-cycle-context.d.ts +0 -6
- package/core/utils/automap-cycle-context.js +0 -33
- package/core/utils/env.config.d.ts +0 -6
- package/core/utils/env.config.js +0 -18
- package/core/utils/filter-request-params.d.ts +0 -13
- package/core/utils/filter-request-params.js +0 -22
- package/core/utils/find-on-list.d.ts +0 -2
- package/core/utils/find-on-list.js +0 -13
- package/core/utils/generate-prisma-include-schema.d.ts +0 -9
- package/core/utils/generate-prisma-include-schema.js +0 -60
- package/core/utils/get-type-by-prop.d.ts +0 -2
- package/core/utils/get-type-by-prop.js +0 -11
- package/core/utils/hydrate-entity-from-cache.d.ts +0 -22
- package/core/utils/hydrate-entity-from-cache.js +0 -76
- package/core/utils/instanciate-class-with-dependencies-injection.d.ts +0 -2
- package/core/utils/instanciate-class-with-dependencies-injection.js +0 -10
- package/core/utils/interfaces/icomparable.d.ts +0 -5
- package/core/utils/interfaces/icomparable.js +0 -6
- package/core/utils/is-plain-object.d.ts +0 -1
- package/core/utils/is-plain-object.js +0 -8
- package/core/utils/list.d.ts +0 -39
- package/core/utils/list.js +0 -167
- package/core/utils/promise-all.d.ts +0 -7
- package/core/utils/promise-all.js +0 -19
- package/core/utils/proxy.d.ts +0 -1
- package/core/utils/proxy.js +0 -27
- package/core/utils/set-mask-document-number.d.ts +0 -1
- package/core/utils/set-mask-document-number.js +0 -13
- package/core/validators/file-validator.d.ts +0 -27
- package/core/validators/file-validator.js +0 -94
- package/decorators/api-exclude-endpoint-diff-develop.decorator.d.ts +0 -1
- package/decorators/api-exclude-endpoint-diff-develop.decorator.js +0 -9
- package/decorators/api-property-enum.decorator.d.ts +0 -8
- package/decorators/api-property-enum.decorator.js +0 -21
- package/decorators/api-property-only-develop.decorator.d.ts +0 -2
- package/decorators/api-property-only-develop.decorator.js +0 -9
- package/decorators/cookies.decorator.d.ts +0 -1
- package/decorators/cookies.decorator.js +0 -8
- package/decorators/is-public.decorator.d.ts +0 -2
- package/decorators/is-public.decorator.js +0 -7
- package/decorators/upload.decorator.d.ts +0 -1
- package/decorators/upload.decorator.js +0 -18
- package/env/env.d.ts +0 -25
- package/env/env.js +0 -14
- package/env/env.module.d.ts +0 -2
- package/env/env.module.js +0 -20
- package/env/env.service.d.ts +0 -7
- package/env/env.service.js +0 -28
- package/filters/domain-errors.filter.d.ts +0 -18
- package/filters/domain-errors.filter.js +0 -92
- package/filters/global-exception.filter.d.ts +0 -8
- package/filters/global-exception.filter.js +0 -68
- package/filters/prisma-validation-exception.filter.d.ts +0 -10
- package/filters/prisma-validation-exception.filter.js +0 -82
- package/filters/zod-errors.filter.d.ts +0 -9
- package/filters/zod-errors.filter.js +0 -60
- package/services/logging/ilogging.service.d.ts +0 -16
- package/services/logging/ilogging.service.js +0 -6
- package/services/logging/logging.service.d.ts +0 -4
- package/services/logging/logging.service.js +0 -20
- package/services/redis/iredis.service.d.ts +0 -6
- package/services/redis/iredis.service.js +0 -6
- package/services/redis/redis.service.d.ts +0 -14
- package/services/redis/redis.service.js +0 -65
- package/services/redlock/ired-lock.service.d.ts +0 -4
- package/services/redlock/ired-lock.service.js +0 -6
- package/services/redlock/red-lock.service.d.ts +0 -9
- package/services/redlock/red-lock.service.js +0 -46
- package/test/koala-app-test-dependencies.d.ts +0 -10
- package/test/koala-app-test-dependencies.js +0 -13
- package/test/koala-app-test.d.ts +0 -22
- package/test/koala-app-test.js +0 -77
- package/test/repositories/in-memory-base.repository.d.ts +0 -17
- package/test/repositories/in-memory-base.repository.js +0 -67
- package/test/services/fake-logging.service.d.ts +0 -4
- package/test/services/fake-logging.service.js +0 -9
- package/test/services/fake-red-lock.service.d.ts +0 -5
- package/test/services/fake-red-lock.service.js +0 -11
- package/test/utils/create-e2e-database.d.ts +0 -7
- package/test/utils/create-e2e-database.js +0 -38
- package/test/utils/e2e-database-client.d.ts +0 -7
- package/test/utils/e2e-database-client.js +0 -12
- package/test/utils/wait-for.d.ts +0 -1
- package/test/utils/wait-for.js +0 -21
- package/tsconfig.lib.tsbuildinfo +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import color from "picocolors";
|
|
3
|
+
import {
|
|
4
|
+
AddArgKind,
|
|
5
|
+
AuthStrategy,
|
|
6
|
+
ExtraFeature,
|
|
7
|
+
FEATURE_PROMPT_LABELS
|
|
8
|
+
} from "../../constants/domain.js";
|
|
9
|
+
import { addProjectFeatures } from "../../utils/add-project-features.js";
|
|
10
|
+
import { assertNotCancel } from "../../utils/cancel.js";
|
|
11
|
+
import {
|
|
12
|
+
assertKoalaProject,
|
|
13
|
+
dedupeAddArgs,
|
|
14
|
+
detectProjectState,
|
|
15
|
+
listAvailableAddOptions,
|
|
16
|
+
parseAddArgs
|
|
17
|
+
} from "../../utils/detect-project-state.js";
|
|
18
|
+
function formatResultSummary(results) {
|
|
19
|
+
if (results.length === 0) {
|
|
20
|
+
return color.dim("Nenhuma alteração necessária.");
|
|
21
|
+
}
|
|
22
|
+
return results.map((result) => {
|
|
23
|
+
if (result.installed) {
|
|
24
|
+
return `${color.green("✓")} ${result.label}`;
|
|
25
|
+
}
|
|
26
|
+
return `${color.yellow("○")} ${result.label} — ${result.reason ?? "já instalado"}`;
|
|
27
|
+
}).join(`
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
async function resolveAddArgsFromPrompt() {
|
|
31
|
+
const state = detectProjectState(".");
|
|
32
|
+
const available = listAvailableAddOptions(state);
|
|
33
|
+
const args = [];
|
|
34
|
+
if (available.authStrategies.length > 0) {
|
|
35
|
+
const authStrategies = assertNotCancel(await p.multiselect({
|
|
36
|
+
message: "Estratégias de autenticação para adicionar",
|
|
37
|
+
options: [
|
|
38
|
+
{
|
|
39
|
+
value: AuthStrategy.JWT,
|
|
40
|
+
label: "JWT",
|
|
41
|
+
hint: "RS256 + guards globais"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
value: AuthStrategy.OAUTH2,
|
|
45
|
+
label: "OAuth2",
|
|
46
|
+
hint: "JWT + OAuth2 genérico"
|
|
47
|
+
}
|
|
48
|
+
].filter((option) => available.authStrategies.includes(option.value)),
|
|
49
|
+
required: false
|
|
50
|
+
}));
|
|
51
|
+
if (authStrategies.length > 0) {
|
|
52
|
+
args.push({ kind: AddArgKind.AUTH, strategies: authStrategies });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (available.features.length > 0) {
|
|
56
|
+
const features = assertNotCancel(await p.multiselect({
|
|
57
|
+
message: "Funcionalidades para adicionar",
|
|
58
|
+
options: available.features.map((feature) => ({
|
|
59
|
+
value: feature,
|
|
60
|
+
label: FEATURE_PROMPT_LABELS[feature]
|
|
61
|
+
})),
|
|
62
|
+
required: false
|
|
63
|
+
}));
|
|
64
|
+
for (const feature of features) {
|
|
65
|
+
args.push({ kind: AddArgKind.FEATURE, feature });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return dedupeAddArgs(args);
|
|
69
|
+
}
|
|
70
|
+
export async function runAdd(rawArgs = process.argv.slice(3)) {
|
|
71
|
+
p.intro(`${color.bgCyan(color.black(" koala-nest "))} ${color.dim("Adicionar funcionalidades")}`);
|
|
72
|
+
assertKoalaProject(".");
|
|
73
|
+
const state = detectProjectState(".");
|
|
74
|
+
const available = listAvailableAddOptions(state);
|
|
75
|
+
if (available.authStrategies.length === 0 && available.features.length === 0) {
|
|
76
|
+
p.outro(color.green("Este projeto já possui todas as funcionalidades disponíveis."));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let args;
|
|
80
|
+
try {
|
|
81
|
+
args = rawArgs.length > 0 ? dedupeAddArgs(parseAddArgs(rawArgs)) : await resolveAddArgsFromPrompt();
|
|
82
|
+
} catch (error) {
|
|
83
|
+
p.cancel(error instanceof Error ? error.message : String(error));
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (args.length === 0) {
|
|
87
|
+
p.cancel("Nenhuma funcionalidade selecionada.");
|
|
88
|
+
process.exit(0);
|
|
89
|
+
}
|
|
90
|
+
const spinner = p.spinner();
|
|
91
|
+
spinner.start("Instalando funcionalidades...");
|
|
92
|
+
const results = await addProjectFeatures(".", args);
|
|
93
|
+
spinner.stop("Instalação concluída.");
|
|
94
|
+
p.note(formatResultSummary(results), "Resumo");
|
|
95
|
+
p.outro(color.green("Funcionalidades aplicadas.") + color.dim(`
|
|
96
|
+
Revise o .env e reinicie a aplicação se necessário.`));
|
|
97
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import color from "picocolors";
|
|
2
|
+
import { CLI_VERSION } from "../constants/version.js";
|
|
3
|
+
export function printHelp() {
|
|
4
|
+
console.log(`
|
|
5
|
+
${color.bold("Koala Nest CLI")} ${color.dim(`v${CLI_VERSION}`)}
|
|
6
|
+
|
|
7
|
+
${color.cyan("Uso:")}
|
|
8
|
+
kl-nest ${color.dim("<comando>")} ${color.dim("[opções]")}
|
|
9
|
+
|
|
10
|
+
${color.cyan("Opções globais:")}
|
|
11
|
+
${color.dim("--verbose")} Exibe a saída dos comandos externos (npm, bun, nest, …)
|
|
12
|
+
|
|
13
|
+
${color.cyan("New — opções:")}
|
|
14
|
+
${color.dim("-y, --yes")} Pula perguntas e cria com os argumentos informados
|
|
15
|
+
${color.dim("<nome>")} Nome do projeto (não pergunta de novo se já informado)
|
|
16
|
+
${color.dim("--template, -t")} ${color.dim("default")} ou ${color.dim("crud")}
|
|
17
|
+
${color.dim("--pm")} ${color.dim("bun")}, ${color.dim("npm")} ou ${color.dim("pnpm")}
|
|
18
|
+
${color.dim("--auth")} ${color.dim("none")}, ${color.dim("jwt")} ou ${color.dim("oauth2")}
|
|
19
|
+
${color.dim("--features")} ${color.dim("cache,health,cron,events")} (vírgula)
|
|
20
|
+
|
|
21
|
+
${color.cyan("Comandos:")}
|
|
22
|
+
${color.green("new")} Cria um novo projeto
|
|
23
|
+
${color.green("add")} Adiciona funcionalidades a um projeto existente
|
|
24
|
+
${color.green("version")} Exibe a versão da CLI
|
|
25
|
+
${color.green("help")} Exibe esta ajuda
|
|
26
|
+
|
|
27
|
+
${color.cyan("Add — funcionalidades:")}
|
|
28
|
+
${color.dim("auth jwt|oauth2")} Autenticação
|
|
29
|
+
${color.dim("cache")} Cache Redis (+ exemplos no CRUD)
|
|
30
|
+
${color.dim("health")} GET /health
|
|
31
|
+
${color.dim("cron")} Jobs com expressão cron
|
|
32
|
+
${color.dim("events")} Jobs reativos a eventos
|
|
33
|
+
|
|
34
|
+
${color.cyan("Exemplos:")}
|
|
35
|
+
kl-nest new example
|
|
36
|
+
kl-nest new my-api -y --template default --pm bun --auth none
|
|
37
|
+
kl-nest new my-api -y --template crud --pm bun --auth jwt
|
|
38
|
+
kl-nest new --verbose
|
|
39
|
+
kl-nest add cache
|
|
40
|
+
kl-nest add auth jwt health --verbose
|
|
41
|
+
kl-nest add cron events
|
|
42
|
+
kl-nest version
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function configureTestRunner(packageJson, packageManager) {
|
|
2
|
+
const scripts = packageJson.scripts;
|
|
3
|
+
const devDependencies = packageJson.devDependencies;
|
|
4
|
+
if (packageManager === "bun") {
|
|
5
|
+
scripts.test = "bun test";
|
|
6
|
+
scripts["test:watch"] = "bun test --watch";
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
scripts.test = "vitest run";
|
|
10
|
+
scripts["test:watch"] = "vitest";
|
|
11
|
+
devDependencies.vitest = "^4.1.8";
|
|
12
|
+
devDependencies["vite-tsconfig-paths"] = "^5.1.4";
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { DDD_LAYER_FOLDERS } from "../../constants/domain.js";
|
|
4
|
+
import { patchGeneratedProjectConfig } from "../../utils/patch-generated-project.js";
|
|
5
|
+
import { runCommand } from "../../utils/run-command.js";
|
|
6
|
+
import { configureTestRunner } from "./configure-test-runner.js";
|
|
7
|
+
export async function createDDDStructure(projectName, packageManager) {
|
|
8
|
+
const folders = [...DDD_LAYER_FOLDERS];
|
|
9
|
+
for (const folder of folders) {
|
|
10
|
+
mkdirSync(path.join(process.cwd(), projectName, folder), {
|
|
11
|
+
recursive: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
rmSync(path.join(process.cwd(), projectName, "test"), {
|
|
15
|
+
recursive: true,
|
|
16
|
+
force: true
|
|
17
|
+
});
|
|
18
|
+
rmSync(path.join(process.cwd(), projectName, "src/app.controller.spec.ts"), {
|
|
19
|
+
force: true
|
|
20
|
+
});
|
|
21
|
+
rmSync(path.join(process.cwd(), projectName, "src/app.controller.ts"), {
|
|
22
|
+
force: true
|
|
23
|
+
});
|
|
24
|
+
rmSync(path.join(process.cwd(), projectName, "src/app.module.ts"), {
|
|
25
|
+
force: true
|
|
26
|
+
});
|
|
27
|
+
rmSync(path.join(process.cwd(), projectName, "src/app.service.ts"), {
|
|
28
|
+
force: true
|
|
29
|
+
});
|
|
30
|
+
rmSync(path.join(process.cwd(), projectName, "src/main.ts"), { force: true });
|
|
31
|
+
const packageJson = JSON.parse(readFileSync(path.join(process.cwd(), projectName, "package.json"), "utf8"));
|
|
32
|
+
packageJson.packageManager = packageManager;
|
|
33
|
+
const migrationDatasource = "-d ./src/infra/database/migrations/migration-datasource.ts";
|
|
34
|
+
const typeormCli = "./node_modules/typeorm/cli.js";
|
|
35
|
+
const migrationRunner = packageManager === "bun" ? "bun" : "node --import ts-node/register/transpile-only";
|
|
36
|
+
packageJson.scripts["migration:generate"] = packageManager === "bun" ? "bun ./src/infra/database/migrations/generate-migration.ts" : "node --import ts-node/register/transpile-only ./src/infra/database/migrations/generate-migration.ts";
|
|
37
|
+
packageJson.scripts["migration:run"] = `${migrationRunner} ${typeormCli} migration:run ${migrationDatasource}`;
|
|
38
|
+
packageJson.scripts["migration:revert"] = `${migrationRunner} ${typeormCli} migration:revert ${migrationDatasource}`;
|
|
39
|
+
packageJson.devDependencies ??= {};
|
|
40
|
+
configureTestRunner(packageJson, packageManager);
|
|
41
|
+
delete packageJson.scripts["test:cov"];
|
|
42
|
+
delete packageJson.scripts["test:debug"];
|
|
43
|
+
delete packageJson.scripts["test:e2e"];
|
|
44
|
+
delete packageJson.jest;
|
|
45
|
+
delete packageJson.devDependencies["@types/jest"];
|
|
46
|
+
delete packageJson.devDependencies["@types/supertest"];
|
|
47
|
+
delete packageJson.devDependencies["ts-jest"];
|
|
48
|
+
delete packageJson.devDependencies["supertest"];
|
|
49
|
+
writeFileSync(path.join(process.cwd(), projectName, "package.json"), JSON.stringify(packageJson, null, 2));
|
|
50
|
+
patchGeneratedProjectConfig(path.join(process.cwd(), projectName));
|
|
51
|
+
await runCommand([packageManager, "install"], path.join(process.cwd(), projectName));
|
|
52
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cpSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
writeFileSync
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { PackageManagerRunner } from "../../constants/package-manager.js";
|
|
11
|
+
import { runCommand } from "../../utils/run-command.js";
|
|
12
|
+
function updatePackageName(projectDir, projectName) {
|
|
13
|
+
const packageJsonPath = path.join(projectDir, "package.json");
|
|
14
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
15
|
+
packageJson.name = projectName;
|
|
16
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
function copyScaffoldFromCache(scaffoldCache, projectName, cwd) {
|
|
20
|
+
const projectDir = path.join(cwd, projectName);
|
|
21
|
+
cpSync(scaffoldCache, projectDir, { recursive: true });
|
|
22
|
+
updatePackageName(projectDir, projectName);
|
|
23
|
+
}
|
|
24
|
+
function persistScaffoldCache(projectDir, scaffoldCache) {
|
|
25
|
+
rmSync(scaffoldCache, { recursive: true, force: true });
|
|
26
|
+
mkdirSync(scaffoldCache, { recursive: true });
|
|
27
|
+
cpSync(projectDir, scaffoldCache, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
export async function createEmptyNestProject(projectName, packageManager) {
|
|
30
|
+
const cwd = process.cwd();
|
|
31
|
+
const projectDir = path.join(cwd, projectName);
|
|
32
|
+
const scaffoldCache = process.env.KOALA_NEST_SCAFFOLD_CACHE;
|
|
33
|
+
if (scaffoldCache && packageManager === "bun" && existsSync(path.join(scaffoldCache, "node_modules"))) {
|
|
34
|
+
copyScaffoldFromCache(scaffoldCache, projectName, cwd);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const command = PackageManagerRunner[packageManager];
|
|
38
|
+
await runCommand([
|
|
39
|
+
command,
|
|
40
|
+
"@nestjs/cli",
|
|
41
|
+
"new",
|
|
42
|
+
projectName,
|
|
43
|
+
"--package-manager",
|
|
44
|
+
"npm",
|
|
45
|
+
"--skip-git"
|
|
46
|
+
]);
|
|
47
|
+
if (packageManager !== "npm") {
|
|
48
|
+
rmSync(path.join(cwd, projectName, "package-lock.json"));
|
|
49
|
+
rmSync(path.join(cwd, projectName, "node_modules"), {
|
|
50
|
+
recursive: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
await runCommand([packageManager, "install"], projectDir);
|
|
54
|
+
const scaffoldCacheBuild = process.env.KOALA_NEST_SCAFFOLD_CACHE_BUILD;
|
|
55
|
+
if (scaffoldCacheBuild && packageManager === "bun") {
|
|
56
|
+
persistScaffoldCache(projectDir, scaffoldCacheBuild);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { cpSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { getSourceCodePath } from "../../utils/get-source-code-path.js";
|
|
4
|
+
import { resolveProjectPath } from "../../utils/resolve-project-path.js";
|
|
5
|
+
export function fixLintConfig(projectName) {
|
|
6
|
+
const projectPath = resolveProjectPath(projectName);
|
|
7
|
+
const tsconfigPath = path.join(projectPath, "tsconfig.json");
|
|
8
|
+
const tsconfigProjectContent = JSON.parse(readFileSync(tsconfigPath, "utf8"));
|
|
9
|
+
tsconfigProjectContent.compilerOptions ??= {};
|
|
10
|
+
tsconfigProjectContent.compilerOptions.baseUrl = "./";
|
|
11
|
+
tsconfigProjectContent.compilerOptions.paths = {
|
|
12
|
+
...tsconfigProjectContent.compilerOptions.paths ?? {},
|
|
13
|
+
"@/*": ["./src/*"]
|
|
14
|
+
};
|
|
15
|
+
writeFileSync(tsconfigPath, `${JSON.stringify(tsconfigProjectContent, null, 2)}
|
|
16
|
+
`);
|
|
17
|
+
const eslintKoalaNestConfig = path.join(getSourceCodePath(), "eslint.config.mjs");
|
|
18
|
+
const eslintProjectConfig = path.join(projectPath, "eslint.config.mjs");
|
|
19
|
+
cpSync(eslintKoalaNestConfig, eslintProjectConfig, { force: true });
|
|
20
|
+
const packageJsonProjectContent = JSON.parse(readFileSync(path.join(projectPath, "package.json"), "utf8"));
|
|
21
|
+
packageJsonProjectContent.scripts.lint = 'eslint "src/**/*.ts" --fix';
|
|
22
|
+
packageJsonProjectContent.scripts.format = 'prettier --write "src/**/*.ts"';
|
|
23
|
+
writeFileSync(path.join(projectPath, "package.json"), JSON.stringify(packageJsonProjectContent, null, 2));
|
|
24
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as p from "@clack/prompts";
|
|
2
|
+
import color from "picocolors";
|
|
3
|
+
import { assertNotCancel } from "../../utils/cancel.js";
|
|
4
|
+
import { applyOptionalFeatures } from "../../utils/apply-optional-features.js";
|
|
5
|
+
import {
|
|
6
|
+
buildNewProjectConfig,
|
|
7
|
+
parseNewArgs
|
|
8
|
+
} from "../../utils/parse-new-args.js";
|
|
9
|
+
import { createEmptyNestProject } from "./create-empty-nest-project.js";
|
|
10
|
+
import { createDDDStructure } from "./create-ddd-structure.js";
|
|
11
|
+
import {
|
|
12
|
+
AuthStrategy,
|
|
13
|
+
CRUD_BUNDLED_FEATURES,
|
|
14
|
+
DEFAULT_PACKAGE_MANAGER,
|
|
15
|
+
ExtraFeature,
|
|
16
|
+
FEATURE_LABELS,
|
|
17
|
+
FEATURE_PROMPT_LABELS,
|
|
18
|
+
formatAuthStrategies,
|
|
19
|
+
Template,
|
|
20
|
+
TEMPLATE_LABELS
|
|
21
|
+
} from "../../constants/domain.js";
|
|
22
|
+
import {
|
|
23
|
+
installModule,
|
|
24
|
+
Modules,
|
|
25
|
+
resolveNewProjectOptions,
|
|
26
|
+
resolveProjectFeatures
|
|
27
|
+
} from "../../utils/install-module.js";
|
|
28
|
+
import { fixLintConfig } from "./fix-lint-config.js";
|
|
29
|
+
async function promptAuthStrategies(template) {
|
|
30
|
+
const isCrud = template === Template.CRUD_SAMPLE;
|
|
31
|
+
return assertNotCancel(await p.multiselect({
|
|
32
|
+
message: isCrud ? "Estratégias de autenticação (incluídas no exemplo CRUD)" : "Estratégias de autenticação",
|
|
33
|
+
options: [
|
|
34
|
+
{
|
|
35
|
+
value: AuthStrategy.JWT,
|
|
36
|
+
label: "JWT",
|
|
37
|
+
hint: "RS256 + guards globais"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
value: AuthStrategy.OAUTH2,
|
|
41
|
+
label: "OAuth2",
|
|
42
|
+
hint: "JWT + OAuth2 genérico"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
value: "api-key",
|
|
46
|
+
label: "API Key",
|
|
47
|
+
hint: "em breve",
|
|
48
|
+
disabled: true
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
required: isCrud
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
async function promptExtraFeatures(template) {
|
|
55
|
+
if (template === Template.CRUD_SAMPLE) {
|
|
56
|
+
const bundled = CRUD_BUNDLED_FEATURES.map((feature) => FEATURE_LABELS[feature]).join(", ");
|
|
57
|
+
p.note(`O exemplo CRUD já inclui: ${bundled} e autenticação.
|
|
58
|
+
` + "Escolha abaixo apenas funcionalidades adicionais.", "Incluso no template");
|
|
59
|
+
return assertNotCancel(await p.multiselect({
|
|
60
|
+
message: "Funcionalidades extras adicionais",
|
|
61
|
+
options: [
|
|
62
|
+
{
|
|
63
|
+
value: ExtraFeature.HEALTH_CHECK,
|
|
64
|
+
label: FEATURE_PROMPT_LABELS[ExtraFeature.HEALTH_CHECK]
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
required: false
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
return assertNotCancel(await p.multiselect({
|
|
71
|
+
message: "Funcionalidades extras",
|
|
72
|
+
options: [
|
|
73
|
+
{
|
|
74
|
+
value: ExtraFeature.CACHE,
|
|
75
|
+
label: FEATURE_PROMPT_LABELS[ExtraFeature.CACHE],
|
|
76
|
+
hint: "ICacheService + ioredis"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
value: ExtraFeature.HEALTH_CHECK,
|
|
80
|
+
label: FEATURE_PROMPT_LABELS[ExtraFeature.HEALTH_CHECK]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
value: ExtraFeature.INTERNAL_CRON_JOBS,
|
|
84
|
+
label: FEATURE_PROMPT_LABELS[ExtraFeature.INTERNAL_CRON_JOBS],
|
|
85
|
+
hint: "cron-parser + bases"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
value: ExtraFeature.INTERNAL_EVENT_JOBS,
|
|
89
|
+
label: FEATURE_PROMPT_LABELS[ExtraFeature.INTERNAL_EVENT_JOBS],
|
|
90
|
+
hint: "EventJob + bases"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
required: false
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
async function promptProjectName() {
|
|
97
|
+
return assertNotCancel(await p.text({
|
|
98
|
+
message: "Nome do projeto",
|
|
99
|
+
placeholder: "my-api",
|
|
100
|
+
validate: (value) => value ? undefined : "Campo obrigatório"
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
async function promptPackageManager() {
|
|
104
|
+
return assertNotCancel(await p.select({
|
|
105
|
+
message: "Gerenciador de pacotes",
|
|
106
|
+
options: [
|
|
107
|
+
{ value: "bun", label: "Bun", hint: "recomendado" },
|
|
108
|
+
{ value: "npm", label: "npm" },
|
|
109
|
+
{ value: "pnpm", label: "pnpm" }
|
|
110
|
+
]
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
async function promptTemplate() {
|
|
114
|
+
return assertNotCancel(await p.select({
|
|
115
|
+
message: "Template",
|
|
116
|
+
options: [
|
|
117
|
+
{
|
|
118
|
+
value: Template.DEFAULT,
|
|
119
|
+
label: TEMPLATE_LABELS[Template.DEFAULT],
|
|
120
|
+
hint: "sem código de exemplo"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
value: Template.CRUD_SAMPLE,
|
|
124
|
+
label: TEMPLATE_LABELS[Template.CRUD_SAMPLE],
|
|
125
|
+
hint: "Person + auth, cache e jobs"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
async function resolveProjectInput(args) {
|
|
131
|
+
const parsed = parseNewArgs(args);
|
|
132
|
+
if (parsed.interactive) {
|
|
133
|
+
const name = parsed.projectName ?? await promptProjectName();
|
|
134
|
+
const packageManager = parsed.packageManager ?? await promptPackageManager();
|
|
135
|
+
const template = parsed.template ?? await promptTemplate();
|
|
136
|
+
const auth = parsed.auth ?? await promptAuthStrategies(template);
|
|
137
|
+
const features = parsed.features.length > 0 ? parsed.features : await promptExtraFeatures(template);
|
|
138
|
+
return buildNewProjectConfig(parsed, {
|
|
139
|
+
name,
|
|
140
|
+
packageManager,
|
|
141
|
+
template,
|
|
142
|
+
auth,
|
|
143
|
+
features
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!parsed.projectName) {
|
|
147
|
+
throw new Error("Informe o nome do projeto com -y. Ex.: kl-nest new my-api -y --template default --pm bun --auth none");
|
|
148
|
+
}
|
|
149
|
+
return buildNewProjectConfig(parsed, {
|
|
150
|
+
name: parsed.projectName,
|
|
151
|
+
packageManager: DEFAULT_PACKAGE_MANAGER,
|
|
152
|
+
template: Template.DEFAULT,
|
|
153
|
+
auth: [],
|
|
154
|
+
features: []
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
export async function runNew(args = []) {
|
|
158
|
+
p.intro(`${color.bgCyan(color.black(" koala-nest "))} ${color.dim("Criar novo projeto")}`);
|
|
159
|
+
let project;
|
|
160
|
+
try {
|
|
161
|
+
project = await resolveProjectInput(args);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
p.cancel(error instanceof Error ? error.message : String(error));
|
|
164
|
+
process.exit(1);
|
|
165
|
+
}
|
|
166
|
+
const { auth: authStrategies, features } = resolveNewProjectOptions(project.template, project.auth, project.features);
|
|
167
|
+
const spinner = p.spinner();
|
|
168
|
+
spinner.start("Criando projeto...");
|
|
169
|
+
await createEmptyNestProject(project.name, project.packageManager);
|
|
170
|
+
spinner.message("Definindo estrutura de pastas...");
|
|
171
|
+
await createDDDStructure(project.name, project.packageManager);
|
|
172
|
+
spinner.message("Aplicando configuração de lint...");
|
|
173
|
+
fixLintConfig(project.name);
|
|
174
|
+
spinner.message("Instalando módulo core...");
|
|
175
|
+
await installModule(Modules.CORE, project.template, project.name);
|
|
176
|
+
spinner.message("Instalando funcionalidades opcionais...");
|
|
177
|
+
await applyOptionalFeatures({
|
|
178
|
+
projectName: project.name,
|
|
179
|
+
template: project.template,
|
|
180
|
+
auth: authStrategies,
|
|
181
|
+
features
|
|
182
|
+
});
|
|
183
|
+
spinner.stop("Projeto criado com sucesso!");
|
|
184
|
+
const projectFeatures = resolveProjectFeatures(features, authStrategies);
|
|
185
|
+
const extrasSummary = [
|
|
186
|
+
project.template === Template.CRUD_SAMPLE ? color.dim("exemplo Person completo") : null,
|
|
187
|
+
projectFeatures.cacheWithRedis ? FEATURE_LABELS[ExtraFeature.CACHE] : null,
|
|
188
|
+
projectFeatures.cache && !projectFeatures.cacheWithRedis ? color.dim("cache em memória") : null,
|
|
189
|
+
projectFeatures.health ? FEATURE_LABELS[ExtraFeature.HEALTH_CHECK] : null,
|
|
190
|
+
projectFeatures.cronJobs ? FEATURE_LABELS[ExtraFeature.INTERNAL_CRON_JOBS] : null,
|
|
191
|
+
projectFeatures.eventJobs ? FEATURE_LABELS[ExtraFeature.INTERNAL_EVENT_JOBS] : null
|
|
192
|
+
].filter(Boolean).join(", ");
|
|
193
|
+
p.note([
|
|
194
|
+
`${color.bold("Projeto:")} ${project.name}`,
|
|
195
|
+
`${color.bold("Template:")} ${TEMPLATE_LABELS[project.template]}`,
|
|
196
|
+
`${color.bold("Gerenciador:")} ${project.packageManager}`,
|
|
197
|
+
`${color.bold("Autenticação:")} ${formatAuthStrategies(authStrategies)}`,
|
|
198
|
+
`${color.bold("Extras:")} ${extrasSummary || color.dim("nenhum")}`,
|
|
199
|
+
`${color.dim("Depois:")} cd ${project.name} && kl-nest add <feature>`
|
|
200
|
+
].join(`
|
|
201
|
+
`), "Resumo");
|
|
202
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const JWT_ONLY_REMOVE_PATHS = [
|
|
2
|
+
"src/application/auth/oauth2",
|
|
3
|
+
"src/host/controllers/oauth2",
|
|
4
|
+
"src/host/decorators/scalar-token-endpoint.decorator.ts",
|
|
5
|
+
"src/domain/auth/dtos/oauth-user-info.dto.ts",
|
|
6
|
+
"src/domain/auth/dtos/auth-provider-config.dto.ts",
|
|
7
|
+
"src/infra/auth/oauth2-auth.service.ts",
|
|
8
|
+
"src/core/types/auth-provider-config-response.type.ts",
|
|
9
|
+
"src/core/auth/oauth-provider.registry.ts",
|
|
10
|
+
"src/core/auth/parse-oauth2-provider-env.ts",
|
|
11
|
+
"src/test/application/exchange-code.handler.spec.ts",
|
|
12
|
+
"src/test/application/scalar-oauth-token.handler.spec.ts",
|
|
13
|
+
"src/test/application/auth-link.handler.spec.ts",
|
|
14
|
+
"src/test/host/oauth-callback.controller.spec.ts",
|
|
15
|
+
"src/test/infra/oauth2-auth.service.spec.ts",
|
|
16
|
+
"src/test/core/oauth-provider.registry.spec.ts"
|
|
17
|
+
];
|
|
18
|
+
export const OAUTH2_INSTALL_PATHS = [
|
|
19
|
+
"src/application/auth/oauth2",
|
|
20
|
+
"src/host/controllers/oauth2",
|
|
21
|
+
"src/host/decorators/scalar-token-endpoint.decorator.ts",
|
|
22
|
+
"src/domain/auth/dtos/oauth-user-info.dto.ts",
|
|
23
|
+
"src/domain/auth/dtos/auth-provider-config.dto.ts",
|
|
24
|
+
"src/infra/auth/oauth2-auth.service.ts",
|
|
25
|
+
"src/core/types/auth-provider-config-response.type.ts",
|
|
26
|
+
"src/core/auth/oauth-provider.registry.ts",
|
|
27
|
+
"src/core/auth/parse-oauth2-provider-env.ts",
|
|
28
|
+
"src/test/application/exchange-code.handler.spec.ts",
|
|
29
|
+
"src/test/application/scalar-oauth-token.handler.spec.ts",
|
|
30
|
+
"src/test/application/auth-link.handler.spec.ts",
|
|
31
|
+
"src/test/host/oauth-callback.controller.spec.ts",
|
|
32
|
+
"src/test/infra/oauth2-auth.service.spec.ts",
|
|
33
|
+
"src/test/core/oauth-provider.registry.spec.ts",
|
|
34
|
+
"src/test/core/env.spec.ts"
|
|
35
|
+
];
|
|
36
|
+
export const OAUTH2_ONLY_REMOVE_PATHS = [
|
|
37
|
+
"src/application/auth/login",
|
|
38
|
+
"src/host/controllers/auth/login.controller.ts",
|
|
39
|
+
"src/test/application/login.handler.spec.ts"
|
|
40
|
+
];
|
|
41
|
+
export const JWT_ONLY_FORBIDDEN_CONTENT = [
|
|
42
|
+
"IOAuth2Service",
|
|
43
|
+
"OAuth2AuthService",
|
|
44
|
+
"OAuthProviderRegistry",
|
|
45
|
+
"OAuthUserInfoDto",
|
|
46
|
+
"AuthProviderConfigDto",
|
|
47
|
+
"parse-oauth2-provider-env",
|
|
48
|
+
"oauth-provider.registry",
|
|
49
|
+
"oauth2-auth.service",
|
|
50
|
+
"OAuthAuthLinkHandler",
|
|
51
|
+
"OAuthExchangeCodeController",
|
|
52
|
+
"ScalarOAuthTokenHandler",
|
|
53
|
+
"OAUTH2_PROVIDERS",
|
|
54
|
+
"OAUTH2_PROVIDER_ENV",
|
|
55
|
+
"parseOAuth2ProviderEnv"
|
|
56
|
+
];
|