arkos 1.2.13-test → 1.2.13-test.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.
Files changed (265) hide show
  1. package/README.md +22 -14
  2. package/cli.js +2 -11
  3. package/dist/cjs/app.js +138 -1
  4. package/dist/cjs/app.js.map +1 -1
  5. package/dist/cjs/index.js +22 -0
  6. package/dist/cjs/modules/auth/auth.router.js +9 -83
  7. package/dist/cjs/modules/auth/auth.router.js.map +1 -1
  8. package/dist/cjs/modules/auth/auth.service.js +0 -7
  9. package/dist/cjs/modules/auth/auth.service.js.map +1 -1
  10. package/dist/cjs/modules/base/base.controller.js +11 -12
  11. package/dist/cjs/modules/base/base.controller.js.map +1 -1
  12. package/dist/cjs/modules/base/base.middlewares.js +4 -4
  13. package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
  14. package/dist/cjs/modules/base/base.router.js.map +1 -1
  15. package/dist/cjs/modules/base/base.service.js.map +1 -1
  16. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +43 -113
  17. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  18. package/dist/cjs/modules/error-handler/error-handler.controller.js +2 -0
  19. package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
  20. package/dist/cjs/modules/error-handler/utils/catch-async.js +1 -1
  21. package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
  22. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +6 -0
  23. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
  24. package/dist/cjs/modules/file-upload/file-upload.router.js +9 -21
  25. package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
  26. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +7 -0
  27. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js.map +1 -1
  28. package/dist/cjs/modules/swagger/swagger.router.js +71 -93
  29. package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
  30. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +270 -0
  31. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -0
  32. package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +66 -0
  33. package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -0
  34. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +41 -0
  35. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -0
  36. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +29 -0
  37. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -0
  38. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +30 -0
  39. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +1 -0
  40. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +471 -0
  41. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +1 -0
  42. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +575 -0
  43. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +1 -0
  44. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +253 -0
  45. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
  46. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +105 -0
  47. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -0
  48. package/dist/cjs/paths.js +9 -1
  49. package/dist/cjs/server.js +85 -3
  50. package/dist/cjs/server.js.map +1 -1
  51. package/dist/cjs/types/arkos-config.js.map +1 -1
  52. package/dist/cjs/utils/cli/build.js +2 -19
  53. package/dist/cjs/utils/cli/build.js.map +1 -1
  54. package/dist/cjs/utils/cli/dev.js +35 -47
  55. package/dist/cjs/utils/cli/dev.js.map +1 -1
  56. package/dist/cjs/utils/cli/generate.js +6 -6
  57. package/dist/cjs/utils/cli/generate.js.map +1 -1
  58. package/dist/cjs/utils/cli/start.js +4 -3
  59. package/dist/cjs/utils/cli/start.js.map +1 -1
  60. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -3
  61. package/dist/cjs/utils/cli/utils/cli.helpers.js.map +1 -1
  62. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +33 -66
  63. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
  64. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +17 -11
  65. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
  66. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +5 -0
  67. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
  68. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +1 -1
  69. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
  70. package/dist/cjs/utils/features/api.features.js +10 -4
  71. package/dist/cjs/utils/features/api.features.js.map +1 -1
  72. package/dist/cjs/utils/helpers/fs.helpers.js +12 -5
  73. package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
  74. package/dist/cjs/utils/helpers/global.helpers.js +51 -2
  75. package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
  76. package/dist/cjs/utils/helpers/models.helpers.js +81 -67
  77. package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
  78. package/dist/cjs/utils/helpers/prisma.helpers.js +7 -4
  79. package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
  80. package/dist/cjs/utils/helpers/routers.helpers.js +21 -0
  81. package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -0
  82. package/dist/cjs/utils/prisma/enhaced-prisma-json-schema-generator.js +451 -0
  83. package/dist/cjs/utils/prisma/enhaced-prisma-json-schema-generator.js.map +1 -0
  84. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +88 -0
  85. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -0
  86. package/dist/cjs/utils/prisma/prisma-schema-parser.js +158 -0
  87. package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +1 -0
  88. package/dist/cjs/utils/prisma/types.js +3 -0
  89. package/dist/cjs/utils/prisma/types.js.map +1 -0
  90. package/dist/cjs/utils/sheu.js +119 -0
  91. package/dist/cjs/utils/sheu.js.map +1 -0
  92. package/dist/esm/index.d.mts +280 -0
  93. package/dist/esm/index.mjs +22 -0
  94. package/dist/exports/index.js +1 -0
  95. package/dist/types/arkos-config.js +1 -0
  96. package/dist/types/auth.js +1 -0
  97. package/dist/types/index.js +1 -0
  98. package/dist/types/modules/base/base.middlewares.d.ts +4 -4
  99. package/dist/types/modules/base/base.service.d.ts +1 -1
  100. package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +4 -1
  101. package/dist/types/modules/error-handler/utils/catch-async.d.ts +1 -0
  102. package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +4 -0
  103. package/dist/types/modules/file-upload/file-upload.router.d.ts +1 -1
  104. package/dist/types/modules/file-upload/utils/helpers/file-upload.helpers.d.ts +2 -1
  105. package/dist/types/modules/swagger/swagger.router.d.ts +1 -1
  106. package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +3 -0
  107. package/dist/types/modules/swagger/utils/helpers/get-system-json-schema-paths.d.ts +2 -0
  108. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.d.ts +1 -0
  109. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +2 -0
  110. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.d.ts +1 -0
  111. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.d.ts +3 -0
  112. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.d.ts +3 -0
  113. package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +34 -0
  114. package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +7 -0
  115. package/dist/types/router-config.js +1 -0
  116. package/dist/types/server.d.ts +3 -0
  117. package/dist/types/types/arkos-config.d.ts +10 -5
  118. package/dist/types/utils/cli/utils/cli.helpers.d.ts +1 -1
  119. package/dist/types/utils/features/api.features.d.ts +1 -0
  120. package/dist/types/utils/helpers/global.helpers.d.ts +6 -1
  121. package/dist/types/utils/helpers/models.helpers.d.ts +31 -5
  122. package/dist/types/utils/helpers/routers.helpers.d.ts +2 -0
  123. package/dist/types/utils/prisma/enhaced-prisma-json-schema-generator.d.ts +34 -0
  124. package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +10 -0
  125. package/dist/types/utils/prisma/prisma-schema-parser.d.ts +18 -0
  126. package/dist/types/utils/prisma/types.d.ts +48 -0
  127. package/dist/types/utils/sheu.d.ts +70 -0
  128. package/dist/utils/arkos-env.js +1 -0
  129. package/dist/utils/dotenv.helpers.js +1 -0
  130. package/dist/utils/sheu.js +1 -0
  131. package/dist/utils/validate-dto.js +1 -0
  132. package/dist/utils/validate-schema.js +1 -0
  133. package/package.json +32 -34
  134. package/dist/es2020/app.js +0 -1
  135. package/dist/es2020/app.js.map +0 -1
  136. package/dist/es2020/exports/auth/index.js +0 -2
  137. package/dist/es2020/exports/auth/index.js.map +0 -1
  138. package/dist/es2020/exports/controllers/index.js +0 -4
  139. package/dist/es2020/exports/controllers/index.js.map +0 -1
  140. package/dist/es2020/exports/error-handler/index.js +0 -4
  141. package/dist/es2020/exports/error-handler/index.js.map +0 -1
  142. package/dist/es2020/exports/index.js +0 -8
  143. package/dist/es2020/exports/index.js.map +0 -1
  144. package/dist/es2020/exports/middlewares/index.js +0 -2
  145. package/dist/es2020/exports/middlewares/index.js.map +0 -1
  146. package/dist/es2020/exports/prisma/index.js +0 -3
  147. package/dist/es2020/exports/prisma/index.js.map +0 -1
  148. package/dist/es2020/exports/services/index.js +0 -9
  149. package/dist/es2020/exports/services/index.js.map +0 -1
  150. package/dist/es2020/exports/utils/index.js +0 -4
  151. package/dist/es2020/exports/utils/index.js.map +0 -1
  152. package/dist/es2020/exports/validation/index.js +0 -4
  153. package/dist/es2020/exports/validation/index.js.map +0 -1
  154. package/dist/es2020/modules/auth/auth.controller.js +0 -187
  155. package/dist/es2020/modules/auth/auth.controller.js.map +0 -1
  156. package/dist/es2020/modules/auth/auth.router.js +0 -118
  157. package/dist/es2020/modules/auth/auth.router.js.map +0 -1
  158. package/dist/es2020/modules/auth/auth.service.js +0 -185
  159. package/dist/es2020/modules/auth/auth.service.js.map +0 -1
  160. package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js +0 -73
  161. package/dist/es2020/modules/auth/utils/helpers/auth.controller.helpers.js.map +0 -1
  162. package/dist/es2020/modules/base/base.controller.js +0 -151
  163. package/dist/es2020/modules/base/base.controller.js.map +0 -1
  164. package/dist/es2020/modules/base/base.middlewares.js +0 -81
  165. package/dist/es2020/modules/base/base.middlewares.js.map +0 -1
  166. package/dist/es2020/modules/base/base.router.js +0 -17
  167. package/dist/es2020/modules/base/base.router.js.map +0 -1
  168. package/dist/es2020/modules/base/base.service.js +0 -120
  169. package/dist/es2020/modules/base/base.service.js.map +0 -1
  170. package/dist/es2020/modules/base/utils/helpers/base.controller.helpers.js +0 -77
  171. package/dist/es2020/modules/base/utils/helpers/base.controller.helpers.js.map +0 -1
  172. package/dist/es2020/modules/base/utils/helpers/base.middlewares.helpers.js +0 -44
  173. package/dist/es2020/modules/base/utils/helpers/base.middlewares.helpers.js.map +0 -1
  174. package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +0 -161
  175. package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +0 -1
  176. package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js +0 -165
  177. package/dist/es2020/modules/base/utils/helpers/base.service.helpers.js.map +0 -1
  178. package/dist/es2020/modules/email/email.service.js +0 -97
  179. package/dist/es2020/modules/email/email.service.js.map +0 -1
  180. package/dist/es2020/modules/error-handler/error-handler.controller.js +0 -105
  181. package/dist/es2020/modules/error-handler/error-handler.controller.js.map +0 -1
  182. package/dist/es2020/modules/error-handler/utils/app-error.js +0 -15
  183. package/dist/es2020/modules/error-handler/utils/app-error.js.map +0 -1
  184. package/dist/es2020/modules/error-handler/utils/catch-async.js +0 -10
  185. package/dist/es2020/modules/error-handler/utils/catch-async.js.map +0 -1
  186. package/dist/es2020/modules/error-handler/utils/error-handler.helpers.js +0 -155
  187. package/dist/es2020/modules/error-handler/utils/error-handler.helpers.js.map +0 -1
  188. package/dist/es2020/modules/file-upload/file-upload.controller.js +0 -266
  189. package/dist/es2020/modules/file-upload/file-upload.controller.js.map +0 -1
  190. package/dist/es2020/modules/file-upload/file-upload.router.js +0 -50
  191. package/dist/es2020/modules/file-upload/file-upload.router.js.map +0 -1
  192. package/dist/es2020/modules/file-upload/file-upload.service.js +0 -314
  193. package/dist/es2020/modules/file-upload/file-upload.service.js.map +0 -1
  194. package/dist/es2020/modules/file-upload/utils/helpers/file-upload.helpers.js +0 -81
  195. package/dist/es2020/modules/file-upload/utils/helpers/file-upload.helpers.js.map +0 -1
  196. package/dist/es2020/modules/swagger/swagger.router.js +0 -135
  197. package/dist/es2020/modules/swagger/swagger.router.js.map +0 -1
  198. package/dist/es2020/paths.js +0 -1
  199. package/dist/es2020/paths.js.map +0 -1
  200. package/dist/es2020/server.js +0 -3
  201. package/dist/es2020/server.js.map +0 -1
  202. package/dist/es2020/types/arkos-config.js +0 -2
  203. package/dist/es2020/types/arkos-config.js.map +0 -1
  204. package/dist/es2020/types/auth.js +0 -2
  205. package/dist/es2020/types/auth.js.map +0 -1
  206. package/dist/es2020/types/index.js +0 -8
  207. package/dist/es2020/types/index.js.map +0 -1
  208. package/dist/es2020/types/router-config.js +0 -2
  209. package/dist/es2020/types/router-config.js.map +0 -1
  210. package/dist/es2020/utils/arkos-env.js +0 -7
  211. package/dist/es2020/utils/arkos-env.js.map +0 -1
  212. package/dist/es2020/utils/cli/build.js +0 -223
  213. package/dist/es2020/utils/cli/build.js.map +0 -1
  214. package/dist/es2020/utils/cli/dev.js +0 -261
  215. package/dist/es2020/utils/cli/dev.js.map +0 -1
  216. package/dist/es2020/utils/cli/generate.js +0 -183
  217. package/dist/es2020/utils/cli/generate.js.map +0 -1
  218. package/dist/es2020/utils/cli/index.js +0 -74
  219. package/dist/es2020/utils/cli/index.js.map +0 -1
  220. package/dist/es2020/utils/cli/start.js +0 -86
  221. package/dist/es2020/utils/cli/start.js.map +0 -1
  222. package/dist/es2020/utils/cli/utils/cli.helpers.js +0 -18
  223. package/dist/es2020/utils/cli/utils/cli.helpers.js.map +0 -1
  224. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +0 -33
  225. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +0 -1
  226. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -18
  227. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -1
  228. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-middlewares.js +0 -265
  229. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +0 -1
  230. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +0 -55
  231. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +0 -1
  232. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-router-template.js +0 -32
  233. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-router-template.js.map +0 -1
  234. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-service-template.js +0 -32
  235. package/dist/es2020/utils/cli/utils/template-generator/templates/generate-service-template.js.map +0 -1
  236. package/dist/es2020/utils/cli/utils/template-generators.js +0 -25
  237. package/dist/es2020/utils/cli/utils/template-generators.js.map +0 -1
  238. package/dist/es2020/utils/dotenv.helpers.js +0 -37
  239. package/dist/es2020/utils/dotenv.helpers.js.map +0 -1
  240. package/dist/es2020/utils/features/api.features.js +0 -154
  241. package/dist/es2020/utils/features/api.features.js.map +0 -1
  242. package/dist/es2020/utils/features/change-case.features.js +0 -31
  243. package/dist/es2020/utils/features/change-case.features.js.map +0 -1
  244. package/dist/es2020/utils/helpers/api.features.helpers.js +0 -103
  245. package/dist/es2020/utils/helpers/api.features.helpers.js.map +0 -1
  246. package/dist/es2020/utils/helpers/change-case.helpers.js +0 -161
  247. package/dist/es2020/utils/helpers/change-case.helpers.js.map +0 -1
  248. package/dist/es2020/utils/helpers/deepmerge.helper.js +0 -113
  249. package/dist/es2020/utils/helpers/deepmerge.helper.js.map +0 -1
  250. package/dist/es2020/utils/helpers/fs.helpers.js +0 -45
  251. package/dist/es2020/utils/helpers/fs.helpers.js.map +0 -1
  252. package/dist/es2020/utils/helpers/global.helpers.js +0 -4
  253. package/dist/es2020/utils/helpers/global.helpers.js.map +0 -1
  254. package/dist/es2020/utils/helpers/models.helpers.js +0 -276
  255. package/dist/es2020/utils/helpers/models.helpers.js.map +0 -1
  256. package/dist/es2020/utils/helpers/prisma.helpers.js +0 -41
  257. package/dist/es2020/utils/helpers/prisma.helpers.js.map +0 -1
  258. package/dist/es2020/utils/helpers/query-parser.helpers.js +0 -40
  259. package/dist/es2020/utils/helpers/query-parser.helpers.js.map +0 -1
  260. package/dist/es2020/utils/helpers/text.helpers.js +0 -22
  261. package/dist/es2020/utils/helpers/text.helpers.js.map +0 -1
  262. package/dist/es2020/utils/validate-dto.js +0 -11
  263. package/dist/es2020/utils/validate-dto.js.map +0 -1
  264. package/dist/es2020/utils/validate-schema.js +0 -9
  265. package/dist/es2020/utils/validate-schema.js.map +0 -1
@@ -4,23 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.setupRouters = setupRouters;
7
- const pluralize_1 = require("pluralize");
7
+ exports.isEndpointDisabled = isEndpointDisabled;
8
+ exports.isParentEndpointAllowed = isParentEndpointAllowed;
9
+ const pluralize_1 = __importDefault(require("pluralize"));
8
10
  const utils_1 = require("../../../../exports/utils");
9
11
  const models_helpers_1 = require("../../../../utils/helpers/models.helpers");
10
12
  const auth_service_1 = __importDefault(require("../../../auth/auth.service"));
11
13
  const base_controller_1 = require("../../base.controller");
12
14
  const base_middlewares_1 = require("../../base.middlewares");
13
- const catch_async_1 = __importDefault(require("../../../error-handler/utils/catch-async"));
15
+ const routers_helpers_1 = require("../../../../utils/helpers/routers.helpers");
14
16
  function setupRouters(models, router, arkosConfigs) {
15
17
  return models.map(async (model) => {
16
18
  const modelNameInKebab = (0, utils_1.kebabCase)(model);
17
- const modelModules = await (0, models_helpers_1.importPrismaModelModules)(modelNameInKebab);
19
+ const modelModules = await (0, models_helpers_1.importPrismaModelModules)(modelNameInKebab, arkosConfigs);
18
20
  const { middlewares, authConfigs, prismaQueryOptions, router: customRouterModule, dtos, schemas, } = modelModules;
19
- const routeName = (0, pluralize_1.plural)(modelNameInKebab);
21
+ const routeName = pluralize_1.default.plural(modelNameInKebab);
20
22
  const controller = new base_controller_1.BaseController(model);
21
- const routerConfig = customRouterModule?.config;
22
- const disableConfig = routerConfig?.disable || {};
23
- const isCompletelyDisabled = disableConfig === true;
23
+ const routerConfig = customRouterModule?.config || {};
24
24
  const customRouter = customRouterModule || {};
25
25
  const hasCustomImplementation = (path, method) => {
26
26
  return customRouter.stack?.some((layer) => (layer.path === `/api/${path}` ||
@@ -29,11 +29,6 @@ function setupRouters(models, router, arkosConfigs) {
29
29
  layer.path === `/api/${path}/`) &&
30
30
  layer.method.toLowerCase() === method.toLowerCase());
31
31
  };
32
- const isEndpointDisabled = (endpoint) => {
33
- if (isCompletelyDisabled)
34
- return true;
35
- return typeof disableConfig === "object" && !!disableConfig[endpoint];
36
- };
37
32
  const getValidationSchemaOrDto = (key) => {
38
33
  const validationConfigs = arkosConfigs?.validation;
39
34
  if (validationConfigs?.resolver === "class-validator") {
@@ -44,124 +39,59 @@ function setupRouters(models, router, arkosConfigs) {
44
39
  }
45
40
  return undefined;
46
41
  };
47
- if (customRouterModule?.default && !customRouterModule?.config?.disable)
42
+ if (customRouterModule?.default && !routerConfig?.disable)
48
43
  router.use(`/${routeName}`, customRouterModule.default);
49
- function safeCatchAsync(middleware) {
50
- return middleware ? (0, catch_async_1.default)(middleware) : undefined;
51
- }
52
- if (!isEndpointDisabled("createOne") &&
44
+ if (!isEndpointDisabled(routerConfig, "createOne") &&
53
45
  !hasCustomImplementation(`/${routeName}`, "post")) {
54
- router.post(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...[
55
- safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,
56
- safeCatchAsync(middlewares?.beforeCreateOne)
57
- ? controller.createOne
58
- : safeCatchAsync(middlewares?.afterCreateOne) || base_middlewares_1.sendResponse,
59
- safeCatchAsync(middlewares?.beforeCreateOne) &&
60
- safeCatchAsync(middlewares?.afterCreateOne)
61
- ? safeCatchAsync(middlewares?.afterCreateOne)
62
- : base_middlewares_1.sendResponse,
63
- ].filter((m) => !!m), base_middlewares_1.sendResponse);
46
+ router.post(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("create")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeCreateOne), controller.createOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterCreateOne), base_middlewares_1.sendResponse);
64
47
  }
65
- if (!isEndpointDisabled("findMany") &&
48
+ if (!isEndpointDisabled(routerConfig, "findMany") &&
66
49
  !hasCustomImplementation(`/${routeName}`, "get")) {
67
- router.get(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...[
68
- safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,
69
- safeCatchAsync(middlewares?.beforeFindMany)
70
- ? controller.findMany
71
- : safeCatchAsync(middlewares?.afterFindMany) || base_middlewares_1.sendResponse,
72
- safeCatchAsync(middlewares?.beforeFindMany) &&
73
- safeCatchAsync(middlewares?.afterFindMany)
74
- ? safeCatchAsync(middlewares?.afterFindMany)
75
- : base_middlewares_1.sendResponse,
76
- base_middlewares_1.sendResponse,
77
- ].filter((m) => !!m));
50
+ router.get(`/${routeName}`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeFindMany), controller.findMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterFindMany), base_middlewares_1.sendResponse);
78
51
  }
79
- if (!isEndpointDisabled("createMany") &&
52
+ if (!isEndpointDisabled(routerConfig, "createMany") &&
80
53
  !hasCustomImplementation(`/${routeName}/many`, "post")) {
81
- router.post(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...[
82
- safeCatchAsync(middlewares?.beforeCreateMany) ||
83
- controller.createMany,
84
- safeCatchAsync(middlewares?.beforeCreateMany)
85
- ? controller.createMany
86
- : safeCatchAsync(middlewares?.afterCreateMany) || base_middlewares_1.sendResponse,
87
- safeCatchAsync(middlewares?.beforeCreateMany) &&
88
- safeCatchAsync(middlewares?.afterCreateMany)
89
- ? safeCatchAsync(middlewares?.afterCreateMany)
90
- : base_middlewares_1.sendResponse,
91
- base_middlewares_1.sendResponse,
92
- ].filter((m) => !!m));
54
+ router.post(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Create", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("createMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "createMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeCreateMany), controller.createMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterCreateMany), base_middlewares_1.sendResponse);
93
55
  }
94
- if (!isEndpointDisabled("updateMany") &&
56
+ if (!isEndpointDisabled(routerConfig, "updateMany") &&
95
57
  !hasCustomImplementation(`/${routeName}/many`, "patch")) {
96
- router.patch(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...[
97
- safeCatchAsync(middlewares?.beforeUpdateMany) ||
98
- controller.updateMany,
99
- safeCatchAsync(middlewares?.beforeUpdateMany)
100
- ? controller.updateMany
101
- : safeCatchAsync(middlewares?.afterUpdateMany) || base_middlewares_1.sendResponse,
102
- safeCatchAsync(middlewares?.beforeUpdateMany) &&
103
- safeCatchAsync(middlewares?.afterUpdateMany)
104
- ? safeCatchAsync(middlewares?.afterUpdateMany)
105
- : base_middlewares_1.sendResponse,
106
- base_middlewares_1.sendResponse,
107
- ].filter((m) => !!m));
58
+ router.patch(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("updateMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateMany), controller.updateMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateMany), base_middlewares_1.sendResponse);
108
59
  }
109
- if (!isEndpointDisabled("deleteMany") &&
60
+ if (!isEndpointDisabled(routerConfig, "deleteMany") &&
110
61
  !hasCustomImplementation(`/${routeName}/many`, "delete")) {
111
- router.delete(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("deleteMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...[
112
- safeCatchAsync(middlewares?.beforeDeleteMany) ||
113
- controller.deleteMany,
114
- safeCatchAsync(middlewares?.beforeDeleteMany)
115
- ? controller.deleteMany
116
- : safeCatchAsync(middlewares?.afterDeleteMany) || base_middlewares_1.sendResponse,
117
- safeCatchAsync(middlewares?.beforeDeleteMany) &&
118
- safeCatchAsync(middlewares?.afterDeleteMany)
119
- ? safeCatchAsync(middlewares?.afterDeleteMany)
120
- : base_middlewares_1.sendResponse,
121
- base_middlewares_1.sendResponse,
122
- ].filter((middleware) => !!middleware));
62
+ router.delete(`/${routeName}/many`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("deleteMany")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteMany"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteMany), controller.deleteMany, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteMany), base_middlewares_1.sendResponse);
123
63
  }
124
- if (!isEndpointDisabled("findOne") &&
64
+ if (!isEndpointDisabled(routerConfig, "findOne") &&
125
65
  !hasCustomImplementation(`/${routeName}/:id`, "get")) {
126
- router.get(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("findOne")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...[
127
- safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,
128
- safeCatchAsync(middlewares?.beforeFindOne)
129
- ? controller.findOne
130
- : safeCatchAsync(middlewares?.afterFindOne) || base_middlewares_1.sendResponse,
131
- safeCatchAsync(middlewares?.beforeFindOne) &&
132
- safeCatchAsync(middlewares?.afterFindOne)
133
- ? safeCatchAsync(middlewares?.afterFindOne)
134
- : base_middlewares_1.sendResponse,
135
- base_middlewares_1.sendResponse,
136
- ].filter((m) => !!m));
66
+ router.get(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("View", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("View", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("findOne")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "findOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeFindOne), controller.findOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterFindOne), base_middlewares_1.sendResponse);
137
67
  }
138
- if (!isEndpointDisabled("updateOne") &&
68
+ if (!isEndpointDisabled(routerConfig, "updateOne") &&
139
69
  !hasCustomImplementation(`/${routeName}/:id`, "patch")) {
140
- router.patch(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...[
141
- safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,
142
- safeCatchAsync(middlewares?.beforeUpdateOne)
143
- ? controller.updateOne
144
- : safeCatchAsync(middlewares?.afterUpdateOne) || base_middlewares_1.sendResponse,
145
- safeCatchAsync(middlewares?.beforeUpdateOne) &&
146
- safeCatchAsync(middlewares?.afterUpdateOne)
147
- ? safeCatchAsync(middlewares?.afterUpdateOne)
148
- : base_middlewares_1.sendResponse,
149
- ].filter((m) => !!m), base_middlewares_1.sendResponse);
70
+ router.patch(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Update", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("update")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "updateOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateOne), controller.updateOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateOne), base_middlewares_1.sendResponse);
150
71
  }
151
- if (!isEndpointDisabled("deleteOne") &&
72
+ if (!isEndpointDisabled(routerConfig, "deleteOne") &&
152
73
  !hasCustomImplementation(`/${routeName}/:id`, "delete")) {
153
- router.delete(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)((0, pluralize_1.singular)(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("delete")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...[
154
- safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,
155
- safeCatchAsync(middlewares?.beforeDeleteOne)
156
- ? controller.deleteOne
157
- : safeCatchAsync(middlewares?.afterDeleteOne) || base_middlewares_1.sendResponse,
158
- safeCatchAsync(middlewares?.beforeDeleteOne) &&
159
- safeCatchAsync(middlewares?.afterDeleteOne)
160
- ? safeCatchAsync(middlewares?.afterDeleteOne)
161
- : base_middlewares_1.sendResponse,
162
- base_middlewares_1.sendResponse,
163
- ].filter((m) => !!m));
74
+ router.delete(`/${routeName}/:id`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs?.authenticationControl), auth_service_1.default.handleAccessControl("Delete", (0, utils_1.kebabCase)(pluralize_1.default.singular(modelNameInKebab)), authConfigs?.accessControl || {}), (0, base_middlewares_1.handleRequestBodyValidationAndTransformation)(getValidationSchemaOrDto("delete")), (0, base_middlewares_1.addPrismaQueryOptionsToRequest)(prismaQueryOptions, "deleteOne"), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteOne), controller.deleteOne, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteOne), base_middlewares_1.sendResponse);
164
75
  }
165
76
  });
166
77
  }
78
+ function isEndpointDisabled(routerConfig, endpoint) {
79
+ if (!routerConfig?.disable)
80
+ return false;
81
+ if (routerConfig.disable === true)
82
+ return true;
83
+ if (typeof routerConfig.disable === "object")
84
+ return routerConfig.disable[endpoint] === true;
85
+ return false;
86
+ }
87
+ function isParentEndpointAllowed(routerConfig, endpoint) {
88
+ if (!routerConfig?.parent)
89
+ return false;
90
+ const parentEndpoints = routerConfig.parent.endpoints;
91
+ if (parentEndpoints === "*")
92
+ return true;
93
+ if (Array.isArray(parentEndpoints))
94
+ return parentEndpoints.includes(endpoint);
95
+ return true;
96
+ }
167
97
  //# sourceMappingURL=base.router.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AAgBA,oCAyWC;AAxXD,yCAA6C;AAE7C,qDAAsD;AAGtD,6EAAoF;AACpF,8EAAqD;AACrD,2DAAuD;AACvD,6DAIgC;AAChC,2FAAkE;AAElE,SAAgB,YAAY,CAC1B,MAAgB,EAChB,MAAc,EACd,YAAyB;IAEz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AAE,cAAc,CAAC;oBACzC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC;oBAC7C,CAAC,CAAC,+BAAY;gBAChB,+BAAY;aACb,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { singular, plural } from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport catchAsync from \"../../../error-handler/utils/catch-async\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(modelNameInKebab);\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n // Check for router customization/disabling\n const routerConfig: RouterConfig = customRouterModule?.config;\n const disableConfig = routerConfig?.disable || {};\n const isCompletelyDisabled = disableConfig === true;\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to determine if an endpoint should be disabled\n const isEndpointDisabled = (endpoint: RouterEndpoint): boolean => {\n if (isCompletelyDisabled) return true;\n return typeof disableConfig === \"object\" && !!disableConfig[endpoint];\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (\n key: keyof typeof dtos | keyof typeof schemas\n ) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !customRouterModule?.config?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n function safeCatchAsync(middleware: any) {\n return middleware ? catchAsync(middleware) : undefined;\n }\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(\"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateOne) || controller.createOne,\n safeCatchAsync(middlewares?.beforeCreateOne)\n ? controller.createOne\n : safeCatchAsync(middlewares?.afterCreateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateOne) &&\n safeCatchAsync(middlewares?.afterCreateOne)\n ? safeCatchAsync(middlewares?.afterCreateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(\"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindMany) || controller.findMany,\n safeCatchAsync(middlewares?.beforeFindMany)\n ? controller.findMany\n : safeCatchAsync(middlewares?.afterFindMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindMany) &&\n safeCatchAsync(middlewares?.afterFindMany)\n ? safeCatchAsync(middlewares?.afterFindMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(\"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeCreateMany) ||\n controller.createMany,\n safeCatchAsync(middlewares?.beforeCreateMany)\n ? controller.createMany\n : safeCatchAsync(middlewares?.afterCreateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeCreateMany) &&\n safeCatchAsync(middlewares?.afterCreateMany)\n ? safeCatchAsync(middlewares?.afterCreateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(\"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateMany) ||\n controller.updateMany,\n safeCatchAsync(middlewares?.beforeUpdateMany)\n ? controller.updateMany\n : safeCatchAsync(middlewares?.afterUpdateMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateMany) &&\n safeCatchAsync(middlewares?.afterUpdateMany)\n ? safeCatchAsync(middlewares?.afterUpdateMany)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(\"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteMany) ||\n controller.deleteMany,\n safeCatchAsync(middlewares?.beforeDeleteMany)\n ? controller.deleteMany\n : safeCatchAsync(middlewares?.afterDeleteMany) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteMany) &&\n safeCatchAsync(middlewares?.afterDeleteMany)\n ? safeCatchAsync(middlewares?.afterDeleteMany)\n : sendResponse,\n sendResponse,\n ].filter((middleware) => !!middleware)\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(\"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeFindOne) || controller.findOne,\n safeCatchAsync(middlewares?.beforeFindOne)\n ? controller.findOne\n : safeCatchAsync(middlewares?.afterFindOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeFindOne) &&\n safeCatchAsync(middlewares?.afterFindOne)\n ? safeCatchAsync(middlewares?.afterFindOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(\"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeUpdateOne) || controller.updateOne,\n safeCatchAsync(middlewares?.beforeUpdateOne)\n ? controller.updateOne\n : safeCatchAsync(middlewares?.afterUpdateOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeUpdateOne) &&\n safeCatchAsync(middlewares?.afterUpdateOne)\n ? safeCatchAsync(middlewares?.afterUpdateOne)\n : sendResponse,\n ].filter((m) => !!m),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(\"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...[\n safeCatchAsync(middlewares?.beforeDeleteOne) || controller.deleteOne,\n safeCatchAsync(middlewares?.beforeDeleteOne)\n ? controller.deleteOne\n : safeCatchAsync(middlewares?.afterDeleteOne) || sendResponse,\n safeCatchAsync(middlewares?.beforeDeleteOne) &&\n safeCatchAsync(middlewares?.afterDeleteOne)\n ? safeCatchAsync(middlewares?.afterDeleteOne)\n : sendResponse,\n sendResponse,\n ].filter((m) => !!m)\n );\n }\n });\n}\n"]}
1
+ {"version":3,"file":"base.router.helpers.js","sourceRoot":"","sources":["../../../../../../src/modules/base/utils/helpers/base.router.helpers.ts"],"names":[],"mappings":";;;;;AAgBA,oCAkSC;AAED,gDAYC;AAED,0DAWC;AA5UD,0DAAkC;AAElC,qDAAsD;AAGtD,6EAAoF;AACpF,8EAAqD;AACrD,2DAAuD;AACvD,6DAIgC;AAChC,+EAA8E;AAE9E,SAAgB,YAAY,CAC1B,MAAgB,EAChB,MAAc,EACd,YAAyB;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChC,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,CAAC;QAC1C,MAAM,YAAY,GAAG,MAAM,IAAA,yCAAwB,EACjD,gBAAgB,EAChB,YAAY,CACb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AE,OAAO,IAAI,CAAC;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;QAAE,OAAO,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9E,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Router } from \"express\";\nimport pluralize from \"pluralize\";\nimport { ArkosConfig, RouterConfig } from \"../../../../exports\";\nimport { kebabCase } from \"../../../../exports/utils\";\nimport { PrismaQueryOptions } from \"../../../../types\";\nimport { RouterEndpoint } from \"../../../../types/router-config\";\nimport { importPrismaModelModules } from \"../../../../utils/helpers/models.helpers\";\nimport authService from \"../../../auth/auth.service\";\nimport { BaseController } from \"../../base.controller\";\nimport {\n addPrismaQueryOptionsToRequest,\n handleRequestBodyValidationAndTransformation,\n sendResponse,\n} from \"../../base.middlewares\";\nimport { processMiddleware } from \"../../../../utils/helpers/routers.helpers\";\n\nexport function setupRouters(\n models: string[],\n router: Router,\n arkosConfigs: ArkosConfig\n) {\n return models.map(async (model) => {\n const modelNameInKebab = kebabCase(model);\n const modelModules = await importPrismaModelModules(\n modelNameInKebab,\n arkosConfigs\n );\n const {\n middlewares,\n authConfigs,\n prismaQueryOptions,\n router: customRouterModule,\n dtos,\n schemas,\n } = modelModules;\n\n const routeName = pluralize.plural(modelNameInKebab);\n const controller = new BaseController(model);\n\n const routerConfig: RouterConfig = customRouterModule?.config || {};\n\n // Check if custom implementation exists\n const customRouter = (customRouterModule as Router) || {};\n const hasCustomImplementation = (path: string, method: string) => {\n return customRouter.stack?.some(\n (layer) =>\n (layer.path === `/api/${path}` ||\n layer.path === `api/${path}` ||\n layer.path === `api/${path}/` ||\n layer.path === `/api/${path}/`) &&\n layer.method.toLowerCase() === method.toLowerCase()\n );\n };\n\n // Helper to get the correct schema or DTO based on Arkos Config\n const getValidationSchemaOrDto = (key: string) => {\n const validationConfigs = arkosConfigs?.validation;\n if (validationConfigs?.resolver === \"class-validator\") {\n return dtos?.[key];\n } else if (validationConfigs?.resolver === \"zod\") {\n return schemas?.[key];\n }\n return undefined;\n };\n\n // If the custom router has its own routes, add them\n if (customRouterModule?.default && !routerConfig?.disable)\n router.use(`/${routeName}`, customRouterModule.default);\n\n // POST /{routeName} - Create One\n if (\n !isEndpointDisabled(routerConfig, \"createOne\") &&\n !hasCustomImplementation(`/${routeName}`, \"post\")\n ) {\n router.post(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"create\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createOne\"\n ),\n ...processMiddleware(middlewares?.beforeCreateOne),\n controller.createOne,\n ...processMiddleware(middlewares?.afterCreateOne),\n sendResponse\n );\n }\n\n // GET /{routeName} - Find Many\n if (\n !isEndpointDisabled(routerConfig, \"findMany\") &&\n !hasCustomImplementation(`/${routeName}`, \"get\")\n ) {\n router.get(\n `/${routeName}`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findMany\"\n ),\n ...processMiddleware(middlewares?.beforeFindMany),\n controller.findMany,\n ...processMiddleware(middlewares?.afterFindMany),\n sendResponse\n );\n }\n\n // POST /{routeName}/many - Create Many\n if (\n !isEndpointDisabled(routerConfig, \"createMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"post\")\n ) {\n router.post(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"createMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"createMany\"\n ),\n ...processMiddleware(middlewares?.beforeCreateMany),\n controller.createMany,\n ...processMiddleware(middlewares?.afterCreateMany),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/many - Update Many\n if (\n !isEndpointDisabled(routerConfig, \"updateMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"updateMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateMany\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateMany),\n controller.updateMany,\n ...processMiddleware(middlewares?.afterUpdateMany),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/many - Delete Many\n if (\n !isEndpointDisabled(routerConfig, \"deleteMany\") &&\n !hasCustomImplementation(`/${routeName}/many`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/many`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"deleteMany\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteMany\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteMany),\n controller.deleteMany,\n ...processMiddleware(middlewares?.afterDeleteMany),\n sendResponse\n );\n }\n\n // GET /{routeName}/:id - Find One\n if (\n !isEndpointDisabled(routerConfig, \"findOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"get\")\n ) {\n router.get(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"findOne\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"findOne\"\n ),\n ...processMiddleware(middlewares?.beforeFindOne),\n controller.findOne,\n ...processMiddleware(middlewares?.afterFindOne),\n sendResponse\n );\n }\n\n // PATCH /{routeName}/:id - Update One\n if (\n !isEndpointDisabled(routerConfig, \"updateOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"patch\")\n ) {\n router.patch(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"update\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"updateOne\"\n ),\n ...processMiddleware(middlewares?.beforeUpdateOne),\n controller.updateOne,\n ...processMiddleware(middlewares?.afterUpdateOne),\n sendResponse\n );\n }\n\n // DELETE /{routeName}/:id - Delete One\n if (\n !isEndpointDisabled(routerConfig, \"deleteOne\") &&\n !hasCustomImplementation(`/${routeName}/:id`, \"delete\")\n ) {\n router.delete(\n `/${routeName}/:id`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs?.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n kebabCase(pluralize.singular(modelNameInKebab)),\n authConfigs?.accessControl || {}\n ),\n handleRequestBodyValidationAndTransformation(\n getValidationSchemaOrDto(\"delete\")\n ),\n addPrismaQueryOptionsToRequest<any>(\n prismaQueryOptions as PrismaQueryOptions<any>,\n \"deleteOne\"\n ),\n ...processMiddleware(middlewares?.beforeDeleteOne),\n controller.deleteOne,\n ...processMiddleware(middlewares?.afterDeleteOne),\n sendResponse\n );\n }\n });\n}\n\nexport function isEndpointDisabled(\n routerConfig: RouterConfig,\n endpoint: RouterEndpoint\n): boolean {\n if (!routerConfig?.disable) return false;\n\n if (routerConfig.disable === true) return true;\n\n if (typeof routerConfig.disable === \"object\")\n return routerConfig.disable[endpoint] === true;\n\n return false;\n}\n\nexport function isParentEndpointAllowed(\n routerConfig: any,\n endpoint: string\n): boolean {\n if (!routerConfig?.parent) return false;\n\n const parentEndpoints = routerConfig.parent.endpoints;\n if (parentEndpoints === \"*\") return true;\n if (Array.isArray(parentEndpoints)) return parentEndpoints.includes(endpoint);\n\n return true; // Default to allow if not specified\n}\n"]}
@@ -73,6 +73,8 @@ function errorHandler(err, req, res, next) {
73
73
  error = errorControllerHelper.handleForeignKeyConstraintError(err);
74
74
  if (err.code === "P2004")
75
75
  error = errorControllerHelper.handleConstraintFailedError(err);
76
+ if (err.code === "P2025")
77
+ error = errorControllerHelper.handleNonExistingRecord(err);
76
78
  if (err.code === "P3000")
77
79
  error = errorControllerHelper.handleSchemaCreationFailedError(err);
78
80
  if (err.code === "P3001")
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAyEC;AA5FD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,G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AAG,CAAC,OAAO;SACrB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,yBAAyB;KACnC,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,eAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
1
+ {"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAkEC;AArFD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD,IAAI,KAAK,GAAG,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IAG7C,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;IACjD,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IAGnD,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B;QAC5C,KAAK,GAAG,qBAAqB,CAAC,iCAAiC,CAAC,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;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P2025\")\n error = errorControllerHelper.handleNonExistingRecord(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n if (!error.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n process.exit();\n });\n }\n});\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const catchAsync = (fn) => async (req, res, next) => {
4
4
  try {
5
- return await fn(req, res, next);
5
+ return (await fn(req, res, next));
6
6
  }
7
7
  catch (err) {
8
8
  next(err);
@@ -1 +1 @@
1
- {"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":";;AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EAAE,GAAiB,EAAE,GAAkB,EAAE,IAAuB,EAAE,EAAE;IACvE,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEJ,kBAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../../types\";\n\n/**\n * Used to wrap request handlers and middleware for automatic catch async errors and throw to next to invoke the global error handler\n *\n * @param {ArkosRequestHandler} fn - an express request handler or middleware that will be called with req, res, next, with catch attached for error handling\n * @returns\n *\n * @example\n * ```typescript\n * import { ArkosRequest, ArkosResponse, ArkosNextFunction } from 'arkos'\n *\n * export const getManyPosts = catchAsync(async\n * (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n * const posts = await getSomePosts()\n * res.status(200).json({ data: posts })\n * })\n * ```\n */\nconst catchAsync =\n (fn: ArkosRequestHandler) =>\n async (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n try {\n return await fn(req, res, next);\n } catch (err) {\n next(err);\n }\n };\n\nexport default catchAsync;\n"]}
1
+ {"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":";;AAwBA,MAAM,UAAU,GACd,CAAC,EAAuB,EAAE,EAAE,CAC5B,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;IACjB,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAIJ,kBAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n} from \"../../../types\";\n\n/**\n * Used to wrap request handlers and middleware for automatic catch async errors and throw to next to invoke the global error handler\n *\n * @param {ArkosRequestHandler} fn - an express request handler or middleware that will be called with req, res, next, with catch attached for error handling\n * @returns\n *\n * @example\n * ```typescript\n * import { ArkosRequest, ArkosResponse, ArkosNextFunction } from 'arkos'\n *\n * export const getManyPosts = catchAsync(async\n * (req: ArkosRequest, res: ArkosResponse, next: ArkosNextFunction) => {\n * const posts = await getSomePosts()\n * res.status(200).json({ data: posts })\n * })\n * ```\n */\nconst catchAsync =\n (fn: ArkosRequestHandler) =>\n async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await fn(req, res, next)) as void;\n } catch (err) {\n next(err);\n }\n };\n\nexport type CatchAsyncReturnType = ReturnType<typeof catchAsync>;\n\nexport default catchAsync;\n"]}
@@ -38,6 +38,7 @@ exports.handleNetworkError = handleNetworkError;
38
38
  exports.handleUnhandledPromiseError = handleUnhandledPromiseError;
39
39
  exports.handleDataTypeError = handleDataTypeError;
40
40
  exports.handleEmptyResultError = handleEmptyResultError;
41
+ exports.handleNonExistingRecord = handleNonExistingRecord;
41
42
  const app_error_1 = __importDefault(require("./app-error"));
42
43
  function handleJWTError() {
43
44
  return new app_error_1.default("Invalid token. Please log in again!", 401);
@@ -192,4 +193,9 @@ function handleEmptyResultError(err) {
192
193
  const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;
193
194
  return new app_error_1.default(message, 404);
194
195
  }
196
+ function handleNonExistingRecord(err) {
197
+ const message = err?.meta?.cause ||
198
+ `Operation could not be completed as the required record was not found`;
199
+ return new app_error_1.default(message, 404, err.meta || {}, "PrismaRecordNotFound");
200
+ }
195
201
  //# sourceMappingURL=error-handler.helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":";;;;;AASA,wCAEC;AAED,4CAEC;AAED,8EAGC;AAED,8DAIC;AAED,sEAIC;AAED,oEAIC;AAED,kEAGC;AA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AAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,iGAAiG,CAAC;IAClH,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,mBAAmB,CAAC,GAAa;IAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
1
+ {"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":";;;;;AASA,wCAEC;AAED,4CAEC;AAED,8EAGC;AAED,8DAIC;AAED,sEAIC;AAED,oEAIC;AAED,kEAGC;AAED,wEAIC;AAED,sEAGC;AAED,8DAIC;AAED,kEAIC;AAED,0EAIC;AAED,kEAIC;AAED,oEAIC;AAED,0EAIC;AAED,8DAIC;AAED,0DAIC;AAED,sEAIC;AAED,oEAIC;AAED,gFAIC;AAED,0EAIC;AAED,gFAIC;AAED,4EAIC;AAED,gEAGC;AAED,oEAIC;AAED,wDAGC;AAED,0DAGC;AAED,sDAGC;AAED,0DAGC;AAED,gEAIC;AAED,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,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,uBAAuB,CAAC,GAGvC;IACC,MAAM,OAAO,GACX,GAAG,EAAE,IAAI,EAAE,KAAK;QAChB,uEAAuE,CAAC;IAC1E,OAAO,IAAI,mBAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,sBAAsB,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n\nexport function handleNonExistingRecord(err: {\n meta?: Record<string, any>;\n [x: string]: any;\n}) {\n const message =\n err?.meta?.cause ||\n `Operation could not be completed as the required record was not found`;\n return new AppError(message, 404, err.meta || {}, \"PrismaRecordNotFound\");\n}\n"]}
@@ -12,9 +12,12 @@ const path_1 = __importDefault(require("path"));
12
12
  const express_2 = __importDefault(require("express"));
13
13
  const deepmerge_helper_1 = __importDefault(require("../../utils/helpers/deepmerge.helper"));
14
14
  const base_middlewares_1 = require("../base/base.middlewares");
15
+ const routers_helpers_1 = require("../../utils/helpers/routers.helpers");
16
+ const file_upload_helpers_1 = require("./utils/helpers/file-upload.helpers");
15
17
  const router = (0, express_1.Router)();
16
- async function getFileUploadRouter({ fileUpload }) {
17
- const modelModules = await (0, models_helpers_1.importPrismaModelModules)("file-upload");
18
+ async function getFileUploadRouter(arkosConfig) {
19
+ const { fileUpload } = arkosConfig;
20
+ const modelModules = await (0, models_helpers_1.importPrismaModelModules)("file-upload", arkosConfig);
18
21
  let { middlewares = {}, authConfigs = {} } = {};
19
22
  if (modelModules) {
20
23
  ({ middlewares = {}, authConfigs = {} } = modelModules);
@@ -24,10 +27,7 @@ async function getFileUploadRouter({ fileUpload }) {
24
27
  basePathname = "/" + basePathname;
25
28
  if (!basePathname.endsWith("/"))
26
29
  basePathname = basePathname + "/";
27
- router.get(`${basePathname}*`, auth_service_1.default.handleAuthenticationControl("View", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(middlewares?.beforeFindFile ? [middlewares?.beforeFindFile] : []), (req, res, next) => {
28
- req.url = req.url.replace(basePathname, "/");
29
- next();
30
- }, express_2.default.static(path_1.default.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), (0, deepmerge_helper_1.default)({
30
+ router.get(`${basePathname}*`, auth_service_1.default.handleAuthenticationControl("View", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("View", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeFindFile), file_upload_helpers_1.adjustRequestUrl, express_2.default.static(path_1.default.resolve(process.cwd(), fileUpload?.baseUploadDir || "uploads"), (0, deepmerge_helper_1.default)({
31
31
  maxAge: "1y",
32
32
  etag: true,
33
33
  lastModified: true,
@@ -36,21 +36,9 @@ async function getFileUploadRouter({ fileUpload }) {
36
36
  index: false,
37
37
  cacheControl: true,
38
38
  }, fileUpload?.expressStaticOptions || {})));
39
- router.post(`${basePathname}:fileType`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Create", "file-upload", authConfigs.accessControl), middlewares?.beforeUploadFile || file_upload_controller_1.default.uploadFile, middlewares?.beforeUploadFile
40
- ? file_upload_controller_1.default.uploadFile
41
- : middlewares?.afterUploadFile || base_middlewares_1.sendResponse, middlewares?.beforeUploadFile && middlewares?.afterUploadFile
42
- ? middlewares?.afterUploadFile
43
- : base_middlewares_1.sendResponse, base_middlewares_1.sendResponse);
44
- router.patch(`${basePathname}:fileType/:fileName`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Update", "file-upload", authConfigs.accessControl), middlewares?.beforeUpdateFile || file_upload_controller_1.default.updateFile, middlewares?.beforeUpdateFile
45
- ? file_upload_controller_1.default.updateFile
46
- : middlewares?.afterUpdateFile || base_middlewares_1.sendResponse, middlewares?.beforeUpdateFile && middlewares?.afterUpdateFile
47
- ? middlewares?.afterUpdateFile
48
- : base_middlewares_1.sendResponse, base_middlewares_1.sendResponse);
49
- router.delete(`${basePathname}:fileType/:fileName`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), middlewares?.beforeDeleteFile || file_upload_controller_1.default.deleteFile, middlewares?.beforeDeleteFile
50
- ? file_upload_controller_1.default.deleteFile
51
- : middlewares?.afterDeleteFile || base_middlewares_1.sendResponse, middlewares?.beforeDeleteFile && middlewares?.afterDeleteFile
52
- ? middlewares?.afterDeleteFile
53
- : base_middlewares_1.sendResponse, base_middlewares_1.sendResponse);
39
+ router.post(`${basePathname}:fileType`, auth_service_1.default.handleAuthenticationControl("Create", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Create", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUploadFile), file_upload_controller_1.default.uploadFile, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUploadFile), base_middlewares_1.sendResponse);
40
+ router.patch(`${basePathname}:fileType/:fileName`, auth_service_1.default.handleAuthenticationControl("Update", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Update", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeUpdateFile), file_upload_controller_1.default.updateFile, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterUpdateFile), base_middlewares_1.sendResponse);
41
+ router.delete(`${basePathname}:fileType/:fileName`, auth_service_1.default.handleAuthenticationControl("Delete", authConfigs.authenticationControl), auth_service_1.default.handleAccessControl("Delete", "file-upload", authConfigs.accessControl), ...(0, routers_helpers_1.processMiddleware)(middlewares?.beforeDeleteFile), file_upload_controller_1.default.deleteFile, ...(0, routers_helpers_1.processMiddleware)(middlewares?.afterDeleteFile), base_middlewares_1.sendResponse);
54
42
  return router;
55
43
  }
56
44
  //# sourceMappingURL=file-upload.router.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":";;;;;AAaA,kDAkHC;AA/HD,qCAAiC;AACjC,uEAA8E;AAC9E,wEAA+C;AAC/C,sFAA4D;AAE5D,gDAAwB;AACxB,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AAExD,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEzB,KAAK,UAAU,mBAAmB,CAAC,EAAE,UAAU,EAAe;IACnE,MAAM,YAAY,GAAG,MAAM,IAAA,yCAAwB,EAAC,aAAa,CAAC,CAAC;IACnE,IAAI,EAAE,WAAW,GAAG,EAAS,EAAE,WAAW,GAAG,EAAiB,EAAE,GAAG,EAAE,CAAC;IAEtE,IAAI,YAAY,EAAE,CAAC;QACjB,CAAC,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,YAAY,GAAG,UAAU,EAAE,SAAS,IAAI,eAAe,CAAC;IAE5D,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,YAAY,GAAG,GAAG,GAAG,YAAY,CAAC;IACrE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,YAAY,GAAG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sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\n\nconst router: Router = Router();\n\nexport async function getFileUploadRouter({ fileUpload }: ArkosConfig) {\n const modelModules = await importPrismaModelModules(\"file-upload\");\n let { middlewares = {} as any, authConfigs = {} as AuthConfigs } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Static file serving route\n router.get(\n `${basePathname}*`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...(middlewares?.beforeFindFile ? [middlewares?.beforeFindFile] : []),\n (req, res, next) => {\n req.url = req.url.replace(basePathname, \"/\");\n next();\n },\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n // POST /{basePathname}:fileType - Upload File\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeUploadFile || fileUploadController.uploadFile,\n middlewares?.beforeUploadFile\n ? fileUploadController.uploadFile\n : middlewares?.afterUploadFile || sendResponse,\n middlewares?.beforeUploadFile && middlewares?.afterUploadFile\n ? middlewares?.afterUploadFile\n : sendResponse,\n sendResponse\n );\n\n // PATCH /{basePathname}:fileType/:fileName - Update File\n router.patch(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeUpdateFile || fileUploadController.updateFile,\n middlewares?.beforeUpdateFile\n ? fileUploadController.updateFile\n : middlewares?.afterUpdateFile || sendResponse,\n middlewares?.beforeUpdateFile && middlewares?.afterUpdateFile\n ? middlewares?.afterUpdateFile\n : sendResponse,\n sendResponse\n );\n\n // DELETE /{basePathname}:fileType/:fileName - Delete File\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n middlewares?.beforeDeleteFile || fileUploadController.deleteFile,\n middlewares?.beforeDeleteFile\n ? fileUploadController.deleteFile\n : middlewares?.afterDeleteFile || sendResponse,\n middlewares?.beforeDeleteFile && middlewares?.afterDeleteFile\n ? middlewares?.afterDeleteFile\n : sendResponse,\n sendResponse\n );\n\n return router;\n}\n"]}
1
+ {"version":3,"file":"file-upload.router.js","sourceRoot":"","sources":["../../../../src/modules/file-upload/file-upload.router.ts"],"names":[],"mappings":";;;;;AAeA,kDAwGC;AAvHD,qCAAiC;AACjC,uEAA8E;AAC9E,wEAA+C;AAC/C,sFAA4D;AAE5D,gDAAwB;AACxB,sDAA8B;AAC9B,4FAA6D;AAE7D,+DAAwD;AACxD,yEAAwE;AACxE,6EAAuE;AAEvE,MAAM,MAAM,GAAW,IAAA,gBAAM,GAAE,CAAC;AAEzB,KAAK,UAAU,mBAAmB,CAAC,WAAwB;IAChE,MAAM,EAAE,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IAGF,MAAM,CAAC,IAAI,CACT,GAAG,YAAY,WAAW,EAC1B,sBAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,sBAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,gCAAoB,CAAC,UAAU,EAC/B,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,eAAe,CAAC,EAClD,+BAAY,CACb,CAAC;IAGF,MAAM,CAAC,KAAK,CACV,GAAG,YAAY,qBAAqB,EACpC,sBAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,sBAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,gCAAoB,CAAC,UAAU,EAC/B,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,eAAe,CAAC,EAClD,+BAAY,CACb,CAAC;IAGF,MAAM,CAAC,MAAM,CACX,GAAG,YAAY,qBAAqB,EACpC,sBAAW,CAAC,2BAA2B,CACrC,QAAQ,EACR,WAAW,CAAC,qBAAqB,CAClC,EACD,sBAAW,CAAC,mBAAmB,CAC7B,QAAQ,EACR,aAAa,EACb,WAAW,CAAC,aAAa,CAC1B,EACD,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,gBAAgB,CAAC,EACnD,gCAAoB,CAAC,UAAU,EAC/B,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,eAAe,CAAC,EAClD,+BAAY,CACb,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { Router } from \"express\";\nimport { importPrismaModelModules } from \"../../utils/helpers/models.helpers\";\nimport authService from \"../auth/auth.service\";\nimport fileUploadController from \"./file-upload.controller\";\nimport { ArkosConfig } from \"../../types/arkos-config\";\nimport path from \"path\";\nimport express from \"express\";\nimport deepmerge from \"../../utils/helpers/deepmerge.helper\";\nimport { AuthConfigs } from \"../../types/auth\";\nimport { sendResponse } from \"../base/base.middlewares\";\nimport { processMiddleware } from \"../../utils/helpers/routers.helpers\";\nimport { adjustRequestUrl } from \"./utils/helpers/file-upload.helpers\";\n\nconst router: Router = Router();\n\nexport async function getFileUploadRouter(arkosConfig: ArkosConfig) {\n const { fileUpload } = arkosConfig;\n\n const modelModules = await importPrismaModelModules(\n \"file-upload\",\n arkosConfig\n );\n let { middlewares = {} as any, authConfigs = {} as AuthConfigs } = {};\n\n if (modelModules) {\n ({ middlewares = {}, authConfigs = {} } = modelModules);\n }\n\n let basePathname = fileUpload?.baseRoute || \"/api/uploads/\";\n\n if (!basePathname.startsWith(\"/\")) basePathname = \"/\" + basePathname;\n if (!basePathname.endsWith(\"/\")) basePathname = basePathname + \"/\";\n\n // Static file serving route\n router.get(\n `${basePathname}*`,\n authService.handleAuthenticationControl(\n \"View\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"View\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeFindFile),\n adjustRequestUrl,\n express.static(\n path.resolve(process.cwd(), fileUpload?.baseUploadDir || \"uploads\"),\n deepmerge(\n {\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n },\n fileUpload?.expressStaticOptions || {}\n )\n )\n );\n\n // POST /{basePathname}:fileType - Upload File\n router.post(\n `${basePathname}:fileType`,\n authService.handleAuthenticationControl(\n \"Create\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Create\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUploadFile),\n fileUploadController.uploadFile,\n ...processMiddleware(middlewares?.afterUploadFile),\n sendResponse\n );\n\n // PATCH /{basePathname}:fileType/:fileName - Update File\n router.patch(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Update\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Update\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeUpdateFile),\n fileUploadController.updateFile,\n ...processMiddleware(middlewares?.afterUpdateFile),\n sendResponse\n );\n\n // DELETE /{basePathname}:fileType/:fileName - Delete File\n router.delete(\n `${basePathname}:fileType/:fileName`,\n authService.handleAuthenticationControl(\n \"Delete\",\n authConfigs.authenticationControl\n ),\n authService.handleAccessControl(\n \"Delete\",\n \"file-upload\",\n authConfigs.accessControl\n ),\n ...processMiddleware(middlewares?.beforeDeleteFile),\n fileUploadController.deleteFile,\n ...processMiddleware(middlewares?.afterDeleteFile),\n sendResponse\n );\n\n return router;\n}\n"]}