arkos 1.2.31-test → 1.3.0-beta

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 (397) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/app.js +1 -1
  3. package/dist/cjs/app.js.map +1 -1
  4. package/dist/cjs/exports/auth/index.js +1 -6
  5. package/dist/cjs/exports/controllers/index.js +1 -11
  6. package/dist/cjs/exports/error-handler/index.js +1 -11
  7. package/dist/cjs/exports/index.js +1 -12
  8. package/dist/cjs/exports/middlewares/index.js +1 -7
  9. package/dist/cjs/exports/prisma/index.js +1 -6
  10. package/dist/cjs/exports/prisma/index.js.map +1 -1
  11. package/dist/cjs/exports/services/index.js +1 -49
  12. package/dist/cjs/exports/services/index.js.map +1 -1
  13. package/dist/cjs/exports/utils/index.js +1 -44
  14. package/dist/cjs/exports/validation/index.js +1 -11
  15. package/dist/cjs/modules/auth/auth.controller.js +1 -194
  16. package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
  17. package/dist/cjs/modules/auth/auth.router.js +1 -50
  18. package/dist/cjs/modules/auth/auth.router.js.map +1 -1
  19. package/dist/cjs/modules/auth/auth.service.js +1 -185
  20. package/dist/cjs/modules/auth/auth.service.js.map +1 -1
  21. package/dist/cjs/modules/auth/utils/auth-error-objects.js +1 -0
  22. package/dist/cjs/modules/auth/utils/auth-error-objects.js.map +1 -0
  23. package/dist/cjs/modules/auth/utils/helpers/auth.controller.helpers.js +1 -83
  24. package/dist/cjs/modules/auth/utils/services/auth-action.service.js +1 -0
  25. package/dist/cjs/modules/auth/utils/services/auth-action.service.js.map +1 -0
  26. package/dist/cjs/modules/base/base.controller.js +1 -158
  27. package/dist/cjs/modules/base/base.controller.js.map +1 -1
  28. package/dist/cjs/modules/base/base.middlewares.js +1 -92
  29. package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
  30. package/dist/cjs/modules/base/base.router.js +1 -24
  31. package/dist/cjs/modules/base/base.router.js.map +1 -1
  32. package/dist/cjs/modules/base/base.service.js +1 -128
  33. package/dist/cjs/modules/base/base.service.js.map +1 -1
  34. package/dist/cjs/modules/base/types/base.service.types.js +1 -0
  35. package/dist/cjs/modules/base/types/base.service.types.js.map +1 -0
  36. package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js +1 -82
  37. package/dist/cjs/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
  38. package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js +1 -50
  39. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +1 -97
  40. package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  41. package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js +1 -171
  42. package/dist/cjs/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
  43. package/dist/cjs/modules/base/utils/router-validator.js +1 -0
  44. package/dist/cjs/modules/base/utils/router-validator.js.map +1 -0
  45. package/dist/cjs/modules/base/utils/service-hooks-manager.js +1 -0
  46. package/dist/cjs/modules/base/utils/service-hooks-manager.js.map +1 -0
  47. package/dist/cjs/modules/email/email.service.js +1 -104
  48. package/dist/cjs/modules/error-handler/error-handler.controller.js +4 -146
  49. package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
  50. package/dist/cjs/modules/error-handler/utils/app-error.js +1 -17
  51. package/dist/cjs/modules/error-handler/utils/app-error.js.map +1 -1
  52. package/dist/cjs/modules/error-handler/utils/catch-async.js +1 -12
  53. package/dist/cjs/modules/error-handler/utils/catch-async.js.map +1 -1
  54. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js +3 -201
  55. package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
  56. package/dist/cjs/modules/file-upload/file-upload.controller.js +1 -271
  57. package/dist/cjs/modules/file-upload/file-upload.controller.js.map +1 -1
  58. package/dist/cjs/modules/file-upload/file-upload.router.js +1 -44
  59. package/dist/cjs/modules/file-upload/file-upload.router.js.map +1 -1
  60. package/dist/cjs/modules/file-upload/file-upload.service.js +1 -322
  61. package/dist/cjs/modules/file-upload/file-upload.service.js.map +1 -1
  62. package/dist/cjs/modules/file-upload/utils/helpers/file-upload.helpers.js +1 -97
  63. package/dist/cjs/modules/swagger/swagger.router.js +1 -99
  64. package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
  65. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +1 -250
  66. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
  67. package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -0
  68. package/dist/cjs/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -0
  69. package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js +1 -66
  70. package/dist/cjs/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -1
  71. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +1 -41
  72. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
  73. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +1 -22
  74. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
  75. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +1 -0
  76. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +1 -0
  77. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -0
  78. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -0
  79. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +1 -0
  80. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -0
  81. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +1 -0
  82. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -0
  83. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +1 -0
  84. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
  85. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +1 -94
  86. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
  87. package/dist/cjs/package.json +3 -0
  88. package/dist/cjs/server.js +4 -2
  89. package/dist/cjs/server.js.map +1 -1
  90. package/dist/cjs/types/arkos-config.js +1 -3
  91. package/dist/cjs/types/arkos-config.js.map +1 -1
  92. package/dist/cjs/types/auth.js +1 -3
  93. package/dist/cjs/types/auth.js.map +1 -1
  94. package/dist/cjs/types/index.js +1 -11
  95. package/dist/cjs/types/index.js.map +1 -1
  96. package/dist/cjs/types/router-config.js +1 -3
  97. package/dist/cjs/types/router-config.js.map +1 -1
  98. package/dist/cjs/utils/arkos-env.js +1 -9
  99. package/dist/cjs/utils/cli/build.js +5 -212
  100. package/dist/cjs/utils/cli/build.js.map +1 -1
  101. package/dist/cjs/utils/cli/dev.js +3 -256
  102. package/dist/cjs/utils/cli/dev.js.map +1 -1
  103. package/dist/cjs/utils/cli/generate.js +1 -189
  104. package/dist/cjs/utils/cli/generate.js.map +1 -1
  105. package/dist/cjs/utils/cli/index.js +1 -81
  106. package/dist/cjs/utils/cli/index.js.map +1 -1
  107. package/dist/cjs/utils/cli/start.js +1 -93
  108. package/dist/cjs/utils/cli/start.js.map +1 -1
  109. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -24
  110. package/dist/cjs/utils/cli/utils/smart-fs-watcher.js +1 -0
  111. package/dist/cjs/utils/cli/utils/smart-fs-watcher.js.map +1 -0
  112. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +5 -20
  113. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js +9 -18
  114. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
  115. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js +144 -0
  116. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +1 -0
  117. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js +156 -135
  118. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
  119. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +9 -37
  120. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
  121. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js +11 -36
  122. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
  123. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +6 -32
  124. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
  125. package/dist/cjs/utils/cli/utils/template-generators.js +2 -28
  126. package/dist/cjs/utils/cli/utils/template-generators.js.map +1 -1
  127. package/dist/cjs/utils/cli/utils/watermark-stamper.js +3 -0
  128. package/dist/cjs/utils/cli/utils/watermark-stamper.js.map +1 -0
  129. package/dist/cjs/utils/dotenv.helpers.js +1 -43
  130. package/dist/cjs/utils/dynamic-loader.js +9 -0
  131. package/dist/cjs/utils/dynamic-loader.js.map +1 -0
  132. package/dist/cjs/utils/features/api.features.js +1 -167
  133. package/dist/cjs/utils/features/api.features.js.map +1 -1
  134. package/dist/cjs/utils/features/change-case.features.js +1 -67
  135. package/dist/cjs/utils/features/port-and-host-allocator.js +1 -0
  136. package/dist/cjs/utils/features/port-and-host-allocator.js.map +1 -0
  137. package/dist/cjs/utils/helpers/api.features.helpers.js +1 -106
  138. package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
  139. package/dist/cjs/utils/helpers/change-case.helpers.js +1 -177
  140. package/dist/cjs/utils/helpers/deepmerge.helper.js +1 -115
  141. package/dist/cjs/utils/helpers/dynamic-loader.helpers.js +1 -0
  142. package/dist/cjs/utils/helpers/dynamic-loader.helpers.js.map +1 -0
  143. package/dist/cjs/utils/helpers/fs.helpers.js +1 -61
  144. package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
  145. package/dist/cjs/utils/helpers/global.helpers.js +1 -92
  146. package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
  147. package/dist/cjs/utils/helpers/prisma.helpers.js +1 -52
  148. package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
  149. package/dist/cjs/utils/helpers/query-parser.helpers.js +1 -45
  150. package/dist/cjs/utils/helpers/routers.helpers.js +1 -21
  151. package/dist/cjs/utils/helpers/routers.helpers.js.map +1 -1
  152. package/dist/cjs/utils/helpers/text.helpers.js +1 -28
  153. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +1 -0
  154. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -0
  155. package/dist/cjs/utils/prisma/prisma-schema-parser.js +4 -0
  156. package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +1 -0
  157. package/dist/cjs/utils/prisma/types.js +1 -0
  158. package/dist/cjs/utils/prisma/types.js.map +1 -0
  159. package/dist/cjs/utils/sheu.js +1 -119
  160. package/dist/cjs/utils/sheu.js.map +1 -1
  161. package/dist/cjs/utils/validate-dto.js +1 -17
  162. package/dist/cjs/utils/validate-dto.js.map +1 -1
  163. package/dist/cjs/utils/validate-schema.js +1 -15
  164. package/dist/cjs/utils/validate-schema.js.map +1 -1
  165. package/dist/esm/app.js +1 -1
  166. package/dist/esm/app.js.map +1 -1
  167. package/dist/esm/exports/auth/index.js +1 -2
  168. package/dist/esm/exports/controllers/index.js +1 -4
  169. package/dist/esm/exports/error-handler/index.js +1 -4
  170. package/dist/esm/exports/index.js +1 -8
  171. package/dist/esm/exports/middlewares/index.js +1 -2
  172. package/dist/esm/exports/prisma/index.js +1 -3
  173. package/dist/esm/exports/prisma/index.js.map +1 -1
  174. package/dist/esm/exports/services/index.js +1 -9
  175. package/dist/esm/exports/services/index.js.map +1 -1
  176. package/dist/esm/exports/utils/index.js +1 -4
  177. package/dist/esm/exports/validation/index.js +1 -4
  178. package/dist/esm/modules/auth/auth.controller.js +1 -187
  179. package/dist/esm/modules/auth/auth.controller.js.map +1 -1
  180. package/dist/esm/modules/auth/auth.router.js +1 -44
  181. package/dist/esm/modules/auth/auth.router.js.map +1 -1
  182. package/dist/esm/modules/auth/auth.service.js +1 -178
  183. package/dist/esm/modules/auth/auth.service.js.map +1 -1
  184. package/dist/esm/modules/auth/utils/auth-error-objects.js +1 -0
  185. package/dist/esm/modules/auth/utils/auth-error-objects.js.map +1 -0
  186. package/dist/esm/modules/auth/utils/helpers/auth.controller.helpers.js +1 -73
  187. package/dist/esm/modules/auth/utils/services/auth-action.service.js +1 -0
  188. package/dist/esm/modules/auth/utils/services/auth-action.service.js.map +1 -0
  189. package/dist/esm/modules/base/base.controller.js +1 -150
  190. package/dist/esm/modules/base/base.controller.js.map +1 -1
  191. package/dist/esm/modules/base/base.middlewares.js +1 -81
  192. package/dist/esm/modules/base/base.middlewares.js.map +1 -1
  193. package/dist/esm/modules/base/base.router.js +1 -17
  194. package/dist/esm/modules/base/base.router.js.map +1 -1
  195. package/dist/esm/modules/base/base.service.js +1 -120
  196. package/dist/esm/modules/base/base.service.js.map +1 -1
  197. package/dist/esm/modules/base/types/base.service.types.js +1 -0
  198. package/dist/esm/modules/base/types/base.service.types.js.map +1 -0
  199. package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js +1 -77
  200. package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js.map +1 -1
  201. package/dist/esm/modules/base/utils/helpers/base.middlewares.helpers.js +1 -44
  202. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +1 -89
  203. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
  204. package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +1 -165
  205. package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +1 -1
  206. package/dist/esm/modules/base/utils/router-validator.js +1 -0
  207. package/dist/esm/modules/base/utils/router-validator.js.map +1 -0
  208. package/dist/esm/modules/base/utils/service-hooks-manager.js +1 -0
  209. package/dist/esm/modules/base/utils/service-hooks-manager.js.map +1 -0
  210. package/dist/esm/modules/email/email.service.js +1 -97
  211. package/dist/esm/modules/error-handler/error-handler.controller.js +4 -107
  212. package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
  213. package/dist/esm/modules/error-handler/utils/app-error.js +1 -15
  214. package/dist/esm/modules/error-handler/utils/app-error.js.map +1 -1
  215. package/dist/esm/modules/error-handler/utils/catch-async.js +1 -10
  216. package/dist/esm/modules/error-handler/utils/catch-async.js.map +1 -1
  217. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +3 -160
  218. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
  219. package/dist/esm/modules/file-upload/file-upload.controller.js +1 -266
  220. package/dist/esm/modules/file-upload/file-upload.controller.js.map +1 -1
  221. package/dist/esm/modules/file-upload/file-upload.router.js +1 -38
  222. package/dist/esm/modules/file-upload/file-upload.router.js.map +1 -1
  223. package/dist/esm/modules/file-upload/file-upload.service.js +1 -314
  224. package/dist/esm/modules/file-upload/file-upload.service.js.map +1 -1
  225. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +1 -87
  226. package/dist/esm/modules/swagger/swagger.router.js +1 -93
  227. package/dist/esm/modules/swagger/swagger.router.js.map +1 -1
  228. package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +1 -247
  229. package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
  230. package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js +1 -0
  231. package/dist/esm/modules/swagger/utils/helpers/get-swagger-default-configs.js.map +1 -0
  232. package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +1 -63
  233. package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +1 -1
  234. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +1 -38
  235. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +1 -1
  236. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +1 -19
  237. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
  238. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js +1 -0
  239. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.js.map +1 -0
  240. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js +1 -0
  241. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.js.map +1 -0
  242. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js +1 -0
  243. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.js.map +1 -0
  244. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js +1 -0
  245. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.js.map +1 -0
  246. package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js +1 -0
  247. package/dist/esm/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
  248. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +1 -84
  249. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
  250. package/dist/esm/package.json +3 -0
  251. package/dist/esm/server.js +4 -2
  252. package/dist/esm/server.js.map +1 -1
  253. package/dist/esm/types/arkos-config.js +1 -2
  254. package/dist/esm/types/arkos-config.js.map +1 -1
  255. package/dist/esm/types/auth.js +1 -2
  256. package/dist/esm/types/auth.js.map +1 -1
  257. package/dist/esm/types/index.js +1 -8
  258. package/dist/esm/types/index.js.map +1 -1
  259. package/dist/esm/types/router-config.js +1 -2
  260. package/dist/esm/types/router-config.js.map +1 -1
  261. package/dist/esm/utils/arkos-env.js +1 -7
  262. package/dist/esm/utils/cli/build.js +5 -206
  263. package/dist/esm/utils/cli/build.js.map +1 -1
  264. package/dist/esm/utils/cli/dev.js +3 -249
  265. package/dist/esm/utils/cli/dev.js.map +1 -1
  266. package/dist/esm/utils/cli/generate.js +1 -183
  267. package/dist/esm/utils/cli/generate.js.map +1 -1
  268. package/dist/esm/utils/cli/index.js +1 -74
  269. package/dist/esm/utils/cli/index.js.map +1 -1
  270. package/dist/esm/utils/cli/start.js +1 -86
  271. package/dist/esm/utils/cli/start.js.map +1 -1
  272. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -16
  273. package/dist/esm/utils/cli/utils/smart-fs-watcher.js +1 -0
  274. package/dist/esm/utils/cli/utils/smart-fs-watcher.js.map +1 -0
  275. package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +5 -17
  276. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +9 -15
  277. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +1 -1
  278. package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js +144 -0
  279. package/dist/esm/utils/cli/utils/template-generator/templates/generate-hooks-template.js.map +1 -0
  280. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js +156 -132
  281. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +1 -1
  282. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +9 -34
  283. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +1 -1
  284. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js +11 -30
  285. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +1 -1
  286. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js +6 -29
  287. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js.map +1 -1
  288. package/dist/esm/utils/cli/utils/template-generators.js +2 -25
  289. package/dist/esm/utils/cli/utils/template-generators.js.map +1 -1
  290. package/dist/esm/utils/cli/utils/watermark-stamper.js +3 -0
  291. package/dist/esm/utils/cli/utils/watermark-stamper.js.map +1 -0
  292. package/dist/esm/utils/dotenv.helpers.js +1 -37
  293. package/dist/esm/utils/dynamic-loader.js +9 -0
  294. package/dist/esm/utils/dynamic-loader.js.map +1 -0
  295. package/dist/esm/utils/features/api.features.js +1 -160
  296. package/dist/esm/utils/features/api.features.js.map +1 -1
  297. package/dist/esm/utils/features/change-case.features.js +1 -31
  298. package/dist/esm/utils/features/port-and-host-allocator.js +1 -0
  299. package/dist/esm/utils/features/port-and-host-allocator.js.map +1 -0
  300. package/dist/esm/utils/helpers/api.features.helpers.js +1 -103
  301. package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
  302. package/dist/esm/utils/helpers/change-case.helpers.js +1 -161
  303. package/dist/esm/utils/helpers/deepmerge.helper.js +1 -113
  304. package/dist/esm/utils/helpers/dynamic-loader.helpers.js +1 -0
  305. package/dist/esm/utils/helpers/dynamic-loader.helpers.js.map +1 -0
  306. package/dist/esm/utils/helpers/fs.helpers.js +1 -52
  307. package/dist/esm/utils/helpers/fs.helpers.js.map +1 -1
  308. package/dist/esm/utils/helpers/global.helpers.js +1 -50
  309. package/dist/esm/utils/helpers/global.helpers.js.map +1 -1
  310. package/dist/esm/utils/helpers/prisma.helpers.js +1 -44
  311. package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
  312. package/dist/esm/utils/helpers/query-parser.helpers.js +1 -40
  313. package/dist/esm/utils/helpers/routers.helpers.js +1 -16
  314. package/dist/esm/utils/helpers/routers.helpers.js.map +1 -1
  315. package/dist/esm/utils/helpers/text.helpers.js +1 -22
  316. package/dist/esm/utils/prisma/prisma-json-schema-generator.js +1 -0
  317. package/dist/esm/utils/prisma/prisma-json-schema-generator.js.map +1 -0
  318. package/dist/esm/utils/prisma/prisma-schema-parser.js +4 -0
  319. package/dist/esm/utils/prisma/prisma-schema-parser.js.map +1 -0
  320. package/dist/esm/utils/prisma/types.js +1 -0
  321. package/dist/esm/utils/prisma/types.js.map +1 -0
  322. package/dist/esm/utils/sheu.js +1 -117
  323. package/dist/esm/utils/sheu.js.map +1 -1
  324. package/dist/esm/utils/validate-dto.js +1 -11
  325. package/dist/esm/utils/validate-dto.js.map +1 -1
  326. package/dist/esm/utils/validate-schema.js +1 -9
  327. package/dist/esm/utils/validate-schema.js.map +1 -1
  328. package/dist/types/exports/prisma/index.d.ts +3 -2
  329. package/dist/types/exports/services/index.d.ts +3 -2
  330. package/dist/types/modules/auth/auth.controller.d.ts +10 -9
  331. package/dist/types/modules/auth/auth.service.d.ts +7 -3
  332. package/dist/types/modules/auth/utils/auth-error-objects.d.ts +3 -0
  333. package/dist/types/modules/auth/utils/services/auth-action.service.d.ts +23 -0
  334. package/dist/types/modules/base/base.controller.d.ts +10 -12
  335. package/dist/types/modules/base/base.middlewares.d.ts +4 -4
  336. package/dist/types/modules/base/base.service.d.ts +14 -68
  337. package/dist/types/modules/base/types/base.service.types.d.ts +215 -0
  338. package/dist/types/modules/base/utils/helpers/base.controller.helpers.d.ts +0 -2
  339. package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +3 -3
  340. package/dist/types/modules/base/utils/helpers/base.service.helpers.d.ts +9 -2
  341. package/dist/types/modules/base/utils/router-validator.d.ts +5 -0
  342. package/dist/types/modules/base/utils/service-hooks-manager.d.ts +7 -0
  343. package/dist/types/modules/error-handler/error-handler.controller.d.ts +1 -1
  344. package/dist/types/modules/error-handler/utils/catch-async.d.ts +4 -2
  345. package/dist/types/modules/error-handler/utils/error-handler.helpers.d.ts +18 -17
  346. package/dist/types/modules/file-upload/file-upload.controller.d.ts +4 -6
  347. package/dist/types/modules/file-upload/file-upload.service.d.ts +4 -5
  348. package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +3 -1
  349. package/dist/types/modules/swagger/utils/helpers/get-swagger-default-configs.d.ts +46 -0
  350. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +2 -1
  351. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-system-json-schemas.d.ts +4 -0
  352. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schemas.d.ts +1 -0
  353. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes-paths.d.ts +3 -0
  354. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes-paths.d.ts +3 -0
  355. package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +34 -0
  356. package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +4 -2
  357. package/dist/types/server.d.ts +4 -1
  358. package/dist/types/types/arkos-config.d.ts +5 -3
  359. package/dist/types/types/auth.d.ts +7 -1
  360. package/dist/types/types/index.d.ts +4 -1
  361. package/dist/types/types/router-config.d.ts +24 -1
  362. package/dist/types/utils/cli/generate.d.ts +2 -1
  363. package/dist/types/utils/cli/utils/smart-fs-watcher.d.ts +11 -0
  364. package/dist/types/utils/cli/utils/template-generator/templates/generate-hooks-template.d.ts +2 -0
  365. package/dist/types/utils/cli/utils/watermark-stamper.d.ts +9 -0
  366. package/dist/types/utils/dynamic-loader.d.ts +104 -0
  367. package/dist/types/utils/features/port-and-host-allocator.d.ts +21 -0
  368. package/dist/types/utils/helpers/dynamic-loader.helpers.d.ts +3 -0
  369. package/dist/types/utils/helpers/fs.helpers.d.ts +0 -4
  370. package/dist/types/utils/helpers/global.helpers.d.ts +1 -0
  371. package/dist/types/utils/helpers/prisma.helpers.d.ts +0 -1
  372. package/dist/types/utils/helpers/routers.helpers.d.ts +6 -2
  373. package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +34 -0
  374. package/dist/types/utils/prisma/prisma-schema-parser.d.ts +28 -0
  375. package/dist/types/utils/prisma/types.d.ts +49 -0
  376. package/dist/types/utils/sheu.d.ts +15 -15
  377. package/package.json +32 -18
  378. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +0 -30
  379. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +0 -1
  380. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +0 -442
  381. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +0 -1
  382. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +0 -165
  383. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +0 -1
  384. package/dist/cjs/utils/helpers/models.helpers.js +0 -313
  385. package/dist/cjs/utils/helpers/models.helpers.js.map +0 -1
  386. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +0 -24
  387. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +0 -1
  388. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +0 -436
  389. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +0 -1
  390. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +0 -159
  391. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +0 -1
  392. package/dist/esm/utils/helpers/models.helpers.js +0 -296
  393. package/dist/esm/utils/helpers/models.helpers.js.map +0 -1
  394. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.d.ts +0 -1
  395. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.d.ts +0 -2
  396. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.d.ts +0 -2
  397. package/dist/types/utils/helpers/models.helpers.d.ts +0 -107
@@ -1,146 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = errorHandler;
40
- const app_error_1 = __importDefault(require("./utils/app-error"));
41
- const errorControllerHelper = __importStar(require("./utils/error-handler.helpers"));
42
- const server_1 = require("../../server");
43
- function errorHandler(err, req, res, next) {
44
- console.error("[\x1b[31mERROR\x1b[0m]:", err);
45
- err.statusCode = err.statusCode || 500;
46
- err.status = err.status || "error";
47
- if (process.env.NODE_ENV !== "production") {
48
- sendDevelopmentError(err, req, res);
49
- return;
50
- }
51
- let error = { ...err, message: err.message };
52
- if (err.name === "JsonWebTokenError")
53
- error = errorControllerHelper.handleJWTError();
54
- if (err.name === "TokenExpiredError")
55
- error = errorControllerHelper.handleJWTExpired();
56
- if (err.name === "PrismaClientValidationError")
57
- error = errorControllerHelper.handlePrismaClientValidationError(err);
58
- if (err.code === "P1000")
59
- error = errorControllerHelper.handleAuthenticationError(err);
60
- if (err.code === "P1001")
61
- error = errorControllerHelper.handleServerNotReachableError(err);
62
- if (err.code === "P1002")
63
- error = errorControllerHelper.handleConnectionTimeoutError(err);
64
- if (err.code === "P1003")
65
- error = errorControllerHelper.handleDatabaseNotFoundError(err);
66
- if (err.code === "P2000")
67
- error = errorControllerHelper.handleFieldValueTooLargeError(err);
68
- if (err.code === "P2001")
69
- error = errorControllerHelper.handleRecordNotFoundError(err);
70
- if (err.code === "P2002")
71
- error = errorControllerHelper.handleUniqueConstraintError(err);
72
- if (err.code === "P2003")
73
- error = errorControllerHelper.handleForeignKeyConstraintError(err);
74
- if (err.code === "P2004")
75
- error = errorControllerHelper.handleConstraintFailedError(err);
76
- if (err.code === "P2025")
77
- error = errorControllerHelper.handleNonExistingRecord(err);
78
- if (err.code === "P3000")
79
- error = errorControllerHelper.handleSchemaCreationFailedError(err);
80
- if (err.code === "P3001")
81
- error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);
82
- if (err.code === "P3002")
83
- error = errorControllerHelper.handleMigrationScriptFailedError(err);
84
- if (err.code === "P3003")
85
- error = errorControllerHelper.handleVersionMismatchError(err);
86
- if (err.name === "NetworkError")
87
- error = errorControllerHelper.handleNetworkError(err);
88
- if (!error.isOperational)
89
- error = new app_error_1.default("Something went wrong!", 500);
90
- sendProductionError(error, req, res);
91
- }
92
- function sendDevelopmentError(err, req, res) {
93
- if (req.originalUrl.startsWith("/api"))
94
- res.status(err.statusCode).json({
95
- ...err,
96
- message: err.message.split("\n")[err.message.split("\n").length - 1],
97
- stack: err.stack?.split("\n"),
98
- });
99
- else
100
- res.status(err.statusCode).json({
101
- title: "Something went wrong!",
102
- message: err.message,
103
- });
104
- }
105
- function sendProductionError(err, req, res) {
106
- if (req.originalUrl.startsWith("/api")) {
107
- if (err.isOperational)
108
- res.status(err.statusCode).json({
109
- status: err.status,
110
- message: err.message,
111
- meta: err.meta || {},
112
- code: err.code || "unknown",
113
- });
114
- else
115
- res.status(500).json({
116
- status: "error",
117
- message: "Something went wrong!",
118
- });
119
- return;
120
- }
121
- if (err.isOperational) {
122
- res.status(err.statusCode).json({
123
- title: "Something went wrong!",
124
- message: err.message,
125
- });
126
- return;
127
- }
128
- res.status(err.statusCode).json({
129
- title: "Something went wrong!",
130
- message: "Please try again later.",
131
- });
132
- }
133
- process.on("SIGTERM", () => {
134
- if (process.env.NODE_ENV !== "production" &&
135
- process.env.NODE_ENV !== "staging") {
136
- process.exit();
137
- }
138
- else {
139
- console.error("SIGTERM RECEIVED in Production. Shutting down gracefully!");
140
- server_1.server.close(() => {
141
- console.error("Process terminated!!!");
142
- process.exit();
143
- });
144
- }
145
- });
146
- //# sourceMappingURL=error-handler.controller.js.map
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,n,o,a){a===void 0&&(a=o);var t=Object.getOwnPropertyDescriptor(n,o);(!t||("get"in t?!n.__esModule:t.writable||t.configurable))&&(t={enumerable:!0,get:function(){return n[o]}}),Object.defineProperty(e,a,t)}:function(e,n,o,a){a===void 0&&(a=o),e[a]=n[o]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),__importStar=this&&this.__importStar||function(){var e=function(n){return e=Object.getOwnPropertyNames||function(o){var a=[];for(var t in o)Object.prototype.hasOwnProperty.call(o,t)&&(a[a.length]=t);return a},e(n)};return function(n){if(n&&n.__esModule)return n;var o={};if(n!=null)for(var a=e(n),t=0;t<a.length;t++)a[t]!=="default"&&__createBinding(o,n,a[t]);return __setModuleDefault(o,n),o}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=errorHandler;const app_error_1=__importDefault(require("./utils/app-error")),errorControllerHelper=__importStar(require("./utils/error-handler.helpers")),server_1=require("../../server");function errorHandler(e,n,o,a){if(console.error("[\x1B[31mError\x1B[0m]:",e),e.statusCode=e.statusCode||500,e.status=e.status||"error",process.env.NODE_ENV!=="production")return sendDevelopmentError(e,n,o);let t={...e,message:e.message};e.name==="JsonWebTokenError"&&(t=errorControllerHelper.handleJWTError()),e.name==="TokenExpiredError"&&(t=errorControllerHelper.handleJWTExpired()),e.name==="PrismaClientValidationError"&&(t=errorControllerHelper.handlePrismaClientValidationError(e)),e.name==="PrismaClientInitializationError"&&(t=errorControllerHelper.handlePrismaClientInitializationError(e)),e.code==="P1000"&&(t=errorControllerHelper.handleAuthenticationError(e)),e.code==="P1001"&&(t=errorControllerHelper.handleServerNotReachableError(e)),e.code==="P1002"&&(t=errorControllerHelper.handleConnectionTimeoutError(e)),e.code==="P1003"&&(t=errorControllerHelper.handleDatabaseNotFoundError(e)),e.code==="P2000"&&(t=errorControllerHelper.handleFieldValueTooLargeError(e)),e.code==="P2001"&&(t=errorControllerHelper.handleRecordNotFoundError(e)),e.code==="P2002"&&(t=errorControllerHelper.handleUniqueConstraintError(e)),e.code==="P2003"&&(t=errorControllerHelper.handleForeignKeyConstraintError(e)),e.code==="P2004"&&(t=errorControllerHelper.handleConstraintFailedError(e)),e.code==="P2025"&&(t=errorControllerHelper.handleNonExistingRecord(e)),e.code==="P3000"&&(t=errorControllerHelper.handleSchemaCreationFailedError(e)),e.code==="P3001"&&(t=errorControllerHelper.handleMigrationAlreadyAppliedError(e)),e.code==="P3002"&&(t=errorControllerHelper.handleMigrationScriptFailedError(e)),e.code==="P3003"&&(t=errorControllerHelper.handleVersionMismatchError(e)),e.name==="NetworkError"&&(t=errorControllerHelper.handleNetworkError(e)),t.isOperational||(t=new app_error_1.default("Internal server error",500)),sendProductionError(t,n,o)}function sendDevelopmentError(e,n,o){n.originalUrl.startsWith("/api")?o.status(e.statusCode).json({...e,message:e.message.split(`
2
+ `)[e.message.split(`
3
+ `).length-1],stack:e.stack?.split(`
4
+ `)}):o.status(e.statusCode).json({title:"Internal server error",message:e.message})}function sendProductionError(e,n,o){if(n.originalUrl.startsWith("/api")){e.isOperational?o.status(e.statusCode).json({status:e.status,message:e.message,meta:e.meta||{},code:e.code||"unknown"}):o.status(500).json({status:"error",message:"Internal server error"});return}if(e.isOperational){o.status(e.statusCode).json({title:"Internal server error",message:e.message});return}o.status(e.statusCode).json({title:"Internal server error",message:"Please try again later."})}process.on("SIGTERM",()=>{process.env.NODE_ENV!=="production"&&process.env.NODE_ENV!=="staging"?process.exit():(console.error("SIGTERM RECEIVED in Production. Shutting down gracefully!"),server_1.server.close(()=>{console.error("Process terminated!!!"),process.exit()}))});
@@ -1 +1 @@
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,CAA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AC;YAC9B,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,GAAG,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 === \"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"]}
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,CAAe;IAEf,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;QACvC,OAAO,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAG7C,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,GAAG,CAAC,CAAC;IACvE,IAAI,GAAG,CAAC,IAAI,KAAK,iCAAiC;QAChD,KAAK,GAAG,qBAAqB,CAAC,qCAAqC,CAAC,GAAG,CAAC,CAAC;IAG3E,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QACtB,KAAK,GAA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AAE,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} _ - 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 _: 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 return sendDevelopmentError(err, req, res);\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 if (err.name === \"PrismaClientInitializationError\")\n error = errorControllerHelper.handlePrismaClientInitializationError(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(\"Internal server error\", 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: \"Internal server error\",\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: \"Internal server error\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Internal server error\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Internal server error\",\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,17 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class AppError extends Error {
4
- constructor(message, statusCode, meta, code) {
5
- super(message);
6
- this.message = message;
7
- this.statusCode = statusCode;
8
- this.status = `${statusCode}`.startsWith("4") ? "fail" : "error";
9
- this.isOperational = true;
10
- this.code = code;
11
- this.meta = meta;
12
- this.missing = false;
13
- Error.captureStackTrace(this, this.constructor);
14
- }
15
- }
16
- exports.default = AppError;
17
- //# sourceMappingURL=app-error.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class AppError extends Error{constructor(r,t,s,e){super(r),this.message=r||"An error occurred, try again!",this.statusCode=t,this.status=`${t}`.startsWith("4")?"fail":"error",this.isOperational=!0,this.code=e||"Unknown",this.meta=s,this.missing=!1,Error.captureStackTrace(this,this.constructor)}}exports.default=AppError;
@@ -1 +1 @@
1
- {"version":3,"file":"app-error.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/app-error.ts"],"names":[],"mappings":";;AAgCA,MAAM,QAAS,SAAQ,KAAK;IAgB1B,YACE,OAAe,EACf,UAAkB,EAClB,IAA0B,EAC1B,IAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC","sourcesContent":["/**\n * Custom error class for handling application errors.\n *\n * @extends {Error}\n *\n * @property {number} statusCode - HTTP status code of the error.\n * @property {string} status - Status message derived from the status code (`fail` for 4xx, `error` for 5xx).\n * @property {boolean} [missing=false] - Flag to indicate if a resource is missing.\n * @property {boolean} isOperational - Indicates if the error is operational (intended for client visibility).\n * @property {string} [code] - Optional error code for categorization.\n * @property {Record<string, any>} [meta] - Additional metadata related to the error.\n *\n * @example\n * ```typescript\n *\n * function getUser(id: string) {\n * if (!id) {\n * throw new AppError('User ID is required', 400, { field: 'id' }, 'USER_ID_MISSING');\n * }\n * // Simulate a user not found scenario\n * throw new AppError('User not found', 404, { userId: id }, 'USER_NOT_FOUND');\n * }\n *\n * try {\n * getUser('');\n * } catch (error) {\n * if (error instanceof AppError) {\n * console.error(`Error: ${error.message}, Code: ${error.code}, Status: ${error.status}`);\n * }\n * }\n * ```\n */\nclass AppError extends Error {\n statusCode: number;\n status: string;\n public missing?: boolean;\n public isOperational: boolean;\n code?: string;\n meta?: Record<string, any>;\n\n /**\n * Creates an instance of AppError.\n *\n * @param {string} message - The error message.\n * @param {number} statusCode - The HTTP status code.\n * @param {Record<string, any>} [meta] - Additional metadata for debugging or client feedback.\n * @param {string} [code] - A custom error code for categorization.\n */\n constructor(\n message: string,\n statusCode: number,\n meta?: Record<string, any>,\n code?: string\n ) {\n super(message);\n\n this.message = message;\n this.statusCode = statusCode;\n this.status = `${statusCode}`.startsWith(\"4\") ? \"fail\" : \"error\";\n this.isOperational = true;\n this.code = code;\n this.meta = meta;\n this.missing = false;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport default AppError;\n"]}
1
+ {"version":3,"file":"app-error.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/app-error.ts"],"names":[],"mappings":";;AAgCA,MAAM,QAAS,SAAQ,KAAK;IAgB1B,YACE,OAAe,EACf,UAAkB,EAClB,IAA0B,EAC1B,IAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,+BAA+B,CAAC;QAC1D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,SAAS,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAErB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED,kBAAe,QAAQ,CAAC","sourcesContent":["/**\n * Custom error class for handling application errors.\n *\n * @extends {Error}\n *\n * @property {number} statusCode - HTTP status code of the error.\n * @property {string} status - Status message derived from the status code (`fail` for 4xx, `error` for 5xx).\n * @property {boolean} [missing=false] - Flag to indicate if a resource is missing.\n * @property {boolean} isOperational - Indicates if the error is operational (intended for client visibility).\n * @property {string} [code] - Optional error code for categorization.\n * @property {Record<string, any>} [meta] - Additional metadata related to the error.\n *\n * @example\n * ```typescript\n *\n * function getUser(id: string) {\n * if (!id) {\n * throw new AppError('User ID is required', 400, { field: 'id' }, 'USER_ID_MISSING');\n * }\n * // Simulate a user not found scenario\n * throw new AppError('User not found', 404, { userId: id }, 'USER_NOT_FOUND');\n * }\n *\n * try {\n * getUser('');\n * } catch (error) {\n * if (error instanceof AppError) {\n * console.error(`Error: ${error.message}, Code: ${error.code}, Status: ${error.status}`);\n * }\n * }\n * ```\n */\nclass AppError extends Error {\n statusCode: number;\n status: string;\n public missing?: boolean;\n public isOperational: boolean;\n code?: string;\n meta?: Record<string, any>;\n\n /**\n * Creates an instance of AppError.\n *\n * @param {string} message - The error message.\n * @param {number} statusCode - The HTTP status code.\n * @param {Record<string, any>} [meta] - Additional metadata for debugging or client feedback.\n * @param {string} [code] - A custom error code for categorization.\n */\n constructor(\n message: string,\n statusCode: number,\n meta?: Record<string, any>,\n code?: string\n ) {\n super(message);\n\n this.message = message || \"An error occurred, try again!\";\n this.statusCode = statusCode;\n this.status = `${statusCode}`.startsWith(\"4\") ? \"fail\" : \"error\";\n this.isOperational = true;\n this.code = code || \"Unknown\";\n this.meta = meta;\n this.missing = false;\n\n Error.captureStackTrace(this, this.constructor);\n }\n}\n\nexport default AppError;\n"]}
@@ -1,12 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const catchAsync = (fn) => async (req, res, next) => {
4
- try {
5
- return (await fn(req, res, next));
6
- }
7
- catch (err) {
8
- next(err);
9
- }
10
- };
11
- exports.default = catchAsync;
12
- //# sourceMappingURL=catch-async.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const catchAsync=(c,s={type:"normal"})=>s?.type==="error"?async(e,a,r,t)=>{try{return await c(e,a,r,t)}catch(y){t(y)}}:async(e,a,r)=>{try{return await c(e,a,r)}catch(t){r(t)}};exports.default=catchAsync;
@@ -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,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"]}
1
+ {"version":3,"file":"catch-async.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/catch-async.ts"],"names":[],"mappings":";;AAyBA,MAAM,UAAU,GAAG,CACjB,EAAkD,EAClD,UAAwC,EAAE,IAAI,EAAE,QAAQ,EAAE,EACrD,EAAE,CACP,OAAO,EAAE,IAAI,KAAK,OAAO;IACvB,CAAC,CAAC,KAAK,EACH,GAAQ,EACR,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;QACjB,IAAI,CAAC;YACH,OAAO,CAAC,MAAO,EAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;QAC1D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;IACH,CAAC,CAAC,KAAK,EACH,GAAiB,EACjB,GAAkB,EAClB,IAAuB,EACR,EAAE;QACjB,IAAI,CAAC;YACH,OAAO,CAAC,MAAO,EAA0B,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAS,CAAC;QACrE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AAIR,kBAAe,UAAU,CAAC","sourcesContent":["import {\n ArkosRequest,\n ArkosResponse,\n ArkosNextFunction,\n ArkosRequestHandler,\n ArkosErrorRequestHandler,\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 | ArkosErrorRequestHandler,\n options: { type: \"error\" | \"normal\" } = { type: \"normal\" }\n): any =>\n options?.type === \"error\"\n ? async (\n err: any,\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await (fn as any)(err, req, res, next)) as void;\n } catch (err) {\n next(err);\n }\n }\n : async (\n req: ArkosRequest,\n res: ArkosResponse,\n next: ArkosNextFunction\n ): Promise<void> => {\n try {\n return (await (fn as ArkosRequestHandler)(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"]}
@@ -1,201 +1,3 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handleJWTError = handleJWTError;
7
- exports.handleJWTExpired = handleJWTExpired;
8
- exports.handlePrismaClientValidationError = handlePrismaClientValidationError;
9
- exports.handleAuthenticationError = handleAuthenticationError;
10
- exports.handleServerNotReachableError = handleServerNotReachableError;
11
- exports.handleConnectionTimeoutError = handleConnectionTimeoutError;
12
- exports.handleDatabaseNotFoundError = handleDatabaseNotFoundError;
13
- exports.handleEnvironmentVariableError = handleEnvironmentVariableError;
14
- exports.handleFieldValueTooLargeError = handleFieldValueTooLargeError;
15
- exports.handleRecordNotFoundError = handleRecordNotFoundError;
16
- exports.handleUniqueConstraintError = handleUniqueConstraintError;
17
- exports.handleForeignKeyConstraintError = handleForeignKeyConstraintError;
18
- exports.handleConstraintFailedError = handleConstraintFailedError;
19
- exports.handleInvalidFieldValueError = handleInvalidFieldValueError;
20
- exports.handleInvalidFieldProvidedError = handleInvalidFieldProvidedError;
21
- exports.handleDataValidationError = handleDataValidationError;
22
- exports.handleQueryParsingError = handleQueryParsingError;
23
- exports.handleInvalidQueryFormatError = handleInvalidQueryFormatError;
24
- exports.handleRawQueryExecutionError = handleRawQueryExecutionError;
25
- exports.handleNullConstraintViolationError = handleNullConstraintViolationError;
26
- exports.handleSchemaCreationFailedError = handleSchemaCreationFailedError;
27
- exports.handleMigrationAlreadyAppliedError = handleMigrationAlreadyAppliedError;
28
- exports.handleMigrationScriptFailedError = handleMigrationScriptFailedError;
29
- exports.handleVersionMismatchError = handleVersionMismatchError;
30
- exports.handleMigrationFileReadError = handleMigrationFileReadError;
31
- exports.handleSchemaDriftError = handleSchemaDriftError;
32
- exports.handleSchemaSyntaxError = handleSchemaSyntaxError;
33
- exports.handleClientTypeError = handleClientTypeError;
34
- exports.handleDynamicQueryError = handleDynamicQueryError;
35
- exports.handleRelationLoadingError = handleRelationLoadingError;
36
- exports.handleBinaryError = handleBinaryError;
37
- exports.handleNetworkError = handleNetworkError;
38
- exports.handleUnhandledPromiseError = handleUnhandledPromiseError;
39
- exports.handleDataTypeError = handleDataTypeError;
40
- exports.handleEmptyResultError = handleEmptyResultError;
41
- exports.handleNonExistingRecord = handleNonExistingRecord;
42
- const app_error_1 = __importDefault(require("./app-error"));
43
- function handleJWTError() {
44
- return new app_error_1.default("Invalid token. Please log in again!", 401);
45
- }
46
- function handleJWTExpired() {
47
- return new app_error_1.default("Your token has expired, Please log again!", 401);
48
- }
49
- function handlePrismaClientValidationError(err) {
50
- const message = err?.message.split("\n")[err?.message.split("\n").length - 1];
51
- return new app_error_1.default(message, 400);
52
- }
53
- function handleAuthenticationError(err) {
54
- const message = "Authentication failed against the database server. Please check your credentials.";
55
- return new app_error_1.default(message, 401);
56
- }
57
- function handleServerNotReachableError(err) {
58
- const message = "The database server is not reachable. Verify your connection string or ensure the server is online.";
59
- return new app_error_1.default(message, 503);
60
- }
61
- function handleConnectionTimeoutError(err) {
62
- const message = "Connection to the database timed out. Please check server performance or network connectivity.";
63
- return new app_error_1.default(message, 504);
64
- }
65
- function handleDatabaseNotFoundError(err) {
66
- const message = "The specified database does not exist on the server.";
67
- return new app_error_1.default(message, 404);
68
- }
69
- function handleEnvironmentVariableError(err) {
70
- const missingVars = err?.missing || "unknown environment variables";
71
- const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;
72
- return new app_error_1.default(message, 500);
73
- }
74
- function handleFieldValueTooLargeError(err) {
75
- const message = `The value for the field "${err?.meta?.field_name}" is too large. Please provide a smaller value.`;
76
- return new app_error_1.default(message, 400);
77
- }
78
- function handleRecordNotFoundError(err) {
79
- const message = "No record found for the given query. Ensure the query parameters are correct.";
80
- return new app_error_1.default(message, 404);
81
- }
82
- function handleUniqueConstraintError(err) {
83
- const field = err?.meta?.target || "unknown field";
84
- const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;
85
- return new app_error_1.default(message, 409);
86
- }
87
- function handleForeignKeyConstraintError(err) {
88
- const message = "Foreign key constraint violation. Ensure that the referenced record exists.";
89
- return new app_error_1.default(message, 400);
90
- }
91
- function handleConstraintFailedError(err) {
92
- const constraint = err?.meta?.constraint || "unknown constraint";
93
- const message = `A database constraint "${constraint}" failed. Please review your input data.`;
94
- return new app_error_1.default(message, 400);
95
- }
96
- function handleInvalidFieldValueError(err) {
97
- const fieldName = err?.meta?.field_name || "unknown field";
98
- const message = `Invalid value provided for the field "${fieldName}". Please provide a valid value.`;
99
- return new app_error_1.default(message, 400);
100
- }
101
- function handleInvalidFieldProvidedError(err) {
102
- const fieldName = err?.meta?.field_name || "unknown field";
103
- const message = `The field "${fieldName}" has been provided with an invalid value. Check the data and try again.`;
104
- return new app_error_1.default(message, 400);
105
- }
106
- function handleDataValidationError(err) {
107
- const message = "Data validation error occurred. Please ensure all fields meet the required criteria.";
108
- return new app_error_1.default(message, 400);
109
- }
110
- function handleQueryParsingError(err) {
111
- const query = err?.meta?.query || "unknown query";
112
- const message = `Failed to parse the query: "${query}". Check the syntax and structure.`;
113
- return new app_error_1.default(message, 400);
114
- }
115
- function handleInvalidQueryFormatError(err) {
116
- const query = err?.meta?.query || "unknown query";
117
- const message = `The query format is invalid: "${query}". Ensure the query adheres to the expected format.`;
118
- return new app_error_1.default(message, 400);
119
- }
120
- function handleRawQueryExecutionError(err) {
121
- const message = "An error occurred during the execution of a raw query. Verify the query and try again.";
122
- return new app_error_1.default(message, 500);
123
- }
124
- function handleNullConstraintViolationError(err) {
125
- const fieldName = err?.meta?.field_name || "unknown field";
126
- const message = `The field "${fieldName}" cannot be null. Please provide a value.`;
127
- return new app_error_1.default(message, 400);
128
- }
129
- function handleSchemaCreationFailedError(err) {
130
- const message = "Failed to create the database schema. Verify the schema definition and try again.";
131
- return new app_error_1.default(message, 500);
132
- }
133
- function handleMigrationAlreadyAppliedError(err) {
134
- const migrationName = err?.meta?.migration || "unknown migration";
135
- const message = `The migration "${migrationName}" has already been applied to the database.`;
136
- return new app_error_1.default(message, 409);
137
- }
138
- function handleMigrationScriptFailedError(err) {
139
- const migrationName = err?.meta?.migration || "unknown migration";
140
- const message = `The migration script "${migrationName}" failed. Review the script and resolve any issues.`;
141
- return new app_error_1.default(message, 500);
142
- }
143
- function handleVersionMismatchError(err) {
144
- const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;
145
- return new app_error_1.default(message, 400);
146
- }
147
- function handleMigrationFileReadError(err) {
148
- const migrationFile = err?.meta?.migration_file || "unknown file";
149
- const message = `Failed to read the migration file "${migrationFile}". Ensure the file exists and is accessible.`;
150
- return new app_error_1.default(message, 500);
151
- }
152
- function handleSchemaDriftError(err) {
153
- const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;
154
- return new app_error_1.default(message, 400);
155
- }
156
- function handleSchemaSyntaxError(err) {
157
- const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;
158
- return new app_error_1.default(message, 500);
159
- }
160
- function handleClientTypeError(err) {
161
- const message = `Type error, Ensure proper usage of methods and correct data types.`;
162
- return new app_error_1.default(message, 400);
163
- }
164
- function handleDynamicQueryError(err) {
165
- const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;
166
- return new app_error_1.default(message, 400);
167
- }
168
- function handleRelationLoadingError(err) {
169
- const relation = err?.meta?.relation || "unknown relation";
170
- const message = `Error loading relation "${relation}". Ensure it is correctly defined and included in the query.`;
171
- return new app_error_1.default(message, 400);
172
- }
173
- function handleBinaryError(err) {
174
- const binaryName = err?.meta?.binary || "unknown binary";
175
- const message = `Error with Prisma binary "${binaryName}". Ensure the binary is properly installed and compatible.`;
176
- return new app_error_1.default(message, 500);
177
- }
178
- function handleNetworkError(err) {
179
- const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;
180
- return new app_error_1.default(message, 500);
181
- }
182
- function handleUnhandledPromiseError(err) {
183
- const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;
184
- return new app_error_1.default(message, 500);
185
- }
186
- function handleDataTypeError(err) {
187
- const field = err?.meta?.field || "unknown field";
188
- const expectedType = err?.meta?.expected_type || "unknown type";
189
- const message = `Invalid data type for field "${field}". Expected type: ${expectedType}.`;
190
- return new app_error_1.default(message, 400);
191
- }
192
- function handleEmptyResultError(err) {
193
- const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;
194
- return new app_error_1.default(message, 404);
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
- }
201
- //# sourceMappingURL=error-handler.helpers.js.map
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleJWTError=handleJWTError,exports.handleJWTExpired=handleJWTExpired,exports.handlePrismaClientValidationError=handlePrismaClientValidationError,exports.handleAuthenticationError=handleAuthenticationError,exports.handleServerNotReachableError=handleServerNotReachableError,exports.handleConnectionTimeoutError=handleConnectionTimeoutError,exports.handleDatabaseNotFoundError=handleDatabaseNotFoundError,exports.handleEnvironmentVariableError=handleEnvironmentVariableError,exports.handleFieldValueTooLargeError=handleFieldValueTooLargeError,exports.handleRecordNotFoundError=handleRecordNotFoundError,exports.handleUniqueConstraintError=handleUniqueConstraintError,exports.handleForeignKeyConstraintError=handleForeignKeyConstraintError,exports.handleConstraintFailedError=handleConstraintFailedError,exports.handleInvalidFieldValueError=handleInvalidFieldValueError,exports.handleInvalidFieldProvidedError=handleInvalidFieldProvidedError,exports.handleDataValidationError=handleDataValidationError,exports.handleQueryParsingError=handleQueryParsingError,exports.handleInvalidQueryFormatError=handleInvalidQueryFormatError,exports.handleRawQueryExecutionError=handleRawQueryExecutionError,exports.handleNullConstraintViolationError=handleNullConstraintViolationError,exports.handleSchemaCreationFailedError=handleSchemaCreationFailedError,exports.handleMigrationAlreadyAppliedError=handleMigrationAlreadyAppliedError,exports.handleMigrationScriptFailedError=handleMigrationScriptFailedError,exports.handleVersionMismatchError=handleVersionMismatchError,exports.handleMigrationFileReadError=handleMigrationFileReadError,exports.handleSchemaDriftError=handleSchemaDriftError,exports.handleSchemaSyntaxError=handleSchemaSyntaxError,exports.handleClientTypeError=handleClientTypeError,exports.handleDynamicQueryError=handleDynamicQueryError,exports.handleRelationLoadingError=handleRelationLoadingError,exports.handleBinaryError=handleBinaryError,exports.handleNetworkError=handleNetworkError,exports.handleUnhandledPromiseError=handleUnhandledPromiseError,exports.handleDataTypeError=handleDataTypeError,exports.handleEmptyResultError=handleEmptyResultError,exports.handleNonExistingRecord=handleNonExistingRecord,exports.handlePrismaClientInitializationError=handlePrismaClientInitializationError;const app_error_1=__importDefault(require("./app-error"));function handleJWTError(){return new app_error_1.default("Invalid token. Please log in again!",401)}function handleJWTExpired(){return new app_error_1.default("Your token has expired, Please log again!",401)}function handlePrismaClientValidationError(e){const r=e?.message?.split(`
2
+ `)[e?.message.split(`
3
+ `).length-1];return new app_error_1.default(r,400)}function handleAuthenticationError(e){const r="Authentication failed against the database server. Please check your credentials.";return new app_error_1.default(r,401)}function handleServerNotReachableError(e){const r="The database server is not reachable. Verify your connection string or ensure the server is online.";return new app_error_1.default(r,503)}function handleConnectionTimeoutError(e){const r="Connection to the database timed out. Please check server performance or network connectivity.";return new app_error_1.default(r,504)}function handleDatabaseNotFoundError(e){const r="The specified database does not exist on the server.";return new app_error_1.default(r,404)}function handleEnvironmentVariableError(e){const n=`Missing or invalid environment variables: ${e?.missing||"unknown environment variables"}. Please check your configuration.`;return new app_error_1.default(n,500)}function handleFieldValueTooLargeError(e){const r=`The value for the field "${e?.meta?.field_name}" is too large. Please provide a smaller value.`;return new app_error_1.default(r,400)}function handleRecordNotFoundError(e){const r="No record found for the given query. Ensure the query parameters are correct.";return new app_error_1.default(r,404)}function handleUniqueConstraintError(e){const n=`Duplicate value detected for the unique field(s): ${e?.meta?.target||"unknown field"}. Please use a different value.`;return new app_error_1.default(n,409)}function handleForeignKeyConstraintError(e){const r="Foreign key constraint violation. Ensure that the referenced record exists.";return new app_error_1.default(r,400)}function handleConstraintFailedError(e){const n=`A database constraint "${e?.meta?.constraint||"unknown constraint"}" failed. Please review your input data.`;return new app_error_1.default(n,400)}function handleInvalidFieldValueError(e){const n=`Invalid value provided for the field "${e?.meta?.field_name||"unknown field"}". Please provide a valid value.`;return new app_error_1.default(n,400)}function handleInvalidFieldProvidedError(e){const n=`The field "${e?.meta?.field_name||"unknown field"}" has been provided with an invalid value. Check the data and try again.`;return new app_error_1.default(n,400)}function handleDataValidationError(e){const r="Data validation error occurred. Please ensure all fields meet the required criteria.";return new app_error_1.default(r,400)}function handleQueryParsingError(e){const n=`Failed to parse the query: "${e?.meta?.query||"unknown query"}". Check the syntax and structure.`;return new app_error_1.default(n,400)}function handleInvalidQueryFormatError(e){const n=`The query format is invalid: "${e?.meta?.query||"unknown query"}". Ensure the query adheres to the expected format.`;return new app_error_1.default(n,400)}function handleRawQueryExecutionError(e){const r="An error occurred during the execution of a raw query. Verify the query and try again.";return new app_error_1.default(r,500)}function handleNullConstraintViolationError(e){const n=`The field "${e?.meta?.field_name||"unknown field"}" cannot be null. Please provide a value.`;return new app_error_1.default(n,400)}function handleSchemaCreationFailedError(e){const r="Failed to create the database schema. Verify the schema definition and try again.";return new app_error_1.default(r,500)}function handleMigrationAlreadyAppliedError(e){const n=`The migration "${e?.meta?.migration||"unknown migration"}" has already been applied to the database.`;return new app_error_1.default(n,409)}function handleMigrationScriptFailedError(e){const n=`The migration script "${e?.meta?.migration||"unknown migration"}" failed. Review the script and resolve any issues.`;return new app_error_1.default(n,500)}function handleVersionMismatchError(e){const r="Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.";return new app_error_1.default(r,400)}function handleMigrationFileReadError(e){const n=`Failed to read the migration file "${e?.meta?.migration_file||"unknown file"}". Ensure the file exists and is accessible.`;return new app_error_1.default(n,500)}function handleSchemaDriftError(e){const r="Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.";return new app_error_1.default(r,400)}function handleSchemaSyntaxError(e){const r="Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.";return new app_error_1.default(r,500)}function handleClientTypeError(e){const r="Type error, Ensure proper usage of methods and correct data types.";return new app_error_1.default(r,400)}function handleDynamicQueryError(e){const r="Error constructing or executing a dynamic query. Verify query structure and parameters.";return new app_error_1.default(r,400)}function handleRelationLoadingError(e){const n=`Error loading relation "${e?.meta?.relation||"unknown relation"}". Ensure it is correctly defined and included in the query.`;return new app_error_1.default(n,400)}function handleBinaryError(e){const n=`Error with Prisma binary "${e?.meta?.binary||"unknown binary"}". Ensure the binary is properly installed and compatible.`;return new app_error_1.default(n,500)}function handleNetworkError(e){const r="Network error: Unable to connect to the database or internet. Please check your network connection.";return new app_error_1.default(r,500)}function handleUnhandledPromiseError(e){const r="Unhandled promise rejection detected. Please check asynchronous code for proper error handling.";return new app_error_1.default(r,500)}function handleDataTypeError(e){const r=e?.meta?.field||"unknown field",n=e?.meta?.expected_type||"unknown type",t=`Invalid data type for field "${r}". Expected type: ${n}.`;return new app_error_1.default(t,400)}function handleEmptyResultError(e){const r="Empty result: No data was found for the given query. Ensure the query criteria are correct.";return new app_error_1.default(r,404)}function handleNonExistingRecord(e){const r=e?.meta?.cause||"Operation could not be completed as the required record was not found";return new app_error_1.default(r,404,e.meta||{},"RecordNotFound")}function handlePrismaClientInitializationError(e){return new app_error_1.default("Service temporarily unavailable",503,{},"DatabaseNotAvailable")}
@@ -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;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,8CAIC;AAED,gDAGC;AAED,kEAGC;AAED,kDAKC;AAED,wDAGC;AAED,0DAQC;AArND,4DAAmC;AASnC,SAAgB,cAAc;IAC5B,OAAO,IAAI,mBAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,mBAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,mBAAQ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AuE,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"]}
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,8EAIC;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,8CAIC;AAED,gDAGC;AAED,kEAGC;AAED,kDAKC;AAED,wDAGC;AAED,0DAQC;AAED,sFAOC;AA/ND,4DAAmC;AASnC,SAAgB,cAAc;IAC5B,OAAO,IAAI,mBAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,mBAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GACX,GAAG,EAAE,OAAO,EAAE,KAAK,CAA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E,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,gBAAgB,CAAC,CAAC;AACtE,CAAC;AAED,SAAgB,qCAAqC,CAAC,CAAM;IAC1D,OAAO,IAAI,mBAAQ,CACjB,iCAAiC,EACjC,GAAG,EACH,EAAE,EACF,sBAAsB,CACvB,CAAC;AACJ,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 =\n err?.message?.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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(_: 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 || {}, \"RecordNotFound\");\n}\n\nexport function handlePrismaClientInitializationError(_: any) {\n return new AppError(\n \"Service temporarily unavailable\",\n 503,\n {},\n \"DatabaseNotAvailable\"\n );\n}\n"]}