@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
package/src/core/config/utils.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
// Configuration Utilities for Modules and Environment Handling
|
|
2
|
-
import { AppConfig } from './schema';
|
|
3
|
-
import { createFrameworkLogger } from '../logger';
|
|
2
|
+
import { AppConfig } from './schema.js';
|
|
3
|
+
import { createFrameworkLogger } from '../logger/index.js';
|
|
4
|
+
import { getGlobalConfig } from './config-manager.js';
|
|
4
5
|
|
|
5
6
|
const logger = createFrameworkLogger('ConfigUtils');
|
|
6
7
|
|
|
7
|
-
// Global configuration store
|
|
8
|
-
let appConfig: AppConfig | null = null;
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
|
-
* Set the global configuration (
|
|
9
|
+
* Set the global configuration (deprecated - for backward compatibility only)
|
|
10
|
+
* @deprecated Use the new immutable config system instead
|
|
12
11
|
*/
|
|
13
|
-
export function setConfig(
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export function setConfig(_config: AppConfig): void {
|
|
13
|
+
logger.warn(
|
|
14
|
+
'setConfig() is deprecated. Configuration is now immutable after createApp() initialization.'
|
|
15
|
+
);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Get the global configuration
|
|
20
|
+
* This now delegates to the new config manager
|
|
20
21
|
*/
|
|
21
22
|
export function getConfig(): AppConfig {
|
|
22
|
-
|
|
23
|
-
throw new Error('Configuration not initialized. Call loadConfig() first.');
|
|
24
|
-
}
|
|
25
|
-
return appConfig;
|
|
23
|
+
return getGlobalConfig();
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
/**
|
|
@@ -63,6 +61,7 @@ function coerceEnvironmentValue(value: string): any {
|
|
|
63
61
|
|
|
64
62
|
/**
|
|
65
63
|
* Create module-specific configuration with environment override support
|
|
64
|
+
* This now uses the new immutable config system
|
|
66
65
|
*/
|
|
67
66
|
export function createModuleConfig<T>(
|
|
68
67
|
schema: { parse: (data: any) => T },
|
|
@@ -72,10 +71,12 @@ export function createModuleConfig<T>(
|
|
|
72
71
|
// Try to get global config, but don't fail if not initialized
|
|
73
72
|
let globalConfig = {};
|
|
74
73
|
try {
|
|
75
|
-
const { getGlobalConfig } = require('./index');
|
|
76
74
|
globalConfig = getGlobalConfig();
|
|
77
75
|
} catch {
|
|
78
76
|
// Global config not initialized - use empty object (module config can still work independently)
|
|
77
|
+
logger.debug(
|
|
78
|
+
`Global config not available for module config with prefix ${envPrefix}, using defaults only`
|
|
79
|
+
);
|
|
79
80
|
globalConfig = {};
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -104,7 +105,7 @@ export function createModuleConfig<T>(
|
|
|
104
105
|
// Priority: environment variables > global config > default config
|
|
105
106
|
const mergedConfig = {
|
|
106
107
|
...defaultConfig,
|
|
107
|
-
...globalConfig, // Now
|
|
108
|
+
...globalConfig, // Now uses the new immutable config system
|
|
108
109
|
...envConfig,
|
|
109
110
|
};
|
|
110
111
|
|
|
@@ -208,9 +209,10 @@ export function envVar(prefix: string, name: string): string {
|
|
|
208
209
|
|
|
209
210
|
/**
|
|
210
211
|
* Get configuration value with dot notation
|
|
212
|
+
* This now delegates to the new config manager
|
|
211
213
|
*/
|
|
212
214
|
export function getConfigValue(path: string): any {
|
|
213
|
-
const config =
|
|
215
|
+
const config = getGlobalConfig();
|
|
214
216
|
|
|
215
217
|
return path.split('.').reduce((obj, key) => {
|
|
216
218
|
return obj && obj[key] !== undefined ? obj[key] : undefined;
|
|
@@ -219,33 +221,24 @@ export function getConfigValue(path: string): any {
|
|
|
219
221
|
|
|
220
222
|
/**
|
|
221
223
|
* Check if we're in development environment
|
|
224
|
+
* Now reads NODE_ENV directly for consistency with Node.js ecosystem
|
|
222
225
|
*/
|
|
223
226
|
export function isDevelopment(): boolean {
|
|
224
|
-
|
|
225
|
-
return getConfig().server.environment === 'development';
|
|
226
|
-
} catch {
|
|
227
|
-
return process.env.NODE_ENV === 'development';
|
|
228
|
-
}
|
|
227
|
+
return process.env.NODE_ENV === 'development';
|
|
229
228
|
}
|
|
230
229
|
|
|
231
230
|
/**
|
|
232
231
|
* Check if we're in production environment
|
|
232
|
+
* Now reads NODE_ENV directly for consistency with Node.js ecosystem
|
|
233
233
|
*/
|
|
234
234
|
export function isProduction(): boolean {
|
|
235
|
-
|
|
236
|
-
return getConfig().server.environment === 'production';
|
|
237
|
-
} catch {
|
|
238
|
-
return process.env.NODE_ENV === 'production';
|
|
239
|
-
}
|
|
235
|
+
return process.env.NODE_ENV === 'production';
|
|
240
236
|
}
|
|
241
237
|
|
|
242
238
|
/**
|
|
243
239
|
* Check if we're in staging environment
|
|
240
|
+
* Now reads NODE_ENV directly for consistency with Node.js ecosystem
|
|
244
241
|
*/
|
|
245
242
|
export function isStaging(): boolean {
|
|
246
|
-
|
|
247
|
-
return getConfig().server.environment === 'staging';
|
|
248
|
-
} catch {
|
|
249
|
-
return process.env.NODE_ENV === 'staging';
|
|
250
|
-
}
|
|
243
|
+
return process.env.NODE_ENV === 'staging';
|
|
251
244
|
}
|
|
@@ -7,16 +7,19 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
7
7
|
### SQL Databases
|
|
8
8
|
|
|
9
9
|
#### MySQL Adapter
|
|
10
|
+
|
|
10
11
|
- **Package Required**: `mysql2`
|
|
11
12
|
- **Usage**: Production-ready with connection pooling
|
|
12
13
|
- **Type**: `mysql`
|
|
13
14
|
|
|
14
|
-
#### PostgreSQL Adapter
|
|
15
|
+
#### PostgreSQL Adapter
|
|
16
|
+
|
|
15
17
|
- **Package Required**: `pg` and `@types/pg`
|
|
16
18
|
- **Usage**: Full PostgreSQL feature support
|
|
17
19
|
- **Type**: `postgresql`, `postgres`, or `pg`
|
|
18
20
|
|
|
19
21
|
#### SQLite Adapter
|
|
22
|
+
|
|
20
23
|
- **Package Required**: `better-sqlite3`
|
|
21
24
|
- **Usage**: Lightweight, file-based database
|
|
22
25
|
- **Type**: `sqlite` or `sqlite3`
|
|
@@ -24,11 +27,13 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
24
27
|
### NoSQL Databases
|
|
25
28
|
|
|
26
29
|
#### MongoDB Adapter
|
|
30
|
+
|
|
27
31
|
- **Package Required**: `mongodb`
|
|
28
32
|
- **Usage**: Document database with aggregation support
|
|
29
33
|
- **Type**: `mongodb` or `mongo`
|
|
30
34
|
|
|
31
35
|
#### Redis Adapter
|
|
36
|
+
|
|
32
37
|
- **Package Required**: `ioredis`
|
|
33
38
|
- **Usage**: In-memory key-value store with pub/sub
|
|
34
39
|
- **Type**: `redis`
|
|
@@ -36,6 +41,7 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
36
41
|
### ORM
|
|
37
42
|
|
|
38
43
|
#### Drizzle Adapter
|
|
44
|
+
|
|
39
45
|
- **Package Required**: `drizzle-orm` + database driver
|
|
40
46
|
- **Usage**: Type-safe ORM with schema validation
|
|
41
47
|
- **Type**: `drizzle` or `orm`
|
|
@@ -43,7 +49,7 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
43
49
|
## Factory Pattern (Recommended)
|
|
44
50
|
|
|
45
51
|
```typescript
|
|
46
|
-
import { createDatabaseAdapter } from 'moro';
|
|
52
|
+
import { createDatabaseAdapter } from '@morojs/moro';
|
|
47
53
|
|
|
48
54
|
// SQL Databases
|
|
49
55
|
const mysql = createDatabaseAdapter('mysql', {
|
|
@@ -52,7 +58,7 @@ const mysql = createDatabaseAdapter('mysql', {
|
|
|
52
58
|
user: 'root',
|
|
53
59
|
password: 'password',
|
|
54
60
|
database: 'my_app',
|
|
55
|
-
connectionLimit: 10
|
|
61
|
+
connectionLimit: 10,
|
|
56
62
|
});
|
|
57
63
|
|
|
58
64
|
const postgres = createDatabaseAdapter('postgresql', {
|
|
@@ -62,12 +68,12 @@ const postgres = createDatabaseAdapter('postgresql', {
|
|
|
62
68
|
password: 'password',
|
|
63
69
|
database: 'my_app',
|
|
64
70
|
connectionLimit: 10,
|
|
65
|
-
ssl: false
|
|
71
|
+
ssl: false,
|
|
66
72
|
});
|
|
67
73
|
|
|
68
74
|
const sqlite = createDatabaseAdapter('sqlite', {
|
|
69
75
|
filename: 'app.db',
|
|
70
|
-
memory: false
|
|
76
|
+
memory: false,
|
|
71
77
|
});
|
|
72
78
|
|
|
73
79
|
// NoSQL Databases
|
|
@@ -76,34 +82,34 @@ const mongodb = createDatabaseAdapter('mongodb', {
|
|
|
76
82
|
port: 27017,
|
|
77
83
|
database: 'my_app',
|
|
78
84
|
username: 'user',
|
|
79
|
-
password: 'password'
|
|
85
|
+
password: 'password',
|
|
80
86
|
});
|
|
81
87
|
|
|
82
88
|
const redis = createDatabaseAdapter('redis', {
|
|
83
89
|
host: 'localhost',
|
|
84
90
|
port: 6379,
|
|
85
91
|
password: 'password',
|
|
86
|
-
keyPrefix: 'myapp:'
|
|
92
|
+
keyPrefix: 'myapp:',
|
|
87
93
|
});
|
|
88
94
|
|
|
89
95
|
// ORM
|
|
90
96
|
const drizzle = createDatabaseAdapter('drizzle', {
|
|
91
97
|
database: drizzleInstance,
|
|
92
|
-
schema: schemaObject
|
|
98
|
+
schema: schemaObject,
|
|
93
99
|
});
|
|
94
100
|
```
|
|
95
101
|
|
|
96
102
|
## Direct Instantiation
|
|
97
103
|
|
|
98
104
|
```typescript
|
|
99
|
-
import {
|
|
100
|
-
MySQLAdapter,
|
|
101
|
-
PostgreSQLAdapter,
|
|
105
|
+
import {
|
|
106
|
+
MySQLAdapter,
|
|
107
|
+
PostgreSQLAdapter,
|
|
102
108
|
SQLiteAdapter,
|
|
103
109
|
MongoDBAdapter,
|
|
104
110
|
RedisAdapter,
|
|
105
111
|
DrizzleAdapter
|
|
106
|
-
} from 'moro';
|
|
112
|
+
} from '@morojs/moro';
|
|
107
113
|
|
|
108
114
|
// SQL
|
|
109
115
|
const mysql = new MySQLAdapter({ host: 'localhost', ... });
|
|
@@ -151,7 +157,7 @@ const updated = await db.update('users', { name: 'Jane' }, { id: 1 });
|
|
|
151
157
|
const deleted = await db.delete('users', { id: 1 });
|
|
152
158
|
|
|
153
159
|
// Transactions
|
|
154
|
-
const result = await db.transaction(async
|
|
160
|
+
const result = await db.transaction(async tx => {
|
|
155
161
|
const user = await tx.insert('users', userData);
|
|
156
162
|
await tx.insert('profiles', { user_id: user.id, ...profileData });
|
|
157
163
|
return user;
|
|
@@ -161,6 +167,7 @@ const result = await db.transaction(async (tx) => {
|
|
|
161
167
|
## Usage Examples
|
|
162
168
|
|
|
163
169
|
### SQL Operations
|
|
170
|
+
|
|
164
171
|
```typescript
|
|
165
172
|
// Standard CRUD operations work across all SQL adapters
|
|
166
173
|
const users = await db.query('SELECT * FROM users WHERE age > ?', [18]);
|
|
@@ -171,6 +178,7 @@ const deleted = await db.delete('users', { id: 1 });
|
|
|
171
178
|
```
|
|
172
179
|
|
|
173
180
|
### MongoDB Operations
|
|
181
|
+
|
|
174
182
|
```typescript
|
|
175
183
|
// MongoDB uses collections instead of tables
|
|
176
184
|
const users = await mongoDb.query('users'); // Get all
|
|
@@ -179,12 +187,13 @@ const user = await mongoDb.queryOne('users', { email: 'john@example.com' });
|
|
|
179
187
|
|
|
180
188
|
// MongoDB-specific methods
|
|
181
189
|
const stats = await mongoDb.aggregate('users', [
|
|
182
|
-
{ $group: { _id: null, avgAge: { $avg: '$age' } } }
|
|
190
|
+
{ $group: { _id: null, avgAge: { $avg: '$age' } } },
|
|
183
191
|
]);
|
|
184
192
|
await mongoDb.createIndex('users', { email: 1 }, { unique: true });
|
|
185
193
|
```
|
|
186
194
|
|
|
187
195
|
### Redis Operations
|
|
196
|
+
|
|
188
197
|
```typescript
|
|
189
198
|
// Key-value operations
|
|
190
199
|
await redisDb.set('user:123', userData, 3600); // with TTL
|
|
@@ -197,6 +206,7 @@ await redisDb.publish('notifications', message);
|
|
|
197
206
|
```
|
|
198
207
|
|
|
199
208
|
### Drizzle ORM Operations
|
|
209
|
+
|
|
200
210
|
```typescript
|
|
201
211
|
// Type-safe queries (requires schema setup)
|
|
202
212
|
const users = await drizzleDb.select('users').where(eq(schema.users.age, 25));
|
|
@@ -213,7 +223,7 @@ Choose and install the appropriate database package:
|
|
|
213
223
|
```bash
|
|
214
224
|
# SQL Databases
|
|
215
225
|
npm install mysql2 # MySQL
|
|
216
|
-
npm install pg @types/pg # PostgreSQL
|
|
226
|
+
npm install pg @types/pg # PostgreSQL
|
|
217
227
|
npm install better-sqlite3 # SQLite
|
|
218
228
|
|
|
219
229
|
# NoSQL Databases
|
|
@@ -225,4 +235,4 @@ npm install drizzle-orm # Drizzle ORM
|
|
|
225
235
|
# Plus the appropriate driver (mysql2, pg, better-sqlite3, etc.)
|
|
226
236
|
```
|
|
227
237
|
|
|
228
|
-
The adapters will gracefully handle missing packages with helpful error messages.
|
|
238
|
+
The adapters will gracefully handle missing packages with helpful error messages.
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// Database Drizzle ORM Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
-
import { createFrameworkLogger } from '../../logger';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database.js';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger/index.js';
|
|
4
|
+
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
5
|
+
|
|
6
|
+
// Cache the drizzle-orm module
|
|
7
|
+
let drizzleOrm: any = null;
|
|
8
|
+
async function getDrizzleOrm() {
|
|
9
|
+
if (!drizzleOrm) {
|
|
10
|
+
const drizzlePath = resolveUserPackage('drizzle-orm');
|
|
11
|
+
const module = await import(drizzlePath);
|
|
12
|
+
drizzleOrm = module;
|
|
13
|
+
}
|
|
14
|
+
return drizzleOrm;
|
|
15
|
+
}
|
|
4
16
|
|
|
5
17
|
interface DrizzleConfig {
|
|
6
18
|
database: any; // Drizzle database instance
|
|
@@ -108,7 +120,7 @@ export class DrizzleAdapter implements DatabaseAdapter {
|
|
|
108
120
|
if (this.schema && this.schema[table]) {
|
|
109
121
|
// Use schema-based update
|
|
110
122
|
try {
|
|
111
|
-
const { eq, and } =
|
|
123
|
+
const { eq, and } = await getDrizzleOrm();
|
|
112
124
|
|
|
113
125
|
// Build where conditions
|
|
114
126
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
@@ -165,7 +177,7 @@ export class DrizzleAdapter implements DatabaseAdapter {
|
|
|
165
177
|
if (this.schema && this.schema[table]) {
|
|
166
178
|
// Use schema-based delete
|
|
167
179
|
try {
|
|
168
|
-
const { eq, and } =
|
|
180
|
+
const { eq, and } = await getDrizzleOrm();
|
|
169
181
|
|
|
170
182
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
171
183
|
eq(this.schema[table][key], value)
|
|
@@ -314,7 +326,7 @@ class DrizzleTransaction implements DatabaseTransaction {
|
|
|
314
326
|
): Promise<T> {
|
|
315
327
|
if (this.schema && this.schema[table]) {
|
|
316
328
|
try {
|
|
317
|
-
const { eq, and } =
|
|
329
|
+
const { eq, and } = await getDrizzleOrm();
|
|
318
330
|
|
|
319
331
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
320
332
|
eq(this.schema[table][key], value)
|
|
@@ -360,7 +372,7 @@ class DrizzleTransaction implements DatabaseTransaction {
|
|
|
360
372
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
361
373
|
if (this.schema && this.schema[table]) {
|
|
362
374
|
try {
|
|
363
|
-
const { eq, and } =
|
|
375
|
+
const { eq, and } = await getDrizzleOrm();
|
|
364
376
|
|
|
365
377
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
366
378
|
eq(this.schema[table][key], value)
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// Database Adapters
|
|
2
|
-
export { MySQLAdapter } from './mysql';
|
|
3
|
-
export { PostgreSQLAdapter } from './postgresql';
|
|
4
|
-
export { SQLiteAdapter } from './sqlite';
|
|
5
|
-
export { MongoDBAdapter } from './mongodb';
|
|
6
|
-
export { RedisAdapter } from './redis';
|
|
7
|
-
export { DrizzleAdapter } from './drizzle';
|
|
2
|
+
export { MySQLAdapter } from './mysql.js';
|
|
3
|
+
export { PostgreSQLAdapter } from './postgresql.js';
|
|
4
|
+
export { SQLiteAdapter } from './sqlite.js';
|
|
5
|
+
export { MongoDBAdapter } from './mongodb.js';
|
|
6
|
+
export { RedisAdapter } from './redis.js';
|
|
7
|
+
export { DrizzleAdapter } from './drizzle.js';
|
|
8
8
|
|
|
9
|
-
import { MySQLAdapter } from './mysql';
|
|
10
|
-
import { PostgreSQLAdapter } from './postgresql';
|
|
11
|
-
import { SQLiteAdapter } from './sqlite';
|
|
12
|
-
import { MongoDBAdapter } from './mongodb';
|
|
13
|
-
import { RedisAdapter } from './redis';
|
|
14
|
-
import { DrizzleAdapter } from './drizzle';
|
|
15
|
-
import { DatabaseAdapter } from '../../../types/database';
|
|
9
|
+
import { MySQLAdapter } from './mysql.js';
|
|
10
|
+
import { PostgreSQLAdapter } from './postgresql.js';
|
|
11
|
+
import { SQLiteAdapter } from './sqlite.js';
|
|
12
|
+
import { MongoDBAdapter } from './mongodb.js';
|
|
13
|
+
import { RedisAdapter } from './redis.js';
|
|
14
|
+
import { DrizzleAdapter } from './drizzle.js';
|
|
15
|
+
import { DatabaseAdapter } from '../../../types/database.js';
|
|
16
16
|
|
|
17
17
|
// Adapter factory function for auto-loading
|
|
18
18
|
export function createDatabaseAdapter(type: string, options: any = {}): DatabaseAdapter {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Database MongoDB Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
-
import { createFrameworkLogger } from '../../logger';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database.js';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger/index.js';
|
|
4
|
+
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
4
5
|
|
|
5
6
|
interface MongoDBConfig {
|
|
6
7
|
url?: string;
|
|
@@ -11,6 +12,16 @@ interface MongoDBConfig {
|
|
|
11
12
|
database?: string;
|
|
12
13
|
authSource?: string;
|
|
13
14
|
ssl?: boolean;
|
|
15
|
+
tls?: {
|
|
16
|
+
ca?: string;
|
|
17
|
+
cert?: string;
|
|
18
|
+
key?: string;
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
insecure?: boolean;
|
|
21
|
+
allowInvalidCertificates?: boolean;
|
|
22
|
+
allowInvalidHostnames?: boolean;
|
|
23
|
+
checkServerIdentity?: boolean;
|
|
24
|
+
};
|
|
14
25
|
replicaSet?: string;
|
|
15
26
|
maxPoolSize?: number;
|
|
16
27
|
minPoolSize?: number;
|
|
@@ -25,18 +36,43 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
25
36
|
private client: any;
|
|
26
37
|
private db: any;
|
|
27
38
|
private logger = createFrameworkLogger('MongoDB');
|
|
39
|
+
private initPromise: Promise<void>;
|
|
28
40
|
|
|
29
41
|
constructor(config: MongoDBConfig) {
|
|
42
|
+
this.initPromise = this.initialize(config);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private async initialize(config: MongoDBConfig): Promise<void> {
|
|
30
46
|
try {
|
|
31
|
-
const
|
|
47
|
+
const mongodbPath = resolveUserPackage('mongodb');
|
|
48
|
+
const mongodb = await import(mongodbPath);
|
|
49
|
+
const { MongoClient } = mongodb;
|
|
32
50
|
|
|
33
51
|
const url = config.url || this.buildConnectionString(config);
|
|
34
52
|
|
|
35
|
-
|
|
53
|
+
const clientOptions: any = {
|
|
36
54
|
maxPoolSize: config.maxPoolSize || 10,
|
|
37
55
|
minPoolSize: config.minPoolSize || 0,
|
|
38
56
|
ssl: config.ssl || false,
|
|
39
|
-
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Add TLS options if provided
|
|
60
|
+
if (config.tls) {
|
|
61
|
+
clientOptions.tls = true;
|
|
62
|
+
if (config.tls.ca) clientOptions.tlsCAFile = config.tls.ca;
|
|
63
|
+
if (config.tls.cert) clientOptions.tlsCertificateFile = config.tls.cert;
|
|
64
|
+
if (config.tls.key) clientOptions.tlsCertificateKeyFile = config.tls.key;
|
|
65
|
+
if (config.tls.passphrase)
|
|
66
|
+
clientOptions.tlsCertificateKeyFilePassword = config.tls.passphrase;
|
|
67
|
+
if (config.tls.insecure) clientOptions.tlsInsecure = config.tls.insecure;
|
|
68
|
+
if (config.tls.allowInvalidCertificates)
|
|
69
|
+
clientOptions.tlsAllowInvalidCertificates = config.tls.allowInvalidCertificates;
|
|
70
|
+
if (config.tls.allowInvalidHostnames)
|
|
71
|
+
clientOptions.tlsAllowInvalidHostnames = config.tls.allowInvalidHostnames;
|
|
72
|
+
if (config.tls.checkServerIdentity === false) clientOptions.checkServerIdentity = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.client = new MongoClient(url, clientOptions);
|
|
40
76
|
|
|
41
77
|
this.db = this.client.db(config.database || 'moro_app');
|
|
42
78
|
|
|
@@ -58,6 +94,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
58
94
|
}
|
|
59
95
|
|
|
60
96
|
async connect(): Promise<void> {
|
|
97
|
+
await this.initPromise;
|
|
61
98
|
try {
|
|
62
99
|
await this.client.connect();
|
|
63
100
|
await this.client.db('admin').command({ ping: 1 });
|
|
@@ -71,11 +108,13 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
71
108
|
}
|
|
72
109
|
|
|
73
110
|
async disconnect(): Promise<void> {
|
|
111
|
+
await this.initPromise;
|
|
74
112
|
await this.client.close();
|
|
75
113
|
}
|
|
76
114
|
|
|
77
115
|
// For MongoDB, we'll treat "sql" as collection name and "params" as query/pipeline
|
|
78
116
|
async query<T = any>(collection: string, pipeline?: any[]): Promise<T[]> {
|
|
117
|
+
await this.initPromise;
|
|
79
118
|
try {
|
|
80
119
|
const coll = this.db.collection(collection);
|
|
81
120
|
|
|
@@ -102,6 +141,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
102
141
|
}
|
|
103
142
|
|
|
104
143
|
async queryOne<T = any>(collection: string, query?: any): Promise<T | null> {
|
|
144
|
+
await this.initPromise;
|
|
105
145
|
try {
|
|
106
146
|
const coll = this.db.collection(collection);
|
|
107
147
|
return await coll.findOne(query || {});
|
|
@@ -115,6 +155,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
115
155
|
}
|
|
116
156
|
|
|
117
157
|
async insert<T = any>(collection: string, data: Record<string, any>): Promise<T> {
|
|
158
|
+
await this.initPromise;
|
|
118
159
|
try {
|
|
119
160
|
const coll = this.db.collection(collection);
|
|
120
161
|
const result = await coll.insertOne(data);
|
|
@@ -135,6 +176,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
135
176
|
data: Record<string, any>,
|
|
136
177
|
where: Record<string, any>
|
|
137
178
|
): Promise<T> {
|
|
179
|
+
await this.initPromise;
|
|
138
180
|
try {
|
|
139
181
|
const coll = this.db.collection(collection);
|
|
140
182
|
const result = await coll.findOneAndUpdate(
|
|
@@ -154,6 +196,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
154
196
|
}
|
|
155
197
|
|
|
156
198
|
async delete(collection: string, where: Record<string, any>): Promise<number> {
|
|
199
|
+
await this.initPromise;
|
|
157
200
|
try {
|
|
158
201
|
const coll = this.db.collection(collection);
|
|
159
202
|
const result = await coll.deleteMany(where);
|
|
@@ -168,6 +211,7 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
168
211
|
}
|
|
169
212
|
|
|
170
213
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
214
|
+
await this.initPromise;
|
|
171
215
|
const session = this.client.startSession();
|
|
172
216
|
|
|
173
217
|
try {
|
|
@@ -182,22 +226,26 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
182
226
|
|
|
183
227
|
// MongoDB-specific methods
|
|
184
228
|
async aggregate<T = any>(collection: string, pipeline: any[]): Promise<T[]> {
|
|
229
|
+
await this.initPromise;
|
|
185
230
|
const coll = this.db.collection(collection);
|
|
186
231
|
const cursor = coll.aggregate(pipeline);
|
|
187
232
|
return await cursor.toArray();
|
|
188
233
|
}
|
|
189
234
|
|
|
190
235
|
async createIndex(collection: string, index: any, options?: any): Promise<string> {
|
|
236
|
+
await this.initPromise;
|
|
191
237
|
const coll = this.db.collection(collection);
|
|
192
238
|
return await coll.createIndex(index, options);
|
|
193
239
|
}
|
|
194
240
|
|
|
195
241
|
async dropIndex(collection: string, indexName: string): Promise<any> {
|
|
242
|
+
await this.initPromise;
|
|
196
243
|
const coll = this.db.collection(collection);
|
|
197
244
|
return await coll.dropIndex(indexName);
|
|
198
245
|
}
|
|
199
246
|
|
|
200
247
|
async count(collection: string, query?: any): Promise<number> {
|
|
248
|
+
await this.initPromise;
|
|
201
249
|
const coll = this.db.collection(collection);
|
|
202
250
|
return await coll.countDocuments(query || {});
|
|
203
251
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Database MySQL Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
-
import { createFrameworkLogger } from '../../logger';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database.js';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger/index.js';
|
|
4
|
+
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
4
5
|
|
|
5
6
|
interface MySQLConfig {
|
|
6
7
|
host?: string;
|
|
@@ -9,16 +10,35 @@ interface MySQLConfig {
|
|
|
9
10
|
password?: string;
|
|
10
11
|
database?: string;
|
|
11
12
|
connectionLimit?: number;
|
|
13
|
+
ssl?:
|
|
14
|
+
| {
|
|
15
|
+
rejectUnauthorized?: boolean;
|
|
16
|
+
ca?: string;
|
|
17
|
+
cert?: string;
|
|
18
|
+
key?: string;
|
|
19
|
+
passphrase?: string;
|
|
20
|
+
servername?: string;
|
|
21
|
+
checkServerIdentity?: boolean;
|
|
22
|
+
ciphers?: string;
|
|
23
|
+
secureProtocol?: string;
|
|
24
|
+
}
|
|
25
|
+
| boolean;
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
export class MySQLAdapter implements DatabaseAdapter {
|
|
15
29
|
private pool: any;
|
|
16
30
|
private logger = createFrameworkLogger('MySQL');
|
|
31
|
+
private initPromise: Promise<void>;
|
|
17
32
|
|
|
18
33
|
constructor(config: MySQLConfig) {
|
|
34
|
+
this.initPromise = this.initialize(config);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private async initialize(config: MySQLConfig): Promise<void> {
|
|
19
38
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
39
|
+
const mysqlPath = resolveUserPackage('mysql2/promise');
|
|
40
|
+
const mysql = await import(mysqlPath);
|
|
41
|
+
this.pool = mysql.default.createPool({
|
|
22
42
|
host: config.host || 'localhost',
|
|
23
43
|
port: config.port || 3306,
|
|
24
44
|
user: config.user || 'root',
|
|
@@ -27,6 +47,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
27
47
|
waitForConnections: true,
|
|
28
48
|
connectionLimit: config.connectionLimit || 10,
|
|
29
49
|
queueLimit: 0,
|
|
50
|
+
ssl: typeof config.ssl === 'object' ? { ...config.ssl } : config.ssl || false,
|
|
30
51
|
});
|
|
31
52
|
} catch (error) {
|
|
32
53
|
throw new Error(
|
|
@@ -36,6 +57,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
async connect(): Promise<void> {
|
|
60
|
+
await this.initPromise;
|
|
39
61
|
try {
|
|
40
62
|
const connection = await this.pool.getConnection();
|
|
41
63
|
connection.release();
|
|
@@ -49,10 +71,12 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
49
71
|
}
|
|
50
72
|
|
|
51
73
|
async disconnect(): Promise<void> {
|
|
74
|
+
await this.initPromise;
|
|
52
75
|
await this.pool.end();
|
|
53
76
|
}
|
|
54
77
|
|
|
55
78
|
async query<T = any>(sql: string, params?: any[]): Promise<T[]> {
|
|
79
|
+
await this.initPromise;
|
|
56
80
|
const [rows] = await this.pool.execute(sql, params);
|
|
57
81
|
return rows as T[];
|
|
58
82
|
}
|
|
@@ -63,6 +87,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
63
87
|
}
|
|
64
88
|
|
|
65
89
|
async insert<T = any>(table: string, data: Record<string, any>): Promise<T> {
|
|
90
|
+
await this.initPromise;
|
|
66
91
|
const keys = Object.keys(data);
|
|
67
92
|
const values = Object.values(data);
|
|
68
93
|
const placeholders = keys.map(() => '?').join(', ');
|
|
@@ -83,6 +108,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
83
108
|
data: Record<string, any>,
|
|
84
109
|
where: Record<string, any>
|
|
85
110
|
): Promise<T> {
|
|
111
|
+
await this.initPromise;
|
|
86
112
|
const setClause = Object.keys(data)
|
|
87
113
|
.map(key => `${key} = ?`)
|
|
88
114
|
.join(', ');
|
|
@@ -105,6 +131,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
105
131
|
}
|
|
106
132
|
|
|
107
133
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
134
|
+
await this.initPromise;
|
|
108
135
|
const whereClause = Object.keys(where)
|
|
109
136
|
.map(key => `${key} = ?`)
|
|
110
137
|
.join(' AND ');
|
|
@@ -115,6 +142,7 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
115
142
|
}
|
|
116
143
|
|
|
117
144
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
145
|
+
await this.initPromise;
|
|
118
146
|
const connection = await this.pool.getConnection();
|
|
119
147
|
|
|
120
148
|
try {
|