raiton 6.8.9-beta.25 → 6.11.0-beta.29
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/CHANGELOG.md +67 -0
- package/README.md +65 -1
- package/benchmarks/README.md +31 -0
- package/benchmarks/ai-debug.json +145 -0
- package/benchmarks/ai-debug.md +64 -0
- package/benchmarks/latest.json +172 -0
- package/benchmarks/latest.md +66 -0
- package/build/bin/index.mjs +37621 -21866
- package/build/types/bin/bootstrapper.d.ts +2 -0
- package/build/types/bin/cli-output.d.ts +46 -0
- package/build/types/bin/cli-tools.d.ts +13 -0
- package/build/types/bin/cli.d.ts +3 -0
- package/build/types/bin/commands.registry.d.ts +4 -0
- package/build/types/bin/constants.d.ts +3 -0
- package/build/types/bin/file-utils.d.ts +21 -0
- package/build/types/bin/index.d.ts +2 -0
- package/build/types/bin/name-utils.d.ts +4 -0
- package/build/types/bin/project-utils.d.ts +12 -0
- package/build/types/commands/artifact.command.d.ts +7 -0
- package/build/types/commands/build.command.d.ts +8 -0
- package/build/types/commands/call.command.d.ts +10 -0
- package/build/types/commands/client.command.d.ts +7 -0
- package/build/types/commands/contract.command.d.ts +8 -0
- package/build/types/commands/debug.shared.d.ts +16 -0
- package/build/types/commands/develop.command.d.ts +9 -0
- package/build/types/commands/docs.command.d.ts +8 -0
- package/build/types/commands/doctor.command.d.ts +9 -0
- package/build/types/commands/explain.command.d.ts +8 -0
- package/build/types/commands/generate.command.d.ts +7 -0
- package/build/types/commands/inspect.command.d.ts +7 -0
- package/build/types/commands/mcp.command.d.ts +12 -0
- package/build/types/commands/new.command.d.ts +7 -0
- package/build/types/commands/openapi.command.d.ts +7 -0
- package/build/types/commands/requests.command.d.ts +8 -0
- package/build/types/commands/routes.command.d.ts +7 -0
- package/build/types/commands/start.command.d.ts +9 -0
- package/build/types/commands/verify.command.d.ts +8 -0
- package/build/types/commands/why.command.d.ts +7 -0
- package/build/types/contracts/decorators.d.ts +59 -0
- package/build/types/contracts/errors.d.ts +68 -0
- package/build/types/contracts/index.d.ts +4 -0
- package/build/types/contracts/schema.d.ts +83 -0
- package/build/types/contracts/typebox.d.ts +81 -0
- package/build/types/core/application.d.ts +45 -0
- package/build/types/core/artifacts/artifact.d.ts +3 -0
- package/build/types/core/artifacts/index.d.ts +1 -0
- package/build/types/core/artifacts/runner.d.ts +1 -0
- package/build/types/core/builder.d.ts +42 -0
- package/build/types/core/bytes.util.d.ts +3 -0
- package/build/types/core/command.d.ts +13 -0
- package/build/types/core/commands.d.ts +10 -0
- package/build/types/core/config/config.d.ts +27 -0
- package/build/types/core/config/define.d.ts +8 -0
- package/build/types/core/config/index.d.ts +3 -0
- package/build/types/core/config/schema.d.ts +24 -0
- package/build/types/core/context.d.ts +11 -0
- package/build/types/core/controller/builder.d.ts +26 -0
- package/build/types/core/controller/compiler.d.ts +2 -0
- package/build/types/core/controller/index.d.ts +4 -0
- package/build/types/core/controller/metadata.d.ts +3 -0
- package/build/types/core/controller/tracker.d.ts +9 -0
- package/build/types/core/directories.d.ts +10 -0
- package/build/types/core/guards.d.ts +11 -0
- package/build/types/core/helpers/index.d.ts +1 -0
- package/build/types/core/helpers/raiton.d.ts +1 -0
- package/build/types/core/hooks.d.ts +14 -0
- package/build/types/core/index.d.ts +17 -0
- package/build/types/core/injection/index.d.ts +1 -0
- package/build/types/core/injection/injection.d.ts +37 -0
- package/build/types/core/mcp/builder.d.ts +2 -0
- package/build/types/core/mcp/index.d.ts +3 -0
- package/build/types/core/mcp/metadata.d.ts +9 -0
- package/build/types/core/mcp/tracker.d.ts +9 -0
- package/build/types/core/middleware/compose.d.ts +8 -0
- package/build/types/core/middleware/index.d.ts +2 -0
- package/build/types/core/middleware/pipeline.d.ts +12 -0
- package/build/types/core/plugins/index.d.ts +2 -0
- package/build/types/core/plugins/plugin.d.ts +2 -0
- package/build/types/core/plugins/scope.d.ts +15 -0
- package/build/types/core/process.util.d.ts +1 -0
- package/build/types/core/raiton.d.ts +15 -0
- package/build/types/core/router/handler.d.ts +2 -0
- package/build/types/core/router/handler.utils.d.ts +37 -0
- package/build/types/core/router/index.d.ts +4 -0
- package/build/types/core/router/matcher.d.ts +50 -0
- package/build/types/core/router/route.d.ts +52 -0
- package/build/types/core/router/router.d.ts +23 -0
- package/build/types/core/scheduler/builder.d.ts +2 -0
- package/build/types/core/scheduler/cron.d.ts +32 -0
- package/build/types/core/scheduler/duration.d.ts +7 -0
- package/build/types/core/scheduler/index.d.ts +6 -0
- package/build/types/core/scheduler/manager.d.ts +47 -0
- package/build/types/core/scheduler/metadata.d.ts +8 -0
- package/build/types/core/scheduler/queue/backend.d.ts +42 -0
- package/build/types/core/scheduler/queue/index.d.ts +3 -0
- package/build/types/core/scheduler/queue/rabbitmq.backend.d.ts +37 -0
- package/build/types/core/scheduler/queue/redis.backend.d.ts +38 -0
- package/build/types/core/server.d.ts +9 -0
- package/build/types/core/socket/builder.d.ts +1 -0
- package/build/types/core/socket/index.d.ts +2 -0
- package/build/types/core/socket/metadata.d.ts +14 -0
- package/build/types/core/thread.d.ts +21 -0
- package/build/types/debug/cli.d.ts +33 -0
- package/build/types/debug/collector.d.ts +41 -0
- package/build/types/debug/collector.internal.d.ts +27 -0
- package/build/types/debug/config.d.ts +19 -0
- package/build/types/debug/examples.d.ts +43 -0
- package/build/types/debug/explain.d.ts +9 -0
- package/build/types/debug/index.d.ts +15 -0
- package/build/types/debug/invocation.d.ts +53 -0
- package/build/types/debug/journal.d.ts +49 -0
- package/build/types/debug/mcp-http.d.ts +17 -0
- package/build/types/debug/mcp.d.ts +14 -0
- package/build/types/debug/redaction.d.ts +48 -0
- package/build/types/debug/requests.d.ts +37 -0
- package/build/types/debug/runtime.d.ts +52 -0
- package/build/types/debug/session.d.ts +21 -0
- package/build/types/debug/source.d.ts +17 -0
- package/build/types/debug/surface.d.ts +10 -0
- package/build/types/debug/types.d.ts +271 -0
- package/build/types/debug/verify.d.ts +23 -0
- package/build/types/framework/artifacts.d.ts +20 -0
- package/build/types/framework/cache/cache.d.ts +84 -0
- package/build/types/framework/cache/cache.decorator.d.ts +21 -0
- package/build/types/framework/cache/etag.d.ts +62 -0
- package/build/types/framework/cache/index.d.ts +4 -0
- package/build/types/framework/cache/types.d.ts +89 -0
- package/build/types/framework/constants/decorators.constant.d.ts +28 -0
- package/build/types/framework/constants/index.d.ts +2 -0
- package/build/types/framework/constants/microservices.constant.d.ts +3 -0
- package/build/types/framework/controllers.d.ts +2 -0
- package/build/types/framework/data-transfer-object.d.ts +5 -0
- package/build/types/framework/decorators/access-guard.decorator.d.ts +1 -0
- package/build/types/framework/decorators/api-response.decorator.d.ts +66 -0
- package/build/types/framework/decorators/api.decorator.d.ts +160 -0
- package/build/types/framework/decorators/controllable.decorator.d.ts +3 -0
- package/build/types/framework/decorators/csrf-guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/csrf-token.decorator.d.ts +1 -0
- package/build/types/framework/decorators/guard.decorator.d.ts +2 -0
- package/build/types/framework/decorators/health-check.decorator.d.ts +17 -0
- package/build/types/framework/decorators/index.d.ts +15 -0
- package/build/types/framework/decorators/injection.decorator.d.ts +5 -0
- package/build/types/framework/decorators/mcp.decorator.d.ts +68 -0
- package/build/types/framework/decorators/middleware.decorator.d.ts +3 -0
- package/build/types/framework/decorators/parametrable.decorator.d.ts +9 -0
- package/build/types/framework/decorators/routable.decorator.d.ts +12 -0
- package/build/types/framework/decorators/route-interaction.decorator.d.ts +81 -0
- package/build/types/framework/decorators/scheduler.decorator.d.ts +54 -0
- package/build/types/framework/decorators/socket.decorator.d.ts +5 -0
- package/build/types/framework/encryption.d.ts +25 -0
- package/build/types/framework/enums/csrf.enum.d.ts +4 -0
- package/build/types/framework/enums/encrypted.enum.d.ts +20 -0
- package/build/types/framework/enums/event.message.enum.d.ts +4 -0
- package/build/types/framework/enums/http-method.enum.d.ts +10 -0
- package/build/types/framework/enums/http-parameters.enum.d.ts +11 -0
- package/build/types/framework/enums/http-status.enum.d.ts +64 -0
- package/build/types/framework/enums/index.d.ts +9 -0
- package/build/types/framework/enums/runtime.enum.d.ts +5 -0
- package/build/types/framework/enums/scheduler.enum.d.ts +21 -0
- package/build/types/framework/enums/timestamp.enum.d.ts +6 -0
- package/build/types/framework/env.d.ts +3 -0
- package/build/types/framework/errors/catalog.d.ts +57 -0
- package/build/types/framework/exceptions/http-exception.d.ts +18 -0
- package/build/types/framework/exceptions/index.d.ts +2 -0
- package/build/types/framework/exceptions/throwable.d.ts +76 -0
- package/build/types/framework/health-check.d.ts +42 -0
- package/build/types/framework/index.d.ts +20 -0
- package/build/types/framework/mcp/audit.d.ts +12 -0
- package/build/types/framework/mcp/conformance.d.ts +31 -0
- package/build/types/framework/mcp/handler.d.ts +11 -0
- package/build/types/framework/mcp/index.d.ts +5 -0
- package/build/types/framework/mcp/protocol.d.ts +17 -0
- package/build/types/framework/mcp/rate-limit.d.ts +10 -0
- package/build/types/framework/mcp/stdio.d.ts +40 -0
- package/build/types/framework/mcp/streamable-http.d.ts +17 -0
- package/build/types/framework/observability/index.d.ts +6 -0
- package/build/types/framework/observability/metrics.d.ts +23 -0
- package/build/types/framework/observability/plugin.d.ts +20 -0
- package/build/types/framework/observability/readiness.d.ts +9 -0
- package/build/types/framework/observability/request.d.ts +7 -0
- package/build/types/framework/observability/shutdown.d.ts +21 -0
- package/build/types/framework/observability/trace.d.ts +96 -0
- package/build/types/framework/parameter-bag.d.ts +14 -0
- package/build/types/framework/plugins/body-parser.plugin.d.ts +3 -0
- package/build/types/framework/plugins/dev.plugin.d.ts +12 -0
- package/build/types/framework/plugins/index.d.ts +5 -0
- package/build/types/framework/plugins/mcp.plugin.d.ts +15 -0
- package/build/types/framework/plugins/openapi.plugin.d.ts +58 -0
- package/build/types/framework/plugins/security/body-limit.d.ts +1 -0
- package/build/types/framework/plugins/security/cors.d.ts +10 -0
- package/build/types/framework/plugins/security/csrf.d.ts +2 -0
- package/build/types/framework/plugins/security/headers.d.ts +1 -0
- package/build/types/framework/plugins/security/index.d.ts +13 -0
- package/build/types/framework/plugins/security/method-guard.d.ts +1 -0
- package/build/types/framework/plugins/security/rate-limit.d.ts +5 -0
- package/build/types/framework/repositories.d.ts +5 -0
- package/build/types/framework/responses/error.d.ts +13 -0
- package/build/types/framework/responses/helpers.d.ts +7 -0
- package/build/types/framework/responses/http-throwable.d.ts +14 -0
- package/build/types/framework/responses/http.d.ts +13 -0
- package/build/types/framework/responses/index.d.ts +4 -0
- package/build/types/framework/runtime/bun/server.d.ts +2 -0
- package/build/types/framework/runtime/deno/server.d.ts +2 -0
- package/build/types/framework/runtime/index.d.ts +17 -0
- package/build/types/framework/runtime/node/reply.d.ts +12 -0
- package/build/types/framework/runtime/node/request.d.ts +33 -0
- package/build/types/framework/runtime/node/server.d.ts +2 -0
- package/build/types/framework/runtime/web/server.d.ts +1 -0
- package/build/types/framework/services.d.ts +5 -0
- package/build/types/framework/utilities/alias-path.util.d.ts +1 -0
- package/build/types/framework/utilities/artifact.util.d.ts +7 -0
- package/build/types/framework/utilities/callable.util.d.ts +1 -0
- package/build/types/framework/utilities/cookie.util.d.ts +1 -0
- package/build/types/framework/utilities/csrf.util.d.ts +26 -0
- package/build/types/framework/utilities/https.util.d.ts +49 -0
- package/build/types/framework/utilities/index.d.ts +12 -0
- package/build/types/framework/utilities/ip.util.d.ts +15 -0
- package/build/types/framework/utilities/json.util.d.ts +10 -0
- package/build/types/framework/utilities/openapi.utils.d.ts +7 -0
- package/build/types/framework/utilities/openapi.utils.impl.d.ts +18 -0
- package/build/types/framework/utilities/path.util.d.ts +3 -0
- package/build/types/framework/utilities/route-suggestion.util.d.ts +10 -0
- package/build/types/framework/utilities/url.util.d.ts +1 -0
- package/build/types/framework/utilities/utilities.util.d.ts +3 -0
- package/build/types/framework/utilities/validation.util.d.ts +8 -0
- package/build/types/framework/view-model.d.ts +4 -0
- package/build/types/generators/artifact.templates.d.ts +7 -0
- package/build/types/generators/index.d.ts +2 -0
- package/build/types/generators/project.templates.d.ts +21 -0
- package/build/types/manifest/client.d.ts +12 -0
- package/build/types/manifest/contract.d.ts +25 -0
- package/build/types/manifest/index.d.ts +5 -0
- package/build/types/manifest/introspect.d.ts +18 -0
- package/build/types/manifest/manifest.d.ts +18 -0
- package/build/types/manifest/schema.d.ts +241 -0
- package/build/types/requirements.d.ts +1 -0
- package/build/types/types/access-guards.d.ts +4 -0
- package/build/types/types/application.d.ts +32 -0
- package/build/types/types/artifact.d.ts +8 -0
- package/build/types/types/builder.d.ts +37 -0
- package/build/types/types/config.d.ts +112 -0
- package/build/types/types/controller.d.ts +27 -0
- package/build/types/types/contruct.d.ts +1 -0
- package/build/types/types/core.d.ts +11 -0
- package/build/types/types/csrf.d.ts +33 -0
- package/build/types/types/directory.d.ts +6 -0
- package/build/types/types/encryption.d.ts +14 -0
- package/build/types/types/generic.d.ts +2 -0
- package/build/types/types/guard.d.ts +9 -0
- package/build/types/types/http-responses.d.ts +7 -0
- package/build/types/types/index.d.ts +27 -0
- package/build/types/types/injection.d.ts +11 -0
- package/build/types/types/lifecycle.d.ts +9 -0
- package/build/types/types/mcp.d.ts +148 -0
- package/build/types/types/middleware.d.ts +12 -0
- package/build/types/types/parseable.d.ts +3 -0
- package/build/types/types/plugin.d.ts +6 -0
- package/build/types/types/raiton.d.ts +13 -0
- package/build/types/types/responses.d.ts +20 -0
- package/build/types/types/router.d.ts +13 -0
- package/build/types/types/runtime.d.ts +48 -0
- package/build/types/types/scheduler.d.ts +140 -0
- package/build/types/types/scheme.d.ts +125 -0
- package/build/types/types/server.d.ts +10 -0
- package/build/types/types/socket.d.ts +11 -0
- package/build/types/types/thread.d.ts +25 -0
- package/build/types/types/utilities.d.ts +4 -0
- package/build/types/types/values.d.ts +2 -0
- package/docs/AGENTS.md +55 -0
- package/docs/CLAUDE.md +55 -0
- package/docs/README.md +5 -0
- package/docs/contributors/cli/README.md +17 -3
- package/docs/contributors/cli/commands.md +28 -17
- package/docs/contributors/framework/plugins/openapi.md +12 -3
- package/docs/generated/cli/commands.md +31 -0
- package/docs/generated/config-schema.json +243 -0
- package/docs/generated/manifest-schema.json +312 -0
- package/docs/generated/manifest.json +118 -0
- package/docs/llms-full.txt +1450 -0
- package/docs/llms.txt +51 -0
- package/docs/user-guide/README.md +19 -12
- package/docs/user-guide/cli.md +26 -0
- package/docs/user-guide/config.md +32 -0
- package/docs/user-guide/contracts.md +67 -0
- package/docs/user-guide/debug.md +130 -0
- package/docs/user-guide/en/README.md +83 -0
- package/docs/user-guide/getting-started.md +13 -1
- package/docs/user-guide/mcp.md +45 -2
- package/docs/user-guide/observability.md +74 -0
- package/docs/user-guide/openapi/plugin.md +10 -0
- package/docs/user-guide/recipes/README.md +32 -0
- package/docs/user-guide/recipes/contracts.md +52 -0
- package/docs/user-guide/recipes/doctor.md +16 -0
- package/docs/user-guide/recipes/generate.md +28 -0
- package/docs/user-guide/recipes/manifest.md +17 -0
- package/docs/user-guide/recipes/mcp-stdio.md +35 -0
- package/docs/user-guide/recipes/new-project.md +34 -0
- package/docs/user-guide/recipes/observability.md +17 -0
- package/package.json +42 -7
- package/scripts/bench-ai-debug.ts +572 -0
- package/scripts/bench.ts +586 -0
- package/scripts/postinstall.mjs +15 -0
- package/source/bin/cli-output.ts +139 -0
- package/source/bin/commands.registry.ts +31 -3
- package/source/bin/file-utils.ts +95 -0
- package/source/bin/name-utils.ts +26 -0
- package/source/bin/project-utils.ts +78 -0
- package/source/commands/artifact.command.ts +30 -15
- package/source/commands/call.command.ts +247 -0
- package/source/commands/client.command.ts +64 -0
- package/source/commands/contract.command.ts +104 -0
- package/source/commands/debug.shared.ts +90 -0
- package/source/commands/docs.command.ts +269 -0
- package/source/commands/doctor.command.ts +226 -0
- package/source/commands/explain.command.ts +119 -0
- package/source/commands/generate.command.ts +58 -0
- package/source/commands/inspect.command.ts +108 -0
- package/source/commands/mcp.command.ts +322 -0
- package/source/commands/new.command.ts +135 -0
- package/source/commands/openapi.command.ts +95 -0
- package/source/commands/requests.command.ts +137 -0
- package/source/commands/routes.command.ts +39 -0
- package/source/commands/verify.command.ts +173 -0
- package/source/commands/why.command.ts +61 -0
- package/source/contracts/decorators.ts +216 -0
- package/source/contracts/errors.ts +135 -0
- package/source/contracts/index.ts +4 -0
- package/source/contracts/schema.ts +438 -0
- package/source/contracts/typebox.ts +193 -0
- package/source/core/application.ts +322 -72
- package/source/core/builder.ts +10 -2
- package/source/core/config/config.ts +155 -26
- package/source/core/config/define.ts +35 -8
- package/source/core/config/index.ts +2 -1
- package/source/core/config/schema.ts +406 -0
- package/source/core/controller/builder.ts +38 -13
- package/source/core/controller/compiler.ts +14 -7
- package/source/core/controller/metadata.ts +1 -1
- package/source/core/hooks.ts +13 -1
- package/source/core/injection/injection.ts +47 -9
- package/source/core/mcp/builder.ts +13 -2
- package/source/core/mcp/metadata.ts +2 -1
- package/source/core/middleware/compose.ts +48 -0
- package/source/core/middleware/pipeline.ts +69 -46
- package/source/core/raiton.ts +8 -0
- package/source/core/router/handler.ts +246 -37
- package/source/core/router/handler.utils.ts +107 -51
- package/source/core/router/matcher.ts +195 -24
- package/source/core/router/route.ts +100 -31
- package/source/core/router/router.ts +27 -2
- package/source/core/scheduler/metadata.ts +1 -1
- package/source/core/socket/metadata.ts +1 -1
- package/source/core/thread.ts +37 -2
- package/source/debug/cli.ts +206 -0
- package/source/debug/collector.internal.ts +27 -0
- package/source/debug/collector.ts +294 -0
- package/source/debug/config.ts +142 -0
- package/source/debug/examples.ts +188 -0
- package/source/debug/explain.ts +187 -0
- package/source/debug/index.ts +15 -0
- package/source/debug/invocation.ts +695 -0
- package/source/debug/journal.ts +249 -0
- package/source/debug/mcp-http.ts +145 -0
- package/source/debug/mcp.ts +410 -0
- package/source/debug/redaction.ts +225 -0
- package/source/debug/requests.ts +136 -0
- package/source/debug/runtime.ts +181 -0
- package/source/debug/session.ts +107 -0
- package/source/debug/source.ts +95 -0
- package/source/debug/surface.ts +375 -0
- package/source/debug/types.ts +311 -0
- package/source/debug/verify.ts +186 -0
- package/source/framework/artifacts.ts +47 -15
- package/source/framework/cache/cache.ts +48 -3
- package/source/framework/constants/decorators.constant.ts +5 -0
- package/source/framework/data-transfer-object.ts +4 -3
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +3 -2
- package/source/framework/decorators/csrf-token.decorator.ts +1 -1
- package/source/framework/decorators/guard.decorator.ts +3 -2
- package/source/framework/decorators/health-check.decorator.ts +1 -1
- package/source/framework/decorators/mcp.decorator.ts +38 -7
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -1
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +2 -2
- package/source/framework/decorators/scheduler.decorator.ts +3 -3
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +46 -7
- package/source/framework/errors/catalog.ts +205 -0
- package/source/framework/exceptions/http-exception.ts +1 -1
- package/source/framework/health-check.ts +18 -0
- package/source/framework/index.ts +2 -0
- package/source/framework/mcp/audit.ts +57 -0
- package/source/framework/mcp/conformance.ts +195 -0
- package/source/framework/mcp/handler.ts +139 -9
- package/source/framework/mcp/index.ts +6 -1
- package/source/framework/mcp/protocol.ts +6 -0
- package/source/framework/mcp/rate-limit.ts +33 -0
- package/source/framework/mcp/stdio.ts +150 -0
- package/source/framework/mcp/streamable-http.ts +36 -5
- package/source/framework/observability/index.ts +6 -0
- package/source/framework/observability/metrics.ts +162 -0
- package/source/framework/observability/plugin.ts +151 -0
- package/source/framework/observability/readiness.ts +22 -0
- package/source/framework/observability/request.ts +31 -0
- package/source/framework/observability/shutdown.ts +68 -0
- package/source/framework/observability/trace.ts +241 -0
- package/source/framework/plugins/body-parser.plugin.ts +88 -85
- package/source/framework/plugins/dev.plugin.ts +227 -0
- package/source/framework/plugins/index.ts +2 -1
- package/source/framework/plugins/mcp.plugin.ts +14 -3
- package/source/framework/plugins/openapi.plugin.ts +56 -13
- package/source/framework/responses/helpers.ts +4 -4
- package/source/framework/responses/http-throwable.ts +1 -1
- package/source/framework/runtime/bun/server.ts +2 -1
- package/source/framework/runtime/deno/server.ts +2 -1
- package/source/framework/runtime/index.ts +45 -13
- package/source/framework/runtime/node/request.ts +59 -13
- package/source/framework/utilities/index.ts +3 -1
- package/source/framework/utilities/openapi.utils.impl.ts +733 -0
- package/source/framework/utilities/openapi.utils.ts +6 -636
- package/source/framework/utilities/route-suggestion.util.ts +59 -0
- package/source/framework/utilities/validation.util.ts +20 -0
- package/source/generators/artifact.templates.ts +230 -0
- package/source/generators/index.ts +2 -0
- package/source/generators/project.templates.ts +392 -0
- package/source/manifest/client.ts +299 -0
- package/source/manifest/contract.ts +138 -0
- package/source/manifest/index.ts +5 -0
- package/source/manifest/introspect.ts +57 -0
- package/source/manifest/manifest.ts +364 -0
- package/source/manifest/schema.ts +200 -0
- package/source/types/builder.ts +5 -0
- package/source/types/config.ts +120 -2
- package/source/types/mcp.ts +63 -1
- package/tsconfig.build.json +13 -0
- package/source/commands/grafts.command.ts +0 -27
- package/tests/artifact-resolution.test.ts +0 -60
|
@@ -4,7 +4,13 @@ import {McpServerRegistrationInterface} from "../../types/index.ts";
|
|
|
4
4
|
import {McpRouteTracker} from "./tracker.ts";
|
|
5
5
|
import {RaitonThread} from "../thread.ts";
|
|
6
6
|
import {HttpMethod} from "../../framework/enums/index.ts";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
mcpHandleGet,
|
|
9
|
+
mcpHandlePost,
|
|
10
|
+
isMcpJsonRpc,
|
|
11
|
+
mcpContextFromHeaders,
|
|
12
|
+
SESSION_HEADER
|
|
13
|
+
} from "../../framework/mcp/streamable-http.ts";
|
|
8
14
|
import type {ContextInterface} from "../../types/core.ts";
|
|
9
15
|
|
|
10
16
|
export function compileMcp(McpServerClass: any): McpServerRegistrationInterface | undefined {
|
|
@@ -31,7 +37,12 @@ export function compileMcp(McpServerClass: any): McpServerRegistrationInterface
|
|
|
31
37
|
return {error: {code: -32700, message: 'Invalid JSON-RPC request'}}
|
|
32
38
|
}
|
|
33
39
|
const existingSessionId = readSessionId(context)
|
|
34
|
-
const result = await mcpHandlePost(
|
|
40
|
+
const result = await mcpHandlePost(
|
|
41
|
+
entry,
|
|
42
|
+
context.req.body,
|
|
43
|
+
existingSessionId,
|
|
44
|
+
mcpContextFromHeaders(context.req.headers),
|
|
45
|
+
)
|
|
35
46
|
context.reply.status(result.status)
|
|
36
47
|
if (result.headers[SESSION_HEADER]) {
|
|
37
48
|
context.reply.header(SESSION_HEADER, result.headers[SESSION_HEADER])
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {McpServerMetaInterface, McpServerRegistrationInterface} from "../../types/index.ts";
|
|
2
|
-
import {METADATA_KEYS} from "../../framework/constants/
|
|
2
|
+
import {METADATA_KEYS} from "../../framework/constants/decorators.constant.ts";
|
|
3
3
|
import "reflect-metadata";
|
|
4
4
|
|
|
5
5
|
const registry = new Map<string, McpServerRegistrationInterface>();
|
|
@@ -17,6 +17,7 @@ export function getMcpServerMetadata(target: any): McpServerMetaInterface {
|
|
|
17
17
|
prompts: [],
|
|
18
18
|
resources: [],
|
|
19
19
|
resourceTemplates: [],
|
|
20
|
+
exposeDestructive: false,
|
|
20
21
|
};
|
|
21
22
|
Reflect.defineMetadata(METADATA_KEYS.MCP, metadata, target);
|
|
22
23
|
}
|
|
@@ -38,3 +38,51 @@ export function middlewareCompose(middlewares: MiddlewareType[]) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Précompose la pile de middlewares en gardant le terminal (handler de route)
|
|
44
|
+
* en paramètre d'exécution. La pile n'est plus recopiée à chaque requête ;
|
|
45
|
+
* `MiddlewarePipeline` invalide le runner compilé à chaque mutation.
|
|
46
|
+
*/
|
|
47
|
+
export function middlewareComposeWithTerminal(middlewares: readonly MiddlewareType[]) {
|
|
48
|
+
return function (request: any, terminal: MiddlewareType) {
|
|
49
|
+
let index = -1
|
|
50
|
+
|
|
51
|
+
return dispatch(0)
|
|
52
|
+
|
|
53
|
+
async function dispatch(i: number): Promise<void> {
|
|
54
|
+
if (i <= index) {
|
|
55
|
+
return Promise.reject(
|
|
56
|
+
new Throwable('next() called multiple times')
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
index = i
|
|
61
|
+
|
|
62
|
+
if (i >= middlewares.length) {
|
|
63
|
+
return Promise.resolve(
|
|
64
|
+
(terminal as any)({context: request, next: () => dispatch(i + 1)})
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const fn = middlewares[i];
|
|
69
|
+
try {
|
|
70
|
+
if (typeof fn === 'function') {
|
|
71
|
+
return Promise.resolve(fn({context: request, next: () => dispatch(i + 1)}))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof fn === 'object' && 'setup' in fn && typeof fn.setup == 'function') {
|
|
75
|
+
if (fn.setup.length === 1) {
|
|
76
|
+
await Promise.resolve(fn.setup(request))
|
|
77
|
+
return await dispatch(i + 1)
|
|
78
|
+
}
|
|
79
|
+
return Promise.resolve(fn.setup(request, () => dispatch(i + 1)))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return await dispatch(i + 1)
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return Promise.reject(err)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,51 +1,74 @@
|
|
|
1
1
|
import { MiddlewareType } from '../../types/index.ts'
|
|
2
|
-
import { middlewareCompose } from '../
|
|
2
|
+
import { middlewareCompose, middlewareComposeWithTerminal } from '../middleware/compose.ts'
|
|
3
3
|
|
|
4
4
|
export class MiddlewarePipeline {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
private stack: MiddlewareType[] = []
|
|
6
|
+
private compiled?: ReturnType<typeof middlewareCompose>
|
|
7
|
+
private terminalRunner?: ReturnType<typeof middlewareComposeWithTerminal>
|
|
8
|
+
|
|
9
|
+
private invalidate(): void {
|
|
10
|
+
this.compiled = undefined
|
|
11
|
+
this.terminalRunner = undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
use(mw: MiddlewareType): this {
|
|
15
|
+
this.stack.push(mw)
|
|
16
|
+
this.invalidate()
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
replace(name: string, mw: MiddlewareType): this {
|
|
21
|
+
const normalized = name.toLowerCase()
|
|
22
|
+
for (let i = 0; i < this.stack.length; i++) {
|
|
23
|
+
const entry = this.stack[i]
|
|
24
|
+
let entryName: string | undefined
|
|
25
|
+
if (typeof entry === 'function') {
|
|
26
|
+
entryName = entry.name?.toLowerCase()
|
|
27
|
+
} else if (typeof entry === 'object' && entry !== null && 'name' in entry) {
|
|
28
|
+
entryName = (entry as any).name?.toLowerCase()
|
|
29
|
+
}
|
|
30
|
+
if (entryName === normalized) {
|
|
31
|
+
this.stack[i] = mw
|
|
32
|
+
this.invalidate()
|
|
33
|
+
return this
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.stack.push(mw)
|
|
37
|
+
this.invalidate()
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
remove(name: string): this {
|
|
42
|
+
const normalized = name.toLowerCase()
|
|
43
|
+
this.stack = this.stack.filter(entry => {
|
|
44
|
+
if (typeof entry === 'function') return entry.name?.toLowerCase() !== normalized
|
|
45
|
+
if (typeof entry === 'object' && entry !== null && 'name' in entry)
|
|
46
|
+
return (entry as any).name?.toLowerCase() !== normalized
|
|
47
|
+
return true
|
|
48
|
+
})
|
|
49
|
+
this.invalidate()
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
clear(): this {
|
|
54
|
+
this.stack = []
|
|
55
|
+
this.invalidate()
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
run(ctx: any, ...extra: MiddlewareType[]) {
|
|
60
|
+
// Hot path: the application appends its route terminal. The stack is
|
|
61
|
+
// precomposed and only the terminal is supplied per request.
|
|
62
|
+
if (extra.length === 1 && typeof extra[0] === 'function') {
|
|
63
|
+
this.terminalRunner ??= middlewareComposeWithTerminal(this.stack)
|
|
64
|
+
return this.terminalRunner(ctx, extra[0])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (extra.length === 0) {
|
|
68
|
+
this.compiled ??= middlewareCompose(this.stack)
|
|
69
|
+
return this.compiled(ctx)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return middlewareCompose([...this.stack, ...extra])(ctx)
|
|
26
73
|
}
|
|
27
|
-
this.stack.push(mw)
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
remove(name: string): this {
|
|
32
|
-
const normalized = name.toLowerCase()
|
|
33
|
-
this.stack = this.stack.filter(entry => {
|
|
34
|
-
if (typeof entry === 'function') return entry.name?.toLowerCase() !== normalized
|
|
35
|
-
if (typeof entry === 'object' && entry !== null && 'name' in entry)
|
|
36
|
-
return (entry as any).name?.toLowerCase() !== normalized
|
|
37
|
-
return true
|
|
38
|
-
})
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
clear(): this {
|
|
43
|
-
this.stack = []
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
run(ctx: any, ...extra: MiddlewareType[]) {
|
|
48
|
-
const fn = middlewareCompose([...this.stack, ...extra])
|
|
49
|
-
return typeof fn == 'function' ? fn(ctx) : undefined;
|
|
50
|
-
}
|
|
51
74
|
}
|
package/source/core/raiton.ts
CHANGED
|
@@ -17,4 +17,12 @@ export class Raiton {
|
|
|
17
17
|
static set thread(thread: ThreadInterface | undefined) {
|
|
18
18
|
this._thread = this._thread || thread;
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reset the thread singleton. Used by tests and by CLI commands that run
|
|
23
|
+
* several introspections in the same process.
|
|
24
|
+
*/
|
|
25
|
+
static resetThread(): void {
|
|
26
|
+
this._thread = undefined;
|
|
27
|
+
}
|
|
20
28
|
}
|
|
@@ -1,47 +1,191 @@
|
|
|
1
1
|
import {ControllerMetaInterface, RouteMetaInterface} from "../../types/index.ts";
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import {Raiton} from "../
|
|
4
|
-
import {HttpException} from "../../framework/exceptions/
|
|
3
|
+
import {Raiton} from "../raiton.ts";
|
|
4
|
+
import {HttpException} from "../../framework/exceptions/http-exception.ts";
|
|
5
5
|
import {ThrowableResponse} from "../../framework/responses/http-throwable.ts";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
collectArguments,
|
|
8
|
+
createResponseValidator,
|
|
9
|
+
getRouteParameters,
|
|
10
|
+
validateDtoArguments,
|
|
11
|
+
runMiddlewares,
|
|
12
|
+
} from "./handler.utils.ts";
|
|
7
13
|
import {RouteCache, getCacheMetadata} from "../../framework/cache/index.ts";
|
|
8
|
-
import {
|
|
14
|
+
import {HttpStatus} from "../../framework/enums/http-status.enum.ts";
|
|
15
|
+
import {RaitonConfig} from "../config/index.ts";
|
|
16
|
+
import {
|
|
17
|
+
ContractValidationError,
|
|
18
|
+
getRouteContract,
|
|
19
|
+
OutputContractError,
|
|
20
|
+
validateRouteInput,
|
|
21
|
+
validateRouteOutput,
|
|
22
|
+
} from "../../contracts/index.ts";
|
|
23
|
+
import {enrichErrorPayload, errorPayload, hintFor} from "../../framework/errors/catalog.ts";
|
|
24
|
+
import {getDebugCollector, getDebugRuntime, recordDebugLog} from "../../debug/runtime.ts";
|
|
25
|
+
import {resolveRouteSource, firstUserFrame, stackLines, relativeLocation} from "../../debug/source.ts";
|
|
26
|
+
import {toDebugIssues} from "../../debug/collector.ts";
|
|
27
|
+
import type {ContractIssue} from "../../contracts/index.ts";
|
|
28
|
+
|
|
29
|
+
function isDevelopment(): boolean {
|
|
30
|
+
return Boolean(
|
|
31
|
+
Raiton.thread?.builder?.options?.hmr
|
|
32
|
+
|| RaitonConfig.get("develop")
|
|
33
|
+
|| process.env.NODE_ENV === "development"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
9
36
|
|
|
10
37
|
export function createHandler(
|
|
11
38
|
instance: any,
|
|
12
39
|
routeMeta: RouteMetaInterface,
|
|
13
40
|
controllerMeta: ControllerMetaInterface,
|
|
14
41
|
) {
|
|
42
|
+
// Everything that does not depend on the request is resolved exactly once,
|
|
43
|
+
// at handler compilation (including on every HMR recompile).
|
|
44
|
+
const development = isDevelopment();
|
|
45
|
+
const handlerName = `${instance.constructor.name}.${routeMeta.propertyKey}`
|
|
46
|
+
const routeLabel = `${routeMeta.method} ${controllerMeta.prefix ?? ""}${routeMeta.path}`;
|
|
15
47
|
const cacheOptions = getCacheMetadata(instance, routeMeta.propertyKey);
|
|
16
|
-
const routeCache = cacheOptions
|
|
48
|
+
const routeCache = cacheOptions
|
|
49
|
+
? new RouteCache(`${controllerMeta.prefix ?? ''}${routeMeta.path}`, cacheOptions)
|
|
50
|
+
: undefined;
|
|
51
|
+
const cacheEnabled = Boolean(routeCache?.enabled)
|
|
52
|
+
const contract = getRouteContract(instance.constructor, routeMeta.propertyKey);
|
|
53
|
+
const parameters = getRouteParameters(instance, routeMeta);
|
|
54
|
+
const middlewares = [
|
|
55
|
+
...(controllerMeta.middlewares['@'] || []),
|
|
56
|
+
...(controllerMeta.middlewares[routeMeta.propertyKey] || []),
|
|
57
|
+
];
|
|
58
|
+
const responseValidator = RaitonConfig.shouldValidateResponses(development)
|
|
59
|
+
? createResponseValidator(instance, routeMeta)
|
|
60
|
+
: undefined;
|
|
61
|
+
const source = resolveRouteSource(
|
|
62
|
+
instance.constructor,
|
|
63
|
+
controllerMeta,
|
|
64
|
+
routeMeta,
|
|
65
|
+
getDebugRuntime()?.workdir ?? process.cwd(),
|
|
66
|
+
);
|
|
67
|
+
const debugWorkdir = getDebugRuntime()?.workdir ?? process.cwd();
|
|
68
|
+
const redactKeys = getDebugRuntime()?.config.journal.redact ?? [];
|
|
69
|
+
|
|
70
|
+
const locationOf = (location?: string): string | undefined => {
|
|
71
|
+
if (!development || !location) return undefined;
|
|
72
|
+
return relativeLocation(location, debugWorkdir);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const journalIssues = (issues: ContractIssue[] | undefined, location?: string) => {
|
|
76
|
+
if (!issues?.length) return [];
|
|
77
|
+
return toDebugIssues(issues, redactKeys).map(issue => ({
|
|
78
|
+
...issue,
|
|
79
|
+
...(development && !issue.location && location ? {location: relativeLocation(location, debugWorkdir)} : {}),
|
|
80
|
+
}));
|
|
81
|
+
};
|
|
17
82
|
|
|
18
83
|
const handler = async (ctx: any) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
84
|
+
const collector = ctx.state?.debug ? getDebugCollector() : undefined;
|
|
85
|
+
if (collector) collector.setSource(ctx, source);
|
|
21
86
|
|
|
22
87
|
try {
|
|
23
|
-
const cacheKey = (
|
|
24
|
-
? await routeCache
|
|
88
|
+
const cacheKey = (cacheEnabled && routeCache!.matchesMethod(ctx.req?.method))
|
|
89
|
+
? await routeCache!.key(ctx)
|
|
25
90
|
: undefined;
|
|
26
91
|
|
|
27
92
|
if (cacheKey) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ctx
|
|
31
|
-
|
|
32
|
-
|
|
93
|
+
if (collector) {
|
|
94
|
+
const startedCache = performance.now();
|
|
95
|
+
const cached = await routeCache!.get(ctx, cacheKey);
|
|
96
|
+
if (cached) {
|
|
97
|
+
collector.step(ctx, "cache", "hit", performance.now() - startedCache);
|
|
98
|
+
collector.setCache(ctx, true);
|
|
99
|
+
ctx.reply.status(cached.status);
|
|
100
|
+
for (const [name, value] of Object.entries(cached.headers)) {
|
|
101
|
+
ctx.reply.header(name, value);
|
|
102
|
+
}
|
|
103
|
+
collector.step(ctx, "handler", "cached");
|
|
104
|
+
return cached.body;
|
|
33
105
|
}
|
|
34
|
-
|
|
106
|
+
collector.step(ctx, "cache", "miss", performance.now() - startedCache);
|
|
107
|
+
collector.setCache(ctx, false);
|
|
108
|
+
} else {
|
|
109
|
+
const cached = await routeCache!.get(ctx, cacheKey);
|
|
110
|
+
if (cached) {
|
|
111
|
+
ctx.reply.status(cached.status);
|
|
112
|
+
for (const [name, value] of Object.entries(cached.headers)) {
|
|
113
|
+
ctx.reply.header(name, value);
|
|
114
|
+
}
|
|
115
|
+
return cached.body;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else if (collector) {
|
|
119
|
+
collector.step(ctx, "cache", cacheEnabled ? "skip" : "disabled");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (collector) {
|
|
123
|
+
const startedMiddlewares = performance.now();
|
|
124
|
+
try {
|
|
125
|
+
await runMiddlewares(middlewares, ctx);
|
|
126
|
+
collector.step(ctx, "middleware", "ok", performance.now() - startedMiddlewares);
|
|
127
|
+
} catch (error: any) {
|
|
128
|
+
collector.step(ctx, "middleware", "rejected", performance.now() - startedMiddlewares);
|
|
129
|
+
throw error;
|
|
35
130
|
}
|
|
131
|
+
} else {
|
|
132
|
+
await runMiddlewares(middlewares, ctx);
|
|
36
133
|
}
|
|
37
134
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
135
|
+
// Schema-first input validation runs before the handler and before
|
|
136
|
+
// DTO construction: an invalid payload never reaches user code.
|
|
137
|
+
if (contract?.input) {
|
|
138
|
+
const startedValidation = performance.now();
|
|
139
|
+
const input = await validateRouteInput(contract, ctx);
|
|
140
|
+
if (!input.success) {
|
|
141
|
+
if (collector) {
|
|
142
|
+
collector.setValidation(ctx, {
|
|
143
|
+
ok: false,
|
|
144
|
+
issues: journalIssues(input.issues, contract.inputLocation),
|
|
145
|
+
});
|
|
146
|
+
collector.step(ctx, "validation:input", "rejected", performance.now() - startedValidation);
|
|
147
|
+
collector.markHandler(ctx, false);
|
|
148
|
+
collector.step(ctx, "handler", "not-executed");
|
|
149
|
+
}
|
|
150
|
+
throw new ContractValidationError(input.issues);
|
|
151
|
+
}
|
|
152
|
+
if (collector) {
|
|
153
|
+
collector.setValidation(ctx, {ok: true, issues: []});
|
|
154
|
+
collector.step(ctx, "validation:input", "ok", performance.now() - startedValidation);
|
|
155
|
+
}
|
|
156
|
+
if (input.body !== undefined) ctx.req.body = input.body;
|
|
157
|
+
} else if (collector) {
|
|
158
|
+
collector.setValidation(ctx, {ok: true, absent: true, issues: []});
|
|
159
|
+
collector.step(ctx, "validation:input", "absent");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const args = collectArguments(parameters, ctx);
|
|
41
163
|
await validateDtoArguments(args);
|
|
164
|
+
if (collector) collector.markHandler(ctx, true);
|
|
165
|
+
const startedHandler = performance.now();
|
|
42
166
|
let responses = instance[routeMeta.propertyKey](...args);
|
|
43
167
|
if (responses instanceof Promise) responses = await responses;
|
|
44
|
-
|
|
168
|
+
if (collector) collector.step(ctx, "handler", "ok", performance.now() - startedHandler);
|
|
169
|
+
|
|
170
|
+
if (contract?.output && responseValidator) {
|
|
171
|
+
const startedOutput = performance.now();
|
|
172
|
+
const output = await validateRouteOutput(contract, responses);
|
|
173
|
+
if (!output.success) {
|
|
174
|
+
if (collector) {
|
|
175
|
+
collector.step(ctx, "validation:output", "rejected", performance.now() - startedOutput);
|
|
176
|
+
}
|
|
177
|
+
Logger.error(
|
|
178
|
+
`[contract] ${routeLabel} returned an invalid response` +
|
|
179
|
+
(ctx.state?.requestId ? ` request_id=${ctx.state.requestId}` : '') +
|
|
180
|
+
`: ` + output.issues.map(issue => `${issue.path || "<root>"} (${issue.code})`).join(", ")
|
|
181
|
+
);
|
|
182
|
+
if (development) throw new OutputContractError(routeLabel, output.issues);
|
|
183
|
+
} else if (collector) {
|
|
184
|
+
collector.step(ctx, "validation:output", "ok", performance.now() - startedOutput);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (responseValidator) await responseValidator(responses);
|
|
45
189
|
|
|
46
190
|
if (cacheKey && !(responses instanceof ThrowableResponse)) {
|
|
47
191
|
await routeCache!.set(ctx, responses, 200, {}, cacheKey);
|
|
@@ -50,35 +194,100 @@ export function createHandler(
|
|
|
50
194
|
return responses;
|
|
51
195
|
} catch (err: any) {
|
|
52
196
|
|
|
53
|
-
|
|
197
|
+
const requestId = ctx.state?.requestId
|
|
198
|
+
Logger.info(`${ctx.req?.method} ${ctx.req?.url}${requestId ? ` request_id=${requestId}` : ''}`)
|
|
54
199
|
|
|
55
|
-
if (err instanceof
|
|
56
|
-
Logger.
|
|
57
|
-
|
|
58
|
-
|
|
200
|
+
if (err instanceof ContractValidationError || err instanceof OutputContractError) {
|
|
201
|
+
Logger.warn(`[contract] ${routeLabel} rejected request${requestId ? ` request_id=${requestId}` : ''}`);
|
|
202
|
+
const location = err instanceof OutputContractError
|
|
203
|
+
? locationOf(contract?.outputLocation)
|
|
204
|
+
: locationOf(contract?.inputLocation);
|
|
205
|
+
const issues = journalIssues(err.issues, location);
|
|
206
|
+
if (collector) {
|
|
207
|
+
collector.setValidation(ctx, {
|
|
208
|
+
ok: false,
|
|
209
|
+
issues: err instanceof OutputContractError
|
|
210
|
+
? journalIssues(err.issues, contract?.outputLocation)
|
|
211
|
+
: journalIssues(err.issues, contract?.inputLocation),
|
|
212
|
+
});
|
|
213
|
+
collector.setError(ctx, {
|
|
214
|
+
code: err instanceof OutputContractError ? "OUTPUT_VALIDATION_ERROR" : "VALIDATION_ERROR",
|
|
215
|
+
message: err.message,
|
|
216
|
+
statusCode: err.statusCode,
|
|
217
|
+
...(development && err.stack ? {stack: stackLines(err)} : {}),
|
|
218
|
+
...(location ? {location} : {}),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
recordDebugLog("warn", `[contract] ${routeLabel} rejected request ${requestId ?? ""}`);
|
|
222
|
+
ctx.reply.status(err.statusCode);
|
|
223
|
+
return enrichErrorPayload(err.render({
|
|
224
|
+
requestId,
|
|
225
|
+
hint: err instanceof OutputContractError
|
|
226
|
+
? `The handler ran but its response does not match the @Output contract of ${routeLabel}.`
|
|
227
|
+
: "The handler was not executed. Fix the listed fields and retry.",
|
|
228
|
+
location,
|
|
229
|
+
redact: redactKeys,
|
|
230
|
+
development,
|
|
231
|
+
}), err.statusCode, requestId, {redact: redactKeys});
|
|
59
232
|
}
|
|
60
233
|
|
|
61
|
-
|
|
62
|
-
err.message ?? err
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
234
|
+
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
235
|
+
Logger.error(`Failed to execute ${handlerName} handler${requestId ? ` request_id=${requestId}` : ''}`, err.message ?? err);
|
|
236
|
+
const status = err.statusCode ?? 500;
|
|
237
|
+
const location = development ? firstUserFrame(err.stack) : undefined;
|
|
238
|
+
if (collector) {
|
|
239
|
+
collector.setError(ctx, {
|
|
240
|
+
code: typeof (err as any).code === "string" ? (err as any).code : "INTERNAL_SERVER_ERROR",
|
|
241
|
+
message: String(err.message ?? err),
|
|
242
|
+
statusCode: status,
|
|
243
|
+
...(development ? {stack: stackLines(err)} : {}),
|
|
244
|
+
...(location ? {location} : {}),
|
|
245
|
+
});
|
|
246
|
+
collector.step(ctx, "handler", "error", undefined, String(err.message ?? err));
|
|
71
247
|
}
|
|
72
|
-
|
|
248
|
+
recordDebugLog("error", `${handlerName}: ${err.message ?? err}`);
|
|
249
|
+
ctx.reply.status(status)
|
|
250
|
+
return enrichErrorPayload(err.render(), status, requestId, {
|
|
251
|
+
hint: hintFor("INTERNAL_SERVER_ERROR"),
|
|
252
|
+
location,
|
|
253
|
+
stack: development ? stackLines(err) : undefined,
|
|
254
|
+
redact: redactKeys,
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const location = development ? firstUserFrame(err?.stack) : undefined;
|
|
259
|
+
if (collector) {
|
|
260
|
+
collector.setError(ctx, {
|
|
261
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
262
|
+
message: String(err?.message ?? err),
|
|
263
|
+
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
264
|
+
...(development ? {stack: stackLines(err)} : {}),
|
|
265
|
+
...(location ? {location} : {}),
|
|
266
|
+
});
|
|
267
|
+
collector.step(ctx, "handler", "error", undefined, String(err?.message ?? err));
|
|
268
|
+
}
|
|
269
|
+
recordDebugLog("error", `${handlerName}: ${err?.message ?? err}`);
|
|
270
|
+
ctx.reply.status(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
271
|
+
return errorPayload("INTERNAL_SERVER_ERROR", {
|
|
272
|
+
requestId,
|
|
273
|
+
hint: hintFor("INTERNAL_SERVER_ERROR"),
|
|
274
|
+
redact: redactKeys,
|
|
275
|
+
...(development ? {
|
|
276
|
+
details: {message: String(err?.message ?? err)},
|
|
277
|
+
location,
|
|
278
|
+
stack: stackLines(err),
|
|
279
|
+
} : {}),
|
|
280
|
+
});
|
|
73
281
|
}
|
|
74
282
|
};
|
|
75
283
|
|
|
76
|
-
// Attach metadata for OpenAPI generation
|
|
284
|
+
// Attach metadata for OpenAPI generation and CLI introspection.
|
|
77
285
|
(handler as any)._raitonMeta = {
|
|
78
286
|
routeMeta,
|
|
79
287
|
controllerMeta,
|
|
80
288
|
controllerClass: instance.constructor
|
|
81
289
|
};
|
|
290
|
+
(handler as any)._raitonContract = contract;
|
|
82
291
|
|
|
83
292
|
return handler;
|
|
84
|
-
}
|
|
293
|
+
}
|