@zintrust/core 0.1.19 → 0.1.21
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 +10 -10
- package/bin/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +9 -0
- package/package.json +3 -2
- package/public/error-pages/404.html +145 -0
- package/public/error-pages/500.html +266 -0
- package/public/error-pages/error.css +628 -0
- package/public/error-pages/error.js +428 -0
- package/public/zintrust.svg +30 -0
- package/routes/api.d.ts.map +1 -1
- package/routes/api.js +41 -17
- package/routes/metrics.d.ts +9 -0
- package/routes/metrics.d.ts.map +1 -0
- package/routes/metrics.js +20 -0
- package/routes/openapi.d.ts +9 -0
- package/routes/openapi.d.ts.map +1 -0
- package/routes/openapi.js +76 -0
- package/src/boot/Application.d.ts +2 -2
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +66 -13
- package/src/boot/Server.d.ts +3 -2
- package/src/boot/Server.d.ts.map +1 -1
- package/src/boot/Server.js +39 -165
- package/src/boot/bootstrap.js +2 -0
- package/src/cache/Cache.d.ts +1 -1
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/CacheDriver.d.ts +4 -0
- package/src/cache/CacheDriver.d.ts.map +1 -1
- package/src/cache/drivers/KVDriver.d.ts +1 -1
- package/src/cache/drivers/KVDriver.d.ts.map +1 -1
- package/src/cache/drivers/MemoryDriver.d.ts +1 -1
- package/src/cache/drivers/MemoryDriver.d.ts.map +1 -1
- package/src/cache/drivers/MemoryDriver.js +16 -0
- package/src/cache/drivers/MongoDriver.d.ts +1 -1
- package/src/cache/drivers/MongoDriver.d.ts.map +1 -1
- package/src/cache/drivers/RedisDriver.d.ts +1 -1
- package/src/cache/drivers/RedisDriver.d.ts.map +1 -1
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +10 -4
- package/src/cli/commands/AddCommand.d.ts +2 -2
- package/src/cli/commands/AddCommand.d.ts.map +1 -1
- package/src/cli/commands/AddCommand.js +135 -58
- package/src/cli/commands/ConfigCommand.d.ts +1 -1
- package/src/cli/commands/ConfigCommand.d.ts.map +1 -1
- package/src/cli/commands/CreateCommand.d.ts +15 -0
- package/src/cli/commands/CreateCommand.d.ts.map +1 -0
- package/src/cli/commands/CreateCommand.js +143 -0
- package/src/cli/commands/D1MigrateCommand.d.ts +1 -1
- package/src/cli/commands/D1MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/D1MigrateCommand.js +16 -20
- package/src/cli/commands/DbSeedCommand.d.ts +9 -0
- package/src/cli/commands/DbSeedCommand.d.ts.map +1 -0
- package/src/cli/commands/DbSeedCommand.js +171 -0
- package/src/cli/commands/DebugCommand.d.ts +1 -1
- package/src/cli/commands/DebugCommand.d.ts.map +1 -1
- package/src/cli/commands/FixCommand.d.ts +1 -1
- package/src/cli/commands/FixCommand.d.ts.map +1 -1
- package/src/cli/commands/JwtDevCommand.d.ts +8 -0
- package/src/cli/commands/JwtDevCommand.d.ts.map +1 -0
- package/src/cli/commands/JwtDevCommand.js +114 -0
- package/src/cli/commands/KeyGenerateCommand.d.ts +1 -1
- package/src/cli/commands/KeyGenerateCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.d.ts +2 -2
- package/src/cli/commands/LogsCommand.d.ts.map +1 -1
- package/src/cli/commands/LogsCommand.js +36 -2
- package/src/cli/commands/MakeMailTemplateCommand.d.ts +1 -1
- package/src/cli/commands/MakeMailTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts +1 -1
- package/src/cli/commands/MakeNotificationTemplateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.d.ts +1 -1
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +324 -35
- package/src/cli/commands/NewCommand.d.ts +1 -1
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +12 -4
- package/src/cli/commands/PluginCommand.d.ts +1 -1
- package/src/cli/commands/PluginCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.d.ts +1 -1
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/QACommand.d.ts +2 -2
- package/src/cli/commands/QACommand.d.ts.map +1 -1
- package/src/cli/commands/RoutesCommand.d.ts +10 -0
- package/src/cli/commands/RoutesCommand.d.ts.map +1 -0
- package/src/cli/commands/RoutesCommand.js +242 -0
- package/src/cli/commands/SimulateCommand.d.ts +1 -1
- package/src/cli/commands/SimulateCommand.d.ts.map +1 -1
- package/src/cli/commands/index.d.ts +3 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +3 -0
- package/src/cli/config/ConfigManager.d.ts +1 -1
- package/src/cli/config/ConfigManager.d.ts.map +1 -1
- package/src/cli/config/ConfigValidator.d.ts +1 -1
- package/src/cli/config/ConfigValidator.d.ts.map +1 -1
- package/src/cli/config/ConfigValidator.js +1 -1
- package/src/cli/d1/D1SqlMigrations.d.ts +20 -0
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -0
- package/src/cli/d1/D1SqlMigrations.js +229 -0
- package/src/cli/d1/WranglerConfig.d.ts +4 -0
- package/src/cli/d1/WranglerConfig.d.ts.map +1 -0
- package/src/cli/d1/WranglerConfig.js +122 -0
- package/src/cli/d1/WranglerD1.d.ts +11 -0
- package/src/cli/d1/WranglerD1.d.ts.map +1 -0
- package/src/cli/d1/WranglerD1.js +16 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ControllerGenerator.js +76 -26
- package/src/cli/scaffolding/FactoryGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/FactoryGenerator.js +3 -1
- package/src/cli/scaffolding/GovernanceScaffolder.d.ts +23 -0
- package/src/cli/scaffolding/GovernanceScaffolder.d.ts.map +1 -0
- package/src/cli/scaffolding/GovernanceScaffolder.js +327 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts +10 -0
- package/src/cli/scaffolding/MigrationGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/MigrationGenerator.js +137 -51
- package/src/cli/scaffolding/ModelGenerator.js +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +36 -4
- package/src/cli/scaffolding/RouteGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/RouteGenerator.js +79 -43
- package/src/cli/scaffolding/SeederGenerator.d.ts +5 -0
- package/src/cli/scaffolding/SeederGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/SeederGenerator.js +63 -15
- package/src/cli/scaffolding/ServiceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +28 -7
- package/src/cli/scaffolding/index.d.ts +2 -0
- package/src/cli/scaffolding/index.d.ts.map +1 -1
- package/src/cli/scaffolding/index.js +1 -0
- package/src/common/index.d.ts +8 -0
- package/src/common/index.d.ts.map +1 -1
- package/src/common/index.js +28 -0
- package/src/common/utility.d.ts +38 -0
- package/src/common/utility.d.ts.map +1 -0
- package/src/common/utility.js +101 -0
- package/src/config/FileLogWriter.d.ts +2 -1
- package/src/config/FileLogWriter.d.ts.map +1 -1
- package/src/config/FileLogWriter.js +83 -2
- package/src/config/app.d.ts.map +1 -1
- package/src/config/app.js +3 -1
- package/src/config/broadcast.d.ts +14 -28
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +69 -35
- package/src/config/cache.d.ts +13 -45
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +69 -25
- package/src/config/cloudflare.d.ts +1 -1
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/database.d.ts +22 -64
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +191 -37
- package/src/config/env.d.ts +12 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +14 -0
- package/src/config/index.d.ts +33 -137
- package/src/config/index.d.ts.map +1 -1
- package/src/config/logging/KvLogger.js +1 -1
- package/src/config/logging/SlackLogger.js +2 -2
- package/src/config/mail.d.ts +19 -55
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +63 -21
- package/src/config/middleware.d.ts +44 -1
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +157 -5
- package/src/config/notification.d.ts +14 -27
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +82 -36
- package/src/config/queue.d.ts +21 -51
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +72 -27
- package/src/config/security.d.ts +1 -1
- package/src/config/security.js +1 -1
- package/src/config/storage.d.ts +27 -34
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +97 -56
- package/src/config/type.d.ts +13 -2
- package/src/config/type.d.ts.map +1 -1
- package/src/events/EventDispatcher.d.ts.map +1 -1
- package/src/events/EventDispatcher.js +6 -4
- package/src/exceptions/ZintrustError.d.ts +7 -0
- package/src/exceptions/ZintrustError.d.ts.map +1 -1
- package/src/exceptions/ZintrustError.js +56 -0
- package/src/features/Auth.d.ts +1 -1
- package/src/features/Auth.d.ts.map +1 -1
- package/src/features/Auth.js +3 -3
- package/src/features/Queue.js +1 -1
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +3 -14
- package/src/functions/deno.d.ts.map +1 -1
- package/src/functions/deno.js +3 -14
- package/src/functions/lambda.d.ts.map +1 -1
- package/src/functions/lambda.js +3 -14
- package/src/health/StartupHealthChecks.js +1 -1
- package/src/http/Controller.d.ts +2 -2
- package/src/http/Controller.d.ts.map +1 -1
- package/src/http/FileUpload.d.ts +68 -0
- package/src/http/FileUpload.d.ts.map +1 -0
- package/src/http/FileUpload.js +120 -0
- package/src/http/Kernel.d.ts +5 -5
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +139 -23
- package/src/http/Request.d.ts +20 -1
- package/src/http/Request.d.ts.map +1 -1
- package/src/http/Request.js +23 -0
- package/src/http/RequestContext.d.ts +6 -0
- package/src/http/RequestContext.d.ts.map +1 -1
- package/src/http/RequestContext.js +77 -1
- package/src/http/Response.d.ts +1 -1
- package/src/http/Response.d.ts.map +1 -1
- package/src/http/ValidationHelper.d.ts +78 -0
- package/src/http/ValidationHelper.d.ts.map +1 -0
- package/src/http/ValidationHelper.js +121 -0
- package/src/http/error-pages/ErrorPageRenderer.d.ts +17 -0
- package/src/http/error-pages/ErrorPageRenderer.d.ts.map +1 -0
- package/src/http/error-pages/ErrorPageRenderer.js +88 -0
- package/src/http/middleware/BodyParsingMiddleware.d.ts +12 -0
- package/src/http/middleware/BodyParsingMiddleware.d.ts.map +1 -0
- package/src/http/middleware/BodyParsingMiddleware.js +251 -0
- package/src/http/middleware/FileUploadMiddleware.d.ts +12 -0
- package/src/http/middleware/FileUploadMiddleware.d.ts.map +1 -0
- package/src/http/middleware/FileUploadMiddleware.js +74 -0
- package/src/http/parsers/BodyParsers.d.ts +32 -0
- package/src/http/parsers/BodyParsers.d.ts.map +1 -0
- package/src/http/parsers/BodyParsers.js +159 -0
- package/src/http/parsers/MultipartParser.d.ts +33 -0
- package/src/http/parsers/MultipartParser.d.ts.map +1 -0
- package/src/http/parsers/MultipartParser.js +156 -0
- package/src/http/parsers/MultipartParserRegistry.d.ts +34 -0
- package/src/http/parsers/MultipartParserRegistry.d.ts.map +1 -0
- package/src/http/parsers/MultipartParserRegistry.js +20 -0
- package/src/http/validated.d.ts +12 -0
- package/src/http/validated.d.ts.map +1 -0
- package/src/http/validated.js +41 -0
- package/src/index.d.ts +73 -12
- package/src/index.d.ts.map +1 -1
- package/src/index.js +60 -5
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +0 -1
- package/src/microservices/RequestTracingMiddleware.d.ts +2 -2
- package/src/microservices/RequestTracingMiddleware.d.ts.map +1 -1
- package/src/microservices/RequestTracingMiddleware.js +3 -0
- package/src/microservices/ServiceAuthMiddleware.d.ts +2 -2
- package/src/microservices/ServiceAuthMiddleware.d.ts.map +1 -1
- package/src/middleware/AuthMiddleware.d.ts +10 -0
- package/src/middleware/AuthMiddleware.d.ts.map +1 -0
- package/src/middleware/AuthMiddleware.js +16 -0
- package/src/middleware/CsrfMiddleware.d.ts +11 -1
- package/src/middleware/CsrfMiddleware.d.ts.map +1 -1
- package/src/middleware/CsrfMiddleware.js +33 -0
- package/src/middleware/JwtAuthMiddleware.d.ts +11 -0
- package/src/middleware/JwtAuthMiddleware.d.ts.map +1 -0
- package/src/middleware/JwtAuthMiddleware.js +73 -0
- package/src/middleware/LoggingMiddleware.d.ts.map +1 -1
- package/src/middleware/LoggingMiddleware.js +8 -3
- package/src/middleware/MiddlewareStack.d.ts +2 -2
- package/src/middleware/MiddlewareStack.d.ts.map +1 -1
- package/src/middleware/RateLimiter.d.ts +2 -2
- package/src/middleware/RateLimiter.d.ts.map +1 -1
- package/src/middleware/SanitizeBodyMiddleware.d.ts +12 -0
- package/src/middleware/SanitizeBodyMiddleware.d.ts.map +1 -0
- package/src/middleware/SanitizeBodyMiddleware.js +31 -0
- package/src/middleware/SecurityMiddleware.d.ts +1 -1
- package/src/middleware/SecurityMiddleware.d.ts.map +1 -1
- package/src/middleware/SessionMiddleware.d.ts +1 -1
- package/src/middleware/SessionMiddleware.d.ts.map +1 -1
- package/src/middleware/ValidationMiddleware.d.ts +25 -0
- package/src/middleware/ValidationMiddleware.d.ts.map +1 -0
- package/src/middleware/ValidationMiddleware.js +251 -0
- package/src/migrations/MigrationDiscovery.d.ts +5 -0
- package/src/migrations/MigrationDiscovery.d.ts.map +1 -0
- package/src/migrations/MigrationDiscovery.js +16 -0
- package/src/migrations/MigrationLoader.d.ts +5 -0
- package/src/migrations/MigrationLoader.d.ts.map +1 -0
- package/src/migrations/MigrationLoader.js +43 -0
- package/src/migrations/MigrationLock.d.ts +4 -0
- package/src/migrations/MigrationLock.d.ts.map +1 -0
- package/src/migrations/MigrationLock.js +33 -0
- package/src/migrations/Migrator.d.ts +23 -0
- package/src/migrations/Migrator.d.ts.map +1 -0
- package/src/migrations/Migrator.js +4 -0
- package/src/migrations/MigratorFactory.d.ts +25 -0
- package/src/migrations/MigratorFactory.d.ts.map +1 -0
- package/src/migrations/MigratorFactory.js +339 -0
- package/src/migrations/schema/Blueprint.d.ts +5 -0
- package/src/migrations/schema/Blueprint.d.ts.map +1 -0
- package/src/migrations/schema/Blueprint.js +189 -0
- package/src/migrations/schema/Schema.d.ts +8 -0
- package/src/migrations/schema/Schema.d.ts.map +1 -0
- package/src/migrations/schema/Schema.js +141 -0
- package/src/migrations/schema/SchemaCompiler.d.ts +20 -0
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -0
- package/src/migrations/schema/SchemaCompiler.js +262 -0
- package/src/migrations/schema/index.d.ts +5 -0
- package/src/migrations/schema/index.d.ts.map +1 -0
- package/src/migrations/schema/index.js +3 -0
- package/src/migrations/schema/types.d.ts +86 -0
- package/src/migrations/schema/types.d.ts.map +1 -0
- package/src/migrations/schema/types.js +1 -0
- package/src/migrations/types.d.ts +45 -0
- package/src/migrations/types.d.ts.map +1 -0
- package/src/migrations/types.js +1 -0
- package/src/node-singletons/crypto.d.ts +1 -1
- package/src/node-singletons/crypto.d.ts.map +1 -1
- package/src/node-singletons/crypto.js +1 -1
- package/src/node-singletons/fs.d.ts +2 -2
- package/src/node-singletons/fs.d.ts.map +1 -1
- package/src/node-singletons/fs.js +1 -1
- package/src/node-singletons/util.d.ts +6 -0
- package/src/node-singletons/util.d.ts.map +1 -0
- package/src/node-singletons/util.js +5 -0
- package/src/node.d.ts +3 -1
- package/src/node.d.ts.map +1 -1
- package/src/node.js +6 -2
- package/src/observability/OpenTelemetry.d.ts +62 -0
- package/src/observability/OpenTelemetry.d.ts.map +1 -0
- package/src/observability/OpenTelemetry.js +167 -0
- package/src/observability/PrometheusMetrics.d.ts +25 -0
- package/src/observability/PrometheusMetrics.d.ts.map +1 -0
- package/src/observability/PrometheusMetrics.js +114 -0
- package/src/openapi/OpenApiGenerator.d.ts +68 -0
- package/src/openapi/OpenApiGenerator.d.ts.map +1 -0
- package/src/openapi/OpenApiGenerator.js +287 -0
- package/src/orm/Database.d.ts +5 -2
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +219 -63
- package/src/orm/DatabaseAdapter.d.ts +14 -0
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseAdapterRegistry.d.ts.map +1 -1
- package/src/orm/DatabaseAdapterRegistry.js +3 -1
- package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.js +12 -0
- package/src/orm/Model.d.ts +30 -2
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +255 -62
- package/src/orm/QueryBuilder.d.ts +22 -1
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +406 -99
- package/src/orm/Relationships.d.ts +7 -1
- package/src/orm/Relationships.d.ts.map +1 -1
- package/src/orm/Relationships.js +18 -0
- package/src/orm/SchemaCompiler.d.ts +9 -0
- package/src/orm/SchemaCompiler.d.ts.map +1 -0
- package/src/orm/SchemaCompiler.js +145 -0
- package/src/orm/adapters/D1Adapter.d.ts +1 -1
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.d.ts +1 -1
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +88 -69
- package/src/orm/adapters/PostgreSQLAdapter.d.ts +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/PostgreSQLAdapter.js +88 -69
- package/src/orm/adapters/SQLServerAdapter.d.ts +1 -1
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts +1 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +59 -3
- package/src/orm/maintenance/SqliteMaintenance.d.ts +5 -0
- package/src/orm/maintenance/SqliteMaintenance.d.ts.map +1 -0
- package/src/orm/maintenance/SqliteMaintenance.js +14 -0
- package/src/orm/migrations/MigrationStore.d.ts +38 -0
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -0
- package/src/orm/migrations/MigrationStore.js +157 -0
- package/src/performance/CodeGenerationBenchmark.d.ts.map +1 -1
- package/src/performance/Optimizer.d.ts +7 -6
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +170 -55
- package/src/profiling/MemoryProfiler.d.ts +1 -1
- package/src/profiling/MemoryProfiler.d.ts.map +1 -1
- package/src/profiling/N1Detector.d.ts +1 -1
- package/src/profiling/N1Detector.d.ts.map +1 -1
- package/src/profiling/QueryLogger.d.ts +1 -1
- package/src/profiling/QueryLogger.d.ts.map +1 -1
- package/src/profiling/RequestProfiler.d.ts +3 -3
- package/src/profiling/RequestProfiler.d.ts.map +1 -1
- package/src/routes/metrics.d.ts +2 -0
- package/src/routes/metrics.d.ts.map +1 -0
- package/src/routes/metrics.js +1 -0
- package/src/routing/CoreRoutes.d.ts +12 -0
- package/src/routing/CoreRoutes.d.ts.map +1 -0
- package/src/routing/CoreRoutes.js +151 -0
- package/src/routing/RouteRegistry.d.ts +39 -0
- package/src/routing/RouteRegistry.d.ts.map +1 -0
- package/src/routing/RouteRegistry.js +44 -0
- package/src/routing/Router.d.ts +26 -9
- package/src/routing/Router.d.ts.map +1 -1
- package/src/routing/Router.js +79 -35
- package/src/routing/common.d.ts +15 -0
- package/src/routing/common.d.ts.map +1 -0
- package/src/routing/common.js +47 -0
- package/src/routing/doc.d.ts +27 -0
- package/src/routing/doc.d.ts.map +1 -0
- package/src/routing/doc.js +110 -0
- package/src/routing/error.d.ts +21 -0
- package/src/routing/error.d.ts.map +1 -0
- package/src/routing/error.js +126 -0
- package/src/routing/errorPages.d.ts +14 -0
- package/src/routing/errorPages.d.ts.map +1 -0
- package/src/routing/errorPages.js +103 -0
- package/src/routing/publicRoot.d.ts +27 -0
- package/src/routing/publicRoot.d.ts.map +1 -0
- package/src/routing/publicRoot.js +110 -0
- package/src/runtime/PluginAutoImports.d.ts +21 -0
- package/src/runtime/PluginAutoImports.d.ts.map +1 -0
- package/src/runtime/PluginAutoImports.js +59 -0
- package/src/runtime/PluginManager.d.ts +1 -5
- package/src/runtime/PluginManager.d.ts.map +1 -1
- package/src/runtime/PluginManager.js +25 -18
- package/src/runtime/RuntimeDetector.d.ts +1 -1
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- package/src/runtime/StartupConfigFileRegistry.d.ts +20 -0
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -0
- package/src/runtime/StartupConfigFileRegistry.js +44 -0
- package/src/runtime/adapters/CloudflareAdapter.d.ts +1 -1
- package/src/runtime/adapters/CloudflareAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/CloudflareAdapter.js +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts +1 -1
- package/src/runtime/adapters/DenoAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/DenoAdapter.js +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts +1 -1
- package/src/runtime/adapters/LambdaAdapter.d.ts.map +1 -1
- package/src/runtime/adapters/LambdaAdapter.js +1 -1
- package/src/runtime/adapters/NodeServerAdapter.d.ts +1 -1
- package/src/runtime/adapters/NodeServerAdapter.d.ts.map +1 -1
- package/src/runtime/getKernel.d.ts +9 -0
- package/src/runtime/getKernel.d.ts.map +1 -0
- package/src/runtime/getKernel.js +27 -0
- package/src/runtime/useFileLoader.d.ts +26 -0
- package/src/runtime/useFileLoader.d.ts.map +1 -0
- package/src/runtime/useFileLoader.js +188 -0
- package/src/scripts/TemplateImportsCheck.js +40 -0
- package/src/scripts/TemplateSync.js +90 -24
- package/src/security/Encryptor.d.ts.map +1 -1
- package/src/security/Encryptor.js +64 -7
- package/src/security/JwtManager.d.ts +1 -0
- package/src/security/JwtManager.d.ts.map +1 -1
- package/src/security/JwtManager.js +33 -0
- package/src/security/Sanitizer.d.ts +76 -0
- package/src/security/Sanitizer.d.ts.map +1 -0
- package/src/security/Sanitizer.js +412 -0
- package/src/security/TokenRevocation.d.ts +7 -0
- package/src/security/TokenRevocation.d.ts.map +1 -0
- package/src/security/TokenRevocation.js +57 -0
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +62 -14
- package/src/seeders/SeederDiscovery.d.ts +5 -0
- package/src/seeders/SeederDiscovery.d.ts.map +1 -0
- package/src/seeders/SeederDiscovery.js +21 -0
- package/src/seeders/SeederLoader.d.ts +5 -0
- package/src/seeders/SeederLoader.d.ts.map +1 -0
- package/src/seeders/SeederLoader.js +60 -0
- package/src/seeders/types.d.ts +18 -0
- package/src/seeders/types.d.ts.map +1 -0
- package/src/seeders/types.js +1 -0
- package/src/session/SessionManager.js +1 -1
- package/src/templates/adapters/MySQLAdapter.ts.tpl +109 -85
- package/src/templates/adapters/PostgreSQLAdapter.ts.tpl +129 -88
- package/src/templates/adapters/SQLServerAdapter.ts.tpl +5 -9
- package/src/templates/adapters/SQLiteAdapter.ts.tpl +78 -11
- package/src/templates/features/Queue.ts.tpl +3 -2
- package/src/templates/project/basic/app/Controllers/AuthController.ts.tpl +217 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +1 -12
- package/src/templates/project/basic/app/Types/controller.ts.tpl +46 -0
- package/src/templates/project/basic/config/FileLogWriter.ts.tpl +5 -236
- package/src/templates/project/basic/config/SecretsManager.ts.tpl +10 -447
- package/src/templates/project/basic/config/StartupConfigValidator.ts.tpl +9 -268
- package/src/templates/project/basic/config/app.ts.tpl +13 -153
- package/src/templates/project/basic/config/broadcast.ts.tpl +29 -126
- package/src/templates/project/basic/config/cache.ts.tpl +12 -70
- package/src/templates/project/basic/config/cloudflare.ts.tpl +4 -39
- package/src/templates/project/basic/config/constants.ts.tpl +9 -65
- package/src/templates/project/basic/config/database.ts.tpl +66 -123
- package/src/templates/project/basic/config/env.ts.tpl +5 -169
- package/src/templates/project/basic/config/features.ts.tpl +6 -54
- package/src/templates/project/basic/config/index.ts.tpl +8 -23
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +7 -114
- package/src/templates/project/basic/config/mail.ts.tpl +9 -62
- package/src/templates/project/basic/config/microservices.ts.tpl +11 -97
- package/src/templates/project/basic/config/middleware.ts.tpl +25 -43
- package/src/templates/project/basic/config/notification.ts.tpl +13 -114
- package/src/templates/project/basic/config/queue.ts.tpl +9 -40
- package/src/templates/project/basic/config/security.ts.tpl +11 -163
- package/src/templates/project/basic/config/startup.ts.tpl +10 -21
- package/src/templates/project/basic/config/storage.ts.tpl +57 -137
- package/src/templates/project/basic/config/type.ts.tpl +32 -451
- package/src/templates/project/basic/database/factories/UserFactory.ts.tpl +80 -0
- package/src/templates/project/basic/database/migrations/create_tasks_table.ts.tpl +28 -0
- package/src/templates/project/basic/database/migrations/create_users_table.ts.tpl +29 -0
- package/src/templates/project/basic/database/seeders/DatabaseSeeder.ts.tpl +19 -0
- package/src/templates/project/basic/database/seeders/UserSeeder.ts.tpl +18 -0
- package/src/templates/project/basic/database/seeders/index.ts.tpl +2 -0
- package/src/templates/project/basic/routes/api.ts.tpl +71 -33
- package/src/templates/project/basic/routes/metrics.ts.tpl +22 -0
- package/src/templates/project/basic/src/index.ts.tpl +3 -0
- package/src/templates/project/basic/tsconfig.json.tpl +12 -11
- package/src/testing/TestEnvironment.d.ts +40 -0
- package/src/testing/TestEnvironment.d.ts.map +1 -0
- package/src/testing/TestEnvironment.js +141 -0
- package/src/testing/TestHttp.d.ts +29 -0
- package/src/testing/TestHttp.d.ts.map +1 -0
- package/src/testing/TestHttp.js +96 -0
- package/src/testing/index.d.ts +5 -0
- package/src/testing/index.d.ts.map +1 -0
- package/src/testing/index.js +2 -0
- package/src/time/DateTime.d.ts +181 -0
- package/src/time/DateTime.d.ts.map +1 -0
- package/src/time/DateTime.js +300 -0
- package/src/time/index.d.ts +7 -0
- package/src/time/index.d.ts.map +1 -0
- package/src/time/index.js +5 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +4 -0
- package/src/tools/mail/drivers/Smtp.js +1 -1
- package/src/tools/queue/drivers/InMemory.d.ts +1 -1
- package/src/tools/queue/drivers/InMemory.d.ts.map +1 -1
- package/src/tools/queue/drivers/InMemory.js +1 -1
- package/src/tools/queue/drivers/Redis.d.ts +1 -1
- package/src/tools/queue/drivers/Redis.d.ts.map +1 -1
- package/src/tools/queue/drivers/Redis.js +1 -1
- package/src/validation/ValidationError.d.ts.map +1 -1
- package/src/validation/ValidationError.js +4 -2
- package/src/validation/Validator.d.ts +49 -16
- package/src/validation/Validator.d.ts.map +1 -1
- package/src/validation/Validator.js +307 -5
- package/src/common/uuid.d.ts +0 -3
- package/src/common/uuid.d.ts.map +0 -1
- package/src/common/uuid.js +0 -30
- package/src/templates/project/basic/.env.example.tpl +0 -74
- package/src/templates/project/basic/.env.tpl +0 -166
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +0 -181
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +0 -156
- package/src/templates/project/basic/database/migrations/index.ts.tpl +0 -2
package/src/config/cache.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Caching drivers and settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
6
7
|
import { Env } from './env.js';
|
|
7
8
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
8
9
|
const getCacheDriver = (config, name) => {
|
|
@@ -22,22 +23,16 @@ const getCacheDriver = (config, name) => {
|
|
|
22
23
|
}
|
|
23
24
|
throw ErrorFactory.createConfigError(`Cache default store not configured: ${storeName || '<empty>'}`);
|
|
24
25
|
};
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
* Default cache driver
|
|
28
|
-
*/
|
|
29
|
-
default: (() => {
|
|
26
|
+
const createCacheConfig = () => {
|
|
27
|
+
const baseDefault = (() => {
|
|
30
28
|
const envConnection = Env.get('CACHE_CONNECTION', '').trim();
|
|
31
29
|
const envDriver = typeof Env.CACHE_DRIVER === 'string'
|
|
32
30
|
? String(Env.CACHE_DRIVER)
|
|
33
31
|
: Env.get('CACHE_DRIVER', 'memory');
|
|
34
32
|
const selected = envConnection.length > 0 ? envConnection : String(envDriver ?? 'memory');
|
|
35
33
|
return selected.trim().toLowerCase();
|
|
36
|
-
})()
|
|
37
|
-
|
|
38
|
-
* Cache drivers
|
|
39
|
-
*/
|
|
40
|
-
drivers: {
|
|
34
|
+
})();
|
|
35
|
+
const baseDrivers = {
|
|
41
36
|
memory: {
|
|
42
37
|
driver: 'memory',
|
|
43
38
|
ttl: Env.getInt('CACHE_MEMORY_TTL', 3600),
|
|
@@ -62,20 +57,69 @@ const cacheConfigObj = {
|
|
|
62
57
|
driver: 'kv-remote',
|
|
63
58
|
ttl: Env.getInt('CACHE_KV_TTL', 3600),
|
|
64
59
|
},
|
|
60
|
+
};
|
|
61
|
+
const overrides = StartupConfigFileRegistry.get(StartupConfigFile.Cache) ?? {};
|
|
62
|
+
const mergedDrivers = {
|
|
63
|
+
...baseDrivers,
|
|
64
|
+
...(overrides.drivers ?? {}),
|
|
65
|
+
};
|
|
66
|
+
const mergedDefault = typeof overrides.default === 'string' && overrides.default.trim() !== ''
|
|
67
|
+
? overrides.default.trim().toLowerCase()
|
|
68
|
+
: baseDefault;
|
|
69
|
+
const mergedKeyPrefix = typeof overrides.keyPrefix === 'string' && overrides.keyPrefix.length > 0
|
|
70
|
+
? overrides.keyPrefix
|
|
71
|
+
: Env.get('CACHE_KEY_PREFIX', 'zintrust:');
|
|
72
|
+
const mergedTtl = typeof overrides.ttl === 'number' && Number.isFinite(overrides.ttl) ? overrides.ttl : 3600;
|
|
73
|
+
const cacheConfigObj = {
|
|
74
|
+
/**
|
|
75
|
+
* Default cache driver
|
|
76
|
+
*/
|
|
77
|
+
default: mergedDefault,
|
|
78
|
+
/**
|
|
79
|
+
* Cache drivers
|
|
80
|
+
*/
|
|
81
|
+
drivers: mergedDrivers,
|
|
82
|
+
/**
|
|
83
|
+
* Get cache driver config
|
|
84
|
+
*/
|
|
85
|
+
getDriver(name) {
|
|
86
|
+
return getCacheDriver(this, name);
|
|
87
|
+
},
|
|
88
|
+
/**
|
|
89
|
+
* Key prefix for all cache keys
|
|
90
|
+
*/
|
|
91
|
+
keyPrefix: mergedKeyPrefix,
|
|
92
|
+
/**
|
|
93
|
+
* Default cache TTL (seconds)
|
|
94
|
+
*/
|
|
95
|
+
ttl: mergedTtl,
|
|
96
|
+
};
|
|
97
|
+
return Object.freeze(cacheConfigObj);
|
|
98
|
+
};
|
|
99
|
+
let cached = null;
|
|
100
|
+
const proxyTarget = {};
|
|
101
|
+
const ensureCacheConfig = () => {
|
|
102
|
+
if (cached)
|
|
103
|
+
return cached;
|
|
104
|
+
cached = createCacheConfig();
|
|
105
|
+
try {
|
|
106
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(cached));
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// best-effort
|
|
110
|
+
}
|
|
111
|
+
return cached;
|
|
112
|
+
};
|
|
113
|
+
export const cacheConfig = new Proxy(proxyTarget, {
|
|
114
|
+
get(_target, prop) {
|
|
115
|
+
return ensureCacheConfig()[prop];
|
|
65
116
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getDriver(name) {
|
|
70
|
-
return getCacheDriver(this, name);
|
|
117
|
+
ownKeys() {
|
|
118
|
+
ensureCacheConfig();
|
|
119
|
+
return Reflect.ownKeys(proxyTarget);
|
|
71
120
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
* Default cache TTL (seconds)
|
|
78
|
-
*/
|
|
79
|
-
ttl: Env.getInt('CACHE_DEFAULT_TTL', 3600),
|
|
80
|
-
};
|
|
81
|
-
export const cacheConfig = Object.freeze(cacheConfigObj);
|
|
121
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
122
|
+
ensureCacheConfig();
|
|
123
|
+
return Object.getOwnPropertyDescriptor(proxyTarget, prop);
|
|
124
|
+
},
|
|
125
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralizes access to Workers bindings via globalThis.env.
|
|
5
5
|
* This keeps runtime-specific globals out of adapters/drivers.
|
|
6
6
|
*/
|
|
7
|
-
import { KVNamespace, WorkersEnv } from './type';
|
|
7
|
+
import type { KVNamespace, WorkersEnv } from './type';
|
|
8
8
|
import type { DatabaseConfig, ID1Database } from '../orm/DatabaseAdapter';
|
|
9
9
|
export declare const Cloudflare: Readonly<{
|
|
10
10
|
getWorkersEnv: () => WorkersEnv | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/config/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../../src/config/cloudflare.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA8BxE,eAAO,MAAM,UAAU;yBA5BG,UAAU,GAAG,IAAI;2BAOb,cAAc,KAAG,WAAW,GAAG,IAAI;4CAanB,WAAW,GAAG,IAAI;EAY9D,CAAC"}
|
package/src/config/database.d.ts
CHANGED
|
@@ -3,81 +3,39 @@
|
|
|
3
3
|
* Database connections and pooling settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
import { DatabaseConfigShape, DatabaseConnectionConfig } from './type';
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Default database connection
|
|
10
|
-
*/
|
|
6
|
+
import type { DatabaseConfigShape, DatabaseConnectionConfig, DatabaseConnections } from './type';
|
|
7
|
+
export type DatabaseConfigOverrides = Partial<{
|
|
11
8
|
default: string;
|
|
12
|
-
|
|
13
|
-
* Database connections
|
|
14
|
-
*/
|
|
15
|
-
connections: {
|
|
16
|
-
sqlite: {
|
|
17
|
-
driver: "sqlite";
|
|
18
|
-
database: string;
|
|
19
|
-
migrations: string;
|
|
20
|
-
};
|
|
21
|
-
d1: {
|
|
22
|
-
driver: "d1";
|
|
23
|
-
};
|
|
24
|
-
'd1-remote': {
|
|
25
|
-
driver: "d1-remote";
|
|
26
|
-
};
|
|
27
|
-
postgresql: {
|
|
28
|
-
driver: "postgresql";
|
|
29
|
-
host: string;
|
|
30
|
-
port: number;
|
|
31
|
-
database: string;
|
|
32
|
-
username: string;
|
|
33
|
-
password: string;
|
|
34
|
-
ssl: boolean;
|
|
35
|
-
pooling: {
|
|
36
|
-
enabled: boolean;
|
|
37
|
-
min: number;
|
|
38
|
-
max: number;
|
|
39
|
-
idleTimeout: number;
|
|
40
|
-
connectionTimeout: number;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
mysql: {
|
|
44
|
-
driver: "mysql";
|
|
45
|
-
host: string;
|
|
46
|
-
port: number;
|
|
47
|
-
database: string;
|
|
48
|
-
username: string;
|
|
49
|
-
password: string;
|
|
50
|
-
pooling: {
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
min: number;
|
|
53
|
-
max: number;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Get current connection config
|
|
59
|
-
*/
|
|
60
|
-
getConnection(this: DatabaseConfigShape): DatabaseConnectionConfig;
|
|
61
|
-
/**
|
|
62
|
-
* Enable query logging
|
|
63
|
-
*/
|
|
9
|
+
connections: DatabaseConnections;
|
|
64
10
|
logging: {
|
|
65
11
|
enabled: boolean;
|
|
66
12
|
level: string;
|
|
67
13
|
};
|
|
68
|
-
/**
|
|
69
|
-
* Migration settings
|
|
70
|
-
*/
|
|
71
14
|
migrations: {
|
|
72
15
|
directory: string;
|
|
73
16
|
extension: string;
|
|
74
17
|
};
|
|
75
|
-
/**
|
|
76
|
-
* Seeding settings
|
|
77
|
-
*/
|
|
78
18
|
seeders: {
|
|
79
19
|
directory: string;
|
|
80
20
|
};
|
|
81
21
|
}>;
|
|
82
|
-
|
|
22
|
+
declare const createDatabaseConfig: () => {
|
|
23
|
+
default: string;
|
|
24
|
+
connections: DatabaseConnections;
|
|
25
|
+
getConnection: (this: DatabaseConfigShape) => DatabaseConnectionConfig;
|
|
26
|
+
logging: {
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
level: string;
|
|
29
|
+
};
|
|
30
|
+
migrations: {
|
|
31
|
+
directory: string;
|
|
32
|
+
extension: string;
|
|
33
|
+
};
|
|
34
|
+
seeders: {
|
|
35
|
+
directory: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type DatabaseConfig = ReturnType<typeof createDatabaseConfig>;
|
|
39
|
+
export declare const databaseConfig: DatabaseConfig;
|
|
40
|
+
export {};
|
|
83
41
|
//# sourceMappingURL=database.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/config/database.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../src/config/database.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,mBAAmB,CAAC;IACjC,OAAO,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC,CAAC,CAAC;AA0LH,QAAA,MAAM,oBAAoB,QAAO;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,mBAAmB,CAAC;IACjC,aAAa,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,wBAAwB,CAAC;IACvE,OAAO,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAyEhC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAqBrE,eAAO,MAAM,cAAc,EAAE,cAY3B,CAAC"}
|
package/src/config/database.js
CHANGED
|
@@ -3,11 +3,105 @@
|
|
|
3
3
|
* Database connections and pooling settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
6
7
|
import { Env } from './env.js';
|
|
7
8
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
9
|
+
const isNodeProcess = () => {
|
|
10
|
+
return typeof process !== 'undefined' && typeof process.cwd === 'function';
|
|
11
|
+
};
|
|
12
|
+
const isExplicitEnvValue = (key) => {
|
|
13
|
+
if (!isNodeProcess())
|
|
14
|
+
return false;
|
|
15
|
+
const raw = process.env[key];
|
|
16
|
+
return typeof raw === 'string' && raw.trim() !== '';
|
|
17
|
+
};
|
|
18
|
+
const looksLikeSqliteFilePath = (value) => {
|
|
19
|
+
const v = value.trim();
|
|
20
|
+
if (v === '')
|
|
21
|
+
return false;
|
|
22
|
+
if (v === ':memory:')
|
|
23
|
+
return true;
|
|
24
|
+
// Heuristic: if it's a path, has an extension, or is explicitly relative.
|
|
25
|
+
if (v.includes('/') || v.includes('\\'))
|
|
26
|
+
return true;
|
|
27
|
+
if (v.startsWith('.'))
|
|
28
|
+
return true;
|
|
29
|
+
if (v.startsWith('~'))
|
|
30
|
+
return true;
|
|
31
|
+
if (v.endsWith('.sqlite') || v.endsWith('.db'))
|
|
32
|
+
return true;
|
|
33
|
+
// Otherwise it's likely a placeholder name (e.g. "zintrust"), not a file path.
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
const toSafeDbBasename = (raw) => {
|
|
37
|
+
const trimmed = raw.trim();
|
|
38
|
+
if (trimmed === '')
|
|
39
|
+
return 'zintrust';
|
|
40
|
+
// Conservative filename allowlist: letters/numbers/_/-, collapse everything else.
|
|
41
|
+
// Avoid regexes that can exhibit catastrophic backtracking; do deterministic collapsing/trimming.
|
|
42
|
+
const collapsed = trimmed.toLowerCase().replaceAll(/[^a-z0-9_-]+/g, '-');
|
|
43
|
+
// Collapse consecutive hyphens deterministically without regex backtracking.
|
|
44
|
+
let normalized = '';
|
|
45
|
+
let prevHyphen = false;
|
|
46
|
+
for (const element of collapsed) {
|
|
47
|
+
const ch = element;
|
|
48
|
+
if (ch === '-') {
|
|
49
|
+
if (!prevHyphen) {
|
|
50
|
+
normalized += ch;
|
|
51
|
+
prevHyphen = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
normalized += ch;
|
|
56
|
+
prevHyphen = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Trim leading/trailing hyphens deterministically without regex.
|
|
60
|
+
let start = 0;
|
|
61
|
+
let end = normalized.length;
|
|
62
|
+
while (start < end && normalized.charAt(start) === '-')
|
|
63
|
+
start++;
|
|
64
|
+
while (end > start && normalized.charAt(end - 1) === '-')
|
|
65
|
+
end--;
|
|
66
|
+
const result = normalized.slice(start, end);
|
|
67
|
+
return result === '' ? 'zintrust' : result;
|
|
68
|
+
};
|
|
69
|
+
const resolveSqliteDefaultBasename = () => {
|
|
70
|
+
const service = typeof process.env['SERVICE_NAME'] === 'string' ? process.env['SERVICE_NAME'] : '';
|
|
71
|
+
if (service.trim() !== '')
|
|
72
|
+
return toSafeDbBasename(service);
|
|
73
|
+
const app = typeof process.env['APP_NAME'] === 'string' ? process.env['APP_NAME'] : '';
|
|
74
|
+
if (app.trim() !== '')
|
|
75
|
+
return toSafeDbBasename(app);
|
|
76
|
+
return 'zintrust';
|
|
77
|
+
};
|
|
78
|
+
const resolveDefaultSqliteDatabasePath = () => {
|
|
79
|
+
// Respect explicit sqlite *file path* configuration.
|
|
80
|
+
// Note: we intentionally treat plain names like "zintrust" as placeholders, not file paths,
|
|
81
|
+
// to avoid creating stray DB files in the project root.
|
|
82
|
+
if (isExplicitEnvValue('DB_DATABASE') || isExplicitEnvValue('DB_PATH')) {
|
|
83
|
+
const configured = Env.DB_DATABASE;
|
|
84
|
+
if (looksLikeSqliteFilePath(configured))
|
|
85
|
+
return configured;
|
|
86
|
+
}
|
|
87
|
+
// Only change the default behavior for dev/testing; production should be explicit.
|
|
88
|
+
if (!isNodeProcess() || Env.NODE_ENV === 'production')
|
|
89
|
+
return Env.DB_DATABASE;
|
|
90
|
+
// Store dev sqlite files in project-local metadata folder.
|
|
91
|
+
// Note: the SQLite adapter ensures the parent directory exists.
|
|
92
|
+
const base = resolveSqliteDefaultBasename();
|
|
93
|
+
return `.zintrust/dbs/${base}.sqlite`;
|
|
94
|
+
};
|
|
8
95
|
const hasOwn = (obj, key) => {
|
|
9
96
|
return Object.hasOwn(obj, key);
|
|
10
97
|
};
|
|
98
|
+
const parseReadHosts = (raw) => {
|
|
99
|
+
const list = String(raw ?? '')
|
|
100
|
+
.split(',')
|
|
101
|
+
.map((v) => v.trim())
|
|
102
|
+
.filter((v) => v.length > 0);
|
|
103
|
+
return list.length > 0 ? list : undefined;
|
|
104
|
+
};
|
|
11
105
|
const getDefaultConnection = (connections) => {
|
|
12
106
|
const envSelectedRaw = Env.get('DB_CONNECTION', '');
|
|
13
107
|
const value = String(envSelectedRaw ?? '').trim();
|
|
@@ -35,7 +129,7 @@ const getDatabaseConnection = (config) => {
|
|
|
35
129
|
const connections = {
|
|
36
130
|
sqlite: {
|
|
37
131
|
driver: 'sqlite',
|
|
38
|
-
database:
|
|
132
|
+
database: resolveDefaultSqliteDatabasePath(),
|
|
39
133
|
migrations: 'database/migrations',
|
|
40
134
|
},
|
|
41
135
|
d1: {
|
|
@@ -47,11 +141,12 @@ const connections = {
|
|
|
47
141
|
postgresql: {
|
|
48
142
|
driver: 'postgresql',
|
|
49
143
|
host: Env.DB_HOST,
|
|
50
|
-
port: Env.
|
|
51
|
-
database: Env.
|
|
52
|
-
username: Env.
|
|
53
|
-
password: Env.
|
|
144
|
+
port: Env.DB_PORT_POSTGRESQL,
|
|
145
|
+
database: Env.DB_DATABASE_POSTGRESQL,
|
|
146
|
+
username: Env.DB_USERNAME_POSTGRESQL,
|
|
147
|
+
password: Env.DB_PASSWORD_POSTGRESQL,
|
|
54
148
|
ssl: Env.getBool('DB_SSL', false),
|
|
149
|
+
readHosts: parseReadHosts(Env.DB_READ_HOSTS_POSTGRESQL),
|
|
55
150
|
pooling: {
|
|
56
151
|
enabled: Env.getBool('DB_POOLING', true),
|
|
57
152
|
min: Env.getInt('DB_POOL_MIN', 5),
|
|
@@ -67,47 +162,106 @@ const connections = {
|
|
|
67
162
|
database: Env.DB_DATABASE,
|
|
68
163
|
username: Env.DB_USERNAME,
|
|
69
164
|
password: Env.DB_PASSWORD,
|
|
165
|
+
readHosts: parseReadHosts(Env.DB_READ_HOSTS),
|
|
70
166
|
pooling: {
|
|
71
167
|
enabled: Env.getBool('DB_POOLING', true),
|
|
72
168
|
min: Env.getInt('DB_POOL_MIN', 5),
|
|
73
169
|
max: Env.getInt('DB_POOL_MAX', 20),
|
|
74
170
|
},
|
|
75
171
|
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*/
|
|
85
|
-
connections,
|
|
86
|
-
/**
|
|
87
|
-
* Get current connection config
|
|
88
|
-
*/
|
|
89
|
-
getConnection() {
|
|
90
|
-
return getDatabaseConnection(this);
|
|
172
|
+
sqlserver: {
|
|
173
|
+
driver: 'sqlserver',
|
|
174
|
+
host: Env.DB_HOST_MSSQL,
|
|
175
|
+
port: Env.DB_PORT_MSSQL,
|
|
176
|
+
database: Env.DB_DATABASE_MSSQL,
|
|
177
|
+
username: Env.DB_USERNAME_MSSQL,
|
|
178
|
+
password: Env.DB_PASSWORD_MSSQL,
|
|
179
|
+
readHosts: parseReadHosts(Env.DB_READ_HOSTS_MSSQL),
|
|
91
180
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
181
|
+
};
|
|
182
|
+
const createDatabaseConfig = () => {
|
|
183
|
+
const overrides = StartupConfigFileRegistry.get(StartupConfigFile.Database) ?? {};
|
|
184
|
+
const mergedConnections = {
|
|
185
|
+
...connections,
|
|
186
|
+
...overrides.connections,
|
|
187
|
+
};
|
|
188
|
+
const baseLogging = {
|
|
189
|
+
enabled: Env.getBool('DB_LOG_QUERIES', Env.DEBUG),
|
|
97
190
|
level: Env.get('DB_LOG_LEVEL', 'debug'),
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
* Migration settings
|
|
101
|
-
*/
|
|
102
|
-
migrations: {
|
|
191
|
+
};
|
|
192
|
+
const baseMigrations = {
|
|
103
193
|
directory: 'database/migrations',
|
|
104
194
|
extension: Env.get('DB_MIGRATION_EXT', '.ts'),
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
* Seeding settings
|
|
108
|
-
*/
|
|
109
|
-
seeders: {
|
|
195
|
+
};
|
|
196
|
+
const baseSeeders = {
|
|
110
197
|
directory: 'database/seeders',
|
|
111
|
-
}
|
|
198
|
+
};
|
|
199
|
+
const mergedDefault = typeof overrides.default === 'string' && overrides.default.trim() !== ''
|
|
200
|
+
? overrides.default.trim()
|
|
201
|
+
: getDefaultConnection(mergedConnections);
|
|
202
|
+
const databaseConfigObj = {
|
|
203
|
+
/**
|
|
204
|
+
* Default database connection
|
|
205
|
+
*/
|
|
206
|
+
default: mergedDefault,
|
|
207
|
+
/**
|
|
208
|
+
* Database connections
|
|
209
|
+
*/
|
|
210
|
+
connections: mergedConnections,
|
|
211
|
+
/**
|
|
212
|
+
* Get current connection config
|
|
213
|
+
*/
|
|
214
|
+
getConnection() {
|
|
215
|
+
return getDatabaseConnection(this);
|
|
216
|
+
},
|
|
217
|
+
/**
|
|
218
|
+
* Enable query logging
|
|
219
|
+
*/
|
|
220
|
+
logging: {
|
|
221
|
+
...baseLogging,
|
|
222
|
+
...overrides.logging,
|
|
223
|
+
},
|
|
224
|
+
/**
|
|
225
|
+
* Migration settings
|
|
226
|
+
*/
|
|
227
|
+
migrations: {
|
|
228
|
+
...baseMigrations,
|
|
229
|
+
...overrides.migrations,
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* Seeding settings
|
|
233
|
+
*/
|
|
234
|
+
seeders: {
|
|
235
|
+
...baseSeeders,
|
|
236
|
+
...overrides.seeders,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
return Object.freeze(databaseConfigObj);
|
|
240
|
+
};
|
|
241
|
+
let cached = null;
|
|
242
|
+
const proxyTarget = {};
|
|
243
|
+
const ensureDatabaseConfig = () => {
|
|
244
|
+
if (cached)
|
|
245
|
+
return cached;
|
|
246
|
+
cached = createDatabaseConfig();
|
|
247
|
+
try {
|
|
248
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(cached));
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// best-effort
|
|
252
|
+
}
|
|
253
|
+
return cached;
|
|
112
254
|
};
|
|
113
|
-
export const databaseConfig =
|
|
255
|
+
export const databaseConfig = new Proxy(proxyTarget, {
|
|
256
|
+
get(_target, prop) {
|
|
257
|
+
return ensureDatabaseConfig()[prop];
|
|
258
|
+
},
|
|
259
|
+
ownKeys() {
|
|
260
|
+
ensureDatabaseConfig();
|
|
261
|
+
return Reflect.ownKeys(proxyTarget);
|
|
262
|
+
},
|
|
263
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
264
|
+
ensureDatabaseConfig();
|
|
265
|
+
return Object.getOwnPropertyDescriptor(proxyTarget, prop);
|
|
266
|
+
},
|
|
267
|
+
});
|
package/src/config/env.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const Env: Readonly<{
|
|
|
12
12
|
NODE_ENV: string;
|
|
13
13
|
PORT: number;
|
|
14
14
|
HOST: string;
|
|
15
|
+
BASE_URL: string;
|
|
15
16
|
APP_NAME: string;
|
|
16
17
|
APP_KEY: string;
|
|
17
18
|
APP_PREVIOUS_KEYS: string;
|
|
@@ -22,6 +23,17 @@ export declare const Env: Readonly<{
|
|
|
22
23
|
DB_USERNAME: string;
|
|
23
24
|
DB_PASSWORD: string;
|
|
24
25
|
DB_READ_HOSTS: string;
|
|
26
|
+
DB_PORT_POSTGRESQL: number;
|
|
27
|
+
DB_DATABASE_POSTGRESQL: string;
|
|
28
|
+
DB_USERNAME_POSTGRESQL: string;
|
|
29
|
+
DB_PASSWORD_POSTGRESQL: string;
|
|
30
|
+
DB_READ_HOSTS_POSTGRESQL: string;
|
|
31
|
+
DB_HOST_MSSQL: string;
|
|
32
|
+
DB_PORT_MSSQL: number;
|
|
33
|
+
DB_DATABASE_MSSQL: string;
|
|
34
|
+
DB_USERNAME_MSSQL: string;
|
|
35
|
+
DB_PASSWORD_MSSQL: string;
|
|
36
|
+
DB_READ_HOSTS_MSSQL: string;
|
|
25
37
|
D1_DATABASE_ID: string;
|
|
26
38
|
KV_NAMESPACE_ID: string;
|
|
27
39
|
D1_REMOTE_URL: string;
|
package/src/config/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+CH,eAAO,MAAM,GAAG;eA/BE,MAAM,iBAAiB,MAAM,KAAG,MAAM;kBAMnC,MAAM,iBAAiB,MAAM,KAAG,MAAM;mBASrC,MAAM,iBAAiB,OAAO,KAAG,OAAO
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+CH,eAAO,MAAM,GAAG;eA/BE,MAAM,iBAAiB,MAAM,KAAG,MAAM;kBAMnC,MAAM,iBAAiB,MAAM,KAAG,MAAM;mBASrC,MAAM,iBAAiB,OAAO,KAAG,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAoHP,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;;;;;;;;;EAkCxF,CAAC"}
|
package/src/config/env.js
CHANGED
|
@@ -58,6 +58,7 @@ export const Env = Object.freeze({
|
|
|
58
58
|
// Prefer PORT, fallback to APP_PORT for compatibility
|
|
59
59
|
PORT: getInt('PORT', getInt('APP_PORT', 3000)),
|
|
60
60
|
HOST: get('HOST', 'localhost'),
|
|
61
|
+
BASE_URL: get('BASE_URL', ''),
|
|
61
62
|
APP_NAME: get('APP_NAME', 'ZinTrust'),
|
|
62
63
|
APP_KEY: get('APP_KEY', ''),
|
|
63
64
|
// Optional key rotation support (comma-separated or JSON array of keys)
|
|
@@ -71,6 +72,19 @@ export const Env = Object.freeze({
|
|
|
71
72
|
DB_USERNAME: get('DB_USERNAME', 'postgres'),
|
|
72
73
|
DB_PASSWORD: get('DB_PASSWORD', ''),
|
|
73
74
|
DB_READ_HOSTS: get('DB_READ_HOSTS', ''),
|
|
75
|
+
// PostgreSQL-specific configuration (with _POSTGRESQL suffix to avoid conflicts with MySQL)
|
|
76
|
+
DB_PORT_POSTGRESQL: getInt('DB_PORT_POSTGRESQL', 5432),
|
|
77
|
+
DB_DATABASE_POSTGRESQL: get('DB_DATABASE_POSTGRESQL', 'postgres'),
|
|
78
|
+
DB_USERNAME_POSTGRESQL: get('DB_USERNAME_POSTGRESQL', 'postgres'),
|
|
79
|
+
DB_PASSWORD_POSTGRESQL: get('DB_PASSWORD_POSTGRESQL', ''),
|
|
80
|
+
DB_READ_HOSTS_POSTGRESQL: get('DB_READ_HOSTS_POSTGRESQL', ''),
|
|
81
|
+
// SQL Server (MSSQL) specific configuration
|
|
82
|
+
DB_HOST_MSSQL: get('DB_HOST_MSSQL', get('DB_HOST', 'localhost')),
|
|
83
|
+
DB_PORT_MSSQL: getInt('DB_PORT_MSSQL', 1433),
|
|
84
|
+
DB_DATABASE_MSSQL: get('DB_DATABASE_MSSQL', 'zintrust'),
|
|
85
|
+
DB_USERNAME_MSSQL: get('DB_USERNAME_MSSQL', 'sa'),
|
|
86
|
+
DB_PASSWORD_MSSQL: get('DB_PASSWORD_MSSQL', ''),
|
|
87
|
+
DB_READ_HOSTS_MSSQL: get('DB_READ_HOSTS_MSSQL', ''),
|
|
74
88
|
// Cloudflare
|
|
75
89
|
D1_DATABASE_ID: get('D1_DATABASE_ID'),
|
|
76
90
|
KV_NAMESPACE_ID: get('KV_NAMESPACE_ID'),
|