@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.
Files changed (499) hide show
  1. package/README.md +126 -439
  2. package/cli/commands/add/index.js +97 -0
  3. package/cli/commands/help.js +44 -0
  4. package/cli/commands/new/configure-test-runner.js +13 -0
  5. package/cli/commands/new/create-ddd-structure.js +52 -0
  6. package/cli/commands/new/create-empty-nest-project.js +58 -0
  7. package/cli/commands/new/fix-lint-config.js +24 -0
  8. package/cli/commands/new/index.js +202 -0
  9. package/cli/commands/version.js +5 -0
  10. package/cli/constants/auth-strategy-artifacts.js +56 -0
  11. package/cli/constants/auth-strategy-checklist.js +314 -0
  12. package/cli/constants/cli-commands.js +24 -0
  13. package/cli/constants/cli-project-checklist.js +289 -0
  14. package/cli/constants/core-packages.js +34 -0
  15. package/cli/constants/domain.js +171 -0
  16. package/cli/constants/package-manager.js +5 -0
  17. package/cli/constants/version.js +5 -0
  18. package/cli/index.js +55 -0
  19. package/cli/types/index.js +0 -0
  20. package/cli/utils/add-project-features.js +170 -0
  21. package/cli/utils/apply-optional-features.js +48 -0
  22. package/cli/utils/auth-strategy-validation.js +179 -0
  23. package/cli/utils/cancel.js +8 -0
  24. package/cli/utils/cli-options.js +27 -0
  25. package/cli/utils/cli-project-validation.js +157 -0
  26. package/cli/utils/detect-project-state.js +131 -0
  27. package/cli/utils/format-code.js +9 -0
  28. package/cli/utils/get-package-manager.js +12 -0
  29. package/cli/utils/get-package-root.js +19 -0
  30. package/cli/utils/get-source-code-path.js +15 -0
  31. package/cli/utils/install-module.js +258 -0
  32. package/cli/utils/normalize-add-args.js +25 -0
  33. package/cli/utils/parse-new-args.js +127 -0
  34. package/cli/utils/patch-auth-install.js +224 -0
  35. package/cli/utils/patch-define-documentation.js +222 -0
  36. package/cli/utils/patch-env.js +106 -0
  37. package/cli/utils/patch-generated-project.js +21 -0
  38. package/cli/utils/patch-health-module.js +80 -0
  39. package/cli/utils/patch-infra-module.js +62 -0
  40. package/cli/utils/patch-jobs-module.js +103 -0
  41. package/cli/utils/patch-main.js +15 -0
  42. package/cli/utils/patch-person-features.js +127 -0
  43. package/cli/utils/project-files.js +11 -0
  44. package/cli/utils/prune-auth-strategies.js +116 -0
  45. package/cli/utils/prune-core-auth.js +17 -0
  46. package/cli/utils/remove-sample-parts.js +203 -0
  47. package/cli/utils/resolve-project-path.js +19 -0
  48. package/cli/utils/restore-person-features.js +64 -0
  49. package/cli/utils/run-command.js +31 -0
  50. package/cli/utils/sync-auth-strategy-files.js +63 -0
  51. package/koala-nest/.env.example +34 -0
  52. package/koala-nest/.prettierrc +4 -0
  53. package/koala-nest/README.md +51 -0
  54. package/koala-nest/bunfig.toml +7 -0
  55. package/koala-nest/eslint.config.mjs +55 -0
  56. package/koala-nest/nest-cli.json +9 -0
  57. package/koala-nest/package.json +79 -0
  58. package/koala-nest/src/application/auth/common/auth-token.response.ts +15 -0
  59. package/koala-nest/src/application/auth/common/user-claims.ts +6 -0
  60. package/koala-nest/src/application/auth/login/login.handler.ts +42 -0
  61. package/koala-nest/src/application/auth/login/login.request.ts +9 -0
  62. package/koala-nest/src/application/auth/login/login.response.ts +3 -0
  63. package/koala-nest/src/application/auth/login/login.validator.ts +12 -0
  64. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.handler.ts +24 -0
  65. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.request.ts +10 -0
  66. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.response.ts +6 -0
  67. package/koala-nest/src/application/auth/oauth2/auth-link/auth-link.validator.ts +12 -0
  68. package/koala-nest/src/application/auth/oauth2/callback/oauth-callback.response.ts +10 -0
  69. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.handler.ts +73 -0
  70. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.request.ts +16 -0
  71. package/koala-nest/src/application/auth/oauth2/exchange-code/exchange-code.validator.ts +14 -0
  72. package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-oauth-token.handler.ts +35 -0
  73. package/koala-nest/src/application/auth/oauth2/scalar-token/scalar-token.types.ts +1 -0
  74. package/koala-nest/src/application/auth/refresh-token/refresh-token.handler.ts +26 -0
  75. package/koala-nest/src/application/auth/user-info/user-info.handler.ts +30 -0
  76. package/koala-nest/src/application/auth/user-info/user-info.response.ts +20 -0
  77. package/koala-nest/src/application/common/created-registre.response.ts +20 -0
  78. package/koala-nest/src/application/common/pagination.request.ts +41 -0
  79. package/koala-nest/src/application/common/request-handler.base.ts +3 -0
  80. package/koala-nest/src/application/common/request-validator.base.ts +33 -0
  81. package/koala-nest/src/application/mapping/mapping.provider.ts +9 -0
  82. package/koala-nest/src/application/mapping/person.mapper.ts +44 -0
  83. package/koala-nest/src/application/person/create/create-person.handler.ts +34 -0
  84. package/koala-nest/src/application/person/create/create-person.request.ts +29 -0
  85. package/koala-nest/src/application/person/create/create-person.response.ts +3 -0
  86. package/koala-nest/src/application/person/create/create-person.validator.ts +9 -0
  87. package/koala-nest/src/application/person/delete/delete-person.handler.ts +22 -0
  88. package/koala-nest/src/application/person/find-person-or-throw.ts +16 -0
  89. package/koala-nest/src/application/person/jobs/cron/create-person.job.ts +58 -0
  90. package/koala-nest/src/application/person/jobs/cron/delete-inactive.job.ts +57 -0
  91. package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.event.ts +4 -0
  92. package/koala-nest/src/application/person/jobs/events/person/inactive-person/inactive-person.handler.ts +54 -0
  93. package/koala-nest/src/application/person/jobs/events/person/person-event.job.ts +19 -0
  94. package/koala-nest/src/application/person/person.schemas.ts +21 -0
  95. package/koala-nest/src/application/person/read/read-person.handler.ts +22 -0
  96. package/koala-nest/src/application/person/read/read-person.response.ts +44 -0
  97. package/koala-nest/src/application/person/read-many/read-many-person.handler.ts +63 -0
  98. package/koala-nest/src/application/person/read-many/read-many-person.request.ts +13 -0
  99. package/koala-nest/src/application/person/read-many/read-many-person.response.ts +30 -0
  100. package/koala-nest/src/application/person/read-many/read-many-person.validator.ts +15 -0
  101. package/koala-nest/src/application/person/update/update-person.handler.ts +51 -0
  102. package/koala-nest/src/application/person/update/update-person.request.ts +41 -0
  103. package/koala-nest/src/application/person/update/update-person.validator.ts +9 -0
  104. package/koala-nest/src/core/auth/assert-user-active.ts +18 -0
  105. package/koala-nest/src/core/auth/auth-profile.enum.ts +7 -0
  106. package/koala-nest/src/core/auth/auth-routes.ts +5 -0
  107. package/koala-nest/src/core/auth/auth.constants.ts +6 -0
  108. package/koala-nest/src/core/auth/jwt-claims.ts +23 -0
  109. package/koala-nest/src/core/auth/oauth-provider.registry.ts +94 -0
  110. package/koala-nest/src/core/auth/parse-jwt-expires-in.ts +30 -0
  111. package/koala-nest/src/core/auth/parse-oauth2-provider-env.ts +56 -0
  112. package/koala-nest/src/core/auth/resolve-refresh-token.ts +40 -0
  113. package/koala-nest/src/core/background-services/cron-service/cron-job.handler.base.ts +65 -0
  114. package/koala-nest/src/core/background-services/event-service/event-class.ts +5 -0
  115. package/koala-nest/src/core/background-services/event-service/event-handler.base.ts +17 -0
  116. package/koala-nest/src/core/background-services/event-service/event-job.ts +31 -0
  117. package/koala-nest/src/core/background-services/event-service/event-queue.ts +107 -0
  118. package/koala-nest/src/core/base/entity.base.ts +3 -0
  119. package/koala-nest/src/core/base/object-class.ts +14 -0
  120. package/koala-nest/src/core/constants/cache.constants.ts +16 -0
  121. package/koala-nest/src/core/constants/cron.constants.ts +14 -0
  122. package/koala-nest/src/core/constants/query-params.ts +7 -0
  123. package/koala-nest/src/core/env.ts +42 -0
  124. package/koala-nest/src/core/schemas/boolean.schema.ts +24 -0
  125. package/koala-nest/src/core/schemas/document-number-mask.ts +22 -0
  126. package/koala-nest/src/core/schemas/document-number.schema.ts +21 -0
  127. package/koala-nest/src/core/schemas/document-number.utils.ts +15 -0
  128. package/koala-nest/src/core/schemas/email.schema.ts +13 -0
  129. package/koala-nest/src/core/schemas/index.ts +6 -0
  130. package/koala-nest/src/core/schemas/list-query.schema.ts +18 -0
  131. package/koala-nest/src/core/schemas/native-enum.schema.ts +36 -0
  132. package/koala-nest/src/core/tools/mapping/auto-map.ts +14 -0
  133. package/koala-nest/src/core/tools/mapping/auto-mapper.ts +102 -0
  134. package/koala-nest/src/core/tools/mapping/create-map.ts +11 -0
  135. package/koala-nest/src/core/tools/mapping/for-member.ts +16 -0
  136. package/koala-nest/src/core/tools/mapping/index.ts +4 -0
  137. package/koala-nest/src/core/tools/mapping/mapping-store.ts +121 -0
  138. package/koala-nest/src/core/types/auth-provider-config-response.type.ts +5 -0
  139. package/koala-nest/src/core/types/index.ts +5 -0
  140. package/koala-nest/src/core/utils/build-list-cache-key.ts +19 -0
  141. package/koala-nest/src/core/utils/cron-expression-to-boolean.ts +65 -0
  142. package/koala-nest/src/core/utils/env.config.ts +17 -0
  143. package/koala-nest/src/core/utils/filter-request-params.ts +29 -0
  144. package/koala-nest/src/core/utils/format-typeorm-error.ts +173 -0
  145. package/koala-nest/src/core/utils/format-zod-error.ts +201 -0
  146. package/koala-nest/src/core/utils/hash-password.ts +5 -0
  147. package/koala-nest/src/core/utils/icomparable.ts +1 -0
  148. package/koala-nest/src/core/utils/is-provider-registered.ts +40 -0
  149. package/koala-nest/src/core/utils/name-to-login.ts +25 -0
  150. package/koala-nest/src/core/utils/person-list-cache.ts +7 -0
  151. package/koala-nest/src/core/utils/report-error.ts +18 -0
  152. package/koala-nest/src/core/utils/resolve-api-host.ts +8 -0
  153. package/koala-nest/src/core/utils/time.constants.ts +5 -0
  154. package/koala-nest/src/domain/auth/dtos/auth-provider-config.dto.ts +12 -0
  155. package/koala-nest/src/domain/auth/dtos/oauth-user-info.dto.ts +9 -0
  156. package/koala-nest/src/domain/auth/services/iauth.service.ts +37 -0
  157. package/koala-nest/src/domain/common/icache.service.ts +11 -0
  158. package/koala-nest/src/domain/common/ilogging.service.ts +9 -0
  159. package/koala-nest/src/domain/common/ired-lock.service.ts +4 -0
  160. package/koala-nest/src/domain/dtos/logged-user-info.dto.ts +30 -0
  161. package/koala-nest/src/domain/dtos/pagination.dto.ts +35 -0
  162. package/koala-nest/src/domain/dtos/person-query.dto.ts +10 -0
  163. package/koala-nest/src/domain/entities/person/person-address.ts +14 -0
  164. package/koala-nest/src/domain/entities/person/person-contact.ts +28 -0
  165. package/koala-nest/src/domain/entities/person/person.ts +44 -0
  166. package/koala-nest/src/domain/entities/user/enums/user-status.enum.ts +6 -0
  167. package/koala-nest/src/domain/entities/user/user.ts +49 -0
  168. package/koala-nest/src/domain/repositories/iperson.repository.ts +10 -0
  169. package/koala-nest/src/domain/repositories/iuser.repository.ts +8 -0
  170. package/koala-nest/src/domain/services/ilogged-user-info.service.ts +5 -0
  171. package/koala-nest/src/host/app.module.ts +27 -0
  172. package/koala-nest/src/host/controllers/auth/auth.module.ts +38 -0
  173. package/koala-nest/src/host/controllers/auth/login.controller.ts +41 -0
  174. package/koala-nest/src/host/controllers/auth/refresh-token.controller.ts +24 -0
  175. package/koala-nest/src/host/controllers/auth/router.config.ts +9 -0
  176. package/koala-nest/src/host/controllers/auth/user-info.controller.ts +19 -0
  177. package/koala-nest/src/host/controllers/common/controller.base.ts +9 -0
  178. package/koala-nest/src/host/controllers/common/controller.module.ts +10 -0
  179. package/koala-nest/src/host/controllers/common/router-config.base.ts +14 -0
  180. package/koala-nest/src/host/controllers/health-check/health-check.controller.ts +29 -0
  181. package/koala-nest/src/host/controllers/health-check/health-check.module.ts +22 -0
  182. package/koala-nest/src/host/controllers/oauth2/auth-link.controller.ts +29 -0
  183. package/koala-nest/src/host/controllers/oauth2/exchange-code.controller.ts +29 -0
  184. package/koala-nest/src/host/controllers/oauth2/oauth-callback.controller.ts +28 -0
  185. package/koala-nest/src/host/controllers/oauth2/router.config.ts +9 -0
  186. package/koala-nest/src/host/controllers/oauth2/scalar-token.controller.ts +16 -0
  187. package/koala-nest/src/host/controllers/person/create-person.controller.ts +23 -0
  188. package/koala-nest/src/host/controllers/person/delete-person.controller.ts +23 -0
  189. package/koala-nest/src/host/controllers/person/person.module.ts +39 -0
  190. package/koala-nest/src/host/controllers/person/read-many-person.controller.ts +24 -0
  191. package/koala-nest/src/host/controllers/person/read-person.controller.ts +21 -0
  192. package/koala-nest/src/host/controllers/person/router.config.ts +9 -0
  193. package/koala-nest/src/host/controllers/person/update-person.controller.ts +22 -0
  194. package/koala-nest/src/host/decorators/api-exclude-endpoint-diff-develop.decorator.ts +9 -0
  195. package/koala-nest/src/host/decorators/api-property-enum.decorator.ts +49 -0
  196. package/koala-nest/src/host/decorators/api-property-only-develop.decorator.ts +19 -0
  197. package/koala-nest/src/host/decorators/controller.decorator.ts +10 -0
  198. package/koala-nest/src/host/decorators/is-public.decorator.ts +82 -0
  199. package/koala-nest/src/host/decorators/restriction-by-profile.decorator.ts +13 -0
  200. package/koala-nest/src/host/decorators/scalar-token-endpoint.decorator.ts +14 -0
  201. package/koala-nest/src/host/filters/errors.filter.ts +99 -0
  202. package/koala-nest/src/host/jobs/jobs-bootstrap.service.ts +61 -0
  203. package/koala-nest/src/host/jobs/jobs.module.ts +41 -0
  204. package/koala-nest/src/host/jobs/jobs.tokens.ts +2 -0
  205. package/koala-nest/src/host/main.ts +43 -0
  206. package/koala-nest/src/host/open-api/define-documentation.ts +210 -0
  207. package/koala-nest/src/host/security/guards/auth.guard.ts +107 -0
  208. package/koala-nest/src/host/security/guards/profiles.guard.ts +32 -0
  209. package/koala-nest/src/host/security/security.module.ts +62 -0
  210. package/koala-nest/src/host/security/strategies/jwt.strategy.ts +61 -0
  211. package/koala-nest/src/infra/auth/jwt-token.service.ts +48 -0
  212. package/koala-nest/src/infra/auth/oauth2-auth.service.ts +208 -0
  213. package/koala-nest/src/infra/common/cache-service.provider.ts +47 -0
  214. package/koala-nest/src/infra/common/env.service.ts +12 -0
  215. package/koala-nest/src/infra/common/in-memory-cache.service.ts +71 -0
  216. package/koala-nest/src/infra/common/logging.service.ts +19 -0
  217. package/koala-nest/src/infra/common/red-lock.service.ts +44 -0
  218. package/koala-nest/src/infra/common/redis-cache.service.ts +72 -0
  219. package/koala-nest/src/infra/database/data-source-factory.ts +23 -0
  220. package/koala-nest/src/infra/database/database.module.ts +19 -0
  221. package/koala-nest/src/infra/database/migrations/1781281330533-Init.ts +67 -0
  222. package/koala-nest/src/infra/database/migrations/generate-migration.ts +26 -0
  223. package/koala-nest/src/infra/database/migrations/migration-datasource.ts +14 -0
  224. package/koala-nest/src/infra/infra.module.ts +29 -0
  225. package/koala-nest/src/infra/repositories/person.repository.ts +49 -0
  226. package/koala-nest/src/infra/repositories/repository.base.ts +20 -0
  227. package/koala-nest/src/infra/repositories/repository.module.ts +16 -0
  228. package/koala-nest/src/infra/repositories/user.repository.ts +38 -0
  229. package/koala-nest/src/infra/services/database.indicator.service.ts +17 -0
  230. package/koala-nest/src/infra/services/logged-user-info.service.ts +32 -0
  231. package/koala-nest/src/infra/services/redis.indicator.service.ts +66 -0
  232. package/koala-nest/src/test/app-auth-test.module.ts +32 -0
  233. package/koala-nest/src/test/app-test.module.ts +22 -0
  234. package/koala-nest/src/test/application/auth-link.handler.spec.ts +22 -0
  235. package/koala-nest/src/test/application/create-person.handler.spec.ts +39 -0
  236. package/koala-nest/src/test/application/create-person.job.spec.ts +55 -0
  237. package/koala-nest/src/test/application/delete-inactive.job.spec.ts +35 -0
  238. package/koala-nest/src/test/application/delete-person.handler.spec.ts +46 -0
  239. package/koala-nest/src/test/application/exchange-code.handler.spec.ts +67 -0
  240. package/koala-nest/src/test/application/inactive-person.handler.spec.ts +48 -0
  241. package/koala-nest/src/test/application/login.handler.spec.ts +55 -0
  242. package/koala-nest/src/test/application/read-many-person.handler.spec.ts +64 -0
  243. package/koala-nest/src/test/application/read-person.handler.spec.ts +44 -0
  244. package/koala-nest/src/test/application/refresh-token.handler.spec.ts +34 -0
  245. package/koala-nest/src/test/application/scalar-oauth-token.handler.spec.ts +63 -0
  246. package/koala-nest/src/test/application/update-person.handler.spec.ts +78 -0
  247. package/koala-nest/src/test/bun-test-globals.d.ts +1 -0
  248. package/koala-nest/src/test/core/auth.guard.spec.ts +77 -0
  249. package/koala-nest/src/test/core/build-list-cache-key.spec.ts +29 -0
  250. package/koala-nest/src/test/core/cron-expression-to-boolean.spec.ts +22 -0
  251. package/koala-nest/src/test/core/cron-job.handler.spec.ts +40 -0
  252. package/koala-nest/src/test/core/env.config.spec.ts +14 -0
  253. package/koala-nest/src/test/core/env.spec.ts +61 -0
  254. package/koala-nest/src/test/core/event-queue.spec.ts +53 -0
  255. package/koala-nest/src/test/core/format-typeorm-error.spec.ts +42 -0
  256. package/koala-nest/src/test/core/format-zod-error.spec.ts +38 -0
  257. package/koala-nest/src/test/core/is-provider-registered.spec.ts +35 -0
  258. package/koala-nest/src/test/core/jwt.strategy.spec.ts +38 -0
  259. package/koala-nest/src/test/core/mapping.spec.ts +177 -0
  260. package/koala-nest/src/test/core/oauth-provider.registry.spec.ts +79 -0
  261. package/koala-nest/src/test/core/profiles.guard.spec.ts +42 -0
  262. package/koala-nest/src/test/core/resolve-api-host.spec.ts +20 -0
  263. package/koala-nest/src/test/core/schemas.spec.ts +95 -0
  264. package/koala-nest/src/test/create-auth-e2e-test-app.ts +22 -0
  265. package/koala-nest/src/test/create-e2e-test-app.ts +14 -0
  266. package/koala-nest/src/test/e2e-context.ts +7 -0
  267. package/koala-nest/src/test/host/controllers/auth/auth.controller.e2e.spec.ts +87 -0
  268. package/koala-nest/src/test/host/controllers/person/lazy-loading.e2e.spec.ts +181 -0
  269. package/koala-nest/src/test/host/controllers/person/person.controller.e2e.spec.ts +148 -0
  270. package/koala-nest/src/test/host/errors.filter.spec.ts +75 -0
  271. package/koala-nest/src/test/host/is-public-open-api.spec.ts +60 -0
  272. package/koala-nest/src/test/host/oauth-callback.controller.spec.ts +18 -0
  273. package/koala-nest/src/test/infra/cache-service.provider.spec.ts +21 -0
  274. package/koala-nest/src/test/infra/in-memory-cache.service.spec.ts +49 -0
  275. package/koala-nest/src/test/infra/jwt-token.service.spec.ts +28 -0
  276. package/koala-nest/src/test/infra/logged-user-info.service.spec.ts +33 -0
  277. package/koala-nest/src/test/infra/oauth2-auth.service.spec.ts +112 -0
  278. package/koala-nest/src/test/infra/red-lock.service.spec.ts +43 -0
  279. package/koala-nest/src/test/infra/redis-cache.service.spec.ts +100 -0
  280. package/koala-nest/src/test/infra/redis-indicator.service.spec.ts +75 -0
  281. package/koala-nest/src/test/mockup/person/person.entities.ts +35 -0
  282. package/koala-nest/src/test/mockup/person/person.requests.ts +23 -0
  283. package/koala-nest/src/test/mockup/person/person.responses.ts +31 -0
  284. package/koala-nest/src/test/services/cache.stub.ts +41 -0
  285. package/koala-nest/src/test/services/fake-logging.service.ts +13 -0
  286. package/koala-nest/src/test/services/fake-red-lock.service.ts +11 -0
  287. package/koala-nest/src/test/services/logged-user-info.fake-service.ts +18 -0
  288. package/koala-nest/src/test/setup-e2e.ts +66 -0
  289. package/koala-nest/src/test/setup.ts +1 -0
  290. package/koala-nest/src/test/utils/configure-test-app.ts +24 -0
  291. package/koala-nest/src/test/utils/create-e2e-database.ts +50 -0
  292. package/koala-nest/src/test/utils/e2e-database-client.ts +9 -0
  293. package/koala-nest/src/test/utils/guard-test-context.ts +28 -0
  294. package/koala-nest/src/test/utils/jwt-test-keys.ts +27 -0
  295. package/koala-nest/tsconfig.build.json +8 -0
  296. package/koala-nest/tsconfig.json +36 -0
  297. package/koala-nest/tsconfig.spec.json +11 -0
  298. package/package.json +19 -29
  299. package/core/backgroud-services/cron-service/cron-job.handler.base.d.ts +0 -16
  300. package/core/backgroud-services/cron-service/cron-job.handler.base.js +0 -49
  301. package/core/backgroud-services/event-service/event-class.d.ts +0 -5
  302. package/core/backgroud-services/event-service/event-class.js +0 -11
  303. package/core/backgroud-services/event-service/event-handler.base.d.ts +0 -8
  304. package/core/backgroud-services/event-service/event-handler.base.js +0 -14
  305. package/core/backgroud-services/event-service/event-is-trigger.d.ts +0 -3
  306. package/core/backgroud-services/event-service/event-is-trigger.js +0 -7
  307. package/core/backgroud-services/event-service/event-job.d.ts +0 -13
  308. package/core/backgroud-services/event-service/event-job.js +0 -21
  309. package/core/backgroud-services/event-service/event-queue.d.ts +0 -18
  310. package/core/backgroud-services/event-service/event-queue.js +0 -65
  311. package/core/constants/query-params.d.ts +0 -6
  312. package/core/constants/query-params.js +0 -8
  313. package/core/controllers/base.controller.d.ts +0 -4
  314. package/core/controllers/base.controller.js +0 -6
  315. package/core/controllers/controller.decorator.d.ts +0 -2
  316. package/core/controllers/controller.decorator.js +0 -11
  317. package/core/controllers/created-registre-response.base.d.ts +0 -10
  318. package/core/controllers/created-registre-response.base.js +0 -35
  319. package/core/controllers/list-response.base.d.ts +0 -4
  320. package/core/controllers/list-response.base.js +0 -21
  321. package/core/controllers/pagination.request.d.ts +0 -10
  322. package/core/controllers/pagination.request.js +0 -56
  323. package/core/controllers/router-config.base.d.ts +0 -7
  324. package/core/controllers/router-config.base.js +0 -18
  325. package/core/controllers/schemas/boolean.schema.d.ts +0 -2
  326. package/core/controllers/schemas/boolean.schema.js +0 -12
  327. package/core/controllers/schemas/document-number.schema.d.ts +0 -1
  328. package/core/controllers/schemas/document-number.schema.js +0 -26
  329. package/core/controllers/schemas/email.schema.d.ts +0 -1
  330. package/core/controllers/schemas/email.schema.js +0 -13
  331. package/core/controllers/schemas/list-query.schema.d.ts +0 -17
  332. package/core/controllers/schemas/list-query.schema.js +0 -19
  333. package/core/controllers/schemas/native-enum.schema.d.ts +0 -7
  334. package/core/controllers/schemas/native-enum.schema.js +0 -28
  335. package/core/controllers/schemas/set-mask-document-number.schema.d.ts +0 -1
  336. package/core/controllers/schemas/set-mask-document-number.schema.js +0 -13
  337. package/core/database/entity.base.d.ts +0 -27
  338. package/core/database/entity.base.js +0 -145
  339. package/core/database/entity.decorator.d.ts +0 -12
  340. package/core/database/entity.decorator.js +0 -37
  341. package/core/database/prisma-client-with-custom-transaction.interface.d.ts +0 -8
  342. package/core/database/prisma-client-with-custom-transaction.interface.js +0 -2
  343. package/core/database/prisma-resolver.d.ts +0 -2
  344. package/core/database/prisma-resolver.js +0 -74
  345. package/core/database/prisma-transactional-client.d.ts +0 -11
  346. package/core/database/prisma-transactional-client.js +0 -25
  347. package/core/database/prisma.service.d.ts +0 -24
  348. package/core/database/prisma.service.js +0 -104
  349. package/core/database/repository.base.d.ts +0 -83
  350. package/core/database/repository.base.js +0 -668
  351. package/core/dtos/pagination.dto.d.ts +0 -9
  352. package/core/dtos/pagination.dto.js +0 -49
  353. package/core/errors/bad-request.error.d.ts +0 -5
  354. package/core/errors/bad-request.error.js +0 -10
  355. package/core/errors/conflict.error.d.ts +0 -4
  356. package/core/errors/conflict.error.js +0 -10
  357. package/core/errors/error.base.d.ts +0 -4
  358. package/core/errors/error.base.js +0 -11
  359. package/core/errors/no-content.error.d.ts +0 -5
  360. package/core/errors/no-content.error.js +0 -10
  361. package/core/errors/not-allowed.error.d.ts +0 -5
  362. package/core/errors/not-allowed.error.js +0 -10
  363. package/core/errors/resource-not-found.error.d.ts +0 -5
  364. package/core/errors/resource-not-found.error.js +0 -10
  365. package/core/errors/use-case-error.d.ts +0 -3
  366. package/core/errors/use-case-error.js +0 -2
  367. package/core/errors/user-already-exist.error.d.ts +0 -4
  368. package/core/errors/user-already-exist.error.js +0 -10
  369. package/core/errors/wrong-credentials.error.d.ts +0 -4
  370. package/core/errors/wrong-credentials.error.js +0 -10
  371. package/core/health-check/health-check.controller.d.ts +0 -5
  372. package/core/health-check/health-check.controller.js +0 -32
  373. package/core/health-check/health-check.module.d.ts +0 -2
  374. package/core/health-check/health-check.module.js +0 -19
  375. package/core/index.d.ts +0 -18
  376. package/core/index.js +0 -7
  377. package/core/koala-app.d.ts +0 -64
  378. package/core/koala-app.js +0 -258
  379. package/core/koala-global-vars.d.ts +0 -7
  380. package/core/koala-global-vars.js +0 -9
  381. package/core/koala-nest-database.module.d.ts +0 -16
  382. package/core/koala-nest-database.module.js +0 -52
  383. package/core/koala-nest-http.module.d.ts +0 -13
  384. package/core/koala-nest-http.module.js +0 -37
  385. package/core/koala-nest.module.d.ts +0 -17
  386. package/core/koala-nest.module.js +0 -66
  387. package/core/mapping/auto-mapping-class-context.d.ts +0 -16
  388. package/core/mapping/auto-mapping-class-context.js +0 -18
  389. package/core/mapping/auto-mapping-context.d.ts +0 -11
  390. package/core/mapping/auto-mapping-context.js +0 -24
  391. package/core/mapping/auto-mapping-list.d.ts +0 -28
  392. package/core/mapping/auto-mapping-list.js +0 -99
  393. package/core/mapping/auto-mapping-profile.d.ts +0 -3
  394. package/core/mapping/auto-mapping-profile.js +0 -6
  395. package/core/mapping/auto-mapping.decorator.d.ts +0 -9
  396. package/core/mapping/auto-mapping.decorator.js +0 -27
  397. package/core/mapping/auto-mapping.module.d.ts +0 -5
  398. package/core/mapping/auto-mapping.module.js +0 -29
  399. package/core/mapping/auto-mapping.service.d.ts +0 -20
  400. package/core/mapping/auto-mapping.service.js +0 -197
  401. package/core/mapping/create-map.d.ts +0 -3
  402. package/core/mapping/create-map.js +0 -7
  403. package/core/mapping/for-member.d.ts +0 -5
  404. package/core/mapping/for-member.js +0 -8
  405. package/core/request-overflow/request-handler.base.d.ts +0 -4
  406. package/core/request-overflow/request-handler.base.js +0 -6
  407. package/core/request-overflow/request-result.d.ts +0 -15
  408. package/core/request-overflow/request-result.js +0 -37
  409. package/core/request-overflow/request-validator.base.d.ts +0 -7
  410. package/core/request-overflow/request-validator.base.js +0 -26
  411. package/core/security/strategies/api-key.strategy.d.ts +0 -16
  412. package/core/security/strategies/api-key.strategy.js +0 -31
  413. package/core/utils/assing-object.d.ts +0 -5
  414. package/core/utils/assing-object.js +0 -6
  415. package/core/utils/automap-cycle-context.d.ts +0 -6
  416. package/core/utils/automap-cycle-context.js +0 -33
  417. package/core/utils/env.config.d.ts +0 -6
  418. package/core/utils/env.config.js +0 -18
  419. package/core/utils/filter-request-params.d.ts +0 -13
  420. package/core/utils/filter-request-params.js +0 -22
  421. package/core/utils/find-on-list.d.ts +0 -2
  422. package/core/utils/find-on-list.js +0 -13
  423. package/core/utils/generate-prisma-include-schema.d.ts +0 -9
  424. package/core/utils/generate-prisma-include-schema.js +0 -60
  425. package/core/utils/get-type-by-prop.d.ts +0 -2
  426. package/core/utils/get-type-by-prop.js +0 -11
  427. package/core/utils/hydrate-entity-from-cache.d.ts +0 -22
  428. package/core/utils/hydrate-entity-from-cache.js +0 -76
  429. package/core/utils/instanciate-class-with-dependencies-injection.d.ts +0 -2
  430. package/core/utils/instanciate-class-with-dependencies-injection.js +0 -10
  431. package/core/utils/interfaces/icomparable.d.ts +0 -5
  432. package/core/utils/interfaces/icomparable.js +0 -6
  433. package/core/utils/is-plain-object.d.ts +0 -1
  434. package/core/utils/is-plain-object.js +0 -8
  435. package/core/utils/list.d.ts +0 -39
  436. package/core/utils/list.js +0 -167
  437. package/core/utils/promise-all.d.ts +0 -7
  438. package/core/utils/promise-all.js +0 -19
  439. package/core/utils/proxy.d.ts +0 -1
  440. package/core/utils/proxy.js +0 -27
  441. package/core/utils/set-mask-document-number.d.ts +0 -1
  442. package/core/utils/set-mask-document-number.js +0 -13
  443. package/core/validators/file-validator.d.ts +0 -27
  444. package/core/validators/file-validator.js +0 -94
  445. package/decorators/api-exclude-endpoint-diff-develop.decorator.d.ts +0 -1
  446. package/decorators/api-exclude-endpoint-diff-develop.decorator.js +0 -9
  447. package/decorators/api-property-enum.decorator.d.ts +0 -8
  448. package/decorators/api-property-enum.decorator.js +0 -21
  449. package/decorators/api-property-only-develop.decorator.d.ts +0 -2
  450. package/decorators/api-property-only-develop.decorator.js +0 -9
  451. package/decorators/cookies.decorator.d.ts +0 -1
  452. package/decorators/cookies.decorator.js +0 -8
  453. package/decorators/is-public.decorator.d.ts +0 -2
  454. package/decorators/is-public.decorator.js +0 -7
  455. package/decorators/upload.decorator.d.ts +0 -1
  456. package/decorators/upload.decorator.js +0 -18
  457. package/env/env.d.ts +0 -25
  458. package/env/env.js +0 -14
  459. package/env/env.module.d.ts +0 -2
  460. package/env/env.module.js +0 -20
  461. package/env/env.service.d.ts +0 -7
  462. package/env/env.service.js +0 -28
  463. package/filters/domain-errors.filter.d.ts +0 -18
  464. package/filters/domain-errors.filter.js +0 -92
  465. package/filters/global-exception.filter.d.ts +0 -8
  466. package/filters/global-exception.filter.js +0 -68
  467. package/filters/prisma-validation-exception.filter.d.ts +0 -10
  468. package/filters/prisma-validation-exception.filter.js +0 -82
  469. package/filters/zod-errors.filter.d.ts +0 -9
  470. package/filters/zod-errors.filter.js +0 -60
  471. package/services/logging/ilogging.service.d.ts +0 -16
  472. package/services/logging/ilogging.service.js +0 -6
  473. package/services/logging/logging.service.d.ts +0 -4
  474. package/services/logging/logging.service.js +0 -20
  475. package/services/redis/iredis.service.d.ts +0 -6
  476. package/services/redis/iredis.service.js +0 -6
  477. package/services/redis/redis.service.d.ts +0 -14
  478. package/services/redis/redis.service.js +0 -65
  479. package/services/redlock/ired-lock.service.d.ts +0 -4
  480. package/services/redlock/ired-lock.service.js +0 -6
  481. package/services/redlock/red-lock.service.d.ts +0 -9
  482. package/services/redlock/red-lock.service.js +0 -46
  483. package/test/koala-app-test-dependencies.d.ts +0 -10
  484. package/test/koala-app-test-dependencies.js +0 -13
  485. package/test/koala-app-test.d.ts +0 -22
  486. package/test/koala-app-test.js +0 -77
  487. package/test/repositories/in-memory-base.repository.d.ts +0 -17
  488. package/test/repositories/in-memory-base.repository.js +0 -67
  489. package/test/services/fake-logging.service.d.ts +0 -4
  490. package/test/services/fake-logging.service.js +0 -9
  491. package/test/services/fake-red-lock.service.d.ts +0 -5
  492. package/test/services/fake-red-lock.service.js +0 -11
  493. package/test/utils/create-e2e-database.d.ts +0 -7
  494. package/test/utils/create-e2e-database.js +0 -38
  495. package/test/utils/e2e-database-client.d.ts +0 -7
  496. package/test/utils/e2e-database-client.js +0 -12
  497. package/test/utils/wait-for.d.ts +0 -1
  498. package/test/utils/wait-for.js +0 -21
  499. package/tsconfig.lib.tsbuildinfo +0 -1
@@ -0,0 +1,157 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import {
4
+ appModuleMustContain,
5
+ appModuleMustNotContain,
6
+ buildProjectExpectation,
7
+ forbiddenPathsForExpectation,
8
+ healthControllerMustContain,
9
+ healthControllerMustNotContain,
10
+ infraModuleMustContain,
11
+ infraModuleMustNotContain,
12
+ requiredPackagesForExpectation,
13
+ requiredPathsForExpectation
14
+ } from "../constants/cli-project-checklist.js";
15
+ import { AuthStrategy, ExtraFeature, Template } from "../constants/domain.js";
16
+ import { detectProjectState } from "./detect-project-state.js";
17
+ import { resolveProjectPath } from "./resolve-project-path.js";
18
+ import { assertAuthStrategyProject } from "./auth-strategy-validation.js";
19
+ function readOptional(projectRoot, relativePath) {
20
+ const filePath = path.join(projectRoot, relativePath);
21
+ return existsSync(filePath) ? readFileSync(filePath, "utf8") : null;
22
+ }
23
+ function expectContains(violations, label, source, patterns) {
24
+ if (!source) {
25
+ if (patterns.length > 0) {
26
+ violations.push(`missing:${label}`);
27
+ }
28
+ return;
29
+ }
30
+ for (const pattern of patterns) {
31
+ if (!source.includes(pattern)) {
32
+ violations.push(`${label}: ausente "${pattern}"`);
33
+ }
34
+ }
35
+ }
36
+ function expectNotContains(violations, label, source, patterns) {
37
+ if (!source) {
38
+ return;
39
+ }
40
+ for (const pattern of patterns) {
41
+ if (source.includes(pattern)) {
42
+ violations.push(`${label}: inesperado "${pattern}"`);
43
+ }
44
+ }
45
+ }
46
+ function readInstalledPackages(projectRoot) {
47
+ const packageJsonPath = path.join(projectRoot, "package.json");
48
+ if (!existsSync(packageJsonPath)) {
49
+ return null;
50
+ }
51
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
52
+ return {
53
+ ...packageJson.dependencies,
54
+ ...packageJson.devDependencies
55
+ };
56
+ }
57
+ export function listCliProjectViolations(projectName = "", expectation) {
58
+ const projectRoot = resolveProjectPath(projectName);
59
+ const violations = [];
60
+ for (const relativePath of requiredPathsForExpectation(expectation)) {
61
+ if (!existsSync(path.join(projectRoot, relativePath))) {
62
+ violations.push(`path:obrigatório ausente ${relativePath}`);
63
+ }
64
+ }
65
+ for (const relativePath of forbiddenPathsForExpectation(expectation)) {
66
+ if (existsSync(path.join(projectRoot, relativePath))) {
67
+ violations.push(`path:proibido presente ${relativePath}`);
68
+ }
69
+ }
70
+ const appModule = readOptional(projectRoot, "src/host/app.module.ts");
71
+ const infraModule = readOptional(projectRoot, "src/infra/infra.module.ts");
72
+ const healthController = readOptional(projectRoot, "src/host/controllers/health-check/health-check.controller.ts");
73
+ expectContains(violations, "app.module", appModule, appModuleMustContain(expectation));
74
+ expectNotContains(violations, "app.module", appModule, appModuleMustNotContain(expectation));
75
+ expectContains(violations, "infra.module", infraModule, infraModuleMustContain(expectation));
76
+ expectNotContains(violations, "infra.module", infraModule, infraModuleMustNotContain(expectation));
77
+ expectContains(violations, "health-check.controller", healthController, healthControllerMustContain(expectation));
78
+ expectNotContains(violations, "health-check.controller", healthController, healthControllerMustNotContain(expectation));
79
+ if (expectation.template === Template.CRUD_SAMPLE) {
80
+ const deletePerson = readOptional(projectRoot, "src/host/controllers/person/delete-person.controller.ts");
81
+ expectContains(violations, "delete-person.controller", deletePerson, [
82
+ "RestrictionByProfile"
83
+ ]);
84
+ }
85
+ const nestCliPath = path.join(projectRoot, "nest-cli.json");
86
+ if (existsSync(nestCliPath)) {
87
+ const nestCli = JSON.parse(readFileSync(nestCliPath, "utf8"));
88
+ if (nestCli.entryFile !== "host/main") {
89
+ violations.push('nest-cli.json: entryFile deve ser "host/main"');
90
+ }
91
+ }
92
+ const packageJson = readOptional(projectRoot, "package.json");
93
+ if (packageJson?.includes('"start:prod": "node dist/host/main"') === false) {
94
+ violations.push("package.json: start:prod deve apontar para dist/host/main");
95
+ }
96
+ const installed = readInstalledPackages(projectRoot);
97
+ if (installed) {
98
+ for (const dependency of requiredPackagesForExpectation(expectation)) {
99
+ if (!installed[dependency]) {
100
+ violations.push(`package:obrigatório ausente ${dependency}`);
101
+ }
102
+ }
103
+ if (expectation.cache !== "redis" && installed.ioredis) {
104
+ violations.push("package:proibido presente ioredis");
105
+ }
106
+ if (!expectation.cronJobs && installed["cron-parser"]) {
107
+ violations.push("package:proibido presente cron-parser");
108
+ }
109
+ if (!expectation.health && installed["@nestjs/terminus"]) {
110
+ violations.push("package:proibido presente @nestjs/terminus");
111
+ }
112
+ }
113
+ try {
114
+ const detected = detectProjectState(projectName);
115
+ if (detected.template !== expectation.template) {
116
+ violations.push(`state:template esperado ${expectation.template}, detectado ${detected.template}`);
117
+ }
118
+ if (detected.cache !== expectation.cache) {
119
+ violations.push(`state:cache esperado ${String(expectation.cache)}, detectado ${String(detected.cache)}`);
120
+ }
121
+ if (detected.health !== expectation.health) {
122
+ violations.push(`state:health esperado ${expectation.health}, detectado ${detected.health}`);
123
+ }
124
+ if (detected.cronJobs !== expectation.cronJobs) {
125
+ violations.push(`state:cronJobs esperado ${expectation.cronJobs}, detectado ${detected.cronJobs}`);
126
+ }
127
+ if (detected.eventJobs !== expectation.eventJobs) {
128
+ violations.push(`state:eventJobs esperado ${expectation.eventJobs}, detectado ${detected.eventJobs}`);
129
+ }
130
+ const expectedAuth = expectation.auth === false ? false : [...expectation.auth].sort().join(",");
131
+ const detectedAuth = detected.auth === false ? false : [...detected.auth].sort().join(",");
132
+ if (expectedAuth !== detectedAuth) {
133
+ violations.push(`state:auth esperado ${String(expectedAuth)}, detectado ${String(detectedAuth)}`);
134
+ }
135
+ } catch (error) {
136
+ violations.push(`state:${error instanceof Error ? error.message : String(error)}`);
137
+ }
138
+ return [...new Set(violations)].sort();
139
+ }
140
+ export function assertCliProject(projectName = "", expectation) {
141
+ const violations = listCliProjectViolations(projectName, expectation);
142
+ if (violations.length > 0) {
143
+ throw new Error(`Checklist CLI falhou (${expectation.template}, auth=${expectation.auth === false ? "none" : expectation.auth.join("+")}):
144
+ ${violations.join(`
145
+ `)}`);
146
+ }
147
+ if (expectation.auth !== false) {
148
+ assertAuthStrategyProject(projectName, expectation.auth);
149
+ } else {
150
+ assertAuthStrategyProject(projectName, false);
151
+ }
152
+ }
153
+ export function assertCliProjectFromSelection(projectName = "", template, auth, features) {
154
+ assertCliProject(projectName, buildProjectExpectation(template, auth, features));
155
+ }
156
+
157
+ export { buildProjectExpectation };
@@ -0,0 +1,131 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import {
4
+ AddArgKind,
5
+ ExtraFeature,
6
+ FEATURE_ALIASES,
7
+ isAuthStrategy,
8
+ listMissingAuthStrategies,
9
+ mergeAuthStrategies,
10
+ ProjectMarker,
11
+ resolveAuthStrategiesFromModule,
12
+ Template
13
+ } from "../constants/domain.js";
14
+ import { resolveProjectPath } from "./resolve-project-path.js";
15
+ export function assertKoalaProject(projectName = "") {
16
+ const root = resolveProjectPath(projectName);
17
+ const envPath = path.join(root, "src/core/env.ts");
18
+ if (!existsSync(envPath)) {
19
+ throw new Error("Projeto Koala Nest não encontrado. Execute o comando na raiz do projeto (com src/core/env.ts).");
20
+ }
21
+ return root;
22
+ }
23
+ function readProjectFile(projectName, relativePath) {
24
+ return readFileSync(path.join(resolveProjectPath(projectName), relativePath), "utf8");
25
+ }
26
+ export function detectProjectState(projectName = "") {
27
+ assertKoalaProject(projectName);
28
+ const appModule = readProjectFile(projectName, "src/host/app.module.ts");
29
+ const authModulePath = path.join(resolveProjectPath(projectName), "src/host/controllers/auth/auth.module.ts");
30
+ const authModule = existsSync(authModulePath) ? readFileSync(authModulePath, "utf8") : "";
31
+ const hasPersonModule = appModule.includes(ProjectMarker.PERSON_MODULE) || existsSync(path.join(resolveProjectPath(projectName), "src/host/controllers/person/person.module.ts"));
32
+ let auth = false;
33
+ if (existsSync(authModulePath) && appModule.includes(ProjectMarker.SECURITY_MODULE)) {
34
+ auth = resolveAuthStrategiesFromModule(authModule);
35
+ }
36
+ let cache = false;
37
+ const infraModule = readProjectFile(projectName, "src/infra/infra.module.ts");
38
+ if (infraModule.includes(ProjectMarker.CACHE_SERVICE_PROVIDER)) {
39
+ const hasRedisFile = existsSync(path.join(resolveProjectPath(projectName), "src/infra/common/redis-cache.service.ts"));
40
+ cache = hasRedisFile ? "redis" : "memory";
41
+ }
42
+ return {
43
+ template: hasPersonModule ? Template.CRUD_SAMPLE : Template.DEFAULT,
44
+ auth,
45
+ cache,
46
+ health: appModule.includes(ProjectMarker.HEALTH_CHECK_MODULE),
47
+ cronJobs: existsSync(path.join(resolveProjectPath(projectName), "src/core/utils/cron-expression-to-boolean.ts")),
48
+ eventJobs: existsSync(path.join(resolveProjectPath(projectName), "src/core/background-services/event-service/event-handler.base.ts"))
49
+ };
50
+ }
51
+ export function listAvailableAddOptions(state) {
52
+ const features = [];
53
+ if (state.cache !== "redis") {
54
+ features.push(ExtraFeature.CACHE);
55
+ }
56
+ if (!state.health) {
57
+ features.push(ExtraFeature.HEALTH_CHECK);
58
+ }
59
+ if (!state.cronJobs) {
60
+ features.push(ExtraFeature.INTERNAL_CRON_JOBS);
61
+ }
62
+ if (!state.eventJobs) {
63
+ features.push(ExtraFeature.INTERNAL_EVENT_JOBS);
64
+ }
65
+ return {
66
+ authStrategies: listMissingAuthStrategies(state.auth),
67
+ features
68
+ };
69
+ }
70
+ export function parseAddArgs(args) {
71
+ const parsed = [];
72
+ for (let index = 0;index < args.length; index += 1) {
73
+ const arg = args[index]?.toLowerCase();
74
+ if (!arg) {
75
+ continue;
76
+ }
77
+ if (arg === AddArgKind.AUTH) {
78
+ const strategies = [];
79
+ let cursor = index + 1;
80
+ while (cursor < args.length) {
81
+ const strategy = args[cursor]?.toLowerCase();
82
+ if (!strategy || !isAuthStrategy(strategy)) {
83
+ break;
84
+ }
85
+ strategies.push(strategy);
86
+ cursor += 1;
87
+ }
88
+ if (strategies.length === 0) {
89
+ throw new Error("Use: kl-nest add auth jwt ou kl-nest add auth oauth2 ou kl-nest add auth jwt oauth2");
90
+ }
91
+ parsed.push({
92
+ kind: AddArgKind.AUTH,
93
+ strategies: Array.from(new Set(strategies))
94
+ });
95
+ index = cursor - 1;
96
+ continue;
97
+ }
98
+ const feature = FEATURE_ALIASES[arg];
99
+ if (!feature) {
100
+ throw new Error(`Opção desconhecida: "${args[index]}". Use: cache, auth, health, cron, events.`);
101
+ }
102
+ parsed.push({ kind: AddArgKind.FEATURE, feature });
103
+ }
104
+ return parsed;
105
+ }
106
+ export function dedupeAddArgs(args) {
107
+ const seenFeatures = new Set;
108
+ const authStrategies = new Set;
109
+ const result = [];
110
+ for (const arg of args) {
111
+ if (arg.kind === AddArgKind.AUTH) {
112
+ for (const strategy of arg.strategies) {
113
+ authStrategies.add(strategy);
114
+ }
115
+ continue;
116
+ }
117
+ if (!seenFeatures.has(arg.feature)) {
118
+ seenFeatures.add(arg.feature);
119
+ result.push(arg);
120
+ }
121
+ }
122
+ if (authStrategies.size > 0) {
123
+ result.unshift({
124
+ kind: AddArgKind.AUTH,
125
+ strategies: Array.from(authStrategies)
126
+ });
127
+ }
128
+ return result;
129
+ }
130
+
131
+ export { mergeAuthStrategies };
@@ -0,0 +1,9 @@
1
+ import { getPackageManager } from "./get-package-manager.js";
2
+ import { resolveProjectPath } from "./resolve-project-path.js";
3
+ import { runCommand } from "./run-command.js";
4
+ export async function formatCode(projectName) {
5
+ if (process.env.CI === "1" || process.env.KOALA_SKIP_FORMAT === "1") {
6
+ return;
7
+ }
8
+ await runCommand([getPackageManager(projectName), "run", "format"], resolveProjectPath(projectName));
9
+ }
@@ -0,0 +1,12 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { resolveProjectPath } from "./resolve-project-path.js";
4
+ export function getPackageManager(projectName) {
5
+ const packageJson = JSON.parse(readFileSync(path.join(resolveProjectPath(projectName), "package.json"), "utf8"));
6
+ const raw = packageJson.packageManager ?? "bun";
7
+ const manager = raw.split("@")[0];
8
+ if (manager === "npm" || manager === "pnpm" || manager === "bun") {
9
+ return manager;
10
+ }
11
+ return "bun";
12
+ }
@@ -0,0 +1,19 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ function isPackageRoot(dir) {
5
+ if (!existsSync(path.join(dir, "package.json"))) {
6
+ return false;
7
+ }
8
+ return existsSync(path.join(dir, "koala-nest")) || existsSync(path.join(dir, "libs", "koala-nest"));
9
+ }
10
+ export function getPackageRoot(fromUrl = import.meta.url) {
11
+ let dir = path.dirname(fileURLToPath(fromUrl));
12
+ while (dir !== path.dirname(dir)) {
13
+ if (isPackageRoot(dir)) {
14
+ return dir;
15
+ }
16
+ dir = path.dirname(dir);
17
+ }
18
+ throw new Error("Não foi possível resolver a raiz do pacote koala-nest.");
19
+ }
@@ -0,0 +1,15 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { getPackageRoot } from "./get-package-root.js";
4
+ export function getSourceCodePath() {
5
+ const root = getPackageRoot(import.meta.url);
6
+ const distTemplate = path.join(root, "dist", "koala-nest");
7
+ if (existsSync(distTemplate)) {
8
+ return distTemplate;
9
+ }
10
+ const publishedTemplate = path.join(root, "koala-nest");
11
+ if (existsSync(publishedTemplate)) {
12
+ return publishedTemplate;
13
+ }
14
+ return path.join(root, "libs", "koala-nest");
15
+ }
@@ -0,0 +1,258 @@
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 {
11
+ AUTH_DEV_PACKAGES,
12
+ AUTH_PACKAGES,
13
+ CACHE_PACKAGES,
14
+ CORE_PACKAGES,
15
+ CRON_PACKAGES,
16
+ devAddFlag,
17
+ HEALTH_PACKAGES
18
+ } from "../constants/core-packages.js";
19
+ import {
20
+ AuthChoice,
21
+ AuthStrategy,
22
+ ExtraFeature,
23
+ InstallModule as Modules,
24
+ Template
25
+ } from "../constants/domain.js";
26
+ import { getSourceCodePath } from "./get-source-code-path.js";
27
+ import {
28
+ patchAppModuleForHealth,
29
+ patchHealthCheckWithoutRedis
30
+ } from "./patch-health-module.js";
31
+ import {
32
+ patchInfraModuleForAuth,
33
+ patchInfraModuleForCache,
34
+ stripInfraModuleCache
35
+ } from "./patch-infra-module.js";
36
+ import { patchAuthInstall } from "./patch-auth-install.js";
37
+ import { patchMainForAuth, stripMainOptionalFeatures } from "./patch-main.js";
38
+ import { restoreDefineDocumentationWithAuth } from "./patch-define-documentation.js";
39
+ import { pruneCoreAuthForSlimTemplate } from "./prune-core-auth.js";
40
+ import { removeSampleParts } from "./remove-sample-parts.js";
41
+ import { resolveProjectPath } from "./resolve-project-path.js";
42
+ import { runCommand } from "./run-command.js";
43
+ import { getPackageManager } from "./get-package-manager.js";
44
+ export {
45
+ AuthChoice,
46
+ AuthStrategy,
47
+ CRUD_BUNDLED_FEATURES,
48
+ ExtraFeature,
49
+ InstallModule as Modules,
50
+ mapExtraFeatureToModule,
51
+ mergeCrudSampleFeatures,
52
+ resolveNewProjectOptions,
53
+ Template
54
+ } from "../constants/domain.js";
55
+ function install(modulePath, projectName) {
56
+ const koalaNestPath = path.join(getSourceCodePath(), modulePath);
57
+ const projectPath = path.join(resolveProjectPath(projectName), modulePath);
58
+ mkdirSync(path.dirname(projectPath), { recursive: true });
59
+ cpSync(koalaNestPath, projectPath, { recursive: true, force: true });
60
+ }
61
+ async function installPackages(projectName, packages, devPackages = []) {
62
+ const packageManager = getPackageManager(projectName);
63
+ const projectPath = resolveProjectPath(projectName);
64
+ if (packages.length > 0) {
65
+ await runCommand([packageManager, "add", ...packages], projectPath);
66
+ }
67
+ if (devPackages.length > 0) {
68
+ await runCommand([packageManager, "add", devAddFlag(packageManager), ...devPackages], projectPath);
69
+ }
70
+ }
71
+ function patchInfraModuleFile(projectName, withCache) {
72
+ const infraModulePath = path.join(resolveProjectPath(projectName), "src/infra/infra.module.ts");
73
+ const content = readFileSync(infraModulePath, "utf8");
74
+ writeFileSync(infraModulePath, withCache ? patchInfraModuleForCache(content) : stripInfraModuleCache(content));
75
+ }
76
+ function patchInfraModuleAuthFile(projectName) {
77
+ const infraModulePath = path.join(resolveProjectPath(projectName), "src/infra/infra.module.ts");
78
+ writeFileSync(infraModulePath, patchInfraModuleForAuth(readFileSync(infraModulePath, "utf8")));
79
+ }
80
+ function patchAppModuleFile(projectName, replacer) {
81
+ const appModulePath = path.join(resolveProjectPath(projectName), "src/host/app.module.ts");
82
+ writeFileSync(appModulePath, replacer(readFileSync(appModulePath, "utf8")));
83
+ }
84
+ function patchMainFile(projectName, replacer) {
85
+ const mainPath = path.join(resolveProjectPath(projectName), "src/host/main.ts");
86
+ writeFileSync(mainPath, replacer(readFileSync(mainPath, "utf8")));
87
+ }
88
+ function installCacheInfrastructure(projectName, withRedis) {
89
+ install("src/domain/common/icache.service.ts", projectName);
90
+ install("src/domain/common/ired-lock.service.ts", projectName);
91
+ install("src/infra/common/in-memory-cache.service.ts", projectName);
92
+ install("src/infra/common/cache-service.provider.ts", projectName);
93
+ install("src/infra/common/red-lock.service.ts", projectName);
94
+ if (withRedis) {
95
+ install("src/infra/common/redis-cache.service.ts", projectName);
96
+ } else {
97
+ rmSync(path.join(resolveProjectPath(projectName), "src/infra/common/redis-cache.service.ts"), { force: true });
98
+ let provider = readFileSync(path.join(resolveProjectPath(projectName), "src/infra/common/cache-service.provider.ts"), "utf8");
99
+ provider = provider.replace(`import { RedisCacheService } from '@/infra/common/redis-cache.service';
100
+ `, "").replace(/const redisUrl = env\.get\('REDIS_CONNECTION_STRING'\);\n\n {4}this\.delegate = redisUrl\n {6}\? new RedisCacheService\(redisUrl, this\.resolveKeyPrefix\(env\)\)\n {6}: new InMemoryCacheService\(\);/, "this.delegate = new InMemoryCacheService();");
101
+ writeFileSync(path.join(resolveProjectPath(projectName), "src/infra/common/cache-service.provider.ts"), provider);
102
+ }
103
+ patchInfraModuleFile(projectName, true);
104
+ }
105
+ export async function installModule(module, template, projectName = "", options = {}) {
106
+ switch (module) {
107
+ case Modules.CORE: {
108
+ install("src/application/common", projectName);
109
+ install("src/application/mapping/mapping.provider.ts", projectName);
110
+ install("src/core", projectName);
111
+ install("src/domain/common/ilogging.service.ts", projectName);
112
+ install("src/domain/dtos/pagination.dto.ts", projectName);
113
+ install("src/host/controllers/common", projectName);
114
+ install("src/host/decorators", projectName);
115
+ install("src/host/filters", projectName);
116
+ install("src/host/open-api", projectName);
117
+ install("src/host/jobs", projectName);
118
+ install("src/host/app.module.ts", projectName);
119
+ install("src/host/main.ts", projectName);
120
+ install("src/infra/common/env.service.ts", projectName);
121
+ install("src/infra/common/logging.service.ts", projectName);
122
+ install("src/infra/services", projectName);
123
+ install("src/infra/database/migrations/generate-migration.ts", projectName);
124
+ install("src/infra/database/migrations/migration-datasource.ts", projectName);
125
+ install("src/infra/database/data-source-factory.ts", projectName);
126
+ install("src/infra/database/database.module.ts", projectName);
127
+ install("src/infra/repositories/repository.base.ts", projectName);
128
+ install("src/infra/repositories/repository.module.ts", projectName);
129
+ install("src/infra/infra.module.ts", projectName);
130
+ install("src/test", projectName);
131
+ rmSync(path.join(resolveProjectPath(projectName), "src/core/background-services"), { recursive: true, force: true });
132
+ rmSync(path.join(resolveProjectPath(projectName), "src/core/utils/cron-expression-to-boolean.ts"), { force: true });
133
+ rmSync(path.join(resolveProjectPath(projectName), "src/core/utils/person-list-cache.ts"), { force: true });
134
+ rmSync(path.join(resolveProjectPath(projectName), "src/core/utils/build-list-cache-key.ts"), { force: true });
135
+ rmSync(path.join(resolveProjectPath(projectName), "src/host/bootstrap"), {
136
+ recursive: true,
137
+ force: true
138
+ });
139
+ rmSync(path.join(resolveProjectPath(projectName), "src/host/controllers/health-check"), { recursive: true, force: true });
140
+ rmSync(path.join(resolveProjectPath(projectName), "src/infra/services/database.indicator.service.ts"), { force: true });
141
+ rmSync(path.join(resolveProjectPath(projectName), "src/infra/services/redis.indicator.service.ts"), { force: true });
142
+ rmSync(path.join(resolveProjectPath(projectName), "src/infra/services/logged-user-info.service.ts"), { force: true });
143
+ pruneCoreAuthForSlimTemplate(projectName);
144
+ const projectPath = resolveProjectPath(projectName);
145
+ const packageManager = getPackageManager(projectName);
146
+ rmSync(path.join(projectPath, "src/test/cli"), {
147
+ recursive: true,
148
+ force: true
149
+ });
150
+ if (packageManager === "bun") {
151
+ cpSync(path.join(getSourceCodePath(), "bunfig.toml"), path.join(projectPath, "bunfig.toml"));
152
+ }
153
+ for (const configFile of ["tsconfig.build.json", ".env.example"]) {
154
+ cpSync(path.join(getSourceCodePath(), configFile), path.join(projectPath, configFile));
155
+ }
156
+ patchInfraModuleFile(projectName, false);
157
+ patchMainFile(projectName, stripMainOptionalFeatures);
158
+ if (!options.skipPackages) {
159
+ await installPackages(projectName, CORE_PACKAGES);
160
+ }
161
+ if (template === Template.DEFAULT) {
162
+ await removeSampleParts(projectName);
163
+ } else {
164
+ install("src/application/mapping", projectName);
165
+ install("src/application/person", projectName);
166
+ install("src/domain/entities", projectName);
167
+ install("src/domain/repositories", projectName);
168
+ install("src/domain/dtos", projectName);
169
+ install("src/host/controllers/person", projectName);
170
+ install("src/infra/repositories/person.repository.ts", projectName);
171
+ install("src/infra/database/migrations", projectName);
172
+ }
173
+ break;
174
+ }
175
+ case Modules.AUTH: {
176
+ install("src/application/auth", projectName);
177
+ install("src/domain/dtos/logged-user-info.dto.ts", projectName);
178
+ install("src/domain/services", projectName);
179
+ install("src/domain/auth", projectName);
180
+ install("src/domain/entities/user", projectName);
181
+ install("src/domain/repositories/iuser.repository.ts", projectName);
182
+ install("src/infra/auth", projectName);
183
+ install("src/infra/repositories/user.repository.ts", projectName);
184
+ install("src/infra/services/logged-user-info.service.ts", projectName);
185
+ install("src/core/utils/hash-password.ts", projectName);
186
+ install("src/core/utils/name-to-login.ts", projectName);
187
+ const initMigration = "src/infra/database/migrations/1781281330533-Init.ts";
188
+ if (!existsSync(path.join(resolveProjectPath(projectName), initMigration))) {
189
+ install(initMigration, projectName);
190
+ }
191
+ install("src/host/security", projectName);
192
+ install("src/host/controllers/auth", projectName);
193
+ install("src/host/controllers/oauth2", projectName);
194
+ install("src/core/auth", projectName);
195
+ install("src/core/types/auth-provider-config-response.type.ts", projectName);
196
+ install("src/host/decorators/scalar-token-endpoint.decorator.ts", projectName);
197
+ install("src/host/decorators/restriction-by-profile.decorator.ts", projectName);
198
+ restoreDefineDocumentationWithAuth(projectName);
199
+ if (!options.skipPackages) {
200
+ await installPackages(projectName, AUTH_PACKAGES, AUTH_DEV_PACKAGES);
201
+ }
202
+ patchMainFile(projectName, patchMainForAuth);
203
+ patchInfraModuleAuthFile(projectName);
204
+ await patchAuthInstall(projectName, options.authStrategies?.length ? options.authStrategies : [AuthStrategy.JWT]);
205
+ break;
206
+ }
207
+ case Modules.CACHE: {
208
+ installCacheInfrastructure(projectName, options.withRedis ?? false);
209
+ if (options.withRedis && !options.skipPackages) {
210
+ await installPackages(projectName, CACHE_PACKAGES);
211
+ }
212
+ if (template === Template.CRUD_SAMPLE) {
213
+ install("src/core/utils/person-list-cache.ts", projectName);
214
+ install("src/core/utils/build-list-cache-key.ts", projectName);
215
+ }
216
+ break;
217
+ }
218
+ case Modules.HEALTH: {
219
+ install("src/host/controllers/health-check", projectName);
220
+ install("src/infra/services/database.indicator.service.ts", projectName);
221
+ if (options.withRedisIndicator) {
222
+ install("src/infra/services/redis.indicator.service.ts", projectName);
223
+ } else {
224
+ patchHealthCheckWithoutRedis(projectName);
225
+ }
226
+ patchAppModuleFile(projectName, patchAppModuleForHealth);
227
+ if (!options.skipPackages) {
228
+ await installPackages(projectName, HEALTH_PACKAGES);
229
+ }
230
+ break;
231
+ }
232
+ case Modules.INTERNAL_CRON_JOBS: {
233
+ install("src/core/background-services/cron-service", projectName);
234
+ install("src/core/utils/cron-expression-to-boolean.ts", projectName);
235
+ if (!options.skipPackages) {
236
+ await installPackages(projectName, CRON_PACKAGES);
237
+ }
238
+ break;
239
+ }
240
+ case Modules.INTERNAL_EVENT_JOBS: {
241
+ install("src/core/background-services/event-service", projectName);
242
+ break;
243
+ }
244
+ }
245
+ }
246
+ export function resolveProjectFeatures(features, auth) {
247
+ const selected = new Set(features);
248
+ const cacheWithRedis = selected.has(ExtraFeature.CACHE);
249
+ const needsMemoryCache = cacheWithRedis || auth.length > 0 || selected.has(ExtraFeature.INTERNAL_CRON_JOBS);
250
+ return {
251
+ cache: needsMemoryCache,
252
+ cacheWithRedis,
253
+ cacheForCrud: cacheWithRedis,
254
+ health: selected.has(ExtraFeature.HEALTH_CHECK),
255
+ cronJobs: selected.has(ExtraFeature.INTERNAL_CRON_JOBS),
256
+ eventJobs: selected.has(ExtraFeature.INTERNAL_EVENT_JOBS)
257
+ };
258
+ }
@@ -0,0 +1,25 @@
1
+ import {
2
+ AddArgKind,
3
+ ExtraFeature,
4
+ FEATURE_INSTALL_ORDER
5
+ } from "../constants/domain.js";
6
+ export function normalizeAddArgs(args) {
7
+ const auth = args.find((item) => item.kind === AddArgKind.AUTH);
8
+ const selectedFeatures = new Set(args.filter((item) => item.kind === AddArgKind.FEATURE).map((item) => item.feature));
9
+ const ordered = [];
10
+ for (const feature of FEATURE_INSTALL_ORDER) {
11
+ if (selectedFeatures.has(feature)) {
12
+ ordered.push({ kind: AddArgKind.FEATURE, feature });
13
+ }
14
+ }
15
+ if (auth) {
16
+ const cacheIndex = ordered.findIndex((item) => item.kind === AddArgKind.FEATURE && item.feature === ExtraFeature.CACHE);
17
+ const authArg = auth;
18
+ if (cacheIndex >= 0) {
19
+ ordered.splice(cacheIndex + 1, 0, authArg);
20
+ } else {
21
+ ordered.unshift(authArg);
22
+ }
23
+ }
24
+ return ordered;
25
+ }