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
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
import type {ApplicationInterface} from "../types/application.ts";
|
|
2
|
+
import type {ProjectManifest, ProjectRouteManifest} from "../manifest/schema.ts";
|
|
3
|
+
import type {ResolvedDebugConfig} from "./types.ts";
|
|
4
|
+
import type {
|
|
5
|
+
DebugContractStatus,
|
|
6
|
+
DebugInvocationRequest,
|
|
7
|
+
DebugInvocationResult,
|
|
8
|
+
DebugResolvedRequest,
|
|
9
|
+
DebugValidationIssue,
|
|
10
|
+
} from "./types.ts";
|
|
11
|
+
import {DEBUG_SCHEMA_VERSION} from "./types.ts";
|
|
12
|
+
import {generateRequestId} from "../framework/observability/request.ts";
|
|
13
|
+
import {DEFAULT_REDACT_KEYS, redactHeaders, redactValue, truncateValue} from "./redaction.ts";
|
|
14
|
+
import {exampleForSchema} from "./examples.ts";
|
|
15
|
+
import {sanitizeIssues} from "../contracts/errors.ts";
|
|
16
|
+
import type {DebugJournalEntry, DebugReplayComparison} from "./types.ts";
|
|
17
|
+
|
|
18
|
+
export class DebugInvocationError extends Error {
|
|
19
|
+
public readonly code: string;
|
|
20
|
+
public readonly hint: string;
|
|
21
|
+
public readonly location?: string;
|
|
22
|
+
public readonly exitCode: number;
|
|
23
|
+
|
|
24
|
+
constructor(message: string, options: {
|
|
25
|
+
code?: string;
|
|
26
|
+
hint?: string;
|
|
27
|
+
location?: string;
|
|
28
|
+
exitCode?: number;
|
|
29
|
+
} = {}) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "DebugInvocationError";
|
|
32
|
+
this.code = options.code ?? "INVOCATION_FAILED";
|
|
33
|
+
this.hint = options.hint ?? "Run `raiton routes` to inspect the mounted routes.";
|
|
34
|
+
this.location = options.location;
|
|
35
|
+
this.exitCode = options.exitCode ?? 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface InvocationContext {
|
|
40
|
+
manifest: ProjectManifest;
|
|
41
|
+
application?: ApplicationInterface;
|
|
42
|
+
config?: ResolvedDebugConfig;
|
|
43
|
+
baseUrl?: string;
|
|
44
|
+
workdir?: string;
|
|
45
|
+
development?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ResolvedRoute {
|
|
49
|
+
route: ProjectRouteManifest;
|
|
50
|
+
params: Record<string, any>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalize(path: string): string {
|
|
54
|
+
if (!path) return "/";
|
|
55
|
+
let value = path.startsWith("/") ? path : `/${path}`;
|
|
56
|
+
value = value.replace(/\/+/g, "/");
|
|
57
|
+
if (value.length > 1) value = value.replace(/\/+$/, "");
|
|
58
|
+
return value || "/";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function patternOf(routePath: string): RegExp {
|
|
62
|
+
const escaped = normalize(routePath)
|
|
63
|
+
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
64
|
+
.replace(/\\?:([A-Za-z0-9_]+)/g, "[^/]+");
|
|
65
|
+
return new RegExp(`^${escaped}$`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function paramNames(routePath: string): string[] {
|
|
69
|
+
return [...normalize(routePath).matchAll(/:([A-Za-z0-9_]+)/g)].map(match => match[1]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function splitPath(path: string): string {
|
|
73
|
+
try {
|
|
74
|
+
return new URL(path, "http://localhost").pathname;
|
|
75
|
+
} catch {
|
|
76
|
+
return path.split("?")[0];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function appPrefix(application?: ApplicationInterface): string {
|
|
81
|
+
const prefix = String((application as any)?.config?.prefix ?? "").replace(/\/+$/, "");
|
|
82
|
+
return prefix && prefix !== "/" ? prefix : "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function withoutPrefix(path: string, prefix: string): string {
|
|
86
|
+
if (!prefix) return path;
|
|
87
|
+
if (path === prefix) return "/";
|
|
88
|
+
if (path.startsWith(`${prefix}/`)) return path.slice(prefix.length) || "/";
|
|
89
|
+
return path;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function matchRoute(manifest: ProjectManifest, method: string, path: string, application?: ApplicationInterface): ResolvedRoute | undefined {
|
|
93
|
+
const prefix = appPrefix(application);
|
|
94
|
+
const candidates = new Set<string>([normalize(splitPath(path))]);
|
|
95
|
+
if (prefix) candidates.add(normalize(withoutPrefix(normalize(splitPath(path)), prefix)));
|
|
96
|
+
|
|
97
|
+
const entryMethod = method.toUpperCase();
|
|
98
|
+
const routes = manifest.routes.filter(route => route.method.toUpperCase() === entryMethod);
|
|
99
|
+
|
|
100
|
+
for (const candidate of candidates) {
|
|
101
|
+
const exact = routes.find(route => normalize(route.path) === candidate);
|
|
102
|
+
if (exact) return {route: exact, params: {}};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const candidate of candidates) {
|
|
106
|
+
for (const route of routes) {
|
|
107
|
+
const pattern = patternOf(route.path);
|
|
108
|
+
const match = pattern.exec(candidate);
|
|
109
|
+
if (!match) continue;
|
|
110
|
+
const names = paramNames(route.path);
|
|
111
|
+
const params: Record<string, any> = {};
|
|
112
|
+
names.forEach((name, index) => {
|
|
113
|
+
params[name] = decodeURIComponent(match[index + 1]);
|
|
114
|
+
});
|
|
115
|
+
return {route, params};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function fillPath(routePath: string, params: Record<string, any>): string {
|
|
123
|
+
return normalize(routePath).replace(/:([A-Za-z0-9_]+)/g, (_: string, name: string) => {
|
|
124
|
+
const value = params[name];
|
|
125
|
+
return value === undefined ? `:${name}` : encodeURIComponent(String(value));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function defaultBaseUrl(application?: ApplicationInterface): string {
|
|
130
|
+
const app: any = application;
|
|
131
|
+
const config = app?.config ?? {};
|
|
132
|
+
const protocol = app?.https?.enabled ? "https" : (config.protocole || "http");
|
|
133
|
+
const host = config.hostname && config.hostname !== "0.0.0.0" ? config.hostname : "localhost";
|
|
134
|
+
const port = config.port ? `:${config.port}` : "";
|
|
135
|
+
const pathname = config.pathname && config.pathname !== "/" ? config.pathname.replace(/\/+$/, "") : "";
|
|
136
|
+
const prefix = config.prefix ? `/${String(config.prefix).replace(/^\/+|\/+$/g, "")}` : "";
|
|
137
|
+
return `${protocol}://${host}${port}${pathname}${prefix}`;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function joinUrl(base: string, routePath: string, query: Record<string, any>): string {
|
|
141
|
+
const root = base.replace(/\/+$/, "");
|
|
142
|
+
const path = normalize(routePath);
|
|
143
|
+
const search = new URLSearchParams();
|
|
144
|
+
for (const [key, value] of Object.entries(query ?? {})) {
|
|
145
|
+
if (value === undefined || value === null) continue;
|
|
146
|
+
if (Array.isArray(value)) value.forEach(item => search.append(key, String(item)));
|
|
147
|
+
else search.append(key, String(value));
|
|
148
|
+
}
|
|
149
|
+
const serialized = search.toString();
|
|
150
|
+
return `${root}${path}${serialized ? `?${serialized}` : ""}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function issueFromValidation(issues: Array<{path?: string; code?: string; message?: string; expected?: string; received?: string; location?: string}>): DebugValidationIssue[] {
|
|
154
|
+
return sanitizeIssues(issues as any[], {development: true}).map(issue => ({
|
|
155
|
+
path: issue.path ? `/${issue.path.replace(/^\/+/, "")}` : "/",
|
|
156
|
+
code: issue.code ?? "invalid_value",
|
|
157
|
+
message: issue.message ?? "Invalid value",
|
|
158
|
+
...(issue.expected !== undefined ? {expected: issue.expected} : {}),
|
|
159
|
+
...(issue.received !== undefined ? {received: issue.received} : {}),
|
|
160
|
+
...(issue.location !== undefined ? {location: issue.location} : {}),
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function validatePart(schema: any, value: any, part: string): Promise<DebugValidationIssue[]> {
|
|
165
|
+
if (!schema) return [];
|
|
166
|
+
const {validateContract} = await import("../contracts/index.ts");
|
|
167
|
+
const result = await validateContract(schema, value);
|
|
168
|
+
if (result.success) return [];
|
|
169
|
+
return issueFromValidation(result.issues).map(issue => ({
|
|
170
|
+
...issue,
|
|
171
|
+
path: part ? `/${part}${issue.path === "/" ? "" : issue.path}` : issue.path,
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface PreparedInvocation {
|
|
176
|
+
resolved: DebugResolvedRequest;
|
|
177
|
+
raw: {
|
|
178
|
+
headers: Record<string, string>;
|
|
179
|
+
query: Record<string, any>;
|
|
180
|
+
params: Record<string, any>;
|
|
181
|
+
body?: any;
|
|
182
|
+
};
|
|
183
|
+
route?: ProjectRouteManifest;
|
|
184
|
+
contract: DebugContractStatus;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function redactionKeys(context: InvocationContext): string[] {
|
|
188
|
+
return context.config?.journal.redact ?? [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Resolve and validate an invocation without sending it.
|
|
193
|
+
*/
|
|
194
|
+
export async function prepareInvocation(
|
|
195
|
+
context: InvocationContext,
|
|
196
|
+
spec: DebugInvocationRequest,
|
|
197
|
+
): Promise<PreparedInvocation> {
|
|
198
|
+
const method = String(spec.method || "GET").toUpperCase();
|
|
199
|
+
let routePath = spec.path;
|
|
200
|
+
let inlineQuery: Record<string, string> = {};
|
|
201
|
+
try {
|
|
202
|
+
const parsed = new URL(String(spec.path || "/"), "http://localhost");
|
|
203
|
+
routePath = parsed.pathname;
|
|
204
|
+
inlineQuery = Object.fromEntries(parsed.searchParams.entries());
|
|
205
|
+
} catch {
|
|
206
|
+
routePath = splitPath(spec.path);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let route: ProjectRouteManifest | undefined;
|
|
210
|
+
let params: Record<string, any> = {};
|
|
211
|
+
|
|
212
|
+
if (spec.example) {
|
|
213
|
+
const exampleRoute = matchRoute(context.manifest, method, routePath, context.application);
|
|
214
|
+
const candidate = exampleRoute?.route ?? context.manifest.routes.find(item =>
|
|
215
|
+
item.method.toUpperCase() === method && normalize(item.path) === normalize(routePath));
|
|
216
|
+
const example = candidate?.examples?.find(item => item.name === spec.example);
|
|
217
|
+
if (!candidate || !example) {
|
|
218
|
+
throw new DebugInvocationError(
|
|
219
|
+
`Example '${spec.example}' not found for ${method} ${routePath}`,
|
|
220
|
+
{
|
|
221
|
+
code: "EXAMPLE_NOT_FOUND",
|
|
222
|
+
hint: candidate?.examples?.length
|
|
223
|
+
? `Available examples: ${candidate.examples.map(item => item.name).join(", ")}.`
|
|
224
|
+
: "Declare an example with @Example() or omit --example to use the generated one.",
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
route = candidate;
|
|
229
|
+
params = {...(example.params ?? {}), ...(spec.params ?? {})};
|
|
230
|
+
spec = {
|
|
231
|
+
...spec,
|
|
232
|
+
body: spec.body === undefined ? example.body : spec.body,
|
|
233
|
+
query: {...(example.query ?? {}), ...(spec.query ?? {})},
|
|
234
|
+
headers: {...(example.headers ?? {}), ...(spec.headers ?? {})},
|
|
235
|
+
path: candidate.path,
|
|
236
|
+
};
|
|
237
|
+
routePath = candidate.path;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const matched = matchRoute(context.manifest, method, routePath, context.application);
|
|
241
|
+
if (matched) {
|
|
242
|
+
route = matched.route;
|
|
243
|
+
params = {...matched.params, ...params, ...(spec.params ?? {})};
|
|
244
|
+
routePath = matched.route.path;
|
|
245
|
+
} else if (route) {
|
|
246
|
+
params = {...params, ...(spec.params ?? {})};
|
|
247
|
+
} else {
|
|
248
|
+
const {suggestRoute} = await import("../framework/utilities/route-suggestion.util.ts");
|
|
249
|
+
const suggestion = suggestRoute(context.manifest.routes, method, splitPath(routePath));
|
|
250
|
+
throw new DebugInvocationError(
|
|
251
|
+
`Route ${method} ${splitPath(routePath)} was not registered`,
|
|
252
|
+
{
|
|
253
|
+
code: "ROUTE_NOT_FOUND",
|
|
254
|
+
hint: suggestion
|
|
255
|
+
? `Did you mean ${suggestion}? Run \`raiton routes\` to list every mounted route.`
|
|
256
|
+
: "Run `raiton routes` to list every mounted route.",
|
|
257
|
+
},
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const names = paramNames(route.path);
|
|
262
|
+
const missing = names.filter(name => params[name] === undefined || params[name] === null || params[name] === "");
|
|
263
|
+
if (missing.length) {
|
|
264
|
+
const expected = route.path.replace(/:([A-Za-z0-9_]+)/g, (_: string, name: string) =>
|
|
265
|
+
missing.includes(name) ? `{${name}}` : `{${name}}`);
|
|
266
|
+
throw new DebugInvocationError(
|
|
267
|
+
`Missing path parameter(s): ${missing.join(", ")}`,
|
|
268
|
+
{
|
|
269
|
+
code: "MISSING_PATH_PARAMETER",
|
|
270
|
+
hint: `Expected path: ${expected}. Provide ${missing.map(name => `--param ${name}=<value>`).join(" ")}.`,
|
|
271
|
+
location: route.file ? `${route.file}:${route.line}` : undefined,
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const query = {...inlineQuery, ...(spec.query ?? {})};
|
|
277
|
+
const headers: Record<string, string> = {};
|
|
278
|
+
for (const [key, value] of Object.entries(spec.headers ?? {})) {
|
|
279
|
+
if (value === undefined || value === null) continue;
|
|
280
|
+
headers[key.toLowerCase()] = String(value);
|
|
281
|
+
}
|
|
282
|
+
const body = spec.body;
|
|
283
|
+
if (body !== undefined && !Object.keys(headers).some(key => key === "content-type")) {
|
|
284
|
+
headers["content-type"] = "application/json";
|
|
285
|
+
}
|
|
286
|
+
if (spec.baseUrl) headers.accept ??= "application/json";
|
|
287
|
+
|
|
288
|
+
const issues: DebugValidationIssue[] = [];
|
|
289
|
+
let inputStatus: DebugContractStatus["input"] = "absent";
|
|
290
|
+
if (route?.inputSchema || route?.querySchema || route?.paramsSchema || route?.headersSchema) {
|
|
291
|
+
inputStatus = "valid";
|
|
292
|
+
if (route.inputSchema) {
|
|
293
|
+
issues.push(...await validatePart(route.inputSchema, body, "body"));
|
|
294
|
+
}
|
|
295
|
+
if (route.querySchema) {
|
|
296
|
+
issues.push(...await validatePart(route.querySchema, query, "query"));
|
|
297
|
+
}
|
|
298
|
+
if (route.paramsSchema) {
|
|
299
|
+
issues.push(...await validatePart(route.paramsSchema, params, "params"));
|
|
300
|
+
}
|
|
301
|
+
if (route.headersSchema) {
|
|
302
|
+
issues.push(...await validatePart(route.headersSchema, headers, "headers"));
|
|
303
|
+
}
|
|
304
|
+
if (issues.length) inputStatus = "invalid";
|
|
305
|
+
}
|
|
306
|
+
if (spec.validate === false) inputStatus = "skipped";
|
|
307
|
+
|
|
308
|
+
const resolvedPath = fillPath(route.path, params);
|
|
309
|
+
const baseUrl = spec.baseUrl ?? defaultBaseUrl(context.application);
|
|
310
|
+
const url = joinUrl(baseUrl, resolvedPath, query);
|
|
311
|
+
|
|
312
|
+
const keys = redactionKeys(context);
|
|
313
|
+
const resolved: DebugResolvedRequest = {
|
|
314
|
+
method,
|
|
315
|
+
path: resolvedPath,
|
|
316
|
+
url,
|
|
317
|
+
params,
|
|
318
|
+
query,
|
|
319
|
+
headers: redactHeaders(headers, keys),
|
|
320
|
+
...(body !== undefined ? {body: redactValue(body, {keys})} : {}),
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
resolved,
|
|
325
|
+
raw: {
|
|
326
|
+
headers,
|
|
327
|
+
query,
|
|
328
|
+
params,
|
|
329
|
+
...(body !== undefined ? {body} : {}),
|
|
330
|
+
},
|
|
331
|
+
route,
|
|
332
|
+
contract: {
|
|
333
|
+
input: inputStatus,
|
|
334
|
+
output: route?.outputSchema ? "unknown" : "absent",
|
|
335
|
+
issues,
|
|
336
|
+
route: `${method} ${route.path}`,
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
interface MockReply {
|
|
342
|
+
statusCode: number;
|
|
343
|
+
headers: Record<string, string>;
|
|
344
|
+
body?: any;
|
|
345
|
+
status(code: number): MockReply;
|
|
346
|
+
header(name: string, value: any): MockReply;
|
|
347
|
+
send(body: any): void;
|
|
348
|
+
json(body: any): void;
|
|
349
|
+
type(value: string): MockReply;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function mockReply(): MockReply {
|
|
353
|
+
const reply: MockReply = {
|
|
354
|
+
statusCode: 200,
|
|
355
|
+
headers: {},
|
|
356
|
+
body: undefined,
|
|
357
|
+
status(code: number) {
|
|
358
|
+
reply.statusCode = code;
|
|
359
|
+
return reply;
|
|
360
|
+
},
|
|
361
|
+
header(name: string, value: any) {
|
|
362
|
+
reply.headers[name.toLowerCase()] = String(value);
|
|
363
|
+
return reply;
|
|
364
|
+
},
|
|
365
|
+
send(body: any) {
|
|
366
|
+
reply.body = body;
|
|
367
|
+
},
|
|
368
|
+
json(body: any) {
|
|
369
|
+
reply.body = body;
|
|
370
|
+
},
|
|
371
|
+
type() {
|
|
372
|
+
return reply;
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
return reply;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function parseTraceparent(value: string | undefined): string | undefined {
|
|
379
|
+
if (!value) return undefined;
|
|
380
|
+
const match = value.trim().match(/^[0-9a-f]{2}-([0-9a-f]{32})-/i);
|
|
381
|
+
return match?.[1];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function readHeader(headers: any, name: string): string | undefined {
|
|
385
|
+
if (!headers) return undefined;
|
|
386
|
+
if (typeof headers.get === "function") return headers.get(name) ?? undefined;
|
|
387
|
+
const lower = name.toLowerCase();
|
|
388
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
389
|
+
if (key.toLowerCase() === lower && value !== undefined) return String(value);
|
|
390
|
+
}
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async function executeInProcess(
|
|
395
|
+
application: ApplicationInterface,
|
|
396
|
+
prepared: PreparedInvocation,
|
|
397
|
+
timeoutMs: number,
|
|
398
|
+
): Promise<{status: number; body: any; headers: Record<string, string>; durationMs: number}> {
|
|
399
|
+
const reply = mockReply();
|
|
400
|
+
const headers = new Headers();
|
|
401
|
+
for (const [key, value] of Object.entries(prepared.raw.headers ?? {})) {
|
|
402
|
+
headers.set(key, String(value));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const url = prepared.resolved.url.includes("://")
|
|
406
|
+
? new URL(prepared.resolved.url).pathname + new URL(prepared.resolved.url).search
|
|
407
|
+
: prepared.resolved.url;
|
|
408
|
+
|
|
409
|
+
const req: any = {
|
|
410
|
+
method: prepared.resolved.method,
|
|
411
|
+
url,
|
|
412
|
+
headers,
|
|
413
|
+
body: prepared.raw.body,
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const started = performance.now();
|
|
417
|
+
let timer: any;
|
|
418
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
419
|
+
timer = setTimeout(() => reject(new DebugInvocationError(
|
|
420
|
+
`Invocation timed out after ${timeoutMs}ms`,
|
|
421
|
+
{
|
|
422
|
+
code: "INVOCATION_TIMEOUT",
|
|
423
|
+
hint: "Raise --timeout or check that the handler is not blocked.",
|
|
424
|
+
exitCode: 2,
|
|
425
|
+
},
|
|
426
|
+
)), timeoutMs);
|
|
427
|
+
(timer as any)?.unref?.();
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
await Promise.race([
|
|
432
|
+
(application as any).handle(req, reply),
|
|
433
|
+
timeout,
|
|
434
|
+
]);
|
|
435
|
+
} finally {
|
|
436
|
+
clearTimeout(timer);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return {
|
|
440
|
+
status: reply.statusCode,
|
|
441
|
+
body: reply.body,
|
|
442
|
+
headers: reply.headers,
|
|
443
|
+
durationMs: performance.now() - started,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
async function executeOverHttp(
|
|
448
|
+
prepared: PreparedInvocation,
|
|
449
|
+
timeoutMs: number,
|
|
450
|
+
): Promise<{status: number; body: any; headers: Record<string, string>; durationMs: number}> {
|
|
451
|
+
const controller = new AbortController();
|
|
452
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
453
|
+
(timer as any)?.unref?.();
|
|
454
|
+
const started = performance.now();
|
|
455
|
+
|
|
456
|
+
try {
|
|
457
|
+
const response = await fetch(prepared.resolved.url, {
|
|
458
|
+
method: prepared.resolved.method,
|
|
459
|
+
headers: prepared.raw.headers as any,
|
|
460
|
+
...(prepared.raw.body !== undefined && prepared.resolved.method !== "GET" && prepared.resolved.method !== "HEAD"
|
|
461
|
+
? {body: typeof prepared.raw.body === "string" ? prepared.raw.body : JSON.stringify(prepared.raw.body)}
|
|
462
|
+
: {}),
|
|
463
|
+
signal: controller.signal,
|
|
464
|
+
});
|
|
465
|
+
const text = await response.text();
|
|
466
|
+
let body: any = undefined;
|
|
467
|
+
if (text) {
|
|
468
|
+
try {
|
|
469
|
+
body = JSON.parse(text);
|
|
470
|
+
} catch {
|
|
471
|
+
body = text;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const headers: Record<string, string> = {};
|
|
475
|
+
response.headers.forEach((value, key) => {
|
|
476
|
+
headers[key.toLowerCase()] = value;
|
|
477
|
+
});
|
|
478
|
+
return {status: response.status, body, headers, durationMs: performance.now() - started};
|
|
479
|
+
} catch (error: any) {
|
|
480
|
+
if (error?.name === "AbortError") {
|
|
481
|
+
throw new DebugInvocationError(
|
|
482
|
+
`Invocation timed out after ${timeoutMs}ms`,
|
|
483
|
+
{
|
|
484
|
+
code: "INVOCATION_TIMEOUT",
|
|
485
|
+
hint: "Raise --timeout or verify the target application is responsive.",
|
|
486
|
+
exitCode: 2,
|
|
487
|
+
},
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
throw new DebugInvocationError(
|
|
491
|
+
`Cannot reach ${prepared.resolved.url}: ${error?.message ?? error}`,
|
|
492
|
+
{
|
|
493
|
+
code: "CONNECTION_FAILED",
|
|
494
|
+
hint: "Start the application or pass --url <base> to target a running instance.",
|
|
495
|
+
exitCode: 2,
|
|
496
|
+
},
|
|
497
|
+
);
|
|
498
|
+
} finally {
|
|
499
|
+
clearTimeout(timer);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function nextActions(method: string, path: string, requestId?: string, exampleName?: string): string[] {
|
|
504
|
+
const actions: string[] = [];
|
|
505
|
+
if (requestId) actions.push(`raiton explain ${requestId}`);
|
|
506
|
+
if (exampleName) actions.push(`raiton call ${method} ${path} --example ${exampleName}`);
|
|
507
|
+
else actions.push(`raiton call ${method} ${path} --dry-run`);
|
|
508
|
+
return actions;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Resolve, validate, send and normalize a route invocation. Input validation
|
|
513
|
+
* runs before any handler execution; an invalid payload is never sent.
|
|
514
|
+
*/
|
|
515
|
+
export async function invokeRoute(
|
|
516
|
+
context: InvocationContext,
|
|
517
|
+
spec: DebugInvocationRequest,
|
|
518
|
+
): Promise<DebugInvocationResult> {
|
|
519
|
+
const prepared = await prepareInvocation(context, spec);
|
|
520
|
+
const requestId = generateRequestId();
|
|
521
|
+
const timeoutMs = Number.isFinite(spec.timeoutMs) ? Number(spec.timeoutMs) : 10_000;
|
|
522
|
+
const keys = redactionKeys(context);
|
|
523
|
+
const maxBodyBytes = context.config?.journal.maxBodyBytes ?? 65_536;
|
|
524
|
+
|
|
525
|
+
if (prepared.contract.input === "invalid") {
|
|
526
|
+
return {
|
|
527
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
528
|
+
request: {
|
|
529
|
+
method: prepared.resolved.method,
|
|
530
|
+
path: prepared.resolved.path,
|
|
531
|
+
url: prepared.resolved.url,
|
|
532
|
+
headers: prepared.resolved.headers,
|
|
533
|
+
query: prepared.resolved.query,
|
|
534
|
+
...(Object.keys(prepared.resolved.params ?? {}).length ? {params: prepared.resolved.params} : {}),
|
|
535
|
+
...(prepared.resolved.body !== undefined ? {body: prepared.resolved.body} : {}),
|
|
536
|
+
dryRun: true,
|
|
537
|
+
},
|
|
538
|
+
response: {
|
|
539
|
+
status: 0,
|
|
540
|
+
durationMs: 0,
|
|
541
|
+
requestId,
|
|
542
|
+
traceId: generateTraceId(),
|
|
543
|
+
},
|
|
544
|
+
contract: {...prepared.contract, output: "unknown"},
|
|
545
|
+
nextActions: [
|
|
546
|
+
`raiton call ${prepared.resolved.method} ${prepared.resolved.path} --dry-run`,
|
|
547
|
+
...(prepared.route?.examples?.length ? [`raiton call ${prepared.resolved.method} ${prepared.resolved.path} --example ${prepared.route.examples[0].name}`] : []),
|
|
548
|
+
],
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (spec.dryRun) {
|
|
553
|
+
return {
|
|
554
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
555
|
+
request: {
|
|
556
|
+
method: prepared.resolved.method,
|
|
557
|
+
path: prepared.resolved.path,
|
|
558
|
+
url: prepared.resolved.url,
|
|
559
|
+
headers: prepared.resolved.headers,
|
|
560
|
+
query: prepared.resolved.query,
|
|
561
|
+
...(Object.keys(prepared.resolved.params ?? {}).length ? {params: prepared.resolved.params} : {}),
|
|
562
|
+
...(prepared.resolved.body !== undefined ? {body: prepared.resolved.body} : {}),
|
|
563
|
+
dryRun: true,
|
|
564
|
+
},
|
|
565
|
+
response: {
|
|
566
|
+
status: 0,
|
|
567
|
+
durationMs: 0,
|
|
568
|
+
requestId,
|
|
569
|
+
traceId: generateTraceId(),
|
|
570
|
+
},
|
|
571
|
+
contract: {...prepared.contract, output: "unknown"},
|
|
572
|
+
nextActions: nextActions(prepared.resolved.method, prepared.resolved.path, undefined, spec.example),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const executed = context.baseUrl && !context.application
|
|
577
|
+
? await executeOverHttp(prepared, timeoutMs)
|
|
578
|
+
: context.application
|
|
579
|
+
? await executeInProcess(context.application, prepared, timeoutMs)
|
|
580
|
+
: await executeOverHttp(prepared, timeoutMs);
|
|
581
|
+
|
|
582
|
+
let outputStatus: DebugContractStatus["output"] = "absent";
|
|
583
|
+
const outputIssues: DebugValidationIssue[] = [];
|
|
584
|
+
if (prepared.route?.outputSchema) {
|
|
585
|
+
outputStatus = "valid";
|
|
586
|
+
const {validateContract} = await import("../contracts/index.ts");
|
|
587
|
+
const result = await validateContract(prepared.route.outputSchema as any, executed.body);
|
|
588
|
+
if (!result.success) {
|
|
589
|
+
outputStatus = "invalid";
|
|
590
|
+
outputIssues.push(...issueFromValidation(result.issues));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const responseRequestId = readHeader(executed.headers, "x-request-id") ?? requestId;
|
|
595
|
+
const responseTraceId = parseTraceparent(readHeader(executed.headers, "traceparent"))
|
|
596
|
+
?? readHeader(executed.headers, "x-trace-id")
|
|
597
|
+
?? generateTraceId();
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
601
|
+
request: {
|
|
602
|
+
method: prepared.resolved.method,
|
|
603
|
+
path: prepared.resolved.path,
|
|
604
|
+
url: prepared.resolved.url,
|
|
605
|
+
headers: prepared.resolved.headers,
|
|
606
|
+
query: prepared.resolved.query,
|
|
607
|
+
...(Object.keys(prepared.resolved.params ?? {}).length ? {params: prepared.resolved.params} : {}),
|
|
608
|
+
...(prepared.resolved.body !== undefined ? {body: prepared.resolved.body} : {}),
|
|
609
|
+
},
|
|
610
|
+
response: {
|
|
611
|
+
status: executed.status,
|
|
612
|
+
durationMs: Math.round(executed.durationMs * 100) / 100,
|
|
613
|
+
requestId: responseRequestId,
|
|
614
|
+
traceId: responseTraceId,
|
|
615
|
+
...(executed.body !== undefined
|
|
616
|
+
? {body: truncateValue(redactValue(executed.body, {keys}), maxBodyBytes)}
|
|
617
|
+
: {}),
|
|
618
|
+
},
|
|
619
|
+
contract: {
|
|
620
|
+
input: prepared.contract.input,
|
|
621
|
+
output: outputStatus,
|
|
622
|
+
issues: [...prepared.contract.issues, ...outputIssues],
|
|
623
|
+
...(prepared.contract.route ? {route: prepared.contract.route} : {}),
|
|
624
|
+
},
|
|
625
|
+
nextActions: nextActions(
|
|
626
|
+
prepared.resolved.method,
|
|
627
|
+
prepared.resolved.path,
|
|
628
|
+
responseRequestId,
|
|
629
|
+
spec.example,
|
|
630
|
+
),
|
|
631
|
+
...(spec.replayedFrom ? {replayedFrom: spec.replayedFrom} : {}),
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function generateTraceId(): string {
|
|
636
|
+
let output = "";
|
|
637
|
+
while (output.length < 32) {
|
|
638
|
+
output += Math.floor(Math.random() * 0xffffffff).toString(16).padStart(8, "0");
|
|
639
|
+
}
|
|
640
|
+
return output.slice(0, 32);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function stableStringify(value: any): string | undefined {
|
|
644
|
+
if (value === undefined) return undefined;
|
|
645
|
+
try {
|
|
646
|
+
return JSON.stringify(value);
|
|
647
|
+
} catch {
|
|
648
|
+
return String(value);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Compare a replay with the original journal entry. Captured bodies may be
|
|
654
|
+
* absent in metadata mode, in which case the body comparison is `unknown`.
|
|
655
|
+
*/
|
|
656
|
+
export function compareReplay(
|
|
657
|
+
previous: DebugJournalEntry,
|
|
658
|
+
result: DebugInvocationResult,
|
|
659
|
+
): DebugReplayComparison {
|
|
660
|
+
const differences: string[] = [];
|
|
661
|
+
const previousStatus = previous.response.status;
|
|
662
|
+
const currentStatus = result.response.status;
|
|
663
|
+
if (previousStatus !== currentStatus) {
|
|
664
|
+
differences.push(`status: ${previousStatus} → ${currentStatus}`);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const previousCode = previous.error?.code;
|
|
668
|
+
const currentCode = (result.response.body as any)?.code;
|
|
669
|
+
if (previousCode && currentCode && previousCode !== currentCode) {
|
|
670
|
+
differences.push(`error code: ${previousCode} → ${currentCode}`);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const previousIssues = (previous.validation?.issues ?? []).map(issue => issue.path).sort().join(",");
|
|
674
|
+
const currentIssues = (result.contract.issues ?? []).map(issue => issue.path).sort().join(",");
|
|
675
|
+
if (previousIssues !== currentIssues) {
|
|
676
|
+
differences.push(`validation fields: [${previousIssues}] → [${currentIssues}]`);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const previousBody = stableStringify(previous.response.body);
|
|
680
|
+
const currentBody = stableStringify(result.response.body);
|
|
681
|
+
const body = previousBody === undefined || currentBody === undefined
|
|
682
|
+
? "unknown"
|
|
683
|
+
: previousBody === currentBody ? "same" : "changed";
|
|
684
|
+
if (body === "changed") differences.push("response body changed");
|
|
685
|
+
|
|
686
|
+
return {
|
|
687
|
+
status: previousStatus === currentStatus ? "same" : "changed",
|
|
688
|
+
body,
|
|
689
|
+
previousStatus,
|
|
690
|
+
currentStatus,
|
|
691
|
+
differences,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export {DEFAULT_REDACT_KEYS, exampleForSchema};
|