@morojs/moro 1.6.0 → 1.6.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 (388) hide show
  1. package/README.md +256 -74
  2. package/dist/core/auth/morojs-adapter.js +20 -20
  3. package/dist/core/auth/morojs-adapter.js.map +1 -1
  4. package/dist/core/config/file-loader.d.ts +6 -1
  5. package/dist/core/config/file-loader.js +249 -19
  6. package/dist/core/config/file-loader.js.map +1 -1
  7. package/dist/core/config/index.d.ts +12 -41
  8. package/dist/core/config/index.js +54 -65
  9. package/dist/core/config/index.js.map +1 -1
  10. package/dist/core/config/loader.d.ts +7 -0
  11. package/dist/core/config/loader.js +269 -0
  12. package/dist/core/config/loader.js.map +1 -0
  13. package/dist/core/config/schema.d.ts +2 -2
  14. package/dist/core/config/schema.js +44 -52
  15. package/dist/core/config/schema.js.map +1 -1
  16. package/dist/core/config/utils.d.ts +3 -10
  17. package/dist/core/config/utils.js +58 -31
  18. package/dist/core/config/utils.js.map +1 -1
  19. package/dist/core/config/validation.d.ts +17 -0
  20. package/dist/core/config/validation.js +131 -0
  21. package/dist/core/config/validation.js.map +1 -0
  22. package/dist/core/database/adapters/drizzle.d.ts +1 -1
  23. package/dist/core/database/adapters/drizzle.js +11 -18
  24. package/dist/core/database/adapters/drizzle.js.map +1 -1
  25. package/dist/core/database/adapters/index.d.ts +7 -7
  26. package/dist/core/database/adapters/index.js +29 -19
  27. package/dist/core/database/adapters/index.js.map +1 -1
  28. package/dist/core/database/adapters/mongodb.d.ts +1 -13
  29. package/dist/core/database/adapters/mongodb.js +10 -46
  30. package/dist/core/database/adapters/mongodb.js.map +1 -1
  31. package/dist/core/database/adapters/mysql.d.ts +1 -14
  32. package/dist/core/database/adapters/mysql.js +9 -19
  33. package/dist/core/database/adapters/mysql.js.map +1 -1
  34. package/dist/core/database/adapters/postgresql.d.ts +2 -12
  35. package/dist/core/database/adapters/postgresql.js +9 -19
  36. package/dist/core/database/adapters/postgresql.js.map +1 -1
  37. package/dist/core/database/adapters/redis.d.ts +1 -12
  38. package/dist/core/database/adapters/redis.js +13 -48
  39. package/dist/core/database/adapters/redis.js.map +1 -1
  40. package/dist/core/database/adapters/sqlite.d.ts +1 -3
  41. package/dist/core/database/adapters/sqlite.js +8 -19
  42. package/dist/core/database/adapters/sqlite.js.map +1 -1
  43. package/dist/core/database/index.d.ts +2 -2
  44. package/dist/core/database/index.js +18 -2
  45. package/dist/core/database/index.js.map +1 -1
  46. package/dist/core/docs/index.d.ts +9 -9
  47. package/dist/core/docs/index.js +35 -14
  48. package/dist/core/docs/index.js.map +1 -1
  49. package/dist/core/docs/openapi-generator.d.ts +2 -2
  50. package/dist/core/docs/openapi-generator.js +16 -11
  51. package/dist/core/docs/openapi-generator.js.map +1 -1
  52. package/dist/core/docs/schema-to-openapi.d.ts +2 -2
  53. package/dist/core/docs/schema-to-openapi.js +11 -5
  54. package/dist/core/docs/schema-to-openapi.js.map +1 -1
  55. package/dist/core/docs/simple-docs.d.ts +1 -1
  56. package/dist/core/docs/simple-docs.js +9 -4
  57. package/dist/core/docs/simple-docs.js.map +1 -1
  58. package/dist/core/docs/swagger-ui.d.ts +2 -2
  59. package/dist/core/docs/swagger-ui.js +29 -26
  60. package/dist/core/docs/swagger-ui.js.map +1 -1
  61. package/dist/core/docs/zod-to-openapi.js +28 -31
  62. package/dist/core/docs/zod-to-openapi.js.map +1 -1
  63. package/dist/core/events/event-bus.d.ts +1 -1
  64. package/dist/core/events/event-bus.js +10 -6
  65. package/dist/core/events/event-bus.js.map +1 -1
  66. package/dist/core/events/index.d.ts +2 -2
  67. package/dist/core/events/index.js +5 -1
  68. package/dist/core/events/index.js.map +1 -1
  69. package/dist/core/framework.d.ts +12 -19
  70. package/dist/core/framework.js +100 -277
  71. package/dist/core/framework.js.map +1 -1
  72. package/dist/core/http/http-server.d.ts +1 -13
  73. package/dist/core/http/http-server.js +85 -175
  74. package/dist/core/http/http-server.js.map +1 -1
  75. package/dist/core/http/index.d.ts +3 -4
  76. package/dist/core/http/index.js +8 -3
  77. package/dist/core/http/index.js.map +1 -1
  78. package/dist/core/http/router.d.ts +1 -13
  79. package/dist/core/http/router.js +43 -117
  80. package/dist/core/http/router.js.map +1 -1
  81. package/dist/core/logger/filters.d.ts +1 -1
  82. package/dist/core/logger/filters.js +23 -20
  83. package/dist/core/logger/filters.js.map +1 -1
  84. package/dist/core/logger/index.d.ts +3 -3
  85. package/dist/core/logger/index.js +24 -2
  86. package/dist/core/logger/index.js.map +1 -1
  87. package/dist/core/logger/logger.d.ts +14 -30
  88. package/dist/core/logger/logger.js +223 -398
  89. package/dist/core/logger/logger.js.map +1 -1
  90. package/dist/core/logger/outputs.d.ts +1 -1
  91. package/dist/core/logger/outputs.js +17 -8
  92. package/dist/core/logger/outputs.js.map +1 -1
  93. package/dist/core/middleware/built-in/adapters/cache/file.d.ts +1 -1
  94. package/dist/core/middleware/built-in/adapters/cache/file.js +47 -10
  95. package/dist/core/middleware/built-in/adapters/cache/file.js.map +1 -1
  96. package/dist/core/middleware/built-in/adapters/cache/index.d.ts +4 -4
  97. package/dist/core/middleware/built-in/adapters/cache/index.js +17 -10
  98. package/dist/core/middleware/built-in/adapters/cache/index.js.map +1 -1
  99. package/dist/core/middleware/built-in/adapters/cache/memory.d.ts +1 -1
  100. package/dist/core/middleware/built-in/adapters/cache/memory.js +7 -3
  101. package/dist/core/middleware/built-in/adapters/cache/memory.js.map +1 -1
  102. package/dist/core/middleware/built-in/adapters/cache/redis.d.ts +1 -3
  103. package/dist/core/middleware/built-in/adapters/cache/redis.js +9 -11
  104. package/dist/core/middleware/built-in/adapters/cache/redis.js.map +1 -1
  105. package/dist/core/middleware/built-in/adapters/cdn/azure.d.ts +1 -1
  106. package/dist/core/middleware/built-in/adapters/cdn/azure.js +7 -3
  107. package/dist/core/middleware/built-in/adapters/cdn/azure.js.map +1 -1
  108. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.d.ts +1 -1
  109. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js +7 -3
  110. package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js.map +1 -1
  111. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.d.ts +1 -3
  112. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js +10 -12
  113. package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js.map +1 -1
  114. package/dist/core/middleware/built-in/adapters/cdn/index.d.ts +4 -4
  115. package/dist/core/middleware/built-in/adapters/cdn/index.js +17 -10
  116. package/dist/core/middleware/built-in/adapters/cdn/index.js.map +1 -1
  117. package/dist/core/middleware/built-in/adapters/index.d.ts +4 -4
  118. package/dist/core/middleware/built-in/adapters/index.js +23 -4
  119. package/dist/core/middleware/built-in/adapters/index.js.map +1 -1
  120. package/dist/core/middleware/built-in/auth-helpers.js +22 -11
  121. package/dist/core/middleware/built-in/auth-helpers.js.map +1 -1
  122. package/dist/core/middleware/built-in/auth-providers.d.ts +1 -1
  123. package/dist/core/middleware/built-in/auth-providers.js +9 -4
  124. package/dist/core/middleware/built-in/auth-providers.js.map +1 -1
  125. package/dist/core/middleware/built-in/auth.d.ts +2 -2
  126. package/dist/core/middleware/built-in/auth.js +26 -93
  127. package/dist/core/middleware/built-in/auth.js.map +1 -1
  128. package/dist/core/middleware/built-in/cache.d.ts +2 -2
  129. package/dist/core/middleware/built-in/cache.js +12 -11
  130. package/dist/core/middleware/built-in/cache.js.map +1 -1
  131. package/dist/core/middleware/built-in/cdn.d.ts +2 -2
  132. package/dist/core/middleware/built-in/cdn.js +9 -5
  133. package/dist/core/middleware/built-in/cdn.js.map +1 -1
  134. package/dist/core/middleware/built-in/cookie.d.ts +1 -1
  135. package/dist/core/middleware/built-in/cookie.js +7 -3
  136. package/dist/core/middleware/built-in/cookie.js.map +1 -1
  137. package/dist/core/middleware/built-in/cors.d.ts +1 -1
  138. package/dist/core/middleware/built-in/cors.js +7 -3
  139. package/dist/core/middleware/built-in/cors.js.map +1 -1
  140. package/dist/core/middleware/built-in/csp.d.ts +1 -1
  141. package/dist/core/middleware/built-in/csp.js +8 -5
  142. package/dist/core/middleware/built-in/csp.js.map +1 -1
  143. package/dist/core/middleware/built-in/csrf.d.ts +1 -1
  144. package/dist/core/middleware/built-in/csrf.js +8 -5
  145. package/dist/core/middleware/built-in/csrf.js.map +1 -1
  146. package/dist/core/middleware/built-in/error-tracker.js +7 -3
  147. package/dist/core/middleware/built-in/error-tracker.js.map +1 -1
  148. package/dist/core/middleware/built-in/index.d.ts +27 -28
  149. package/dist/core/middleware/built-in/index.js +78 -48
  150. package/dist/core/middleware/built-in/index.js.map +1 -1
  151. package/dist/core/middleware/built-in/performance-monitor.js +7 -3
  152. package/dist/core/middleware/built-in/performance-monitor.js.map +1 -1
  153. package/dist/core/middleware/built-in/rate-limit.d.ts +1 -1
  154. package/dist/core/middleware/built-in/rate-limit.js +7 -3
  155. package/dist/core/middleware/built-in/rate-limit.js.map +1 -1
  156. package/dist/core/middleware/built-in/request-logger.js +8 -5
  157. package/dist/core/middleware/built-in/request-logger.js.map +1 -1
  158. package/dist/core/middleware/built-in/session.d.ts +2 -2
  159. package/dist/core/middleware/built-in/session.js +15 -11
  160. package/dist/core/middleware/built-in/session.js.map +1 -1
  161. package/dist/core/middleware/built-in/sse.d.ts +1 -1
  162. package/dist/core/middleware/built-in/sse.js +14 -12
  163. package/dist/core/middleware/built-in/sse.js.map +1 -1
  164. package/dist/core/middleware/built-in/validation.d.ts +1 -1
  165. package/dist/core/middleware/built-in/validation.js +7 -3
  166. package/dist/core/middleware/built-in/validation.js.map +1 -1
  167. package/dist/core/middleware/index.d.ts +4 -4
  168. package/dist/core/middleware/index.js +28 -8
  169. package/dist/core/middleware/index.js.map +1 -1
  170. package/dist/core/modules/auto-discovery.d.ts +2 -19
  171. package/dist/core/modules/auto-discovery.js +74 -391
  172. package/dist/core/modules/auto-discovery.js.map +1 -1
  173. package/dist/core/modules/index.d.ts +2 -2
  174. package/dist/core/modules/index.js +9 -2
  175. package/dist/core/modules/index.js.map +1 -1
  176. package/dist/core/modules/modules.d.ts +3 -3
  177. package/dist/core/modules/modules.js +54 -23
  178. package/dist/core/modules/modules.js.map +1 -1
  179. package/dist/core/networking/adapters/index.d.ts +3 -4
  180. package/dist/core/networking/adapters/index.js +7 -3
  181. package/dist/core/networking/adapters/index.js.map +1 -1
  182. package/dist/core/networking/adapters/socketio-adapter.d.ts +1 -1
  183. package/dist/core/networking/adapters/socketio-adapter.js +40 -5
  184. package/dist/core/networking/adapters/socketio-adapter.js.map +1 -1
  185. package/dist/core/networking/adapters/ws-adapter.d.ts +2 -2
  186. package/dist/core/networking/adapters/ws-adapter.js +43 -8
  187. package/dist/core/networking/adapters/ws-adapter.js.map +1 -1
  188. package/dist/core/networking/index.d.ts +2 -3
  189. package/dist/core/networking/index.js +7 -2
  190. package/dist/core/networking/index.js.map +1 -1
  191. package/dist/core/networking/service-discovery.js +12 -8
  192. package/dist/core/networking/service-discovery.js.map +1 -1
  193. package/dist/core/networking/websocket-adapter.js +2 -1
  194. package/dist/core/networking/websocket-adapter.js.map +1 -1
  195. package/dist/core/networking/websocket-manager.d.ts +3 -3
  196. package/dist/core/networking/websocket-manager.js +11 -9
  197. package/dist/core/networking/websocket-manager.js.map +1 -1
  198. package/dist/core/routing/app-integration.d.ts +2 -2
  199. package/dist/core/routing/app-integration.js +12 -7
  200. package/dist/core/routing/app-integration.js.map +1 -1
  201. package/dist/core/routing/index.d.ts +2 -22
  202. package/dist/core/routing/index.js +27 -185
  203. package/dist/core/routing/index.js.map +1 -1
  204. package/dist/core/runtime/aws-lambda-adapter.d.ts +3 -3
  205. package/dist/core/runtime/aws-lambda-adapter.js +6 -2
  206. package/dist/core/runtime/aws-lambda-adapter.js.map +1 -1
  207. package/dist/core/runtime/base-adapter.d.ts +2 -2
  208. package/dist/core/runtime/base-adapter.js +7 -3
  209. package/dist/core/runtime/base-adapter.js.map +1 -1
  210. package/dist/core/runtime/cloudflare-workers-adapter.d.ts +3 -3
  211. package/dist/core/runtime/cloudflare-workers-adapter.js +6 -2
  212. package/dist/core/runtime/cloudflare-workers-adapter.js.map +1 -1
  213. package/dist/core/runtime/index.d.ts +12 -12
  214. package/dist/core/runtime/index.js +35 -22
  215. package/dist/core/runtime/index.js.map +1 -1
  216. package/dist/core/runtime/node-adapter.d.ts +4 -4
  217. package/dist/core/runtime/node-adapter.js +49 -18
  218. package/dist/core/runtime/node-adapter.js.map +1 -1
  219. package/dist/core/runtime/vercel-edge-adapter.d.ts +3 -3
  220. package/dist/core/runtime/vercel-edge-adapter.js +6 -2
  221. package/dist/core/runtime/vercel-edge-adapter.js.map +1 -1
  222. package/dist/core/utilities/circuit-breaker.js +5 -1
  223. package/dist/core/utilities/circuit-breaker.js.map +1 -1
  224. package/dist/core/utilities/container.js +22 -12
  225. package/dist/core/utilities/container.js.map +1 -1
  226. package/dist/core/utilities/hooks.d.ts +2 -2
  227. package/dist/core/utilities/hooks.js +12 -7
  228. package/dist/core/utilities/hooks.js.map +1 -1
  229. package/dist/core/utilities/index.d.ts +4 -5
  230. package/dist/core/utilities/index.js +19 -5
  231. package/dist/core/utilities/index.js.map +1 -1
  232. package/dist/core/validation/adapters.d.ts +1 -1
  233. package/dist/core/validation/adapters.js +26 -15
  234. package/dist/core/validation/adapters.js.map +1 -1
  235. package/dist/core/validation/index.d.ts +4 -6
  236. package/dist/core/validation/index.js +28 -57
  237. package/dist/core/validation/index.js.map +1 -1
  238. package/dist/core/validation/schema-interface.js +9 -3
  239. package/dist/core/validation/schema-interface.js.map +1 -1
  240. package/dist/index.d.ts +52 -51
  241. package/dist/index.js +132 -23
  242. package/dist/index.js.map +1 -1
  243. package/dist/moro.d.ts +10 -61
  244. package/dist/moro.js +237 -575
  245. package/dist/moro.js.map +1 -1
  246. package/dist/types/auth.js +9 -3
  247. package/dist/types/auth.js.map +1 -1
  248. package/dist/types/cache.js +2 -1
  249. package/dist/types/cdn.js +2 -1
  250. package/dist/types/config.d.ts +2 -70
  251. package/dist/types/config.js +2 -1
  252. package/dist/types/config.js.map +1 -1
  253. package/dist/types/core.d.ts +42 -36
  254. package/dist/types/core.js +2 -1
  255. package/dist/types/database.js +2 -1
  256. package/dist/types/discovery.js +2 -1
  257. package/dist/types/events.js +2 -1
  258. package/dist/types/hooks.d.ts +1 -1
  259. package/dist/types/hooks.js +2 -1
  260. package/dist/types/http.d.ts +1 -16
  261. package/dist/types/http.js +2 -1
  262. package/dist/types/logger.d.ts +0 -7
  263. package/dist/types/logger.js +2 -1
  264. package/dist/types/module.d.ts +0 -11
  265. package/dist/types/module.js +2 -1
  266. package/dist/types/runtime.d.ts +1 -1
  267. package/dist/types/runtime.js +2 -1
  268. package/dist/types/session.js +2 -1
  269. package/package.json +52 -19
  270. package/src/core/auth/morojs-adapter.ts +13 -18
  271. package/src/core/config/file-loader.ts +273 -13
  272. package/src/core/config/index.ts +34 -83
  273. package/src/core/config/loader.ts +633 -0
  274. package/src/core/config/schema.ts +33 -44
  275. package/src/core/config/utils.ts +31 -24
  276. package/src/core/config/validation.ts +140 -0
  277. package/src/core/database/README.md +16 -26
  278. package/src/core/database/adapters/drizzle.ts +6 -18
  279. package/src/core/database/adapters/index.ts +13 -13
  280. package/src/core/database/adapters/mongodb.ts +5 -53
  281. package/src/core/database/adapters/mysql.ts +4 -32
  282. package/src/core/database/adapters/postgresql.ts +5 -30
  283. package/src/core/database/adapters/redis.ts +8 -61
  284. package/src/core/database/adapters/sqlite.ts +3 -19
  285. package/src/core/database/index.ts +2 -2
  286. package/src/core/docs/index.ts +8 -8
  287. package/src/core/docs/openapi-generator.ts +4 -4
  288. package/src/core/docs/schema-to-openapi.ts +6 -3
  289. package/src/core/docs/simple-docs.ts +2 -2
  290. package/src/core/docs/swagger-ui.ts +16 -19
  291. package/src/core/docs/zod-to-openapi.ts +34 -34
  292. package/src/core/events/event-bus.ts +2 -2
  293. package/src/core/events/index.ts +2 -2
  294. package/src/core/framework.ts +67 -311
  295. package/src/core/http/http-server.ts +45 -190
  296. package/src/core/http/index.ts +3 -4
  297. package/src/core/http/router.ts +40 -129
  298. package/src/core/logger/filters.ts +5 -13
  299. package/src/core/logger/index.ts +3 -4
  300. package/src/core/logger/logger.ts +216 -435
  301. package/src/core/logger/outputs.ts +3 -1
  302. package/src/core/middleware/built-in/adapters/cache/file.ts +3 -3
  303. package/src/core/middleware/built-in/adapters/cache/index.ts +7 -7
  304. package/src/core/middleware/built-in/adapters/cache/memory.ts +2 -2
  305. package/src/core/middleware/built-in/adapters/cache/redis.ts +4 -18
  306. package/src/core/middleware/built-in/adapters/cdn/azure.ts +2 -2
  307. package/src/core/middleware/built-in/adapters/cdn/cloudflare.ts +2 -2
  308. package/src/core/middleware/built-in/adapters/cdn/cloudfront.ts +5 -16
  309. package/src/core/middleware/built-in/adapters/cdn/index.ts +7 -7
  310. package/src/core/middleware/built-in/adapters/index.ts +4 -4
  311. package/src/core/middleware/built-in/auth-helpers.ts +1 -1
  312. package/src/core/middleware/built-in/auth-providers.ts +1 -1
  313. package/src/core/middleware/built-in/auth.ts +21 -102
  314. package/src/core/middleware/built-in/cache.ts +6 -8
  315. package/src/core/middleware/built-in/cdn.ts +4 -4
  316. package/src/core/middleware/built-in/cookie.ts +2 -2
  317. package/src/core/middleware/built-in/cors.ts +2 -2
  318. package/src/core/middleware/built-in/csp.ts +3 -3
  319. package/src/core/middleware/built-in/csrf.ts +3 -3
  320. package/src/core/middleware/built-in/error-tracker.ts +1 -1
  321. package/src/core/middleware/built-in/index.ts +30 -38
  322. package/src/core/middleware/built-in/performance-monitor.ts +1 -1
  323. package/src/core/middleware/built-in/rate-limit.ts +2 -2
  324. package/src/core/middleware/built-in/request-logger.ts +1 -3
  325. package/src/core/middleware/built-in/session.ts +8 -7
  326. package/src/core/middleware/built-in/sse.ts +9 -11
  327. package/src/core/middleware/built-in/validation.ts +2 -2
  328. package/src/core/middleware/index.ts +6 -6
  329. package/src/core/modules/auto-discovery.ts +15 -478
  330. package/src/core/modules/index.ts +2 -2
  331. package/src/core/modules/modules.ts +12 -23
  332. package/src/core/networking/adapters/index.ts +3 -4
  333. package/src/core/networking/adapters/socketio-adapter.ts +3 -5
  334. package/src/core/networking/adapters/ws-adapter.ts +9 -8
  335. package/src/core/networking/index.ts +2 -3
  336. package/src/core/networking/service-discovery.ts +7 -6
  337. package/src/core/networking/websocket-manager.ts +7 -7
  338. package/src/core/routing/app-integration.ts +3 -3
  339. package/src/core/routing/index.ts +17 -201
  340. package/src/core/runtime/aws-lambda-adapter.ts +3 -3
  341. package/src/core/runtime/base-adapter.ts +2 -2
  342. package/src/core/runtime/cloudflare-workers-adapter.ts +3 -3
  343. package/src/core/runtime/index.ts +13 -13
  344. package/src/core/runtime/node-adapter.ts +10 -16
  345. package/src/core/runtime/vercel-edge-adapter.ts +3 -3
  346. package/src/core/utilities/hooks.ts +3 -3
  347. package/src/core/utilities/index.ts +4 -5
  348. package/src/core/validation/adapters.ts +1 -1
  349. package/src/core/validation/index.ts +16 -68
  350. package/src/index.ts +66 -73
  351. package/src/moro.ts +204 -685
  352. package/src/types/config.ts +2 -71
  353. package/src/types/core.ts +47 -49
  354. package/src/types/hooks.ts +1 -1
  355. package/src/types/http.ts +1 -23
  356. package/src/types/logger.ts +0 -9
  357. package/src/types/module.ts +0 -12
  358. package/src/types/runtime.ts +1 -1
  359. package/tsconfig.json +2 -4
  360. package/dist/core/config/config-manager.d.ts +0 -44
  361. package/dist/core/config/config-manager.js +0 -104
  362. package/dist/core/config/config-manager.js.map +0 -1
  363. package/dist/core/config/config-sources.d.ts +0 -21
  364. package/dist/core/config/config-sources.js +0 -499
  365. package/dist/core/config/config-sources.js.map +0 -1
  366. package/dist/core/config/config-validator.d.ts +0 -21
  367. package/dist/core/config/config-validator.js +0 -788
  368. package/dist/core/config/config-validator.js.map +0 -1
  369. package/dist/core/http/uws-http-server.d.ts +0 -64
  370. package/dist/core/http/uws-http-server.js +0 -688
  371. package/dist/core/http/uws-http-server.js.map +0 -1
  372. package/dist/core/middleware/built-in/jwt-helpers.d.ts +0 -118
  373. package/dist/core/middleware/built-in/jwt-helpers.js +0 -218
  374. package/dist/core/middleware/built-in/jwt-helpers.js.map +0 -1
  375. package/dist/core/networking/adapters/uws-adapter.d.ts +0 -44
  376. package/dist/core/networking/adapters/uws-adapter.js +0 -513
  377. package/dist/core/networking/adapters/uws-adapter.js.map +0 -1
  378. package/dist/core/utilities/package-utils.d.ts +0 -38
  379. package/dist/core/utilities/package-utils.js +0 -57
  380. package/dist/core/utilities/package-utils.js.map +0 -1
  381. package/jest.config.mjs +0 -41
  382. package/src/core/config/config-manager.ts +0 -133
  383. package/src/core/config/config-sources.ts +0 -596
  384. package/src/core/config/config-validator.ts +0 -1113
  385. package/src/core/http/uws-http-server.ts +0 -794
  386. package/src/core/middleware/built-in/jwt-helpers.ts +0 -243
  387. package/src/core/networking/adapters/uws-adapter.ts +0 -619
  388. package/src/core/utilities/package-utils.ts +0 -59
@@ -1,788 +0,0 @@
1
- /**
2
- * Configuration Validator - Type-Safe Schema Validation
3
- *
4
- * This module provides runtime validation for configuration objects using
5
- * simple TypeScript functions that match the type definitions exactly.
6
- */
7
- import { createFrameworkLogger } from '../logger/index.js';
8
- const logger = createFrameworkLogger('ConfigValidator');
9
- /**
10
- * Configuration validation error with detailed context
11
- */
12
- export class ConfigValidationError extends Error {
13
- field;
14
- value;
15
- expectedType;
16
- constructor(field, value, expectedType, message) {
17
- super(`Configuration validation failed for '${field}': ${message}`);
18
- this.field = field;
19
- this.value = value;
20
- this.expectedType = expectedType;
21
- this.name = 'ConfigValidationError';
22
- }
23
- }
24
- /**
25
- * Validate and normalize a complete configuration object
26
- * This ensures type safety and provides helpful error messages
27
- */
28
- export function validateConfig(config) {
29
- logger.debug('Validating configuration');
30
- try {
31
- const validatedConfig = {
32
- server: validateServerConfig(config.server, 'server'),
33
- serviceDiscovery: validateServiceDiscoveryConfig(config.serviceDiscovery, 'serviceDiscovery'),
34
- database: validateDatabaseConfig(config.database, 'database'),
35
- modules: validateModuleDefaultsConfig(config.modules, 'modules'),
36
- logging: validateLoggingConfig(config.logging, 'logging'),
37
- security: validateSecurityConfig(config.security, 'security'),
38
- external: validateExternalServicesConfig(config.external, 'external'),
39
- performance: validatePerformanceConfig(config.performance, 'performance'),
40
- websocket: validateWebSocketConfig(config.websocket, 'websocket'),
41
- };
42
- logger.debug('Configuration validation successful');
43
- return validatedConfig;
44
- }
45
- catch (error) {
46
- if (error instanceof ConfigValidationError) {
47
- logger.error(`❌ Configuration validation failed for '${error.field}':`, error.message);
48
- // Provide helpful hints
49
- provideValidationHints(error);
50
- throw error;
51
- }
52
- logger.error('❌ Unexpected configuration validation error:', String(error));
53
- throw new Error(`Configuration validation failed: ${String(error)}`);
54
- }
55
- }
56
- /**
57
- * Validate server configuration
58
- */
59
- function validateServerConfig(config, path) {
60
- if (!config || typeof config !== 'object') {
61
- throw new ConfigValidationError(path, config, 'object', 'Server configuration must be an object');
62
- }
63
- const result = {
64
- port: validatePort(config.port, `${path}.port`),
65
- host: validateString(config.host, `${path}.host`),
66
- maxConnections: validateNumber(config.maxConnections, `${path}.maxConnections`, { min: 1 }),
67
- timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
68
- bodySizeLimit: validateString(config.bodySizeLimit, `${path}.bodySizeLimit`),
69
- requestTracking: {
70
- enabled: validateBoolean(config.requestTracking?.enabled, `${path}.requestTracking.enabled`),
71
- },
72
- errorBoundary: {
73
- enabled: validateBoolean(config.errorBoundary?.enabled, `${path}.errorBoundary.enabled`),
74
- },
75
- };
76
- // Optional uWebSockets configuration
77
- if (config.useUWebSockets !== undefined) {
78
- result.useUWebSockets = validateBoolean(config.useUWebSockets, `${path}.useUWebSockets`);
79
- }
80
- // Optional SSL configuration
81
- if (config.ssl !== undefined) {
82
- result.ssl = validateSSLConfig(config.ssl, `${path}.ssl`);
83
- }
84
- return result;
85
- }
86
- /**
87
- * Validate SSL configuration
88
- */
89
- function validateSSLConfig(config, path) {
90
- if (!config || typeof config !== 'object') {
91
- throw new ConfigValidationError(path, config, 'object', 'SSL configuration must be an object');
92
- }
93
- const result = {};
94
- if (config.key_file_name !== undefined) {
95
- result.key_file_name = validateString(config.key_file_name, `${path}.key_file_name`);
96
- }
97
- if (config.cert_file_name !== undefined) {
98
- result.cert_file_name = validateString(config.cert_file_name, `${path}.cert_file_name`);
99
- }
100
- if (config.passphrase !== undefined) {
101
- result.passphrase = validateString(config.passphrase, `${path}.passphrase`);
102
- }
103
- return result;
104
- }
105
- /**
106
- * Validate service discovery configuration
107
- */
108
- function validateServiceDiscoveryConfig(config, path) {
109
- if (!config || typeof config !== 'object') {
110
- throw new ConfigValidationError(path, config, 'object', 'Service discovery configuration must be an object');
111
- }
112
- return {
113
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
114
- type: validateEnum(config.type, ['memory', 'consul', 'kubernetes'], `${path}.type`),
115
- consulUrl: validateString(config.consulUrl, `${path}.consulUrl`),
116
- kubernetesNamespace: validateString(config.kubernetesNamespace, `${path}.kubernetesNamespace`),
117
- healthCheckInterval: validateNumber(config.healthCheckInterval, `${path}.healthCheckInterval`, {
118
- min: 1000,
119
- }),
120
- retryAttempts: validateNumber(config.retryAttempts, `${path}.retryAttempts`, { min: 0 }),
121
- };
122
- }
123
- /**
124
- * Validate database configuration
125
- */
126
- function validateDatabaseConfig(config, path) {
127
- if (!config || typeof config !== 'object') {
128
- throw new ConfigValidationError(path, config, 'object', 'Database configuration must be an object');
129
- }
130
- const result = {};
131
- // Optional URL
132
- if (config.url !== undefined) {
133
- result.url = validateString(config.url, `${path}.url`);
134
- }
135
- // Optional Redis - only validate if present
136
- if (config.redis !== undefined) {
137
- result.redis = validateRedisConfig(config.redis, `${path}.redis`);
138
- }
139
- // Optional MySQL - only validate if present
140
- if (config.mysql !== undefined) {
141
- result.mysql = validateMySQLConfig(config.mysql, `${path}.mysql`);
142
- }
143
- // Optional PostgreSQL - only validate if present
144
- if (config.postgresql !== undefined) {
145
- result.postgresql = validatePostgreSQLConfig(config.postgresql, `${path}.postgresql`);
146
- }
147
- // Optional SQLite - only validate if present
148
- if (config.sqlite !== undefined) {
149
- result.sqlite = validateSQLiteConfig(config.sqlite, `${path}.sqlite`);
150
- }
151
- // Optional MongoDB - only validate if present
152
- if (config.mongodb !== undefined) {
153
- result.mongodb = validateMongoDBConfig(config.mongodb, `${path}.mongodb`);
154
- }
155
- return result;
156
- }
157
- /**
158
- * Validate Redis configuration
159
- */
160
- function validateRedisConfig(config, path) {
161
- if (!config || typeof config !== 'object') {
162
- throw new ConfigValidationError(path, config, 'object', 'Redis configuration must be an object');
163
- }
164
- return {
165
- url: validateString(config.url, `${path}.url`),
166
- maxRetries: validateNumber(config.maxRetries, `${path}.maxRetries`, { min: 0 }),
167
- retryDelay: validateNumber(config.retryDelay, `${path}.retryDelay`, { min: 0 }),
168
- keyPrefix: validateString(config.keyPrefix, `${path}.keyPrefix`),
169
- };
170
- }
171
- /**
172
- * Validate MySQL configuration
173
- */
174
- function validateMySQLConfig(config, path) {
175
- if (!config || typeof config !== 'object') {
176
- throw new ConfigValidationError(path, config, 'object', 'MySQL configuration must be an object');
177
- }
178
- const result = {
179
- host: validateString(config.host, `${path}.host`),
180
- port: validatePort(config.port, `${path}.port`),
181
- connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
182
- acquireTimeout: validateNumber(config.acquireTimeout, `${path}.acquireTimeout`, { min: 1000 }),
183
- timeout: validateNumber(config.timeout, `${path}.timeout`, { min: 1000 }),
184
- };
185
- // Optional fields
186
- if (config.database !== undefined) {
187
- result.database = validateString(config.database, `${path}.database`);
188
- }
189
- if (config.username !== undefined) {
190
- result.username = validateString(config.username, `${path}.username`);
191
- }
192
- if (config.password !== undefined) {
193
- result.password = validateString(config.password, `${path}.password`);
194
- }
195
- return result;
196
- }
197
- /**
198
- * Validate PostgreSQL configuration
199
- */
200
- function validatePostgreSQLConfig(config, path) {
201
- if (!config || typeof config !== 'object') {
202
- throw new ConfigValidationError(path, config, 'object', 'PostgreSQL configuration must be an object');
203
- }
204
- const result = {
205
- host: validateString(config.host, `${path}.host`),
206
- port: validatePort(config.port, `${path}.port`),
207
- connectionLimit: validateNumber(config.connectionLimit, `${path}.connectionLimit`, { min: 1 }),
208
- };
209
- // Optional fields
210
- if (config.database !== undefined) {
211
- result.database = validateString(config.database, `${path}.database`);
212
- }
213
- if (config.user !== undefined) {
214
- result.user = validateString(config.user, `${path}.user`);
215
- }
216
- if (config.password !== undefined) {
217
- result.password = validateString(config.password, `${path}.password`);
218
- }
219
- if (config.ssl !== undefined) {
220
- result.ssl = validateBoolean(config.ssl, `${path}.ssl`);
221
- }
222
- return result;
223
- }
224
- /**
225
- * Validate SQLite configuration
226
- */
227
- function validateSQLiteConfig(config, path) {
228
- if (!config || typeof config !== 'object') {
229
- throw new ConfigValidationError(path, config, 'object', 'SQLite configuration must be an object');
230
- }
231
- const result = {
232
- filename: validateString(config.filename, `${path}.filename`),
233
- };
234
- // Optional fields
235
- if (config.memory !== undefined) {
236
- result.memory = validateBoolean(config.memory, `${path}.memory`);
237
- }
238
- if (config.verbose !== undefined) {
239
- result.verbose = validateBoolean(config.verbose, `${path}.verbose`);
240
- }
241
- return result;
242
- }
243
- /**
244
- * Validate MongoDB configuration
245
- */
246
- function validateMongoDBConfig(config, path) {
247
- if (!config || typeof config !== 'object') {
248
- throw new ConfigValidationError(path, config, 'object', 'MongoDB configuration must be an object');
249
- }
250
- const result = {};
251
- // Either url or host+port
252
- if (config.url !== undefined) {
253
- result.url = validateString(config.url, `${path}.url`);
254
- }
255
- if (config.host !== undefined) {
256
- result.host = validateString(config.host, `${path}.host`);
257
- }
258
- if (config.port !== undefined) {
259
- result.port = validatePort(config.port, `${path}.port`);
260
- }
261
- if (config.database !== undefined) {
262
- result.database = validateString(config.database, `${path}.database`);
263
- }
264
- if (config.username !== undefined) {
265
- result.username = validateString(config.username, `${path}.username`);
266
- }
267
- if (config.password !== undefined) {
268
- result.password = validateString(config.password, `${path}.password`);
269
- }
270
- return result;
271
- }
272
- /**
273
- * Validate module defaults configuration
274
- */
275
- function validateModuleDefaultsConfig(config, path) {
276
- if (!config || typeof config !== 'object') {
277
- throw new ConfigValidationError(path, config, 'object', 'Module defaults configuration must be an object');
278
- }
279
- return {
280
- cache: validateCacheConfig(config.cache, `${path}.cache`),
281
- rateLimit: validateRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
282
- validation: validateValidationConfig(config.validation, `${path}.validation`),
283
- autoDiscovery: validateAutoDiscoveryConfig(config.autoDiscovery, `${path}.autoDiscovery`),
284
- };
285
- }
286
- /**
287
- * Validate auto-discovery configuration
288
- */
289
- function validateAutoDiscoveryConfig(config, path) {
290
- if (!config || typeof config !== 'object') {
291
- throw new ConfigValidationError(path, config, 'object', 'Auto-discovery configuration must be an object');
292
- }
293
- return {
294
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
295
- paths: validateStringArray(config.paths, `${path}.paths`),
296
- patterns: validateStringArray(config.patterns, `${path}.patterns`),
297
- recursive: validateBoolean(config.recursive, `${path}.recursive`),
298
- loadingStrategy: validateEnum(config.loadingStrategy, ['eager', 'lazy', 'conditional'], `${path}.loadingStrategy`),
299
- watchForChanges: validateBoolean(config.watchForChanges, `${path}.watchForChanges`),
300
- ignorePatterns: validateStringArray(config.ignorePatterns, `${path}.ignorePatterns`),
301
- loadOrder: validateEnum(config.loadOrder, ['alphabetical', 'dependency', 'custom'], `${path}.loadOrder`),
302
- failOnError: validateBoolean(config.failOnError, `${path}.failOnError`),
303
- maxDepth: validateNumber(config.maxDepth, `${path}.maxDepth`),
304
- };
305
- }
306
- /**
307
- * Validate cache configuration
308
- */
309
- function validateCacheConfig(config, path) {
310
- if (!config || typeof config !== 'object') {
311
- throw new ConfigValidationError(path, config, 'object', 'Cache configuration must be an object');
312
- }
313
- return {
314
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
315
- defaultTtl: validateNumber(config.defaultTtl, `${path}.defaultTtl`, { min: 0 }),
316
- maxSize: validateNumber(config.maxSize, `${path}.maxSize`, { min: 1 }),
317
- strategy: validateEnum(config.strategy, ['lru', 'lfu', 'fifo'], `${path}.strategy`),
318
- };
319
- }
320
- /**
321
- * Validate rate limit configuration
322
- */
323
- function validateRateLimitConfig(config, path) {
324
- if (!config || typeof config !== 'object') {
325
- throw new ConfigValidationError(path, config, 'object', 'Rate limit configuration must be an object');
326
- }
327
- return {
328
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
329
- defaultRequests: validateNumber(config.defaultRequests, `${path}.defaultRequests`, { min: 1 }),
330
- defaultWindow: validateNumber(config.defaultWindow, `${path}.defaultWindow`, { min: 1000 }),
331
- skipSuccessfulRequests: validateBoolean(config.skipSuccessfulRequests, `${path}.skipSuccessfulRequests`),
332
- skipFailedRequests: validateBoolean(config.skipFailedRequests, `${path}.skipFailedRequests`),
333
- };
334
- }
335
- /**
336
- * Validate validation configuration
337
- */
338
- function validateValidationConfig(config, path) {
339
- if (!config || typeof config !== 'object') {
340
- throw new ConfigValidationError(path, config, 'object', 'Validation configuration must be an object');
341
- }
342
- return {
343
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
344
- stripUnknown: validateBoolean(config.stripUnknown, `${path}.stripUnknown`),
345
- abortEarly: validateBoolean(config.abortEarly, `${path}.abortEarly`),
346
- };
347
- }
348
- /**
349
- * Validate logging configuration
350
- */
351
- function validateLoggingConfig(config, path) {
352
- if (!config || typeof config !== 'object') {
353
- throw new ConfigValidationError(path, config, 'object', 'Logging configuration must be an object');
354
- }
355
- return {
356
- level: validateEnum(config.level, ['debug', 'info', 'warn', 'error', 'fatal'], `${path}.level`),
357
- format: validateEnum(config.format, ['pretty', 'json', 'compact'], `${path}.format`),
358
- enableColors: validateBoolean(config.enableColors, `${path}.enableColors`),
359
- enableTimestamp: validateBoolean(config.enableTimestamp, `${path}.enableTimestamp`),
360
- enableContext: validateBoolean(config.enableContext, `${path}.enableContext`),
361
- outputs: validateLoggingOutputsConfig(config.outputs, `${path}.outputs`),
362
- };
363
- }
364
- /**
365
- * Validate logging outputs configuration
366
- */
367
- function validateLoggingOutputsConfig(config, path) {
368
- if (!config || typeof config !== 'object') {
369
- throw new ConfigValidationError(path, config, 'object', 'Logging outputs configuration must be an object');
370
- }
371
- return {
372
- console: validateBoolean(config.console, `${path}.console`),
373
- file: validateLoggingFileConfig(config.file, `${path}.file`),
374
- webhook: validateLoggingWebhookConfig(config.webhook, `${path}.webhook`),
375
- };
376
- }
377
- /**
378
- * Validate logging file configuration
379
- */
380
- function validateLoggingFileConfig(config, path) {
381
- if (!config || typeof config !== 'object') {
382
- throw new ConfigValidationError(path, config, 'object', 'Logging file configuration must be an object');
383
- }
384
- return {
385
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
386
- path: validateString(config.path, `${path}.path`),
387
- maxSize: validateString(config.maxSize, `${path}.maxSize`),
388
- maxFiles: validateNumber(config.maxFiles, `${path}.maxFiles`, { min: 1 }),
389
- };
390
- }
391
- /**
392
- * Validate logging webhook configuration
393
- */
394
- function validateLoggingWebhookConfig(config, path) {
395
- if (!config || typeof config !== 'object') {
396
- throw new ConfigValidationError(path, config, 'object', 'Logging webhook configuration must be an object');
397
- }
398
- const result = {
399
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
400
- headers: validateObject(config.headers, `${path}.headers`),
401
- };
402
- // Optional URL
403
- if (config.url !== undefined) {
404
- result.url = validateString(config.url, `${path}.url`);
405
- }
406
- return result;
407
- }
408
- /**
409
- * Validate security configuration
410
- */
411
- function validateSecurityConfig(config, path) {
412
- if (!config || typeof config !== 'object') {
413
- throw new ConfigValidationError(path, config, 'object', 'Security configuration must be an object');
414
- }
415
- return {
416
- cors: validateCorsConfig(config.cors, `${path}.cors`),
417
- helmet: validateHelmetConfig(config.helmet, `${path}.helmet`),
418
- rateLimit: validateSecurityRateLimitConfig(config.rateLimit, `${path}.rateLimit`),
419
- };
420
- }
421
- /**
422
- * Validate CORS configuration
423
- */
424
- function validateCorsConfig(config, path) {
425
- if (!config || typeof config !== 'object') {
426
- throw new ConfigValidationError(path, config, 'object', 'CORS configuration must be an object');
427
- }
428
- return {
429
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
430
- origin: validateCorsOrigin(config.origin, `${path}.origin`),
431
- methods: validateStringArray(config.methods, `${path}.methods`),
432
- allowedHeaders: validateStringArray(config.allowedHeaders, `${path}.allowedHeaders`),
433
- credentials: validateBoolean(config.credentials, `${path}.credentials`),
434
- };
435
- }
436
- /**
437
- * Validate CORS origin (can be string, array, or boolean)
438
- */
439
- function validateCorsOrigin(value, path) {
440
- if (typeof value === 'boolean' || typeof value === 'string') {
441
- return value;
442
- }
443
- if (Array.isArray(value)) {
444
- return validateStringArray(value, path);
445
- }
446
- throw new ConfigValidationError(path, value, 'string | string[] | boolean', 'Must be a string, array of strings, or boolean');
447
- }
448
- /**
449
- * Validate helmet configuration
450
- */
451
- function validateHelmetConfig(config, path) {
452
- if (!config || typeof config !== 'object') {
453
- throw new ConfigValidationError(path, config, 'object', 'Helmet configuration must be an object');
454
- }
455
- return {
456
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
457
- contentSecurityPolicy: validateBoolean(config.contentSecurityPolicy, `${path}.contentSecurityPolicy`),
458
- hsts: validateBoolean(config.hsts, `${path}.hsts`),
459
- noSniff: validateBoolean(config.noSniff, `${path}.noSniff`),
460
- frameguard: validateBoolean(config.frameguard, `${path}.frameguard`),
461
- };
462
- }
463
- /**
464
- * Validate security rate limit configuration
465
- */
466
- function validateSecurityRateLimitConfig(config, path) {
467
- if (!config || typeof config !== 'object') {
468
- throw new ConfigValidationError(path, config, 'object', 'Security rate limit configuration must be an object');
469
- }
470
- return {
471
- global: validateGlobalRateLimitConfig(config.global, `${path}.global`),
472
- };
473
- }
474
- /**
475
- * Validate global rate limit configuration
476
- */
477
- function validateGlobalRateLimitConfig(config, path) {
478
- if (!config || typeof config !== 'object') {
479
- throw new ConfigValidationError(path, config, 'object', 'Global rate limit configuration must be an object');
480
- }
481
- return {
482
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
483
- requests: validateNumber(config.requests, `${path}.requests`, { min: 1 }),
484
- window: validateNumber(config.window, `${path}.window`, { min: 1000 }),
485
- };
486
- }
487
- /**
488
- * Validate external services configuration
489
- */
490
- function validateExternalServicesConfig(config, path) {
491
- if (!config || typeof config !== 'object') {
492
- throw new ConfigValidationError(path, config, 'object', 'External services configuration must be an object');
493
- }
494
- const result = {};
495
- // Optional services - only validate if present
496
- if (config.stripe !== undefined) {
497
- result.stripe = validateStripeConfig(config.stripe, `${path}.stripe`);
498
- }
499
- if (config.paypal !== undefined) {
500
- result.paypal = validatePayPalConfig(config.paypal, `${path}.paypal`);
501
- }
502
- if (config.smtp !== undefined) {
503
- result.smtp = validateSMTPConfig(config.smtp, `${path}.smtp`);
504
- }
505
- return result;
506
- }
507
- /**
508
- * Validate Stripe configuration
509
- */
510
- function validateStripeConfig(config, path) {
511
- if (!config || typeof config !== 'object') {
512
- throw new ConfigValidationError(path, config, 'object', 'Stripe configuration must be an object');
513
- }
514
- const result = {};
515
- // Optional fields
516
- if (config.secretKey !== undefined) {
517
- result.secretKey = validateString(config.secretKey, `${path}.secretKey`);
518
- }
519
- if (config.publishableKey !== undefined) {
520
- result.publishableKey = validateString(config.publishableKey, `${path}.publishableKey`);
521
- }
522
- if (config.webhookSecret !== undefined) {
523
- result.webhookSecret = validateString(config.webhookSecret, `${path}.webhookSecret`);
524
- }
525
- if (config.apiVersion !== undefined) {
526
- result.apiVersion = validateString(config.apiVersion, `${path}.apiVersion`);
527
- }
528
- else {
529
- result.apiVersion = '2023-10-16'; // Default API version
530
- }
531
- return result;
532
- }
533
- /**
534
- * Validate PayPal configuration
535
- */
536
- function validatePayPalConfig(config, path) {
537
- if (!config || typeof config !== 'object') {
538
- throw new ConfigValidationError(path, config, 'object', 'PayPal configuration must be an object');
539
- }
540
- const result = {
541
- environment: validateEnum(config.environment, ['sandbox', 'production'], `${path}.environment`),
542
- };
543
- // Optional fields
544
- if (config.clientId !== undefined) {
545
- result.clientId = validateString(config.clientId, `${path}.clientId`);
546
- }
547
- if (config.clientSecret !== undefined) {
548
- result.clientSecret = validateString(config.clientSecret, `${path}.clientSecret`);
549
- }
550
- if (config.webhookId !== undefined) {
551
- result.webhookId = validateString(config.webhookId, `${path}.webhookId`);
552
- }
553
- return result;
554
- }
555
- /**
556
- * Validate SMTP configuration
557
- */
558
- function validateSMTPConfig(config, path) {
559
- if (!config || typeof config !== 'object') {
560
- throw new ConfigValidationError(path, config, 'object', 'SMTP configuration must be an object');
561
- }
562
- const result = {
563
- port: validatePort(config.port, `${path}.port`),
564
- secure: validateBoolean(config.secure, `${path}.secure`),
565
- };
566
- // Optional fields
567
- if (config.host !== undefined) {
568
- result.host = validateString(config.host, `${path}.host`);
569
- }
570
- if (config.username !== undefined) {
571
- result.username = validateString(config.username, `${path}.username`);
572
- }
573
- if (config.password !== undefined) {
574
- result.password = validateString(config.password, `${path}.password`);
575
- }
576
- return result;
577
- }
578
- /**
579
- * Validate performance configuration
580
- */
581
- function validatePerformanceConfig(config, path) {
582
- if (!config || typeof config !== 'object') {
583
- throw new ConfigValidationError(path, config, 'object', 'Performance configuration must be an object');
584
- }
585
- return {
586
- compression: validateCompressionConfig(config.compression, `${path}.compression`),
587
- circuitBreaker: validateCircuitBreakerConfig(config.circuitBreaker, `${path}.circuitBreaker`),
588
- clustering: validateClusteringConfig(config.clustering, `${path}.clustering`),
589
- };
590
- }
591
- /**
592
- * Validate compression configuration
593
- */
594
- function validateCompressionConfig(config, path) {
595
- if (!config || typeof config !== 'object') {
596
- throw new ConfigValidationError(path, config, 'object', 'Compression configuration must be an object');
597
- }
598
- return {
599
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
600
- level: validateNumber(config.level, `${path}.level`, { min: 1, max: 9 }),
601
- threshold: validateNumber(config.threshold, `${path}.threshold`, { min: 0 }),
602
- };
603
- }
604
- /**
605
- * Validate circuit breaker configuration
606
- */
607
- function validateCircuitBreakerConfig(config, path) {
608
- if (!config || typeof config !== 'object') {
609
- throw new ConfigValidationError(path, config, 'object', 'Circuit breaker configuration must be an object');
610
- }
611
- return {
612
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
613
- failureThreshold: validateNumber(config.failureThreshold, `${path}.failureThreshold`, {
614
- min: 1,
615
- }),
616
- resetTimeout: validateNumber(config.resetTimeout, `${path}.resetTimeout`, { min: 1000 }),
617
- monitoringPeriod: validateNumber(config.monitoringPeriod, `${path}.monitoringPeriod`, {
618
- min: 1000,
619
- }),
620
- };
621
- }
622
- /**
623
- * Validate clustering configuration
624
- */
625
- function validateClusteringConfig(config, path) {
626
- if (!config || typeof config !== 'object') {
627
- throw new ConfigValidationError(path, config, 'object', 'Clustering configuration must be an object');
628
- }
629
- const result = {
630
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
631
- };
632
- // Workers can be number or 'auto'
633
- if (typeof config.workers === 'string' && config.workers === 'auto') {
634
- result.workers = 'auto';
635
- }
636
- else {
637
- result.workers = validateNumber(config.workers, `${path}.workers`, { min: 1 });
638
- }
639
- // Optional memoryPerWorkerGB
640
- if (config.memoryPerWorkerGB !== undefined) {
641
- result.memoryPerWorkerGB = validateNumber(config.memoryPerWorkerGB, `${path}.memoryPerWorkerGB`, { min: 0.1 });
642
- }
643
- return result;
644
- }
645
- /**
646
- * Validate WebSocket configuration
647
- */
648
- function validateWebSocketConfig(config, path) {
649
- if (!config || typeof config !== 'object') {
650
- throw new ConfigValidationError(path, config, 'object', 'WebSocket configuration must be an object');
651
- }
652
- const result = {
653
- enabled: validateBoolean(config.enabled, `${path}.enabled`),
654
- };
655
- // Optional fields
656
- if (config.adapter !== undefined) {
657
- result.adapter = validateString(config.adapter, `${path}.adapter`);
658
- }
659
- if (config.compression !== undefined) {
660
- result.compression = validateBoolean(config.compression, `${path}.compression`);
661
- }
662
- if (config.customIdGenerator !== undefined) {
663
- result.customIdGenerator = config.customIdGenerator; // Function - no validation needed
664
- }
665
- if (config.options !== undefined) {
666
- result.options = validateWebSocketOptions(config.options, `${path}.options`);
667
- }
668
- return result;
669
- }
670
- /**
671
- * Validate WebSocket options
672
- */
673
- function validateWebSocketOptions(config, path) {
674
- if (!config || typeof config !== 'object') {
675
- throw new ConfigValidationError(path, config, 'object', 'WebSocket options must be an object');
676
- }
677
- const result = {};
678
- if (config.cors !== undefined) {
679
- result.cors = validateWebSocketCorsOptions(config.cors, `${path}.cors`);
680
- }
681
- if (config.path !== undefined) {
682
- result.path = validateString(config.path, `${path}.path`);
683
- }
684
- if (config.maxPayloadLength !== undefined) {
685
- result.maxPayloadLength = validateNumber(config.maxPayloadLength, `${path}.maxPayloadLength`, {
686
- min: 1024,
687
- });
688
- }
689
- return result;
690
- }
691
- /**
692
- * Validate WebSocket CORS options
693
- */
694
- function validateWebSocketCorsOptions(config, path) {
695
- if (!config || typeof config !== 'object') {
696
- throw new ConfigValidationError(path, config, 'object', 'WebSocket CORS options must be an object');
697
- }
698
- const result = {};
699
- if (config.origin !== undefined) {
700
- result.origin = validateCorsOrigin(config.origin, `${path}.origin`);
701
- }
702
- if (config.credentials !== undefined) {
703
- result.credentials = validateBoolean(config.credentials, `${path}.credentials`);
704
- }
705
- return result;
706
- }
707
- // Basic validation functions
708
- function validatePort(value, path) {
709
- const num = Number(value);
710
- if (isNaN(num) || num < 1 || num > 65535) {
711
- throw new ConfigValidationError(path, value, 'number (1-65535)', 'Must be a number between 1 and 65535');
712
- }
713
- return num;
714
- }
715
- function validateBoolean(value, path) {
716
- if (value === 'true' || value === true)
717
- return true;
718
- if (value === 'false' || value === false)
719
- return false;
720
- if (value === '1' || value === 1)
721
- return true;
722
- if (value === '0' || value === 0)
723
- return false;
724
- throw new ConfigValidationError(path, value, 'boolean', 'Must be a boolean (true/false) or numeric (1/0)');
725
- }
726
- function validateNumber(value, path, options = {}) {
727
- const num = Number(value);
728
- if (isNaN(num)) {
729
- throw new ConfigValidationError(path, value, 'number', 'Must be a valid number');
730
- }
731
- if (options.min !== undefined && num < options.min) {
732
- throw new ConfigValidationError(path, value, `number >= ${options.min}`, `Must be at least ${options.min}`);
733
- }
734
- if (options.max !== undefined && num > options.max) {
735
- throw new ConfigValidationError(path, value, `number <= ${options.max}`, `Must be at most ${options.max}`);
736
- }
737
- return num;
738
- }
739
- function validateString(value, path) {
740
- if (typeof value !== 'string') {
741
- throw new ConfigValidationError(path, value, 'string', 'Must be a string');
742
- }
743
- return value;
744
- }
745
- function validateEnum(value, validValues, path) {
746
- const str = validateString(value, path);
747
- if (!validValues.includes(str)) {
748
- throw new ConfigValidationError(path, value, `one of: ${validValues.join(', ')}`, `Must be one of: ${validValues.join(', ')}`);
749
- }
750
- return str;
751
- }
752
- function validateStringArray(value, path) {
753
- if (!Array.isArray(value)) {
754
- // Try to parse comma-separated string
755
- if (typeof value === 'string') {
756
- return value
757
- .split(',')
758
- .map(s => s.trim())
759
- .filter(s => s.length > 0);
760
- }
761
- throw new ConfigValidationError(path, value, 'string[]', 'Must be an array or comma-separated string');
762
- }
763
- return value.map((item, index) => validateString(item, `${path}[${index}]`));
764
- }
765
- function validateObject(value, path) {
766
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
767
- throw new ConfigValidationError(path, value, 'object', 'Must be an object');
768
- }
769
- return value;
770
- }
771
- /**
772
- * Provide helpful validation hints based on the error
773
- */
774
- function provideValidationHints(error) {
775
- if (error.field.includes('port')) {
776
- logger.error(' 💡 Hint: Ports must be numbers between 1 and 65535');
777
- }
778
- if (error.field.includes('url')) {
779
- logger.error(' 💡 Hint: URLs must include protocol (http:// or https://)');
780
- }
781
- if (error.field.includes('environment')) {
782
- logger.error(' 💡 Hint: NODE_ENV must be one of: development, staging, production');
783
- }
784
- if (error.field.includes('level')) {
785
- logger.error(' 💡 Hint: Log level must be one of: debug, info, warn, error, fatal');
786
- }
787
- }
788
- //# sourceMappingURL=config-validator.js.map