@morojs/moro 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -256
- package/dist/core/auth/morojs-adapter.js +20 -20
- package/dist/core/auth/morojs-adapter.js.map +1 -1
- package/dist/core/config/config-manager.d.ts +44 -0
- package/dist/core/config/config-manager.js +104 -0
- package/dist/core/config/config-manager.js.map +1 -0
- package/dist/core/config/config-sources.d.ts +21 -0
- package/dist/core/config/config-sources.js +503 -0
- package/dist/core/config/config-sources.js.map +1 -0
- package/dist/core/config/config-validator.d.ts +21 -0
- package/dist/core/config/config-validator.js +791 -0
- package/dist/core/config/config-validator.js.map +1 -0
- package/dist/core/config/file-loader.d.ts +1 -6
- package/dist/core/config/file-loader.js +21 -249
- package/dist/core/config/file-loader.js.map +1 -1
- package/dist/core/config/index.d.ts +41 -12
- package/dist/core/config/index.js +65 -54
- package/dist/core/config/index.js.map +1 -1
- package/dist/core/config/schema.d.ts +2 -2
- package/dist/core/config/schema.js +55 -44
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/utils.d.ts +10 -3
- package/dist/core/config/utils.js +31 -58
- package/dist/core/config/utils.js.map +1 -1
- package/dist/core/database/adapters/drizzle.d.ts +1 -1
- package/dist/core/database/adapters/drizzle.js +18 -11
- package/dist/core/database/adapters/drizzle.js.map +1 -1
- package/dist/core/database/adapters/index.d.ts +7 -7
- package/dist/core/database/adapters/index.js +19 -29
- package/dist/core/database/adapters/index.js.map +1 -1
- package/dist/core/database/adapters/mongodb.d.ts +13 -1
- package/dist/core/database/adapters/mongodb.js +46 -10
- package/dist/core/database/adapters/mongodb.js.map +1 -1
- package/dist/core/database/adapters/mysql.d.ts +14 -1
- package/dist/core/database/adapters/mysql.js +19 -9
- package/dist/core/database/adapters/mysql.js.map +1 -1
- package/dist/core/database/adapters/postgresql.d.ts +12 -2
- package/dist/core/database/adapters/postgresql.js +19 -9
- package/dist/core/database/adapters/postgresql.js.map +1 -1
- package/dist/core/database/adapters/redis.d.ts +12 -1
- package/dist/core/database/adapters/redis.js +48 -13
- package/dist/core/database/adapters/redis.js.map +1 -1
- package/dist/core/database/adapters/sqlite.d.ts +3 -1
- package/dist/core/database/adapters/sqlite.js +19 -8
- package/dist/core/database/adapters/sqlite.js.map +1 -1
- package/dist/core/database/index.d.ts +2 -2
- package/dist/core/database/index.js +2 -18
- package/dist/core/database/index.js.map +1 -1
- package/dist/core/docs/index.d.ts +9 -9
- package/dist/core/docs/index.js +14 -35
- package/dist/core/docs/index.js.map +1 -1
- package/dist/core/docs/openapi-generator.d.ts +2 -2
- package/dist/core/docs/openapi-generator.js +11 -16
- package/dist/core/docs/openapi-generator.js.map +1 -1
- package/dist/core/docs/schema-to-openapi.d.ts +2 -2
- package/dist/core/docs/schema-to-openapi.js +5 -11
- package/dist/core/docs/schema-to-openapi.js.map +1 -1
- package/dist/core/docs/simple-docs.d.ts +1 -1
- package/dist/core/docs/simple-docs.js +4 -9
- package/dist/core/docs/simple-docs.js.map +1 -1
- package/dist/core/docs/swagger-ui.d.ts +2 -2
- package/dist/core/docs/swagger-ui.js +26 -29
- package/dist/core/docs/swagger-ui.js.map +1 -1
- package/dist/core/docs/zod-to-openapi.js +31 -28
- package/dist/core/docs/zod-to-openapi.js.map +1 -1
- package/dist/core/events/event-bus.d.ts +1 -1
- package/dist/core/events/event-bus.js +7 -11
- package/dist/core/events/event-bus.js.map +1 -1
- package/dist/core/events/index.d.ts +2 -2
- package/dist/core/events/index.js +1 -5
- package/dist/core/events/index.js.map +1 -1
- package/dist/core/framework.d.ts +20 -13
- package/dist/core/framework.js +285 -102
- package/dist/core/framework.js.map +1 -1
- package/dist/core/http/http-server.d.ts +59 -7
- package/dist/core/http/http-server.js +190 -176
- package/dist/core/http/http-server.js.map +1 -1
- package/dist/core/http/index.d.ts +4 -3
- package/dist/core/http/index.js +3 -8
- package/dist/core/http/index.js.map +1 -1
- package/dist/core/http/uws-http-server.d.ts +46 -0
- package/dist/core/http/uws-http-server.js +523 -0
- package/dist/core/http/uws-http-server.js.map +1 -0
- package/dist/core/logger/filters.d.ts +1 -1
- package/dist/core/logger/filters.js +20 -23
- package/dist/core/logger/filters.js.map +1 -1
- package/dist/core/logger/index.d.ts +3 -3
- package/dist/core/logger/index.js +2 -24
- package/dist/core/logger/index.js.map +1 -1
- package/dist/core/logger/logger.d.ts +30 -14
- package/dist/core/logger/logger.js +398 -223
- package/dist/core/logger/logger.js.map +1 -1
- package/dist/core/logger/outputs.d.ts +1 -1
- package/dist/core/logger/outputs.js +8 -17
- package/dist/core/logger/outputs.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cache/file.d.ts +1 -1
- package/dist/core/middleware/built-in/adapters/cache/file.js +10 -47
- package/dist/core/middleware/built-in/adapters/cache/file.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cache/index.d.ts +4 -4
- package/dist/core/middleware/built-in/adapters/cache/index.js +10 -17
- package/dist/core/middleware/built-in/adapters/cache/index.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cache/memory.d.ts +1 -1
- package/dist/core/middleware/built-in/adapters/cache/memory.js +3 -7
- package/dist/core/middleware/built-in/adapters/cache/memory.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cache/redis.d.ts +3 -1
- package/dist/core/middleware/built-in/adapters/cache/redis.js +11 -9
- package/dist/core/middleware/built-in/adapters/cache/redis.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/azure.d.ts +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/azure.js +3 -7
- package/dist/core/middleware/built-in/adapters/cdn/azure.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/cloudflare.d.ts +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js +3 -7
- package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/cloudfront.d.ts +3 -1
- package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js +12 -10
- package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/index.d.ts +4 -4
- package/dist/core/middleware/built-in/adapters/cdn/index.js +10 -17
- package/dist/core/middleware/built-in/adapters/cdn/index.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/index.d.ts +4 -4
- package/dist/core/middleware/built-in/adapters/index.js +4 -23
- package/dist/core/middleware/built-in/adapters/index.js.map +1 -1
- package/dist/core/middleware/built-in/auth-helpers.js +11 -22
- package/dist/core/middleware/built-in/auth-helpers.js.map +1 -1
- package/dist/core/middleware/built-in/auth-providers.d.ts +1 -1
- package/dist/core/middleware/built-in/auth-providers.js +4 -9
- package/dist/core/middleware/built-in/auth-providers.js.map +1 -1
- package/dist/core/middleware/built-in/auth.d.ts +2 -2
- package/dist/core/middleware/built-in/auth.js +93 -26
- package/dist/core/middleware/built-in/auth.js.map +1 -1
- package/dist/core/middleware/built-in/cache.d.ts +2 -2
- package/dist/core/middleware/built-in/cache.js +11 -12
- package/dist/core/middleware/built-in/cache.js.map +1 -1
- package/dist/core/middleware/built-in/cdn.d.ts +2 -2
- package/dist/core/middleware/built-in/cdn.js +5 -9
- package/dist/core/middleware/built-in/cdn.js.map +1 -1
- package/dist/core/middleware/built-in/cookie.d.ts +1 -1
- package/dist/core/middleware/built-in/cookie.js +3 -7
- package/dist/core/middleware/built-in/cookie.js.map +1 -1
- package/dist/core/middleware/built-in/cors.d.ts +1 -1
- package/dist/core/middleware/built-in/cors.js +3 -7
- package/dist/core/middleware/built-in/cors.js.map +1 -1
- package/dist/core/middleware/built-in/csp.d.ts +1 -1
- package/dist/core/middleware/built-in/csp.js +5 -8
- package/dist/core/middleware/built-in/csp.js.map +1 -1
- package/dist/core/middleware/built-in/csrf.d.ts +1 -1
- package/dist/core/middleware/built-in/csrf.js +5 -8
- package/dist/core/middleware/built-in/csrf.js.map +1 -1
- package/dist/core/middleware/built-in/error-tracker.js +3 -7
- package/dist/core/middleware/built-in/error-tracker.js.map +1 -1
- package/dist/core/middleware/built-in/index.d.ts +28 -27
- package/dist/core/middleware/built-in/index.js +48 -78
- package/dist/core/middleware/built-in/index.js.map +1 -1
- package/dist/core/middleware/built-in/jwt-helpers.d.ts +118 -0
- package/dist/core/middleware/built-in/jwt-helpers.js +218 -0
- package/dist/core/middleware/built-in/jwt-helpers.js.map +1 -0
- package/dist/core/middleware/built-in/performance-monitor.js +3 -7
- package/dist/core/middleware/built-in/performance-monitor.js.map +1 -1
- package/dist/core/middleware/built-in/rate-limit.d.ts +1 -1
- package/dist/core/middleware/built-in/rate-limit.js +3 -7
- package/dist/core/middleware/built-in/rate-limit.js.map +1 -1
- package/dist/core/middleware/built-in/request-logger.js +5 -8
- package/dist/core/middleware/built-in/request-logger.js.map +1 -1
- package/dist/core/middleware/built-in/session.d.ts +2 -2
- package/dist/core/middleware/built-in/session.js +11 -15
- package/dist/core/middleware/built-in/session.js.map +1 -1
- package/dist/core/middleware/built-in/sse.d.ts +1 -1
- package/dist/core/middleware/built-in/sse.js +12 -14
- package/dist/core/middleware/built-in/sse.js.map +1 -1
- package/dist/core/middleware/built-in/validation.d.ts +1 -1
- package/dist/core/middleware/built-in/validation.js +3 -7
- package/dist/core/middleware/built-in/validation.js.map +1 -1
- package/dist/core/middleware/index.d.ts +4 -4
- package/dist/core/middleware/index.js +8 -28
- package/dist/core/middleware/index.js.map +1 -1
- package/dist/core/modules/auto-discovery.d.ts +19 -2
- package/dist/core/modules/auto-discovery.js +391 -74
- package/dist/core/modules/auto-discovery.js.map +1 -1
- package/dist/core/modules/index.d.ts +2 -2
- package/dist/core/modules/index.js +2 -9
- package/dist/core/modules/index.js.map +1 -1
- package/dist/core/modules/modules.d.ts +3 -3
- package/dist/core/modules/modules.js +23 -54
- package/dist/core/modules/modules.js.map +1 -1
- package/dist/core/networking/adapters/index.d.ts +4 -3
- package/dist/core/networking/adapters/index.js +3 -7
- package/dist/core/networking/adapters/index.js.map +1 -1
- package/dist/core/networking/adapters/socketio-adapter.d.ts +1 -1
- package/dist/core/networking/adapters/socketio-adapter.js +5 -40
- package/dist/core/networking/adapters/socketio-adapter.js.map +1 -1
- package/dist/core/networking/adapters/uws-adapter.d.ts +44 -0
- package/dist/core/networking/adapters/uws-adapter.js +513 -0
- package/dist/core/networking/adapters/uws-adapter.js.map +1 -0
- package/dist/core/networking/adapters/ws-adapter.d.ts +2 -2
- package/dist/core/networking/adapters/ws-adapter.js +8 -43
- package/dist/core/networking/adapters/ws-adapter.js.map +1 -1
- package/dist/core/networking/index.d.ts +3 -2
- package/dist/core/networking/index.js +2 -7
- package/dist/core/networking/index.js.map +1 -1
- package/dist/core/networking/service-discovery.js +8 -12
- package/dist/core/networking/service-discovery.js.map +1 -1
- package/dist/core/networking/websocket-adapter.js +1 -2
- package/dist/core/networking/websocket-adapter.js.map +1 -1
- package/dist/core/networking/websocket-manager.d.ts +3 -3
- package/dist/core/networking/websocket-manager.js +9 -11
- package/dist/core/networking/websocket-manager.js.map +1 -1
- package/dist/core/pooling/object-pool-manager.d.ts +140 -0
- package/dist/core/pooling/object-pool-manager.js +502 -0
- package/dist/core/pooling/object-pool-manager.js.map +1 -0
- package/dist/core/routing/app-integration.d.ts +14 -12
- package/dist/core/routing/app-integration.js +49 -85
- package/dist/core/routing/app-integration.js.map +1 -1
- package/dist/core/routing/index.d.ts +17 -11
- package/dist/core/routing/index.js +48 -237
- package/dist/core/routing/index.js.map +1 -1
- package/dist/core/routing/path-matcher.d.ts +67 -0
- package/dist/core/routing/path-matcher.js +182 -0
- package/dist/core/routing/path-matcher.js.map +1 -0
- package/dist/core/routing/router.d.ts +38 -0
- package/dist/core/routing/router.js +68 -0
- package/dist/core/routing/router.js.map +1 -0
- package/dist/core/routing/unified-router.d.ts +148 -0
- package/dist/core/routing/unified-router.js +684 -0
- package/dist/core/routing/unified-router.js.map +1 -0
- package/dist/core/runtime/aws-lambda-adapter.d.ts +3 -3
- package/dist/core/runtime/aws-lambda-adapter.js +2 -6
- package/dist/core/runtime/aws-lambda-adapter.js.map +1 -1
- package/dist/core/runtime/base-adapter.d.ts +2 -2
- package/dist/core/runtime/base-adapter.js +3 -7
- package/dist/core/runtime/base-adapter.js.map +1 -1
- package/dist/core/runtime/cloudflare-workers-adapter.d.ts +3 -3
- package/dist/core/runtime/cloudflare-workers-adapter.js +2 -6
- package/dist/core/runtime/cloudflare-workers-adapter.js.map +1 -1
- package/dist/core/runtime/index.d.ts +12 -12
- package/dist/core/runtime/index.js +22 -35
- package/dist/core/runtime/index.js.map +1 -1
- package/dist/core/runtime/node-adapter.d.ts +4 -4
- package/dist/core/runtime/node-adapter.js +18 -49
- package/dist/core/runtime/node-adapter.js.map +1 -1
- package/dist/core/runtime/vercel-edge-adapter.d.ts +3 -3
- package/dist/core/runtime/vercel-edge-adapter.js +2 -6
- package/dist/core/runtime/vercel-edge-adapter.js.map +1 -1
- package/dist/core/utilities/circuit-breaker.js +1 -5
- package/dist/core/utilities/circuit-breaker.js.map +1 -1
- package/dist/core/utilities/container.js +12 -22
- package/dist/core/utilities/container.js.map +1 -1
- package/dist/core/utilities/hooks.d.ts +2 -2
- package/dist/core/utilities/hooks.js +7 -12
- package/dist/core/utilities/hooks.js.map +1 -1
- package/dist/core/utilities/index.d.ts +5 -4
- package/dist/core/utilities/index.js +5 -19
- package/dist/core/utilities/index.js.map +1 -1
- package/dist/core/utilities/package-utils.d.ts +38 -0
- package/dist/core/utilities/package-utils.js +57 -0
- package/dist/core/utilities/package-utils.js.map +1 -0
- package/dist/core/validation/adapters.d.ts +1 -1
- package/dist/core/validation/adapters.js +15 -26
- package/dist/core/validation/adapters.js.map +1 -1
- package/dist/core/validation/index.d.ts +6 -4
- package/dist/core/validation/index.js +57 -28
- package/dist/core/validation/index.js.map +1 -1
- package/dist/core/validation/schema-interface.js +3 -9
- package/dist/core/validation/schema-interface.js.map +1 -1
- package/dist/index.d.ts +51 -52
- package/dist/index.js +23 -132
- package/dist/index.js.map +1 -1
- package/dist/moro.d.ts +70 -16
- package/dist/moro.js +658 -271
- package/dist/moro.js.map +1 -1
- package/dist/types/auth.js +3 -9
- package/dist/types/auth.js.map +1 -1
- package/dist/types/cache.js +1 -2
- package/dist/types/cdn.js +1 -2
- package/dist/types/config.d.ts +73 -2
- package/dist/types/config.js +1 -2
- package/dist/types/config.js.map +1 -1
- package/dist/types/core.d.ts +36 -42
- package/dist/types/core.js +1 -2
- package/dist/types/database.js +1 -2
- package/dist/types/discovery.js +1 -2
- package/dist/types/events.js +1 -2
- package/dist/types/hooks.d.ts +1 -1
- package/dist/types/hooks.js +1 -2
- package/dist/types/http.d.ts +16 -1
- package/dist/types/http.js +1 -2
- package/dist/types/logger.d.ts +7 -0
- package/dist/types/logger.js +1 -2
- package/dist/types/module.d.ts +11 -0
- package/dist/types/module.js +1 -2
- package/dist/types/runtime.d.ts +1 -1
- package/dist/types/runtime.js +1 -2
- package/dist/types/session.js +1 -2
- package/jest.config.mjs +41 -0
- package/package.json +19 -52
- package/src/core/auth/morojs-adapter.ts +18 -13
- package/src/core/config/config-manager.ts +133 -0
- package/src/core/config/config-sources.ts +600 -0
- package/src/core/config/config-validator.ts +1116 -0
- package/src/core/config/file-loader.ts +16 -273
- package/src/core/config/index.ts +83 -34
- package/src/core/config/schema.ts +47 -33
- package/src/core/config/utils.ts +24 -31
- package/src/core/database/README.md +26 -16
- package/src/core/database/adapters/drizzle.ts +18 -6
- package/src/core/database/adapters/index.ts +13 -13
- package/src/core/database/adapters/mongodb.ts +53 -5
- package/src/core/database/adapters/mysql.ts +32 -4
- package/src/core/database/adapters/postgresql.ts +30 -5
- package/src/core/database/adapters/redis.ts +61 -8
- package/src/core/database/adapters/sqlite.ts +19 -3
- package/src/core/database/index.ts +2 -2
- package/src/core/docs/index.ts +8 -8
- package/src/core/docs/openapi-generator.ts +4 -4
- package/src/core/docs/schema-to-openapi.ts +3 -6
- package/src/core/docs/simple-docs.ts +2 -2
- package/src/core/docs/swagger-ui.ts +19 -16
- package/src/core/docs/zod-to-openapi.ts +34 -34
- package/src/core/events/event-bus.ts +3 -3
- package/src/core/events/index.ts +2 -2
- package/src/core/framework.ts +320 -71
- package/src/core/http/http-server.ts +203 -143
- package/src/core/http/index.ts +4 -3
- package/src/core/http/uws-http-server.ts +591 -0
- package/src/core/logger/filters.ts +13 -5
- package/src/core/logger/index.ts +4 -3
- package/src/core/logger/logger.ts +435 -216
- package/src/core/logger/outputs.ts +1 -3
- package/src/core/middleware/built-in/adapters/cache/file.ts +3 -3
- package/src/core/middleware/built-in/adapters/cache/index.ts +7 -7
- package/src/core/middleware/built-in/adapters/cache/memory.ts +2 -2
- package/src/core/middleware/built-in/adapters/cache/redis.ts +18 -4
- package/src/core/middleware/built-in/adapters/cdn/azure.ts +2 -2
- package/src/core/middleware/built-in/adapters/cdn/cloudflare.ts +2 -2
- package/src/core/middleware/built-in/adapters/cdn/cloudfront.ts +16 -5
- package/src/core/middleware/built-in/adapters/cdn/index.ts +7 -7
- package/src/core/middleware/built-in/adapters/index.ts +4 -4
- package/src/core/middleware/built-in/auth-helpers.ts +1 -1
- package/src/core/middleware/built-in/auth-providers.ts +1 -1
- package/src/core/middleware/built-in/auth.ts +102 -21
- package/src/core/middleware/built-in/cache.ts +8 -6
- package/src/core/middleware/built-in/cdn.ts +4 -4
- package/src/core/middleware/built-in/cookie.ts +2 -2
- package/src/core/middleware/built-in/cors.ts +2 -2
- package/src/core/middleware/built-in/csp.ts +3 -3
- package/src/core/middleware/built-in/csrf.ts +3 -3
- package/src/core/middleware/built-in/error-tracker.ts +1 -1
- package/src/core/middleware/built-in/index.ts +38 -30
- package/src/core/middleware/built-in/jwt-helpers.ts +243 -0
- package/src/core/middleware/built-in/performance-monitor.ts +1 -1
- package/src/core/middleware/built-in/rate-limit.ts +2 -2
- package/src/core/middleware/built-in/request-logger.ts +3 -1
- package/src/core/middleware/built-in/session.ts +7 -8
- package/src/core/middleware/built-in/sse.ts +11 -9
- package/src/core/middleware/built-in/validation.ts +2 -2
- package/src/core/middleware/index.ts +6 -6
- package/src/core/modules/auto-discovery.ts +478 -15
- package/src/core/modules/index.ts +2 -2
- package/src/core/modules/modules.ts +23 -12
- package/src/core/networking/adapters/index.ts +4 -3
- package/src/core/networking/adapters/socketio-adapter.ts +5 -3
- package/src/core/networking/adapters/uws-adapter.ts +619 -0
- package/src/core/networking/adapters/ws-adapter.ts +8 -9
- package/src/core/networking/index.ts +3 -2
- package/src/core/networking/service-discovery.ts +6 -7
- package/src/core/networking/websocket-manager.ts +7 -7
- package/src/core/pooling/object-pool-manager.ts +630 -0
- package/src/core/routing/app-integration.ts +60 -112
- package/src/core/routing/index.ts +66 -293
- package/src/core/routing/path-matcher.ts +222 -0
- package/src/core/routing/router.ts +97 -0
- package/src/core/routing/unified-router.ts +870 -0
- package/src/core/runtime/aws-lambda-adapter.ts +3 -3
- package/src/core/runtime/base-adapter.ts +2 -2
- package/src/core/runtime/cloudflare-workers-adapter.ts +3 -3
- package/src/core/runtime/index.ts +13 -13
- package/src/core/runtime/node-adapter.ts +16 -10
- package/src/core/runtime/vercel-edge-adapter.ts +3 -3
- package/src/core/utilities/hooks.ts +3 -3
- package/src/core/utilities/index.ts +5 -4
- package/src/core/utilities/package-utils.ts +59 -0
- package/src/core/validation/adapters.ts +1 -1
- package/src/core/validation/index.ts +68 -16
- package/src/index.ts +73 -66
- package/src/moro.ts +784 -253
- package/src/types/config.ts +74 -2
- package/src/types/core.ts +49 -47
- package/src/types/hooks.ts +1 -1
- package/src/types/http.ts +23 -1
- package/src/types/logger.ts +9 -0
- package/src/types/module.ts +12 -0
- package/src/types/runtime.ts +1 -1
- package/tsconfig.json +4 -2
- package/dist/core/config/loader.d.ts +0 -7
- package/dist/core/config/loader.js +0 -269
- package/dist/core/config/loader.js.map +0 -1
- package/dist/core/config/validation.d.ts +0 -17
- package/dist/core/config/validation.js +0 -131
- package/dist/core/config/validation.js.map +0 -1
- package/dist/core/http/router.d.ts +0 -14
- package/dist/core/http/router.js +0 -109
- package/dist/core/http/router.js.map +0 -1
- package/src/core/config/loader.ts +0 -633
- package/src/core/config/validation.ts +0 -140
- package/src/core/http/router.ts +0 -141
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Shared Path Matching Utility with Caching
|
|
2
|
+
// Replaces 6 different pathToRegex implementations across the codebase
|
|
3
|
+
|
|
4
|
+
export interface CompiledPath {
|
|
5
|
+
pattern: RegExp | null;
|
|
6
|
+
paramNames: string[];
|
|
7
|
+
isStatic: boolean;
|
|
8
|
+
path: string;
|
|
9
|
+
segments: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MatchResult {
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* LRU Cache implementation for compiled paths
|
|
18
|
+
*/
|
|
19
|
+
class LRUCache<K, V> {
|
|
20
|
+
private cache = new Map<K, V>();
|
|
21
|
+
private readonly maxSize: number;
|
|
22
|
+
|
|
23
|
+
constructor(maxSize: number = 1000) {
|
|
24
|
+
this.maxSize = maxSize;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get(key: K): V | undefined {
|
|
28
|
+
const value = this.cache.get(key);
|
|
29
|
+
if (value !== undefined) {
|
|
30
|
+
// Move to end (most recently used)
|
|
31
|
+
this.cache.delete(key);
|
|
32
|
+
this.cache.set(key, value);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
set(key: K, value: V): void {
|
|
38
|
+
// Remove if exists (to update position)
|
|
39
|
+
if (this.cache.has(key)) {
|
|
40
|
+
this.cache.delete(key);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Add to end
|
|
44
|
+
this.cache.set(key, value);
|
|
45
|
+
|
|
46
|
+
// Evict oldest if over capacity
|
|
47
|
+
if (this.cache.size > this.maxSize) {
|
|
48
|
+
const firstKey = this.cache.keys().next().value;
|
|
49
|
+
if (firstKey !== undefined) {
|
|
50
|
+
this.cache.delete(firstKey);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
has(key: K): boolean {
|
|
56
|
+
return this.cache.has(key);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
clear(): void {
|
|
60
|
+
this.cache.clear();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get size(): number {
|
|
64
|
+
return this.cache.size;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* PathMatcher - Single source of truth for path pattern compilation and matching
|
|
70
|
+
*/
|
|
71
|
+
export class PathMatcher {
|
|
72
|
+
private static readonly cache = new LRUCache<string, CompiledPath>(1000);
|
|
73
|
+
private static compilationCount = 0;
|
|
74
|
+
private static cacheHits = 0;
|
|
75
|
+
private static cacheMisses = 0;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Compile a path pattern into an efficient matching structure
|
|
79
|
+
* Results are cached for performance
|
|
80
|
+
*/
|
|
81
|
+
static compile(path: string): CompiledPath {
|
|
82
|
+
// Check cache first
|
|
83
|
+
const cached = this.cache.get(path);
|
|
84
|
+
if (cached) {
|
|
85
|
+
this.cacheHits++;
|
|
86
|
+
return cached;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.cacheMisses++;
|
|
90
|
+
this.compilationCount++;
|
|
91
|
+
|
|
92
|
+
// Compile the pattern
|
|
93
|
+
const compiled = this.compileInternal(path);
|
|
94
|
+
this.cache.set(path, compiled);
|
|
95
|
+
return compiled;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Internal compilation logic
|
|
100
|
+
*/
|
|
101
|
+
private static compileInternal(path: string): CompiledPath {
|
|
102
|
+
const paramNames: string[] = [];
|
|
103
|
+
const isStatic = !path.includes(':') && !path.includes('*');
|
|
104
|
+
|
|
105
|
+
// Calculate segment count for optimization
|
|
106
|
+
const segments = path.split('/').filter(s => s.length > 0).length;
|
|
107
|
+
|
|
108
|
+
if (isStatic) {
|
|
109
|
+
// No regex needed for static routes
|
|
110
|
+
return {
|
|
111
|
+
pattern: null,
|
|
112
|
+
paramNames: [],
|
|
113
|
+
isStatic: true,
|
|
114
|
+
path,
|
|
115
|
+
segments,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Convert parameterized routes to regex
|
|
120
|
+
// Match :paramName and capture the parameter name
|
|
121
|
+
const regexPath = path
|
|
122
|
+
.replace(/\/:([^/]+)/g, (match, paramName) => {
|
|
123
|
+
paramNames.push(paramName);
|
|
124
|
+
return '/([^/]+)';
|
|
125
|
+
})
|
|
126
|
+
.replace(/\//g, '\\/');
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
pattern: new RegExp(`^${regexPath}$`),
|
|
130
|
+
paramNames,
|
|
131
|
+
isStatic: false,
|
|
132
|
+
path,
|
|
133
|
+
segments,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Match a request path against a compiled pattern
|
|
139
|
+
* Returns match result with extracted parameters, or null if no match
|
|
140
|
+
*/
|
|
141
|
+
static match(compiledPath: CompiledPath, requestPath: string): MatchResult | null {
|
|
142
|
+
// Path for static routes - simple string comparison
|
|
143
|
+
if (compiledPath.isStatic) {
|
|
144
|
+
return compiledPath.path === requestPath ? { params: {} } : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Dynamic route - use regex matching
|
|
148
|
+
if (!compiledPath.pattern) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const matches = requestPath.match(compiledPath.pattern);
|
|
153
|
+
if (!matches) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Extract parameters
|
|
158
|
+
const params: Record<string, string> = {};
|
|
159
|
+
compiledPath.paramNames.forEach((name, index) => {
|
|
160
|
+
params[name] = matches[index + 1];
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return { params };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Compile and match in one operation (convenience method)
|
|
168
|
+
*/
|
|
169
|
+
static compileAndMatch(pathPattern: string, requestPath: string): MatchResult | null {
|
|
170
|
+
const compiled = this.compile(pathPattern);
|
|
171
|
+
return this.match(compiled, requestPath);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Check if a path pattern is static (no parameters)
|
|
176
|
+
*/
|
|
177
|
+
static isStatic(path: string): boolean {
|
|
178
|
+
return !path.includes(':') && !path.includes('*');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get performance statistics
|
|
183
|
+
*/
|
|
184
|
+
static getStats() {
|
|
185
|
+
const totalRequests = this.cacheHits + this.cacheMisses;
|
|
186
|
+
return {
|
|
187
|
+
cacheSize: this.cache.size,
|
|
188
|
+
cacheHits: this.cacheHits,
|
|
189
|
+
cacheMisses: this.cacheMisses,
|
|
190
|
+
hitRate: totalRequests > 0 ? this.cacheHits / totalRequests : 0,
|
|
191
|
+
compilationCount: this.compilationCount,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Clear the cache (useful for testing)
|
|
197
|
+
*/
|
|
198
|
+
static clearCache(): void {
|
|
199
|
+
this.cache.clear();
|
|
200
|
+
this.cacheHits = 0;
|
|
201
|
+
this.cacheMisses = 0;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Pre-compile multiple paths (cache warming)
|
|
206
|
+
*/
|
|
207
|
+
static precompile(paths: string[]): void {
|
|
208
|
+
paths.forEach(path => this.compile(path));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Legacy compatibility function - maps to PathMatcher.compile
|
|
214
|
+
* @deprecated Use PathMatcher.compile instead
|
|
215
|
+
*/
|
|
216
|
+
export function pathToRegex(path: string): { pattern: RegExp; paramNames: string[] } {
|
|
217
|
+
const compiled = PathMatcher.compile(path);
|
|
218
|
+
return {
|
|
219
|
+
pattern: compiled.pattern || new RegExp(`^${path.replace(/\//g, '\\/')}$`),
|
|
220
|
+
paramNames: compiled.paramNames,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/core/routing/router.ts
|
|
2
|
+
// FACADE: This class now delegates to UnifiedRouter for actual routing
|
|
3
|
+
// Maintains backward compatibility while using optimized implementation
|
|
4
|
+
import {
|
|
5
|
+
HttpRequest,
|
|
6
|
+
HttpResponse,
|
|
7
|
+
HttpHandler,
|
|
8
|
+
Middleware,
|
|
9
|
+
RouteDefinition,
|
|
10
|
+
} from '../../types/http.js';
|
|
11
|
+
import { createFrameworkLogger } from '../logger/index.js';
|
|
12
|
+
import { UnifiedRouter } from './unified-router.js';
|
|
13
|
+
|
|
14
|
+
export class Router {
|
|
15
|
+
private logger = createFrameworkLogger('Router');
|
|
16
|
+
|
|
17
|
+
// Delegate to shared UnifiedRouter singleton for actual routing
|
|
18
|
+
private unifiedRouter = UnifiedRouter.getInstance();
|
|
19
|
+
|
|
20
|
+
// Maintain route definitions for backward compatibility (getRoutes())
|
|
21
|
+
private routes: RouteDefinition[] = [];
|
|
22
|
+
|
|
23
|
+
get(path: string, ...handlers: (Middleware | HttpHandler)[]): void {
|
|
24
|
+
this.addRoute('GET', path, handlers);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
post(path: string, ...handlers: (Middleware | HttpHandler)[]): void {
|
|
28
|
+
this.addRoute('POST', path, handlers);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
put(path: string, ...handlers: (Middleware | HttpHandler)[]): void {
|
|
32
|
+
this.addRoute('PUT', path, handlers);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
delete(path: string, ...handlers: (Middleware | HttpHandler)[]): void {
|
|
36
|
+
this.addRoute('DELETE', path, handlers);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
patch(path: string, ...handlers: (Middleware | HttpHandler)[]): void {
|
|
40
|
+
this.addRoute('PATCH', path, handlers);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private addRoute(method: string, path: string, handlers: (Middleware | HttpHandler)[]): void {
|
|
44
|
+
const handler = handlers.pop() as HttpHandler;
|
|
45
|
+
const middleware = handlers as Middleware[];
|
|
46
|
+
|
|
47
|
+
// Delegate to UnifiedRouter for actual routing
|
|
48
|
+
this.unifiedRouter.addRoute(method as any, path, handler, middleware);
|
|
49
|
+
|
|
50
|
+
// Keep route definition for backward compatibility (getRoutes())
|
|
51
|
+
const route: RouteDefinition = {
|
|
52
|
+
method,
|
|
53
|
+
path,
|
|
54
|
+
pattern: new RegExp(''), // Not used since we delegate
|
|
55
|
+
paramNames: [],
|
|
56
|
+
handler,
|
|
57
|
+
middleware,
|
|
58
|
+
};
|
|
59
|
+
this.routes.push(route);
|
|
60
|
+
|
|
61
|
+
this.logger.debug(`Delegated route to UnifiedRouter: ${method} ${path}`, 'Facade');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async handle(req: HttpRequest, res: HttpResponse, basePath: string = ''): Promise<boolean> {
|
|
65
|
+
// Adjust path for basePath
|
|
66
|
+
let path = req.path.startsWith(basePath) ? req.path.substring(basePath.length) : req.path;
|
|
67
|
+
if (path === '' || path === undefined) {
|
|
68
|
+
path = '/';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this.logger.debug(
|
|
72
|
+
`Router delegating to UnifiedRouter: originalPath="${req.path}", basePath="${basePath}", processedPath="${path}"`,
|
|
73
|
+
'Facade'
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Temporarily adjust request path for processing
|
|
77
|
+
const originalPath = req.path;
|
|
78
|
+
req.path = path;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
// Delegate to UnifiedRouter for actual routing
|
|
82
|
+
return await this.unifiedRouter.handleRequest(req, res);
|
|
83
|
+
} finally {
|
|
84
|
+
// Restore original path
|
|
85
|
+
req.path = originalPath;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getRoutes(): RouteDefinition[] {
|
|
90
|
+
return [...this.routes];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Performance statistics for monitoring (delegates to UnifiedRouter)
|
|
94
|
+
getPerformanceStats() {
|
|
95
|
+
return this.unifiedRouter.getStats();
|
|
96
|
+
}
|
|
97
|
+
}
|