arkos 1.2.13-beta → 1.2.13-test.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/dist/cjs/app.js +138 -1
  2. package/dist/cjs/app.js.map +1 -1
  3. package/dist/cjs/index.js +22 -0
  4. package/dist/cjs/modules/base/base.middlewares.js +4 -4
  5. package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
  6. package/dist/cjs/modules/swagger/swagger.router.js +62 -43
  7. package/dist/cjs/modules/swagger/swagger.router.js.map +1 -1
  8. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +82 -62
  9. package/dist/cjs/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +1 -1
  10. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +23 -16
  11. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +1 -1
  12. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +1 -1
  13. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +1 -1
  14. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +40 -11
  15. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +1 -1
  16. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +419 -9
  17. package/dist/cjs/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +1 -1
  18. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js +253 -0
  19. package/dist/cjs/modules/swagger/utils/helpers/missing-json-schemas-generator.js.map +1 -0
  20. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js +31 -20
  21. package/dist/cjs/modules/swagger/utils/helpers/swagger.router.helpers.js.map +1 -1
  22. package/dist/cjs/paths.js +9 -1
  23. package/dist/cjs/server.js +85 -5
  24. package/dist/cjs/server.js.map +1 -1
  25. package/dist/cjs/types/arkos-config.js.map +1 -1
  26. package/dist/cjs/utils/cli/dev.js +7 -7
  27. package/dist/cjs/utils/cli/dev.js.map +1 -1
  28. package/dist/cjs/utils/cli/start.js +4 -3
  29. package/dist/cjs/utils/cli/start.js.map +1 -1
  30. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +1 -1
  31. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-service-template.js +1 -1
  32. package/dist/cjs/utils/features/api.features.js +1 -1
  33. package/dist/cjs/utils/features/api.features.js.map +1 -1
  34. package/dist/cjs/utils/helpers/global.helpers.js.map +1 -1
  35. package/dist/cjs/utils/helpers/models.helpers.js +43 -21
  36. package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
  37. package/dist/cjs/utils/prisma/enhaced-prisma-json-schema-generator.js +451 -0
  38. package/dist/cjs/utils/prisma/enhaced-prisma-json-schema-generator.js.map +1 -0
  39. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js +88 -0
  40. package/dist/cjs/utils/prisma/prisma-json-schema-generator.js.map +1 -0
  41. package/dist/cjs/utils/prisma/prisma-schema-parser.js +158 -0
  42. package/dist/cjs/utils/prisma/prisma-schema-parser.js.map +1 -0
  43. package/dist/cjs/utils/prisma/types.js +3 -0
  44. package/dist/cjs/utils/prisma/types.js.map +1 -0
  45. package/dist/esm/index.d.mts +280 -0
  46. package/dist/esm/index.mjs +22 -0
  47. package/dist/exports/index.js +1 -0
  48. package/dist/types/arkos-config.js +1 -0
  49. package/dist/types/auth.js +1 -0
  50. package/dist/types/index.js +1 -0
  51. package/dist/types/modules/base/base.middlewares.d.ts +4 -4
  52. package/dist/types/modules/swagger/utils/helpers/get-authentication-json-schema-paths.d.ts +2 -1
  53. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.d.ts +2 -1
  54. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.d.ts +2 -1
  55. package/dist/types/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.d.ts +2 -1
  56. package/dist/types/modules/swagger/utils/helpers/missing-json-schemas-generator.d.ts +34 -0
  57. package/dist/types/modules/swagger/utils/helpers/swagger.router.helpers.d.ts +2 -2
  58. package/dist/types/router-config.js +1 -0
  59. package/dist/types/types/arkos-config.d.ts +3 -1
  60. package/dist/types/utils/helpers/models.helpers.d.ts +18 -4
  61. package/dist/types/utils/prisma/enhaced-prisma-json-schema-generator.d.ts +34 -0
  62. package/dist/types/utils/prisma/prisma-json-schema-generator.d.ts +10 -0
  63. package/dist/types/utils/prisma/prisma-schema-parser.d.ts +18 -0
  64. package/dist/types/utils/prisma/types.d.ts +48 -0
  65. package/dist/utils/arkos-env.js +1 -0
  66. package/dist/utils/dotenv.helpers.js +1 -0
  67. package/dist/utils/sheu.js +1 -0
  68. package/dist/utils/validate-dto.js +1 -0
  69. package/dist/utils/validate-schema.js +1 -0
  70. package/package.json +11 -6
  71. package/dist/esm/app.js +0 -1
  72. package/dist/esm/app.js.map +0 -1
  73. package/dist/esm/exports/auth/index.js +0 -2
  74. package/dist/esm/exports/auth/index.js.map +0 -1
  75. package/dist/esm/exports/controllers/index.js +0 -4
  76. package/dist/esm/exports/controllers/index.js.map +0 -1
  77. package/dist/esm/exports/error-handler/index.js +0 -4
  78. package/dist/esm/exports/error-handler/index.js.map +0 -1
  79. package/dist/esm/exports/index.js +0 -8
  80. package/dist/esm/exports/index.js.map +0 -1
  81. package/dist/esm/exports/middlewares/index.js +0 -2
  82. package/dist/esm/exports/middlewares/index.js.map +0 -1
  83. package/dist/esm/exports/prisma/index.js +0 -3
  84. package/dist/esm/exports/prisma/index.js.map +0 -1
  85. package/dist/esm/exports/services/index.js +0 -9
  86. package/dist/esm/exports/services/index.js.map +0 -1
  87. package/dist/esm/exports/utils/index.js +0 -4
  88. package/dist/esm/exports/utils/index.js.map +0 -1
  89. package/dist/esm/exports/validation/index.js +0 -4
  90. package/dist/esm/exports/validation/index.js.map +0 -1
  91. package/dist/esm/modules/auth/auth.controller.js +0 -187
  92. package/dist/esm/modules/auth/auth.controller.js.map +0 -1
  93. package/dist/esm/modules/auth/auth.router.js +0 -44
  94. package/dist/esm/modules/auth/auth.router.js.map +0 -1
  95. package/dist/esm/modules/auth/auth.service.js +0 -178
  96. package/dist/esm/modules/auth/auth.service.js.map +0 -1
  97. package/dist/esm/modules/auth/utils/helpers/auth.controller.helpers.js +0 -73
  98. package/dist/esm/modules/auth/utils/helpers/auth.controller.helpers.js.map +0 -1
  99. package/dist/esm/modules/base/base.controller.js +0 -150
  100. package/dist/esm/modules/base/base.controller.js.map +0 -1
  101. package/dist/esm/modules/base/base.middlewares.js +0 -81
  102. package/dist/esm/modules/base/base.middlewares.js.map +0 -1
  103. package/dist/esm/modules/base/base.router.js +0 -17
  104. package/dist/esm/modules/base/base.router.js.map +0 -1
  105. package/dist/esm/modules/base/base.service.js +0 -120
  106. package/dist/esm/modules/base/base.service.js.map +0 -1
  107. package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js +0 -77
  108. package/dist/esm/modules/base/utils/helpers/base.controller.helpers.js.map +0 -1
  109. package/dist/esm/modules/base/utils/helpers/base.middlewares.helpers.js +0 -44
  110. package/dist/esm/modules/base/utils/helpers/base.middlewares.helpers.js.map +0 -1
  111. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js +0 -89
  112. package/dist/esm/modules/base/utils/helpers/base.router.helpers.js.map +0 -1
  113. package/dist/esm/modules/base/utils/helpers/base.service.helpers.js +0 -165
  114. package/dist/esm/modules/base/utils/helpers/base.service.helpers.js.map +0 -1
  115. package/dist/esm/modules/email/email.service.js +0 -97
  116. package/dist/esm/modules/email/email.service.js.map +0 -1
  117. package/dist/esm/modules/error-handler/error-handler.controller.js +0 -107
  118. package/dist/esm/modules/error-handler/error-handler.controller.js.map +0 -1
  119. package/dist/esm/modules/error-handler/utils/app-error.js +0 -15
  120. package/dist/esm/modules/error-handler/utils/app-error.js.map +0 -1
  121. package/dist/esm/modules/error-handler/utils/catch-async.js +0 -10
  122. package/dist/esm/modules/error-handler/utils/catch-async.js.map +0 -1
  123. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js +0 -160
  124. package/dist/esm/modules/error-handler/utils/error-handler.helpers.js.map +0 -1
  125. package/dist/esm/modules/file-upload/file-upload.controller.js +0 -266
  126. package/dist/esm/modules/file-upload/file-upload.controller.js.map +0 -1
  127. package/dist/esm/modules/file-upload/file-upload.router.js +0 -38
  128. package/dist/esm/modules/file-upload/file-upload.router.js.map +0 -1
  129. package/dist/esm/modules/file-upload/file-upload.service.js +0 -314
  130. package/dist/esm/modules/file-upload/file-upload.service.js.map +0 -1
  131. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js +0 -87
  132. package/dist/esm/modules/file-upload/utils/helpers/file-upload.helpers.js.map +0 -1
  133. package/dist/esm/modules/swagger/swagger.router.js +0 -94
  134. package/dist/esm/modules/swagger/swagger.router.js.map +0 -1
  135. package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js +0 -247
  136. package/dist/esm/modules/swagger/utils/helpers/get-authentication-json-schema-paths.js.map +0 -1
  137. package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js +0 -63
  138. package/dist/esm/modules/swagger/utils/helpers/get-system-json-schema-paths.js.map +0 -1
  139. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js +0 -38
  140. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-class-validator-json-schemas.js.map +0 -1
  141. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js +0 -19
  142. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-prisma-json-schemas.js.map +0 -1
  143. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js +0 -24
  144. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/generate-zod-json-schema.js.map +0 -1
  145. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js +0 -436
  146. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-main-routes.js.map +0 -1
  147. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js +0 -159
  148. package/dist/esm/modules/swagger/utils/helpers/json-schema-generators/prisma-models/generate-prisma-model-parent-routes.js.map +0 -1
  149. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js +0 -84
  150. package/dist/esm/modules/swagger/utils/helpers/swagger.router.helpers.js.map +0 -1
  151. package/dist/esm/paths.js +0 -1
  152. package/dist/esm/paths.js.map +0 -1
  153. package/dist/esm/server.js +0 -5
  154. package/dist/esm/server.js.map +0 -1
  155. package/dist/esm/types/arkos-config.js +0 -2
  156. package/dist/esm/types/arkos-config.js.map +0 -1
  157. package/dist/esm/types/auth.js +0 -2
  158. package/dist/esm/types/auth.js.map +0 -1
  159. package/dist/esm/types/index.js +0 -8
  160. package/dist/esm/types/index.js.map +0 -1
  161. package/dist/esm/types/router-config.js +0 -2
  162. package/dist/esm/types/router-config.js.map +0 -1
  163. package/dist/esm/utils/arkos-env.js +0 -7
  164. package/dist/esm/utils/arkos-env.js.map +0 -1
  165. package/dist/esm/utils/cli/build.js +0 -206
  166. package/dist/esm/utils/cli/build.js.map +0 -1
  167. package/dist/esm/utils/cli/dev.js +0 -249
  168. package/dist/esm/utils/cli/dev.js.map +0 -1
  169. package/dist/esm/utils/cli/generate.js +0 -183
  170. package/dist/esm/utils/cli/generate.js.map +0 -1
  171. package/dist/esm/utils/cli/index.js +0 -74
  172. package/dist/esm/utils/cli/index.js.map +0 -1
  173. package/dist/esm/utils/cli/start.js +0 -86
  174. package/dist/esm/utils/cli/start.js.map +0 -1
  175. package/dist/esm/utils/cli/utils/cli.helpers.js +0 -16
  176. package/dist/esm/utils/cli/utils/cli.helpers.js.map +0 -1
  177. package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js +0 -33
  178. package/dist/esm/utils/cli/utils/template-generator/templates/generate-auth-configs-template.js.map +0 -1
  179. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js +0 -18
  180. package/dist/esm/utils/cli/utils/template-generator/templates/generate-controller-template.js.map +0 -1
  181. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js +0 -232
  182. package/dist/esm/utils/cli/utils/template-generator/templates/generate-middlewares.js.map +0 -1
  183. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js +0 -61
  184. package/dist/esm/utils/cli/utils/template-generator/templates/generate-prisma-query-options.js.map +0 -1
  185. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js +0 -37
  186. package/dist/esm/utils/cli/utils/template-generator/templates/generate-router-template.js.map +0 -1
  187. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js +0 -32
  188. package/dist/esm/utils/cli/utils/template-generator/templates/generate-service-template.js.map +0 -1
  189. package/dist/esm/utils/cli/utils/template-generators.js +0 -25
  190. package/dist/esm/utils/cli/utils/template-generators.js.map +0 -1
  191. package/dist/esm/utils/dotenv.helpers.js +0 -37
  192. package/dist/esm/utils/dotenv.helpers.js.map +0 -1
  193. package/dist/esm/utils/features/api.features.js +0 -160
  194. package/dist/esm/utils/features/api.features.js.map +0 -1
  195. package/dist/esm/utils/features/change-case.features.js +0 -31
  196. package/dist/esm/utils/features/change-case.features.js.map +0 -1
  197. package/dist/esm/utils/helpers/api.features.helpers.js +0 -103
  198. package/dist/esm/utils/helpers/api.features.helpers.js.map +0 -1
  199. package/dist/esm/utils/helpers/change-case.helpers.js +0 -161
  200. package/dist/esm/utils/helpers/change-case.helpers.js.map +0 -1
  201. package/dist/esm/utils/helpers/deepmerge.helper.js +0 -113
  202. package/dist/esm/utils/helpers/deepmerge.helper.js.map +0 -1
  203. package/dist/esm/utils/helpers/fs.helpers.js +0 -52
  204. package/dist/esm/utils/helpers/fs.helpers.js.map +0 -1
  205. package/dist/esm/utils/helpers/global.helpers.js +0 -47
  206. package/dist/esm/utils/helpers/global.helpers.js.map +0 -1
  207. package/dist/esm/utils/helpers/models.helpers.js +0 -300
  208. package/dist/esm/utils/helpers/models.helpers.js.map +0 -1
  209. package/dist/esm/utils/helpers/prisma.helpers.js +0 -44
  210. package/dist/esm/utils/helpers/prisma.helpers.js.map +0 -1
  211. package/dist/esm/utils/helpers/query-parser.helpers.js +0 -40
  212. package/dist/esm/utils/helpers/query-parser.helpers.js.map +0 -1
  213. package/dist/esm/utils/helpers/routers.helpers.js +0 -16
  214. package/dist/esm/utils/helpers/routers.helpers.js.map +0 -1
  215. package/dist/esm/utils/helpers/text.helpers.js +0 -22
  216. package/dist/esm/utils/helpers/text.helpers.js.map +0 -1
  217. package/dist/esm/utils/sheu.js +0 -117
  218. package/dist/esm/utils/sheu.js.map +0 -1
  219. package/dist/esm/utils/validate-dto.js +0 -11
  220. package/dist/esm/utils/validate-dto.js.map +0 -1
  221. package/dist/esm/utils/validate-schema.js +0 -9
  222. package/dist/esm/utils/validate-schema.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"arkos-config.js","sourceRoot":"","sources":["../../../src/types/arkos-config.ts"],"names":[],"mappings":"","sourcesContent":["import http from \"http\";\nimport cors from \"cors\";\nimport express from \"express\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport cookieParser from \"cookie-parser\";\nimport compression from \"compression\";\nimport { Options as QueryParserOptions } from \"../utils/helpers/query-parser.helpers\";\nimport { ValidatorOptions } from \"class-validator\";\nimport { MsDuration } from \"../modules/auth/utils/helpers/auth.controller.helpers\";\nimport { OpenAPIV3 } from \"openapi-types\";\n\n/**\n * Defines the initial configs of the api to be loaded at startup when arkos.init() is called.\n */\nexport type ArkosConfig = {\n /**\n * Allows to configure request configs\n */\n request?: {\n /**\n * Allows to configure request parameters\n */\n parameters?: {\n /**\n * Toggles allowing `VERY DANGEROUS` request paramateres under `req.query` for passing prisma query options.\n *\n * See more\n */\n allowDangerousPrismaQueryOptions?: boolean;\n };\n };\n /** Message you would like to send, as Json and 200 response when\n * ```curl\n * GET /api\n * ```\n *\n * ```json\n * { \"message\": \"Welcome to YourAppName\" }\n * ```\n *\n * default message is: Welcome to our Rest API generated by Arkos, find more about Arkos at www.arkosjs.com.\n *\n *\n * */\n welcomeMessage?: string;\n /**\n * Port where the application will run, can be set in 3 ways:\n *\n * 1. default is 8000\n * 2. PORT under environment variables (Lower precedence)\n * 3. this config option (Higher precedence)\n */\n port?: number | undefined;\n /**\n * Allows to listen on a different host than localhost only\n */\n host?: string;\n /**\n * Defines authentication related configurations, by default is undefined.\n *\n * See [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for details.\n */\n authentication?: {\n /**\n * Defines whether to use Static or Dynamic Role-Based Acess Control\n *\n * Visit [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for more details.\n */\n mode: \"static\" | \"dynamic\";\n /**\n * Defines auth login related configurations to customize the api.\n */\n login?: {\n /**\n * Defines the field that will be used as username by the built-in auth system, by default arkos will look for the field \"username\" in your model User, hence when making login for example you must send:\n *\n * ```json\n * {\n * \"username\": \"johndoe\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n *\n * **Note:** You can also modify the usernameField on the fly by passing it to the request query parameters. example:\n *\n * ```curl\n * POST /api/auth/login?usernameField=email\n * ```\n *\n * See more at [www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n * By specifing here another field for username, for example passing \"email\", \"companyCode\" or something else your json will be like:\n *\n * **Example with email**\n *\n * ```json\n * {\n * \"email\": \"john.doe@example.com\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n */\n allowedUsernames?: string[];\n /** Defines wether to send the access token in response after login or only send as cookie, defeault is both.*/\n sendAccessTokenThrough?: \"cookie-only\" | \"response-only\" | \"both\";\n };\n /**\n * Specifies the regex pattern used by the authentication system to enforce password strength requirements.\n *\n * **Important**: If using validation libraries like Zod or class-validator, this will be completely overwritten.\n *\n * **Default**: ```/^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/``` - Ensures the password contains at least one uppercase letter, one lowercase letter, and one numeric digit.\n *\n * **message**: (Optional) A custom error message to display when the password does not meet the required strength criteria.\n */\n passwordValidation?: { regex: RegExp; message?: string };\n /**\n * Allows to specify the request rate limit for all authentication endpoints but `/api/users/me`.\n * \n * #### Default\n *{\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n *@see This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n requestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * JWT (JSON Web Token) authentication configuration.\n *\n * You can override these values directly in code, or use environment variables:\n *\n * - `JWT_SECRET`: Secret used to sign and verify JWT tokens.\n * - `JWT_EXPIRES_IN`: Duration string or number indicating when the token should expire (e.g. \"30d\", 3600).\n * - `JWT_COOKIE_SECURE`: Whether the cookie is sent only over HTTPS. Default: `true` in production.\n * - `JWT_COOKIE_HTTP_ONLY`: Whether the cookie is HTTP-only. Default: `true`.\n * - `JWT_COOKIE_SAME_SITE`: Can be \"lax\", \"strict\", or \"none\". Defaults to \"lax\" in dev, \"none\" in prod.\n *\n * ⚠️ Values passed here take precedence over environment variables.\n */\n jwt?: {\n /** Secret key used for signing and verifying JWT tokens */\n secret?: string;\n /**\n * Duration after which the JWT token expires.\n * Accepts either a duration string (e.g. \"30d\", \"1h\") or a number in milliseconds.\n * Defaults to \"30d\" if not provided.\n */\n expiresIn?: MsDuration | number;\n\n /**\n * Configuration for the JWT cookie sent to the client\n */\n cookie?: {\n /**\n * Whether the cookie should be marked as secure (sent only over HTTPS).\n * Defaults to `true` in production and `false` in development.\n */\n secure?: boolean;\n\n /**\n * Whether the cookie should be marked as HTTP-only.\n * Default is `true` to prevent access via JavaScript.\n */\n httpOnly?: boolean;\n\n /**\n * Controls the SameSite attribute of the cookie.\n * Defaults to \"none\" in production and \"lax\" in development.\n * Options: \"lax\" | \"strict\" | \"none\"\n */\n sameSite?: \"lax\" | \"strict\" | \"none\";\n };\n };\n };\n /** Allows to customize and toggle the built-in validation, by default it is set to `false`. If true is passed it will use validation with the default resolver set to `class-validator` if you intend to change the resolver to `zod` do the following:\n *\n *```ts\n * // src/app.ts\n * import arkos from 'arkos'\n *\n * arkos.init({\n * validation: {\n * resolver: \"zod\"\n * }\n * })\n * ```\n *\n * @See [www.arkosjs.com/docs/core-concepts/request-data-validation](https://www.arkosjs.com/docs/core-concepts/request-data-validation) for more details.\n */\n validation?:\n | {\n resolver?: \"class-validator\";\n /**\n * ValidatorOptions to used while validating request data.\n *\n * **Default**:\n * ```ts\n * {\n * whitelist: true\n * }\n * ```\n */\n validationOptions?: ValidatorOptions;\n }\n | {\n resolver?: \"zod\";\n validationOptions?: Record<string, any>;\n };\n /**\n * Defines file upload configurations\n *\n * See [www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations](https://www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations)\n */\n fileUpload?: {\n /**\n * Defiens the base file upload directory, default is set to /uploads (on root directory)\n *\n * When setting up a path dir always now that root directory will be the starting reference.\n *\n * #### Example\n * passing `../my-arkos-uploaded-files`\n *\n * Will save uploaded files one level outside the root dir inside `my-arkos-uploaded-files`\n *\n * NB: You must be aware of permissions on your server to acess files outside your project directory.\n *\n */\n baseUploadDir?: string;\n /**\n * Changes the default `/api/uploads` base route for accessing file upload route.\n *\n * #### IMPORTANT\n * Changing this will not affect the `baseUploadDir` folder. You can\n * pass here `/api/files/my-user-files` and `baseUploadDir` be `/uploaded-files`.\n *\n */\n baseRoute?: string;\n /**\n * Defines options for `express.static(somePath, someOptions)`\n *\n * #### Default:\n *\n * ```ts\n *{\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n }\n * ```\n * \n * By passing your custom options have in mind that it\n * will be deepmerged with the default.\n * \n * Visit [https://expressjs.com/en/4x/api.html#express.static](https://expressjs.com/en/4x/api.html#express.static) for more understanding.\n * \n */\n expressStaticOptions?: Parameters<typeof express.static>[1];\n /**\n * Defines upload restrictions for each file type: image, video, document or other.\n *\n * #### Important:\n * Passing an object without overriding everything will only cause it\n * to be deepmerged with the default options.\n *\n * See [www.arkosjs.com/docs/api-reference/default-supported-upload-files](https://www.arkosjs.com/docs/api-reference/default-supported-upload-files) for detailed explanation about default values.\n * ```\n */\n restrictions?: {\n images?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n videos?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n documents?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n files?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n };\n };\n /**\n * Allows to specify the request rate limit for all endpoints.\n * \n * #### Default\n *```ts\n *{\n windowMs: 60 * 1000,\n limit: 1000,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n ```\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n globalRequestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * Defines options for the built-in express.json() middleware\n * Nothing is passed by default.\n */\n jsonBodyParserOptions?: Parameters<typeof express.json>[0];\n /**\n * Allows to pass paremeters to cookieParser from npm package cookie-parser\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/cookie-parser](https://www.npmjs.com/package/cookie-parser) for further details.\n */\n cookieParserParameters?: Parameters<typeof cookieParser>;\n /**\n * Allows to define options for npm package compression\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/compression](https://www.npmjs.com/package/compression) for further details.\n */\n compressionOptions?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * #### for example:\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n * \n * #### Default:\n * \n * {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n }\n * \n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n * \n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParserOptions?: QueryParserOptions;\n /**\n * Configuration for CORS (Cross-Origin Resource Sharing).\n *\n * @property {string | string[] | \"all\"} [allowedOrigins] - List of allowed origins. If set to `\"all\"`, all origins are accepted.\n * @property {import('cors').CorsOptions} [options] - Additional CORS options passed directly to the `cors` middleware.\n * @property {import('cors').CorsOptionsDelegate} [customMiddleware] - A custom middleware function that overrides the default behavior.\n *\n * @remarks\n * If `customMiddleware` is provided, both `allowedOrigins` and `options` will be ignored in favor of the custom logic.\n *\n * See https://www.npmjs.com/package/cors\n */\n cors?: {\n /**\n * Defines allowed origins to acess the API.\n */\n allowedOrigins?: string | string[] | \"*\";\n options?: cors.CorsOptions;\n /**\n * If you would like to override the entire middleware\n *\n * see\n */\n customHandler?: cors.CorsOptionsDelegate;\n };\n /**\n * Defines express/arkos middlewares configurations\n */\n middlewares?: {\n /**\n * Allows to add an array of custom express middlewares into the default middleware stack.\n *\n * **Tip**: If you would like to acess the express app before everthing use `configureApp` and pass a function.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order](https://www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order)\n *\n * **Note**: If you want to use custom global error handler middleware use `middlewares.replace.globalErrorHandler`.\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.RequestHandler[];\n /**\n * An array containing a list of defaults middlewares to be disabled\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n disable?: (\n | \"compression\"\n | \"global-rate-limit\"\n | \"auth-rate-limit\"\n | \"cors\"\n | \"express-json\"\n | \"cookie-parser\"\n | \"query-parser\"\n | \"database-connection\"\n | \"request-logger\"\n | \"global-error-handler\"\n )[];\n /**\n * Allows you to replace each of the built-in middlewares with your own implementation\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default compression middleware\n */\n compression?: express.RequestHandler;\n /**\n * Replace the default global rate limit middleware\n */\n globalRateLimit?: express.RequestHandler;\n /**\n * Replace the default authentication rate limit middleware\n */\n authRateLimit?: express.RequestHandler;\n /**\n * Replace the default CORS middleware\n */\n cors?: express.RequestHandler;\n /**\n * Replace the default JSON body parser middleware\n */\n expressJson?: express.RequestHandler;\n /**\n * Replace the default cookie parser middleware\n */\n cookieParser?: express.RequestHandler;\n /**\n * Replace the default query parser middleware\n */\n queryParser?: express.RequestHandler;\n /**\n * Replace the default database connection check middleware\n */\n databaseConnection?: express.RequestHandler;\n /**\n * Replace the default request logger middleware\n */\n requestLogger?: express.RequestHandler;\n /**\n * Replace the default global error handler middleware\n */\n globalErrorHandler?: express.ErrorRequestHandler;\n };\n };\n /**\n * Defines express/arkos routers configurations\n */\n routers?: {\n /**\n * Allows to add an array of custom express routers into the default middleware/router stack.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/adding-custom-routers](https://www.arkosjs.com/docs/advanced-guide/adding-custom-routers)\n *\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.Router[];\n disable?: (\n | \"auth-router\"\n | \"prisma-models-router\"\n | \"file-upload\"\n | \"welcome-endpoint\"\n )[];\n /**\n * Allows you to replace each of the built-in routers with your own implementation.\n *\n * **Note**: Doing this you will lose all default middleware chaining, auth control, handlers from the specific router.\n *\n * **Tip**: I you want to disable some prisma models specific endpoint\n * see [www.arkosjs.com/docs/guide/adding-custom-routers#disabling-auto-generated-endpoints](https://www.arkosjs.com/docs/guide/adding-custom-routers#disabling-auto-generated-endpoints)\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default authentication router\n * @param config The original Arkos configuration\n * @returns A router handling authentication endpoints\n */\n authRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default Prisma models router\n * @param config The original Arkos configuration\n * @returns A router handling Prisma model endpoints\n */\n prismaModelsRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default file upload router\n * @param config The original Arkos configuration\n * @returns A router handling file upload endpoints\n */\n fileUpload?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default welcome endpoint handler\n * @param req Express request object\n * @param res Express response object\n * @param next Express next function\n */\n welcomeEndpoint?: express.RequestHandler;\n };\n };\n /**\n * Gives acess to the underlying express app so that you can add custom configurations beyong **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `app.listen` for you.\n *\n * If you want to call `app.listen` by yourself pass port as `undefined` and then use the return app from `arkos.init()`.\n *\n * See how to call `app.listen` correctly [www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself](https://www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself)\n *\n * See [www.arkosjs.com/docs/guide/accessing-the-express-app](https://www.arkosjs.com/docs/guide/accessing-the-express-app) for further details on the method configureApp.\n *\n * @param {express.Express} app\n * @returns {any}\n */\n configureApp?: (app: express.Express) => Promise<any> | any;\n /**\n * Gives access to the underlying HTTP server so that you can add custom configurations beyond **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `server.listen` for you.\n *\n * If you want to call `server.listen` by yourself pass port as `undefined` and then use the return server from `arkos.init()`.\n *\n * See how to call `server.listen` correctly [www.arkosjs.com/docs/guide/accessing-the-express-app#creating-your-own-http-server](https://www.arkosjs.com/docs/guide/accessing-the-express-app#creating-your-own-http-server)\n *\n * See [www.arkosjs.com/docs/guide/accessing-the-express-app#accessing-the-http-server](https://www.arkosjs.com/docs/guide/accessing-the-express-app#accessing-the-http-server) for further details on the method configureServer.\n *\n * @param {http.Server} server - The HTTP server instance\n * @returns {any}\n */\n configureServer?: (server: http.Server) => Promise<any> | any;\n /**\n * Allows to configure email configurations for sending emails through `emailService`\n *\n * See [www.arkosjs.com/docs/core-concepts/sending-emails](https://www.arkosjs.com/docs/core-concepts/sending-emails)\n */\n email?: {\n /**\n * Your email provider url\n */\n host: string;\n /**\n * Email provider SMTP port, Default is `465`\n */\n port?: number;\n /**\n * If smtp connection must be secure, Default is `true`\n */\n secure?: boolean;\n /**\n * Used to authenticate in your smtp server\n */\n auth: {\n /**\n * Email used for auth as well as sending emails\n */\n user: string;\n /**\n * Your SMTP password\n */\n pass: string;\n };\n /**\n * Email name to used like:\n *\n * John Doe\\<john.doe@gmail.com>\n */\n name?: string;\n };\n /**\n * Defines Swagger and OpenApi specifications for auto generating swagger documentation UI using whether it is Prisma Schemas, Class-validator DTOs, Zod Schemas or JSON-Schemas\n *\n * **Usage**\n *\n * ```ts\n * // src/app.ts\n *\n * import arkos from \"arkos\"\n *\n * arkos.init({\n * // other configs\n * swagger: {\n * mode: \"zod\",\n * options: {\n * openapi: \"3.0.0\",\n * title: \"API Generated By Arkos.js\",\n * description: \"This API was automatically generated by Arkos.js read more about at www.arkosjs.com\"\n * }\n * }\n * })\n * ```\n * @see {@link https://www.arkosjs.com/docs/core-concepts/swagger-api-documentation}\n */\n swagger?: {\n /**\n * By default Arkos will disable API Documentation when the project is built `npm run build`, it does not matter what node environment is set. If you want to use it even after the `arkos build` command just set this to `true`.\n * */\n enableAfterBuild?: boolean;\n /**\n * Endpoint where the Swagger UI will be available.\n *\n * @default \"/api/api-docs\"\n */\n endpoint?: string;\n /**\n * Determines how your API schemas should be generated.\n *\n * - \"prisma\": Generates schemas based on Prisma models\n * - \"class-validator\": Uses class-validator and class-transformer DTO classes\n * - \"zod\": Uses OpenAPI-compliant schemas directly\n */\n mode: \"prisma\" | \"class-validator\" | \"zod\";\n /**\n *\n */\n options?: {\n /**\n * Swagger definition according to OpenAPI Specification.\n */\n definition?: {\n /**\n * OpenAPI version.\n *\n * @default \"3.0.0\"\n */\n openapi?: string;\n\n /**\n * Information about your API.\n */\n info?: {\n /**\n * Title of the API documentation.\n *\n *\n * @example \"My API\"\n *\n * @default \"API Generated By Arkos.js\"\n */\n title?: string;\n\n /**\n * Version of the API.\n *\n * @example \"1.0.0\"\n */\n version?: string;\n\n /**\n * Description of the API.\n *\n * @default \"This API was automatically generated by Arkos.js read more about at www.arkosjs.com\"\n */\n description?: string;\n };\n\n /**\n * Server configurations for the API.\n *\n * @default [{ url: \"http://localhost:8000\", description: \"Development server\" }]\n *\n * This can be overridden automatically by Arkos based on CLI, .env, or `arkos.init()`.\n */\n servers?: {\n /**\n * Base URL of the server.\n *\n * @example \"http://localhost:8000\"\n */\n url: string;\n\n /**\n * Human-readable description of the server.\n *\n * @example \"Development Server\"\n */\n description?: string;\n }[];\n /**\n * Allows adding more paths for your OpenAPI documentation\n *\n * */\n paths?: OpenAPIV3.PathsObject;\n /**\n * (Optional) Additional metadata such as terms of service, contact, or license.\n *\n * See: https://swagger.io/specification/#infoObject\n */\n termsOfService?: string;\n contact?: {\n name?: string;\n url?: string;\n email?: string;\n };\n license?: {\n name: string;\n url?: string;\n };\n\n /**\n * Tags to group and describe endpoints.\n */\n tags?: {\n name: string;\n description?: string;\n }[];\n\n /**\n * Security definitions (e.g., Bearer Auth).\n */\n components?: {\n securitySchemes?: Record<string, any>;\n schemas?: Record<string, any>;\n };\n\n /**\n * Global security requirements.\n */\n security?: Array<Record<string, string[]>>;\n };\n\n /**\n * Glob patterns defining where Swagger should look for API route definitions and comments.\n *\n * @default \n * ```ts\n * [\"./src/routers/*.router.{ts,js}\", \"./src/modules/**\\/*.router.{ts,js}\"]\n ```\n *\n * Adjust depending on TypeScript or JavaScript usage.\n */\n apis?: string[];\n\n /**\n * Custom Swagger UI options.\n *\n * See: https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md\n */\n swaggerUiOptions?: Record<string, any>;\n\n /**\n * Enables deep linking in the Swagger UI.\n *\n * @default true\n */\n deepLinking?: boolean;\n\n /**\n * Enable/disable the \"Try it out\" button globally.\n *\n * @default true\n */\n tryItOutEnabled?: boolean;\n\n /**\n * Whether to persist authorization data across page reloads.\n *\n * @default false\n */\n persistAuthorization?: boolean;\n };\n };\n};\n"]}
1
+ {"version":3,"file":"arkos-config.js","sourceRoot":"","sources":["../../../src/types/arkos-config.ts"],"names":[],"mappings":"","sourcesContent":["import http from \"http\";\nimport cors from \"cors\";\nimport express from \"express\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport cookieParser from \"cookie-parser\";\nimport compression from \"compression\";\nimport { Options as QueryParserOptions } from \"../utils/helpers/query-parser.helpers\";\nimport { ValidatorOptions } from \"class-validator\";\nimport { MsDuration } from \"../modules/auth/utils/helpers/auth.controller.helpers\";\nimport { OpenAPIV3 } from \"openapi-types\";\nimport type { ApiReferenceConfiguration } from \"@scalar/express-api-reference\" with { \"resolution-mode\": \"import\" };\n\n/**\n * Defines the initial configs of the api to be loaded at startup when arkos.init() is called.\n */\nexport type ArkosConfig = {\n /**\n * Allows to configure request configs\n */\n request?: {\n /**\n * Allows to configure request parameters\n */\n parameters?: {\n /**\n * Toggles allowing `VERY DANGEROUS` request paramateres under `req.query` for passing prisma query options.\n *\n * See more\n */\n allowDangerousPrismaQueryOptions?: boolean;\n };\n };\n /** Message you would like to send, as Json and 200 response when\n * ```curl\n * GET /api\n * ```\n *\n * ```json\n * { \"message\": \"Welcome to YourAppName\" }\n * ```\n *\n * default message is: Welcome to our Rest API generated by Arkos, find more about Arkos at www.arkosjs.com.\n *\n *\n * */\n welcomeMessage?: string;\n /**\n * Port where the application will run, can be set in 3 ways:\n *\n * 1. default is 8000\n * 2. PORT under environment variables (Lower precedence)\n * 3. this config option (Higher precedence)\n */\n port?: number | undefined;\n /**\n * Allows to listen on a different host than localhost only\n */\n host?: string;\n /**\n * Defines authentication related configurations, by default is undefined.\n *\n * See [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for details.\n */\n authentication?: {\n /**\n * Defines whether to use Static or Dynamic Role-Based Acess Control\n *\n * Visit [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for more details.\n */\n mode: \"static\" | \"dynamic\";\n /**\n * Defines auth login related configurations to customize the api.\n */\n login?: {\n /**\n * Defines the field that will be used as username by the built-in auth system, by default arkos will look for the field \"username\" in your model User, hence when making login for example you must send:\n *\n * ```json\n * {\n * \"username\": \"johndoe\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n *\n * **Note:** You can also modify the usernameField on the fly by passing it to the request query parameters. example:\n *\n * ```curl\n * POST /api/auth/login?usernameField=email\n * ```\n *\n * See more at [www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n * By specifing here another field for username, for example passing \"email\", \"companyCode\" or something else your json will be like:\n *\n * **Example with email**\n *\n * ```json\n * {\n * \"email\": \"john.doe@example.com\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n */\n allowedUsernames?: string[];\n /** Defines wether to send the access token in response after login or only send as cookie, defeault is both.*/\n sendAccessTokenThrough?: \"cookie-only\" | \"response-only\" | \"both\";\n };\n /**\n * Specifies the regex pattern used by the authentication system to enforce password strength requirements.\n *\n * **Important**: If using validation libraries like Zod or class-validator, this will be completely overwritten.\n *\n * **Default**: ```/^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/``` - Ensures the password contains at least one uppercase letter, one lowercase letter, and one numeric digit.\n *\n * **message**: (Optional) A custom error message to display when the password does not meet the required strength criteria.\n */\n passwordValidation?: { regex: RegExp; message?: string };\n /**\n * Allows to specify the request rate limit for all authentication endpoints but `/api/users/me`.\n * \n * #### Default\n *{\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n *@see This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n requestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * JWT (JSON Web Token) authentication configuration.\n *\n * You can override these values directly in code, or use environment variables:\n *\n * - `JWT_SECRET`: Secret used to sign and verify JWT tokens.\n * - `JWT_EXPIRES_IN`: Duration string or number indicating when the token should expire (e.g. \"30d\", 3600).\n * - `JWT_COOKIE_SECURE`: Whether the cookie is sent only over HTTPS. Default: `true` in production.\n * - `JWT_COOKIE_HTTP_ONLY`: Whether the cookie is HTTP-only. Default: `true`.\n * - `JWT_COOKIE_SAME_SITE`: Can be \"lax\", \"strict\", or \"none\". Defaults to \"lax\" in dev, \"none\" in prod.\n *\n * ⚠️ Values passed here take precedence over environment variables.\n */\n jwt?: {\n /** Secret key used for signing and verifying JWT tokens */\n secret?: string;\n /**\n * Duration after which the JWT token expires.\n * Accepts either a duration string (e.g. \"30d\", \"1h\") or a number in milliseconds.\n * Defaults to \"30d\" if not provided.\n */\n expiresIn?: MsDuration | number;\n\n /**\n * Configuration for the JWT cookie sent to the client\n */\n cookie?: {\n /**\n * Whether the cookie should be marked as secure (sent only over HTTPS).\n * Defaults to `true` in production and `false` in development.\n */\n secure?: boolean;\n\n /**\n * Whether the cookie should be marked as HTTP-only.\n * Default is `true` to prevent access via JavaScript.\n */\n httpOnly?: boolean;\n\n /**\n * Controls the SameSite attribute of the cookie.\n * Defaults to \"none\" in production and \"lax\" in development.\n * Options: \"lax\" | \"strict\" | \"none\"\n */\n sameSite?: \"lax\" | \"strict\" | \"none\";\n };\n };\n };\n /** Allows to customize and toggle the built-in validation, by default it is set to `false`. If true is passed it will use validation with the default resolver set to `class-validator` if you intend to change the resolver to `zod` do the following:\n *\n *```ts\n * // src/app.ts\n * import arkos from 'arkos'\n *\n * arkos.init({\n * validation: {\n * resolver: \"zod\"\n * }\n * })\n * ```\n *\n * @See [www.arkosjs.com/docs/core-concepts/request-data-validation](https://www.arkosjs.com/docs/core-concepts/request-data-validation) for more details.\n */\n validation?:\n | {\n resolver?: \"class-validator\";\n /**\n * ValidatorOptions to used while validating request data.\n *\n * **Default**:\n * ```ts\n * {\n * whitelist: true\n * }\n * ```\n */\n validationOptions?: ValidatorOptions;\n }\n | {\n resolver?: \"zod\";\n validationOptions?: Record<string, any>;\n };\n /**\n * Defines file upload configurations\n *\n * See [www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations](https://www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations)\n */\n fileUpload?: {\n /**\n * Defiens the base file upload directory, default is set to /uploads (on root directory)\n *\n * When setting up a path dir always now that root directory will be the starting reference.\n *\n * #### Example\n * passing `../my-arkos-uploaded-files`\n *\n * Will save uploaded files one level outside the root dir inside `my-arkos-uploaded-files`\n *\n * NB: You must be aware of permissions on your server to acess files outside your project directory.\n *\n */\n baseUploadDir?: string;\n /**\n * Changes the default `/api/uploads` base route for accessing file upload route.\n *\n * #### IMPORTANT\n * Changing this will not affect the `baseUploadDir` folder. You can\n * pass here `/api/files/my-user-files` and `baseUploadDir` be `/uploaded-files`.\n *\n */\n baseRoute?: string;\n /**\n * Defines options for `express.static(somePath, someOptions)`\n *\n * #### Default:\n *\n * ```ts\n *{\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n }\n * ```\n * \n * By passing your custom options have in mind that it\n * will be deepmerged with the default.\n * \n * Visit [https://expressjs.com/en/4x/api.html#express.static](https://expressjs.com/en/4x/api.html#express.static) for more understanding.\n * \n */\n expressStaticOptions?: Parameters<typeof express.static>[1];\n /**\n * Defines upload restrictions for each file type: image, video, document or other.\n *\n * #### Important:\n * Passing an object without overriding everything will only cause it\n * to be deepmerged with the default options.\n *\n * See [www.arkosjs.com/docs/api-reference/default-supported-upload-files](https://www.arkosjs.com/docs/api-reference/default-supported-upload-files) for detailed explanation about default values.\n * ```\n */\n restrictions?: {\n images?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n videos?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n documents?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n files?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n };\n };\n /**\n * Allows to specify the request rate limit for all endpoints.\n * \n * #### Default\n *```ts\n *{\n windowMs: 60 * 1000,\n limit: 1000,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n ```\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n globalRequestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * Defines options for the built-in express.json() middleware\n * Nothing is passed by default.\n */\n jsonBodyParserOptions?: Parameters<typeof express.json>[0];\n /**\n * Allows to pass paremeters to cookieParser from npm package cookie-parser\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/cookie-parser](https://www.npmjs.com/package/cookie-parser) for further details.\n */\n cookieParserParameters?: Parameters<typeof cookieParser>;\n /**\n * Allows to define options for npm package compression\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/compression](https://www.npmjs.com/package/compression) for further details.\n */\n compressionOptions?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * #### for example:\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n * \n * #### Default:\n * \n * {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n }\n * \n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n * \n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParserOptions?: QueryParserOptions;\n /**\n * Configuration for CORS (Cross-Origin Resource Sharing).\n *\n * @property {string | string[] | \"all\"} [allowedOrigins] - List of allowed origins. If set to `\"all\"`, all origins are accepted.\n * @property {import('cors').CorsOptions} [options] - Additional CORS options passed directly to the `cors` middleware.\n * @property {import('cors').CorsOptionsDelegate} [customMiddleware] - A custom middleware function that overrides the default behavior.\n *\n * @remarks\n * If `customMiddleware` is provided, both `allowedOrigins` and `options` will be ignored in favor of the custom logic.\n *\n * See https://www.npmjs.com/package/cors\n */\n cors?: {\n /**\n * Defines allowed origins to acess the API.\n */\n allowedOrigins?: string | string[] | \"*\";\n options?: cors.CorsOptions;\n /**\n * If you would like to override the entire middleware\n *\n * see\n */\n customHandler?: cors.CorsOptionsDelegate;\n };\n /**\n * Defines express/arkos middlewares configurations\n */\n middlewares?: {\n /**\n * Allows to add an array of custom express middlewares into the default middleware stack.\n *\n * **Tip**: If you would like to acess the express app before everthing use `configureApp` and pass a function.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order](https://www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order)\n *\n * **Note**: If you want to use custom global error handler middleware use `middlewares.replace.globalErrorHandler`.\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.RequestHandler[];\n /**\n * An array containing a list of defaults middlewares to be disabled\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n disable?: (\n | \"compression\"\n | \"global-rate-limit\"\n | \"auth-rate-limit\"\n | \"cors\"\n | \"express-json\"\n | \"cookie-parser\"\n | \"query-parser\"\n | \"database-connection\"\n | \"request-logger\"\n | \"global-error-handler\"\n )[];\n /**\n * Allows you to replace each of the built-in middlewares with your own implementation\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default compression middleware\n */\n compression?: express.RequestHandler;\n /**\n * Replace the default global rate limit middleware\n */\n globalRateLimit?: express.RequestHandler;\n /**\n * Replace the default authentication rate limit middleware\n */\n authRateLimit?: express.RequestHandler;\n /**\n * Replace the default CORS middleware\n */\n cors?: express.RequestHandler;\n /**\n * Replace the default JSON body parser middleware\n */\n expressJson?: express.RequestHandler;\n /**\n * Replace the default cookie parser middleware\n */\n cookieParser?: express.RequestHandler;\n /**\n * Replace the default query parser middleware\n */\n queryParser?: express.RequestHandler;\n /**\n * Replace the default database connection check middleware\n */\n databaseConnection?: express.RequestHandler;\n /**\n * Replace the default request logger middleware\n */\n requestLogger?: express.RequestHandler;\n /**\n * Replace the default global error handler middleware\n */\n globalErrorHandler?: express.ErrorRequestHandler;\n };\n };\n /**\n * Defines express/arkos routers configurations\n */\n routers?: {\n /**\n * Allows to add an array of custom express routers into the default middleware/router stack.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/adding-custom-routers](https://www.arkosjs.com/docs/advanced-guide/adding-custom-routers)\n *\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.Router[];\n disable?: (\n | \"auth-router\"\n | \"prisma-models-router\"\n | \"file-upload\"\n | \"welcome-endpoint\"\n )[];\n /**\n * Allows you to replace each of the built-in routers with your own implementation.\n *\n * **Note**: Doing this you will lose all default middleware chaining, auth control, handlers from the specific router.\n *\n * **Tip**: I you want to disable some prisma models specific endpoint\n * see [www.arkosjs.com/docs/guide/adding-custom-routers#disabling-auto-generated-endpoints](https://www.arkosjs.com/docs/guide/adding-custom-routers#disabling-auto-generated-endpoints)\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default authentication router\n * @param config The original Arkos configuration\n * @returns A router handling authentication endpoints\n */\n authRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default Prisma models router\n * @param config The original Arkos configuration\n * @returns A router handling Prisma model endpoints\n */\n prismaModelsRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default file upload router\n * @param config The original Arkos configuration\n * @returns A router handling file upload endpoints\n */\n fileUpload?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default welcome endpoint handler\n * @param req Express request object\n * @param res Express response object\n * @param next Express next function\n */\n welcomeEndpoint?: express.RequestHandler;\n };\n };\n /**\n * Gives acess to the underlying express app so that you can add custom configurations beyong **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `app.listen` for you.\n *\n * If you want to call `app.listen` by yourself pass port as `undefined` and then use the return app from `arkos.init()`.\n *\n * See how to call `app.listen` correctly [www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself](https://www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself)\n *\n * See [www.arkosjs.com/docs/guide/accessing-the-express-app](https://www.arkosjs.com/docs/guide/accessing-the-express-app) for further details on the method configureApp.\n *\n * @param {express.Express} app\n * @returns {any}\n */\n configureApp?: (app: express.Express) => Promise<any> | any;\n /**\n * Gives access to the underlying HTTP server so that you can add custom configurations beyond **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `server.listen` for you.\n *\n * If you want to call `server.listen` by yourself pass port as `undefined` and then use the return server from `arkos.init()`.\n *\n * See how to call `server.listen` correctly [www.arkosjs.com/docs/guide/accessing-the-express-app#creating-your-own-http-server](https://www.arkosjs.com/docs/guide/accessing-the-express-app#creating-your-own-http-server)\n *\n * See [www.arkosjs.com/docs/guide/accessing-the-express-app#accessing-the-http-server](https://www.arkosjs.com/docs/guide/accessing-the-express-app#accessing-the-http-server) for further details on the method configureServer.\n *\n * @param {http.Server} server - The HTTP server instance\n * @returns {any}\n */\n configureServer?: (server: http.Server) => Promise<any> | any;\n /**\n * Allows to configure email configurations for sending emails through `emailService`\n *\n * See [www.arkosjs.com/docs/core-concepts/sending-emails](https://www.arkosjs.com/docs/core-concepts/sending-emails)\n */\n email?: {\n /**\n * Your email provider url\n */\n host: string;\n /**\n * Email provider SMTP port, Default is `465`\n */\n port?: number;\n /**\n * If smtp connection must be secure, Default is `true`\n */\n secure?: boolean;\n /**\n * Used to authenticate in your smtp server\n */\n auth: {\n /**\n * Email used for auth as well as sending emails\n */\n user: string;\n /**\n * Your SMTP password\n */\n pass: string;\n };\n /**\n * Email name to used like:\n *\n * John Doe\\<john.doe@gmail.com>\n */\n name?: string;\n };\n /**\n * Defines Swagger and OpenApi specifications for auto generating swagger documentation UI using whether it is Prisma Schemas, Class-validator DTOs, Zod Schemas or JSON-Schemas.\n *\n * **Important**: Is worth mentioning that this works alongside `@scalar/express-api-reference` npm package, you define it's ApiReferenceConfiguration under ``. also consider checking the package documentation at []\n *\n * **Usage**\n *\n * ```ts\n * // src/app.ts\n *\n * import arkos from \"arkos\"\n *\n * arkos.init({\n * // other configs\n * swagger: {\n * mode: \"zod\",\n * options: {\n * defintion: {\n * info: {\n * openapi: \"3.0.0\",\n * title: \"API Generated By Arkos.js\",\n * description: \"This API was automatically generated by Arkos.js read more about at www.arkosjs.com\"\n * }\n * }\n * }\n * }\n * })\n * ```\n * @see {@link https://www.arkosjs.com/docs/core-concepts/swagger-api-documentation}\n */\n swagger?: {\n /**\n * By default Arkos will disable API Documentation when the project is built `npm run build`, it does not matter what node environment is set. If you want to use it even after the `arkos build` command just set this to `true`.\n * */\n enableAfterBuild?: boolean;\n /**\n * Endpoint where the Swagger UI will be available.\n *\n * @default \"/api/api-docs\"\n */\n endpoint?: string;\n /**\n * Determines how your API schemas should be generated.\n *\n * - \"prisma\": Generates schemas based on Prisma models\n * - \"class-validator\": Uses class-validator and class-transformer DTO classes\n * - \"zod\": Uses OpenAPI-compliant schemas directly\n */\n mode: \"prisma\" | \"class-validator\" | \"zod\";\n /**\n * Allows `Arkos.js` to fallback to prisma schema and use them as json schema for defining request body and response data\n * when a given zod Schema or class-validator Class is not found to be transformed to json schema.\n *\n * @default false\n */\n strict: boolean;\n /**\n * Defines your swagger configurations\n */\n options?: {\n /**\n * Swagger definition according to OpenAPI Specification.\n */\n definition?: {\n /**\n * OpenAPI version.\n *\n * @default \"3.0.0\"\n */\n openapi?: string;\n\n /**\n * Information about your API.\n */\n info?: {\n /**\n * Title of the API documentation.\n *\n *\n * @example \"My API\"\n *\n * @default \"API Generated By Arkos.js\"\n */\n title?: string;\n\n /**\n * Version of the API.\n *\n * @example \"1.0.0\"\n */\n version?: string;\n\n /**\n * Description of the API.\n *\n * @default \"This API was automatically generated by Arkos.js read more about at www.arkosjs.com\"\n */\n description?: string;\n };\n\n /**\n * Server configurations for the API.\n *\n * @default [{ url: \"http://localhost:8000\", description: \"Development server\" }]\n *\n * This can be overridden automatically by Arkos based on CLI, .env, or `arkos.init()`.\n */\n servers?: {\n /**\n * Base URL of the server.\n *\n * @example \"http://localhost:8000\"\n */\n url: string;\n\n /**\n * Human-readable description of the server.\n *\n * @example \"Development Server\"\n */\n description?: string;\n }[];\n /**\n * Allows adding more paths for your OpenAPI documentation\n *\n * */\n paths?: OpenAPIV3.PathsObject;\n /**\n * (Optional) Additional metadata such as terms of service, contact, or license.\n *\n * See: https://swagger.io/specification/#infoObject\n */\n termsOfService?: string;\n contact?: {\n name?: string;\n url?: string;\n email?: string;\n };\n license?: {\n name: string;\n url?: string;\n };\n\n /**\n * Tags to group and describe endpoints.\n */\n tags?: {\n name: string;\n description?: string;\n }[];\n\n /**\n * Security definitions (e.g., Bearer Auth).\n */\n components?: {\n securitySchemes?: Record<string, any>;\n schemas?: Record<string, any>;\n };\n\n /**\n * Global security requirements.\n */\n security?: Array<Record<string, string[]>>;\n };\n\n /**\n * Glob patterns defining where Swagger should look for API route definitions and comments.\n *\n * @default \n * ```ts\n * [\"./src/routers/*.router.{ts,js}\", \"./src/modules/**\\/*.router.{ts,js}\"]\n ```\n *\n * Adjust depending on TypeScript or JavaScript usage.\n */\n apis?: string[];\n\n /**\n * Enables deep linking in the Swagger UI.\n *\n * @default true\n */\n deepLinking?: boolean;\n\n /**\n * Enable/disable the \"Try it out\" button globally.\n *\n * @default true\n */\n tryItOutEnabled?: boolean;\n\n /**\n * Whether to persist authorization data across page reloads.\n *\n * @default false\n */\n persistAuthorization?: boolean;\n };\n /**\n * Custom `@scalar/express-api-reference` package options.\n *\n * @see {@link https://guides.scalar.com/scalar/scalar-api-references/integrations/express}\n */\n scalarApiReferenceConfiguration?: Partial<ApiReferenceConfiguration>;\n };\n};\n"]}
@@ -125,7 +125,7 @@ async function devCommand(options = {}) {
125
125
  ignoreInitial: true,
126
126
  persistent: true,
127
127
  });
128
- envWatcher.on("all", (event, filePath) => {
128
+ envWatcher.on("all", (_, filePath) => {
129
129
  try {
130
130
  envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)();
131
131
  scheduleRestart("Environments files changed");
@@ -165,9 +165,6 @@ async function devCommand(options = {}) {
165
165
  additionalWatcher.on("unlink", (filePath) => {
166
166
  scheduleRestart(`${(0, fs_helpers_1.fullCleanCwd)(filePath)} has been deleted`);
167
167
  });
168
- additionalWatcher.on("change", (filePath) => {
169
- console.log(`file changed`, filePath);
170
- });
171
168
  return additionalWatcher;
172
169
  };
173
170
  startServer();
@@ -190,8 +187,11 @@ async function devCommand(options = {}) {
190
187
  }
191
188
  return false;
192
189
  }
193
- catch (error) {
194
- console.info(error);
190
+ catch (err) {
191
+ const message = err?.message;
192
+ if (!message.includes("../../server") &&
193
+ !message.includes("cjs/server"))
194
+ console.info(err);
195
195
  return false;
196
196
  }
197
197
  };
@@ -202,7 +202,7 @@ async function devCommand(options = {}) {
202
202
  const ready = await checkConfig();
203
203
  if (ready)
204
204
  break;
205
- await new Promise((resolve) => setTimeout(resolve, 50));
205
+ await new Promise((resolve) => setTimeout(resolve, 150));
206
206
  attempts++;
207
207
  }
208
208
  if (attempts >= maxAttempts) {
@@ -1 +1 @@
1
- {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":";;;;;AAqBA,gCAqTC;AAKD,8EAGC;AAlVD,iDAAoD;AACpD,uCAAiC;AACjC,sDAA2E;AAC3E,qDAAiD;AACjD,sDAA6D;AAC7D,8DAAyD;AACzD,4CAAoB;AACpB,gDAAwB;AACxB,mDAA2B;AAO3B,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAK5B,KAAK,UAAU,UAAU,CAAC,UAAsB,EAAE;IACvD,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAC;IACrC,QAAQ,GAAG,IAAA,yCAAwB,GAAE,CAAC;IACtC,KAAK,GAAG,IAAI,CAAC;IACb,IAAI,cAAc,GAA0B,IAAI,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAC/B,IAAI,YAAY,GAAG,KAAK,CAAC;QAEzB,MAAM,OAAO,GAAG,IAAA,iCAAoB,GAAE,CAAC;QAGvC,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WA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,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAE5D,IAAI,KAAK,EAAE,CAAC;YACT,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;YAClC,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,iCAAiC;IAC9C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["import { spawn, ChildProcess } from \"child_process\";\nimport { watch } from \"chokidar\";\nimport { fullCleanCwd, getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport sheu from \"../sheu\";\n\ninterface DevOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Dev server command for the arkos CLI\n */\nexport async function devCommand(options: DevOptions = {}) {\n process.env.NODE_ENV = \"development\";\n envFiles = loadEnvironmentVariables();\n child = null;\n let restartTimeout: NodeJS.Timeout | null = null;\n\n try {\n const { port, host } = options;\n let isRestarting = false;\n // Detect if project uses TypeScript or JavaScript\n const fileExt = getUserFileExtension();\n\n // Find the application entry point\n const entryPoint = path.resolve(process.cwd(), `src/app.${fileExt}`);\n\n if (!fs.existsSync(entryPoint)) {\n console.error(`Could not find application entry point at ${entryPoint}`);\n process.exit(1);\n }\n\n // Set environment variables\n const getEnv = () =>\n ({\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n }) as { [x: string]: string };\n\n // Function to start the child process\n const startServer = () => {\n if (child) {\n child.kill();\n child = null;\n }\n\n const env = getEnv();\n\n if (fileExt === \"ts\") {\n // Enhanced ts-node-dev configuration\n child = spawn(\n \"npx\",\n [\n \"ts-node-dev\",\n \"--respawn\",\n \"--notify=false\", // Disable desktop notifications\n \"--ignore-watch\",\n \"node_modules\",\n \"--ignore-watch\",\n \"dist\",\n \"--ignore-watch\",\n \"build\",\n \"--ignore-watch\",\n \".dist\",\n \"--ignore-watch\",\n \".build\",\n \"--watch\",\n \"src\", // Explicitly watch src directory\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n } else {\n // Enhanced nodemon configuration\n\n child = spawn(\n \"npx\",\n [\n \"node-dev\",\n \"--respawn\",\n \"--notify=false\",\n \"--ignore\",\n \"node_modules\",\n \"--ignore\",\n \"dist\",\n \"--ignore\",\n \"build\",\n \"--ignore\",\n \".dist\",\n \"--ignore\",\n \".build\",\n \"--watch\",\n \"src\",\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n }\n\n if (child) {\n child.on(\"error\", (error) => {\n console.error(\"Failed to start server:\", error);\n });\n\n child.on(\"exit\", (code, signal) => {\n if (!isRestarting && signal !== \"SIGTERM\" && signal !== \"SIGINT\") {\n console.info(`Server exited with code ${code}, restarting...`);\n startServer();\n }\n });\n }\n };\n\n // Function to handle server restart with debouncing\n const scheduleRestart = (reason: string) => {\n if (restartTimeout) clearTimeout(restartTimeout);\n const now = new Date();\n const time = now.toTimeString().split(\" \")[0];\n\n sheu.info(`\\x1b[90m${time}\\x1b[0m Restarting: ${reason.toLowerCase()}`);\n\n isRestarting = true;\n if (child) {\n child.kill();\n child = null;\n }\n restartTimeout = setTimeout(() => {\n startServer();\n restartTimeout = null;\n }, 1000);\n };\n\n // Setup environment file watching\n const setupEnvWatcher = () => {\n const envWatcher = watch(\n fullCleanCwd(envFiles?.join(\",\") || \"\")\n .replaceAll(\"/\", \"\")\n .split(\",\") || [],\n {\n ignoreInitial: true,\n persistent: true,\n }\n );\n\n envWatcher.on(\"all\", (event, filePath) => {\n try {\n envFiles = loadEnvironmentVariables();\n\n // Restart server to pick up new env vars\n scheduleRestart(\"Environments files changed\");\n } catch (error) {\n console.error(`Error reloading ${filePath}:`, error);\n }\n });\n\n return envWatcher;\n };\n\n // Setup additional file watching for better new file detection\n const setupAdditionalWatcher = () => {\n const additionalWatcher = watch(\n [\n \"src\",\n \"package.json\",\n \"tsconfig.json\",\n \"jsconfig.json\",\n \"arkos.config.ts\",\n \"arkos.config.js\",\n ],\n {\n ignoreInitial: true,\n ignored: [\n /node_modules/,\n /\\.git/,\n /\\.dist/,\n /\\.build/,\n /dist/,\n /build/,\n /\\.env.*/,\n ],\n awaitWriteFinish: {\n stabilityThreshold: 3000,\n },\n }\n );\n\n additionalWatcher.on(\"add\", (filePath) => {\n scheduleRestart(`${fullCleanCwd(filePath)} has been created`);\n });\n\n additionalWatcher.on(\"unlink\", (filePath) => {\n scheduleRestart(`${fullCleanCwd(filePath)} has been deleted`);\n });\n\n additionalWatcher.on(\"change\", (filePath) => {\n console.log(`file changed`, filePath);\n });\n\n return additionalWatcher;\n };\n\n // Start the server\n startServer();\n\n // Setup watchers if enabled\n const envWatcher = setupEnvWatcher();\n const additionalWatcher = setupAdditionalWatcher();\n\n const checkConfig = async () => {\n try {\n // Import the config getter\n const { getArkosConfig } = await importModule(\"../../server\");\n const config = getArkosConfig();\n if (config && config.available) {\n // Config is ready, display the info with actual values\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n console.info(\"\\n\");\n return true;\n }\n return false;\n } catch (error) {\n console.info(error);\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n await new Promise((resolve) => setTimeout(resolve, 50));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n console.info(\"\\n\");\n }\n };\n\n waitForConfig();\n\n // Enhanced cleanup function\n const cleanup = () => {\n // console.info(\"\\nShutting down development server...\");\n\n if (restartTimeout) clearTimeout(restartTimeout);\n\n if (envWatcher) envWatcher.close();\n\n if (additionalWatcher) additionalWatcher.close();\n\n if (child) {\n child.kill(\"SIGTERM\");\n\n // Force kill after 5 seconds if still running\n setTimeout(() => {\n if (child && !child.killed) child.kill(\"SIGKILL\");\n }, 5000);\n }\n\n process.exit(0);\n };\n\n // Handle process exit\n process.on(\"SIGINT\", cleanup);\n process.on(\"SIGTERM\", cleanup);\n\n // Handle uncaught exceptions\n process.on(\"uncaughtException\", (error) => {\n console.error(\"Uncaught Exception:\", error);\n cleanup();\n });\n } catch (error) {\n console.error(\"Development server failed to start:\", error);\n\n if (child) {\n (child as ChildProcess)?.kill?.();\n child = null;\n }\n\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the development server child process\n */\nexport function killDevelopmentServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
1
+ {"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[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,UAAU,CAAC,KAAK,EAAE,CAAC;YAEnC,IAAI,iBAAiB;gBAAE,iBAAiB,CAAC,KAAK,EAAE,CAAC;YAEjD,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAGtB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM;wBAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACpD,CAAC,EAAE,IAAI,CAAC,CAAC;YACX,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAGF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAG/B,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;YACxC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAE5D,IAAI,KAAK,EAAE,CAAC;YACT,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;YAClC,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,iCAAiC;IAC9C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["import { spawn, ChildProcess } from \"child_process\";\nimport { watch } from \"chokidar\";\nimport { fullCleanCwd, getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport sheu from \"../sheu\";\n\ninterface DevOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Dev server command for the arkos CLI\n */\nexport async function devCommand(options: DevOptions = {}) {\n process.env.NODE_ENV = \"development\";\n envFiles = loadEnvironmentVariables();\n child = null;\n let restartTimeout: NodeJS.Timeout | null = null;\n\n try {\n const { port, host } = options;\n let isRestarting = false;\n // Detect if project uses TypeScript or JavaScript\n const fileExt = getUserFileExtension();\n\n // Find the application entry point\n const entryPoint = path.resolve(process.cwd(), `src/app.${fileExt}`);\n\n if (!fs.existsSync(entryPoint)) {\n console.error(`Could not find application entry point at ${entryPoint}`);\n process.exit(1);\n }\n\n // Set environment variables\n const getEnv = () =>\n ({\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n }) as { [x: string]: string };\n\n // Function to start the child process\n const startServer = () => {\n if (child) {\n child.kill();\n child = null;\n }\n\n const env = getEnv();\n\n if (fileExt === \"ts\") {\n // Enhanced ts-node-dev configuration\n child = spawn(\n \"npx\",\n [\n \"ts-node-dev\",\n \"--respawn\",\n \"--notify=false\", // Disable desktop notifications\n \"--ignore-watch\",\n \"node_modules\",\n \"--ignore-watch\",\n \"dist\",\n \"--ignore-watch\",\n \"build\",\n \"--ignore-watch\",\n \".dist\",\n \"--ignore-watch\",\n \".build\",\n \"--watch\",\n \"src\", // Explicitly watch src directory\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n } else {\n // Enhanced nodemon configuration\n\n child = spawn(\n \"npx\",\n [\n \"node-dev\",\n \"--respawn\",\n \"--notify=false\",\n \"--ignore\",\n \"node_modules\",\n \"--ignore\",\n \"dist\",\n \"--ignore\",\n \"build\",\n \"--ignore\",\n \".dist\",\n \"--ignore\",\n \".build\",\n \"--watch\",\n \"src\",\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n }\n\n if (child) {\n child.on(\"error\", (error) => {\n console.error(\"Failed to start server:\", error);\n });\n\n child.on(\"exit\", (code, signal) => {\n if (!isRestarting && signal !== \"SIGTERM\" && signal !== \"SIGINT\") {\n console.info(`Server exited with code ${code}, restarting...`);\n startServer();\n }\n });\n }\n };\n\n // Function to handle server restart with debouncing\n const scheduleRestart = (reason: string) => {\n if (restartTimeout) clearTimeout(restartTimeout);\n const now = new Date();\n const time = now.toTimeString().split(\" \")[0];\n\n sheu.info(`\\x1b[90m${time}\\x1b[0m Restarting: ${reason.toLowerCase()}`);\n\n isRestarting = true;\n if (child) {\n child.kill();\n child = null;\n }\n restartTimeout = setTimeout(() => {\n startServer();\n restartTimeout = null;\n }, 1000);\n };\n\n // Setup environment file watching\n const setupEnvWatcher = () => {\n const envWatcher = watch(\n fullCleanCwd(envFiles?.join(\",\") || \"\")\n .replaceAll(\"/\", \"\")\n .split(\",\") || [],\n {\n ignoreInitial: true,\n persistent: true,\n }\n );\n\n envWatcher.on(\"all\", (_, filePath) => {\n try {\n envFiles = loadEnvironmentVariables();\n\n // Restart server to pick up new env vars\n scheduleRestart(\"Environments files changed\");\n } catch (error) {\n console.error(`Error reloading ${filePath}:`, error);\n }\n });\n\n return envWatcher;\n };\n\n // Setup additional file watching for better new file detection\n const setupAdditionalWatcher = () => {\n const additionalWatcher = watch(\n [\n \"src\",\n \"package.json\",\n \"tsconfig.json\",\n \"jsconfig.json\",\n \"arkos.config.ts\",\n \"arkos.config.js\",\n ],\n {\n ignoreInitial: true,\n ignored: [\n /node_modules/,\n /\\.git/,\n /\\.dist/,\n /\\.build/,\n /dist/,\n /build/,\n /\\.env.*/,\n ],\n awaitWriteFinish: {\n stabilityThreshold: 3000,\n },\n }\n );\n\n additionalWatcher.on(\"add\", (filePath) => {\n scheduleRestart(`${fullCleanCwd(filePath)} has been created`);\n });\n\n additionalWatcher.on(\"unlink\", (filePath) => {\n scheduleRestart(`${fullCleanCwd(filePath)} has been deleted`);\n });\n\n return additionalWatcher;\n };\n\n // Start the server\n startServer();\n\n // Setup watchers if enabled\n const envWatcher = setupEnvWatcher();\n const additionalWatcher = setupAdditionalWatcher();\n\n const checkConfig = async () => {\n try {\n // Import the config getter\n const { getArkosConfig } = await importModule(\"../../server\");\n const config = getArkosConfig();\n if (config && config.available) {\n // Config is ready, display the info with actual values\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n console.info(\"\\n\");\n return true;\n }\n return false;\n } catch (err: any) {\n const message = err?.message;\n if (\n !message.includes(\"../../server\") &&\n !message.includes(\"cjs/server\")\n )\n console.info(err);\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n await new Promise((resolve) => setTimeout(resolve, 150));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n console.info(\"\\n\");\n }\n };\n\n waitForConfig();\n\n // Enhanced cleanup function\n const cleanup = () => {\n if (restartTimeout) clearTimeout(restartTimeout);\n\n if (envWatcher) envWatcher.close();\n\n if (additionalWatcher) additionalWatcher.close();\n\n if (child) {\n child.kill(\"SIGTERM\");\n\n // Force kill after 5 seconds if still running\n setTimeout(() => {\n if (child && !child.killed) child.kill(\"SIGKILL\");\n }, 5000);\n }\n\n process.exit(0);\n };\n\n // Handle process exit\n process.on(\"SIGINT\", cleanup);\n process.on(\"SIGTERM\", cleanup);\n\n // Handle uncaught exceptions\n process.on(\"uncaughtException\", (error) => {\n console.error(\"Uncaught Exception:\", error);\n cleanup();\n });\n } catch (error) {\n console.error(\"Development server failed to start:\", error);\n\n if (child) {\n (child as ChildProcess)?.kill?.();\n child = null;\n }\n\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the development server child process\n */\nexport function killDevelopmentServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
@@ -55,8 +55,9 @@ async function startCommand(options = {}) {
55
55
  }
56
56
  return false;
57
57
  }
58
- catch (error) {
59
- console.info(error);
58
+ catch (err) {
59
+ if (!err.message.includes("../../server"))
60
+ console.info(err);
60
61
  return false;
61
62
  }
62
63
  };
@@ -67,7 +68,7 @@ async function startCommand(options = {}) {
67
68
  const ready = await checkConfig();
68
69
  if (ready)
69
70
  break;
70
- await new Promise((resolve) => setTimeout(resolve, 50));
71
+ await new Promise((resolve) => setTimeout(resolve, 150));
71
72
  attempts++;
72
73
  }
73
74
  if (attempts >= maxAttempts) {
@@ -1 +1 @@
1
- {"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;AAoBA,oCAsGC;AAKD,4EAGC;AAjID,gDAAwB;AACxB,4CAAoB;AACpB,iDAAoD;AACpD,qDAAiD;AACjD,sDAA6D;AAC7D,8DAAyD;AACzD,sDAAqD;AAOrD,IAAI,KAAK,GAAwB,IAAI,C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AAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;gBACxD,QAAQ,EAAE,CAAC;YACb,CAAC;YAGD,IAAI,QAAQ,IAAI,WAAW,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnB,OAAO,CAAC,IAAI,CAAC,+BAA+B,IAAA,wBAAU,GAAE,SAAS,CAAC,CAAC;gBACnE,OAAO,CAAC,IAAI,CACV,4BACE,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,WAC9B,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,CACzC,CAAC;gBACF,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ;oBAC3B,EAAE,IAAI,CAAC,IAAI,CAAC;qBACX,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAC3C,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,aAAa,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,gCAAgC;IAC7C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["// src/utils/cli/start.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { ChildProcess, spawn } from \"child_process\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport { fullCleanCwd } from \"../helpers/fs.helpers\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Production start command for the arkos CLI\n */\nexport async function startCommand(options: StartOptions = {}) {\n process.env.NODE_ENV = \"production\";\n envFiles = loadEnvironmentVariables();\n\n try {\n const { port, host } = options;\n\n // Check for built app file\n const entryPoint = path.join(process.cwd(), \".build\", \"src\", \"app.js\");\n\n if (!fs.existsSync(path.join(entryPoint))) {\n console.error(\n `❌ Could not find built application entry point at ${fullCleanCwd(entryPoint)}`\n );\n process.exit(1);\n }\n\n // Set environment variables\n const env: { [x: string]: string } = {\n ...process.env,\n NODE_ENV: \"production\",\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n ARKOS_BUILD: \"true\",\n };\n\n // Start the application\n child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n\n const checkConfig = async () => {\n try {\n const { getArkosConfig } = await importModule(\"../../server\");\n\n const config = getArkosConfig();\n\n if (config && config.available) {\n // Config is ready, display the info with actual values\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\").replaceAll(\"/\", \"\")}\\n`\n );\n return true;\n }\n return false;\n } catch (error) {\n console.info(error);\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n await new Promise((resolve) => setTimeout(resolve, 50));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${envFiles\n ?.join(\", \")\n .replaceAll(`${process.cwd()}/`, \"\")}\\n`\n );\n }\n };\n\n waitForConfig();\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the production server child process\n */\nexport function killProductionServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;AAoBA,oCAsGC;AAKD,4EAGC;AAjID,gDAAwB;AACxB,4CAAoB;AACpB,iDAAoD;AACpD,qDAAiD;AACjD,sDAA6D;AAC7D,8DAAyD;AACzD,sDAAqD;AAOrD,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAK5B,KAAK,UAAU,YAAY,CAAC,UAAwB,EAAE;IAC3D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;IACpC,QAAQ,GAAG,IAAA,yCAAwB,GAAE,CAAC;IAEtC,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAG/B,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEvE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAC1C,OAAO,CAAC,KAAK,CACX,qDAAqD,IAAA,yBAAY,EAAC,UAAU,CAAC,EAAE,CAChF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;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,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAC3C,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,aAAa,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAgB,gCAAgC;IAC7C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["// src/utils/cli/start.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { ChildProcess, spawn } from \"child_process\";\nimport { getVersion } from \"./utils/cli.helpers\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport { fullCleanCwd } from \"../helpers/fs.helpers\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Production start command for the arkos CLI\n */\nexport async function startCommand(options: StartOptions = {}) {\n process.env.NODE_ENV = \"production\";\n envFiles = loadEnvironmentVariables();\n\n try {\n const { port, host } = options;\n\n // Check for built app file\n const entryPoint = path.join(process.cwd(), \".build\", \"src\", \"app.js\");\n\n if (!fs.existsSync(path.join(entryPoint))) {\n console.error(\n `❌ Could not find built application entry point at ${fullCleanCwd(entryPoint)}`\n );\n process.exit(1);\n }\n\n // Set environment variables\n const env: { [x: string]: string } = {\n ...process.env,\n NODE_ENV: \"production\",\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n ARKOS_BUILD: \"true\",\n };\n\n // Start the application\n child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n\n const checkConfig = async () => {\n try {\n const { getArkosConfig } = await importModule(\"../../server\");\n\n const config = getArkosConfig();\n\n if (config && config.available) {\n // Config is ready, display the info with actual values\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\").replaceAll(\"/\", \"\")}\\n`\n );\n return true;\n }\n return false;\n } catch (err: any) {\n if (!err.message.includes(\"../../server\")) console.info(err);\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n await new Promise((resolve) => setTimeout(resolve, 150));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${envFiles\n ?.join(\", \")\n .replaceAll(`${process.cwd()}/`, \"\")}\\n`\n );\n }\n };\n\n waitForConfig();\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the production server child process\n */\nexport function killProductionServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
@@ -18,7 +18,7 @@ function generateQueryOptionsTemplate(options) {
18
18
  : `: PrismaQueryOptions<typeof prisma.${modelName.camel}>`
19
19
  : "";
20
20
  const prismaImport = isTypeScript
21
- ? `import { prisma } from "../../utils/prisma";\n`
21
+ ? `import { prisma } from "../../utils/prisma.js";\n`
22
22
  : "";
23
23
  if (isAuth) {
24
24
  return `${prismaImport}${imports};
@@ -9,7 +9,7 @@ function generateServiceTemplate(options) {
9
9
  if (!modelName)
10
10
  throw new Error("Model name is required for service template");
11
11
  const prismaImport = isTypeScript
12
- ? `import prisma from "../../utils/prisma";\n`
12
+ ? `import prisma from "../../utils/prisma.js";\n`
13
13
  : "";
14
14
  const baseServiceImport = isTypeScript
15
15
  ? `import { BaseService } from "${imports?.baseService || "arkos/services"}";`
@@ -67,7 +67,7 @@ class APIFeatures {
67
67
  if (this.modelName)
68
68
  Object.keys(prisma[this.modelName].fields).forEach((key) => {
69
69
  const field = prisma[this.modelName].fields[key];
70
- if (field.typeName === "String" &&
70
+ if (field?.typeName === "String" &&
71
71
  key !== "id" &&
72
72
  key !== "password" &&
73
73
  !field.isList &&
@@ -1 +1 @@
1
- {"version":3,"file":"api.features.js","sourceRoot":"","sources":["../../../../src/utils/features/api.features.ts"],"names":[],"mappings":";;;;;;AACA,mFAAoD;AACpD,0EAAgF;AAChF,4FAAmE;AACnE,8DAA8D;AAK9D,MAAqB,WAAW;IAuB9B,YAAY,GAAa,EAAE,SAAqB;QAnBhD,YAAO,GAAQ,EAAE,CAAC;QAClB,0BAAqB,GAAQ,EAAE,CAAC;QAEhC,mBAAc,GAAG;YACf,MAAM;YACN,SAAS;YACT,MAAM;YACN,OAAO;YACP,QAAQ;YACR,WAAW;YACX,cAAc;YACd,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,OAAO;YACP,oBAAoB;YACpB,eAAe;SAChB,CAAC;QAGA,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;YACrD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,YAAY,GAAG,IAAA,0BAAS,EAC3B,IAAA,oDAA6B,EAAC,WAAW,CAAC,EA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,KAAa,EAAE,EAAE;oBACtC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;gBAC3B,CAAC,CAAC,CAAC;YACL,CAAC;YAGD,IAAI,CAAC,OAAO,GAAG;gBACb,GAAG,IAAI,CAAC,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB,CAAC;YAGF,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;QAGD,IAAI,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAQ,CAChB,4GAA4G,EAC5G,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QAEhC,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,IAAI,CAAC,OAAO;YACf,IAAI;YACJ,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5ND,8BA4NC;AAEY,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["import { Request } from \"express\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport { parseQueryParamsWithModifiers } from \"../helpers/api.features.helpers\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getPrismaInstance } from \"../helpers/prisma.helpers\";\nimport { ArkosRequest } from \"../../types\";\n\ntype ModelName = string;\n\nexport default class APIFeatures {\n req?: ArkosRequest;\n searchParams: any; // The query string parameters from the request\n searchParamsWithModifiers: any; // The query string parameters from the request\n filters: any = {};\n reqFiltersSearchParam: any = {};\n modelName?: ModelName;\n excludedFields = [\n \"page\",\n \"filters\",\n \"sort\",\n \"limit\",\n \"fields\",\n \"addFields\",\n \"removeFields\",\n \"search\",\n \"include\",\n \"filterMode\",\n \"where\",\n \"prismaQueryOptions\",\n \"ignoredFields\",\n ];\n\n constructor(req?: Request, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n JSON.parse(filters as string)\n );\n }\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n }\n\n setup(req: Request, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n JSON.parse(filters as string)\n );\n }\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n\n return this;\n }\n\n filter() {\n if (!this.req)\n throw new Error(\n \"Trying to use APIFeatures.filter() without passing request on class constructor or APIFeatures.setup() method. read more about at www.arkosjs.com/docs/advanced-guide/api-features-class\"\n );\n const searchableFields: Record<string, any>[] = [];\n\n const queryObj = { ...this.searchParams };\n\n this.excludedFields.forEach((el) => delete queryObj[el]);\n\n const whereObj = { ...this.req.params, ...queryObj };\n const whereLogicalOperatorFilters = Object.keys(whereObj).map((key) => ({\n [key]: whereObj[key],\n }));\n\n let whereOptions =\n whereLogicalOperatorFilters.length > 0\n ? {\n [(this.req.query?.filterMode as string) ?? \"OR\"]:\n whereLogicalOperatorFilters,\n }\n : {};\n\n if (!!this.searchParams.search) {\n const prisma = getPrismaInstance();\n\n if (this.modelName)\n Object.keys((prisma as any)[this.modelName].fields).forEach((key) => {\n const field = ((prisma as any)[this.modelName!].fields as any)[key];\n if (\n field.typeName === \"String\" &&\n key !== \"id\" &&\n key !== \"password\" &&\n !field.isList &&\n !key?.includes?.(\"Id\") &&\n !key?.includes?.(\"ID\")\n ) {\n searchableFields.push({\n [`${key}`]: {\n contains: this.searchParams.search,\n mode: \"insensitive\",\n },\n });\n }\n });\n\n whereOptions = deepmerge(\n {\n OR: searchableFields,\n },\n whereOptions\n );\n }\n\n const firstMerge = deepmerge(\n {\n where: whereOptions,\n },\n this.req.prismaQueryOptions || {}\n );\n\n this.filters = deepmerge(firstMerge, this.filters);\n return this;\n }\n\n search() {\n if (this.searchParams?.search) {\n this.filters = deepmerge(this.filters, {\n where: {\n OR: [],\n },\n });\n }\n }\n\n sort() {\n if (this.searchParams.sort) {\n const sortBy = this.searchParams?.sort\n ?.split(\",\")\n ?.map((field: string) => ({\n [field.startsWith(\"-\") ? field.substring(1) : field]:\n field.startsWith(\"-\") ? \"desc\" : \"asc\",\n }));\n this.filters = deepmerge(this.filters, { orderBy: sortBy });\n }\n\n return this;\n }\n\n limitFields() {\n if (this.searchParams?.fields) {\n const fields = this.searchParams.fields.split(\",\");\n\n // Separate fields into includes, excludes, and regular fields\n const regularFields = fields.filter(\n (field: string) => !field.startsWith(\"+\") && !field.startsWith(\"-\")\n );\n const includeFields = fields\n .filter((field: string) => field.startsWith(\"+\"))\n .map((field: string) => field.substring(1));\n const excludeFields = fields\n .filter((field: string) => field.startsWith(\"-\"))\n .map((field: string) => field.substring(1));\n\n // Create selection object based on field type\n let selection: Record<string, any> = {};\n\n // If regular fields exist, use them as the base selection\n if (regularFields.length > 0) {\n selection = regularFields.reduce(\n (acc: Record<string, any>, field: string) => {\n acc[field] = true;\n return acc;\n },\n {} as Record<string, any>\n );\n }\n // Otherwise, use include fields as additions to any existing included fields\n else {\n // Start with current include fields if they exist\n selection = this.filters.include || {};\n\n // Add any explicitly included fields\n includeFields.forEach((field: string) => {\n selection[field] = true;\n });\n\n // Add any explicitly excluded fields\n excludeFields.forEach((field: string) => {\n selection[field] = false;\n });\n }\n\n // Apply the selection to filters\n this.filters = {\n ...this.filters,\n select: selection,\n };\n\n // Remove the include filter as it's now part of select\n if (this.filters.include) {\n delete this.filters.include;\n }\n }\n\n // Remove any references to the now-unused parameters\n if (this.searchParams?.addFields || this.searchParams?.removeFields) {\n throw new AppError(\n \"The addFields and removeFields parameters are deprecated. Please use fields with + and - prefixes instead.\",\n 400\n );\n }\n\n return this;\n }\n\n paginate() {\n const page = parseInt(this.searchParams.page, 10) || 1;\n const limit = parseInt(this.searchParams.limit, 10) || 30;\n const skip = (page - 1) * limit;\n\n this.filters = {\n ...this.filters,\n skip,\n take: limit,\n };\n return this;\n }\n}\n\nexport const apiFeatures = new APIFeatures();\n"]}
1
+ {"version":3,"file":"api.features.js","sourceRoot":"","sources":["../../../../src/utils/features/api.features.ts"],"names":[],"mappings":";;;;;;AACA,mFAAoD;AACpD,0EAAgF;AAChF,4FAAmE;AACnE,8DAA8D;AAK9D,MAAqB,WAAW;IAuB9B,YAAY,GAAa,EAAE,SAAqB;QAnBhD,YAAO,GAAQ,EAAE,CAAC;QAClB,0BAAqB,GAAQ,EAAE,CAAC;QAEhC,mBAAc,GAAG;YACf,MAAM;YACN,SAAS;YACT,MAAM;YACN,OAAO;YACP,QAAQ;YACR,WAAW;YACX,cAAc;YACd,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,OAAO;YACP,oBAAoB;YACpB,eAAe;SAChB,CAAC;QAGA,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC;YACrD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,YAAY,GAAG,IAAA,0BAAS,EAC3B,IAAA,oDAA6B,EAAC,WAAW,CAAC,EAC1C,IAAI,CAAC,KAAK,CAAC,OAAiB,CAAC,CAC9B,CAAC;QACJ,CAAC;QACD,IAAI,SAAS;YAAE,IAAI,CAAC,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AC;YAGD,IAAI,CAAC,OAAO,GAAG;gBACb,GAAG,IAAI,CAAC,OAAO;gBACf,MAAM,EAAE,SAAS;aAClB,CAAC;YAGF,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAC9B,CAAC;QACH,CAAC;QAGD,IAAI,IAAI,CAAC,YAAY,EAAE,SAAS,IAAI,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,CAAC;YACpE,MAAM,IAAI,mBAAQ,CAChB,4GAA4G,EAC5G,GAAG,CACJ,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ;QACN,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QAEhC,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,IAAI,CAAC,OAAO;YACf,IAAI;YACJ,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5ND,8BA4NC;AAEY,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC","sourcesContent":["import { Request } from \"express\";\nimport deepmerge from \"../helpers/deepmerge.helper\";\nimport { parseQueryParamsWithModifiers } from \"../helpers/api.features.helpers\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { getPrismaInstance } from \"../helpers/prisma.helpers\";\nimport { ArkosRequest } from \"../../types\";\n\ntype ModelName = string;\n\nexport default class APIFeatures {\n req?: ArkosRequest;\n searchParams: any; // The query string parameters from the request\n searchParamsWithModifiers: any; // The query string parameters from the request\n filters: any = {};\n reqFiltersSearchParam: any = {};\n modelName?: ModelName;\n excludedFields = [\n \"page\",\n \"filters\",\n \"sort\",\n \"limit\",\n \"fields\",\n \"addFields\",\n \"removeFields\",\n \"search\",\n \"include\",\n \"filterMode\",\n \"where\",\n \"prismaQueryOptions\",\n \"ignoredFields\",\n ];\n\n constructor(req?: Request, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n JSON.parse(filters as string)\n );\n }\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n }\n\n setup(req: Request, modelName?: ModelName) {\n if (req) {\n const { filters = \"{}\", ...restOfQuery } = req.query;\n this.req = req;\n this.searchParams = deepmerge(\n parseQueryParamsWithModifiers(restOfQuery),\n JSON.parse(filters as string)\n );\n }\n if (modelName) this.modelName = modelName;\n this.filters = { ...this.filters };\n\n return this;\n }\n\n filter() {\n if (!this.req)\n throw new Error(\n \"Trying to use APIFeatures.filter() without passing request on class constructor or APIFeatures.setup() method. read more about at www.arkosjs.com/docs/advanced-guide/api-features-class\"\n );\n const searchableFields: Record<string, any>[] = [];\n\n const queryObj = { ...this.searchParams };\n\n this.excludedFields.forEach((el) => delete queryObj[el]);\n\n const whereObj = { ...this.req.params, ...queryObj };\n const whereLogicalOperatorFilters = Object.keys(whereObj).map((key) => ({\n [key]: whereObj[key],\n }));\n\n let whereOptions =\n whereLogicalOperatorFilters.length > 0\n ? {\n [(this.req.query?.filterMode as string) ?? \"OR\"]:\n whereLogicalOperatorFilters,\n }\n : {};\n\n if (!!this.searchParams.search) {\n const prisma = getPrismaInstance();\n\n if (this.modelName)\n Object.keys((prisma as any)[this.modelName].fields).forEach((key) => {\n const field = ((prisma as any)[this.modelName!].fields as any)[key];\n if (\n field?.typeName === \"String\" &&\n key !== \"id\" &&\n key !== \"password\" &&\n !field.isList &&\n !key?.includes?.(\"Id\") &&\n !key?.includes?.(\"ID\")\n ) {\n searchableFields.push({\n [`${key}`]: {\n contains: this.searchParams.search,\n mode: \"insensitive\",\n },\n });\n }\n });\n\n whereOptions = deepmerge(\n {\n OR: searchableFields,\n },\n whereOptions\n );\n }\n\n const firstMerge = deepmerge(\n {\n where: whereOptions,\n },\n this.req.prismaQueryOptions || {}\n );\n\n this.filters = deepmerge(firstMerge, this.filters);\n return this;\n }\n\n search() {\n if (this.searchParams?.search) {\n this.filters = deepmerge(this.filters, {\n where: {\n OR: [],\n },\n });\n }\n }\n\n sort() {\n if (this.searchParams.sort) {\n const sortBy = this.searchParams?.sort\n ?.split(\",\")\n ?.map((field: string) => ({\n [field.startsWith(\"-\") ? field.substring(1) : field]:\n field.startsWith(\"-\") ? \"desc\" : \"asc\",\n }));\n this.filters = deepmerge(this.filters, { orderBy: sortBy });\n }\n\n return this;\n }\n\n limitFields() {\n if (this.searchParams?.fields) {\n const fields = this.searchParams.fields.split(\",\");\n\n // Separate fields into includes, excludes, and regular fields\n const regularFields = fields.filter(\n (field: string) => !field.startsWith(\"+\") && !field.startsWith(\"-\")\n );\n const includeFields = fields\n .filter((field: string) => field.startsWith(\"+\"))\n .map((field: string) => field.substring(1));\n const excludeFields = fields\n .filter((field: string) => field.startsWith(\"-\"))\n .map((field: string) => field.substring(1));\n\n // Create selection object based on field type\n let selection: Record<string, any> = {};\n\n // If regular fields exist, use them as the base selection\n if (regularFields.length > 0) {\n selection = regularFields.reduce(\n (acc: Record<string, any>, field: string) => {\n acc[field] = true;\n return acc;\n },\n {} as Record<string, any>\n );\n }\n // Otherwise, use include fields as additions to any existing included fields\n else {\n // Start with current include fields if they exist\n selection = this.filters.include || {};\n\n // Add any explicitly included fields\n includeFields.forEach((field: string) => {\n selection[field] = true;\n });\n\n // Add any explicitly excluded fields\n excludeFields.forEach((field: string) => {\n selection[field] = false;\n });\n }\n\n // Apply the selection to filters\n this.filters = {\n ...this.filters,\n select: selection,\n };\n\n // Remove the include filter as it's now part of select\n if (this.filters.include) {\n delete this.filters.include;\n }\n }\n\n // Remove any references to the now-unused parameters\n if (this.searchParams?.addFields || this.searchParams?.removeFields) {\n throw new AppError(\n \"The addFields and removeFields parameters are deprecated. Please use fields with + and - prefixes instead.\",\n 400\n );\n }\n\n return this;\n }\n\n paginate() {\n const page = parseInt(this.searchParams.page, 10) || 1;\n const limit = parseInt(this.searchParams.limit, 10) || 30;\n const skip = (page - 1) * limit;\n\n this.filters = {\n ...this.filters,\n skip,\n take: limit,\n };\n return this;\n }\n}\n\nexport const apiFeatures = new APIFeatures();\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"global.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/global.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,wCASC;AAED,sBAGC;AAED,oCAaC;AAQD,8EAaC;AAxDD,4CAAoB;AACpB,gDAAwB;AACxB,mCAAuC;AACvC,6BAAoC;AAGpC,SAAgB,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACzD,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAED,SAAgB,KAAK;IACnB,MAAM,GAAG,GAAG,cAAc,EAAE,CAAC;IAC7B,OAAO,GAAG,EAAE,IAAI,KAAK,QAAQ,CAAC;AAChC,CAAC;AAEM,KAAK,UAAU,YAAY,CAChC,UAAkB,EAClB,UAAqC,EAAE,YAAY,EAAE,IAAI,EAAE;IAE3D,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE;QACjE,OAAO,yBAAa,UAAU,uCAAC,CAAC;IAGlC,MAAM,WAAW,GAAG,IAAA,sBAAa,EAC/B,IAAA,mBAAa,EAAC,OAAO,CAAC,GAAG,EAAE,GAAG,eAAe,CAAC,CAC/C,CAAC;IACF,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACjD,OAAO,yBAAa,IAAA,mBAAa,EAAC,QAAQ,CAAQ,uCAAC,CAAC;AACtD,CAAC;AAQD,SAAgB,iCAAiC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC;IAE1D,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { createRequire } from \"module\";\nimport { pathToFileURL } from \"url\";\nimport { getUserFileExtension } from \"./fs.helpers\";\n\nexport function getPackageJson() {\n try {\n const pkgPath = path.join(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgPath)) {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n }\n } catch (err) {\n console.error(\"Error checking package.json:\", err);\n }\n}\n\nexport function isEsm() {\n const pkg = getPackageJson();\n return pkg?.type === \"module\";\n}\n\nexport async function importModule(\n modulePath: string,\n options: { fixExtension: boolean } = { fixExtension: true }\n) {\n if (!options.fixExtension || modulePath.endsWith(\".ts\") || !isEsm())\n return await import(modulePath);\n\n // When importing user modules: mainly on ESM environment\n const userRequire = createRequire(\n pathToFileURL(process.cwd() + \"/package.json\")\n );\n const resolved = userRequire.resolve(modulePath);\n return await import(pathToFileURL(resolved) as any);\n}\n\n/**\n * Helps getting the current package manager from user agent\n *\n * @returns {string} the package manager\n * @default \"npm\"\n */\nexport function detectPackageManagerFromUserAgent(): string {\n const userAgent = process.env.npm_config_user_agent || \"\";\n\n if (!userAgent) return \"npm\";\n if (userAgent.includes(\"cnpm\")) return \"cnpm\";\n if (userAgent.includes(\"pnpm\")) return \"pnpm\";\n if (userAgent.includes(\"yarn\")) return \"yarn\";\n if (userAgent.includes(\"npm\")) return \"npm\";\n if (userAgent.includes(\"bun\")) return \"bun\";\n if (userAgent.includes(\"corepack\")) return \"corepack\";\n if (userAgent.includes(\"deno\")) return \"deno\";\n\n return \"npm\";\n}\n"]}
1
+ {"version":3,"file":"global.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/global.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,wCASC;AAED,sBAGC;AAED,oCAaC;AAQD,8EAaC;AAvDD,4CAAoB;AACpB,gDAAwB;AACxB,mCAAuC;AACvC,6BAAoC;AAEpC,SAAgB,cAAc;IAC5B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACzD,IAAI,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M,CAAC;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IACtD,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { createRequire } from \"module\";\nimport { pathToFileURL } from \"url\";\n\nexport function getPackageJson() {\n try {\n const pkgPath = path.join(process.cwd(), \"package.json\");\n if (fs.existsSync(pkgPath)) {\n return JSON.parse(fs.readFileSync(pkgPath, \"utf8\"));\n }\n } catch (err) {\n console.error(\"Error checking package.json:\", err);\n }\n}\n\nexport function isEsm() {\n const pkg = getPackageJson();\n return pkg?.type === \"module\";\n}\n\nexport async function importModule(\n modulePath: string,\n options: { fixExtension: boolean } = { fixExtension: true }\n) {\n if (!options.fixExtension || modulePath.endsWith(\".ts\") || !isEsm())\n return await import(modulePath);\n\n // When importing user modules: mainly on ESM environment\n const userRequire = createRequire(\n pathToFileURL(process.cwd() + \"/package.json\")\n );\n const resolved = userRequire.resolve(modulePath);\n return await import(pathToFileURL(resolved) as any);\n}\n\n/**\n * Helps getting the current package manager from user agent\n *\n * @returns {string} the package manager\n * @default \"npm\"\n */\nexport function detectPackageManagerFromUserAgent(): string {\n const userAgent = process.env.npm_config_user_agent || \"\";\n\n if (!userAgent) return \"npm\";\n if (userAgent.includes(\"cnpm\")) return \"cnpm\";\n if (userAgent.includes(\"pnpm\")) return \"pnpm\";\n if (userAgent.includes(\"yarn\")) return \"yarn\";\n if (userAgent.includes(\"npm\")) return \"npm\";\n if (userAgent.includes(\"bun\")) return \"bun\";\n if (userAgent.includes(\"corepack\")) return \"corepack\";\n if (userAgent.includes(\"deno\")) return \"deno\";\n\n return \"npm\";\n}\n"]}
@@ -15,6 +15,7 @@ exports.getAllPrismaFiles = getAllPrismaFiles;
15
15
  exports.initializePrismaModels = initializePrismaModels;
16
16
  exports.getPrismaModelRelations = getPrismaModelRelations;
17
17
  exports.getPrismaSchemasContent = getPrismaSchemasContent;
18
+ exports.localValidatorFileExists = localValidatorFileExists;
18
19
  exports.getModels = getModels;
19
20
  exports.getModelUniqueFields = getModelUniqueFields;
20
21
  const path_1 = __importDefault(require("path"));
@@ -23,6 +24,7 @@ const change_case_helpers_1 = require("../../utils/helpers/change-case.helpers")
23
24
  const fs_helpers_1 = require("./fs.helpers");
24
25
  const global_helpers_1 = require("./global.helpers");
25
26
  const cli_helpers_1 = require("../cli/utils/cli.helpers");
27
+ const sheu_1 = __importDefault(require("../sheu"));
26
28
  let prismaModelsModules = {};
27
29
  function setModelModules(modelName, modules) {
28
30
  prismaModelsModules[(0, change_case_helpers_1.kebabCase)(modelName)] = modules;
@@ -49,35 +51,41 @@ function getFileModelModulesFileStructure(modelName) {
49
51
  ? {
50
52
  login: `login.dto.${ext}`,
51
53
  signup: `signup.dto.${ext}`,
54
+ getMe: `get-me.dto.${ext}`,
52
55
  updateMe: `update-me.dto.${ext}`,
53
56
  updatePassword: `update-password.dto.${ext}`,
54
57
  }
55
58
  : {
56
59
  model: `${kebabModelName}.dto.${ext}`,
57
60
  create: `create-${kebabModelName}.dto.${ext}`,
61
+ createOne: `create-${kebabModelName}.dto.${ext}`,
58
62
  createMany: `create-many-${kebabModelName}.dto.${ext}`,
59
63
  update: `update-${kebabModelName}.dto.${ext}`,
64
+ updateOne: `update-${kebabModelName}.dto.${ext}`,
60
65
  updateMany: `update-many-${kebabModelName}.dto.${ext}`,
66
+ query: `query-${kebabModelName}.dto.${ext}`,
61
67
  findOne: `find-one-${kebabModelName}.dto.${ext}`,
62
68
  findMany: `find-many-${kebabModelName}.dto.${ext}`,
63
- query: `query-${kebabModelName}.dto.${ext}`,
64
69
  },
65
70
  schemas: isAuthModule
66
71
  ? {
67
72
  login: `login.schema.${ext}`,
68
73
  signup: `signup.schema.${ext}`,
74
+ getMe: `get-me.schema.${ext}`,
69
75
  updateMe: `update-me.schema.${ext}`,
70
76
  updatePassword: `update-password.schema.${ext}`,
71
77
  }
72
78
  : {
73
79
  model: `${kebabModelName}.schema.${ext}`,
74
80
  create: `create-${kebabModelName}.schema.${ext}`,
81
+ createOne: `create-${kebabModelName}.schema.${ext}`,
75
82
  createMany: `create-many-${kebabModelName}.schema.${ext}`,
76
83
  update: `update-${kebabModelName}.schema.${ext}`,
84
+ updateOne: `update-${kebabModelName}.schema.${ext}`,
77
85
  updateMany: `update-many-${kebabModelName}.schema.${ext}`,
86
+ query: `query-${kebabModelName}.schema.${ext}`,
78
87
  findOne: `find-one-${kebabModelName}.schema.${ext}`,
79
88
  findMany: `find-many-${kebabModelName}.schema.${ext}`,
80
- query: `query-${kebabModelName}.schema.${ext}`,
81
89
  },
82
90
  };
83
91
  }
@@ -93,7 +101,14 @@ async function processSubdir(modelName, type) {
93
101
  await Promise.all(Object.entries(fileStructure[type]).map(async ([key, fileName]) => {
94
102
  const filePath = path_1.default.join(subdir, fileName);
95
103
  try {
96
- const module = await (0, global_helpers_1.importModule)(filePath).catch(() => null);
104
+ const module = await (0, global_helpers_1.importModule)(filePath).catch((err) => {
105
+ if (!err.message.includes("Cannot find module")) {
106
+ sheu_1.default.error(`Failed to import ${fileName}:`);
107
+ console.error(err);
108
+ (0, cli_helpers_1.killServerChildProcess)();
109
+ process.exit(1);
110
+ }
111
+ });
97
112
  if (module)
98
113
  result[key] = module.default;
99
114
  }
@@ -161,7 +176,7 @@ async function importPrismaModelModules(modelName, arkosConfig) {
161
176
  try {
162
177
  const module = await (0, global_helpers_1.importModule)(filePath).catch((err) => {
163
178
  if (!err.message.includes("Cannot find module")) {
164
- console.error(`Failed to import ${fileName}: \n`);
179
+ sheu_1.default.error(`Failed to import ${fileName}:`);
165
180
  console.error(err);
166
181
  (0, cli_helpers_1.killServerChildProcess)();
167
182
  process.exit(1);
@@ -215,22 +230,7 @@ const modelRegex = /model\s+(\w+)\s*{/g;
215
230
  exports.models = [];
216
231
  exports.prismaModelsUniqueFields = [];
217
232
  function initializePrismaModels() {
218
- const prismaContent = [];
219
- const files = getAllPrismaFiles("./prisma");
220
- for (const file of files) {
221
- const content = fs_1.default.readFileSync(file, "utf-8");
222
- if (!prismaContent?.includes?.(content))
223
- prismaContent.push(content);
224
- }
225
- const content = prismaContent
226
- .join("\n")
227
- .replace(modelRegex, (_, modelName) => {
228
- if (!exports.models?.includes?.(modelName))
229
- exports.models.push((0, change_case_helpers_1.camelCase)(modelName.trim()));
230
- return `model ${modelName} {`;
231
- });
232
- const copiedContent = content;
233
- exports.prismaSchemasContent = content;
233
+ const copiedContent = getPrismaSchemasContent();
234
234
  for (const model of exports.models) {
235
235
  const modelName = (0, change_case_helpers_1.pascalCase)(model);
236
236
  const modelStart = copiedContent.indexOf(`model ${modelName} {`);
@@ -309,9 +309,31 @@ function getModels() {
309
309
  return exports.models;
310
310
  }
311
311
  function getPrismaSchemasContent() {
312
- return exports.prismaSchemasContent;
312
+ if (exports.prismaSchemasContent)
313
+ return exports.prismaSchemasContent;
314
+ const prismaContent = [];
315
+ const files = getAllPrismaFiles("./prisma");
316
+ for (const file of files) {
317
+ const content = fs_1.default.readFileSync(file, "utf-8");
318
+ if (!prismaContent?.includes?.(content))
319
+ prismaContent.push(content);
320
+ }
321
+ const content = prismaContent
322
+ .join("\n")
323
+ .replace(modelRegex, (_, modelName) => {
324
+ if (!exports.models?.includes?.(modelName))
325
+ exports.models.push((0, change_case_helpers_1.camelCase)(modelName.trim()));
326
+ return `model ${modelName} {`;
327
+ });
328
+ return content;
313
329
  }
314
330
  function getModelUniqueFields(modelName) {
315
331
  return exports.prismaModelsUniqueFields[modelName];
316
332
  }
333
+ async function localValidatorFileExists(action, modelName, arkosConfig) {
334
+ if (arkosConfig?.swagger?.mode === "prisma")
335
+ return false;
336
+ const modelModules = await importPrismaModelModules(modelName, arkosConfig);
337
+ return !!modelModules?.[arkosConfig.validation?.resolver === "zod" ? "schemas" : "dtos"]?.[(0, change_case_helpers_1.camelCase)(action)];
338
+ }
317
339
  //# sourceMappingURL=models.helpers.js.map