@koalarx/nest 3.1.49 → 4.0.1
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 +106 -444
- 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 -82
- 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
package/README.md
CHANGED
|
@@ -1,504 +1,166 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
|
|
3
|
-
</p>
|
|
1
|
+
# Koala Nest
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Facilitador para criar APIs NestJS com arquitetura DDD, focado em manutenção, escalabilidade e liberdade para evoluir o código no seu próprio repositório.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
Em vez de depender de uma biblioteca opaca, a CLI **copia módulos prontos para dentro do projeto** — abordagem semelhante ao [shadcn/ui](https://ui.shadcn.com). Você recebe código que pode ler, adaptar e manter sem amarras futuras.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
## O que está disponível hoje
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
| Recurso | Status |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Comando `new` (projeto interativo) | Disponível |
|
|
12
|
+
| Módulo **core** (DDD, TypeORM, Swagger, validação) | Disponível |
|
|
13
|
+
| Template **Padrão** (estrutura limpa) | Disponível |
|
|
14
|
+
| Template **Exemplo de CRUD** (Person) | Disponível |
|
|
15
|
+
| Autenticação (JWT, OAuth2) | Disponível na CLI |
|
|
16
|
+
| API Key | Em breve |
|
|
17
|
+
| Cache, health check, jobs internos | Disponível no template (exemplos Person) |
|
|
18
|
+
| Comando `add` (módulos avulsos) | Em breve |
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
## Instalação e uso
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
O pacote `@koalarx/nest` expõe o comando **`kl-nest`**. Você pode usá-lo de três formas:
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
### Instalação global (recomendado)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Acelere seu desenvolvimento com a **extensão oficial para VS Code**! Toda a documentação do Koala Nest integrada diretamente no GitHub Copilot através do Model Context Protocol.
|
|
27
|
-
|
|
28
|
-
**[📦 Instalar Extensão](https://marketplace.visualstudio.com/items?itemName=koalarx.koala-nest-mcp-docs)**
|
|
29
|
-
|
|
30
|
-
Basta instalar e perguntar ao Copilot sobre o Koala Nest - ele terá acesso instantâneo à documentação oficial!
|
|
31
|
-
|
|
32
|
-
> 💡 **Exemplo:** "Como criar um controller CRUD no Koala Nest?" - O Copilot responderá com base na documentação atualizada.
|
|
33
|
-
|
|
34
|
-
**[📖 Documentação da Extensão MCP](./docs/09-mcp-vscode-extension.md)**
|
|
35
|
-
|
|
36
|
-
## 🎯 O que você consegue fazer com @koalarx/nest
|
|
37
|
-
|
|
38
|
-
- ✅ **Implementar APIs REST completas** com CRUD automático
|
|
39
|
-
- ✅ **AutoMapping** transparente entre Request, Entity e Response
|
|
40
|
-
- ✅ **Validação automática** com Zod integrado
|
|
41
|
-
- ✅ **Testes unitários e E2E** simplificados
|
|
42
|
-
- ✅ **CronJobs** com suporte a múltiplos pods via Redis
|
|
43
|
-
- ✅ **EventJobs** para processamento assíncrono de eventos
|
|
44
|
-
- ✅ **Paginação** automaticamente documentada
|
|
45
|
-
- ✅ **Documentação OpenAPI (Swagger ou Scalar)** automática
|
|
46
|
-
|
|
47
|
-
## 📚 Documentação Completa
|
|
48
|
-
|
|
49
|
-
Toda a documentação está organizada em arquivos separados para facilitar a navegação:
|
|
50
|
-
|
|
51
|
-
| Documento | Descrição |
|
|
52
|
-
|-----------|-----------|
|
|
53
|
-
| [**EXAMPLE.md**](./docs/EXAMPLE.md) | **Exemplo prático completo** - API CRUD com todas as camadas DDD |
|
|
54
|
-
| [**CLI Reference**](./docs/00-cli-reference.md) | Guia da CLI oficial - Forma rápida de criar projetos |
|
|
55
|
-
| [**Guia de Instalação**](./docs/01-guia-instalacao.md) | Como instalar e configurar a biblioteca |
|
|
56
|
-
| [**Configuração Inicial**](./docs/02-configuracao-inicial.md) | Setup do projeto com KoalaNestModule e KoalaApp |
|
|
57
|
-
| [**Tratamento de Erros**](./docs/04-tratamento-erros.md) | Sistema robusto de tratamento e filtros de exceção |
|
|
58
|
-
| [**Features Avançadas**](./docs/05-features-avancadas.md) | Cron Jobs, Event Handlers, Redis, Transações e Padrões de Autenticação |
|
|
59
|
-
| [**Decoradores**](./docs/06-decoradores.md) | @IsPublic, @Upload, @Cookies e mais |
|
|
60
|
-
| [**Guia Bun**](./docs/07-guia-bun.md) | Por que Bun e como usá-lo |
|
|
61
|
-
| [**Prisma Client**](./docs/08-prisma-client.md) | Integração com Prisma |
|
|
62
|
-
| [**🤖 Extensão MCP**](./docs/09-mcp-vscode-extension.md) | **Extensão VS Code com integração ao Copilot** |
|
|
63
|
-
|
|
64
|
-
## Quick Start
|
|
65
|
-
|
|
66
|
-
### Usando Bun (Recomendado - Mais Rápido)
|
|
67
|
-
|
|
68
|
-
O projeto agora usa **Bun** como runtime JavaScript. Para instalar o Bun:
|
|
26
|
+
Instale uma vez e use `kl-nest` em qualquer pasta:
|
|
69
27
|
|
|
70
28
|
```bash
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# Ou em Windows com PowerShell:
|
|
75
|
-
powershell -Command "irm https://bun.sh/install.ps1 | iex"
|
|
76
|
-
|
|
77
|
-
# Instalar dependências
|
|
78
|
-
bun install
|
|
79
|
-
|
|
80
|
-
# Iniciar em modo desenvolvimento
|
|
81
|
-
bun run start:dev
|
|
82
|
-
|
|
83
|
-
# Executar testes
|
|
84
|
-
bun run test
|
|
29
|
+
npm install -g @koalarx/nest
|
|
30
|
+
# ou: bun install -g @koalarx/nest
|
|
31
|
+
# ou: pnpm add -g @koalarx/nest
|
|
85
32
|
|
|
86
|
-
|
|
87
|
-
|
|
33
|
+
kl-nest new
|
|
34
|
+
kl-nest --help
|
|
88
35
|
```
|
|
89
36
|
|
|
90
|
-
|
|
91
|
-
- ⚡ Runtime ~3x mais rápido que Node.js
|
|
92
|
-
- 📦 Package manager integrado (mais rápido que npm)
|
|
93
|
-
- 🧪 Test runner nativo (compatível com Vitest)
|
|
94
|
-
- 🔄 Hot reload automático
|
|
95
|
-
- 💾 Menor consumo de memória
|
|
37
|
+
### Sem instalar (bunx / npx)
|
|
96
38
|
|
|
97
|
-
|
|
39
|
+
Execute a versão publicada diretamente, sem instalação global:
|
|
98
40
|
|
|
99
41
|
```bash
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# Criar novo projeto estruturado
|
|
104
|
-
koala-nest new meu-projeto
|
|
105
|
-
|
|
106
|
-
# Entrar na pasta
|
|
107
|
-
cd meu-projeto
|
|
108
|
-
|
|
109
|
-
# Iniciar em modo desenvolvimento (com Bun)
|
|
110
|
-
bun run start:dev
|
|
42
|
+
bunx @koalarx/nest new
|
|
43
|
+
npx @koalarx/nest new
|
|
111
44
|
```
|
|
112
45
|
|
|
113
|
-
|
|
114
|
-
- [x] Módulo DDD configurado
|
|
115
|
-
- [x] Documentação da API (Scalar UI)
|
|
116
|
-
- [x] Tratamento de erros robusto
|
|
117
|
-
- [x] Banco de dados Prisma
|
|
118
|
-
- [x] Redis para background services
|
|
119
|
-
|
|
120
|
-
### Forma Manual
|
|
121
|
-
|
|
122
|
-
> ⚠️ **Requisito Obrigatório**: A abstração de banco de dados da biblioteca requer **Prisma como ORM**.
|
|
123
|
-
>
|
|
124
|
-
> **💡 Dica**: Para um exemplo completo e funcionando, veja [docs/EXAMPLE.md](./docs/EXAMPLE.md)
|
|
46
|
+
Útil para testar uma versão específica ou usar a CLI pontualmente:
|
|
125
47
|
|
|
126
48
|
```bash
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
# Ou com npm (Alternativa)
|
|
131
|
-
npm install @koalarx/nest
|
|
49
|
+
bunx @koalarx/nest@latest new
|
|
50
|
+
npx @koalarx/nest@latest new
|
|
132
51
|
```
|
|
133
52
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
// src/host/app.module.ts
|
|
138
|
-
import { KoalaNestModule } from '@koalarx/nest/core/koala-nest.module'
|
|
139
|
-
import { Module } from '@nestjs/common'
|
|
140
|
-
import { env } from '../core/env'
|
|
141
|
-
// Importar seus módulos de controllers
|
|
142
|
-
// import { PersonModule } from './controllers/person/person.module'
|
|
143
|
-
|
|
144
|
-
@Module({
|
|
145
|
-
imports: [
|
|
146
|
-
KoalaNestModule.register({
|
|
147
|
-
env,
|
|
148
|
-
// controllers: [PersonModule], // Adicione seus módulos aqui
|
|
149
|
-
}),
|
|
150
|
-
],
|
|
151
|
-
})
|
|
152
|
-
export class AppModule {}
|
|
153
|
-
```
|
|
53
|
+
## CLI
|
|
154
54
|
|
|
155
|
-
###
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
// src/host/main.ts
|
|
159
|
-
import { NestFactory } from '@nestjs/core'
|
|
160
|
-
import { KoalaApp } from '@koalarx/nest/core/koala-app'
|
|
161
|
-
import { AppModule } from './app.module'
|
|
162
|
-
import { DbTransactionContext } from '@/infra/database/db-transaction-context'
|
|
163
|
-
import { setPrismaClientOptions } from '@koalarx/nest/core/database/prisma.service'
|
|
164
|
-
import { PrismaPg } from '@prisma/adapter-pg'
|
|
165
|
-
import { Pool } from 'pg'
|
|
166
|
-
import 'dotenv/config'
|
|
167
|
-
|
|
168
|
-
async function bootstrap() {
|
|
169
|
-
// Configurar Prisma com adapter PostgreSQL
|
|
170
|
-
const pool = new Pool({
|
|
171
|
-
connectionString: process.env.DATABASE_URL,
|
|
172
|
-
})
|
|
173
|
-
const adapter = new PrismaPg(pool)
|
|
174
|
-
setPrismaClientOptions({ adapter })
|
|
175
|
-
|
|
176
|
-
// Criar aplicação NestJS
|
|
177
|
-
const app = await NestFactory.create(AppModule)
|
|
178
|
-
|
|
179
|
-
// Configurar e iniciar KoalaApp
|
|
180
|
-
await new KoalaApp(app)
|
|
181
|
-
.useDoc({
|
|
182
|
-
ui: 'scalar',
|
|
183
|
-
endpoint: '/doc',
|
|
184
|
-
title: 'API de Demonstração',
|
|
185
|
-
version: '1.0',
|
|
186
|
-
})
|
|
187
|
-
.setAppName('example')
|
|
188
|
-
.setInternalUserName('integration.bot')
|
|
189
|
-
.setDbTransactionContext(DbTransactionContext)
|
|
190
|
-
.enableCors()
|
|
191
|
-
.buildAndServe()
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
bootstrap()
|
|
195
|
-
```
|
|
55
|
+
### Comandos
|
|
196
56
|
|
|
197
|
-
|
|
57
|
+
| Comando | Descrição |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `kl-nest new` | Cria um novo projeto (fluxo interativo) |
|
|
60
|
+
| `kl-nest version` | Exibe a versão da CLI |
|
|
61
|
+
| `kl-nest help` | Lista comandos disponíveis |
|
|
198
62
|
|
|
199
63
|
```bash
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
Acesse `http://localhost:3000/doc` para a documentação interativa!
|
|
204
|
-
|
|
205
|
-
## Principais Features
|
|
64
|
+
kl-nest new
|
|
65
|
+
kl-nest version
|
|
66
|
+
kl-nest --help
|
|
206
67
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
1. **Domain** - Entidades, DTOs e interfaces de repositório
|
|
212
|
-
2. **Application** - Handlers com lógica de negócio, Validators, AutoMapping
|
|
213
|
-
3. **Host** - Controllers REST que expõem os endpoints
|
|
214
|
-
4. **Infra** - Repositórios concretos e acesso ao banco de dados
|
|
215
|
-
|
|
216
|
-
Veja [docs/EXAMPLE.md](./docs/EXAMPLE.md) para implementação completa.
|
|
217
|
-
|
|
218
|
-
### AutoMapping Automático
|
|
219
|
-
|
|
220
|
-
Converte Request → Entity → Response transparentemente:
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
// Define os mapeamentos
|
|
224
|
-
createMap(CreatePersonRequest, Person)
|
|
225
|
-
createMap(Person, ReadPersonResponse)
|
|
226
|
-
|
|
227
|
-
// Usa automaticamente
|
|
228
|
-
const person = mapper.map(request, CreatePersonRequest, Person)
|
|
229
|
-
const response = mapper.map(entity, Person, ReadPersonResponse)
|
|
68
|
+
# equivalente sem instalação global:
|
|
69
|
+
bunx @koalarx/nest new
|
|
70
|
+
npx @koalarx/nest new
|
|
230
71
|
```
|
|
231
72
|
|
|
232
|
-
|
|
73
|
+
O comando `new` pergunta:
|
|
233
74
|
|
|
234
|
-
|
|
75
|
+
- nome do projeto;
|
|
76
|
+
- gerenciador de pacotes (`bun`, `npm` ou `pnpm` — Bun recomendado);
|
|
77
|
+
- template (**Padrão** ou **Exemplo de CRUD**);
|
|
78
|
+
- estratégia de autenticação (**JWT**, **OAuth2** ou nenhuma) e funcionalidades extras (opções futuras aparecem desabilitadas).
|
|
235
79
|
|
|
236
|
-
|
|
237
|
-
export class CreatePersonValidator extends RequestValidatorBase<CreatePersonRequest> {
|
|
238
|
-
protected get schema(): ZodType<any, ZodTypeDef, any> {
|
|
239
|
-
return z.object({
|
|
240
|
-
name: z.string(),
|
|
241
|
-
phones: z.array(z.object({ phone: z.string() })),
|
|
242
|
-
address: z.object({ address: z.string() }),
|
|
243
|
-
})
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
```
|
|
80
|
+
### Templates
|
|
247
81
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
Padrão funcional para tratamento de sucesso/erro:
|
|
251
|
-
|
|
252
|
-
```typescript
|
|
253
|
-
@Injectable()
|
|
254
|
-
export class CreatePersonHandler extends RequestHandlerBase<...> {
|
|
255
|
-
async handle(req: CreatePersonRequest): Promise<RequestResult<Error, CreatePersonResponse>> {
|
|
256
|
-
const person = this.mapper.map(
|
|
257
|
-
new CreatePersonValidator(req).validate(),
|
|
258
|
-
CreatePersonRequest,
|
|
259
|
-
Person,
|
|
260
|
-
)
|
|
261
|
-
const result = await this.repository.save(person)
|
|
262
|
-
return ok({ id: result.id })
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Controller
|
|
267
|
-
const response = await handler.handle(request)
|
|
268
|
-
if (response.isFailure()) {
|
|
269
|
-
throw response.value
|
|
270
|
-
}
|
|
271
|
-
return response.value
|
|
272
|
-
```
|
|
82
|
+
**Padrão** — estrutura DDD pronta para começar do zero, sem código de exemplo de domínio.
|
|
273
83
|
|
|
274
|
-
|
|
84
|
+
**Exemplo de CRUD** — inclui um módulo completo de `Person` (entidades, repositório, handlers, controllers e mapeamentos) para servir de referência.
|
|
275
85
|
|
|
276
|
-
|
|
86
|
+
## Estrutura gerada
|
|
277
87
|
|
|
278
|
-
|
|
279
|
-
// Requisição
|
|
280
|
-
GET /person?name=John&active=true&page=1&pageSize=10
|
|
88
|
+
Projetos criados seguem esta organização:
|
|
281
89
|
|
|
282
|
-
// Response com count
|
|
283
|
-
{
|
|
284
|
-
"items": [...],
|
|
285
|
-
"count": 5
|
|
286
|
-
}
|
|
287
90
|
```
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
export class DeleteInactiveJob extends CronJobHandlerBase {
|
|
296
|
-
protected async settings(): Promise<CronJobSettings> {
|
|
297
|
-
return {
|
|
298
|
-
isActive: true,
|
|
299
|
-
timeInMinutes: 1,
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
protected async run(): Promise<CronJobResponse> {
|
|
304
|
-
// Executa apenas em um pod por vez
|
|
305
|
-
const result = await this.readManyPerson.handle(
|
|
306
|
-
new ReadManyPersonDto({ active: false })
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
if (result.isOk()) {
|
|
310
|
-
for (const person of result.value.items) {
|
|
311
|
-
await this.deletePerson.handle(person.id)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return ok(null)
|
|
316
|
-
}
|
|
317
|
-
}
|
|
91
|
+
src/
|
|
92
|
+
├── application/ # casos de uso, validadores, mapeamentos
|
|
93
|
+
├── core/ # utilitários, env, ferramentas compartilhadas
|
|
94
|
+
├── domain/ # entidades, DTOs, contratos de repositório
|
|
95
|
+
├── host/ # controllers, módulos Nest, filtros, OpenAPI
|
|
96
|
+
├── infra/ # banco de dados, repositórios, serviços externos
|
|
97
|
+
└── test/ # testes unitários
|
|
318
98
|
```
|
|
319
99
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
Processamento de eventos assincronamente:
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
export class PersonEventJob extends EventJob<Person> {
|
|
326
|
-
defineHandlers(): Type<EventHandlerBase>[] {
|
|
327
|
-
return [InactivePersonHandler]
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
@Injectable()
|
|
332
|
-
export class InactivePersonHandler extends EventHandlerBase {
|
|
333
|
-
async handleEvent(): Promise<void> {
|
|
334
|
-
const result = await this.repository.readMany(
|
|
335
|
-
new ReadManyPersonDto({ active: true })
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
for (const person of result.items) {
|
|
339
|
-
person.active = false
|
|
340
|
-
await this.repository.save(person)
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Registrar na aplicação
|
|
346
|
-
.addEventJob(InactivePersonHandler)
|
|
347
|
-
```
|
|
100
|
+
## Módulo core
|
|
348
101
|
|
|
349
|
-
|
|
102
|
+
Ao criar um projeto, o módulo core instala e configura:
|
|
350
103
|
|
|
351
|
-
|
|
104
|
+
- validação de variáveis de ambiente com **Zod** (`PORT`, `NODE_ENV`, `DATABASE_URL`);
|
|
105
|
+
- **TypeORM** com PostgreSQL e scripts de migration;
|
|
106
|
+
- documentação OpenAPI em `/doc` via **Scalar**;
|
|
107
|
+
- filtro global de erros;
|
|
108
|
+
- bases reutilizáveis para controllers, handlers, validators e repositórios;
|
|
109
|
+
- sistema de mapeamento entre entidades, requests e responses.
|
|
352
110
|
|
|
353
|
-
|
|
354
|
-
describe('CreatePersonHandler', () => {
|
|
355
|
-
const app = createUnitTestApp()
|
|
111
|
+
### Variáveis de ambiente
|
|
356
112
|
|
|
357
|
-
|
|
358
|
-
const handler = app.get(CreatePersonHandler)
|
|
359
|
-
const result = await handler.handle(createPersonRequestMockup)
|
|
113
|
+
Crie um `.env` na raiz do projeto gerado:
|
|
360
114
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
})
|
|
366
|
-
}
|
|
367
|
-
})
|
|
368
|
-
})
|
|
115
|
+
```env
|
|
116
|
+
PORT=3000
|
|
117
|
+
NODE_ENV=develop
|
|
118
|
+
DATABASE_URL=postgres://user:password@localhost:5432/my_api
|
|
369
119
|
```
|
|
370
120
|
|
|
371
|
-
###
|
|
372
|
-
|
|
373
|
-
Testes de integração completos:
|
|
374
|
-
|
|
375
|
-
```typescript
|
|
376
|
-
const app = await createE2ETestApp()
|
|
121
|
+
### Scripts úteis no projeto gerado
|
|
377
122
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
phones: [],
|
|
384
|
-
address: { address: 'Street 1' },
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
expect(response.statusCode).toBe(201)
|
|
388
|
-
expect(response.body.id).toBeDefined()
|
|
389
|
-
})
|
|
123
|
+
```bash
|
|
124
|
+
bun run start:dev # servidor em modo watch
|
|
125
|
+
bun run migration:generate # gera migration a partir das entidades
|
|
126
|
+
bun run migration:run # aplica migrations pendentes
|
|
127
|
+
bun run migration:revert # reverte a última migration
|
|
390
128
|
```
|
|
391
129
|
|
|
392
|
-
##
|
|
130
|
+
## Documentação para agentes de IA
|
|
393
131
|
|
|
394
|
-
|
|
132
|
+
Índice de documentação otimizado para LLMs:
|
|
395
133
|
|
|
396
|
-
|
|
397
|
-
- ✅ DTOs com paginação (ReadManyPersonDto)
|
|
398
|
-
- ✅ 5 Handlers (Create, Read, ReadMany, Update, Delete)
|
|
399
|
-
- ✅ 5 Controllers REST
|
|
400
|
-
- ✅ Repository com Prisma
|
|
401
|
-
- ✅ Testes unitários e E2E
|
|
402
|
-
- ✅ CronJobs e EventJobs
|
|
403
|
-
- ✅ AutoMapping automático
|
|
404
|
-
- ✅ Validação com Zod
|
|
134
|
+
https://nest.koalarx.com/llm.txt
|
|
405
135
|
|
|
406
|
-
##
|
|
136
|
+
## Repositório (desenvolvimento)
|
|
407
137
|
|
|
408
|
-
|
|
138
|
+
Para contribuir ou testar alterações locais da CLI:
|
|
409
139
|
|
|
140
|
+
```bash
|
|
141
|
+
git clone <url-do-repositorio>
|
|
142
|
+
cd koala-nest
|
|
143
|
+
bun install
|
|
144
|
+
bun run build
|
|
145
|
+
bun kl-nest new
|
|
410
146
|
```
|
|
411
|
-
apps/
|
|
412
|
-
├── example/ # Projeto exemplo
|
|
413
|
-
│ └── src/
|
|
414
|
-
│ ├── domain/ # Entidades, DTOs, Interfaces
|
|
415
|
-
│ ├── application/ # Handlers, Validators, Mapping
|
|
416
|
-
│ ├── host/ # Controllers, Roteamento
|
|
417
|
-
│ ├── infra/ # Repositories, Database
|
|
418
|
-
│ ├── core/ # Configuração
|
|
419
|
-
│ └── test/ # Setup de testes
|
|
420
|
-
└── koala-nest/ # Biblioteca principal
|
|
421
|
-
|
|
422
|
-
prisma/
|
|
423
|
-
├── schema.prisma # Modelo de dados
|
|
424
|
-
├── migrations/ # Histórico de migrações
|
|
425
|
-
└── generated/ # Cliente Prisma gerado
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
## Configuração de Ambiente
|
|
429
|
-
|
|
430
|
-
Crie seu `.env`:
|
|
431
|
-
|
|
432
|
-
```env
|
|
433
|
-
# Banco de dados
|
|
434
|
-
DATABASE_URL=postgresql://user:password@localhost:5432/koala_db
|
|
435
147
|
|
|
436
|
-
|
|
437
|
-
NODE_ENV=develop
|
|
438
|
-
|
|
439
|
-
# Prisma (opcional - habilita logs das queries)
|
|
440
|
-
PRISMA_QUERY_LOG=true
|
|
441
|
-
|
|
442
|
-
# Swagger/Scalar (opcional)
|
|
443
|
-
SWAGGER_USERNAME=admin
|
|
444
|
-
SWAGGER_PASSWORD=password123
|
|
148
|
+
O script `bun kl-nest` no `package.json` compila o projeto e executa a CLI a partir de `dist/cli/index.js`.
|
|
445
149
|
|
|
446
|
-
|
|
447
|
-
|
|
150
|
+
```
|
|
151
|
+
koala-nest/
|
|
152
|
+
├── libs/
|
|
153
|
+
│ ├── cli/ # código-fonte da CLI (kl-nest)
|
|
154
|
+
│ └── koala-nest/ # templates copiados para projetos gerados
|
|
155
|
+
├── scripts/ # build da CLI e dos templates
|
|
156
|
+
└── dist/ # saída do build (cli + koala-nest + package.json)
|
|
448
157
|
```
|
|
449
158
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
## Recursos Adicionais
|
|
453
|
-
|
|
454
|
-
A biblioteca inclui vários decoradores e utilitários para facilitar o desenvolvimento:
|
|
455
|
-
|
|
456
|
-
- **@ApiPropertyEnum()** - Documente enums corretamente no Swagger
|
|
457
|
-
- **@ApiPropertyOnlyDevelop()** - Propriedades apenas em ambiente de desenvolvimento
|
|
458
|
-
- **@ApiExcludeEndpointDiffDevelop()** - Endpoints apenas em dev (excluídos em produção)
|
|
459
|
-
- **@Upload()** - Documentação automática de uploads de arquivos
|
|
460
|
-
- **@Cookies()** - Extrai cookies da requisição HTTP
|
|
461
|
-
- **@IsPublic()** - Marca endpoint como público (sem validação de token)
|
|
462
|
-
|
|
463
|
-
Veja [docs/06-decoradores.md](./docs/06-decoradores.md) para documentação completa.
|
|
464
|
-
|
|
465
|
-
## Arquitetura
|
|
466
|
-
|
|
467
|
-
A biblioteca utiliza duas classes principais:
|
|
468
|
-
|
|
469
|
-
1. **KoalaNestModule** - Módulo NestJS com configuração
|
|
470
|
-
2. **KoalaApp** - Classe fluent para setup da aplicação
|
|
471
|
-
|
|
472
|
-
Ambas seguem o padrão de **Fluent Interface** para configuração clara e intuitiva.
|
|
473
|
-
|
|
474
|
-
## Dependências Principais
|
|
475
|
-
|
|
476
|
-
- `@nestjs/*` - Framework NestJS
|
|
477
|
-
- `@prisma/client` - ORM Prisma
|
|
478
|
-
- `zod` - Validação de dados
|
|
479
|
-
- `ioredis` - Cliente Redis
|
|
480
|
-
- `@nestjs/swagger` - Documentação automática
|
|
481
|
-
|
|
482
|
-
## Links Importantes
|
|
483
|
-
|
|
484
|
-
- **[CLI (@koalarx/nest-cli)](https://www.npmjs.com/package/@koalarx/nest-cli)** - Ferramenta oficial para criar projetos rapidamente
|
|
485
|
-
- **[GitHub da Library](https://github.com/igordrangel/koala-nest)** - Repositório principal
|
|
486
|
-
- **[GitHub da CLI](https://github.com/igordrangel/koala-nest-cli)** - Repositório da CLI
|
|
487
|
-
|
|
488
|
-
## Licença
|
|
489
|
-
|
|
490
|
-
MIT License © 2023-2025 Igor D. Rangel
|
|
491
|
-
|
|
492
|
-
## Contribuindo
|
|
493
|
-
|
|
494
|
-
Contribuições são bem-vindas! Abra uma issue ou pull request no repositório.
|
|
495
|
-
|
|
496
|
-
## Suporte
|
|
497
|
-
|
|
498
|
-
Para dúvidas, abra uma issue no repositório ou consulte a [documentação completa](./docs).
|
|
499
|
-
|
|
500
|
-
---
|
|
159
|
+
### Scripts de desenvolvimento
|
|
501
160
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
161
|
+
```bash
|
|
162
|
+
bun run build # build completo (CLI + templates + dist/package.json)
|
|
163
|
+
bun run build:cli # apenas a CLI
|
|
164
|
+
bun run build:koala-nest # apenas os templates
|
|
165
|
+
bun test # testes em libs/koala-nest
|
|
166
|
+
```
|