@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.
- package/README.md +256 -74
- package/dist/core/auth/morojs-adapter.js +20 -20
- package/dist/core/auth/morojs-adapter.js.map +1 -1
- package/dist/core/config/file-loader.d.ts +6 -1
- package/dist/core/config/file-loader.js +249 -19
- package/dist/core/config/file-loader.js.map +1 -1
- package/dist/core/config/index.d.ts +12 -41
- package/dist/core/config/index.js +54 -65
- package/dist/core/config/index.js.map +1 -1
- package/dist/core/config/loader.d.ts +7 -0
- package/dist/core/config/loader.js +269 -0
- package/dist/core/config/loader.js.map +1 -0
- package/dist/core/config/schema.d.ts +2 -2
- package/dist/core/config/schema.js +44 -52
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/config/utils.d.ts +3 -10
- package/dist/core/config/utils.js +58 -31
- package/dist/core/config/utils.js.map +1 -1
- package/dist/core/config/validation.d.ts +17 -0
- package/dist/core/config/validation.js +131 -0
- package/dist/core/config/validation.js.map +1 -0
- package/dist/core/database/adapters/drizzle.d.ts +1 -1
- package/dist/core/database/adapters/drizzle.js +11 -18
- 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 +29 -19
- package/dist/core/database/adapters/index.js.map +1 -1
- package/dist/core/database/adapters/mongodb.d.ts +1 -13
- package/dist/core/database/adapters/mongodb.js +10 -46
- package/dist/core/database/adapters/mongodb.js.map +1 -1
- package/dist/core/database/adapters/mysql.d.ts +1 -14
- package/dist/core/database/adapters/mysql.js +9 -19
- package/dist/core/database/adapters/mysql.js.map +1 -1
- package/dist/core/database/adapters/postgresql.d.ts +2 -12
- package/dist/core/database/adapters/postgresql.js +9 -19
- package/dist/core/database/adapters/postgresql.js.map +1 -1
- package/dist/core/database/adapters/redis.d.ts +1 -12
- package/dist/core/database/adapters/redis.js +13 -48
- package/dist/core/database/adapters/redis.js.map +1 -1
- package/dist/core/database/adapters/sqlite.d.ts +1 -3
- package/dist/core/database/adapters/sqlite.js +8 -19
- 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 +18 -2
- package/dist/core/database/index.js.map +1 -1
- package/dist/core/docs/index.d.ts +9 -9
- package/dist/core/docs/index.js +35 -14
- 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 +16 -11
- 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 +11 -5
- 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 +9 -4
- 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 +29 -26
- package/dist/core/docs/swagger-ui.js.map +1 -1
- package/dist/core/docs/zod-to-openapi.js +28 -31
- 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 +10 -6
- 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 +5 -1
- package/dist/core/events/index.js.map +1 -1
- package/dist/core/framework.d.ts +12 -19
- package/dist/core/framework.js +100 -277
- package/dist/core/framework.js.map +1 -1
- package/dist/core/http/http-server.d.ts +1 -13
- package/dist/core/http/http-server.js +85 -175
- package/dist/core/http/http-server.js.map +1 -1
- package/dist/core/http/index.d.ts +3 -4
- package/dist/core/http/index.js +8 -3
- package/dist/core/http/index.js.map +1 -1
- package/dist/core/http/router.d.ts +1 -13
- package/dist/core/http/router.js +43 -117
- package/dist/core/http/router.js.map +1 -1
- package/dist/core/logger/filters.d.ts +1 -1
- package/dist/core/logger/filters.js +23 -20
- package/dist/core/logger/filters.js.map +1 -1
- package/dist/core/logger/index.d.ts +3 -3
- package/dist/core/logger/index.js +24 -2
- package/dist/core/logger/index.js.map +1 -1
- package/dist/core/logger/logger.d.ts +14 -30
- package/dist/core/logger/logger.js +223 -398
- package/dist/core/logger/logger.js.map +1 -1
- package/dist/core/logger/outputs.d.ts +1 -1
- package/dist/core/logger/outputs.js +17 -8
- 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 +47 -10
- 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 +17 -10
- 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 +7 -3
- package/dist/core/middleware/built-in/adapters/cache/memory.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cache/redis.d.ts +1 -3
- package/dist/core/middleware/built-in/adapters/cache/redis.js +9 -11
- 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 +7 -3
- 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 +7 -3
- package/dist/core/middleware/built-in/adapters/cdn/cloudflare.js.map +1 -1
- package/dist/core/middleware/built-in/adapters/cdn/cloudfront.d.ts +1 -3
- package/dist/core/middleware/built-in/adapters/cdn/cloudfront.js +10 -12
- 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 +17 -10
- 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 +23 -4
- package/dist/core/middleware/built-in/adapters/index.js.map +1 -1
- package/dist/core/middleware/built-in/auth-helpers.js +22 -11
- 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 +9 -4
- 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 +26 -93
- 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 +12 -11
- 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 +9 -5
- 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 +7 -3
- 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 +7 -3
- 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 +8 -5
- 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 +8 -5
- package/dist/core/middleware/built-in/csrf.js.map +1 -1
- package/dist/core/middleware/built-in/error-tracker.js +7 -3
- package/dist/core/middleware/built-in/error-tracker.js.map +1 -1
- package/dist/core/middleware/built-in/index.d.ts +27 -28
- package/dist/core/middleware/built-in/index.js +78 -48
- package/dist/core/middleware/built-in/index.js.map +1 -1
- package/dist/core/middleware/built-in/performance-monitor.js +7 -3
- 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 +7 -3
- package/dist/core/middleware/built-in/rate-limit.js.map +1 -1
- package/dist/core/middleware/built-in/request-logger.js +8 -5
- 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 +15 -11
- 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 +14 -12
- 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 +7 -3
- 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 +28 -8
- package/dist/core/middleware/index.js.map +1 -1
- package/dist/core/modules/auto-discovery.d.ts +2 -19
- package/dist/core/modules/auto-discovery.js +74 -391
- 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 +9 -2
- package/dist/core/modules/index.js.map +1 -1
- package/dist/core/modules/modules.d.ts +3 -3
- package/dist/core/modules/modules.js +54 -23
- package/dist/core/modules/modules.js.map +1 -1
- package/dist/core/networking/adapters/index.d.ts +3 -4
- package/dist/core/networking/adapters/index.js +7 -3
- 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 +40 -5
- package/dist/core/networking/adapters/socketio-adapter.js.map +1 -1
- package/dist/core/networking/adapters/ws-adapter.d.ts +2 -2
- package/dist/core/networking/adapters/ws-adapter.js +43 -8
- package/dist/core/networking/adapters/ws-adapter.js.map +1 -1
- package/dist/core/networking/index.d.ts +2 -3
- package/dist/core/networking/index.js +7 -2
- package/dist/core/networking/index.js.map +1 -1
- package/dist/core/networking/service-discovery.js +12 -8
- package/dist/core/networking/service-discovery.js.map +1 -1
- package/dist/core/networking/websocket-adapter.js +2 -1
- 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 +11 -9
- package/dist/core/networking/websocket-manager.js.map +1 -1
- package/dist/core/routing/app-integration.d.ts +2 -2
- package/dist/core/routing/app-integration.js +12 -7
- package/dist/core/routing/app-integration.js.map +1 -1
- package/dist/core/routing/index.d.ts +2 -22
- package/dist/core/routing/index.js +27 -185
- package/dist/core/routing/index.js.map +1 -1
- package/dist/core/runtime/aws-lambda-adapter.d.ts +3 -3
- package/dist/core/runtime/aws-lambda-adapter.js +6 -2
- 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 +7 -3
- 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 +6 -2
- 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 +35 -22
- 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 +49 -18
- 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 +6 -2
- package/dist/core/runtime/vercel-edge-adapter.js.map +1 -1
- package/dist/core/utilities/circuit-breaker.js +5 -1
- package/dist/core/utilities/circuit-breaker.js.map +1 -1
- package/dist/core/utilities/container.js +22 -12
- package/dist/core/utilities/container.js.map +1 -1
- package/dist/core/utilities/hooks.d.ts +2 -2
- package/dist/core/utilities/hooks.js +12 -7
- package/dist/core/utilities/hooks.js.map +1 -1
- package/dist/core/utilities/index.d.ts +4 -5
- package/dist/core/utilities/index.js +19 -5
- package/dist/core/utilities/index.js.map +1 -1
- package/dist/core/validation/adapters.d.ts +1 -1
- package/dist/core/validation/adapters.js +26 -15
- package/dist/core/validation/adapters.js.map +1 -1
- package/dist/core/validation/index.d.ts +4 -6
- package/dist/core/validation/index.js +28 -57
- package/dist/core/validation/index.js.map +1 -1
- package/dist/core/validation/schema-interface.js +9 -3
- package/dist/core/validation/schema-interface.js.map +1 -1
- package/dist/index.d.ts +52 -51
- package/dist/index.js +132 -23
- package/dist/index.js.map +1 -1
- package/dist/moro.d.ts +10 -61
- package/dist/moro.js +237 -575
- package/dist/moro.js.map +1 -1
- package/dist/types/auth.js +9 -3
- package/dist/types/auth.js.map +1 -1
- package/dist/types/cache.js +2 -1
- package/dist/types/cdn.js +2 -1
- package/dist/types/config.d.ts +2 -70
- package/dist/types/config.js +2 -1
- package/dist/types/config.js.map +1 -1
- package/dist/types/core.d.ts +42 -36
- package/dist/types/core.js +2 -1
- package/dist/types/database.js +2 -1
- package/dist/types/discovery.js +2 -1
- package/dist/types/events.js +2 -1
- package/dist/types/hooks.d.ts +1 -1
- package/dist/types/hooks.js +2 -1
- package/dist/types/http.d.ts +1 -16
- package/dist/types/http.js +2 -1
- package/dist/types/logger.d.ts +0 -7
- package/dist/types/logger.js +2 -1
- package/dist/types/module.d.ts +0 -11
- package/dist/types/module.js +2 -1
- package/dist/types/runtime.d.ts +1 -1
- package/dist/types/runtime.js +2 -1
- package/dist/types/session.js +2 -1
- package/package.json +52 -19
- package/src/core/auth/morojs-adapter.ts +13 -18
- package/src/core/config/file-loader.ts +273 -13
- package/src/core/config/index.ts +34 -83
- package/src/core/config/loader.ts +633 -0
- package/src/core/config/schema.ts +33 -44
- package/src/core/config/utils.ts +31 -24
- package/src/core/config/validation.ts +140 -0
- package/src/core/database/README.md +16 -26
- package/src/core/database/adapters/drizzle.ts +6 -18
- package/src/core/database/adapters/index.ts +13 -13
- package/src/core/database/adapters/mongodb.ts +5 -53
- package/src/core/database/adapters/mysql.ts +4 -32
- package/src/core/database/adapters/postgresql.ts +5 -30
- package/src/core/database/adapters/redis.ts +8 -61
- package/src/core/database/adapters/sqlite.ts +3 -19
- 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 +6 -3
- package/src/core/docs/simple-docs.ts +2 -2
- package/src/core/docs/swagger-ui.ts +16 -19
- package/src/core/docs/zod-to-openapi.ts +34 -34
- package/src/core/events/event-bus.ts +2 -2
- package/src/core/events/index.ts +2 -2
- package/src/core/framework.ts +67 -311
- package/src/core/http/http-server.ts +45 -190
- package/src/core/http/index.ts +3 -4
- package/src/core/http/router.ts +40 -129
- package/src/core/logger/filters.ts +5 -13
- package/src/core/logger/index.ts +3 -4
- package/src/core/logger/logger.ts +216 -435
- package/src/core/logger/outputs.ts +3 -1
- 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 +4 -18
- 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 +5 -16
- 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 +21 -102
- package/src/core/middleware/built-in/cache.ts +6 -8
- 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 +30 -38
- 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 +1 -3
- package/src/core/middleware/built-in/session.ts +8 -7
- package/src/core/middleware/built-in/sse.ts +9 -11
- 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 +15 -478
- package/src/core/modules/index.ts +2 -2
- package/src/core/modules/modules.ts +12 -23
- package/src/core/networking/adapters/index.ts +3 -4
- package/src/core/networking/adapters/socketio-adapter.ts +3 -5
- package/src/core/networking/adapters/ws-adapter.ts +9 -8
- package/src/core/networking/index.ts +2 -3
- package/src/core/networking/service-discovery.ts +7 -6
- package/src/core/networking/websocket-manager.ts +7 -7
- package/src/core/routing/app-integration.ts +3 -3
- package/src/core/routing/index.ts +17 -201
- 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 +10 -16
- package/src/core/runtime/vercel-edge-adapter.ts +3 -3
- package/src/core/utilities/hooks.ts +3 -3
- package/src/core/utilities/index.ts +4 -5
- package/src/core/validation/adapters.ts +1 -1
- package/src/core/validation/index.ts +16 -68
- package/src/index.ts +66 -73
- package/src/moro.ts +204 -685
- package/src/types/config.ts +2 -71
- package/src/types/core.ts +47 -49
- package/src/types/hooks.ts +1 -1
- package/src/types/http.ts +1 -23
- package/src/types/logger.ts +0 -9
- package/src/types/module.ts +0 -12
- package/src/types/runtime.ts +1 -1
- package/tsconfig.json +2 -4
- package/dist/core/config/config-manager.d.ts +0 -44
- package/dist/core/config/config-manager.js +0 -104
- package/dist/core/config/config-manager.js.map +0 -1
- package/dist/core/config/config-sources.d.ts +0 -21
- package/dist/core/config/config-sources.js +0 -499
- package/dist/core/config/config-sources.js.map +0 -1
- package/dist/core/config/config-validator.d.ts +0 -21
- package/dist/core/config/config-validator.js +0 -788
- package/dist/core/config/config-validator.js.map +0 -1
- package/dist/core/http/uws-http-server.d.ts +0 -64
- package/dist/core/http/uws-http-server.js +0 -688
- package/dist/core/http/uws-http-server.js.map +0 -1
- package/dist/core/middleware/built-in/jwt-helpers.d.ts +0 -118
- package/dist/core/middleware/built-in/jwt-helpers.js +0 -218
- package/dist/core/middleware/built-in/jwt-helpers.js.map +0 -1
- package/dist/core/networking/adapters/uws-adapter.d.ts +0 -44
- package/dist/core/networking/adapters/uws-adapter.js +0 -513
- package/dist/core/networking/adapters/uws-adapter.js.map +0 -1
- package/dist/core/utilities/package-utils.d.ts +0 -38
- package/dist/core/utilities/package-utils.js +0 -57
- package/dist/core/utilities/package-utils.js.map +0 -1
- package/jest.config.mjs +0 -41
- package/src/core/config/config-manager.ts +0 -133
- package/src/core/config/config-sources.ts +0 -596
- package/src/core/config/config-validator.ts +0 -1113
- package/src/core/http/uws-http-server.ts +0 -794
- package/src/core/middleware/built-in/jwt-helpers.ts +0 -243
- package/src/core/networking/adapters/uws-adapter.ts +0 -619
- package/src/core/utilities/package-utils.ts +0 -59
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
// Core Configuration Schema for Moro Framework
|
|
2
2
|
|
|
3
|
-
import { AppConfig } from '../../types/config
|
|
3
|
+
import { AppConfig } from '../../types/config';
|
|
4
4
|
|
|
5
|
-
//
|
|
5
|
+
// Default configuration values
|
|
6
6
|
export const DEFAULT_CONFIG: AppConfig = {
|
|
7
7
|
server: {
|
|
8
8
|
port: 3001,
|
|
9
9
|
host: 'localhost',
|
|
10
|
+
environment: 'development',
|
|
10
11
|
maxConnections: 1000,
|
|
11
12
|
timeout: 30000,
|
|
12
|
-
bodySizeLimit: '10mb',
|
|
13
|
-
useUWebSockets: false, // Opt-in for ultra-high performance
|
|
14
|
-
requestTracking: {
|
|
15
|
-
enabled: true, // Enable by default for debugging
|
|
16
|
-
},
|
|
17
|
-
errorBoundary: {
|
|
18
|
-
enabled: true, // Always enabled for safety
|
|
19
|
-
},
|
|
20
13
|
},
|
|
21
14
|
serviceDiscovery: {
|
|
22
15
|
enabled: false,
|
|
@@ -26,38 +19,33 @@ export const DEFAULT_CONFIG: AppConfig = {
|
|
|
26
19
|
healthCheckInterval: 30000,
|
|
27
20
|
retryAttempts: 3,
|
|
28
21
|
},
|
|
29
|
-
database: {
|
|
22
|
+
database: {
|
|
23
|
+
redis: {
|
|
24
|
+
url: 'redis://localhost:6379',
|
|
25
|
+
maxRetries: 3,
|
|
26
|
+
retryDelay: 1000,
|
|
27
|
+
keyPrefix: 'moro:',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
30
|
modules: {
|
|
31
31
|
cache: {
|
|
32
|
-
enabled:
|
|
32
|
+
enabled: true,
|
|
33
33
|
defaultTtl: 300,
|
|
34
34
|
maxSize: 1000,
|
|
35
35
|
strategy: 'lru',
|
|
36
36
|
},
|
|
37
37
|
rateLimit: {
|
|
38
|
-
enabled:
|
|
38
|
+
enabled: true,
|
|
39
39
|
defaultRequests: 100,
|
|
40
40
|
defaultWindow: 60000,
|
|
41
41
|
skipSuccessfulRequests: false,
|
|
42
42
|
skipFailedRequests: false,
|
|
43
43
|
},
|
|
44
44
|
validation: {
|
|
45
|
-
enabled:
|
|
45
|
+
enabled: true,
|
|
46
46
|
stripUnknown: true,
|
|
47
47
|
abortEarly: false,
|
|
48
48
|
},
|
|
49
|
-
autoDiscovery: {
|
|
50
|
-
enabled: true, // Enable by default for better DX
|
|
51
|
-
paths: ['./modules', './src/modules'],
|
|
52
|
-
patterns: ['**/*.module.{ts,js}', '**/index.{ts,js}', '**/*.config.{ts,js}'],
|
|
53
|
-
recursive: true,
|
|
54
|
-
loadingStrategy: 'eager',
|
|
55
|
-
watchForChanges: false, // Opt-in for development
|
|
56
|
-
ignorePatterns: ['**/*.test.{ts,js}', '**/*.spec.{ts,js}', '**/node_modules/**'],
|
|
57
|
-
loadOrder: 'dependency',
|
|
58
|
-
failOnError: false, // Graceful degradation
|
|
59
|
-
maxDepth: 5,
|
|
60
|
-
},
|
|
61
49
|
},
|
|
62
50
|
logging: {
|
|
63
51
|
level: 'info',
|
|
@@ -81,14 +69,14 @@ export const DEFAULT_CONFIG: AppConfig = {
|
|
|
81
69
|
},
|
|
82
70
|
security: {
|
|
83
71
|
cors: {
|
|
84
|
-
enabled:
|
|
72
|
+
enabled: true,
|
|
85
73
|
origin: '*',
|
|
86
74
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
|
87
75
|
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
88
76
|
credentials: false,
|
|
89
77
|
},
|
|
90
78
|
helmet: {
|
|
91
|
-
enabled:
|
|
79
|
+
enabled: true,
|
|
92
80
|
contentSecurityPolicy: true,
|
|
93
81
|
hsts: true,
|
|
94
82
|
noSniff: true,
|
|
@@ -102,15 +90,26 @@ export const DEFAULT_CONFIG: AppConfig = {
|
|
|
102
90
|
},
|
|
103
91
|
},
|
|
104
92
|
},
|
|
105
|
-
external: {
|
|
93
|
+
external: {
|
|
94
|
+
stripe: {
|
|
95
|
+
apiVersion: '2023-10-16',
|
|
96
|
+
},
|
|
97
|
+
paypal: {
|
|
98
|
+
environment: 'sandbox',
|
|
99
|
+
},
|
|
100
|
+
smtp: {
|
|
101
|
+
port: 587,
|
|
102
|
+
secure: false,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
106
105
|
performance: {
|
|
107
106
|
compression: {
|
|
108
|
-
enabled:
|
|
107
|
+
enabled: true,
|
|
109
108
|
level: 6,
|
|
110
109
|
threshold: 1024,
|
|
111
110
|
},
|
|
112
111
|
circuitBreaker: {
|
|
113
|
-
enabled:
|
|
112
|
+
enabled: true,
|
|
114
113
|
failureThreshold: 5,
|
|
115
114
|
resetTimeout: 60000,
|
|
116
115
|
monitoringPeriod: 10000,
|
|
@@ -118,23 +117,13 @@ export const DEFAULT_CONFIG: AppConfig = {
|
|
|
118
117
|
clustering: {
|
|
119
118
|
enabled: false,
|
|
120
119
|
workers: 1,
|
|
121
|
-
memoryPerWorkerGB: undefined,
|
|
122
120
|
},
|
|
123
121
|
},
|
|
124
|
-
websocket: {
|
|
125
|
-
enabled: false, // Opt-in - user must explicitly enable WebSockets
|
|
126
|
-
},
|
|
127
122
|
};
|
|
128
123
|
|
|
129
|
-
//
|
|
130
|
-
// This export is kept for backward compatibility only
|
|
131
|
-
// Note: For actual validation, use validateConfig() from config-validator.ts directly
|
|
124
|
+
// Simple compatibility export - just return the config as-is
|
|
132
125
|
export const ConfigSchema = {
|
|
133
|
-
parse: (data: any): AppConfig =>
|
|
134
|
-
// Simple pass-through for backward compatibility
|
|
135
|
-
// Real validation happens in the config loading pipeline
|
|
136
|
-
return data as AppConfig;
|
|
137
|
-
},
|
|
126
|
+
parse: (data: any): AppConfig => data as AppConfig,
|
|
138
127
|
};
|
|
139
128
|
|
|
140
129
|
// Re-export types for backward compatibility
|
|
@@ -148,7 +137,7 @@ export type {
|
|
|
148
137
|
SecurityConfig,
|
|
149
138
|
ExternalServicesConfig,
|
|
150
139
|
PerformanceConfig,
|
|
151
|
-
} from '../../types/config
|
|
140
|
+
} from '../../types/config';
|
|
152
141
|
|
|
153
142
|
// For backward compatibility with modules that expect schema objects
|
|
154
143
|
export const ServerConfigSchema = { parse: (data: any) => data };
|
package/src/core/config/utils.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
// Configuration Utilities for Modules and Environment Handling
|
|
2
|
-
import { AppConfig } from './schema
|
|
3
|
-
import { createFrameworkLogger } from '../logger
|
|
4
|
-
import { getGlobalConfig } from './config-manager.js';
|
|
2
|
+
import { AppConfig } from './schema';
|
|
3
|
+
import { createFrameworkLogger } from '../logger';
|
|
5
4
|
|
|
6
5
|
const logger = createFrameworkLogger('ConfigUtils');
|
|
7
6
|
|
|
7
|
+
// Global configuration store
|
|
8
|
+
let appConfig: AppConfig | null = null;
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
|
-
* Set the global configuration (
|
|
10
|
-
* @deprecated Use the new immutable config system instead
|
|
11
|
+
* Set the global configuration (used by framework initialization)
|
|
11
12
|
*/
|
|
12
|
-
export function setConfig(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
);
|
|
13
|
+
export function setConfig(config: AppConfig): void {
|
|
14
|
+
appConfig = config;
|
|
15
|
+
logger.debug('Global configuration updated');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Get the global configuration
|
|
20
|
-
* This now delegates to the new config manager
|
|
21
20
|
*/
|
|
22
21
|
export function getConfig(): AppConfig {
|
|
23
|
-
|
|
22
|
+
if (!appConfig) {
|
|
23
|
+
throw new Error('Configuration not initialized. Call loadConfig() first.');
|
|
24
|
+
}
|
|
25
|
+
return appConfig;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -61,7 +63,6 @@ function coerceEnvironmentValue(value: string): any {
|
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* Create module-specific configuration with environment override support
|
|
64
|
-
* This now uses the new immutable config system
|
|
65
66
|
*/
|
|
66
67
|
export function createModuleConfig<T>(
|
|
67
68
|
schema: { parse: (data: any) => T },
|
|
@@ -71,12 +72,10 @@ export function createModuleConfig<T>(
|
|
|
71
72
|
// Try to get global config, but don't fail if not initialized
|
|
72
73
|
let globalConfig = {};
|
|
73
74
|
try {
|
|
75
|
+
const { getGlobalConfig } = require('./index');
|
|
74
76
|
globalConfig = getGlobalConfig();
|
|
75
77
|
} catch {
|
|
76
78
|
// 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
|
-
);
|
|
80
79
|
globalConfig = {};
|
|
81
80
|
}
|
|
82
81
|
|
|
@@ -105,7 +104,7 @@ export function createModuleConfig<T>(
|
|
|
105
104
|
// Priority: environment variables > global config > default config
|
|
106
105
|
const mergedConfig = {
|
|
107
106
|
...defaultConfig,
|
|
108
|
-
...globalConfig, // Now
|
|
107
|
+
...globalConfig, // Now actually using global config!
|
|
109
108
|
...envConfig,
|
|
110
109
|
};
|
|
111
110
|
|
|
@@ -209,10 +208,9 @@ export function envVar(prefix: string, name: string): string {
|
|
|
209
208
|
|
|
210
209
|
/**
|
|
211
210
|
* Get configuration value with dot notation
|
|
212
|
-
* This now delegates to the new config manager
|
|
213
211
|
*/
|
|
214
212
|
export function getConfigValue(path: string): any {
|
|
215
|
-
const config =
|
|
213
|
+
const config = getConfig();
|
|
216
214
|
|
|
217
215
|
return path.split('.').reduce((obj, key) => {
|
|
218
216
|
return obj && obj[key] !== undefined ? obj[key] : undefined;
|
|
@@ -221,24 +219,33 @@ export function getConfigValue(path: string): any {
|
|
|
221
219
|
|
|
222
220
|
/**
|
|
223
221
|
* Check if we're in development environment
|
|
224
|
-
* Now reads NODE_ENV directly for consistency with Node.js ecosystem
|
|
225
222
|
*/
|
|
226
223
|
export function isDevelopment(): boolean {
|
|
227
|
-
|
|
224
|
+
try {
|
|
225
|
+
return getConfig().server.environment === 'development';
|
|
226
|
+
} catch {
|
|
227
|
+
return process.env.NODE_ENV === 'development';
|
|
228
|
+
}
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
/**
|
|
231
232
|
* 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
|
-
|
|
235
|
+
try {
|
|
236
|
+
return getConfig().server.environment === 'production';
|
|
237
|
+
} catch {
|
|
238
|
+
return process.env.NODE_ENV === 'production';
|
|
239
|
+
}
|
|
236
240
|
}
|
|
237
241
|
|
|
238
242
|
/**
|
|
239
243
|
* Check if we're in staging environment
|
|
240
|
-
* Now reads NODE_ENV directly for consistency with Node.js ecosystem
|
|
241
244
|
*/
|
|
242
245
|
export function isStaging(): boolean {
|
|
243
|
-
|
|
246
|
+
try {
|
|
247
|
+
return getConfig().server.environment === 'staging';
|
|
248
|
+
} catch {
|
|
249
|
+
return process.env.NODE_ENV === 'staging';
|
|
250
|
+
}
|
|
244
251
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Configuration Validation Functions
|
|
2
|
+
// Validation for config system with simple TypeScript functions
|
|
3
|
+
|
|
4
|
+
export class ConfigValidationError extends Error {
|
|
5
|
+
constructor(
|
|
6
|
+
public field: string,
|
|
7
|
+
public value: unknown,
|
|
8
|
+
message: string
|
|
9
|
+
) {
|
|
10
|
+
super(`Configuration validation failed for '${field}': ${message}`);
|
|
11
|
+
this.name = 'ConfigValidationError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Type-safe validation functions for configuration
|
|
16
|
+
export function validatePort(value: unknown, field = 'port'): number {
|
|
17
|
+
const num = Number(value);
|
|
18
|
+
if (isNaN(num) || num < 1 || num > 65535) {
|
|
19
|
+
throw new ConfigValidationError(field, value, 'Must be a number between 1 and 65535');
|
|
20
|
+
}
|
|
21
|
+
return num;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function validateBoolean(value: unknown, field = 'boolean'): boolean {
|
|
25
|
+
if (value === 'true' || value === true) return true;
|
|
26
|
+
if (value === 'false' || value === false) return false;
|
|
27
|
+
if (value === '1' || value === 1) return true;
|
|
28
|
+
if (value === '0' || value === 0) return false;
|
|
29
|
+
throw new ConfigValidationError(field, value, 'Must be a boolean (true/false) or numeric (1/0)');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function validateNumber(
|
|
33
|
+
value: unknown,
|
|
34
|
+
field = 'number',
|
|
35
|
+
options: { min?: number; max?: number } = {}
|
|
36
|
+
): number {
|
|
37
|
+
const num = Number(value);
|
|
38
|
+
if (isNaN(num)) {
|
|
39
|
+
throw new ConfigValidationError(field, value, 'Must be a valid number');
|
|
40
|
+
}
|
|
41
|
+
if (options.min !== undefined && num < options.min) {
|
|
42
|
+
throw new ConfigValidationError(field, value, `Must be at least ${options.min}`);
|
|
43
|
+
}
|
|
44
|
+
if (options.max !== undefined && num > options.max) {
|
|
45
|
+
throw new ConfigValidationError(field, value, `Must be at most ${options.max}`);
|
|
46
|
+
}
|
|
47
|
+
return num;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function validateString(value: unknown, field = 'string'): string {
|
|
51
|
+
if (typeof value !== 'string') {
|
|
52
|
+
throw new ConfigValidationError(field, value, 'Must be a string');
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function validateUrl(value: unknown, field = 'url'): string {
|
|
58
|
+
const str = validateString(value, field);
|
|
59
|
+
try {
|
|
60
|
+
new URL(str);
|
|
61
|
+
return str;
|
|
62
|
+
} catch {
|
|
63
|
+
throw new ConfigValidationError(field, value, 'Must be a valid URL');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function validateEnum<T extends string>(
|
|
68
|
+
value: unknown,
|
|
69
|
+
validValues: readonly T[],
|
|
70
|
+
field = 'enum'
|
|
71
|
+
): T {
|
|
72
|
+
const str = validateString(value, field);
|
|
73
|
+
if (!validValues.includes(str as T)) {
|
|
74
|
+
throw new ConfigValidationError(field, value, `Must be one of: ${validValues.join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
return str as T;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function validateStringArray(value: unknown, field = 'string array'): string[] {
|
|
80
|
+
if (!Array.isArray(value)) {
|
|
81
|
+
// Try to parse comma-separated string
|
|
82
|
+
if (typeof value === 'string') {
|
|
83
|
+
return value
|
|
84
|
+
.split(',')
|
|
85
|
+
.map(s => s.trim())
|
|
86
|
+
.filter(s => s.length > 0);
|
|
87
|
+
}
|
|
88
|
+
throw new ConfigValidationError(field, value, 'Must be an array or comma-separated string');
|
|
89
|
+
}
|
|
90
|
+
return value.map((item, index) => validateString(item, `${field}[${index}]`));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function validateOptional<T>(
|
|
94
|
+
value: unknown,
|
|
95
|
+
validator: (value: unknown, field: string) => T,
|
|
96
|
+
field: string
|
|
97
|
+
): T | undefined {
|
|
98
|
+
if (value === undefined || value === null || value === '') {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return validator(value, field);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Coercion helpers for environment variables
|
|
105
|
+
export function coerceEnvValue(value: string): unknown {
|
|
106
|
+
// Handle common patterns in environment variables
|
|
107
|
+
|
|
108
|
+
// Null/undefined
|
|
109
|
+
if (value === '' || value === 'null' || value === 'undefined') {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Boolean
|
|
114
|
+
if (value === 'true' || value === 'false') {
|
|
115
|
+
return value === 'true';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Number (but not if it starts with 0 - could be port, zip code, etc.)
|
|
119
|
+
if (/^-?\d+(\.\d+)?$/.test(value) && !value.startsWith('0')) {
|
|
120
|
+
const num = Number(value);
|
|
121
|
+
if (!isNaN(num)) {
|
|
122
|
+
return num;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// JSON (for complex objects/arrays)
|
|
127
|
+
if (
|
|
128
|
+
(value.startsWith('{') && value.endsWith('}')) ||
|
|
129
|
+
(value.startsWith('[') && value.endsWith(']'))
|
|
130
|
+
) {
|
|
131
|
+
try {
|
|
132
|
+
return JSON.parse(value);
|
|
133
|
+
} catch {
|
|
134
|
+
// Not valid JSON, treat as string
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Return as string for all other cases
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
@@ -7,19 +7,16 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
7
7
|
### SQL Databases
|
|
8
8
|
|
|
9
9
|
#### MySQL Adapter
|
|
10
|
-
|
|
11
10
|
- **Package Required**: `mysql2`
|
|
12
11
|
- **Usage**: Production-ready with connection pooling
|
|
13
12
|
- **Type**: `mysql`
|
|
14
13
|
|
|
15
|
-
#### PostgreSQL Adapter
|
|
16
|
-
|
|
14
|
+
#### PostgreSQL Adapter
|
|
17
15
|
- **Package Required**: `pg` and `@types/pg`
|
|
18
16
|
- **Usage**: Full PostgreSQL feature support
|
|
19
17
|
- **Type**: `postgresql`, `postgres`, or `pg`
|
|
20
18
|
|
|
21
19
|
#### SQLite Adapter
|
|
22
|
-
|
|
23
20
|
- **Package Required**: `better-sqlite3`
|
|
24
21
|
- **Usage**: Lightweight, file-based database
|
|
25
22
|
- **Type**: `sqlite` or `sqlite3`
|
|
@@ -27,13 +24,11 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
27
24
|
### NoSQL Databases
|
|
28
25
|
|
|
29
26
|
#### MongoDB Adapter
|
|
30
|
-
|
|
31
27
|
- **Package Required**: `mongodb`
|
|
32
28
|
- **Usage**: Document database with aggregation support
|
|
33
29
|
- **Type**: `mongodb` or `mongo`
|
|
34
30
|
|
|
35
31
|
#### Redis Adapter
|
|
36
|
-
|
|
37
32
|
- **Package Required**: `ioredis`
|
|
38
33
|
- **Usage**: In-memory key-value store with pub/sub
|
|
39
34
|
- **Type**: `redis`
|
|
@@ -41,7 +36,6 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
41
36
|
### ORM
|
|
42
37
|
|
|
43
38
|
#### Drizzle Adapter
|
|
44
|
-
|
|
45
39
|
- **Package Required**: `drizzle-orm` + database driver
|
|
46
40
|
- **Usage**: Type-safe ORM with schema validation
|
|
47
41
|
- **Type**: `drizzle` or `orm`
|
|
@@ -49,7 +43,7 @@ The MoroJS database module provides a pluggable adapter system for different dat
|
|
|
49
43
|
## Factory Pattern (Recommended)
|
|
50
44
|
|
|
51
45
|
```typescript
|
|
52
|
-
import { createDatabaseAdapter } from '
|
|
46
|
+
import { createDatabaseAdapter } from 'moro';
|
|
53
47
|
|
|
54
48
|
// SQL Databases
|
|
55
49
|
const mysql = createDatabaseAdapter('mysql', {
|
|
@@ -58,7 +52,7 @@ const mysql = createDatabaseAdapter('mysql', {
|
|
|
58
52
|
user: 'root',
|
|
59
53
|
password: 'password',
|
|
60
54
|
database: 'my_app',
|
|
61
|
-
connectionLimit: 10
|
|
55
|
+
connectionLimit: 10
|
|
62
56
|
});
|
|
63
57
|
|
|
64
58
|
const postgres = createDatabaseAdapter('postgresql', {
|
|
@@ -68,12 +62,12 @@ const postgres = createDatabaseAdapter('postgresql', {
|
|
|
68
62
|
password: 'password',
|
|
69
63
|
database: 'my_app',
|
|
70
64
|
connectionLimit: 10,
|
|
71
|
-
ssl: false
|
|
65
|
+
ssl: false
|
|
72
66
|
});
|
|
73
67
|
|
|
74
68
|
const sqlite = createDatabaseAdapter('sqlite', {
|
|
75
69
|
filename: 'app.db',
|
|
76
|
-
memory: false
|
|
70
|
+
memory: false
|
|
77
71
|
});
|
|
78
72
|
|
|
79
73
|
// NoSQL Databases
|
|
@@ -82,34 +76,34 @@ const mongodb = createDatabaseAdapter('mongodb', {
|
|
|
82
76
|
port: 27017,
|
|
83
77
|
database: 'my_app',
|
|
84
78
|
username: 'user',
|
|
85
|
-
password: 'password'
|
|
79
|
+
password: 'password'
|
|
86
80
|
});
|
|
87
81
|
|
|
88
82
|
const redis = createDatabaseAdapter('redis', {
|
|
89
83
|
host: 'localhost',
|
|
90
84
|
port: 6379,
|
|
91
85
|
password: 'password',
|
|
92
|
-
keyPrefix: 'myapp:'
|
|
86
|
+
keyPrefix: 'myapp:'
|
|
93
87
|
});
|
|
94
88
|
|
|
95
89
|
// ORM
|
|
96
90
|
const drizzle = createDatabaseAdapter('drizzle', {
|
|
97
91
|
database: drizzleInstance,
|
|
98
|
-
schema: schemaObject
|
|
92
|
+
schema: schemaObject
|
|
99
93
|
});
|
|
100
94
|
```
|
|
101
95
|
|
|
102
96
|
## Direct Instantiation
|
|
103
97
|
|
|
104
98
|
```typescript
|
|
105
|
-
import {
|
|
106
|
-
MySQLAdapter,
|
|
107
|
-
PostgreSQLAdapter,
|
|
99
|
+
import {
|
|
100
|
+
MySQLAdapter,
|
|
101
|
+
PostgreSQLAdapter,
|
|
108
102
|
SQLiteAdapter,
|
|
109
103
|
MongoDBAdapter,
|
|
110
104
|
RedisAdapter,
|
|
111
105
|
DrizzleAdapter
|
|
112
|
-
} from '
|
|
106
|
+
} from 'moro';
|
|
113
107
|
|
|
114
108
|
// SQL
|
|
115
109
|
const mysql = new MySQLAdapter({ host: 'localhost', ... });
|
|
@@ -157,7 +151,7 @@ const updated = await db.update('users', { name: 'Jane' }, { id: 1 });
|
|
|
157
151
|
const deleted = await db.delete('users', { id: 1 });
|
|
158
152
|
|
|
159
153
|
// Transactions
|
|
160
|
-
const result = await db.transaction(async tx => {
|
|
154
|
+
const result = await db.transaction(async (tx) => {
|
|
161
155
|
const user = await tx.insert('users', userData);
|
|
162
156
|
await tx.insert('profiles', { user_id: user.id, ...profileData });
|
|
163
157
|
return user;
|
|
@@ -167,7 +161,6 @@ const result = await db.transaction(async tx => {
|
|
|
167
161
|
## Usage Examples
|
|
168
162
|
|
|
169
163
|
### SQL Operations
|
|
170
|
-
|
|
171
164
|
```typescript
|
|
172
165
|
// Standard CRUD operations work across all SQL adapters
|
|
173
166
|
const users = await db.query('SELECT * FROM users WHERE age > ?', [18]);
|
|
@@ -178,7 +171,6 @@ const deleted = await db.delete('users', { id: 1 });
|
|
|
178
171
|
```
|
|
179
172
|
|
|
180
173
|
### MongoDB Operations
|
|
181
|
-
|
|
182
174
|
```typescript
|
|
183
175
|
// MongoDB uses collections instead of tables
|
|
184
176
|
const users = await mongoDb.query('users'); // Get all
|
|
@@ -187,13 +179,12 @@ const user = await mongoDb.queryOne('users', { email: 'john@example.com' });
|
|
|
187
179
|
|
|
188
180
|
// MongoDB-specific methods
|
|
189
181
|
const stats = await mongoDb.aggregate('users', [
|
|
190
|
-
{ $group: { _id: null, avgAge: { $avg: '$age' } } }
|
|
182
|
+
{ $group: { _id: null, avgAge: { $avg: '$age' } } }
|
|
191
183
|
]);
|
|
192
184
|
await mongoDb.createIndex('users', { email: 1 }, { unique: true });
|
|
193
185
|
```
|
|
194
186
|
|
|
195
187
|
### Redis Operations
|
|
196
|
-
|
|
197
188
|
```typescript
|
|
198
189
|
// Key-value operations
|
|
199
190
|
await redisDb.set('user:123', userData, 3600); // with TTL
|
|
@@ -206,7 +197,6 @@ await redisDb.publish('notifications', message);
|
|
|
206
197
|
```
|
|
207
198
|
|
|
208
199
|
### Drizzle ORM Operations
|
|
209
|
-
|
|
210
200
|
```typescript
|
|
211
201
|
// Type-safe queries (requires schema setup)
|
|
212
202
|
const users = await drizzleDb.select('users').where(eq(schema.users.age, 25));
|
|
@@ -223,7 +213,7 @@ Choose and install the appropriate database package:
|
|
|
223
213
|
```bash
|
|
224
214
|
# SQL Databases
|
|
225
215
|
npm install mysql2 # MySQL
|
|
226
|
-
npm install pg @types/pg # PostgreSQL
|
|
216
|
+
npm install pg @types/pg # PostgreSQL
|
|
227
217
|
npm install better-sqlite3 # SQLite
|
|
228
218
|
|
|
229
219
|
# NoSQL Databases
|
|
@@ -235,4 +225,4 @@ npm install drizzle-orm # Drizzle ORM
|
|
|
235
225
|
# Plus the appropriate driver (mysql2, pg, better-sqlite3, etc.)
|
|
236
226
|
```
|
|
237
227
|
|
|
238
|
-
The adapters will gracefully handle missing packages with helpful error messages.
|
|
228
|
+
The adapters will gracefully handle missing packages with helpful error messages.
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
// Database Drizzle ORM Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
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
|
-
}
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
16
4
|
|
|
17
5
|
interface DrizzleConfig {
|
|
18
6
|
database: any; // Drizzle database instance
|
|
@@ -120,7 +108,7 @@ export class DrizzleAdapter implements DatabaseAdapter {
|
|
|
120
108
|
if (this.schema && this.schema[table]) {
|
|
121
109
|
// Use schema-based update
|
|
122
110
|
try {
|
|
123
|
-
const { eq, and } =
|
|
111
|
+
const { eq, and } = require('drizzle-orm');
|
|
124
112
|
|
|
125
113
|
// Build where conditions
|
|
126
114
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
@@ -177,7 +165,7 @@ export class DrizzleAdapter implements DatabaseAdapter {
|
|
|
177
165
|
if (this.schema && this.schema[table]) {
|
|
178
166
|
// Use schema-based delete
|
|
179
167
|
try {
|
|
180
|
-
const { eq, and } =
|
|
168
|
+
const { eq, and } = require('drizzle-orm');
|
|
181
169
|
|
|
182
170
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
183
171
|
eq(this.schema[table][key], value)
|
|
@@ -326,7 +314,7 @@ class DrizzleTransaction implements DatabaseTransaction {
|
|
|
326
314
|
): Promise<T> {
|
|
327
315
|
if (this.schema && this.schema[table]) {
|
|
328
316
|
try {
|
|
329
|
-
const { eq, and } =
|
|
317
|
+
const { eq, and } = require('drizzle-orm');
|
|
330
318
|
|
|
331
319
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
332
320
|
eq(this.schema[table][key], value)
|
|
@@ -372,7 +360,7 @@ class DrizzleTransaction implements DatabaseTransaction {
|
|
|
372
360
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
373
361
|
if (this.schema && this.schema[table]) {
|
|
374
362
|
try {
|
|
375
|
-
const { eq, and } =
|
|
363
|
+
const { eq, and } = require('drizzle-orm');
|
|
376
364
|
|
|
377
365
|
const conditions = Object.entries(where).map(([key, value]) =>
|
|
378
366
|
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';
|
|
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';
|
|
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';
|
|
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';
|
|
16
16
|
|
|
17
17
|
// Adapter factory function for auto-loading
|
|
18
18
|
export function createDatabaseAdapter(type: string, options: any = {}): DatabaseAdapter {
|