@zintrust/core 0.1.18 → 0.1.20
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 +16 -10
- package/bin/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +9 -0
- package/package.json +11 -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/index.html +1 -1
- package/public/zintrust.svg +30 -0
- package/routes/api.d.ts +7 -0
- package/routes/api.d.ts.map +1 -0
- package/routes/api.js +115 -0
- package/routes/broadcast.d.ts +9 -0
- package/routes/broadcast.d.ts.map +1 -0
- package/routes/broadcast.js +27 -0
- package/routes/health.d.ts +7 -0
- package/routes/health.d.ts.map +1 -0
- package/routes/health.js +127 -0
- 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/routes/storage.d.ts +4 -0
- package/routes/storage.d.ts.map +1 -0
- package/routes/storage.js +35 -0
- package/src/boot/Application.d.ts +2 -2
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +18 -3
- 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 +1 -1
- 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 +12 -4
- package/src/cli/PromptHelper.d.ts.map +1 -1
- package/src/cli/PromptHelper.js +4 -3
- 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 +291 -35
- package/src/cli/commands/NewCommand.d.ts +2 -2
- package/src/cli/commands/NewCommand.d.ts.map +1 -1
- package/src/cli/commands/NewCommand.js +38 -13
- 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/SimulateCommand.js +1 -1
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +90 -3
- package/src/cli/commands/UpgradeCommand.d.ts +16 -0
- package/src/cli/commands/UpgradeCommand.d.ts.map +1 -0
- package/src/cli/commands/UpgradeCommand.js +107 -0
- 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/commands/runner/index.d.ts +3 -0
- package/src/cli/commands/runner/index.d.ts.map +1 -0
- package/src/cli/commands/runner/index.js +139 -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 +224 -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/env/EnvFileBackfill.d.ts +10 -0
- package/src/cli/env/EnvFileBackfill.d.ts.map +1 -0
- package/src/cli/env/EnvFileBackfill.js +64 -0
- package/src/cli/scaffolding/ControllerGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ControllerGenerator.js +72 -22
- 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/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +54 -59
- 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 +24 -3
- 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/cli/utils/DistPackager.d.ts.map +1 -1
- package/src/cli/utils/DistPackager.js +8 -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 +1 -1
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +1 -1
- package/src/config/cache.d.ts +1 -1
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cloudflare.d.ts +1 -1
- package/src/config/cloudflare.d.ts.map +1 -1
- package/src/config/database.d.ts +7 -1
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +99 -7
- package/src/config/env.d.ts +6 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +7 -0
- package/src/config/index.d.ts +8 -2
- 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/middleware.d.ts +22 -2
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +179 -11
- package/src/config/notification.js +1 -1
- package/src/config/security.d.ts +1 -1
- package/src/config/security.js +1 -1
- package/src/config/storage.js +1 -1
- package/src/config/type.d.ts +8 -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 +129 -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 +65 -7
- package/src/index.d.ts.map +1 -1
- package/src/index.js +59 -5
- 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/RateLimiter.js +26 -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 +323 -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 +2 -0
- package/src/node.d.ts.map +1 -1
- package/src/node.js +7 -0
- 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 +4 -2
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +142 -29
- package/src/orm/DatabaseAdapter.d.ts +13 -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 +4 -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 +405 -95
- 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 +63 -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 +1 -0
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +37 -3
- 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/api.d.ts +2 -0
- package/src/routes/api.d.ts.map +1 -0
- package/src/routes/api.js +1 -0
- package/src/routes/broadcast.d.ts +2 -0
- package/src/routes/broadcast.d.ts.map +1 -0
- package/src/routes/broadcast.js +1 -0
- package/src/routes/health.d.ts +2 -0
- package/src/routes/health.d.ts.map +1 -0
- package/src/routes/health.js +1 -0
- 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/routes/storage.d.ts +2 -0
- package/src/routes/storage.d.ts.map +1 -0
- package/src/routes/storage.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 +28 -0
- package/src/routing/doc.d.ts.map +1 -0
- package/src/routing/doc.js +95 -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 +18 -0
- package/src/routing/publicRoot.d.ts.map +1 -0
- package/src/routing/publicRoot.js +49 -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/RuntimeAdapter.d.ts.map +1 -1
- package/src/runtime/RuntimeAdapter.js +20 -1
- package/src/runtime/RuntimeDetector.d.ts +1 -1
- package/src/runtime/RuntimeDetector.d.ts.map +1 -1
- 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 +3 -3
- 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/scripts/TemplateImportsCheck.js +47 -7
- package/src/scripts/TemplateSync.js +92 -20
- 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/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/start.d.ts +21 -0
- package/src/start.d.ts.map +1 -0
- package/src/start.js +60 -0
- 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 +2 -2
- package/src/templates/project/basic/app/Controllers/AuthController.ts.tpl +217 -0
- package/src/templates/project/basic/app/Controllers/UserController.ts.tpl +3 -16
- package/src/templates/project/basic/app/Middleware/ProfilerMiddleware.ts.tpl +1 -3
- package/src/templates/project/basic/app/Middleware/index.ts.tpl +3 -8
- package/src/templates/project/basic/app/Models/Post.ts.tpl +2 -3
- package/src/templates/project/basic/app/Models/User.ts.tpl +1 -1
- 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 +13 -450
- 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 +15 -129
- package/src/templates/project/basic/config/cache.ts.tpl +15 -92
- 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 +29 -116
- 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 +27 -24
- package/src/templates/project/basic/config/logger.ts.tpl +5 -381
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +1 -1
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +2 -2
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +1 -1
- package/src/templates/project/basic/config/mail.ts.tpl +15 -115
- package/src/templates/project/basic/config/microservices.ts.tpl +11 -97
- package/src/templates/project/basic/config/middleware.ts.tpl +27 -18
- package/src/templates/project/basic/config/notification.ts.tpl +14 -127
- package/src/templates/project/basic/config/queue.ts.tpl +16 -79
- 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 +15 -133
- package/src/templates/project/basic/config/type.ts.tpl +33 -441
- 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/package.json.tpl +1 -1
- package/src/templates/project/basic/routes/api.ts.tpl +74 -36
- package/src/templates/project/basic/routes/health.ts.tpl +1 -6
- package/src/templates/project/basic/routes/metrics.ts.tpl +22 -0
- package/src/templates/project/basic/src/index.ts.tpl +7 -80
- package/src/templates/project/basic/tsconfig.json.tpl +12 -13
- 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/database/migrations/index.ts.tpl +0 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export const DENO_RUNNER_SOURCE = [
|
|
2
|
+
"import http from 'node:http';",
|
|
3
|
+
"import { deno } from '@zintrust/core/start';",
|
|
4
|
+
'',
|
|
5
|
+
"const port = Number.parseInt(process.env.PORT ?? '3000', 10) || 3000;",
|
|
6
|
+
"const host = process.env.HOST ?? 'localhost';",
|
|
7
|
+
'',
|
|
8
|
+
'const readBody = async (req: http.IncomingMessage): Promise<Buffer | undefined> => {',
|
|
9
|
+
" if (req.method === 'GET' || req.method === 'HEAD') return undefined;",
|
|
10
|
+
' const chunks: Buffer[] = [];',
|
|
11
|
+
' for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));',
|
|
12
|
+
' return chunks.length > 0 ? Buffer.concat(chunks) : undefined;',
|
|
13
|
+
'};',
|
|
14
|
+
'',
|
|
15
|
+
'const server = http.createServer(async (req, res) => {',
|
|
16
|
+
' try {',
|
|
17
|
+
" const proto = (req.headers['x-forwarded-proto'] ?? 'http').toString();",
|
|
18
|
+
' const authority = (req.headers.host ?? host).toString();',
|
|
19
|
+
" const url = new URL(req.url ?? '/', proto + '://' + authority);",
|
|
20
|
+
'',
|
|
21
|
+
' const headers = new Headers();',
|
|
22
|
+
' for (const [key, value] of Object.entries(req.headers)) {',
|
|
23
|
+
' if (value === undefined) continue;',
|
|
24
|
+
' if (Array.isArray(value)) {',
|
|
25
|
+
' for (const v of value) headers.append(key, v);',
|
|
26
|
+
' } else {',
|
|
27
|
+
' headers.set(key, String(value));',
|
|
28
|
+
' }',
|
|
29
|
+
' }',
|
|
30
|
+
'',
|
|
31
|
+
' const body = await readBody(req);',
|
|
32
|
+
' const request = new Request(url.toString(), {',
|
|
33
|
+
" method: req.method ?? 'GET',",
|
|
34
|
+
' headers,',
|
|
35
|
+
' body,',
|
|
36
|
+
' });',
|
|
37
|
+
'',
|
|
38
|
+
' const response = await deno(request);',
|
|
39
|
+
'',
|
|
40
|
+
' res.statusCode = response.status;',
|
|
41
|
+
' response.headers.forEach((v, k) => res.setHeader(k, v));',
|
|
42
|
+
'',
|
|
43
|
+
' const ab = await response.arrayBuffer();',
|
|
44
|
+
' res.end(Buffer.from(ab));',
|
|
45
|
+
' } catch (err) {',
|
|
46
|
+
' res.statusCode = 500;',
|
|
47
|
+
" res.setHeader('content-type', 'text/plain');",
|
|
48
|
+
" res.end('Internal Server Error' + (err as Error).message);",
|
|
49
|
+
' }',
|
|
50
|
+
'});',
|
|
51
|
+
'',
|
|
52
|
+
'server.listen(port, host, () => {',
|
|
53
|
+
' // eslint-disable-next-line no-console',
|
|
54
|
+
" console.log('Deno adapter server listening at http://' + host + ':' + port);",
|
|
55
|
+
'});',
|
|
56
|
+
'',
|
|
57
|
+
].join('\n');
|
|
58
|
+
export const LAMBDA_RUNNER_SOURCE = [
|
|
59
|
+
"import http from 'node:http';",
|
|
60
|
+
"import { handler as lambdaHandler } from '@zintrust/core/start';",
|
|
61
|
+
'',
|
|
62
|
+
"const port = Number.parseInt(process.env.PORT ?? '3000', 10) || 3000;",
|
|
63
|
+
"const host = process.env.HOST ?? 'localhost';",
|
|
64
|
+
'',
|
|
65
|
+
'const readBody = async (req: http.IncomingMessage): Promise<string | undefined> => {',
|
|
66
|
+
" if (req.method === 'GET' || req.method === 'HEAD') return undefined;",
|
|
67
|
+
' const chunks: Buffer[] = [];',
|
|
68
|
+
' for await (const chunk of req) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));',
|
|
69
|
+
" return chunks.length > 0 ? Buffer.concat(chunks).toString('utf-8') : undefined;",
|
|
70
|
+
'};',
|
|
71
|
+
'',
|
|
72
|
+
'const server = http.createServer(async (req, res) => {',
|
|
73
|
+
' try {',
|
|
74
|
+
" const proto = (req.headers['x-forwarded-proto'] ?? 'http').toString();",
|
|
75
|
+
' const authority = (req.headers.host ?? host).toString();',
|
|
76
|
+
" const url = new URL(req.url ?? '/', proto + '://' + authority);",
|
|
77
|
+
'',
|
|
78
|
+
' const body = await readBody(req);',
|
|
79
|
+
' const headers: Record<string, string> = {};',
|
|
80
|
+
' for (const [k, v] of Object.entries(req.headers)) {',
|
|
81
|
+
' if (v === undefined) continue;',
|
|
82
|
+
" headers[k] = Array.isArray(v) ? v.join(',') : String(v);",
|
|
83
|
+
' }',
|
|
84
|
+
'',
|
|
85
|
+
' const queryStringParameters: Record<string, string> = {};',
|
|
86
|
+
' url.searchParams.forEach((value, key) => {',
|
|
87
|
+
' if (queryStringParameters[key] === undefined) queryStringParameters[key] = value;',
|
|
88
|
+
' });',
|
|
89
|
+
'',
|
|
90
|
+
' const event = {',
|
|
91
|
+
" version: '2.0',",
|
|
92
|
+
" routeKey: '$default',",
|
|
93
|
+
' rawPath: url.pathname,',
|
|
94
|
+
' rawQueryString: url.searchParams.toString(),',
|
|
95
|
+
' headers,',
|
|
96
|
+
' queryStringParameters,',
|
|
97
|
+
' requestContext: {',
|
|
98
|
+
' http: {',
|
|
99
|
+
" method: req.method ?? 'GET',",
|
|
100
|
+
' path: url.pathname,',
|
|
101
|
+
" sourceIp: (req.socket.remoteAddress ?? '').toString(),",
|
|
102
|
+
' },',
|
|
103
|
+
' },',
|
|
104
|
+
' body: body ?? null,',
|
|
105
|
+
' isBase64Encoded: false,',
|
|
106
|
+
' };',
|
|
107
|
+
'',
|
|
108
|
+
' const result = (await lambdaHandler(event, {})) as {',
|
|
109
|
+
' statusCode?: number;',
|
|
110
|
+
' headers?: Record<string, string | string[]>;',
|
|
111
|
+
' body?: string;',
|
|
112
|
+
' isBase64Encoded?: boolean;',
|
|
113
|
+
' };',
|
|
114
|
+
'',
|
|
115
|
+
' res.statusCode = typeof result.statusCode === "number" ? result.statusCode : 200;',
|
|
116
|
+
' if (result.headers) {',
|
|
117
|
+
' for (const [k, v] of Object.entries(result.headers)) {',
|
|
118
|
+
' res.setHeader(k, v as any);',
|
|
119
|
+
' }',
|
|
120
|
+
' }',
|
|
121
|
+
'',
|
|
122
|
+
' if (result.isBase64Encoded === true && typeof result.body === "string") {',
|
|
123
|
+
" res.end(Buffer.from(result.body, 'base64'));",
|
|
124
|
+
' } else {',
|
|
125
|
+
" res.end(result.body ?? '');",
|
|
126
|
+
' }',
|
|
127
|
+
' } catch {',
|
|
128
|
+
' res.statusCode = 500;',
|
|
129
|
+
" res.setHeader('content-type', 'application/json');",
|
|
130
|
+
" res.end(JSON.stringify({ message: 'Internal Server Error' }));",
|
|
131
|
+
' }',
|
|
132
|
+
'});',
|
|
133
|
+
'',
|
|
134
|
+
'server.listen(port, host, () => {',
|
|
135
|
+
' // eslint-disable-next-line no-console',
|
|
136
|
+
" console.log('Lambda adapter server listening at http://' + host + ':' + port);",
|
|
137
|
+
'});',
|
|
138
|
+
'',
|
|
139
|
+
].join('\n');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Configuration Manager
|
|
3
3
|
* Handles reading, writing, and managing configuration files
|
|
4
4
|
*/
|
|
5
|
-
import { ProjectConfig } from '../config/ConfigSchema';
|
|
5
|
+
import type { ProjectConfig } from '../config/ConfigSchema';
|
|
6
6
|
export interface IConfigManager {
|
|
7
7
|
load(): Promise<ProjectConfig>;
|
|
8
8
|
save(config?: ProjectConfig): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigManager.d.ts","sourceRoot":"","sources":["../../../../src/cli/config/ConfigManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ConfigManager.d.ts","sourceRoot":"","sources":["../../../../src/cli/config/ConfigManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAYjD,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/B,IAAI,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,SAAS,IAAI,aAAa,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IACvC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IAC7C,MAAM,IAAI,MAAM,CAAC;IACjB,UAAU,IAAI,MAAM,EAAE,CAAC;CACxB;AAkHD;;;;GAIG;AACH,eAAO,MAAM,aAAa;IACxB;;OAEG;wBACgB,MAAM,GAAgC,cAAc;IAqCvE;;OAEG;6BAC4B,OAAO,CAAC,IAAI,CAAC;IAS5C;;OAEG;uBACsB,OAAO,CAAC,cAAc,CAAC;IAOhD;;OAEG;wBACuB,OAAO,CAAC,cAAc,CAAC;EAKjD,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Configuration Validator
|
|
3
3
|
* Validates configuration against schema and rules
|
|
4
4
|
*/
|
|
5
|
-
import { ProjectConfig } from '../config/ConfigSchema';
|
|
5
|
+
import type { ProjectConfig } from '../config/ConfigSchema';
|
|
6
6
|
export interface ValidationError {
|
|
7
7
|
key: string;
|
|
8
8
|
value: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigValidator.d.ts","sourceRoot":"","sources":["../../../../src/cli/config/ConfigValidator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"ConfigValidator.d.ts","sourceRoot":"","sources":["../../../../src/cli/config/ConfigValidator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,aAAa,EACE,MAAM,0BAA0B,CAAC;AAMlD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,CAgBtE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAqCvF;AAoID;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAUvE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGpE;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;EAK1B,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Configuration Validator
|
|
3
3
|
* Validates configuration against schema and rules
|
|
4
4
|
*/
|
|
5
|
-
import { CONFIG_RULES, getConfigValue
|
|
5
|
+
import { CONFIG_RULES, getConfigValue } from '../config/ConfigSchema.js';
|
|
6
6
|
/**
|
|
7
7
|
* Validate entire config against schema
|
|
8
8
|
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type D1SqlMigrationsCompileOptions = {
|
|
2
|
+
projectRoot: string;
|
|
3
|
+
globalDir: string;
|
|
4
|
+
extension: string;
|
|
5
|
+
service?: string;
|
|
6
|
+
includeGlobal?: boolean;
|
|
7
|
+
serviceDirOverride?: string;
|
|
8
|
+
outputDir: string;
|
|
9
|
+
};
|
|
10
|
+
type GeneratedSqlMigration = {
|
|
11
|
+
sourceName: string;
|
|
12
|
+
outputFileName: string;
|
|
13
|
+
outputFilePath: string;
|
|
14
|
+
statements: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare const D1SqlMigrations: Readonly<{
|
|
17
|
+
compileAndWrite(opts: D1SqlMigrationsCompileOptions): Promise<GeneratedSqlMigration[]>;
|
|
18
|
+
}>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=D1SqlMigrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"D1SqlMigrations.d.ts","sourceRoot":"","sources":["../../../../src/cli/d1/D1SqlMigrations.ts"],"names":[],"mappings":"AAWA,KAAK,6BAA6B,GAAG;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AA4NF,eAAO,MAAM,eAAe;0BACE,6BAA6B,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;EAmC5F,CAAC"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
2
|
+
import * as fs from '../../node-singletons/fs.js';
|
|
3
|
+
import * as path from '../../node-singletons/path.js';
|
|
4
|
+
import { MigrationDiscovery } from '../../migrations/MigrationDiscovery.js';
|
|
5
|
+
import { MigrationLoader } from '../../migrations/MigrationLoader.js';
|
|
6
|
+
import { BaseAdapter } from '../../orm/DatabaseAdapter.js';
|
|
7
|
+
const RESOLVED_VOID = Promise.resolve();
|
|
8
|
+
const ensureDir = (dir) => {
|
|
9
|
+
if (fs.existsSync(dir))
|
|
10
|
+
return;
|
|
11
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
12
|
+
};
|
|
13
|
+
const getDefaultOutputFileName = (migrationName, index) => {
|
|
14
|
+
const m = /^(\d+)_(.+)$/.exec(migrationName);
|
|
15
|
+
if (m !== null) {
|
|
16
|
+
return `${m[1]}_${m[2]}.sql`;
|
|
17
|
+
}
|
|
18
|
+
const padded = String(index).padStart(4, '0');
|
|
19
|
+
return `${padded}_${migrationName}.sql`;
|
|
20
|
+
};
|
|
21
|
+
const normalizeSql = (sql) => {
|
|
22
|
+
const trimmed = sql.trim();
|
|
23
|
+
if (trimmed === '')
|
|
24
|
+
return '';
|
|
25
|
+
return trimmed.endsWith(';') ? trimmed : `${trimmed};`;
|
|
26
|
+
};
|
|
27
|
+
const interpolateSql = (sql, parameters) => {
|
|
28
|
+
const placeholders = (sql.match(/\?/g) ?? []).length;
|
|
29
|
+
if (placeholders !== parameters.length) {
|
|
30
|
+
throw ErrorFactory.createValidationError(`Cannot compile parameterized SQL: expected ${placeholders} params but got ${parameters.length}. SQL: ${sql}`);
|
|
31
|
+
}
|
|
32
|
+
let idx = 0;
|
|
33
|
+
return sql.replaceAll('?', () => {
|
|
34
|
+
const value = parameters[idx];
|
|
35
|
+
idx += 1;
|
|
36
|
+
return BaseAdapter.sanitize(value);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const isMutatingSql = (sql) => {
|
|
40
|
+
const s = sql.trimStart().toLowerCase();
|
|
41
|
+
return (s.startsWith('insert') ||
|
|
42
|
+
s.startsWith('update') ||
|
|
43
|
+
s.startsWith('delete') ||
|
|
44
|
+
s.startsWith('create') ||
|
|
45
|
+
s.startsWith('drop') ||
|
|
46
|
+
s.startsWith('alter') ||
|
|
47
|
+
s.startsWith('replace') ||
|
|
48
|
+
s.startsWith('pragma'));
|
|
49
|
+
};
|
|
50
|
+
const createNoopAdapter = (isConnected, setConnected) => ({
|
|
51
|
+
async connect() {
|
|
52
|
+
setConnected(true);
|
|
53
|
+
await RESOLVED_VOID;
|
|
54
|
+
},
|
|
55
|
+
async disconnect() {
|
|
56
|
+
setConnected(false);
|
|
57
|
+
await RESOLVED_VOID;
|
|
58
|
+
},
|
|
59
|
+
async query() {
|
|
60
|
+
await RESOLVED_VOID;
|
|
61
|
+
return { rows: [], rowCount: 0 };
|
|
62
|
+
},
|
|
63
|
+
async queryOne() {
|
|
64
|
+
await RESOLVED_VOID;
|
|
65
|
+
return null;
|
|
66
|
+
},
|
|
67
|
+
async ping() {
|
|
68
|
+
await RESOLVED_VOID;
|
|
69
|
+
},
|
|
70
|
+
async transaction(callback) {
|
|
71
|
+
await RESOLVED_VOID;
|
|
72
|
+
return callback(this);
|
|
73
|
+
},
|
|
74
|
+
async rawQuery() {
|
|
75
|
+
await RESOLVED_VOID;
|
|
76
|
+
return [];
|
|
77
|
+
},
|
|
78
|
+
getType() {
|
|
79
|
+
return 'd1';
|
|
80
|
+
},
|
|
81
|
+
isConnected() {
|
|
82
|
+
return isConnected();
|
|
83
|
+
},
|
|
84
|
+
getPlaceholder() {
|
|
85
|
+
return '?';
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const captureSql = (onSql, sql, parameters) => {
|
|
89
|
+
const compiled = parameters.length > 0 ? interpolateSql(sql, parameters) : sql;
|
|
90
|
+
if (!isMutatingSql(compiled))
|
|
91
|
+
return;
|
|
92
|
+
const normalized = normalizeSql(compiled);
|
|
93
|
+
if (normalized !== '')
|
|
94
|
+
onSql(normalized);
|
|
95
|
+
};
|
|
96
|
+
const createCaptureDb = (onSql) => {
|
|
97
|
+
let connected = false;
|
|
98
|
+
const setConnected = (v) => {
|
|
99
|
+
connected = v;
|
|
100
|
+
};
|
|
101
|
+
const noopAdapter = createNoopAdapter(() => connected, setConnected);
|
|
102
|
+
const db = {
|
|
103
|
+
async connect() {
|
|
104
|
+
connected = true;
|
|
105
|
+
await RESOLVED_VOID;
|
|
106
|
+
},
|
|
107
|
+
async disconnect() {
|
|
108
|
+
connected = false;
|
|
109
|
+
await RESOLVED_VOID;
|
|
110
|
+
},
|
|
111
|
+
isConnected() {
|
|
112
|
+
return connected;
|
|
113
|
+
},
|
|
114
|
+
async query(sql, parameters = []) {
|
|
115
|
+
captureSql(onSql, sql, parameters);
|
|
116
|
+
await RESOLVED_VOID;
|
|
117
|
+
return [];
|
|
118
|
+
},
|
|
119
|
+
async queryOne(sql, parameters = []) {
|
|
120
|
+
captureSql(onSql, sql, parameters);
|
|
121
|
+
await RESOLVED_VOID;
|
|
122
|
+
return null;
|
|
123
|
+
},
|
|
124
|
+
async transaction(callback) {
|
|
125
|
+
await RESOLVED_VOID;
|
|
126
|
+
return callback(db);
|
|
127
|
+
},
|
|
128
|
+
table() {
|
|
129
|
+
throw ErrorFactory.createCliError('D1 SQL compilation does not support QueryBuilder-based migrations yet. Use db.query(...) with explicit SQL.');
|
|
130
|
+
},
|
|
131
|
+
onBeforeQuery() {
|
|
132
|
+
return;
|
|
133
|
+
},
|
|
134
|
+
onAfterQuery() {
|
|
135
|
+
return;
|
|
136
|
+
},
|
|
137
|
+
offBeforeQuery() {
|
|
138
|
+
return;
|
|
139
|
+
},
|
|
140
|
+
offAfterQuery() {
|
|
141
|
+
return;
|
|
142
|
+
},
|
|
143
|
+
getAdapterInstance() {
|
|
144
|
+
return noopAdapter;
|
|
145
|
+
},
|
|
146
|
+
getType() {
|
|
147
|
+
return 'd1';
|
|
148
|
+
},
|
|
149
|
+
getConfig() {
|
|
150
|
+
return { driver: 'd1' };
|
|
151
|
+
},
|
|
152
|
+
dispose() {
|
|
153
|
+
// No resources to dispose for capture DB
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
return db;
|
|
157
|
+
};
|
|
158
|
+
async function runSerial(items, fn) {
|
|
159
|
+
let chain = Promise.resolve();
|
|
160
|
+
let idx = 0;
|
|
161
|
+
for (const item of items) {
|
|
162
|
+
const current = idx;
|
|
163
|
+
chain = chain.then(async () => fn(item, current));
|
|
164
|
+
idx += 1;
|
|
165
|
+
}
|
|
166
|
+
await chain;
|
|
167
|
+
}
|
|
168
|
+
const resolveServiceDir = (opts) => {
|
|
169
|
+
const service = typeof opts.service === 'string' && opts.service.length > 0 ? opts.service : null;
|
|
170
|
+
if (service === null)
|
|
171
|
+
return null;
|
|
172
|
+
const rel = opts.serviceDirOverride ?? path.join('services', service, 'database/migrations');
|
|
173
|
+
return MigrationDiscovery.resolveDir(opts.projectRoot, rel);
|
|
174
|
+
};
|
|
175
|
+
const discoverMigrations = async (opts) => {
|
|
176
|
+
const globalDir = MigrationDiscovery.resolveDir(opts.projectRoot, opts.globalDir);
|
|
177
|
+
const includeGlobal = opts.includeGlobal !== false;
|
|
178
|
+
const dirs = [];
|
|
179
|
+
if (includeGlobal)
|
|
180
|
+
dirs.push(globalDir);
|
|
181
|
+
const serviceDir = resolveServiceDir(opts);
|
|
182
|
+
if (serviceDir !== null)
|
|
183
|
+
dirs.push(serviceDir);
|
|
184
|
+
const files = dirs.flatMap((dir) => MigrationDiscovery.listMigrationFiles(dir, opts.extension));
|
|
185
|
+
const loaded = [];
|
|
186
|
+
let chain = Promise.resolve();
|
|
187
|
+
for (const file of files) {
|
|
188
|
+
chain = chain.then(async () => {
|
|
189
|
+
loaded.push(await MigrationLoader.load(file));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
await chain;
|
|
193
|
+
return loaded.sort((a, b) => a.name.localeCompare(b.name));
|
|
194
|
+
};
|
|
195
|
+
export const D1SqlMigrations = Object.freeze({
|
|
196
|
+
async compileAndWrite(opts) {
|
|
197
|
+
const migrations = await discoverMigrations(opts);
|
|
198
|
+
ensureDir(opts.outputDir);
|
|
199
|
+
const out = [];
|
|
200
|
+
await runSerial(migrations, async (m, idx) => {
|
|
201
|
+
const statements = [];
|
|
202
|
+
const db = createCaptureDb((sql) => statements.push(sql));
|
|
203
|
+
await db.connect();
|
|
204
|
+
try {
|
|
205
|
+
await m.up(db);
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
await db.disconnect();
|
|
209
|
+
}
|
|
210
|
+
const outputFileName = getDefaultOutputFileName(m.name, idx);
|
|
211
|
+
const outputFilePath = path.join(opts.outputDir, outputFileName);
|
|
212
|
+
const header = `-- Generated from ${m.name}\n`;
|
|
213
|
+
const body = statements.length > 0 ? `${statements.join('\n')}\n` : '';
|
|
214
|
+
fs.writeFileSync(outputFilePath, `${header}${body}`, 'utf8');
|
|
215
|
+
out.push({
|
|
216
|
+
sourceName: m.name,
|
|
217
|
+
outputFileName,
|
|
218
|
+
outputFilePath,
|
|
219
|
+
statements,
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
return out;
|
|
223
|
+
},
|
|
224
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WranglerConfig.d.ts","sourceRoot":"","sources":["../../../../src/cli/d1/WranglerConfig.ts"],"names":[],"mappings":"AA2HA,eAAO,MAAM,cAAc;oCACO,MAAM,WAAW,MAAM,GAAG,MAAM;EAqBhE,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as fs from '../../node-singletons/fs.js';
|
|
2
|
+
import * as path from '../../node-singletons/path.js';
|
|
3
|
+
const createStripState = () => ({
|
|
4
|
+
inString: false,
|
|
5
|
+
escaped: false,
|
|
6
|
+
inLineComment: false,
|
|
7
|
+
inBlockComment: false,
|
|
8
|
+
skipNext: false,
|
|
9
|
+
});
|
|
10
|
+
const consumeSkipNext = (state) => {
|
|
11
|
+
if (!state.skipNext)
|
|
12
|
+
return false;
|
|
13
|
+
state.skipNext = false;
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
const handleLineComment = (state, ch, out) => {
|
|
17
|
+
if (!state.inLineComment)
|
|
18
|
+
return false;
|
|
19
|
+
if (ch === '\n') {
|
|
20
|
+
state.inLineComment = false;
|
|
21
|
+
out.push(ch);
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
const handleBlockComment = (state, ch, next) => {
|
|
26
|
+
if (!state.inBlockComment)
|
|
27
|
+
return false;
|
|
28
|
+
if (ch === '*' && next === '/') {
|
|
29
|
+
state.inBlockComment = false;
|
|
30
|
+
state.skipNext = true;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const handleString = (state, ch, out) => {
|
|
35
|
+
if (!state.inString)
|
|
36
|
+
return false;
|
|
37
|
+
out.push(ch);
|
|
38
|
+
if (state.escaped) {
|
|
39
|
+
state.escaped = false;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (ch === '\\') {
|
|
43
|
+
state.escaped = true;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (ch === '"') {
|
|
47
|
+
state.inString = false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const tryStartString = (state, ch, out) => {
|
|
52
|
+
if (ch !== '"')
|
|
53
|
+
return false;
|
|
54
|
+
state.inString = true;
|
|
55
|
+
out.push(ch);
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
const tryStartLineComment = (state, ch, next) => {
|
|
59
|
+
if (ch !== '/' || next !== '/')
|
|
60
|
+
return false;
|
|
61
|
+
state.inLineComment = true;
|
|
62
|
+
state.skipNext = true;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
const tryStartBlockComment = (state, ch, next) => {
|
|
66
|
+
if (ch !== '/' || next !== '*')
|
|
67
|
+
return false;
|
|
68
|
+
state.inBlockComment = true;
|
|
69
|
+
state.skipNext = true;
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
const processStripChar = (state, ch, next, out) => {
|
|
73
|
+
if (consumeSkipNext(state))
|
|
74
|
+
return true;
|
|
75
|
+
if (handleLineComment(state, ch, out))
|
|
76
|
+
return true;
|
|
77
|
+
if (handleBlockComment(state, ch, next))
|
|
78
|
+
return true;
|
|
79
|
+
if (handleString(state, ch, out))
|
|
80
|
+
return true;
|
|
81
|
+
if (tryStartString(state, ch, out))
|
|
82
|
+
return true;
|
|
83
|
+
if (tryStartLineComment(state, ch, next))
|
|
84
|
+
return true;
|
|
85
|
+
if (tryStartBlockComment(state, ch, next))
|
|
86
|
+
return true;
|
|
87
|
+
return false;
|
|
88
|
+
};
|
|
89
|
+
const stripJsonc = (input) => {
|
|
90
|
+
const state = createStripState();
|
|
91
|
+
const out = [];
|
|
92
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
93
|
+
const ch = input[i] ?? '';
|
|
94
|
+
const next = i + 1 < input.length ? (input[i + 1] ?? '') : '';
|
|
95
|
+
if (processStripChar(state, ch, next, out))
|
|
96
|
+
continue;
|
|
97
|
+
out.push(ch);
|
|
98
|
+
}
|
|
99
|
+
return out.join('');
|
|
100
|
+
};
|
|
101
|
+
export const WranglerConfig = Object.freeze({
|
|
102
|
+
getD1MigrationsDir(projectRoot, dbName) {
|
|
103
|
+
const configPath = path.join(projectRoot, 'wrangler.jsonc');
|
|
104
|
+
if (!fs.existsSync(configPath))
|
|
105
|
+
return 'migrations';
|
|
106
|
+
try {
|
|
107
|
+
const raw = fs.readFileSync(configPath, 'utf8');
|
|
108
|
+
const parsed = JSON.parse(stripJsonc(raw));
|
|
109
|
+
const list = parsed.d1_databases;
|
|
110
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
111
|
+
return 'migrations';
|
|
112
|
+
const match = typeof dbName === 'string'
|
|
113
|
+
? list.find((d) => d.database_name === dbName)
|
|
114
|
+
: (list[0] ?? undefined);
|
|
115
|
+
const dir = match?.migrations_dir;
|
|
116
|
+
return typeof dir === 'string' && dir.trim() !== '' ? dir : 'migrations';
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return 'migrations';
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IBaseCommand } from '../BaseCommand';
|
|
2
|
+
type ApplyOptions = {
|
|
3
|
+
cmd: IBaseCommand;
|
|
4
|
+
dbName: string;
|
|
5
|
+
isLocal: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const WranglerD1: Readonly<{
|
|
8
|
+
applyMigrations(opts: ApplyOptions): string;
|
|
9
|
+
}>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=WranglerD1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WranglerD1.d.ts","sourceRoot":"","sources":["../../../../src/cli/d1/WranglerD1.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,YAAY,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,UAAU;0BACC,YAAY,GAAG,MAAM;EAc3C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { resolveNpmPath } from '../../common/index.js';
|
|
2
|
+
import { appConfig } from '../../config/app.js';
|
|
3
|
+
import { execFileSync } from '../../node-singletons/child-process.js';
|
|
4
|
+
export const WranglerD1 = Object.freeze({
|
|
5
|
+
applyMigrations(opts) {
|
|
6
|
+
const args = ['d1', 'migrations', 'apply', opts.dbName, opts.isLocal ? '--local' : '--remote'];
|
|
7
|
+
const npmPath = resolveNpmPath();
|
|
8
|
+
opts.cmd.debug(`Executing: npm exec --yes -- wrangler ${args.join(' ')}`);
|
|
9
|
+
const result = execFileSync(npmPath, ['exec', '--yes', '--', 'wrangler', ...args], {
|
|
10
|
+
stdio: 'pipe',
|
|
11
|
+
encoding: 'utf8',
|
|
12
|
+
env: appConfig.getSafeEnv(),
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type EnvBackfillResult = {
|
|
2
|
+
changed: boolean;
|
|
3
|
+
filledKeys: string[];
|
|
4
|
+
appendedKeys: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare const EnvFileBackfill: Readonly<{
|
|
7
|
+
stripEnvInlineComment: (value: string) => string;
|
|
8
|
+
backfillEnvDefaults: (envPath: string, defaults: Record<string, string>) => EnvBackfillResult;
|
|
9
|
+
}>;
|
|
10
|
+
//# sourceMappingURL=EnvFileBackfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvFileBackfill.d.ts","sourceRoot":"","sources":["../../../../src/cli/env/EnvFileBackfill.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAsEF,eAAO,MAAM,eAAe;mCApEU,MAAM,KAAG,MAAM;mCAqB1C,MAAM,YACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC/B,iBAAiB;EAgDlB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from '../../node-singletons/fs.js';
|
|
2
|
+
const stripEnvInlineComment = (value) => {
|
|
3
|
+
let inSingle = false;
|
|
4
|
+
let inDouble = false;
|
|
5
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
6
|
+
const ch = value[i];
|
|
7
|
+
if (ch === "'" && !inDouble)
|
|
8
|
+
inSingle = !inSingle;
|
|
9
|
+
if (ch === '"' && !inSingle)
|
|
10
|
+
inDouble = !inDouble;
|
|
11
|
+
if (!inSingle && !inDouble && ch === '#') {
|
|
12
|
+
const prev = value[i - 1];
|
|
13
|
+
if (prev === undefined || prev === ' ' || prev === '\t') {
|
|
14
|
+
return value.slice(0, i).trimEnd();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
const backfillEnvDefaults = (envPath, defaults) => {
|
|
21
|
+
const raw = readFileSync(envPath, 'utf8');
|
|
22
|
+
const lines = raw.split(/\r?\n/);
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const filledKeys = [];
|
|
25
|
+
const appendedKeys = [];
|
|
26
|
+
const out = lines.map((line) => {
|
|
27
|
+
const trimmed = line.trim();
|
|
28
|
+
if (trimmed === '' || trimmed.startsWith('#'))
|
|
29
|
+
return line;
|
|
30
|
+
const withoutExport = trimmed.startsWith('export ') ? trimmed.slice('export '.length) : trimmed;
|
|
31
|
+
const eq = withoutExport.indexOf('=');
|
|
32
|
+
if (eq <= 0)
|
|
33
|
+
return line;
|
|
34
|
+
const key = withoutExport.slice(0, eq).trim();
|
|
35
|
+
if (key === '')
|
|
36
|
+
return line;
|
|
37
|
+
if (!Object.hasOwn(defaults, key))
|
|
38
|
+
return line;
|
|
39
|
+
if (seen.has(key))
|
|
40
|
+
return line;
|
|
41
|
+
seen.add(key);
|
|
42
|
+
const rhs = withoutExport.slice(eq + 1);
|
|
43
|
+
const withoutComment = stripEnvInlineComment(rhs);
|
|
44
|
+
const value = withoutComment.trim();
|
|
45
|
+
if (value !== '')
|
|
46
|
+
return line;
|
|
47
|
+
filledKeys.push(key);
|
|
48
|
+
return `${key}=${defaults[key]}`;
|
|
49
|
+
});
|
|
50
|
+
const missingKeys = Object.keys(defaults).filter((k) => !seen.has(k));
|
|
51
|
+
if (missingKeys.length > 0) {
|
|
52
|
+
appendedKeys.push(...missingKeys);
|
|
53
|
+
out.push(...missingKeys.map((k) => `${k}=${defaults[k]}`));
|
|
54
|
+
}
|
|
55
|
+
const changed = filledKeys.length > 0 || appendedKeys.length > 0;
|
|
56
|
+
if (!changed)
|
|
57
|
+
return { changed: false, filledKeys, appendedKeys };
|
|
58
|
+
writeFileSync(envPath, out.join('\n') + (out.at(-1) === '' ? '' : '\n'));
|
|
59
|
+
return { changed: true, filledKeys, appendedKeys };
|
|
60
|
+
};
|
|
61
|
+
export const EnvFileBackfill = Object.freeze({
|
|
62
|
+
stripEnvInlineComment,
|
|
63
|
+
backfillEnvDefaults,
|
|
64
|
+
});
|