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,136 @@
|
|
|
1
|
+
import {getDebugJournal, getDebugRuntime} from "./runtime.ts";
|
|
2
|
+
import {loadSessionJournal, readSessionEntries} from "./session.ts";
|
|
3
|
+
import {matchStatus} from "./journal.ts";
|
|
4
|
+
import type {DebugJournalEntry, DebugRequestsList} from "./types.ts";
|
|
5
|
+
import {DEBUG_SCHEMA_VERSION} from "./types.ts";
|
|
6
|
+
|
|
7
|
+
export interface ListRequestsOptions {
|
|
8
|
+
since?: string | number;
|
|
9
|
+
status?: string;
|
|
10
|
+
route?: string;
|
|
11
|
+
limit?: number;
|
|
12
|
+
includeBodies?: boolean;
|
|
13
|
+
workdir?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Parse `5m`, `30s`, `2h`, `1000ms` or a number of milliseconds. */
|
|
17
|
+
export function parseSince(value?: string | number): number | undefined {
|
|
18
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
19
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : undefined;
|
|
20
|
+
const text = String(value).trim().toLowerCase();
|
|
21
|
+
const match = text.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)?$/);
|
|
22
|
+
if (!match) return undefined;
|
|
23
|
+
const amount = Number(match[1]);
|
|
24
|
+
const unit = match[2] ?? "ms";
|
|
25
|
+
const factor = unit === "ms" ? 1 : unit === "s" ? 1_000 : unit === "m" ? 60_000 : unit === "h" ? 3_600_000 : 86_400_000;
|
|
26
|
+
return amount * factor;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface RequestLookup {
|
|
30
|
+
entry: DebugJournalEntry;
|
|
31
|
+
origin: "journal" | "session";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Find a request by id in the in-memory journal, then in the bounded CLI
|
|
36
|
+
* session file. Returns `undefined` when neither contains it.
|
|
37
|
+
*/
|
|
38
|
+
export function findRequest(requestId: string, workdir?: string): RequestLookup | undefined {
|
|
39
|
+
const journal = getDebugJournal();
|
|
40
|
+
const entry = journal?.get(requestId);
|
|
41
|
+
if (entry) return {entry, origin: "journal"};
|
|
42
|
+
|
|
43
|
+
for (const candidate of readSessionEntries(workdir ?? getDebugRuntime()?.workdir)) {
|
|
44
|
+
if (candidate.requestId === requestId) return {entry: candidate, origin: "session"};
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function lastRequest(workdir?: string): RequestLookup | undefined {
|
|
50
|
+
const journal = getDebugJournal();
|
|
51
|
+
const inMemory = journal?.last();
|
|
52
|
+
if (inMemory) return {entry: inMemory, origin: "journal"};
|
|
53
|
+
|
|
54
|
+
const entries = readSessionEntries(workdir ?? getDebugRuntime()?.workdir);
|
|
55
|
+
const last = entries[entries.length - 1];
|
|
56
|
+
return last ? {entry: last, origin: "session"} : undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function summary(entry: DebugJournalEntry) {
|
|
60
|
+
return {
|
|
61
|
+
requestId: entry.requestId,
|
|
62
|
+
traceId: entry.traceId,
|
|
63
|
+
startedAt: entry.startedAt,
|
|
64
|
+
method: entry.request.method,
|
|
65
|
+
route: entry.request.route,
|
|
66
|
+
status: entry.response.status,
|
|
67
|
+
durationMs: entry.response.durationMs,
|
|
68
|
+
...(entry.stale ? {stale: true} : {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* List retained requests, most recent first. Bodies are omitted by default so
|
|
74
|
+
* the output stays token-efficient.
|
|
75
|
+
*/
|
|
76
|
+
export function listRequests(options: ListRequestsOptions = {}): DebugRequestsList {
|
|
77
|
+
const runtime = getDebugRuntime();
|
|
78
|
+
const journal = getDebugJournal();
|
|
79
|
+
const session = !journal
|
|
80
|
+
? loadSessionJournal(options.workdir ?? runtime?.workdir)
|
|
81
|
+
: undefined;
|
|
82
|
+
const source = journal ?? session;
|
|
83
|
+
|
|
84
|
+
const limit = Math.max(0, Math.floor(Number.isFinite(Number(options.limit)) ? Number(options.limit) : 20));
|
|
85
|
+
const sinceMs = parseSince(options.since);
|
|
86
|
+
|
|
87
|
+
const entries = source?.recent({
|
|
88
|
+
sinceMs,
|
|
89
|
+
status: options.status,
|
|
90
|
+
route: options.route,
|
|
91
|
+
limit,
|
|
92
|
+
}) ?? [];
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
96
|
+
count: entries.length,
|
|
97
|
+
capacity: source?.capacity ?? runtime?.config.journal.capacity ?? 1_000,
|
|
98
|
+
enabled: Boolean(journal || session),
|
|
99
|
+
requests: entries.map(summary),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Used by the HTTP surface when `includeBodies` is requested. */
|
|
104
|
+
export function listRequestsWithBodies(options: ListRequestsOptions = {}): DebugRequestsList & {entries: DebugJournalEntry[]} {
|
|
105
|
+
const runtime = getDebugRuntime();
|
|
106
|
+
const journal = getDebugJournal();
|
|
107
|
+
const session = !journal ? loadSessionJournal(options.workdir ?? runtime?.workdir) : undefined;
|
|
108
|
+
const source = journal ?? session;
|
|
109
|
+
const limit = Math.max(0, Math.floor(Number.isFinite(Number(options.limit)) ? Number(options.limit) : 20));
|
|
110
|
+
const entries = source?.recent({
|
|
111
|
+
sinceMs: parseSince(options.since),
|
|
112
|
+
status: options.status,
|
|
113
|
+
route: options.route,
|
|
114
|
+
limit,
|
|
115
|
+
}) ?? [];
|
|
116
|
+
return {
|
|
117
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
118
|
+
count: entries.length,
|
|
119
|
+
capacity: source?.capacity ?? 1_000,
|
|
120
|
+
enabled: Boolean(journal || session),
|
|
121
|
+
requests: entries.map(summary),
|
|
122
|
+
entries,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export {matchStatus};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Resolve the invocation path for a captured entry. Metadata capture omits
|
|
130
|
+
* params, so the concrete path is the only replayable form in that mode.
|
|
131
|
+
*/
|
|
132
|
+
export function replayPath(entry: DebugJournalEntry): string {
|
|
133
|
+
const hasParams = entry.request.params && Object.keys(entry.request.params).length > 0;
|
|
134
|
+
if (hasParams) return entry.request.pattern || entry.request.route;
|
|
135
|
+
return entry.request.path || entry.request.pattern || entry.request.route;
|
|
136
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type {ApplicationInterface} from "../types/application.ts";
|
|
3
|
+
import type {ProjectManifest} from "../manifest/schema.ts";
|
|
4
|
+
import {DebugCollector} from "./collector.ts";
|
|
5
|
+
import {DebugJournal} from "./journal.ts";
|
|
6
|
+
import type {DebugLogLine, ResolvedDebugConfig} from "./types.ts";
|
|
7
|
+
|
|
8
|
+
const GLOBAL_KEY = "__raitonDebugRuntime";
|
|
9
|
+
const LOG_CAPACITY = 200;
|
|
10
|
+
|
|
11
|
+
export interface DebugLogBuffer {
|
|
12
|
+
record(level: string, message: string): void;
|
|
13
|
+
tail(limit?: number): DebugLogLine[];
|
|
14
|
+
clear(): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function maskSecrets(message: string): string {
|
|
18
|
+
return String(message)
|
|
19
|
+
.replace(/(authorization\s*[:=]\s*)([^\s,;]+)/gi, "$1***")
|
|
20
|
+
.replace(/(bearer\s+)([A-Za-z0-9._~+/=-]+)/gi, "$1***")
|
|
21
|
+
.replace(/((?:password|passwd|secret|token|api[-_]?key)\s*[:=]\s*["']?)([^\s"',;]+)/gi, "$1***")
|
|
22
|
+
.slice(0, 512);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createLogBuffer(): DebugLogBuffer {
|
|
26
|
+
const lines: DebugLogLine[] = [];
|
|
27
|
+
return {
|
|
28
|
+
record(level, message) {
|
|
29
|
+
try {
|
|
30
|
+
lines.push({at: new Date().toISOString(), level, message: maskSecrets(String(message))});
|
|
31
|
+
if (lines.length > LOG_CAPACITY) lines.splice(0, lines.length - LOG_CAPACITY);
|
|
32
|
+
} catch {
|
|
33
|
+
// Logging must never fail.
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
tail(limit = 50) {
|
|
37
|
+
return lines.slice(Math.max(0, lines.length - Math.max(0, limit)));
|
|
38
|
+
},
|
|
39
|
+
clear() {
|
|
40
|
+
lines.length = 0;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DebugRuntimeState {
|
|
46
|
+
config: ResolvedDebugConfig;
|
|
47
|
+
journal?: DebugJournal;
|
|
48
|
+
collector?: DebugCollector;
|
|
49
|
+
buildId: string;
|
|
50
|
+
development: boolean;
|
|
51
|
+
workdir: string;
|
|
52
|
+
application?: ApplicationInterface;
|
|
53
|
+
logs: DebugLogBuffer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ConfigureDebugOptions {
|
|
57
|
+
config: ResolvedDebugConfig;
|
|
58
|
+
development: boolean;
|
|
59
|
+
workdir?: string;
|
|
60
|
+
application?: ApplicationInterface;
|
|
61
|
+
buildId?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function newBuildId(): string {
|
|
65
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Configure the process-wide debug runtime. The journal survives HMR reloads
|
|
70
|
+
* (it lives on `globalThis`) while a new build id marks older entries stale.
|
|
71
|
+
*/
|
|
72
|
+
export function configureDebug(options: ConfigureDebugOptions): DebugRuntimeState {
|
|
73
|
+
const global = globalThis as any;
|
|
74
|
+
const previous: DebugRuntimeState | undefined = global[GLOBAL_KEY];
|
|
75
|
+
const buildId = options.buildId ?? (previous ? newBuildId() : newBuildId());
|
|
76
|
+
const workdir = options.workdir ?? previous?.workdir ?? process.cwd();
|
|
77
|
+
|
|
78
|
+
let journal: DebugJournal | undefined;
|
|
79
|
+
if (options.config.journal.enabled && options.config.journal.capture !== "off") {
|
|
80
|
+
journal = new DebugJournal({
|
|
81
|
+
capacity: options.config.journal.capacity,
|
|
82
|
+
ttlMs: options.config.journal.ttlMs,
|
|
83
|
+
maxTotalBytes: options.config.journal.maxTotalBytes,
|
|
84
|
+
});
|
|
85
|
+
// Preserve entries across HMR by moving them into the new journal.
|
|
86
|
+
if (previous?.journal) {
|
|
87
|
+
const retained = previous.journal.recent({limit: options.config.journal.capacity});
|
|
88
|
+
for (const entry of retained.reverse()) journal.push(entry);
|
|
89
|
+
}
|
|
90
|
+
journal.setBuildId(buildId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const collector = journal
|
|
94
|
+
? new DebugCollector({
|
|
95
|
+
config: options.config,
|
|
96
|
+
journal,
|
|
97
|
+
buildId,
|
|
98
|
+
development: options.development,
|
|
99
|
+
})
|
|
100
|
+
: undefined;
|
|
101
|
+
|
|
102
|
+
const state: DebugRuntimeState = {
|
|
103
|
+
config: options.config,
|
|
104
|
+
journal,
|
|
105
|
+
collector,
|
|
106
|
+
buildId,
|
|
107
|
+
development: options.development,
|
|
108
|
+
workdir,
|
|
109
|
+
application: options.application ?? previous?.application,
|
|
110
|
+
logs: previous?.logs ?? createLogBuffer(),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
global[GLOBAL_KEY] = state;
|
|
114
|
+
return state;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function getDebugRuntime(): DebugRuntimeState | undefined {
|
|
118
|
+
return (globalThis as any)[GLOBAL_KEY] as DebugRuntimeState | undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function getDebugCollector(): DebugCollector | undefined {
|
|
122
|
+
return getDebugRuntime()?.collector;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function getDebugJournal(): DebugJournal | undefined {
|
|
126
|
+
return getDebugRuntime()?.journal;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function isDebugJournalEnabled(): boolean {
|
|
130
|
+
const runtime = getDebugRuntime();
|
|
131
|
+
return Boolean(runtime?.config.journal.enabled && runtime.journal);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function resetDebugRuntime(): void {
|
|
135
|
+
delete (globalThis as any)[GLOBAL_KEY];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Mark every retained entry as stale after a hot reload. The journal survives,
|
|
140
|
+
* but old entries are never mixed with the new build without a marker.
|
|
141
|
+
*/
|
|
142
|
+
export function rotateDebugBuild(): void {
|
|
143
|
+
const runtime = getDebugRuntime();
|
|
144
|
+
if (!runtime) return;
|
|
145
|
+
const buildId = newBuildId();
|
|
146
|
+
runtime.buildId = buildId;
|
|
147
|
+
if (runtime.collector) runtime.collector.buildId = buildId;
|
|
148
|
+
runtime.journal?.setBuildId(buildId);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function recordDebugLog(level: string, message: string): void {
|
|
152
|
+
getDebugRuntime()?.logs.record(level, message);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface DebugContextOptions {
|
|
156
|
+
workdir?: string;
|
|
157
|
+
application?: ApplicationInterface;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function setDebugContext(options: DebugContextOptions): void {
|
|
161
|
+
const runtime = getDebugRuntime();
|
|
162
|
+
if (!runtime) return;
|
|
163
|
+
if (options.workdir) runtime.workdir = options.workdir;
|
|
164
|
+
if (options.application) runtime.application = options.application;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Load the live project manifest, using the existing cache when possible. */
|
|
168
|
+
export async function loadDebugManifest(refresh = false): Promise<ProjectManifest> {
|
|
169
|
+
const runtime = getDebugRuntime();
|
|
170
|
+
if (!runtime) {
|
|
171
|
+
throw new Error("Debug runtime is not configured");
|
|
172
|
+
}
|
|
173
|
+
const {generateManifest} = await import("../manifest/manifest.ts");
|
|
174
|
+
return generateManifest({workdir: runtime.workdir, refresh});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Resolve the session-journal file used to bridge short-lived CLI processes. */
|
|
178
|
+
export function sessionJournalFile(workdir?: string): string {
|
|
179
|
+
const root = workdir ?? getDebugRuntime()?.workdir ?? process.cwd();
|
|
180
|
+
return path.join(root, ".raiton", "debug-session.json");
|
|
181
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {DebugJournal} from "./journal.ts";
|
|
4
|
+
import {sessionJournalFile} from "./runtime.ts";
|
|
5
|
+
import type {DebugJournalEntry} from "./types.ts";
|
|
6
|
+
import {DEBUG_SCHEMA_VERSION, DebugSchemaVersionError, isSupportedDebugSchemaVersion} from "./types.ts";
|
|
7
|
+
|
|
8
|
+
const MAX_ENTRIES = 1_000;
|
|
9
|
+
const MAX_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
const TTL_MS = 900_000;
|
|
11
|
+
|
|
12
|
+
interface DebugSessionFile {
|
|
13
|
+
schemaVersion: string;
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
entries: DebugJournalEntry[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function empty(): DebugSessionFile {
|
|
19
|
+
return {schemaVersion: DEBUG_SCHEMA_VERSION, updatedAt: new Date().toISOString(), entries: []};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Read the bounded CLI session journal.
|
|
24
|
+
*
|
|
25
|
+
* The in-memory journal remains the runtime source of truth; this file only
|
|
26
|
+
* bridges two short-lived CLI processes (`raiton call` then `raiton explain`)
|
|
27
|
+
* when no running application is targeted. It is bounded, expires after 15
|
|
28
|
+
* minutes and is never written on a request hot path.
|
|
29
|
+
*/
|
|
30
|
+
export function readSessionFile(workdir?: string): DebugSessionFile {
|
|
31
|
+
const filename = sessionJournalFile(workdir);
|
|
32
|
+
try {
|
|
33
|
+
if (!fs.existsSync(filename)) return empty();
|
|
34
|
+
const raw = fs.readFileSync(filename, "utf-8");
|
|
35
|
+
if (!raw.trim()) return empty();
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (!parsed || !Array.isArray(parsed.entries)) return empty();
|
|
38
|
+
if (!isSupportedDebugSchemaVersion(parsed.schemaVersion)) {
|
|
39
|
+
throw new DebugSchemaVersionError(parsed.schemaVersion);
|
|
40
|
+
}
|
|
41
|
+
const threshold = Date.now() - TTL_MS;
|
|
42
|
+
return {
|
|
43
|
+
schemaVersion: typeof parsed.schemaVersion === "string" ? parsed.schemaVersion : DEBUG_SCHEMA_VERSION,
|
|
44
|
+
updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : new Date().toISOString(),
|
|
45
|
+
entries: parsed.entries
|
|
46
|
+
.filter((entry: DebugJournalEntry) =>
|
|
47
|
+
entry
|
|
48
|
+
&& typeof entry.requestId === "string"
|
|
49
|
+
&& Date.parse(entry.startedAt) >= threshold)
|
|
50
|
+
.slice(-MAX_ENTRIES),
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof DebugSchemaVersionError) throw error;
|
|
54
|
+
return empty();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function readSessionEntries(workdir?: string): DebugJournalEntry[] {
|
|
59
|
+
return readSessionFile(workdir).entries;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function loadSessionJournal(workdir?: string): DebugJournal {
|
|
63
|
+
const journal = new DebugJournal({capacity: MAX_ENTRIES, ttlMs: TTL_MS, maxTotalBytes: MAX_BYTES});
|
|
64
|
+
for (const entry of readSessionEntries(workdir)) journal.push(entry);
|
|
65
|
+
return journal;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function appendSessionEntry(entry: DebugJournalEntry, workdir?: string): void {
|
|
69
|
+
if (!entry?.requestId) return;
|
|
70
|
+
const file = readSessionFile(workdir);
|
|
71
|
+
const entries = file.entries.filter(candidate => candidate.requestId !== entry.requestId);
|
|
72
|
+
entries.push(entry);
|
|
73
|
+
const bounded = entries.slice(-MAX_ENTRIES);
|
|
74
|
+
const payload: DebugSessionFile = {
|
|
75
|
+
schemaVersion: DEBUG_SCHEMA_VERSION,
|
|
76
|
+
updatedAt: new Date().toISOString(),
|
|
77
|
+
entries: bounded,
|
|
78
|
+
};
|
|
79
|
+
const serialized = JSON.stringify(payload);
|
|
80
|
+
if (serialized.length > MAX_BYTES) {
|
|
81
|
+
// Keep the newest entries that fit, without ever failing the command.
|
|
82
|
+
while (payload.entries.length > 1 && JSON.stringify(payload).length > MAX_BYTES) {
|
|
83
|
+
payload.entries.shift();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
writeAtomic(sessionJournalFile(workdir), JSON.stringify(payload));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function clearSessionJournal(workdir?: string): void {
|
|
90
|
+
try {
|
|
91
|
+
const filename = sessionJournalFile(workdir);
|
|
92
|
+
if (fs.existsSync(filename)) fs.rmSync(filename, {force: true});
|
|
93
|
+
} catch {
|
|
94
|
+
// Ignore.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function writeAtomic(filename: string, content: string): void {
|
|
99
|
+
try {
|
|
100
|
+
fs.mkdirSync(path.dirname(filename), {recursive: true});
|
|
101
|
+
const temporary = `${filename}.${process.pid}.tmp`;
|
|
102
|
+
fs.writeFileSync(temporary, content, "utf-8");
|
|
103
|
+
fs.renameSync(temporary, filename);
|
|
104
|
+
} catch {
|
|
105
|
+
// CLI diagnostics must not fail because the session file is read-only.
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {Injection} from "../core/injection/index.ts";
|
|
4
|
+
import type {DebugRouteSource} from "./types.ts";
|
|
5
|
+
|
|
6
|
+
const lineCache = new Map<string, number>();
|
|
7
|
+
|
|
8
|
+
export function relativePath(workdir: string, filename: string): string {
|
|
9
|
+
if (!filename) return "";
|
|
10
|
+
return path.relative(workdir, filename).split(path.sep).join("/");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Relativize a `file:line` location captured by a decorator. */
|
|
14
|
+
export function relativeLocation(location: string | undefined, workdir = process.cwd()): string | undefined {
|
|
15
|
+
if (!location) return undefined;
|
|
16
|
+
const match = location.match(/^(.*):(\d+)$/);
|
|
17
|
+
if (!match) return location;
|
|
18
|
+
const file = match[1];
|
|
19
|
+
if (!path.isAbsolute(file)) return location;
|
|
20
|
+
return `${relativePath(workdir, file)}:${match[2]}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function methodLine(filename: string, propertyKey: string): number {
|
|
24
|
+
if (!filename) return 0;
|
|
25
|
+
const key = `${filename}:${propertyKey}`;
|
|
26
|
+
const cached = lineCache.get(key);
|
|
27
|
+
if (cached !== undefined) return cached;
|
|
28
|
+
try {
|
|
29
|
+
if (!fs.existsSync(filename)) return 0;
|
|
30
|
+
const lines = fs.readFileSync(filename, "utf-8").split(/\r?\n/);
|
|
31
|
+
const escaped = propertyKey.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
32
|
+
const pattern = new RegExp(`^\\s*(?:async\\s+)?${escaped}\\s*(?:<[^>]*>)?\\s*\\(`);
|
|
33
|
+
const loose = new RegExp(`\\b${escaped}\\s*\\(`);
|
|
34
|
+
let index = lines.findIndex(line => pattern.test(line));
|
|
35
|
+
if (index < 0) index = lines.findIndex(line => loose.test(line));
|
|
36
|
+
const value = index >= 0 ? index + 1 : 0;
|
|
37
|
+
lineCache.set(key, value);
|
|
38
|
+
return value;
|
|
39
|
+
} catch {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Clear cached line numbers after an HMR reload. */
|
|
45
|
+
export function invalidateSourceCache(): void {
|
|
46
|
+
lineCache.clear();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the source location of a compiled route. Called once per handler
|
|
51
|
+
* compilation, never on the request hot path.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveRouteSource(
|
|
54
|
+
controllerClass: any,
|
|
55
|
+
controllerMeta: any,
|
|
56
|
+
routeMeta: any,
|
|
57
|
+
workdir = process.cwd(),
|
|
58
|
+
): DebugRouteSource {
|
|
59
|
+
const controller = controllerClass?.name ?? controllerMeta?.name ?? "Controller";
|
|
60
|
+
const handler = String(routeMeta?.propertyKey ?? "handler");
|
|
61
|
+
const absolute = Injection.getArtifactPath(controller) ?? "";
|
|
62
|
+
const method = String(routeMeta?.method ?? "GET").toUpperCase();
|
|
63
|
+
return {
|
|
64
|
+
file: relativePath(workdir, absolute),
|
|
65
|
+
line: methodLine(absolute, handler),
|
|
66
|
+
controller,
|
|
67
|
+
handler,
|
|
68
|
+
decorator: `@${method.charAt(0)}${method.slice(1).toLowerCase()}("${routeMeta?.path ?? ""}")`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Extract the first application frame from a stack trace. Used only in
|
|
74
|
+
* development to point at the throwing line.
|
|
75
|
+
*/
|
|
76
|
+
export function firstUserFrame(stack?: string): string | undefined {
|
|
77
|
+
if (!stack) return undefined;
|
|
78
|
+
const lines = stack.split(/\r?\n/);
|
|
79
|
+
for (const line of lines) {
|
|
80
|
+
const match = line.match(/\(?([^()\s]+):(\d+):(\d+)\)?$/);
|
|
81
|
+
if (!match) continue;
|
|
82
|
+
const file = match[1];
|
|
83
|
+
if (file.includes("node_modules")) continue;
|
|
84
|
+
if (file.includes("/source/debug/")) continue;
|
|
85
|
+
if (file.includes("/framework/errors/")) continue;
|
|
86
|
+
return `${relativePath(process.cwd(), file)}:${match[2]}`;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function stackLines(error: any, limit = 20): string[] | undefined {
|
|
92
|
+
const stack = typeof error?.stack === "string" ? error.stack : undefined;
|
|
93
|
+
if (!stack) return undefined;
|
|
94
|
+
return stack.split(/\r?\n/).slice(0, limit);
|
|
95
|
+
}
|