@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
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Request Profiler
|
|
3
3
|
* Comprehensive profiling of request execution combining query, N+1, and memory metrics
|
|
4
4
|
*/
|
|
5
|
-
import { IMemoryProfiler } from './MemoryProfiler';
|
|
6
|
-
import { IQueryLogger } from './QueryLogger';
|
|
7
|
-
import { IN1Detector, ProfileReport } from './types';
|
|
5
|
+
import type { IMemoryProfiler } from './MemoryProfiler';
|
|
6
|
+
import type { IQueryLogger } from './QueryLogger';
|
|
7
|
+
import type { IN1Detector, ProfileReport } from './types';
|
|
8
8
|
export interface IRequestProfiler {
|
|
9
9
|
getQueryLogger(): IQueryLogger;
|
|
10
10
|
getN1Detector(): IN1Detector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestProfiler.d.ts","sourceRoot":"","sources":["../../../src/profiling/RequestProfiler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"RequestProfiler.d.ts","sourceRoot":"","sources":["../../../src/profiling/RequestProfiler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAC,MAAM,2BAA2B,CAAC;AAGhE,OAAO,KAAK,EAAE,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAE1D,OAAO,KAAK,EAAE,WAAW,EAAa,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE9E,MAAM,WAAW,gBAAgB;IAC/B,cAAc,IAAI,YAAY,CAAC;IAC/B,aAAa,IAAI,WAAW,CAAC;IAC7B,iBAAiB,IAAI,eAAe,CAAC;IACrC,cAAc,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACnE,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAAC;CAChD;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;IAC1B;;OAEG;cACO,gBAAgB;EAkE1B,CAAC;AAmBH;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/routes/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { registerMetricsRoutes } from '../../routes/metrics.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Routes - Framework built-in routes
|
|
3
|
+
* Health, metrics, and documentation endpoints
|
|
4
|
+
* Not customizable by developers; provide env-based configuration
|
|
5
|
+
*/
|
|
6
|
+
import type { IRouter } from './Router';
|
|
7
|
+
/**
|
|
8
|
+
* Register all core framework routes
|
|
9
|
+
*/
|
|
10
|
+
export declare const registerCoreRoutes: (router: IRouter) => void;
|
|
11
|
+
export default registerCoreRoutes;
|
|
12
|
+
//# sourceMappingURL=CoreRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoreRoutes.d.ts","sourceRoot":"","sources":["../../../src/routing/CoreRoutes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAqJ/C;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,OAAO,KAAG,IAMpD,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Routes - Framework built-in routes
|
|
3
|
+
* Health, metrics, and documentation endpoints
|
|
4
|
+
* Not customizable by developers; provide env-based configuration
|
|
5
|
+
*/
|
|
6
|
+
import { RuntimeHealthProbes } from '../health/RuntimeHealthProbes.js';
|
|
7
|
+
import { PrometheusMetrics } from '../observability/PrometheusMetrics.js';
|
|
8
|
+
import { appConfig } from '../config/app.js';
|
|
9
|
+
import { Env } from '../config/env.js';
|
|
10
|
+
import { Logger } from '../config/logger.js';
|
|
11
|
+
import { useDatabase } from '../orm/Database.js';
|
|
12
|
+
import { QueryBuilder } from '../orm/QueryBuilder.js';
|
|
13
|
+
import { registerDocRoutes } from './doc.js';
|
|
14
|
+
import { registerErrorRoutes } from './error.js';
|
|
15
|
+
import { registerErrorPagesRoutes } from './errorPages.js';
|
|
16
|
+
import { Router } from './Router.js';
|
|
17
|
+
/**
|
|
18
|
+
* Register health endpoints
|
|
19
|
+
*/
|
|
20
|
+
async function handleHealthRoute(_req, res) {
|
|
21
|
+
const environment = Env.NODE_ENV ?? 'development';
|
|
22
|
+
try {
|
|
23
|
+
const db = useDatabase();
|
|
24
|
+
const maybeIsConnected = db.isConnected;
|
|
25
|
+
const maybeConnect = db.connect;
|
|
26
|
+
if (typeof maybeIsConnected === 'function' && maybeIsConnected.call(db) === false) {
|
|
27
|
+
if (typeof maybeConnect === 'function') {
|
|
28
|
+
await maybeConnect.call(db);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await QueryBuilder.ping(db);
|
|
32
|
+
const uptime = typeof process !== 'undefined' && typeof process.uptime === 'function' ? process.uptime() : 0;
|
|
33
|
+
res.json({
|
|
34
|
+
status: 'healthy',
|
|
35
|
+
timestamp: new Date().toISOString(),
|
|
36
|
+
uptime,
|
|
37
|
+
database: 'connected',
|
|
38
|
+
environment,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
Logger.error('Health check failed:', error);
|
|
43
|
+
const isProd = environment === 'production' || environment === 'prod';
|
|
44
|
+
res.setStatus(503).json({
|
|
45
|
+
status: 'unhealthy',
|
|
46
|
+
timestamp: new Date().toISOString(),
|
|
47
|
+
database: 'disconnected',
|
|
48
|
+
error: isProd ? 'Service unavailable' : error.message,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function handleHealthLiveRoute(_req, res) {
|
|
53
|
+
const uptime = typeof process !== 'undefined' && typeof process.uptime === 'function' ? process.uptime() : 0;
|
|
54
|
+
res.json({
|
|
55
|
+
status: 'alive',
|
|
56
|
+
timestamp: new Date().toISOString(),
|
|
57
|
+
uptime,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function handleHealthReadyRoute(_req, res) {
|
|
61
|
+
const startTime = Date.now();
|
|
62
|
+
const environment = appConfig.environment;
|
|
63
|
+
let databaseResponseTime = null;
|
|
64
|
+
let cacheResponseTime = null;
|
|
65
|
+
try {
|
|
66
|
+
const db = useDatabase();
|
|
67
|
+
const maybeIsConnected = db.isConnected;
|
|
68
|
+
const maybeConnect = db.connect;
|
|
69
|
+
if (typeof maybeIsConnected === 'function' && maybeIsConnected.call(db) === false) {
|
|
70
|
+
if (typeof maybeConnect === 'function') {
|
|
71
|
+
await maybeConnect.call(db);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
await QueryBuilder.ping(db);
|
|
75
|
+
databaseResponseTime = Date.now() - startTime;
|
|
76
|
+
cacheResponseTime = await RuntimeHealthProbes.pingKvCache(2000);
|
|
77
|
+
res.json({
|
|
78
|
+
status: 'ready',
|
|
79
|
+
timestamp: new Date().toISOString(),
|
|
80
|
+
environment,
|
|
81
|
+
dependencies: {
|
|
82
|
+
database: {
|
|
83
|
+
status: 'ready',
|
|
84
|
+
responseTime: databaseResponseTime,
|
|
85
|
+
},
|
|
86
|
+
...(cacheResponseTime === null
|
|
87
|
+
? {}
|
|
88
|
+
: {
|
|
89
|
+
cache: {
|
|
90
|
+
status: 'ready',
|
|
91
|
+
responseTime: cacheResponseTime,
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
Logger.error('Readiness check failed:', error);
|
|
99
|
+
const isProd = environment === 'production';
|
|
100
|
+
const responseTime = Date.now() - startTime;
|
|
101
|
+
const dependencies = {
|
|
102
|
+
database: {
|
|
103
|
+
status: databaseResponseTime === null ? 'unavailable' : 'ready',
|
|
104
|
+
responseTime: databaseResponseTime ?? responseTime,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
if (RuntimeHealthProbes.getCacheDriverName() === 'kv') {
|
|
108
|
+
dependencies['cache'] = {
|
|
109
|
+
status: 'unavailable',
|
|
110
|
+
responseTime: cacheResponseTime ?? responseTime,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
res.setStatus(503).json({
|
|
114
|
+
status: 'not_ready',
|
|
115
|
+
timestamp: new Date().toISOString(),
|
|
116
|
+
environment,
|
|
117
|
+
dependencies,
|
|
118
|
+
error: isProd ? 'Service unavailable' : error.message,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function registerHealthRoutes(router) {
|
|
123
|
+
Router.get(router, '/health', handleHealthRoute);
|
|
124
|
+
Router.get(router, '/health/live', handleHealthLiveRoute);
|
|
125
|
+
Router.get(router, '/health/ready', handleHealthReadyRoute);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Register metrics endpoint
|
|
129
|
+
*/
|
|
130
|
+
const registerMetricsRoutes = (router) => {
|
|
131
|
+
if (Env.getBool('METRICS_ENABLED', false) === false)
|
|
132
|
+
return;
|
|
133
|
+
const pathFromEnv = Env.get('METRICS_PATH', '/metrics').trim();
|
|
134
|
+
const metricsPath = pathFromEnv === '' ? '/metrics' : pathFromEnv;
|
|
135
|
+
Router.get(router, metricsPath, async (_req, res) => {
|
|
136
|
+
const { contentType, body } = await PrometheusMetrics.getMetricsText();
|
|
137
|
+
res.setHeader('Content-Type', contentType);
|
|
138
|
+
res.send(body);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Register all core framework routes
|
|
143
|
+
*/
|
|
144
|
+
export const registerCoreRoutes = (router) => {
|
|
145
|
+
registerHealthRoutes(router);
|
|
146
|
+
registerMetricsRoutes(router);
|
|
147
|
+
registerDocRoutes(router);
|
|
148
|
+
registerErrorPagesRoutes(router);
|
|
149
|
+
registerErrorRoutes(router);
|
|
150
|
+
};
|
|
151
|
+
export default registerCoreRoutes;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ISchema, SchemaType } from '../validation/Validator';
|
|
2
|
+
export type ValidationSchema = ISchema | SchemaType;
|
|
3
|
+
export type RouteMetaInput = RouteMeta | {
|
|
4
|
+
summary?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
tags?: readonly string[];
|
|
7
|
+
requestSchema?: ValidationSchema;
|
|
8
|
+
responseSchema?: unknown;
|
|
9
|
+
responseStatus?: number;
|
|
10
|
+
};
|
|
11
|
+
export type RouteMeta = {
|
|
12
|
+
summary?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
tags?: readonly string[];
|
|
15
|
+
request?: {
|
|
16
|
+
bodySchema?: ValidationSchema;
|
|
17
|
+
querySchema?: ValidationSchema;
|
|
18
|
+
paramsSchema?: ValidationSchema;
|
|
19
|
+
headersSchema?: ValidationSchema;
|
|
20
|
+
};
|
|
21
|
+
response?: {
|
|
22
|
+
status?: number;
|
|
23
|
+
schema?: unknown;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type RouteRegistration = {
|
|
27
|
+
method: string;
|
|
28
|
+
path: string;
|
|
29
|
+
middleware?: readonly string[];
|
|
30
|
+
meta?: RouteMeta;
|
|
31
|
+
};
|
|
32
|
+
export declare const normalizeRouteMeta: (input?: RouteMetaInput) => RouteMeta | undefined;
|
|
33
|
+
export declare const RouteRegistry: Readonly<{
|
|
34
|
+
record(route: RouteRegistration): void;
|
|
35
|
+
list(): readonly RouteRegistration[];
|
|
36
|
+
clear(): void;
|
|
37
|
+
}>;
|
|
38
|
+
export default RouteRegistry;
|
|
39
|
+
//# sourceMappingURL=RouteRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteRegistry.d.ts","sourceRoot":"","sources":["../../../src/routing/RouteRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,UAAU,CAAC;AAEpD,MAAM,MAAM,cAAc,GACtB,SAAS,GACT;IACE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEN,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEzB,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,gBAAgB,CAAC;QAC9B,WAAW,CAAC,EAAE,gBAAgB,CAAC;QAC/B,YAAY,CAAC,EAAE,gBAAgB,CAAC;QAChC,aAAa,CAAC,EAAE,gBAAgB,CAAC;KAClC,CAAC;IAEF,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,QAAQ,cAAc,KAAG,SAAS,GAAG,SAwCvE,CAAC;AAUF,eAAO,MAAM,aAAa;kBACV,iBAAiB,GAAG,IAAI;YAI9B,SAAS,iBAAiB,EAAE;aAK3B,IAAI;EAGb,CAAC;AAEH,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const normalizeRouteMeta = (input) => {
|
|
2
|
+
if (input === undefined)
|
|
3
|
+
return undefined;
|
|
4
|
+
// If it already looks like the normalized shape, return as-is.
|
|
5
|
+
if (typeof input === 'object' &&
|
|
6
|
+
input !== null &&
|
|
7
|
+
('request' in input || 'response' in input || 'summary' in input || 'tags' in input)) {
|
|
8
|
+
const any = input;
|
|
9
|
+
return any;
|
|
10
|
+
}
|
|
11
|
+
const any = input;
|
|
12
|
+
return {
|
|
13
|
+
summary: any.summary,
|
|
14
|
+
description: any.description,
|
|
15
|
+
tags: any.tags,
|
|
16
|
+
request: any.requestSchema === undefined
|
|
17
|
+
? undefined
|
|
18
|
+
: {
|
|
19
|
+
bodySchema: any.requestSchema,
|
|
20
|
+
},
|
|
21
|
+
response: any.responseSchema === undefined && any.responseStatus === undefined
|
|
22
|
+
? undefined
|
|
23
|
+
: {
|
|
24
|
+
status: any.responseStatus,
|
|
25
|
+
schema: any.responseSchema,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const state = {
|
|
30
|
+
routes: [],
|
|
31
|
+
};
|
|
32
|
+
export const RouteRegistry = Object.freeze({
|
|
33
|
+
record(route) {
|
|
34
|
+
state.routes.push(route);
|
|
35
|
+
},
|
|
36
|
+
list() {
|
|
37
|
+
// Return readonly reference to avoid unnecessary array cloning
|
|
38
|
+
return state.routes;
|
|
39
|
+
},
|
|
40
|
+
clear() {
|
|
41
|
+
state.routes.length = 0;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
export default RouteRegistry;
|
package/src/routing/Router.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { IRequest } from '../http/Request';
|
|
2
|
-
import { IResponse } from '../http/Response';
|
|
1
|
+
import type { IRequest } from '../http/Request';
|
|
2
|
+
import type { IResponse } from '../http/Response';
|
|
3
|
+
import { type RouteMeta, type RouteMetaInput } from './RouteRegistry';
|
|
3
4
|
/**
|
|
4
5
|
* Router - HTTP Routing Engine
|
|
5
6
|
* Matches incoming requests to route handlers
|
|
6
7
|
*/
|
|
7
8
|
export type RouteHandler = (req: IRequest, res: IResponse) => Promise<void> | void;
|
|
9
|
+
export type RouteOptions<MiddlewareName extends string = string> = {
|
|
10
|
+
middleware?: ReadonlyArray<MiddlewareName>;
|
|
11
|
+
meta?: RouteMetaInput;
|
|
12
|
+
};
|
|
8
13
|
export interface RouteMatch {
|
|
9
14
|
handler: RouteHandler;
|
|
10
15
|
params: Record<string, string>;
|
|
16
|
+
middleware?: string[];
|
|
17
|
+
meta?: RouteMeta;
|
|
18
|
+
routePath?: string;
|
|
11
19
|
}
|
|
12
20
|
export interface Route {
|
|
13
21
|
method: string;
|
|
@@ -15,6 +23,8 @@ export interface Route {
|
|
|
15
23
|
pattern: RegExp;
|
|
16
24
|
handler: RouteHandler;
|
|
17
25
|
paramNames: string[];
|
|
26
|
+
middleware?: string[];
|
|
27
|
+
meta?: RouteMeta;
|
|
18
28
|
}
|
|
19
29
|
export type RouteGroupCallback = (router: IRouter) => void;
|
|
20
30
|
export interface ResourceController {
|
|
@@ -24,6 +34,13 @@ export interface ResourceController {
|
|
|
24
34
|
update?: RouteHandler;
|
|
25
35
|
destroy?: RouteHandler;
|
|
26
36
|
}
|
|
37
|
+
export type ResourceOptions<MiddlewareName extends string = string> = RouteOptions<MiddlewareName> & {
|
|
38
|
+
index?: RouteOptions<MiddlewareName>;
|
|
39
|
+
show?: RouteOptions<MiddlewareName>;
|
|
40
|
+
store?: RouteOptions<MiddlewareName>;
|
|
41
|
+
update?: RouteOptions<MiddlewareName>;
|
|
42
|
+
destroy?: RouteOptions<MiddlewareName>;
|
|
43
|
+
};
|
|
27
44
|
export type IRouter = {
|
|
28
45
|
routes: Route[];
|
|
29
46
|
prefix: string;
|
|
@@ -38,13 +55,13 @@ export declare const Router: Readonly<{
|
|
|
38
55
|
createRouter: () => IRouter;
|
|
39
56
|
scopeRouter: (router: IRouter, prefix: string) => IRouter;
|
|
40
57
|
group: (router: IRouter, prefix: string, callback: RouteGroupCallback) => void;
|
|
41
|
-
resource: (router: IRouter, path: string, controller: ResourceController) => void;
|
|
42
|
-
get: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
43
|
-
post: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
44
|
-
put: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
45
|
-
patch: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
46
|
-
del: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
47
|
-
any: (router: IRouter, path: string, handler: RouteHandler) => void;
|
|
58
|
+
resource: <M extends string = string>(router: IRouter, path: string, controller: ResourceController, options?: ResourceOptions<M>) => void;
|
|
59
|
+
get: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
60
|
+
post: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
61
|
+
put: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
62
|
+
patch: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
63
|
+
del: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
64
|
+
any: <M extends string = string>(router: IRouter, path: string, handler: RouteHandler, options?: RouteOptions<M>) => void;
|
|
48
65
|
match: (router: IRouter, method: string, path: string) => RouteMatch | null;
|
|
49
66
|
getRoutes: (router: IRouter) => Route[];
|
|
50
67
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../src/routing/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../src/routing/Router.ts"],"names":[],"mappings":"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"}
|
package/src/routing/Router.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RouteRegistry, normalizeRouteMeta, } from './RouteRegistry.js';
|
|
1
2
|
export const createRouter = () => ({
|
|
2
3
|
routes: [],
|
|
3
4
|
prefix: '',
|
|
@@ -13,9 +14,13 @@ export const createRouter = () => ({
|
|
|
13
14
|
*/
|
|
14
15
|
const pathToRegex = (path) => {
|
|
15
16
|
const paramNames = [];
|
|
16
|
-
|
|
17
|
+
// Supports:
|
|
18
|
+
// - :id => single path segment (no slashes)
|
|
19
|
+
// - :path* => greedy match (may include slashes)
|
|
20
|
+
let regexPath = path.replaceAll(/:([a-zA-Z_]\w*)(\*)?/g, (_full, paramName, star) => {
|
|
17
21
|
paramNames.push(paramName);
|
|
18
|
-
|
|
22
|
+
const isGreedy = star === '*';
|
|
23
|
+
return isGreedy ? '(.+)' : '([^/]+)';
|
|
19
24
|
});
|
|
20
25
|
regexPath = `^${regexPath}$`;
|
|
21
26
|
const pattern = new RegExp(regexPath);
|
|
@@ -24,7 +29,7 @@ const pathToRegex = (path) => {
|
|
|
24
29
|
/**
|
|
25
30
|
* Register a route
|
|
26
31
|
*/
|
|
27
|
-
const registerRoute = (router, method, path, handler) => {
|
|
32
|
+
const registerRoute = (router, method, path, handler, options) => {
|
|
28
33
|
const { pattern, paramNames } = pathToRegex(path);
|
|
29
34
|
const route = {
|
|
30
35
|
method,
|
|
@@ -32,8 +37,16 @@ const registerRoute = (router, method, path, handler) => {
|
|
|
32
37
|
pattern,
|
|
33
38
|
handler,
|
|
34
39
|
paramNames,
|
|
40
|
+
middleware: Array.isArray(options?.middleware) ? options?.middleware : undefined,
|
|
41
|
+
meta: normalizeRouteMeta(options?.meta),
|
|
35
42
|
};
|
|
36
43
|
router.routes.push(route);
|
|
44
|
+
RouteRegistry.record({
|
|
45
|
+
method,
|
|
46
|
+
path,
|
|
47
|
+
middleware: route.middleware,
|
|
48
|
+
meta: route.meta,
|
|
49
|
+
});
|
|
37
50
|
// Index by method for faster lookup
|
|
38
51
|
if (!router.routeIndex.has(method)) {
|
|
39
52
|
router.routeIndex.set(method, []);
|
|
@@ -54,6 +67,9 @@ const getRouteMatch = (route, path) => {
|
|
|
54
67
|
return {
|
|
55
68
|
handler: route.handler,
|
|
56
69
|
params,
|
|
70
|
+
middleware: route.middleware,
|
|
71
|
+
meta: route.meta,
|
|
72
|
+
routePath: route.path,
|
|
57
73
|
};
|
|
58
74
|
};
|
|
59
75
|
/**
|
|
@@ -131,41 +147,69 @@ const scopeRouter = (router, prefix) => ({
|
|
|
131
147
|
const group = (router, prefix, callback) => {
|
|
132
148
|
callback(scopeRouter(router, prefix));
|
|
133
149
|
};
|
|
134
|
-
|
|
135
|
-
const base = joinPaths(
|
|
150
|
+
function buildResourcePaths(prefix, path) {
|
|
151
|
+
const base = joinPaths(prefix, path);
|
|
136
152
|
const withId = `${base.endsWith('/') ? base.slice(0, -1) : base}/:id`;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (controller.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
return { base, withId };
|
|
154
|
+
}
|
|
155
|
+
function resolveResourceDefaultOptions(options) {
|
|
156
|
+
return options?.middleware ? { middleware: options.middleware } : undefined;
|
|
157
|
+
}
|
|
158
|
+
function registerResourceIndex(router, base, controller, options, defaultOptions) {
|
|
159
|
+
if (!controller.index)
|
|
160
|
+
return;
|
|
161
|
+
registerRoute(router, 'GET', base, controller.index, options?.index ?? defaultOptions);
|
|
162
|
+
}
|
|
163
|
+
function registerResourceStore(router, base, controller, options, defaultOptions) {
|
|
164
|
+
if (!controller.store)
|
|
165
|
+
return;
|
|
166
|
+
registerRoute(router, 'POST', base, controller.store, options?.store ?? defaultOptions);
|
|
167
|
+
}
|
|
168
|
+
function registerResourceShow(router, withId, controller, options, defaultOptions) {
|
|
169
|
+
if (!controller.show)
|
|
170
|
+
return;
|
|
171
|
+
registerRoute(router, 'GET', withId, controller.show, options?.show ?? defaultOptions);
|
|
172
|
+
}
|
|
173
|
+
function registerResourceUpdate(router, withId, controller, options, defaultOptions) {
|
|
174
|
+
if (!controller.update)
|
|
175
|
+
return;
|
|
176
|
+
const updateOptions = options?.update ?? defaultOptions;
|
|
177
|
+
registerRoute(router, 'PUT', withId, controller.update, updateOptions);
|
|
178
|
+
registerRoute(router, 'PATCH', withId, controller.update, updateOptions);
|
|
179
|
+
}
|
|
180
|
+
function registerResourceDestroy(router, withId, controller, options, defaultOptions) {
|
|
181
|
+
if (!controller.destroy)
|
|
182
|
+
return;
|
|
183
|
+
registerRoute(router, 'DELETE', withId, controller.destroy, options?.destroy ?? defaultOptions);
|
|
184
|
+
}
|
|
185
|
+
const resource = (router, path, controller, options) => {
|
|
186
|
+
const { base, withId } = buildResourcePaths(router.prefix, path);
|
|
187
|
+
const defaultOptions = resolveResourceDefaultOptions(options);
|
|
188
|
+
registerResourceIndex(router, base, controller, options, defaultOptions);
|
|
189
|
+
registerResourceStore(router, base, controller, options, defaultOptions);
|
|
190
|
+
registerResourceShow(router, withId, controller, options, defaultOptions);
|
|
191
|
+
registerResourceUpdate(router, withId, controller, options, defaultOptions);
|
|
192
|
+
registerResourceDestroy(router, withId, controller, options, defaultOptions);
|
|
193
|
+
};
|
|
194
|
+
const get = (router, path, handler, options) => {
|
|
195
|
+
registerRoute(router, 'GET', joinPaths(router.prefix, path), handler, options);
|
|
196
|
+
};
|
|
197
|
+
const post = (router, path, handler, options) => {
|
|
198
|
+
registerRoute(router, 'POST', joinPaths(router.prefix, path), handler, options);
|
|
199
|
+
};
|
|
200
|
+
const put = (router, path, handler, options) => {
|
|
201
|
+
registerRoute(router, 'PUT', joinPaths(router.prefix, path), handler, options);
|
|
202
|
+
};
|
|
203
|
+
const patch = (router, path, handler, options) => {
|
|
204
|
+
registerRoute(router, 'PATCH', joinPaths(router.prefix, path), handler, options);
|
|
205
|
+
};
|
|
206
|
+
const del = (router, path, handler, options) => {
|
|
207
|
+
registerRoute(router, 'DELETE', joinPaths(router.prefix, path), handler, options);
|
|
208
|
+
};
|
|
209
|
+
const any = (router, path, handler, options) => {
|
|
166
210
|
const fullPath = joinPaths(router.prefix, path);
|
|
167
211
|
['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].forEach((method) => {
|
|
168
|
-
registerRoute(router, method, fullPath, handler);
|
|
212
|
+
registerRoute(router, method, fullPath, handler, options);
|
|
169
213
|
});
|
|
170
214
|
};
|
|
171
215
|
const match = (router, method, path) => matchRoute(router, method, path);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing Common Utilities
|
|
3
|
+
* Shared helpers for static routes and content-type resolution.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* MIME types for static file serving.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MIME_TYPES_MAP: Record<string, string>;
|
|
9
|
+
export declare const tryDecodeURIComponent: (value: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a relative path against a base directory and ensures it stays within it.
|
|
12
|
+
* Returns undefined if the resolved path escapes the base.
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveSafePath: (baseDir: string, relativePath: string) => string | undefined;
|
|
15
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/routing/common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAgBjD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,OAAO,MAAM,KAAG,MAMrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,cAAc,MAAM,KAAG,MAAM,GAAG,SAQhF,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Routing Common Utilities
|
|
3
|
+
* Shared helpers for static routes and content-type resolution.
|
|
4
|
+
*/
|
|
5
|
+
import { MIME_TYPES } from '../config/constants.js';
|
|
6
|
+
import * as path from '../node-singletons/path.js';
|
|
7
|
+
/**
|
|
8
|
+
* MIME types for static file serving.
|
|
9
|
+
*/
|
|
10
|
+
export const MIME_TYPES_MAP = {
|
|
11
|
+
'.html': MIME_TYPES.HTML,
|
|
12
|
+
'.js': MIME_TYPES.JS,
|
|
13
|
+
'.css': MIME_TYPES.CSS,
|
|
14
|
+
'.json': MIME_TYPES.JSON,
|
|
15
|
+
'.png': MIME_TYPES.PNG,
|
|
16
|
+
'.jpg': MIME_TYPES.JPG,
|
|
17
|
+
'.gif': MIME_TYPES.GIF,
|
|
18
|
+
'.svg': MIME_TYPES.SVG,
|
|
19
|
+
'.wav': MIME_TYPES.WAV,
|
|
20
|
+
'.mp4': MIME_TYPES.MP4,
|
|
21
|
+
'.woff': MIME_TYPES.WOFF,
|
|
22
|
+
'.ttf': MIME_TYPES.TTF,
|
|
23
|
+
'.eot': MIME_TYPES.EOT,
|
|
24
|
+
'.otf': MIME_TYPES.OTF,
|
|
25
|
+
'.wasm': MIME_TYPES.WASM,
|
|
26
|
+
};
|
|
27
|
+
export const tryDecodeURIComponent = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
return decodeURIComponent(value);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Resolves a relative path against a base directory and ensures it stays within it.
|
|
37
|
+
* Returns undefined if the resolved path escapes the base.
|
|
38
|
+
*/
|
|
39
|
+
export const resolveSafePath = (baseDir, relativePath) => {
|
|
40
|
+
const baseAbs = path.resolve(baseDir);
|
|
41
|
+
const candidate = path.resolve(baseDir, relativePath);
|
|
42
|
+
if (candidate === baseAbs)
|
|
43
|
+
return candidate;
|
|
44
|
+
if (!candidate.startsWith(baseAbs + path.sep))
|
|
45
|
+
return undefined;
|
|
46
|
+
return candidate;
|
|
47
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documentation Routes
|
|
3
|
+
* Serves static files from /doc/* paths with relaxed CSP headers.
|
|
4
|
+
*/
|
|
5
|
+
import type { IResponse } from '../http/Response';
|
|
6
|
+
import type { IRouter } from './Router';
|
|
7
|
+
export { MIME_TYPES_MAP } from './common';
|
|
8
|
+
/**
|
|
9
|
+
* Find the package root directory
|
|
10
|
+
*/
|
|
11
|
+
export { findPackageRoot, findPackageRootAsync, getFrameworkPublicRoots, getFrameworkPublicRootsAsync, getPublicRoot, getPublicRootAsync, } from './publicRoot';
|
|
12
|
+
/**
|
|
13
|
+
* Set relaxed CSP headers for docs (allows external assets like Tailwind CDN, Google Fonts)
|
|
14
|
+
*/
|
|
15
|
+
export declare const setDocumentationCSPHeaders: (response: IResponse) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Serve a documentation static file (async)
|
|
18
|
+
*/
|
|
19
|
+
export declare const serveDocumentationFileAsync: (urlPath: string, response: IResponse) => Promise<boolean>;
|
|
20
|
+
export declare const registerDocRoutes: (router: IRouter) => void;
|
|
21
|
+
declare const _default: {
|
|
22
|
+
registerDocRoutes: (router: IRouter) => void;
|
|
23
|
+
setDocumentationCSPHeaders: (response: IResponse) => void;
|
|
24
|
+
serveDocumentationFileAsync: (urlPath: string, response: IResponse) => Promise<boolean>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
27
|
+
//# sourceMappingURL=doc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../../src/routing/doc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;GAEG;AAEH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,4BAA4B,EAC5B,aAAa,EACb,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAiB7B;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,UAAU,SAAS,KAAG,IAWhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GACtC,SAAS,MAAM,EACf,UAAU,SAAS,KAClB,OAAO,CAAC,OAAO,CAgDjB,CAAC;AASF,eAAO,MAAM,iBAAiB,GAAI,QAAQ,OAAO,KAAG,IAMnD,CAAC;;gCANwC,OAAO,KAAG,IAAI;2CA5EH,SAAS,KAAG,IAAI;2CAiB1D,MAAM,YACL,SAAS,KAClB,OAAO,CAAC,OAAO,CAAC;;AAiEnB,wBAIE"}
|