@zintrust/core 0.1.0
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/bin/z.d.ts +7 -0
- package/bin/z.d.ts.map +1 -0
- package/bin/z.js +6 -0
- package/bin/zin.d.ts +7 -0
- package/bin/zin.d.ts.map +1 -0
- package/bin/zin.js +6 -0
- package/bin/zintrust-microservices.d.ts +7 -0
- package/bin/zintrust-microservices.d.ts.map +1 -0
- package/bin/zintrust-microservices.js +165 -0
- package/bin/zintrust.d.ts +9 -0
- package/bin/zintrust.d.ts.map +1 -0
- package/bin/zintrust.js +51 -0
- package/bin/zt.d.ts +7 -0
- package/bin/zt.d.ts.map +1 -0
- package/bin/zt.js +6 -0
- package/package.json +80 -0
- package/src/boot/Application.d.ts +31 -0
- package/src/boot/Application.d.ts.map +1 -0
- package/src/boot/Application.js +159 -0
- package/src/boot/Server.d.ts +23 -0
- package/src/boot/Server.d.ts.map +1 -0
- package/src/boot/Server.js +236 -0
- package/src/boot/bootstrap.d.ts +7 -0
- package/src/boot/bootstrap.d.ts.map +1 -0
- package/src/boot/bootstrap.js +64 -0
- package/src/builder/BundleOptimizer.d.ts +42 -0
- package/src/builder/BundleOptimizer.d.ts.map +1 -0
- package/src/builder/BundleOptimizer.js +356 -0
- package/src/cache/Cache.d.ts +26 -0
- package/src/cache/Cache.d.ts.map +1 -0
- package/src/cache/Cache.js +89 -0
- package/src/cache/CacheDriver.d.ts +28 -0
- package/src/cache/CacheDriver.d.ts.map +1 -0
- package/src/cache/CacheDriver.js +6 -0
- package/src/cache/drivers/KVDriver.d.ts +12 -0
- package/src/cache/drivers/KVDriver.d.ts.map +1 -0
- package/src/cache/drivers/KVDriver.js +54 -0
- package/src/cache/drivers/MemoryDriver.d.ts +12 -0
- package/src/cache/drivers/MemoryDriver.d.ts.map +1 -0
- package/src/cache/drivers/MemoryDriver.js +50 -0
- package/src/cache/drivers/MongoDriver.d.ts +17 -0
- package/src/cache/drivers/MongoDriver.d.ts.map +1 -0
- package/src/cache/drivers/MongoDriver.js +80 -0
- package/src/cache/drivers/RedisDriver.d.ts +12 -0
- package/src/cache/drivers/RedisDriver.d.ts.map +1 -0
- package/src/cache/drivers/RedisDriver.js +79 -0
- package/src/cli/BaseCommand.d.ts +39 -0
- package/src/cli/BaseCommand.d.ts.map +1 -0
- package/src/cli/BaseCommand.js +58 -0
- package/src/cli/CLI.d.ts +21 -0
- package/src/cli/CLI.d.ts.map +1 -0
- package/src/cli/CLI.js +203 -0
- package/src/cli/ErrorHandler.d.ts +23 -0
- package/src/cli/ErrorHandler.d.ts.map +1 -0
- package/src/cli/ErrorHandler.js +95 -0
- package/src/cli/PromptHelper.d.ts +47 -0
- package/src/cli/PromptHelper.d.ts.map +1 -0
- package/src/cli/PromptHelper.js +155 -0
- package/src/cli/commands/AddCommand.d.ts +15 -0
- package/src/cli/commands/AddCommand.d.ts.map +1 -0
- package/src/cli/commands/AddCommand.js +817 -0
- package/src/cli/commands/ConfigCommand.d.ts +15 -0
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/src/cli/commands/ConfigCommand.js +273 -0
- package/src/cli/commands/D1MigrateCommand.d.ts +15 -0
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -0
- package/src/cli/commands/D1MigrateCommand.js +73 -0
- package/src/cli/commands/DebugCommand.d.ts +15 -0
- package/src/cli/commands/DebugCommand.d.ts.map +1 -0
- package/src/cli/commands/DebugCommand.js +52 -0
- package/src/cli/commands/FixCommand.d.ts +15 -0
- package/src/cli/commands/FixCommand.d.ts.map +1 -0
- package/src/cli/commands/FixCommand.js +80 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts +9 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts.map +1 -0
- package/src/cli/commands/KeyGenerateCommand.js +76 -0
- package/src/cli/commands/LogsCommand.d.ts +19 -0
- package/src/cli/commands/LogsCommand.d.ts.map +1 -0
- package/src/cli/commands/LogsCommand.js +185 -0
- package/src/cli/commands/MigrateCommand.d.ts +15 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -0
- package/src/cli/commands/MigrateCommand.js +56 -0
- package/src/cli/commands/NewCommand.d.ts +32 -0
- package/src/cli/commands/NewCommand.d.ts.map +1 -0
- package/src/cli/commands/NewCommand.js +280 -0
- package/src/cli/commands/PluginCommand.d.ts +9 -0
- package/src/cli/commands/PluginCommand.d.ts.map +1 -0
- package/src/cli/commands/PluginCommand.js +94 -0
- package/src/cli/commands/PrepareCommand.d.ts +8 -0
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -0
- package/src/cli/commands/PrepareCommand.js +51 -0
- package/src/cli/commands/QACommand.d.ts +33 -0
- package/src/cli/commands/QACommand.d.ts.map +1 -0
- package/src/cli/commands/QACommand.js +490 -0
- package/src/cli/commands/SimulateCommand.d.ts +12 -0
- package/src/cli/commands/SimulateCommand.d.ts.map +1 -0
- package/src/cli/commands/SimulateCommand.js +79 -0
- package/src/cli/commands/StartCommand.d.ts +5 -0
- package/src/cli/commands/StartCommand.d.ts.map +1 -0
- package/src/cli/commands/StartCommand.js +227 -0
- package/src/cli/commands/index.d.ts +11 -0
- package/src/cli/commands/index.d.ts.map +1 -0
- package/src/cli/commands/index.js +10 -0
- package/src/cli/config/ConfigManager.d.ts +42 -0
- package/src/cli/config/ConfigManager.d.ts.map +1 -0
- package/src/cli/config/ConfigManager.js +175 -0
- package/src/cli/config/ConfigSchema.d.ts +195 -0
- package/src/cli/config/ConfigSchema.d.ts.map +1 -0
- package/src/cli/config/ConfigSchema.js +171 -0
- package/src/cli/config/ConfigValidator.d.ts +41 -0
- package/src/cli/config/ConfigValidator.d.ts.map +1 -0
- package/src/cli/config/ConfigValidator.js +200 -0
- package/src/cli/config/index.d.ts +8 -0
- package/src/cli/config/index.d.ts.map +1 -0
- package/src/cli/config/index.js +7 -0
- package/src/cli/debug/Dashboard.d.ts +34 -0
- package/src/cli/debug/Dashboard.d.ts.map +1 -0
- package/src/cli/debug/Dashboard.js +152 -0
- package/src/cli/index.d.ts +14 -0
- package/src/cli/index.d.ts.map +1 -0
- package/src/cli/index.js +14 -0
- package/src/cli/logger/Logger.d.ts +43 -0
- package/src/cli/logger/Logger.d.ts.map +1 -0
- package/src/cli/logger/Logger.js +137 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts +44 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ControllerGenerator.js +540 -0
- package/src/cli/scaffolding/FactoryGenerator.d.ts +47 -0
- package/src/cli/scaffolding/FactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/FactoryGenerator.js +356 -0
- package/src/cli/scaffolding/FeatureScaffolder.d.ts +40 -0
- package/src/cli/scaffolding/FeatureScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/FeatureScaffolder.js +747 -0
- package/src/cli/scaffolding/FileGenerator.d.ts +31 -0
- package/src/cli/scaffolding/FileGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/FileGenerator.js +222 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts +35 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/MigrationGenerator.js +257 -0
- package/src/cli/scaffolding/ModelGenerator.d.ts +81 -0
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ModelGenerator.js +249 -0
- package/src/cli/scaffolding/ProjectScaffolder.d.ts +66 -0
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/ProjectScaffolder.js +439 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.d.ts +50 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/RequestFactoryGenerator.js +465 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts +43 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ResponseFactoryGenerator.js +321 -0
- package/src/cli/scaffolding/RouteGenerator.d.ts +66 -0
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/RouteGenerator.js +306 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts +47 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/SeederGenerator.js +286 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.d.ts +40 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceIntegrationTestGenerator.js +267 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts +45 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceRequestFactoryGenerator.js +397 -0
- package/src/cli/scaffolding/ServiceScaffolder.d.ts +45 -0
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/ServiceScaffolder.js +367 -0
- package/src/cli/scaffolding/TemplateEngine.d.ts +35 -0
- package/src/cli/scaffolding/TemplateEngine.d.ts.map +1 -0
- package/src/cli/scaffolding/TemplateEngine.js +379 -0
- package/src/cli/scaffolding/WorkflowGenerator.d.ts +31 -0
- package/src/cli/scaffolding/WorkflowGenerator.d.ts.map +1 -0
- package/src/cli/scaffolding/WorkflowGenerator.js +193 -0
- package/src/cli/scaffolding/index.d.ts +34 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -0
- package/src/cli/scaffolding/index.js +18 -0
- package/src/cli/utils/DistPackager.d.ts +8 -0
- package/src/cli/utils/DistPackager.d.ts.map +1 -0
- package/src/cli/utils/DistPackager.js +94 -0
- package/src/cli/utils/EnvFileLoader.d.ts +21 -0
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -0
- package/src/cli/utils/EnvFileLoader.js +166 -0
- package/src/cli/utils/spawn.d.ts +11 -0
- package/src/cli/utils/spawn.d.ts.map +1 -0
- package/src/cli/utils/spawn.js +81 -0
- package/src/common/index.d.ts +87 -0
- package/src/common/index.d.ts.map +1 -0
- package/src/common/index.js +207 -0
- package/src/config/SecretsManager.d.ts +122 -0
- package/src/config/SecretsManager.d.ts.map +1 -0
- package/src/config/SecretsManager.js +328 -0
- package/src/config/app.d.ts +56 -0
- package/src/config/app.d.ts.map +1 -0
- package/src/config/app.js +77 -0
- package/src/config/cache.d.ts +76 -0
- package/src/config/cache.d.ts.map +1 -0
- package/src/config/cache.js +62 -0
- package/src/config/constants.d.ts +108 -0
- package/src/config/constants.d.ts.map +1 -0
- package/src/config/constants.js +64 -0
- package/src/config/database.d.ts +122 -0
- package/src/config/database.d.ts.map +1 -0
- package/src/config/database.js +89 -0
- package/src/config/env.d.ts +56 -0
- package/src/config/env.d.ts.map +1 -0
- package/src/config/env.js +133 -0
- package/src/config/features.d.ts +27 -0
- package/src/config/features.d.ts.map +1 -0
- package/src/config/features.js +49 -0
- package/src/config/index.d.ts +554 -0
- package/src/config/index.d.ts.map +1 -0
- package/src/config/index.js +31 -0
- package/src/config/logger.d.ts +17 -0
- package/src/config/logger.d.ts.map +1 -0
- package/src/config/logger.js +77 -0
- package/src/config/microservices.d.ts +88 -0
- package/src/config/microservices.d.ts.map +1 -0
- package/src/config/microservices.js +90 -0
- package/src/config/queue.d.ts +107 -0
- package/src/config/queue.d.ts.map +1 -0
- package/src/config/queue.js +74 -0
- package/src/config/security.d.ts +108 -0
- package/src/config/security.d.ts.map +1 -0
- package/src/config/security.js +134 -0
- package/src/config/storage.d.ts +105 -0
- package/src/config/storage.d.ts.map +1 -0
- package/src/config/storage.js +79 -0
- package/src/container/ServiceContainer.d.ts +25 -0
- package/src/container/ServiceContainer.d.ts.map +1 -0
- package/src/container/ServiceContainer.js +75 -0
- package/src/database/migrations/index.d.ts +2 -0
- package/src/database/migrations/index.d.ts.map +1 -0
- package/src/database/migrations/index.js +1 -0
- package/src/exceptions/ZintrustError.d.ts +88 -0
- package/src/exceptions/ZintrustError.d.ts.map +1 -0
- package/src/exceptions/ZintrustError.js +110 -0
- package/src/features/Auth.d.ts +20 -0
- package/src/features/Auth.d.ts.map +1 -0
- package/src/features/Auth.js +32 -0
- package/src/features/Queue.d.ts +21 -0
- package/src/features/Queue.d.ts.map +1 -0
- package/src/features/Queue.js +59 -0
- package/src/functions/cloudflare.d.ts +5 -0
- package/src/functions/cloudflare.d.ts.map +1 -0
- package/src/functions/cloudflare.js +34 -0
- package/src/functions/deno.d.ts +3 -0
- package/src/functions/deno.d.ts.map +1 -0
- package/src/functions/deno.js +31 -0
- package/src/functions/lambda.d.ts +2 -0
- package/src/functions/lambda.d.ts.map +1 -0
- package/src/functions/lambda.js +32 -0
- package/src/http/Controller.d.ts +20 -0
- package/src/http/Controller.d.ts.map +1 -0
- package/src/http/Controller.js +46 -0
- package/src/http/Kernel.d.ts +24 -0
- package/src/http/Kernel.d.ts.map +1 -0
- package/src/http/Kernel.js +72 -0
- package/src/http/Request.d.ts +36 -0
- package/src/http/Request.d.ts.map +1 -0
- package/src/http/Request.js +142 -0
- package/src/http/Response.d.ts +32 -0
- package/src/http/Response.d.ts.map +1 -0
- package/src/http/Response.js +70 -0
- package/src/index.d.ts +43 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +37 -0
- package/src/microservices/MicroserviceBootstrap.d.ts +75 -0
- package/src/microservices/MicroserviceBootstrap.d.ts.map +1 -0
- package/src/microservices/MicroserviceBootstrap.js +285 -0
- package/src/microservices/MicroserviceGenerator.d.ts +27 -0
- package/src/microservices/MicroserviceGenerator.d.ts.map +1 -0
- package/src/microservices/MicroserviceGenerator.js +436 -0
- package/src/microservices/MicroserviceManager.d.ts +68 -0
- package/src/microservices/MicroserviceManager.d.ts.map +1 -0
- package/src/microservices/MicroserviceManager.js +266 -0
- package/src/microservices/PostgresAdapter.d.ts +90 -0
- package/src/microservices/PostgresAdapter.d.ts.map +1 -0
- package/src/microservices/PostgresAdapter.js +286 -0
- package/src/microservices/RequestTracingMiddleware.d.ts +41 -0
- package/src/microservices/RequestTracingMiddleware.d.ts.map +1 -0
- package/src/microservices/RequestTracingMiddleware.js +122 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts +58 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -0
- package/src/microservices/ServiceAuthMiddleware.js +240 -0
- package/src/microservices/ServiceBundler.d.ts +45 -0
- package/src/microservices/ServiceBundler.d.ts.map +1 -0
- package/src/microservices/ServiceBundler.js +297 -0
- package/src/microservices/ServiceHealthMonitor.d.ts +96 -0
- package/src/microservices/ServiceHealthMonitor.d.ts.map +1 -0
- package/src/microservices/ServiceHealthMonitor.js +379 -0
- package/src/middleware/CsrfMiddleware.d.ts +19 -0
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -0
- package/src/middleware/CsrfMiddleware.js +121 -0
- package/src/middleware/MiddlewareStack.d.ts +27 -0
- package/src/middleware/MiddlewareStack.d.ts.map +1 -0
- package/src/middleware/MiddlewareStack.js +43 -0
- package/src/middleware/RateLimiter.d.ts +22 -0
- package/src/middleware/RateLimiter.d.ts.map +1 -0
- package/src/middleware/RateLimiter.js +72 -0
- package/src/middleware/SecurityMiddleware.d.ts +33 -0
- package/src/middleware/SecurityMiddleware.d.ts.map +1 -0
- package/src/middleware/SecurityMiddleware.js +106 -0
- package/src/middleware/index.d.ts +9 -0
- package/src/middleware/index.d.ts.map +1 -0
- package/src/middleware/index.js +8 -0
- package/src/node-singletons/child-process.d.ts +7 -0
- package/src/node-singletons/child-process.d.ts.map +1 -0
- package/src/node-singletons/child-process.js +6 -0
- package/src/node-singletons/crypto.d.ts +7 -0
- package/src/node-singletons/crypto.d.ts.map +1 -0
- package/src/node-singletons/crypto.js +6 -0
- package/src/node-singletons/events.d.ts +7 -0
- package/src/node-singletons/events.d.ts.map +1 -0
- package/src/node-singletons/events.js +6 -0
- package/src/node-singletons/fs.d.ts +12 -0
- package/src/node-singletons/fs.d.ts.map +1 -0
- package/src/node-singletons/fs.js +14 -0
- package/src/node-singletons/http.d.ts +8 -0
- package/src/node-singletons/http.d.ts.map +1 -0
- package/src/node-singletons/http.js +6 -0
- package/src/node-singletons/index.d.ts +30 -0
- package/src/node-singletons/index.d.ts.map +1 -0
- package/src/node-singletons/index.js +31 -0
- package/src/node-singletons/os.d.ts +9 -0
- package/src/node-singletons/os.d.ts.map +1 -0
- package/src/node-singletons/os.js +9 -0
- package/src/node-singletons/path.d.ts +7 -0
- package/src/node-singletons/path.d.ts.map +1 -0
- package/src/node-singletons/path.js +6 -0
- package/src/node-singletons/perf-hooks.d.ts +7 -0
- package/src/node-singletons/perf-hooks.d.ts.map +1 -0
- package/src/node-singletons/perf-hooks.js +6 -0
- package/src/node-singletons/readline.d.ts +10 -0
- package/src/node-singletons/readline.d.ts.map +1 -0
- package/src/node-singletons/readline.js +9 -0
- package/src/node-singletons/url.d.ts +7 -0
- package/src/node-singletons/url.d.ts.map +1 -0
- package/src/node-singletons/url.js +6 -0
- package/src/orm/ConnectionManager.d.ts +118 -0
- package/src/orm/ConnectionManager.d.ts.map +1 -0
- package/src/orm/ConnectionManager.js +401 -0
- package/src/orm/Database.d.ts +31 -0
- package/src/orm/Database.d.ts.map +1 -0
- package/src/orm/Database.js +163 -0
- package/src/orm/DatabaseAdapter.d.ts +96 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -0
- package/src/orm/DatabaseAdapter.js +40 -0
- package/src/orm/Model.d.ts +91 -0
- package/src/orm/Model.d.ts.map +1 -0
- package/src/orm/Model.js +206 -0
- package/src/orm/QueryBuilder.d.ts +52 -0
- package/src/orm/QueryBuilder.d.ts.map +1 -0
- package/src/orm/QueryBuilder.js +134 -0
- package/src/orm/Relationships.d.ts +53 -0
- package/src/orm/Relationships.d.ts.map +1 -0
- package/src/orm/Relationships.js +98 -0
- package/src/orm/Schema.d.ts +123 -0
- package/src/orm/Schema.d.ts.map +1 -0
- package/src/orm/Schema.js +169 -0
- package/src/orm/adapters/D1Adapter.d.ts +15 -0
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -0
- package/src/orm/adapters/D1Adapter.js +125 -0
- package/src/orm/adapters/MySQLAdapter.d.ts +16 -0
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -0
- package/src/orm/adapters/MySQLAdapter.js +87 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts +16 -0
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -0
- package/src/orm/adapters/PostgreSQLAdapter.js +87 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts +16 -0
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SQLServerAdapter.js +81 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts +11 -0
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -0
- package/src/orm/adapters/SQLiteAdapter.js +131 -0
- package/src/performance/Benchmark.d.ts +87 -0
- package/src/performance/Benchmark.d.ts.map +1 -0
- package/src/performance/Benchmark.js +304 -0
- package/src/performance/CodeGenerationBenchmark.d.ts +23 -0
- package/src/performance/CodeGenerationBenchmark.d.ts.map +1 -0
- package/src/performance/CodeGenerationBenchmark.js +249 -0
- package/src/performance/Optimizer.d.ts +99 -0
- package/src/performance/Optimizer.d.ts.map +1 -0
- package/src/performance/Optimizer.js +396 -0
- package/src/performance/establish-baseline.d.ts +9 -0
- package/src/performance/establish-baseline.d.ts.map +1 -0
- package/src/performance/establish-baseline.js +55 -0
- package/src/profiling/MemoryProfiler.d.ts +32 -0
- package/src/profiling/MemoryProfiler.d.ts.map +1 -0
- package/src/profiling/MemoryProfiler.js +84 -0
- package/src/profiling/N1Detector.d.ts +16 -0
- package/src/profiling/N1Detector.d.ts.map +1 -0
- package/src/profiling/N1Detector.js +120 -0
- package/src/profiling/QueryLogger.d.ts +107 -0
- package/src/profiling/QueryLogger.d.ts.map +1 -0
- package/src/profiling/QueryLogger.js +148 -0
- package/src/profiling/RequestProfiler.d.ts +30 -0
- package/src/profiling/RequestProfiler.d.ts.map +1 -0
- package/src/profiling/RequestProfiler.js +94 -0
- package/src/profiling/types.d.ts +77 -0
- package/src/profiling/types.d.ts.map +1 -0
- package/src/profiling/types.js +5 -0
- package/src/routing/Router.d.ts +52 -0
- package/src/routing/Router.d.ts.map +1 -0
- package/src/routing/Router.js +191 -0
- package/src/runtime/PluginManager.d.ts +30 -0
- package/src/runtime/PluginManager.d.ts.map +1 -0
- package/src/runtime/PluginManager.js +197 -0
- package/src/runtime/PluginRegistry.d.ts +22 -0
- package/src/runtime/PluginRegistry.d.ts.map +1 -0
- package/src/runtime/PluginRegistry.js +93 -0
- package/src/runtime/RuntimeAdapter.d.ts +126 -0
- package/src/runtime/RuntimeAdapter.d.ts.map +1 -0
- package/src/runtime/RuntimeAdapter.js +127 -0
- package/src/runtime/RuntimeDetector.d.ts +15 -0
- package/src/runtime/RuntimeDetector.d.ts.map +1 -0
- package/src/runtime/RuntimeDetector.js +219 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts +43 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/CloudflareAdapter.js +175 -0
- package/src/runtime/adapters/DenoAdapter.d.ts +30 -0
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/DenoAdapter.js +191 -0
- package/src/runtime/adapters/FargateAdapter.d.ts +40 -0
- package/src/runtime/adapters/FargateAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/FargateAdapter.js +156 -0
- package/src/runtime/adapters/LambdaAdapter.d.ts +13 -0
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/LambdaAdapter.js +302 -0
- package/src/runtime/adapters/NodeServerAdapter.d.ts +16 -0
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -0
- package/src/runtime/adapters/NodeServerAdapter.js +199 -0
- package/src/scripts/TemplateSync.d.ts +7 -0
- package/src/scripts/TemplateSync.d.ts.map +1 -0
- package/src/scripts/TemplateSync.js +234 -0
- package/src/security/CsrfTokenManager.d.ts +28 -0
- package/src/security/CsrfTokenManager.d.ts.map +1 -0
- package/src/security/CsrfTokenManager.js +78 -0
- package/src/security/Encryptor.d.ts +15 -0
- package/src/security/Encryptor.d.ts.map +1 -0
- package/src/security/Encryptor.js +142 -0
- package/src/security/JwtManager.d.ts +41 -0
- package/src/security/JwtManager.d.ts.map +1 -0
- package/src/security/JwtManager.js +229 -0
- package/src/security/UrlValidator.d.ts +21 -0
- package/src/security/UrlValidator.d.ts.map +1 -0
- package/src/security/UrlValidator.js +42 -0
- package/src/security/XssProtection.d.ts +24 -0
- package/src/security/XssProtection.d.ts.map +1 -0
- package/src/security/XssProtection.js +133 -0
- package/src/templates/TemplateRegistry.d.ts +40 -0
- package/src/templates/TemplateRegistry.d.ts.map +1 -0
- package/src/templates/TemplateRegistry.js +78 -0
- package/src/templates/TemplateRegistry.ts +91 -0
- package/src/templates/adapters/MySQLAdapter.ts.tpl +97 -0
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +101 -0
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +95 -0
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +189 -0
- package/src/templates/features/Auth.ts.tpl +40 -0
- package/src/templates/features/Queue.ts.tpl +75 -0
- package/src/templates/project/basic/.env.example.tpl +26 -0
- package/src/templates/project/basic/.env.tpl +164 -0
- package/src/templates/project/basic/README.md.tpl +13 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +155 -0
- package/src/templates/project/basic/app/Middleware/ProfilerMiddleware.ts.tpl +55 -0
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +304 -0
- package/src/templates/project/basic/app/Models/Post.ts.tpl +30 -0
- package/src/templates/project/basic/app/Models/User.ts.tpl +53 -0
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +453 -0
- package/src/templates/project/basic/config/app.ts.tpl +97 -0
- package/src/templates/project/basic/config/cache.ts.tpl +117 -0
- package/src/templates/project/basic/config/constants.ts.tpl +70 -0
- package/src/templates/project/basic/config/database.ts.tpl +152 -0
- package/src/templates/project/basic/config/env.ts.tpl +148 -0
- package/src/templates/project/basic/config/features.ts.tpl +57 -0
- package/src/templates/project/basic/config/index.ts.tpl +36 -0
- package/src/templates/project/basic/config/logger.ts.tpl +95 -0
- package/src/templates/project/basic/config/microservices.ts.tpl +104 -0
- package/src/templates/project/basic/config/queue.ts.tpl +134 -0
- package/src/templates/project/basic/config/security.ts.tpl +149 -0
- package/src/templates/project/basic/config/storage.ts.tpl +136 -0
- package/src/templates/project/basic/database/factories/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/database/migrations/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/database/migrations/index.ts.tpl +2 -0
- package/src/templates/project/basic/database/seeders/.gitkeep.tpl +0 -0
- package/src/templates/project/basic/package.json.tpl +22 -0
- package/src/templates/project/basic/routes/api.ts.tpl +135 -0
- package/src/templates/project/basic/src/index.ts.tpl +49 -0
- package/src/templates/project/basic/template.json +17 -0
- package/src/templates/project/basic/tsconfig.json.tpl +20 -0
- package/src/validation/ValidationError.d.ts +42 -0
- package/src/validation/ValidationError.d.ts.map +1 -0
- package/src/validation/ValidationError.js +53 -0
- package/src/validation/Validator.d.ts +60 -0
- package/src/validation/Validator.d.ts.map +1 -0
- package/src/validation/Validator.js +190 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionManager.d.ts","sourceRoot":"","sources":["../../../src/orm/ConnectionManager.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAKH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,YAAY,GAAG,OAAO,GAAG,WAAW,GAAG,IAAI,GAAG,iBAAiB,CAAC;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAID,UAAU,yBAAyB;IACjC,aAAa,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,YAAY,IAAI,cAAc,CAAC;IAC/B,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAChE;AAoXD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;yBACkB,gBAAgB,GAAG,yBAAyB;IAYjE;;OAEG;gCACkC,OAAO,CAAC,OAAO,CAAC;IAIrD;;OAEG;qCACmC,MAAM,GAAe,OAAO,CAAC,IAAI,CAAC;IAIxE;;OAEG;gBACe,OAAO,CAAC,IAAI,CAAC;IAI/B;;OAEG;oBACa,cAAc;IAI9B;;OAEG;6BAC4B,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD;;OAEG;kCACiC,OAAO,CAAC,uBAAuB,CAAC;EAGpE,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACrE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CAC7F;AAED,MAAM,WAAW,iBAAiB;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAGpF;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,cAAc,CAQ9D;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;EAGxB,CAAC;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
/* eslint-disable @typescript-eslint/require-await */
|
|
3
|
+
/**
|
|
4
|
+
* Persistent Connection Manager for Zintrust Framework
|
|
5
|
+
* Handles database connections across different runtime environments
|
|
6
|
+
* Supports: PostgreSQL, MySQL, SQL Server with connection pooling for Lambda
|
|
7
|
+
*/
|
|
8
|
+
import { Env } from '../config/env';
|
|
9
|
+
import { Logger } from '../config/logger';
|
|
10
|
+
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
11
|
+
let instance;
|
|
12
|
+
/**
|
|
13
|
+
* Close a specific connection
|
|
14
|
+
*/
|
|
15
|
+
const closeConnection = async (conn) => {
|
|
16
|
+
if (conn !== undefined &&
|
|
17
|
+
conn !== null &&
|
|
18
|
+
typeof conn === 'object' &&
|
|
19
|
+
'close' in conn &&
|
|
20
|
+
typeof conn.close === 'function') {
|
|
21
|
+
await conn.close();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Test if connection is still alive
|
|
26
|
+
*/
|
|
27
|
+
const testConnection = async (config, _conn) => {
|
|
28
|
+
try {
|
|
29
|
+
if (config.adapter === 'postgresql' || config.adapter === 'mysql') {
|
|
30
|
+
// SELECT 1 for PostgreSQL/MySQL
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
const timeout = globalThis.setTimeout(() => reject(ErrorFactory.createConnectionError('Connection test timeout')), 5000);
|
|
33
|
+
try {
|
|
34
|
+
// In real implementation, query the connection
|
|
35
|
+
resolve(true);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
clearTimeout(timeout);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
ErrorFactory.createConnectionError('Connection test failed:', error);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Update connection usage metrics
|
|
51
|
+
*/
|
|
52
|
+
const updateConnectionUsage = (connectionPool, id) => {
|
|
53
|
+
const entry = connectionPool.find((c) => c.id === id);
|
|
54
|
+
if (entry !== undefined) {
|
|
55
|
+
entry.lastUsedAt = Date.now();
|
|
56
|
+
entry.queryCount++;
|
|
57
|
+
entry.isActive = true;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Create new database connection
|
|
62
|
+
*/
|
|
63
|
+
const createConnection = async (config, id) => {
|
|
64
|
+
Logger.info(`Creating ${config.adapter} connection (${id}) to ${config.host}:${config.port}`);
|
|
65
|
+
// Connection creation would be adapter-specific
|
|
66
|
+
// This is a placeholder for the actual implementation
|
|
67
|
+
return {
|
|
68
|
+
id,
|
|
69
|
+
adapter: config.adapter,
|
|
70
|
+
query: async (_sql, _params) => {
|
|
71
|
+
throw ErrorFactory.createDatabaseError(`Query execution not implemented for ${config.adapter}`);
|
|
72
|
+
},
|
|
73
|
+
close: async () => {
|
|
74
|
+
Logger.info(`Connection ${id} closed`);
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Create Aurora Data API connection
|
|
80
|
+
*/
|
|
81
|
+
const createAuroraDataApiConnection = () => ({
|
|
82
|
+
execute: async (_sql, _params) => {
|
|
83
|
+
// Call Aurora Data API via AWS SDK
|
|
84
|
+
// Requires proper IAM permissions
|
|
85
|
+
throw ErrorFactory.createConfigError('Aurora Data API not implemented yet');
|
|
86
|
+
},
|
|
87
|
+
batch: async (_statements) => {
|
|
88
|
+
// Execute batch statements
|
|
89
|
+
throw ErrorFactory.createConfigError('Aurora Data API batch not implemented yet');
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Get healthy existing connection if available
|
|
94
|
+
*/
|
|
95
|
+
const getHealthyExistingConnection = async (config, state, id) => {
|
|
96
|
+
if (!state.connections.has(id))
|
|
97
|
+
return null;
|
|
98
|
+
const conn = state.connections.get(id);
|
|
99
|
+
if (conn !== undefined && conn !== null && (await testConnection(config, conn))) {
|
|
100
|
+
updateConnectionUsage(state.connectionPool, id);
|
|
101
|
+
return conn;
|
|
102
|
+
}
|
|
103
|
+
state.connections.delete(id);
|
|
104
|
+
state.connectionPool = state.connectionPool.filter((c) => c.id !== id);
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Find an idle connection in the pool
|
|
109
|
+
*/
|
|
110
|
+
const findIdleConnection = (state) => {
|
|
111
|
+
const idleConnections = state.connectionPool.filter((c) => !c.isActive);
|
|
112
|
+
if (idleConnections.length === 0)
|
|
113
|
+
return null;
|
|
114
|
+
const lru = idleConnections.reduce((prev, current) => (prev.lastUsedAt < current.lastUsedAt ? prev : current), idleConnections[0]);
|
|
115
|
+
updateConnectionUsage(state.connectionPool, lru.id);
|
|
116
|
+
return state.connections.get(lru.id);
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Wait for a connection to become available
|
|
120
|
+
*/
|
|
121
|
+
const waitForIdleConnection = async (state) => {
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
let settled = false;
|
|
124
|
+
let timeoutId;
|
|
125
|
+
const checkInterval = setInterval(() => {
|
|
126
|
+
const idle = state.connectionPool.find((c) => !c.isActive);
|
|
127
|
+
if (idle !== undefined) {
|
|
128
|
+
if (settled)
|
|
129
|
+
return;
|
|
130
|
+
settled = true;
|
|
131
|
+
cleanup();
|
|
132
|
+
updateConnectionUsage(state.connectionPool, idle.id);
|
|
133
|
+
resolve(state.connections.get(idle.id));
|
|
134
|
+
}
|
|
135
|
+
}, 100);
|
|
136
|
+
const cleanup = () => {
|
|
137
|
+
clearInterval(checkInterval);
|
|
138
|
+
if (timeoutId !== undefined) {
|
|
139
|
+
clearTimeout(timeoutId);
|
|
140
|
+
timeoutId = undefined;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
// Node: allow process to exit; other runtimes may not support unref()
|
|
144
|
+
if (isUnrefableTimer(checkInterval)) {
|
|
145
|
+
checkInterval.unref();
|
|
146
|
+
}
|
|
147
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
148
|
+
timeoutId = setTimeout(() => {
|
|
149
|
+
if (settled)
|
|
150
|
+
return;
|
|
151
|
+
settled = true;
|
|
152
|
+
cleanup();
|
|
153
|
+
reject(ErrorFactory.createConnectionError('Connection pool exhausted - timeout waiting for available connection'));
|
|
154
|
+
}, 30000);
|
|
155
|
+
if (isUnrefableTimer(timeoutId)) {
|
|
156
|
+
timeoutId.unref();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
function isUnrefableTimer(value) {
|
|
161
|
+
if (typeof value !== 'object' || value === null)
|
|
162
|
+
return false;
|
|
163
|
+
return 'unref' in value && typeof value.unref === 'function';
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get or reuse a connection when at max capacity
|
|
167
|
+
*/
|
|
168
|
+
const getOrReuseConnection = async (state) => {
|
|
169
|
+
const idle = findIdleConnection(state);
|
|
170
|
+
if (idle !== null)
|
|
171
|
+
return idle;
|
|
172
|
+
return waitForIdleConnection(state);
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Periodically clean up idle connections
|
|
176
|
+
*/
|
|
177
|
+
const startIdleConnectionCleanup = (state, idleTimeout) => {
|
|
178
|
+
if (state.cleanupInterval) {
|
|
179
|
+
clearInterval(state.cleanupInterval);
|
|
180
|
+
}
|
|
181
|
+
state.cleanupInterval = setInterval(() => {
|
|
182
|
+
const now = Date.now();
|
|
183
|
+
const toRemove = [];
|
|
184
|
+
for (const poolEntry of state.connectionPool) {
|
|
185
|
+
if (!poolEntry.isActive && now - poolEntry.lastUsedAt > idleTimeout) {
|
|
186
|
+
toRemove.push(poolEntry.id);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const id of toRemove) {
|
|
190
|
+
const conn = state.connections.get(id);
|
|
191
|
+
closeConnection(conn).catch((err) => Logger.error(`Failed to close idle connection ${id}:`, err));
|
|
192
|
+
state.connections.delete(id);
|
|
193
|
+
state.connectionPool = state.connectionPool.filter((c) => c.id !== id);
|
|
194
|
+
Logger.info(`Removed idle connection: ${id}`);
|
|
195
|
+
}
|
|
196
|
+
}, 300000); // Every 5 minutes
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Create and register a new connection
|
|
200
|
+
*/
|
|
201
|
+
const createNewConnection = async (config, state, id) => {
|
|
202
|
+
const connection = await createConnection(config, id);
|
|
203
|
+
state.connections.set(id, connection);
|
|
204
|
+
state.connectionPool.push({
|
|
205
|
+
id,
|
|
206
|
+
adapter: config.adapter,
|
|
207
|
+
createdAt: Date.now(),
|
|
208
|
+
lastUsedAt: Date.now(),
|
|
209
|
+
isActive: true,
|
|
210
|
+
queryCount: 0,
|
|
211
|
+
});
|
|
212
|
+
return connection;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Close all connections (graceful shutdown)
|
|
216
|
+
*/
|
|
217
|
+
const closeAllConnections = async (state) => {
|
|
218
|
+
if (state.cleanupInterval) {
|
|
219
|
+
clearInterval(state.cleanupInterval);
|
|
220
|
+
state.cleanupInterval = undefined;
|
|
221
|
+
}
|
|
222
|
+
for (const [id, conn] of state.connections.entries()) {
|
|
223
|
+
try {
|
|
224
|
+
await closeConnection(conn);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
ErrorFactory.createConnectionError(`Failed to close connection ${id}:`, error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
state.connections.clear();
|
|
231
|
+
state.connectionPool = [];
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Get connection pool statistics
|
|
235
|
+
*/
|
|
236
|
+
const getPoolStatistics = (state) => {
|
|
237
|
+
const active = state.connectionPool.filter((c) => c.isActive).length;
|
|
238
|
+
const idle = state.connectionPool.filter((c) => !c.isActive).length;
|
|
239
|
+
return {
|
|
240
|
+
total: state.connectionPool.length,
|
|
241
|
+
active,
|
|
242
|
+
idle,
|
|
243
|
+
queued: 0,
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* ConnectionManager implementation
|
|
248
|
+
* Refactored to Functional Object pattern
|
|
249
|
+
*/
|
|
250
|
+
const ConnectionManagerImpl = {
|
|
251
|
+
/**
|
|
252
|
+
* Create a new connection manager instance
|
|
253
|
+
*/
|
|
254
|
+
create(config) {
|
|
255
|
+
const state = {
|
|
256
|
+
connections: new Map(),
|
|
257
|
+
connectionPool: [],
|
|
258
|
+
};
|
|
259
|
+
const maxConnections = config.maxConnections ?? 10;
|
|
260
|
+
const idleTimeout = config.idleTimeout ?? 900000; // 15 minutes
|
|
261
|
+
// Cleanup idle connections every 5 minutes
|
|
262
|
+
startIdleConnectionCleanup(state, idleTimeout);
|
|
263
|
+
return {
|
|
264
|
+
/**
|
|
265
|
+
* Get or create database connection
|
|
266
|
+
*/
|
|
267
|
+
async getConnection(id = 'default') {
|
|
268
|
+
const existing = await getHealthyExistingConnection(config, state, id);
|
|
269
|
+
if (existing !== null)
|
|
270
|
+
return existing;
|
|
271
|
+
if (state.connectionPool.length < maxConnections) {
|
|
272
|
+
return createNewConnection(config, state, id);
|
|
273
|
+
}
|
|
274
|
+
return getOrReuseConnection(state);
|
|
275
|
+
},
|
|
276
|
+
/**
|
|
277
|
+
* Release connection back to pool (but keep persistent)
|
|
278
|
+
*/
|
|
279
|
+
async releaseConnection(connectionId = 'default') {
|
|
280
|
+
const poolEntry = state.connectionPool.find((c) => c.id === connectionId);
|
|
281
|
+
if (poolEntry !== undefined) {
|
|
282
|
+
poolEntry.isActive = false;
|
|
283
|
+
poolEntry.lastUsedAt = Date.now();
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Close all connections (graceful shutdown)
|
|
288
|
+
*/
|
|
289
|
+
async closeAll() {
|
|
290
|
+
return closeAllConnections(state);
|
|
291
|
+
},
|
|
292
|
+
/**
|
|
293
|
+
* Get connection pool statistics
|
|
294
|
+
*/
|
|
295
|
+
getPoolStats() {
|
|
296
|
+
return getPoolStatistics(state);
|
|
297
|
+
},
|
|
298
|
+
/**
|
|
299
|
+
* Enable RDS Proxy for connection pooling
|
|
300
|
+
*/
|
|
301
|
+
async enableRdsProxy(endpoint) {
|
|
302
|
+
config.enableRdsProxy = true;
|
|
303
|
+
config.rdsProxyEndpoint = endpoint;
|
|
304
|
+
config.host = endpoint;
|
|
305
|
+
Logger.info(`RDS Proxy enabled: ${endpoint}`);
|
|
306
|
+
},
|
|
307
|
+
/**
|
|
308
|
+
* Use Aurora Data API for serverless queries (no persistent connection)
|
|
309
|
+
*/
|
|
310
|
+
async getAuroraDataApiConnection() {
|
|
311
|
+
return createAuroraDataApiConnection();
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Manages database connections across Lambda warm invocations
|
|
318
|
+
* Reuses connections to reduce cold start impact and connection overhead
|
|
319
|
+
* Sealed namespace object following Pattern 2
|
|
320
|
+
*
|
|
321
|
+
* @see FRAMEWORK_REFACTOR_FUNCTION_PATTERN.md for Pattern 2 details
|
|
322
|
+
*/
|
|
323
|
+
export const ConnectionManager = Object.freeze({
|
|
324
|
+
/**
|
|
325
|
+
* Get or create singleton instance
|
|
326
|
+
*/
|
|
327
|
+
getInstance(config) {
|
|
328
|
+
if (instance === undefined && config !== undefined) {
|
|
329
|
+
instance = ConnectionManagerImpl.create(config);
|
|
330
|
+
}
|
|
331
|
+
if (instance === undefined) {
|
|
332
|
+
throw ErrorFactory.createConfigError('ConnectionManager not initialized. Call getInstance(config) first.');
|
|
333
|
+
}
|
|
334
|
+
return instance;
|
|
335
|
+
},
|
|
336
|
+
/**
|
|
337
|
+
* Get or create database connection
|
|
338
|
+
*/
|
|
339
|
+
async getConnection(id = 'default') {
|
|
340
|
+
return this.getInstance().getConnection(id);
|
|
341
|
+
},
|
|
342
|
+
/**
|
|
343
|
+
* Release connection back to pool (but keep persistent)
|
|
344
|
+
*/
|
|
345
|
+
async releaseConnection(connectionId = 'default') {
|
|
346
|
+
return this.getInstance().releaseConnection(connectionId);
|
|
347
|
+
},
|
|
348
|
+
/**
|
|
349
|
+
* Close all connections (graceful shutdown)
|
|
350
|
+
*/
|
|
351
|
+
async closeAll() {
|
|
352
|
+
return this.getInstance().closeAll();
|
|
353
|
+
},
|
|
354
|
+
/**
|
|
355
|
+
* Get connection pool statistics
|
|
356
|
+
*/
|
|
357
|
+
getPoolStats() {
|
|
358
|
+
return this.getInstance().getPoolStats();
|
|
359
|
+
},
|
|
360
|
+
/**
|
|
361
|
+
* Enable RDS Proxy for connection pooling
|
|
362
|
+
*/
|
|
363
|
+
async enableRdsProxy(endpoint) {
|
|
364
|
+
return this.getInstance().enableRdsProxy(endpoint);
|
|
365
|
+
},
|
|
366
|
+
/**
|
|
367
|
+
* Use Aurora Data API for serverless queries (no persistent connection)
|
|
368
|
+
*/
|
|
369
|
+
async getAuroraDataApiConnection() {
|
|
370
|
+
return this.getInstance().getAuroraDataApiConnection();
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
/**
|
|
374
|
+
* Get database credentials from AWS Secrets Manager
|
|
375
|
+
*/
|
|
376
|
+
export async function getDatabaseSecret(_secretName) {
|
|
377
|
+
// Would use AWS SDK to fetch from Secrets Manager
|
|
378
|
+
throw ErrorFactory.createConfigError('Secrets Manager integration not implemented');
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get database credentials from environment variables
|
|
382
|
+
*/
|
|
383
|
+
export function getDatabaseCredentialsFromEnv() {
|
|
384
|
+
return {
|
|
385
|
+
username: Env.DB_USERNAME,
|
|
386
|
+
password: Env.DB_PASSWORD,
|
|
387
|
+
host: Env.DB_HOST,
|
|
388
|
+
port: Env.DB_PORT,
|
|
389
|
+
database: Env.DB_DATABASE,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Secrets Manager for retrieving database credentials securely
|
|
394
|
+
* Sealed namespace object following Pattern 2
|
|
395
|
+
*
|
|
396
|
+
* @see FRAMEWORK_REFACTOR_FUNCTION_PATTERN.md for Pattern 2 details
|
|
397
|
+
*/
|
|
398
|
+
export const SecretsHelper = Object.freeze({
|
|
399
|
+
getDatabaseSecret,
|
|
400
|
+
getDatabaseCredentialsFromEnv,
|
|
401
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Manager
|
|
3
|
+
* Central database connection management and query execution
|
|
4
|
+
*/
|
|
5
|
+
import { DatabaseConfig, IDatabaseAdapter } from './DatabaseAdapter';
|
|
6
|
+
import { IQueryBuilder } from './QueryBuilder';
|
|
7
|
+
export interface IDatabase {
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
disconnect(): Promise<void>;
|
|
10
|
+
isConnected(): boolean;
|
|
11
|
+
query(sql: string, parameters?: unknown[], isRead?: boolean): Promise<unknown[]>;
|
|
12
|
+
queryOne(sql: string, parameters?: unknown[], isRead?: boolean): Promise<unknown>;
|
|
13
|
+
transaction<T>(callback: (db: IDatabase) => Promise<T>): Promise<T>;
|
|
14
|
+
table(name: string): IQueryBuilder;
|
|
15
|
+
onBeforeQuery(handler: (query: string, params: unknown[]) => void): void;
|
|
16
|
+
onAfterQuery(handler: (query: string, params: unknown[], duration: number) => void): void;
|
|
17
|
+
offBeforeQuery(handler: (query: string, params: unknown[]) => void): void;
|
|
18
|
+
offAfterQuery(handler: (query: string, params: unknown[], duration: number) => void): void;
|
|
19
|
+
getAdapterInstance(isRead?: boolean): IDatabaseAdapter;
|
|
20
|
+
getType(): string;
|
|
21
|
+
getConfig(): DatabaseConfig;
|
|
22
|
+
}
|
|
23
|
+
export declare const Database: Readonly<{
|
|
24
|
+
/**
|
|
25
|
+
* Create a new database instance
|
|
26
|
+
*/
|
|
27
|
+
create(config?: DatabaseConfig): IDatabase;
|
|
28
|
+
}>;
|
|
29
|
+
export declare function useDatabase(config?: DatabaseConfig, connection?: string): IDatabase;
|
|
30
|
+
export declare function resetDatabase(): Promise<void>;
|
|
31
|
+
//# sourceMappingURL=Database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../../src/orm/Database.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAgB,MAAM,mBAAmB,CAAC;AAEhE,MAAM,WAAW,SAAS;IACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,WAAW,IAAI,OAAO,CAAC;IACvB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACjF,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClF,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACpE,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IACzE,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAC1F,cAAc,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC1E,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3F,kBAAkB,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACvD,OAAO,IAAI,MAAM,CAAC;IAClB,SAAS,IAAI,cAAc,CAAC;CAC7B;AA6ED,eAAO,MAAM,QAAQ;IACnB;;OAEG;oBACa,cAAc,GAAG,SAAS;EAwE1C,CAAC;AAIH,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,UAAU,SAAY,GAAG,SAAS,CAStF;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAUnD"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Manager
|
|
3
|
+
* Central database connection management and query execution
|
|
4
|
+
*/
|
|
5
|
+
import { ErrorFactory } from '../exceptions/ZintrustError';
|
|
6
|
+
import { EventEmitter } from '../node-singletons/events';
|
|
7
|
+
import { D1Adapter } from './adapters/D1Adapter';
|
|
8
|
+
import { MySQLAdapter } from './adapters/MySQLAdapter';
|
|
9
|
+
import { PostgreSQLAdapter } from './adapters/PostgreSQLAdapter';
|
|
10
|
+
import { SQLiteAdapter } from './adapters/SQLiteAdapter';
|
|
11
|
+
import { SQLServerAdapter } from './adapters/SQLServerAdapter';
|
|
12
|
+
import { QueryBuilder } from './QueryBuilder';
|
|
13
|
+
/**
|
|
14
|
+
* Database Manager
|
|
15
|
+
* Refactored to Functional Object pattern
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Create appropriate adapter based on driver
|
|
19
|
+
*/
|
|
20
|
+
const createAdapter = (cfg) => {
|
|
21
|
+
switch (cfg.driver) {
|
|
22
|
+
case 'postgresql':
|
|
23
|
+
return PostgreSQLAdapter.create(cfg);
|
|
24
|
+
case 'mysql':
|
|
25
|
+
return MySQLAdapter.create(cfg);
|
|
26
|
+
case 'sqlserver':
|
|
27
|
+
return SQLServerAdapter.create(cfg);
|
|
28
|
+
case 'd1':
|
|
29
|
+
return D1Adapter.create(cfg);
|
|
30
|
+
case 'sqlite':
|
|
31
|
+
default:
|
|
32
|
+
return SQLiteAdapter.create(cfg);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Initialize write and read adapters
|
|
37
|
+
*/
|
|
38
|
+
const initializeAdapters = (dbConfig) => {
|
|
39
|
+
const writeAdapter = createAdapter(dbConfig);
|
|
40
|
+
const readAdapters = [];
|
|
41
|
+
if (dbConfig.readHosts !== undefined && dbConfig.readHosts.length > 0) {
|
|
42
|
+
for (const host of dbConfig.readHosts) {
|
|
43
|
+
readAdapters.push(createAdapter({ ...dbConfig, host }));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
readAdapters.push(writeAdapter);
|
|
48
|
+
}
|
|
49
|
+
return { writeAdapter, readAdapters };
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Execute a query with events and timing
|
|
53
|
+
*/
|
|
54
|
+
const executeQuery = async (adapter, eventEmitter, sql, parameters, method) => {
|
|
55
|
+
eventEmitter.emit('before-query', sql, parameters);
|
|
56
|
+
const startTime = Date.now();
|
|
57
|
+
const result = await adapter[method](sql, parameters);
|
|
58
|
+
const duration = Date.now() - startTime;
|
|
59
|
+
eventEmitter.emit('after-query', sql, parameters, duration);
|
|
60
|
+
return result.rows;
|
|
61
|
+
};
|
|
62
|
+
const executeQueryOne = async (adapter, eventEmitter, sql, parameters) => {
|
|
63
|
+
eventEmitter.emit('before-query', sql, parameters);
|
|
64
|
+
const startTime = Date.now();
|
|
65
|
+
const result = await adapter.queryOne(sql, parameters);
|
|
66
|
+
const duration = Date.now() - startTime;
|
|
67
|
+
eventEmitter.emit('after-query', sql, parameters, duration);
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
export const Database = Object.freeze({
|
|
71
|
+
/**
|
|
72
|
+
* Create a new database instance
|
|
73
|
+
*/
|
|
74
|
+
create(config) {
|
|
75
|
+
const dbConfig = config ?? { driver: 'sqlite', database: ':memory:' };
|
|
76
|
+
const eventEmitter = new EventEmitter();
|
|
77
|
+
let connected = false;
|
|
78
|
+
let readIndex = 0;
|
|
79
|
+
const { writeAdapter, readAdapters } = initializeAdapters(dbConfig);
|
|
80
|
+
const getAdapter = (isRead = false) => {
|
|
81
|
+
if (isRead === false || readAdapters.length === 0) {
|
|
82
|
+
return writeAdapter;
|
|
83
|
+
}
|
|
84
|
+
const adapter = readAdapters[readIndex];
|
|
85
|
+
if (adapter === undefined)
|
|
86
|
+
return writeAdapter;
|
|
87
|
+
readIndex = (readIndex + 1) % readAdapters.length;
|
|
88
|
+
return adapter;
|
|
89
|
+
};
|
|
90
|
+
const db = {
|
|
91
|
+
async connect() {
|
|
92
|
+
await writeAdapter.connect();
|
|
93
|
+
await Promise.all(readAdapters
|
|
94
|
+
.filter((adapter) => adapter !== writeAdapter)
|
|
95
|
+
.map(async (adapter) => adapter.connect()));
|
|
96
|
+
connected = true;
|
|
97
|
+
},
|
|
98
|
+
async disconnect() {
|
|
99
|
+
await writeAdapter.disconnect();
|
|
100
|
+
await Promise.all(readAdapters
|
|
101
|
+
.filter((adapter) => adapter !== writeAdapter)
|
|
102
|
+
.map(async (adapter) => adapter.disconnect()));
|
|
103
|
+
connected = false;
|
|
104
|
+
},
|
|
105
|
+
isConnected() {
|
|
106
|
+
return connected;
|
|
107
|
+
},
|
|
108
|
+
async query(sql, parameters = [], isRead = false) {
|
|
109
|
+
if (connected === false)
|
|
110
|
+
throw ErrorFactory.createConnectionError('Database not connected. Call connect() first.');
|
|
111
|
+
return executeQuery(getAdapter(isRead), eventEmitter, sql, parameters, 'query');
|
|
112
|
+
},
|
|
113
|
+
async queryOne(sql, parameters = [], isRead = false) {
|
|
114
|
+
if (connected === false)
|
|
115
|
+
throw ErrorFactory.createConnectionError('Database not connected. Call connect() first.');
|
|
116
|
+
return executeQueryOne(getAdapter(isRead), eventEmitter, sql, parameters);
|
|
117
|
+
},
|
|
118
|
+
async transaction(callback) {
|
|
119
|
+
return writeAdapter.transaction(async () => callback(db));
|
|
120
|
+
},
|
|
121
|
+
table(name) {
|
|
122
|
+
return QueryBuilder.create(name, db);
|
|
123
|
+
},
|
|
124
|
+
onBeforeQuery: (h) => eventEmitter.on('before-query', h),
|
|
125
|
+
onAfterQuery: (h) => eventEmitter.on('after-query', h),
|
|
126
|
+
offBeforeQuery: (h) => eventEmitter.off('before-query', h),
|
|
127
|
+
offAfterQuery: (h) => eventEmitter.off('after-query', h),
|
|
128
|
+
getAdapterInstance(isRead = false) {
|
|
129
|
+
return getAdapter(isRead);
|
|
130
|
+
},
|
|
131
|
+
getType() {
|
|
132
|
+
return writeAdapter.getType();
|
|
133
|
+
},
|
|
134
|
+
getConfig() {
|
|
135
|
+
return { ...dbConfig };
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
return db;
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
const databaseInstances = new Map();
|
|
142
|
+
export function useDatabase(config, connection = 'default') {
|
|
143
|
+
if (databaseInstances.has(connection) === false) {
|
|
144
|
+
databaseInstances.set(connection, Database.create(config));
|
|
145
|
+
}
|
|
146
|
+
const instance = databaseInstances.get(connection);
|
|
147
|
+
if (instance === undefined) {
|
|
148
|
+
throw ErrorFactory.createConfigError(`Failed to initialize database instance: ${connection}`);
|
|
149
|
+
}
|
|
150
|
+
return instance;
|
|
151
|
+
}
|
|
152
|
+
export async function resetDatabase() {
|
|
153
|
+
const promises = Array.from(databaseInstances.values()).map(async (instance) => {
|
|
154
|
+
try {
|
|
155
|
+
await instance.disconnect();
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// Ignore errors during disconnect
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
await Promise.all(promises);
|
|
162
|
+
databaseInstances.clear();
|
|
163
|
+
}
|