@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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional OpenTelemetry integration.
|
|
3
|
+
*
|
|
4
|
+
* Design goals:
|
|
5
|
+
* - No hard dependency on SDKs/exporters (apps bring their own).
|
|
6
|
+
* - Safe to import in runtimes without tracing configured (no-op behavior).
|
|
7
|
+
* - Best-effort: never breaks request handling.
|
|
8
|
+
*
|
|
9
|
+
* Tiny Node enablement snippet (exporter is app-owned):
|
|
10
|
+
*
|
|
11
|
+
* npm i @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node \
|
|
12
|
+
* @opentelemetry/exporter-trace-otlp-http
|
|
13
|
+
*
|
|
14
|
+
* // in your app entrypoint (before creating the server)
|
|
15
|
+
* import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
16
|
+
* import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
17
|
+
* import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
18
|
+
*
|
|
19
|
+
* const sdk = new NodeSDK({
|
|
20
|
+
* traceExporter: new OTLPTraceExporter({ url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT }),
|
|
21
|
+
* instrumentations: [getNodeAutoInstrumentations()],
|
|
22
|
+
* });
|
|
23
|
+
* await sdk.start();
|
|
24
|
+
* process.env.OTEL_ENABLED = 'true';
|
|
25
|
+
*/
|
|
26
|
+
import { Env } from '../config/env.js';
|
|
27
|
+
import { context, propagation, SpanKind, SpanStatusCode, trace, } from '@opentelemetry/api';
|
|
28
|
+
const isEnabled = () => {
|
|
29
|
+
return Env.getBool('OTEL_ENABLED', false);
|
|
30
|
+
};
|
|
31
|
+
const extractContextFromHeaders = (req) => {
|
|
32
|
+
const active = context.active();
|
|
33
|
+
try {
|
|
34
|
+
return propagation.extract(active, req, {
|
|
35
|
+
get(carrier, key) {
|
|
36
|
+
const value = carrier.getHeader(key);
|
|
37
|
+
if (typeof value === 'string')
|
|
38
|
+
return value;
|
|
39
|
+
if (Array.isArray(value))
|
|
40
|
+
return value.join(',');
|
|
41
|
+
return undefined;
|
|
42
|
+
},
|
|
43
|
+
keys() {
|
|
44
|
+
return [];
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return active;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const startHttpServerSpan = (req, input) => {
|
|
53
|
+
const parent = extractContextFromHeaders(req);
|
|
54
|
+
const tracer = trace.getTracer('zintrust');
|
|
55
|
+
const span = tracer.startSpan(`${input.method} unmatched`, {
|
|
56
|
+
kind: SpanKind.SERVER,
|
|
57
|
+
attributes: {
|
|
58
|
+
'http.method': input.method,
|
|
59
|
+
'http.target': input.path,
|
|
60
|
+
'http.user_agent': input.userAgent ?? '',
|
|
61
|
+
'service.name': input.serviceName ?? '',
|
|
62
|
+
'enduser.id': input.userId ?? '',
|
|
63
|
+
'zintrust.tenant_id': input.tenantId ?? '',
|
|
64
|
+
'zintrust.request_id': input.requestId ?? '',
|
|
65
|
+
},
|
|
66
|
+
}, parent);
|
|
67
|
+
const spanContext = trace.setSpan(parent, span);
|
|
68
|
+
return { span, context: spanContext };
|
|
69
|
+
};
|
|
70
|
+
const runWithContext = async (ctx, fn) => {
|
|
71
|
+
return context.with(ctx, fn);
|
|
72
|
+
};
|
|
73
|
+
const setHttpRoute = (span, method, route) => {
|
|
74
|
+
try {
|
|
75
|
+
span.setAttribute('http.route', route);
|
|
76
|
+
span.updateName(`${method} ${route}`);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// best-effort
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const endHttpServerSpan = (span, input) => {
|
|
83
|
+
try {
|
|
84
|
+
if (input.route !== undefined && input.route.trim() !== '') {
|
|
85
|
+
span.setAttribute('http.route', input.route);
|
|
86
|
+
}
|
|
87
|
+
if (typeof input.status === 'number') {
|
|
88
|
+
span.setAttribute('http.status_code', input.status);
|
|
89
|
+
if (input.status >= 500) {
|
|
90
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (input.error !== undefined) {
|
|
97
|
+
// Avoid throwing; represent as a string attribute.
|
|
98
|
+
span.setAttribute('zintrust.error', input.error instanceof Error ? input.error.message : String(input.error));
|
|
99
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
100
|
+
}
|
|
101
|
+
span.end();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// best-effort
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const injectTraceHeaders = (headers) => {
|
|
108
|
+
try {
|
|
109
|
+
propagation.inject(context.active(), headers);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// best-effort
|
|
113
|
+
}
|
|
114
|
+
return headers;
|
|
115
|
+
};
|
|
116
|
+
const mapDbSystem = (driver) => {
|
|
117
|
+
switch (driver) {
|
|
118
|
+
case 'postgresql':
|
|
119
|
+
return 'postgresql';
|
|
120
|
+
case 'mysql':
|
|
121
|
+
return 'mysql';
|
|
122
|
+
case 'sqlserver':
|
|
123
|
+
return 'mssql';
|
|
124
|
+
case 'd1':
|
|
125
|
+
case 'd1-remote':
|
|
126
|
+
case 'sqlite':
|
|
127
|
+
default:
|
|
128
|
+
return 'sqlite';
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const recordDbQuerySpan = (input) => {
|
|
132
|
+
if (isEnabled() === false)
|
|
133
|
+
return;
|
|
134
|
+
try {
|
|
135
|
+
// Only create a DB span if we're already inside a request trace.
|
|
136
|
+
const parentSpan = trace.getSpan(context.active());
|
|
137
|
+
if (!parentSpan)
|
|
138
|
+
return;
|
|
139
|
+
const tracer = trace.getTracer('zintrust');
|
|
140
|
+
const now = Date.now();
|
|
141
|
+
const durationMs = Number.isFinite(input.durationMs) ? Math.max(0, input.durationMs) : 0;
|
|
142
|
+
const startTime = now - durationMs;
|
|
143
|
+
const span = tracer.startSpan('db.query', {
|
|
144
|
+
kind: SpanKind.CLIENT,
|
|
145
|
+
startTime,
|
|
146
|
+
attributes: {
|
|
147
|
+
'db.system': mapDbSystem(input.driver),
|
|
148
|
+
'db.operation': 'query',
|
|
149
|
+
'zintrust.db.driver': input.driver,
|
|
150
|
+
},
|
|
151
|
+
}, context.active());
|
|
152
|
+
span.end(now);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// best-effort
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
export const OpenTelemetry = Object.freeze({
|
|
159
|
+
isEnabled,
|
|
160
|
+
startHttpServerSpan,
|
|
161
|
+
runWithContext,
|
|
162
|
+
setHttpRoute,
|
|
163
|
+
endHttpServerSpan,
|
|
164
|
+
injectTraceHeaders,
|
|
165
|
+
recordDbQuerySpan,
|
|
166
|
+
});
|
|
167
|
+
export default OpenTelemetry;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prometheus Metrics (prom-client)
|
|
3
|
+
*
|
|
4
|
+
* Lazy-initialized so importing this module is safe in non-Node runtimes.
|
|
5
|
+
*/
|
|
6
|
+
export type ObserveHttpRequestInput = {
|
|
7
|
+
method: string;
|
|
8
|
+
route: string;
|
|
9
|
+
status: number;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
};
|
|
12
|
+
export type ObserveDbQueryInput = {
|
|
13
|
+
driver: string;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const PrometheusMetrics: Readonly<{
|
|
17
|
+
getMetricsText(): Promise<{
|
|
18
|
+
contentType: string;
|
|
19
|
+
body: string;
|
|
20
|
+
}>;
|
|
21
|
+
observeHttpRequest(input: ObserveHttpRequestInput): Promise<void>;
|
|
22
|
+
observeDbQuery(input: ObserveDbQueryInput): Promise<void>;
|
|
23
|
+
}>;
|
|
24
|
+
export default PrometheusMetrics;
|
|
25
|
+
//# sourceMappingURL=PrometheusMetrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusMetrics.d.ts","sourceRoot":"","sources":["../../../src/observability/PrometheusMetrics.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6GH,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,iBAAiB;sBACJ,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;8BAWtC,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;0BAY3C,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;EAS/D,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prometheus Metrics (prom-client)
|
|
3
|
+
*
|
|
4
|
+
* Lazy-initialized so importing this module is safe in non-Node runtimes.
|
|
5
|
+
*/
|
|
6
|
+
import { Env } from '../config/env.js';
|
|
7
|
+
let statePromise = null;
|
|
8
|
+
const DEFAULT_CONTENT_TYPE = 'text/plain; version=0.0.4; charset=utf-8';
|
|
9
|
+
const createNoopState = () => {
|
|
10
|
+
const noopCounter = { inc: () => undefined };
|
|
11
|
+
const noopHistogram = { observe: () => undefined };
|
|
12
|
+
const noopRegistry = {
|
|
13
|
+
contentType: DEFAULT_CONTENT_TYPE,
|
|
14
|
+
metrics: () => '',
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
client: {},
|
|
18
|
+
registry: noopRegistry,
|
|
19
|
+
httpRequestsTotal: noopCounter,
|
|
20
|
+
httpRequestDurationSeconds: noopHistogram,
|
|
21
|
+
dbQueriesTotal: noopCounter,
|
|
22
|
+
dbQueryDurationSeconds: noopHistogram,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
async function ensureState() {
|
|
26
|
+
if (statePromise !== null)
|
|
27
|
+
return statePromise;
|
|
28
|
+
statePromise = (async () => {
|
|
29
|
+
let client;
|
|
30
|
+
try {
|
|
31
|
+
client = await import('prom-client');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// prom-client is intentionally optional at runtime.
|
|
35
|
+
return createNoopState();
|
|
36
|
+
}
|
|
37
|
+
const registry = new client.Registry();
|
|
38
|
+
const appName = Env.get('APP_NAME', 'ZinTrust');
|
|
39
|
+
if (appName.trim() !== '') {
|
|
40
|
+
registry.setDefaultLabels({ app: appName });
|
|
41
|
+
}
|
|
42
|
+
// Default metrics (process/memory/event loop) for Node runtimes.
|
|
43
|
+
// `collectDefaultMetrics` exists in prom-client; keep this lazy and best-effort.
|
|
44
|
+
try {
|
|
45
|
+
client.collectDefaultMetrics({ register: registry });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// ignore
|
|
49
|
+
}
|
|
50
|
+
const httpRequestsTotal = new client.Counter({
|
|
51
|
+
name: 'http_requests_total',
|
|
52
|
+
help: 'Total number of HTTP requests',
|
|
53
|
+
labelNames: ['method', 'route', 'status'],
|
|
54
|
+
registers: [registry],
|
|
55
|
+
});
|
|
56
|
+
const httpRequestDurationSeconds = new client.Histogram({
|
|
57
|
+
name: 'http_request_duration_seconds',
|
|
58
|
+
help: 'HTTP request duration in seconds',
|
|
59
|
+
labelNames: ['method', 'route', 'status'],
|
|
60
|
+
// Sensible default buckets for web apps (in seconds)
|
|
61
|
+
buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
|
|
62
|
+
registers: [registry],
|
|
63
|
+
});
|
|
64
|
+
const dbQueriesTotal = new client.Counter({
|
|
65
|
+
name: 'db_queries_total',
|
|
66
|
+
help: 'Total number of database queries',
|
|
67
|
+
labelNames: ['driver'],
|
|
68
|
+
registers: [registry],
|
|
69
|
+
});
|
|
70
|
+
const dbQueryDurationSeconds = new client.Histogram({
|
|
71
|
+
name: 'db_query_duration_seconds',
|
|
72
|
+
help: 'Database query duration in seconds',
|
|
73
|
+
labelNames: ['driver'],
|
|
74
|
+
buckets: [0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5],
|
|
75
|
+
registers: [registry],
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
client,
|
|
79
|
+
registry,
|
|
80
|
+
httpRequestsTotal,
|
|
81
|
+
httpRequestDurationSeconds,
|
|
82
|
+
dbQueriesTotal,
|
|
83
|
+
dbQueryDurationSeconds,
|
|
84
|
+
};
|
|
85
|
+
})();
|
|
86
|
+
return statePromise;
|
|
87
|
+
}
|
|
88
|
+
export const PrometheusMetrics = Object.freeze({
|
|
89
|
+
async getMetricsText() {
|
|
90
|
+
const state = await ensureState();
|
|
91
|
+
const body = await state.registry.metrics();
|
|
92
|
+
const contentType = typeof state.registry.contentType === 'string'
|
|
93
|
+
? state.registry.contentType
|
|
94
|
+
: DEFAULT_CONTENT_TYPE;
|
|
95
|
+
return { contentType, body };
|
|
96
|
+
},
|
|
97
|
+
async observeHttpRequest(input) {
|
|
98
|
+
const state = await ensureState();
|
|
99
|
+
const method = input.method || 'UNKNOWN';
|
|
100
|
+
const route = input.route || 'unknown';
|
|
101
|
+
const status = Number.isFinite(input.status) ? String(input.status) : '0';
|
|
102
|
+
const durationSeconds = Math.max(0, input.durationMs / 1000);
|
|
103
|
+
state.httpRequestsTotal.inc({ method, route, status }, 1);
|
|
104
|
+
state.httpRequestDurationSeconds.observe({ method, route, status }, durationSeconds);
|
|
105
|
+
},
|
|
106
|
+
async observeDbQuery(input) {
|
|
107
|
+
const state = await ensureState();
|
|
108
|
+
const driver = input.driver || 'unknown';
|
|
109
|
+
const durationSeconds = Math.max(0, input.durationMs / 1000);
|
|
110
|
+
state.dbQueriesTotal.inc({ driver }, 1);
|
|
111
|
+
state.dbQueryDurationSeconds.observe({ driver }, durationSeconds);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
export default PrometheusMetrics;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { RouteRegistration } from '../routing/RouteRegistry';
|
|
2
|
+
type OpenApiSchema = {
|
|
3
|
+
type?: string;
|
|
4
|
+
format?: string;
|
|
5
|
+
properties?: Record<string, OpenApiSchema>;
|
|
6
|
+
required?: string[];
|
|
7
|
+
items?: OpenApiSchema;
|
|
8
|
+
enum?: Array<string | number | boolean | null>;
|
|
9
|
+
minimum?: number;
|
|
10
|
+
maximum?: number;
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
pattern?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
type OpenApiParameter = {
|
|
17
|
+
name: string;
|
|
18
|
+
in: 'path' | 'query' | 'header';
|
|
19
|
+
required: boolean;
|
|
20
|
+
schema: OpenApiSchema;
|
|
21
|
+
};
|
|
22
|
+
type OpenApiOperation = {
|
|
23
|
+
summary?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
tags?: string[];
|
|
26
|
+
operationId?: string;
|
|
27
|
+
parameters?: OpenApiParameter[];
|
|
28
|
+
requestBody?: {
|
|
29
|
+
required?: boolean;
|
|
30
|
+
content: {
|
|
31
|
+
'application/json': {
|
|
32
|
+
schema: OpenApiSchema;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
responses: Record<string, {
|
|
37
|
+
description: string;
|
|
38
|
+
content?: {
|
|
39
|
+
'application/json': {
|
|
40
|
+
schema: OpenApiSchema;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
type OpenApiDocument = {
|
|
46
|
+
openapi: '3.0.3';
|
|
47
|
+
info: {
|
|
48
|
+
title: string;
|
|
49
|
+
version: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
};
|
|
52
|
+
servers?: Array<{
|
|
53
|
+
url: string;
|
|
54
|
+
}>;
|
|
55
|
+
paths: Record<string, Record<string, OpenApiOperation>>;
|
|
56
|
+
};
|
|
57
|
+
export type OpenApiGeneratorOptions = {
|
|
58
|
+
title: string;
|
|
59
|
+
version: string;
|
|
60
|
+
description?: string;
|
|
61
|
+
serverUrl?: string;
|
|
62
|
+
excludePaths?: readonly string[];
|
|
63
|
+
};
|
|
64
|
+
export declare const OpenApiGenerator: Readonly<{
|
|
65
|
+
generate(routes: RouteRegistration[], options: OpenApiGeneratorOptions): OpenApiDocument;
|
|
66
|
+
}>;
|
|
67
|
+
export default OpenApiGenerator;
|
|
68
|
+
//# sourceMappingURL=OpenApiGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenApiGenerator.d.ts","sourceRoot":"","sources":["../../../src/openapi/OpenApiGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAoB,MAAM,wBAAwB,CAAC;AAGlF,KAAK,aAAa,GAAG;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE;YACP,kBAAkB,EAAE;gBAClB,MAAM,EAAE,aAAa,CAAC;aACvB,CAAC;SACH,CAAC;KACH,CAAC;IACF,SAAS,EAAE,MAAM,CACf,MAAM,EACN;QACE,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE;YACR,kBAAkB,EAAE;gBAClB,MAAM,EAAE,aAAa,CAAC;aACvB,CAAC;SACH,CAAC;KACH,CACF,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAkVF,eAAO,MAAM,gBAAgB;qBACV,iBAAiB,EAAE,WAAW,uBAAuB,GAAG,eAAe;EAyCxF,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
const resolveSchema = (schema) => 'getRules' in schema ? schema : schema.create();
|
|
2
|
+
const normalizeOpenApiPath = (path) => {
|
|
3
|
+
const paramNames = [];
|
|
4
|
+
const openApiPath = path.replaceAll(/:([a-zA-Z_]\w*)/g, (_match, name) => {
|
|
5
|
+
paramNames.push(name);
|
|
6
|
+
return `{${name}}`;
|
|
7
|
+
});
|
|
8
|
+
return { openApiPath, paramNames };
|
|
9
|
+
};
|
|
10
|
+
const replaceBracesSafely = (s) => {
|
|
11
|
+
let out = '';
|
|
12
|
+
let i = 0;
|
|
13
|
+
while (i < s.length) {
|
|
14
|
+
const start = s.indexOf('{', i);
|
|
15
|
+
if (start === -1) {
|
|
16
|
+
out += s.slice(i);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
const close = s.indexOf('}', start + 1);
|
|
20
|
+
if (close === -1) {
|
|
21
|
+
// No closing brace, append rest and stop.
|
|
22
|
+
out += s.slice(i);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
// Append text before '{'
|
|
26
|
+
out += s.slice(i, start);
|
|
27
|
+
// Extract the name between braces without using regex to avoid backtracking issues.
|
|
28
|
+
const name = s.slice(start + 1, close);
|
|
29
|
+
out += `_${name}_`;
|
|
30
|
+
i = close + 1;
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
};
|
|
34
|
+
const trimUnderscores = (s) => {
|
|
35
|
+
let start = 0;
|
|
36
|
+
let end = s.length - 1;
|
|
37
|
+
while (start <= end && s.charAt(start) === '_')
|
|
38
|
+
start++;
|
|
39
|
+
while (end >= start && s.charAt(end) === '_')
|
|
40
|
+
end--;
|
|
41
|
+
return start > end ? '' : s.slice(start, end + 1);
|
|
42
|
+
};
|
|
43
|
+
const operationIdFrom = (method, path) => {
|
|
44
|
+
const intermediate = replaceBracesSafely(path).replaceAll(/\W+/g, '_');
|
|
45
|
+
const safe = trimUnderscores(intermediate);
|
|
46
|
+
return `${method.toLowerCase()}_${safe}`;
|
|
47
|
+
};
|
|
48
|
+
const summarizeRules = (rules) => {
|
|
49
|
+
const summary = {
|
|
50
|
+
required: false,
|
|
51
|
+
types: new Set(),
|
|
52
|
+
constraints: {},
|
|
53
|
+
};
|
|
54
|
+
const numericConstraintMap = {
|
|
55
|
+
min: 'minimum',
|
|
56
|
+
max: 'maximum',
|
|
57
|
+
minLength: 'minLength',
|
|
58
|
+
maxLength: 'maxLength',
|
|
59
|
+
};
|
|
60
|
+
for (const r of rules) {
|
|
61
|
+
summary.types.add(r.rule);
|
|
62
|
+
if (r.rule === 'required') {
|
|
63
|
+
summary.required = true;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const numericKey = numericConstraintMap[r.rule];
|
|
67
|
+
if (numericKey && typeof r.value === 'number') {
|
|
68
|
+
// numericKey is one of 'minimum'|'maximum'|'minLength'|'maxLength', so assigning a number is safe
|
|
69
|
+
summary.constraints[numericKey] = r.value;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (r.rule === 'regex' && r.value instanceof RegExp) {
|
|
73
|
+
summary.constraints.pattern = r.value.source;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (r.rule === 'in' && Array.isArray(r.value)) {
|
|
77
|
+
summary.enumValues = r.value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return summary;
|
|
81
|
+
};
|
|
82
|
+
const openApiTypeFor = (types) => {
|
|
83
|
+
if (types.has('boolean'))
|
|
84
|
+
return { type: 'boolean' };
|
|
85
|
+
if (types.has('integer') || types.has('digits'))
|
|
86
|
+
return { type: 'integer' };
|
|
87
|
+
if (types.has('number') || types.has('decimal') || types.has('positiveNumber'))
|
|
88
|
+
return { type: 'number' };
|
|
89
|
+
if (types.has('array'))
|
|
90
|
+
return { type: 'array' };
|
|
91
|
+
if (types.has('uuid'))
|
|
92
|
+
return { type: 'string', format: 'uuid' };
|
|
93
|
+
if (types.has('email'))
|
|
94
|
+
return { type: 'string', format: 'email' };
|
|
95
|
+
if (types.has('url'))
|
|
96
|
+
return { type: 'string', format: 'uri' };
|
|
97
|
+
if (types.has('ipAddress'))
|
|
98
|
+
return { type: 'string', format: 'ipv4' };
|
|
99
|
+
if (types.has('date'))
|
|
100
|
+
return { type: 'string', format: 'date-time' };
|
|
101
|
+
if (types.size > 0)
|
|
102
|
+
return { type: 'string' };
|
|
103
|
+
return {};
|
|
104
|
+
};
|
|
105
|
+
const schemaToOpenApi = (schema) => {
|
|
106
|
+
const s = resolveSchema(schema);
|
|
107
|
+
const rules = s.getRules();
|
|
108
|
+
const properties = {};
|
|
109
|
+
const required = [];
|
|
110
|
+
for (const [field, fieldRules] of rules.entries()) {
|
|
111
|
+
const summary = summarizeRules(fieldRules);
|
|
112
|
+
const base = openApiTypeFor(summary.types);
|
|
113
|
+
const out = {
|
|
114
|
+
...base,
|
|
115
|
+
...summary.constraints,
|
|
116
|
+
};
|
|
117
|
+
if (summary.enumValues !== undefined) {
|
|
118
|
+
// Only include enum values that are JSON-serializable primitives.
|
|
119
|
+
const primitives = summary.enumValues.filter((v) => v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean');
|
|
120
|
+
if (primitives.length > 0)
|
|
121
|
+
out.enum = primitives;
|
|
122
|
+
}
|
|
123
|
+
if (out.type === 'array') {
|
|
124
|
+
// We don't have element typing information in Validator today.
|
|
125
|
+
out.items = {};
|
|
126
|
+
}
|
|
127
|
+
properties[field] = out;
|
|
128
|
+
if (summary.required)
|
|
129
|
+
required.push(field);
|
|
130
|
+
}
|
|
131
|
+
const obj = {
|
|
132
|
+
type: 'object',
|
|
133
|
+
properties,
|
|
134
|
+
};
|
|
135
|
+
if (required.length > 0)
|
|
136
|
+
obj.required = required;
|
|
137
|
+
return obj;
|
|
138
|
+
};
|
|
139
|
+
const fieldSchemasFromSchema = (schema) => {
|
|
140
|
+
const s = resolveSchema(schema);
|
|
141
|
+
const rules = s.getRules();
|
|
142
|
+
const out = {};
|
|
143
|
+
for (const [field, fieldRules] of rules.entries()) {
|
|
144
|
+
const summary = summarizeRules(fieldRules);
|
|
145
|
+
const typeInfo = openApiTypeFor(summary.types);
|
|
146
|
+
const schemaOut = {
|
|
147
|
+
...typeInfo,
|
|
148
|
+
...summary.constraints,
|
|
149
|
+
};
|
|
150
|
+
if (summary.enumValues !== undefined) {
|
|
151
|
+
const primitives = summary.enumValues.filter((v) => v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean');
|
|
152
|
+
if (primitives.length > 0)
|
|
153
|
+
schemaOut.enum = primitives;
|
|
154
|
+
}
|
|
155
|
+
if (schemaOut.type === 'array') {
|
|
156
|
+
schemaOut.items = {};
|
|
157
|
+
}
|
|
158
|
+
out[field] = schemaOut;
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
};
|
|
162
|
+
const parametersFromSchema = (schema, location) => {
|
|
163
|
+
const s = resolveSchema(schema);
|
|
164
|
+
const rules = s.getRules();
|
|
165
|
+
const params = [];
|
|
166
|
+
for (const [field, fieldRules] of rules.entries()) {
|
|
167
|
+
const summary = summarizeRules(fieldRules);
|
|
168
|
+
const typeInfo = openApiTypeFor(summary.types);
|
|
169
|
+
const schemaOut = {
|
|
170
|
+
...typeInfo,
|
|
171
|
+
...summary.constraints,
|
|
172
|
+
};
|
|
173
|
+
if (summary.enumValues !== undefined) {
|
|
174
|
+
const primitives = summary.enumValues.filter((v) => v === null || typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean');
|
|
175
|
+
if (primitives.length > 0)
|
|
176
|
+
schemaOut.enum = primitives;
|
|
177
|
+
}
|
|
178
|
+
params.push({
|
|
179
|
+
name: field,
|
|
180
|
+
in: location,
|
|
181
|
+
required: summary.required,
|
|
182
|
+
schema: schemaOut,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return params;
|
|
186
|
+
};
|
|
187
|
+
const buildPathParameters = (paramNames, paramSchemas) => paramNames.map((name) => ({
|
|
188
|
+
name,
|
|
189
|
+
in: 'path',
|
|
190
|
+
required: true,
|
|
191
|
+
schema: paramSchemas?.[name] ?? { type: 'string' },
|
|
192
|
+
}));
|
|
193
|
+
const buildOperationParameters = (meta, paramNames, paramSchemas) => {
|
|
194
|
+
const parameters = [];
|
|
195
|
+
parameters.push(...buildPathParameters(paramNames, paramSchemas));
|
|
196
|
+
if (meta?.request?.querySchema !== undefined) {
|
|
197
|
+
parameters.push(...parametersFromSchema(meta.request.querySchema, 'query'));
|
|
198
|
+
}
|
|
199
|
+
if (meta?.request?.headersSchema !== undefined) {
|
|
200
|
+
parameters.push(...parametersFromSchema(meta.request.headersSchema, 'header'));
|
|
201
|
+
}
|
|
202
|
+
return parameters.length > 0 ? parameters : undefined;
|
|
203
|
+
};
|
|
204
|
+
const buildOperationResponses = (meta) => {
|
|
205
|
+
// Default response
|
|
206
|
+
if (meta?.response === undefined ||
|
|
207
|
+
(meta.response.schema === undefined && meta.response.status === undefined)) {
|
|
208
|
+
return {
|
|
209
|
+
'200': {
|
|
210
|
+
description: 'OK',
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const status = String(meta.response.status ?? 200);
|
|
215
|
+
return {
|
|
216
|
+
[status]: {
|
|
217
|
+
description: status === '204' ? 'No Content' : 'OK',
|
|
218
|
+
...(meta.response.schema === undefined
|
|
219
|
+
? {}
|
|
220
|
+
: {
|
|
221
|
+
content: {
|
|
222
|
+
'application/json': {
|
|
223
|
+
schema: meta.response.schema,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
const createOperation = (meta, method, openApiPath, paramNames, paramSchemas) => {
|
|
231
|
+
const responses = buildOperationResponses(meta);
|
|
232
|
+
const parameters = buildOperationParameters(meta, paramNames, paramSchemas);
|
|
233
|
+
const op = {
|
|
234
|
+
summary: meta?.summary,
|
|
235
|
+
description: meta?.description,
|
|
236
|
+
tags: meta?.tags ? Array.from(meta.tags) : undefined,
|
|
237
|
+
operationId: operationIdFrom(method, openApiPath),
|
|
238
|
+
responses,
|
|
239
|
+
};
|
|
240
|
+
if (parameters !== undefined)
|
|
241
|
+
op.parameters = parameters;
|
|
242
|
+
if (meta?.request?.bodySchema !== undefined) {
|
|
243
|
+
op.requestBody = {
|
|
244
|
+
required: true,
|
|
245
|
+
content: {
|
|
246
|
+
'application/json': {
|
|
247
|
+
schema: schemaToOpenApi(meta.request.bodySchema),
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return op;
|
|
253
|
+
};
|
|
254
|
+
export const OpenApiGenerator = Object.freeze({
|
|
255
|
+
generate(routes, options) {
|
|
256
|
+
const excluded = new Set(options.excludePaths ?? []);
|
|
257
|
+
const doc = {
|
|
258
|
+
openapi: '3.0.3',
|
|
259
|
+
info: {
|
|
260
|
+
title: options.title,
|
|
261
|
+
version: options.version,
|
|
262
|
+
description: options.description,
|
|
263
|
+
},
|
|
264
|
+
paths: {},
|
|
265
|
+
};
|
|
266
|
+
if (typeof options.serverUrl === 'string' && options.serverUrl.trim() !== '') {
|
|
267
|
+
doc.servers = [{ url: options.serverUrl.trim() }];
|
|
268
|
+
}
|
|
269
|
+
for (const r of routes) {
|
|
270
|
+
if (excluded.has(r.path))
|
|
271
|
+
continue;
|
|
272
|
+
const { openApiPath, paramNames } = normalizeOpenApiPath(r.path);
|
|
273
|
+
const method = r.method.toLowerCase();
|
|
274
|
+
if (!Object.prototype.hasOwnProperty.call(doc.paths, openApiPath)) {
|
|
275
|
+
doc.paths[openApiPath] = {};
|
|
276
|
+
}
|
|
277
|
+
const meta = r.meta;
|
|
278
|
+
const paramSchemas = meta?.request?.paramsSchema === undefined
|
|
279
|
+
? undefined
|
|
280
|
+
: fieldSchemasFromSchema(meta.request.paramsSchema);
|
|
281
|
+
const op = createOperation(meta, method, openApiPath, paramNames, paramSchemas);
|
|
282
|
+
doc.paths[openApiPath][method] = op;
|
|
283
|
+
}
|
|
284
|
+
return doc;
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
export default OpenApiGenerator;
|