@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,7 +1,6 @@
|
|
|
1
1
|
// Database MongoDB Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
4
|
-
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
5
4
|
|
|
6
5
|
interface MongoDBConfig {
|
|
7
6
|
url?: string;
|
|
@@ -12,16 +11,6 @@ interface MongoDBConfig {
|
|
|
12
11
|
database?: string;
|
|
13
12
|
authSource?: string;
|
|
14
13
|
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
|
-
};
|
|
25
14
|
replicaSet?: string;
|
|
26
15
|
maxPoolSize?: number;
|
|
27
16
|
minPoolSize?: number;
|
|
@@ -36,43 +25,18 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
36
25
|
private client: any;
|
|
37
26
|
private db: any;
|
|
38
27
|
private logger = createFrameworkLogger('MongoDB');
|
|
39
|
-
private initPromise: Promise<void>;
|
|
40
28
|
|
|
41
29
|
constructor(config: MongoDBConfig) {
|
|
42
|
-
this.initPromise = this.initialize(config);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private async initialize(config: MongoDBConfig): Promise<void> {
|
|
46
30
|
try {
|
|
47
|
-
const
|
|
48
|
-
const mongodb = await import(mongodbPath);
|
|
49
|
-
const { MongoClient } = mongodb;
|
|
31
|
+
const { MongoClient } = require('mongodb');
|
|
50
32
|
|
|
51
33
|
const url = config.url || this.buildConnectionString(config);
|
|
52
34
|
|
|
53
|
-
|
|
35
|
+
this.client = new MongoClient(url, {
|
|
54
36
|
maxPoolSize: config.maxPoolSize || 10,
|
|
55
37
|
minPoolSize: config.minPoolSize || 0,
|
|
56
38
|
ssl: config.ssl || false,
|
|
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);
|
|
39
|
+
});
|
|
76
40
|
|
|
77
41
|
this.db = this.client.db(config.database || 'moro_app');
|
|
78
42
|
|
|
@@ -94,7 +58,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
94
58
|
}
|
|
95
59
|
|
|
96
60
|
async connect(): Promise<void> {
|
|
97
|
-
await this.initPromise;
|
|
98
61
|
try {
|
|
99
62
|
await this.client.connect();
|
|
100
63
|
await this.client.db('admin').command({ ping: 1 });
|
|
@@ -108,13 +71,11 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
108
71
|
}
|
|
109
72
|
|
|
110
73
|
async disconnect(): Promise<void> {
|
|
111
|
-
await this.initPromise;
|
|
112
74
|
await this.client.close();
|
|
113
75
|
}
|
|
114
76
|
|
|
115
77
|
// For MongoDB, we'll treat "sql" as collection name and "params" as query/pipeline
|
|
116
78
|
async query<T = any>(collection: string, pipeline?: any[]): Promise<T[]> {
|
|
117
|
-
await this.initPromise;
|
|
118
79
|
try {
|
|
119
80
|
const coll = this.db.collection(collection);
|
|
120
81
|
|
|
@@ -141,7 +102,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
141
102
|
}
|
|
142
103
|
|
|
143
104
|
async queryOne<T = any>(collection: string, query?: any): Promise<T | null> {
|
|
144
|
-
await this.initPromise;
|
|
145
105
|
try {
|
|
146
106
|
const coll = this.db.collection(collection);
|
|
147
107
|
return await coll.findOne(query || {});
|
|
@@ -155,7 +115,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
155
115
|
}
|
|
156
116
|
|
|
157
117
|
async insert<T = any>(collection: string, data: Record<string, any>): Promise<T> {
|
|
158
|
-
await this.initPromise;
|
|
159
118
|
try {
|
|
160
119
|
const coll = this.db.collection(collection);
|
|
161
120
|
const result = await coll.insertOne(data);
|
|
@@ -176,7 +135,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
176
135
|
data: Record<string, any>,
|
|
177
136
|
where: Record<string, any>
|
|
178
137
|
): Promise<T> {
|
|
179
|
-
await this.initPromise;
|
|
180
138
|
try {
|
|
181
139
|
const coll = this.db.collection(collection);
|
|
182
140
|
const result = await coll.findOneAndUpdate(
|
|
@@ -196,7 +154,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
196
154
|
}
|
|
197
155
|
|
|
198
156
|
async delete(collection: string, where: Record<string, any>): Promise<number> {
|
|
199
|
-
await this.initPromise;
|
|
200
157
|
try {
|
|
201
158
|
const coll = this.db.collection(collection);
|
|
202
159
|
const result = await coll.deleteMany(where);
|
|
@@ -211,7 +168,6 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
211
168
|
}
|
|
212
169
|
|
|
213
170
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
214
|
-
await this.initPromise;
|
|
215
171
|
const session = this.client.startSession();
|
|
216
172
|
|
|
217
173
|
try {
|
|
@@ -226,26 +182,22 @@ export class MongoDBAdapter implements DatabaseAdapter {
|
|
|
226
182
|
|
|
227
183
|
// MongoDB-specific methods
|
|
228
184
|
async aggregate<T = any>(collection: string, pipeline: any[]): Promise<T[]> {
|
|
229
|
-
await this.initPromise;
|
|
230
185
|
const coll = this.db.collection(collection);
|
|
231
186
|
const cursor = coll.aggregate(pipeline);
|
|
232
187
|
return await cursor.toArray();
|
|
233
188
|
}
|
|
234
189
|
|
|
235
190
|
async createIndex(collection: string, index: any, options?: any): Promise<string> {
|
|
236
|
-
await this.initPromise;
|
|
237
191
|
const coll = this.db.collection(collection);
|
|
238
192
|
return await coll.createIndex(index, options);
|
|
239
193
|
}
|
|
240
194
|
|
|
241
195
|
async dropIndex(collection: string, indexName: string): Promise<any> {
|
|
242
|
-
await this.initPromise;
|
|
243
196
|
const coll = this.db.collection(collection);
|
|
244
197
|
return await coll.dropIndex(indexName);
|
|
245
198
|
}
|
|
246
199
|
|
|
247
200
|
async count(collection: string, query?: any): Promise<number> {
|
|
248
|
-
await this.initPromise;
|
|
249
201
|
const coll = this.db.collection(collection);
|
|
250
202
|
return await coll.countDocuments(query || {});
|
|
251
203
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Database MySQL Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
4
|
-
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
5
4
|
|
|
6
5
|
interface MySQLConfig {
|
|
7
6
|
host?: string;
|
|
@@ -10,35 +9,16 @@ interface MySQLConfig {
|
|
|
10
9
|
password?: string;
|
|
11
10
|
database?: string;
|
|
12
11
|
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;
|
|
26
12
|
}
|
|
27
13
|
|
|
28
14
|
export class MySQLAdapter implements DatabaseAdapter {
|
|
29
15
|
private pool: any;
|
|
30
16
|
private logger = createFrameworkLogger('MySQL');
|
|
31
|
-
private initPromise: Promise<void>;
|
|
32
17
|
|
|
33
18
|
constructor(config: MySQLConfig) {
|
|
34
|
-
this.initPromise = this.initialize(config);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private async initialize(config: MySQLConfig): Promise<void> {
|
|
38
19
|
try {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
this.pool = mysql.default.createPool({
|
|
20
|
+
const mysql = require('mysql2/promise');
|
|
21
|
+
this.pool = mysql.createPool({
|
|
42
22
|
host: config.host || 'localhost',
|
|
43
23
|
port: config.port || 3306,
|
|
44
24
|
user: config.user || 'root',
|
|
@@ -47,7 +27,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
47
27
|
waitForConnections: true,
|
|
48
28
|
connectionLimit: config.connectionLimit || 10,
|
|
49
29
|
queueLimit: 0,
|
|
50
|
-
ssl: typeof config.ssl === 'object' ? { ...config.ssl } : config.ssl || false,
|
|
51
30
|
});
|
|
52
31
|
} catch (error) {
|
|
53
32
|
throw new Error(
|
|
@@ -57,7 +36,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
57
36
|
}
|
|
58
37
|
|
|
59
38
|
async connect(): Promise<void> {
|
|
60
|
-
await this.initPromise;
|
|
61
39
|
try {
|
|
62
40
|
const connection = await this.pool.getConnection();
|
|
63
41
|
connection.release();
|
|
@@ -71,12 +49,10 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
71
49
|
}
|
|
72
50
|
|
|
73
51
|
async disconnect(): Promise<void> {
|
|
74
|
-
await this.initPromise;
|
|
75
52
|
await this.pool.end();
|
|
76
53
|
}
|
|
77
54
|
|
|
78
55
|
async query<T = any>(sql: string, params?: any[]): Promise<T[]> {
|
|
79
|
-
await this.initPromise;
|
|
80
56
|
const [rows] = await this.pool.execute(sql, params);
|
|
81
57
|
return rows as T[];
|
|
82
58
|
}
|
|
@@ -87,7 +63,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
87
63
|
}
|
|
88
64
|
|
|
89
65
|
async insert<T = any>(table: string, data: Record<string, any>): Promise<T> {
|
|
90
|
-
await this.initPromise;
|
|
91
66
|
const keys = Object.keys(data);
|
|
92
67
|
const values = Object.values(data);
|
|
93
68
|
const placeholders = keys.map(() => '?').join(', ');
|
|
@@ -108,7 +83,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
108
83
|
data: Record<string, any>,
|
|
109
84
|
where: Record<string, any>
|
|
110
85
|
): Promise<T> {
|
|
111
|
-
await this.initPromise;
|
|
112
86
|
const setClause = Object.keys(data)
|
|
113
87
|
.map(key => `${key} = ?`)
|
|
114
88
|
.join(', ');
|
|
@@ -131,7 +105,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
131
105
|
}
|
|
132
106
|
|
|
133
107
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
134
|
-
await this.initPromise;
|
|
135
108
|
const whereClause = Object.keys(where)
|
|
136
109
|
.map(key => `${key} = ?`)
|
|
137
110
|
.join(' AND ');
|
|
@@ -142,7 +115,6 @@ export class MySQLAdapter implements DatabaseAdapter {
|
|
|
142
115
|
}
|
|
143
116
|
|
|
144
117
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
145
|
-
await this.initPromise;
|
|
146
118
|
const connection = await this.pool.getConnection();
|
|
147
119
|
|
|
148
120
|
try {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Database PostgreSQL Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
4
|
-
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
5
4
|
|
|
6
5
|
interface PostgreSQLConfig {
|
|
7
6
|
host?: string;
|
|
@@ -10,33 +9,16 @@ interface PostgreSQLConfig {
|
|
|
10
9
|
password?: string;
|
|
11
10
|
database?: string;
|
|
12
11
|
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
|
-
}
|
|
23
|
-
| boolean;
|
|
12
|
+
ssl?: boolean;
|
|
24
13
|
}
|
|
25
14
|
|
|
26
15
|
export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
27
16
|
private pool: any;
|
|
28
17
|
private logger = createFrameworkLogger('PostgreSQL');
|
|
29
|
-
private initPromise: Promise<void>;
|
|
30
18
|
|
|
31
19
|
constructor(config: PostgreSQLConfig) {
|
|
32
|
-
this.initPromise = this.initialize(config);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private async initialize(config: PostgreSQLConfig): Promise<void> {
|
|
36
20
|
try {
|
|
37
|
-
const
|
|
38
|
-
const pg = await import(pgPath);
|
|
39
|
-
const { Pool } = pg.default;
|
|
21
|
+
const { Pool } = require('pg');
|
|
40
22
|
this.pool = new Pool({
|
|
41
23
|
host: config.host || 'localhost',
|
|
42
24
|
port: config.port || 5432,
|
|
@@ -44,7 +26,7 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
44
26
|
password: config.password || '',
|
|
45
27
|
database: config.database || 'moro_app',
|
|
46
28
|
max: config.connectionLimit || 10,
|
|
47
|
-
ssl:
|
|
29
|
+
ssl: config.ssl || false,
|
|
48
30
|
});
|
|
49
31
|
|
|
50
32
|
this.pool.on('error', (err: Error) => {
|
|
@@ -62,7 +44,6 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
62
44
|
}
|
|
63
45
|
|
|
64
46
|
async connect(): Promise<void> {
|
|
65
|
-
await this.initPromise;
|
|
66
47
|
try {
|
|
67
48
|
const client = await this.pool.connect();
|
|
68
49
|
client.release();
|
|
@@ -76,12 +57,10 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
76
57
|
}
|
|
77
58
|
|
|
78
59
|
async disconnect(): Promise<void> {
|
|
79
|
-
await this.initPromise;
|
|
80
60
|
await this.pool.end();
|
|
81
61
|
}
|
|
82
62
|
|
|
83
63
|
async query<T = any>(sql: string, params?: any[]): Promise<T[]> {
|
|
84
|
-
await this.initPromise;
|
|
85
64
|
const result = await this.pool.query(sql, params);
|
|
86
65
|
return result.rows as T[];
|
|
87
66
|
}
|
|
@@ -92,7 +71,6 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
92
71
|
}
|
|
93
72
|
|
|
94
73
|
async insert<T = any>(table: string, data: Record<string, any>): Promise<T> {
|
|
95
|
-
await this.initPromise;
|
|
96
74
|
const keys = Object.keys(data);
|
|
97
75
|
const values = Object.values(data);
|
|
98
76
|
const placeholders = keys.map((_, index) => `$${index + 1}`).join(', ');
|
|
@@ -108,7 +86,6 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
108
86
|
data: Record<string, any>,
|
|
109
87
|
where: Record<string, any>
|
|
110
88
|
): Promise<T> {
|
|
111
|
-
await this.initPromise;
|
|
112
89
|
const dataKeys = Object.keys(data);
|
|
113
90
|
const dataValues = Object.values(data);
|
|
114
91
|
const whereKeys = Object.keys(where);
|
|
@@ -127,7 +104,6 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
127
104
|
}
|
|
128
105
|
|
|
129
106
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
130
|
-
await this.initPromise;
|
|
131
107
|
const whereKeys = Object.keys(where);
|
|
132
108
|
const whereValues = Object.values(where);
|
|
133
109
|
const whereClause = whereKeys.map((key, index) => `${key} = $${index + 1}`).join(' AND ');
|
|
@@ -139,7 +115,6 @@ export class PostgreSQLAdapter implements DatabaseAdapter {
|
|
|
139
115
|
}
|
|
140
116
|
|
|
141
117
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
142
|
-
await this.initPromise;
|
|
143
118
|
const client = await this.pool.connect();
|
|
144
119
|
|
|
145
120
|
try {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Database Redis Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
4
|
-
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
5
4
|
|
|
6
5
|
interface RedisConfig {
|
|
7
6
|
host?: string;
|
|
@@ -12,15 +11,6 @@ interface RedisConfig {
|
|
|
12
11
|
maxRetriesPerRequest?: number;
|
|
13
12
|
retryDelayOnFailover?: number;
|
|
14
13
|
lazyConnect?: boolean;
|
|
15
|
-
tls?: {
|
|
16
|
-
rejectUnauthorized?: boolean;
|
|
17
|
-
ca?: string;
|
|
18
|
-
cert?: string;
|
|
19
|
-
key?: string;
|
|
20
|
-
passphrase?: string;
|
|
21
|
-
servername?: string;
|
|
22
|
-
checkServerIdentity?: boolean;
|
|
23
|
-
};
|
|
24
14
|
cluster?: {
|
|
25
15
|
enableReadyCheck?: boolean;
|
|
26
16
|
redisOptions?: any;
|
|
@@ -32,35 +22,21 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
32
22
|
private client: any;
|
|
33
23
|
private logger = createFrameworkLogger('Redis');
|
|
34
24
|
private keyPrefix: string;
|
|
35
|
-
private initPromise: Promise<void>;
|
|
36
25
|
|
|
37
26
|
constructor(config: RedisConfig = {}) {
|
|
38
|
-
this.keyPrefix = config.keyPrefix || 'moro:';
|
|
39
|
-
this.initPromise = this.initialize(config);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private async initialize(config: RedisConfig): Promise<void> {
|
|
43
27
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const Redis = ioredis.default;
|
|
28
|
+
const Redis = require('ioredis');
|
|
29
|
+
this.keyPrefix = config.keyPrefix || 'moro:';
|
|
47
30
|
|
|
48
31
|
if (config.cluster) {
|
|
49
32
|
// Redis Cluster
|
|
50
|
-
|
|
33
|
+
this.client = new Redis.Cluster(config.cluster.nodes, {
|
|
51
34
|
enableReadyCheck: config.cluster.enableReadyCheck || false,
|
|
52
35
|
redisOptions: config.cluster.redisOptions || {},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Add TLS options to cluster configuration
|
|
56
|
-
if (config.tls) {
|
|
57
|
-
clusterOptions.redisOptions.tls = { ...config.tls };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.client = new Redis.Cluster(config.cluster.nodes, clusterOptions);
|
|
36
|
+
});
|
|
61
37
|
} else {
|
|
62
38
|
// Single Redis instance
|
|
63
|
-
|
|
39
|
+
this.client = new Redis({
|
|
64
40
|
host: config.host || 'localhost',
|
|
65
41
|
port: config.port || 6379,
|
|
66
42
|
password: config.password,
|
|
@@ -68,14 +44,7 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
68
44
|
maxRetriesPerRequest: config.maxRetriesPerRequest || 3,
|
|
69
45
|
retryDelayOnFailover: config.retryDelayOnFailover || 100,
|
|
70
46
|
lazyConnect: config.lazyConnect || true,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Add TLS options if provided
|
|
74
|
-
if (config.tls) {
|
|
75
|
-
redisOptions.tls = { ...config.tls };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.client = new Redis(redisOptions);
|
|
47
|
+
});
|
|
79
48
|
}
|
|
80
49
|
|
|
81
50
|
this.client.on('error', (err: Error) => {
|
|
@@ -105,7 +74,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
105
74
|
}
|
|
106
75
|
|
|
107
76
|
async connect(): Promise<void> {
|
|
108
|
-
await this.initPromise;
|
|
109
77
|
try {
|
|
110
78
|
await this.client.ping();
|
|
111
79
|
this.logger.info('Redis connection established', 'Connection');
|
|
@@ -118,13 +86,11 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
118
86
|
}
|
|
119
87
|
|
|
120
88
|
async disconnect(): Promise<void> {
|
|
121
|
-
await this.initPromise;
|
|
122
89
|
await this.client.quit();
|
|
123
90
|
}
|
|
124
91
|
|
|
125
92
|
// For Redis, we adapt the SQL-like interface to key-value operations
|
|
126
93
|
async query<T = any>(pattern: string, _params?: any[]): Promise<T[]> {
|
|
127
|
-
await this.initPromise;
|
|
128
94
|
try {
|
|
129
95
|
const keys = await this.client.keys(this.prefixKey(pattern));
|
|
130
96
|
if (keys.length === 0) return [];
|
|
@@ -144,7 +110,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
144
110
|
}
|
|
145
111
|
|
|
146
112
|
async queryOne<T = any>(key: string, _params?: any[]): Promise<T | null> {
|
|
147
|
-
await this.initPromise;
|
|
148
113
|
try {
|
|
149
114
|
const value = await this.client.get(this.prefixKey(key));
|
|
150
115
|
return value ? JSON.parse(value) : null;
|
|
@@ -158,7 +123,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
158
123
|
}
|
|
159
124
|
|
|
160
125
|
async insert<T = any>(key: string, data: Record<string, any>): Promise<T> {
|
|
161
|
-
await this.initPromise;
|
|
162
126
|
try {
|
|
163
127
|
const value = JSON.stringify(data);
|
|
164
128
|
await this.client.set(this.prefixKey(key), value);
|
|
@@ -177,7 +141,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
177
141
|
data: Record<string, any>,
|
|
178
142
|
_where?: Record<string, any>
|
|
179
143
|
): Promise<T> {
|
|
180
|
-
await this.initPromise;
|
|
181
144
|
try {
|
|
182
145
|
// For Redis, we'll merge with existing data if it exists
|
|
183
146
|
const existing = await this.queryOne(key);
|
|
@@ -195,7 +158,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
195
158
|
}
|
|
196
159
|
|
|
197
160
|
async delete(pattern: string, _where?: Record<string, any>): Promise<number> {
|
|
198
|
-
await this.initPromise;
|
|
199
161
|
try {
|
|
200
162
|
const keys = await this.client.keys(this.prefixKey(pattern));
|
|
201
163
|
if (keys.length === 0) return 0;
|
|
@@ -212,7 +174,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
212
174
|
}
|
|
213
175
|
|
|
214
176
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
215
|
-
await this.initPromise;
|
|
216
177
|
const multi = this.client.multi();
|
|
217
178
|
const transaction = new RedisTransaction(multi, this.keyPrefix);
|
|
218
179
|
|
|
@@ -229,7 +190,6 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
229
190
|
|
|
230
191
|
// Redis-specific methods
|
|
231
192
|
async set(key: string, value: any, ttl?: number): Promise<void> {
|
|
232
|
-
await this.initPromise;
|
|
233
193
|
const prefixedKey = this.prefixKey(key);
|
|
234
194
|
if (ttl) {
|
|
235
195
|
await this.client.setex(prefixedKey, ttl, JSON.stringify(value));
|
|
@@ -239,46 +199,38 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
239
199
|
}
|
|
240
200
|
|
|
241
201
|
async get(key: string): Promise<any> {
|
|
242
|
-
await this.initPromise;
|
|
243
202
|
const value = await this.client.get(this.prefixKey(key));
|
|
244
203
|
return value ? JSON.parse(value) : null;
|
|
245
204
|
}
|
|
246
205
|
|
|
247
206
|
async exists(key: string): Promise<boolean> {
|
|
248
|
-
await this.initPromise;
|
|
249
207
|
const result = await this.client.exists(this.prefixKey(key));
|
|
250
208
|
return result === 1;
|
|
251
209
|
}
|
|
252
210
|
|
|
253
211
|
async expire(key: string, ttl: number): Promise<boolean> {
|
|
254
|
-
await this.initPromise;
|
|
255
212
|
const result = await this.client.expire(this.prefixKey(key), ttl);
|
|
256
213
|
return result === 1;
|
|
257
214
|
}
|
|
258
215
|
|
|
259
216
|
async incr(key: string): Promise<number> {
|
|
260
|
-
await this.initPromise;
|
|
261
217
|
return await this.client.incr(this.prefixKey(key));
|
|
262
218
|
}
|
|
263
219
|
|
|
264
220
|
async decr(key: string): Promise<number> {
|
|
265
|
-
await this.initPromise;
|
|
266
221
|
return await this.client.decr(this.prefixKey(key));
|
|
267
222
|
}
|
|
268
223
|
|
|
269
224
|
async hset(hash: string, field: string, value: any): Promise<void> {
|
|
270
|
-
await this.initPromise;
|
|
271
225
|
await this.client.hset(this.prefixKey(hash), field, JSON.stringify(value));
|
|
272
226
|
}
|
|
273
227
|
|
|
274
228
|
async hget(hash: string, field: string): Promise<any> {
|
|
275
|
-
await this.initPromise;
|
|
276
229
|
const value = await this.client.hget(this.prefixKey(hash), field);
|
|
277
230
|
return value ? JSON.parse(value) : null;
|
|
278
231
|
}
|
|
279
232
|
|
|
280
233
|
async hgetall(hash: string): Promise<Record<string, any>> {
|
|
281
|
-
await this.initPromise;
|
|
282
234
|
const result = await this.client.hgetall(this.prefixKey(hash));
|
|
283
235
|
const parsed: Record<string, any> = {};
|
|
284
236
|
for (const [key, value] of Object.entries(result)) {
|
|
@@ -288,30 +240,25 @@ export class RedisAdapter implements DatabaseAdapter {
|
|
|
288
240
|
}
|
|
289
241
|
|
|
290
242
|
async lpush(list: string, ...values: any[]): Promise<number> {
|
|
291
|
-
await this.initPromise;
|
|
292
243
|
const serialized = values.map(v => JSON.stringify(v));
|
|
293
244
|
return await this.client.lpush(this.prefixKey(list), ...serialized);
|
|
294
245
|
}
|
|
295
246
|
|
|
296
247
|
async rpop(list: string): Promise<any> {
|
|
297
|
-
await this.initPromise;
|
|
298
248
|
const value = await this.client.rpop(this.prefixKey(list));
|
|
299
249
|
return value ? JSON.parse(value) : null;
|
|
300
250
|
}
|
|
301
251
|
|
|
302
252
|
async lrange(list: string, start: number, stop: number): Promise<any[]> {
|
|
303
|
-
await this.initPromise;
|
|
304
253
|
const values = await this.client.lrange(this.prefixKey(list), start, stop);
|
|
305
254
|
return values.map((v: string) => JSON.parse(v));
|
|
306
255
|
}
|
|
307
256
|
|
|
308
257
|
async publish(channel: string, message: any): Promise<number> {
|
|
309
|
-
await this.initPromise;
|
|
310
258
|
return await this.client.publish(channel, JSON.stringify(message));
|
|
311
259
|
}
|
|
312
260
|
|
|
313
261
|
async subscribe(channel: string, callback: (message: any) => void): Promise<void> {
|
|
314
|
-
await this.initPromise;
|
|
315
262
|
const subscriber = this.client.duplicate();
|
|
316
263
|
subscriber.subscribe(channel);
|
|
317
264
|
subscriber.on('message', (_channel: string, message: string) => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Database SQLite Adapter
|
|
2
|
-
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database
|
|
3
|
-
import { createFrameworkLogger } from '../../logger
|
|
4
|
-
import { resolveUserPackage } from '../../utilities/package-utils.js';
|
|
2
|
+
import { DatabaseAdapter, DatabaseTransaction } from '../../../types/database';
|
|
3
|
+
import { createFrameworkLogger } from '../../logger';
|
|
5
4
|
|
|
6
5
|
interface SQLiteConfig {
|
|
7
6
|
filename?: string;
|
|
@@ -15,17 +14,10 @@ interface SQLiteConfig {
|
|
|
15
14
|
export class SQLiteAdapter implements DatabaseAdapter {
|
|
16
15
|
private db: any;
|
|
17
16
|
private logger = createFrameworkLogger('SQLite');
|
|
18
|
-
private initPromise: Promise<void>;
|
|
19
17
|
|
|
20
18
|
constructor(config: SQLiteConfig = {}) {
|
|
21
|
-
this.initPromise = this.initialize(config);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private async initialize(config: SQLiteConfig): Promise<void> {
|
|
25
19
|
try {
|
|
26
|
-
const
|
|
27
|
-
const betterSqlite3 = await import(sqlite3Path);
|
|
28
|
-
const Database = betterSqlite3.default;
|
|
20
|
+
const Database = require('better-sqlite3');
|
|
29
21
|
const filename = config.memory ? ':memory:' : config.filename || 'moro_app.db';
|
|
30
22
|
this.db = new Database(filename, {
|
|
31
23
|
readonly: config.readonly || false,
|
|
@@ -48,18 +40,15 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
async connect(): Promise<void> {
|
|
51
|
-
await this.initPromise;
|
|
52
43
|
// SQLite doesn't require explicit connection - it's handled in constructor
|
|
53
44
|
this.logger.info('SQLite adapter ready', 'Connection');
|
|
54
45
|
}
|
|
55
46
|
|
|
56
47
|
async disconnect(): Promise<void> {
|
|
57
|
-
await this.initPromise;
|
|
58
48
|
this.db.close();
|
|
59
49
|
}
|
|
60
50
|
|
|
61
51
|
async query<T = any>(sql: string, params?: any[]): Promise<T[]> {
|
|
62
|
-
await this.initPromise;
|
|
63
52
|
try {
|
|
64
53
|
const stmt = this.db.prepare(sql);
|
|
65
54
|
const results = stmt.all(params || []);
|
|
@@ -74,7 +63,6 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
74
63
|
}
|
|
75
64
|
|
|
76
65
|
async queryOne<T = any>(sql: string, params?: any[]): Promise<T | null> {
|
|
77
|
-
await this.initPromise;
|
|
78
66
|
try {
|
|
79
67
|
const stmt = this.db.prepare(sql);
|
|
80
68
|
const result = stmt.get(params || []);
|
|
@@ -89,7 +77,6 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
89
77
|
}
|
|
90
78
|
|
|
91
79
|
async insert<T = any>(table: string, data: Record<string, any>): Promise<T> {
|
|
92
|
-
await this.initPromise;
|
|
93
80
|
const keys = Object.keys(data);
|
|
94
81
|
const values = Object.values(data);
|
|
95
82
|
const placeholders = keys.map(() => '?').join(', ');
|
|
@@ -120,7 +107,6 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
120
107
|
data: Record<string, any>,
|
|
121
108
|
where: Record<string, any>
|
|
122
109
|
): Promise<T> {
|
|
123
|
-
await this.initPromise;
|
|
124
110
|
const setClause = Object.keys(data)
|
|
125
111
|
.map(key => `${key} = ?`)
|
|
126
112
|
.join(', ');
|
|
@@ -152,7 +138,6 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
152
138
|
}
|
|
153
139
|
|
|
154
140
|
async delete(table: string, where: Record<string, any>): Promise<number> {
|
|
155
|
-
await this.initPromise;
|
|
156
141
|
const whereClause = Object.keys(where)
|
|
157
142
|
.map(key => `${key} = ?`)
|
|
158
143
|
.join(' AND ');
|
|
@@ -172,7 +157,6 @@ export class SQLiteAdapter implements DatabaseAdapter {
|
|
|
172
157
|
}
|
|
173
158
|
|
|
174
159
|
async transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T> {
|
|
175
|
-
await this.initPromise;
|
|
176
160
|
const transaction = this.db.transaction(async () => {
|
|
177
161
|
const tx = new SQLiteTransaction(this.db);
|
|
178
162
|
return await callback(tx);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Database Module
|
|
2
|
-
export * from './adapters
|
|
3
|
-
export * from '../../types/database
|
|
2
|
+
export * from './adapters';
|
|
3
|
+
export * from '../../types/database';
|