raiton 6.8.9-beta.25 → 6.10.0-beta.28
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 +44 -0
- package/README.md +46 -1
- package/benchmarks/README.md +16 -0
- package/benchmarks/latest.json +172 -0
- package/benchmarks/latest.md +66 -0
- package/build/bin/index.mjs +33550 -21725
- 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/client.command.d.ts +7 -0
- package/build/types/commands/contract.command.d.ts +8 -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/generate.command.d.ts +7 -0
- package/build/types/commands/inspect.command.d.ts +7 -0
- package/build/types/commands/mcp.command.d.ts +11 -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/routes.command.d.ts +7 -0
- package/build/types/commands/start.command.d.ts +9 -0
- package/build/types/commands/why.command.d.ts +7 -0
- package/build/types/contracts/decorators.d.ts +41 -0
- package/build/types/contracts/errors.d.ts +42 -0
- package/build/types/contracts/index.d.ts +4 -0
- package/build/types/contracts/schema.d.ts +70 -0
- package/build/types/contracts/typebox.d.ts +81 -0
- package/build/types/core/application.d.ts +37 -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/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 +42 -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 +177 -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 +62 -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 +26 -0
- package/docs/generated/config-schema.json +150 -0
- package/docs/generated/manifest-schema.json +236 -0
- package/docs/generated/manifest.json +101 -0
- package/docs/llms-full.txt +1271 -0
- package/docs/llms.txt +46 -0
- package/docs/user-guide/README.md +18 -12
- package/docs/user-guide/cli.md +21 -0
- package/docs/user-guide/config.md +14 -0
- package/docs/user-guide/contracts.md +67 -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 +40 -7
- 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 +23 -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/client.command.ts +64 -0
- package/source/commands/contract.command.ts +104 -0
- package/source/commands/docs.command.ts +263 -0
- package/source/commands/doctor.command.ts +226 -0
- package/source/commands/generate.command.ts +58 -0
- package/source/commands/inspect.command.ts +108 -0
- package/source/commands/mcp.command.ts +258 -0
- package/source/commands/new.command.ts +135 -0
- package/source/commands/openapi.command.ts +95 -0
- package/source/commands/routes.command.ts +39 -0
- package/source/commands/why.command.ts +61 -0
- package/source/contracts/decorators.ts +151 -0
- package/source/contracts/errors.ts +76 -0
- package/source/contracts/index.ts +4 -0
- package/source/contracts/schema.ts +377 -0
- package/source/contracts/typebox.ts +193 -0
- package/source/core/application.ts +215 -73
- package/source/core/builder.ts +6 -2
- package/source/core/config/config.ts +144 -26
- package/source/core/config/define.ts +35 -8
- package/source/core/config/index.ts +2 -1
- package/source/core/config/schema.ts +263 -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 +91 -31
- 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/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 +159 -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 +131 -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 +705 -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 +52 -0
- package/source/manifest/manifest.ts +341 -0
- package/source/manifest/schema.ts +149 -0
- package/source/types/builder.ts +5 -0
- package/source/types/config.ts +64 -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,258 @@
|
|
|
1
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
2
|
+
import {CLI_JSON_SCHEMA_VERSION, CliError, ExitCode, fail, print} from "../bin/cli-output.ts";
|
|
3
|
+
import {loadProject} from "../bin/project-utils.ts";
|
|
4
|
+
import {getMcpServer, getMcpServerRegistry} from "../core/mcp/metadata.ts";
|
|
5
|
+
import {RaitonConfig} from "../core/config/config.ts";
|
|
6
|
+
import {handleMcpRequest} from "../framework/mcp/handler.ts";
|
|
7
|
+
import {runAllConformance} from "../framework/mcp/conformance.ts";
|
|
8
|
+
import {serveMcpStdio} from "../framework/mcp/stdio.ts";
|
|
9
|
+
import type {McpInvocationContext} from "../types/index.ts";
|
|
10
|
+
|
|
11
|
+
interface ListOptions {
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface InspectOptions {
|
|
16
|
+
json?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface TestOptions {
|
|
20
|
+
args?: string;
|
|
21
|
+
scopes?: string;
|
|
22
|
+
json?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ServeOptions {
|
|
26
|
+
stdio?: boolean;
|
|
27
|
+
json?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface ConformanceOptions {
|
|
31
|
+
json?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseArgs(value?: string): Record<string, any> {
|
|
35
|
+
if (!value) return {};
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(value);
|
|
38
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
39
|
+
throw new Error("arguments must be a JSON object");
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
} catch (error: any) {
|
|
43
|
+
throw new CliError(`Invalid --args JSON: ${error.message}`, {
|
|
44
|
+
code: "INVALID_ARGUMENTS",
|
|
45
|
+
hint: "Pass a JSON object, for example --args '{\"a\":1,\"b\":2}'.",
|
|
46
|
+
exitCode: ExitCode.USAGE,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default class McpCommand extends RaitonCommand {
|
|
52
|
+
public readonly name = "mcp";
|
|
53
|
+
public readonly description = "Inspect, test and serve MCP servers";
|
|
54
|
+
|
|
55
|
+
public register(): void {
|
|
56
|
+
const command = this.cli
|
|
57
|
+
.command("mcp")
|
|
58
|
+
.description(this.description);
|
|
59
|
+
|
|
60
|
+
command
|
|
61
|
+
.command("list")
|
|
62
|
+
.description("List MCP servers and their tools")
|
|
63
|
+
.option("--json", "Emit JSON on stdout")
|
|
64
|
+
.action((options: ListOptions) => this.list(options).catch(error => fail(error, options.json)));
|
|
65
|
+
|
|
66
|
+
command
|
|
67
|
+
.command("inspect <server>")
|
|
68
|
+
.description("Show the schemas and safety annotations of an MCP server")
|
|
69
|
+
.option("--json", "Emit JSON on stdout")
|
|
70
|
+
.action((server: string, options: InspectOptions) => this.inspect(server, options).catch(error => fail(error, options.json)));
|
|
71
|
+
|
|
72
|
+
command
|
|
73
|
+
.command("test <target>")
|
|
74
|
+
.description("Call a tool; target is <server>.<tool> or <tool>")
|
|
75
|
+
.option("--args <json>", "JSON object of tool arguments", "{}")
|
|
76
|
+
.option("--scopes <scopes>", "Comma-separated scopes for the call", "")
|
|
77
|
+
.option("--json", "Emit JSON on stdout")
|
|
78
|
+
.action((target: string, options: TestOptions) => this.test(target, options).catch(error => fail(error, options.json)));
|
|
79
|
+
|
|
80
|
+
command
|
|
81
|
+
.command("serve [server]")
|
|
82
|
+
.description("Serve an MCP server over stdin/stdout")
|
|
83
|
+
.option("--stdio", "Use the stdio transport (default)", true)
|
|
84
|
+
.option("--json", "Emit JSON (not compatible with a long-running server)")
|
|
85
|
+
.action((server: string | undefined, options: ServeOptions) => this.serve(server, options).catch(error => fail(error, options.json)));
|
|
86
|
+
|
|
87
|
+
command
|
|
88
|
+
.command("conformance [server]")
|
|
89
|
+
.description("Run the shared HTTP and stdio MCP conformance suite")
|
|
90
|
+
.option("--json", "Emit JSON on stdout")
|
|
91
|
+
.action((server: string | undefined, options: ConformanceOptions) => this.conformance(server, options).catch(error => fail(error, options.json)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private async list(options: ListOptions): Promise<void> {
|
|
95
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
96
|
+
if (options.json) {
|
|
97
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, servers: manifest.mcp}, true);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!manifest.mcp.length) {
|
|
101
|
+
print("No MCP server registered.");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
for (const server of manifest.mcp) {
|
|
105
|
+
print(`${server.server} ${server.path} (${server.tools.length} tool(s))`);
|
|
106
|
+
for (const tool of server.tools) {
|
|
107
|
+
print(` - ${tool.name}${tool.exposed ? "" : " [hidden: destructive]"}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private async inspect(name: string, options: InspectOptions): Promise<void> {
|
|
113
|
+
await loadProject(this.workdir, options.json);
|
|
114
|
+
const entry = getMcpServer(name);
|
|
115
|
+
if (!entry) {
|
|
116
|
+
throw new CliError(`MCP server not found: ${name}`, {
|
|
117
|
+
code: "MCP_SERVER_NOT_FOUND",
|
|
118
|
+
hint: `Available servers: ${[...getMcpServerRegistry().keys()].join(", ") || "none"}.`,
|
|
119
|
+
exitCode: ExitCode.USAGE,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const payload = {
|
|
124
|
+
server: entry.name,
|
|
125
|
+
path: entry.path,
|
|
126
|
+
version: entry.version,
|
|
127
|
+
description: entry.description,
|
|
128
|
+
exposeDestructive: entry.metadata.exposeDestructive,
|
|
129
|
+
tools: entry.metadata.tools.map(tool => ({
|
|
130
|
+
name: tool.name,
|
|
131
|
+
description: tool.description,
|
|
132
|
+
inputSchema: tool.inputSchema,
|
|
133
|
+
outputSchema: tool.outputSchema,
|
|
134
|
+
annotations: tool.annotations,
|
|
135
|
+
scopes: tool.scopes,
|
|
136
|
+
exposed: !(tool.annotations?.destructiveHint === true || tool.destructive === true)
|
|
137
|
+
|| entry.metadata.exposeDestructive === true
|
|
138
|
+
|| RaitonConfig.get("mcp")?.exposeDestructive === true,
|
|
139
|
+
})),
|
|
140
|
+
prompts: entry.metadata.prompts,
|
|
141
|
+
resources: entry.metadata.resources,
|
|
142
|
+
resourceTemplates: entry.metadata.resourceTemplates,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
if (options.json) {
|
|
146
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, ...payload}, true);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
print(`${payload.server} ${payload.path} (${payload.version})`);
|
|
151
|
+
for (const tool of payload.tools) {
|
|
152
|
+
print(` - ${tool.name}${tool.exposed ? "" : " [hidden]"}: ${tool.description ?? ""}`);
|
|
153
|
+
if (tool.inputSchema) print(` input: ${JSON.stringify(tool.inputSchema)}`);
|
|
154
|
+
if (tool.outputSchema) print(` output: ${JSON.stringify(tool.outputSchema)}`);
|
|
155
|
+
if (tool.annotations) print(` annotations: ${JSON.stringify(tool.annotations)}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private async test(target: string, options: TestOptions): Promise<void> {
|
|
160
|
+
await loadProject(this.workdir, options.json);
|
|
161
|
+
const [serverName, toolName] = target.includes(".")
|
|
162
|
+
? target.split(".", 2)
|
|
163
|
+
: [[...getMcpServerRegistry().keys()][0], target];
|
|
164
|
+
|
|
165
|
+
const entry = getMcpServer(serverName);
|
|
166
|
+
if (!entry) {
|
|
167
|
+
throw new CliError(`MCP server not found: ${serverName}`, {
|
|
168
|
+
code: "MCP_SERVER_NOT_FOUND",
|
|
169
|
+
hint: `Available servers: ${[...getMcpServerRegistry().keys()].join(", ") || "none"}.`,
|
|
170
|
+
exitCode: ExitCode.USAGE,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const context: McpInvocationContext = {
|
|
175
|
+
actor: "raiton-cli",
|
|
176
|
+
transport: "streamable-http",
|
|
177
|
+
scopes: (options.scopes ?? "").split(",").map(scope => scope.trim()).filter(Boolean),
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const handled = await handleMcpRequest(entry, {
|
|
181
|
+
jsonrpc: "2.0",
|
|
182
|
+
id: 1,
|
|
183
|
+
method: "tools/call",
|
|
184
|
+
params: {name: toolName, arguments: parseArgs(options.args)},
|
|
185
|
+
}, context);
|
|
186
|
+
|
|
187
|
+
const message: any = Array.isArray(handled.message) ? handled.message[0] : handled.message;
|
|
188
|
+
if (message?.error) {
|
|
189
|
+
throw new CliError(message.error.message, {
|
|
190
|
+
code: "MCP_CALL_FAILED",
|
|
191
|
+
hint: `Run \`raiton mcp inspect ${entry.name}\` to check the tool name and input schema.`,
|
|
192
|
+
exitCode: ExitCode.USAGE,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const result = message?.result;
|
|
197
|
+
if (options.json) {
|
|
198
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, server: entry.name, tool: toolName, ok: !result?.isError, result}, true);
|
|
199
|
+
} else {
|
|
200
|
+
print(JSON.stringify(result, null, 2));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (result?.isError) process.exitCode = ExitCode.USAGE;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private async serve(name: string | undefined, options: ServeOptions): Promise<void> {
|
|
207
|
+
if (options.json) {
|
|
208
|
+
throw new CliError("`mcp serve` is a long-running server and cannot emit a single JSON document", {
|
|
209
|
+
code: "INVALID_OPTION",
|
|
210
|
+
hint: "Omit --json when serving over stdio.",
|
|
211
|
+
exitCode: ExitCode.USAGE,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// stdout is the stdio protocol channel: silence every incidental log
|
|
216
|
+
// while booting the project.
|
|
217
|
+
await loadProject(this.workdir, true);
|
|
218
|
+
const entry = name ? getMcpServer(name) : [...getMcpServerRegistry().values()][0];
|
|
219
|
+
if (!entry) {
|
|
220
|
+
throw new CliError(name ? `MCP server not found: ${name}` : "No MCP server registered", {
|
|
221
|
+
code: "MCP_SERVER_NOT_FOUND",
|
|
222
|
+
hint: "Add a `@McpServer` class in a `*.mcp.ts` file.",
|
|
223
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
process.stderr.write(`[raiton:mcp] serving ${entry.name} over stdio\n`);
|
|
228
|
+
await serveMcpStdio(entry);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private async conformance(name: string | undefined, options: ConformanceOptions): Promise<void> {
|
|
232
|
+
await loadProject(this.workdir, options.json);
|
|
233
|
+
const entry = name ? getMcpServer(name) : [...getMcpServerRegistry().values()][0];
|
|
234
|
+
if (!entry) {
|
|
235
|
+
throw new CliError("No MCP server registered", {
|
|
236
|
+
code: "MCP_SERVER_NOT_FOUND",
|
|
237
|
+
hint: "Add a `@McpServer` class in a `*.mcp.ts` file.",
|
|
238
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const results = await runAllConformance(entry);
|
|
243
|
+
const passed = results.every(result => result.passed);
|
|
244
|
+
|
|
245
|
+
if (options.json) {
|
|
246
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, passed, results}, true);
|
|
247
|
+
} else {
|
|
248
|
+
for (const result of results) {
|
|
249
|
+
print(`${result.passed ? "PASS" : "FAIL"} ${result.transport}`);
|
|
250
|
+
for (const check of result.checks) {
|
|
251
|
+
print(` ${check.passed ? "ok" : "fail"} ${check.name}${check.detail ? ` (${check.detail})` : ""}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!passed) process.exitCode = ExitCode.DIAGNOSTIC_FAILED;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import {spawnSync} from "node:child_process";
|
|
4
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
5
|
+
import {CLI_JSON_SCHEMA_VERSION, CliError, ExitCode, fail, print} from "../bin/cli-output.ts";
|
|
6
|
+
import {writeFiles} from "../bin/file-utils.ts";
|
|
7
|
+
import {
|
|
8
|
+
assertRuntime,
|
|
9
|
+
assertTemplate,
|
|
10
|
+
projectFiles,
|
|
11
|
+
type ProjectRuntime,
|
|
12
|
+
type ProjectTemplate,
|
|
13
|
+
} from "../generators/project.templates.ts";
|
|
14
|
+
import {isBunUsed, isDenoUsed} from "../bin/constants.ts";
|
|
15
|
+
import {kebab} from "../bin/name-utils.ts";
|
|
16
|
+
|
|
17
|
+
interface NewOptions {
|
|
18
|
+
template?: string;
|
|
19
|
+
runtime?: string;
|
|
20
|
+
dir?: string;
|
|
21
|
+
yes?: boolean;
|
|
22
|
+
offline?: boolean;
|
|
23
|
+
install?: boolean;
|
|
24
|
+
force?: boolean;
|
|
25
|
+
dryRun?: boolean;
|
|
26
|
+
json?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function detectRuntime(): ProjectRuntime {
|
|
30
|
+
if (isBunUsed) return "bun";
|
|
31
|
+
if (isDenoUsed) return "deno";
|
|
32
|
+
return "node";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function install(target: string, runtime: ProjectRuntime, json: boolean): {ran: boolean; command: string; status: number} {
|
|
36
|
+
if (runtime === "deno") return {ran: false, command: "deno (imports resolved at runtime)", status: 0};
|
|
37
|
+
|
|
38
|
+
const command = runtime === "bun" ? "bun" : "npm";
|
|
39
|
+
const result = spawnSync(command, ["install"], {
|
|
40
|
+
cwd: target,
|
|
41
|
+
stdio: json ? ["ignore", "ignore", "inherit"] : "inherit",
|
|
42
|
+
env: process.env,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return {ran: true, command: `${command} install`, status: result.status ?? 1};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class NewCommand extends RaitonCommand {
|
|
49
|
+
public readonly name = "new";
|
|
50
|
+
public readonly description = "Create a new Raiton project";
|
|
51
|
+
|
|
52
|
+
public register(): void {
|
|
53
|
+
this.cli
|
|
54
|
+
.command("new <name>")
|
|
55
|
+
.description(this.description)
|
|
56
|
+
.option("--template <template>", "Project template: api, minimal, mcp-agent", "api")
|
|
57
|
+
.option("--runtime <runtime>", "Target runtime: bun, node, deno")
|
|
58
|
+
.option("--dir <directory>", "Target directory (defaults to ./<name>)")
|
|
59
|
+
.option("--yes", "Non-interactive mode; never prompt")
|
|
60
|
+
.option("--offline", "Do not access the network; skip dependency installation")
|
|
61
|
+
.option("--no-install", "Do not install dependencies")
|
|
62
|
+
.option("--force", "Overwrite existing files explicitly")
|
|
63
|
+
.option("--dry-run", "Print the file plan without writing anything")
|
|
64
|
+
.option("--json", "Emit a machine-readable result on stdout")
|
|
65
|
+
.action((name: string, options: NewOptions) => this.run(name, options).catch(error => fail(error, options.json)));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private async run(name: string, options: NewOptions): Promise<void> {
|
|
69
|
+
const template: ProjectTemplate = assertTemplate(options.template ?? "api");
|
|
70
|
+
const runtime: ProjectRuntime = assertRuntime(options.runtime ?? detectRuntime());
|
|
71
|
+
const target = options.dir
|
|
72
|
+
? path.resolve(this.workdir, options.dir)
|
|
73
|
+
: path.resolve(this.workdir, name);
|
|
74
|
+
|
|
75
|
+
if (fs.existsSync(target) && !fs.statSync(target).isDirectory()) {
|
|
76
|
+
throw new CliError(`Target exists and is not a directory: ${target}`, {
|
|
77
|
+
code: "INVALID_TARGET",
|
|
78
|
+
hint: "Choose another directory or remove the file.",
|
|
79
|
+
location: target,
|
|
80
|
+
exitCode: ExitCode.FILE_CONFLICT,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const files = projectFiles({name: kebab(name), template, runtime});
|
|
85
|
+
const result = writeFiles(target, files, {
|
|
86
|
+
force: options.force,
|
|
87
|
+
dryRun: options.dryRun,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
let installation: {ran: boolean; command: string; status: number} = {
|
|
91
|
+
ran: false,
|
|
92
|
+
command: "",
|
|
93
|
+
status: 0,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (!options.dryRun && options.offline !== true && options.install !== false) {
|
|
97
|
+
installation = install(target, runtime, Boolean(options.json));
|
|
98
|
+
if (installation.ran && installation.status !== 0) {
|
|
99
|
+
throw new CliError(`Dependency installation failed (${installation.command})`, {
|
|
100
|
+
code: "INSTALL_FAILED",
|
|
101
|
+
hint: "Run the install command manually, or use --offline / --no-install.",
|
|
102
|
+
location: target,
|
|
103
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const payload = {
|
|
109
|
+
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
110
|
+
status: options.dryRun ? "planned" : "created",
|
|
111
|
+
project: kebab(name),
|
|
112
|
+
template,
|
|
113
|
+
runtime,
|
|
114
|
+
target,
|
|
115
|
+
files: result.files,
|
|
116
|
+
installed: installation.ran && installation.status === 0,
|
|
117
|
+
installCommand: installation.command || undefined,
|
|
118
|
+
offline: Boolean(options.offline),
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (options.json) {
|
|
122
|
+
print(payload, true);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (options.dryRun) {
|
|
127
|
+
print(`Would create ${payload.files.length} file(s) in ${target}:`);
|
|
128
|
+
for (const file of payload.files) print(` - ${file}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
print(`Created ${payload.project} (${template}, ${runtime}) in ${target}`);
|
|
133
|
+
print(`Next: cd ${path.relative(process.cwd(), target) || "."} && ${runtime === "node" ? "npx raiton dev" : runtime === "deno" ? "deno task dev" : "bun raiton dev"}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
4
|
+
import {CLI_JSON_SCHEMA_VERSION, CliError, ExitCode, fail, print} from "../bin/cli-output.ts";
|
|
5
|
+
import {loadProject} from "../bin/project-utils.ts";
|
|
6
|
+
import {generateOpenApiSpec} from "../framework/utilities/openapi.utils.ts";
|
|
7
|
+
|
|
8
|
+
interface OpenApiExportOptions {
|
|
9
|
+
out?: string;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
title?: string;
|
|
12
|
+
version?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
force?: boolean;
|
|
15
|
+
dryRun?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class OpenApiCommand extends RaitonCommand {
|
|
19
|
+
public readonly name = "openapi";
|
|
20
|
+
public readonly description = "Manage the generated OpenAPI document";
|
|
21
|
+
|
|
22
|
+
public register(): void {
|
|
23
|
+
const command = this.cli
|
|
24
|
+
.command("openapi")
|
|
25
|
+
.description(this.description);
|
|
26
|
+
|
|
27
|
+
command
|
|
28
|
+
.command("export")
|
|
29
|
+
.description("Export the OpenAPI document generated from the live routes")
|
|
30
|
+
.option("--out <file>", "Write the document to a file")
|
|
31
|
+
.option("--title <title>", "API title", "API")
|
|
32
|
+
.option("--version <version>", "API version", "1.0.0")
|
|
33
|
+
.option("--description <description>", "API description", "")
|
|
34
|
+
.option("--force", "Overwrite an existing output file")
|
|
35
|
+
.option("--dry-run", "Print the output plan without writing")
|
|
36
|
+
.option("--json", "Emit the document on stdout")
|
|
37
|
+
.action((options: OpenApiExportOptions) => this.run(options).catch(error => fail(error, options.json)));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private async run(options: OpenApiExportOptions): Promise<void> {
|
|
41
|
+
const {application} = await loadProject(this.workdir, options.json);
|
|
42
|
+
const rootScope = (application as any).root;
|
|
43
|
+
if (!rootScope) {
|
|
44
|
+
throw new CliError("Application root scope is unavailable", {
|
|
45
|
+
code: "INTROSPECTION_FAILED",
|
|
46
|
+
hint: "Ensure the bootstrapper creates a standard Raiton Application.",
|
|
47
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const spec = await generateOpenApiSpec(rootScope, {
|
|
52
|
+
title: options.title ?? "API",
|
|
53
|
+
version: options.version ?? "1.0.0",
|
|
54
|
+
description: options.description ?? "",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (options.out) {
|
|
58
|
+
const filename = path.resolve(this.workdir, options.out);
|
|
59
|
+
if (fs.existsSync(filename) && !options.force) {
|
|
60
|
+
throw new CliError(`Refusing to overwrite existing file: ${path.relative(this.workdir, filename)}`, {
|
|
61
|
+
code: "FILE_CONFLICT",
|
|
62
|
+
hint: "Pass --force to overwrite the OpenAPI document explicitly.",
|
|
63
|
+
location: filename,
|
|
64
|
+
exitCode: ExitCode.FILE_CONFLICT,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (options.dryRun) {
|
|
68
|
+
if (options.json) {
|
|
69
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, status: "planned", file: path.relative(this.workdir, filename)}, true);
|
|
70
|
+
} else {
|
|
71
|
+
print(`Would write OpenAPI document to ${path.relative(process.cwd(), filename)}`);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
fs.mkdirSync(path.dirname(filename), {recursive: true});
|
|
76
|
+
fs.writeFileSync(filename, JSON.stringify(spec, null, 2) + "\n", "utf-8");
|
|
77
|
+
if (options.json) {
|
|
78
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, status: "exported", file: path.relative(this.workdir, filename), paths: Object.keys(spec.paths ?? {}).length}, true);
|
|
79
|
+
} else {
|
|
80
|
+
print(`OpenAPI document written to ${path.relative(process.cwd(), filename)}`);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (options.json) {
|
|
86
|
+
print(spec, true);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
print(`OpenAPI ${spec.openapi} — ${Object.keys(spec.paths ?? {}).length} path(s)`);
|
|
91
|
+
for (const [route, item] of Object.entries(spec.paths ?? {})) {
|
|
92
|
+
print(` ${Object.keys(item as any).join(",").toUpperCase().padEnd(8)} ${route}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
2
|
+
import {CLI_JSON_SCHEMA_VERSION, fail, print} from "../bin/cli-output.ts";
|
|
3
|
+
import {loadProject, printTable, routeRows} from "../bin/project-utils.ts";
|
|
4
|
+
|
|
5
|
+
interface RoutesOptions {
|
|
6
|
+
json?: boolean;
|
|
7
|
+
method?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class RoutesCommand extends RaitonCommand {
|
|
12
|
+
public readonly name = "routes";
|
|
13
|
+
public readonly description = "List the routes mounted by the application";
|
|
14
|
+
|
|
15
|
+
public register(): void {
|
|
16
|
+
this.cli
|
|
17
|
+
.command("routes")
|
|
18
|
+
.description(this.description)
|
|
19
|
+
.option("--json", "Emit a machine-readable list on stdout")
|
|
20
|
+
.option("--method <method>", "Filter by HTTP method")
|
|
21
|
+
.option("--path <path>", "Filter by path substring")
|
|
22
|
+
.action((options: RoutesOptions) => this.run(options).catch(error => fail(error, options.json)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private async run(options: RoutesOptions): Promise<void> {
|
|
26
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
27
|
+
const routes = manifest.routes.filter(route =>
|
|
28
|
+
(!options.method || route.method.toUpperCase() === options.method.toUpperCase())
|
|
29
|
+
&& (!options.path || route.path.includes(options.path))
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (options.json) {
|
|
33
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, routes}, true);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
print(printTable(routeRows({...manifest, routes})));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
2
|
+
import {CLI_JSON_SCHEMA_VERSION, CliError, ExitCode, fail, print} from "../bin/cli-output.ts";
|
|
3
|
+
import {findRoute, loadProject} from "../bin/project-utils.ts";
|
|
4
|
+
import {suggestRoute} from "../framework/utilities/route-suggestion.util.ts";
|
|
5
|
+
|
|
6
|
+
interface WhyOptions {
|
|
7
|
+
json?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default class WhyCommand extends RaitonCommand {
|
|
11
|
+
public readonly name = "why";
|
|
12
|
+
public readonly description = "Explain which source registered a route";
|
|
13
|
+
|
|
14
|
+
public register(): void {
|
|
15
|
+
this.cli
|
|
16
|
+
.command("why <method> <path>")
|
|
17
|
+
.description(this.description)
|
|
18
|
+
.option("--json", "Emit a machine-readable explanation on stdout")
|
|
19
|
+
.action((method: string, routePath: string, options: WhyOptions) =>
|
|
20
|
+
this.run(method, routePath, options).catch(error => fail(error, options.json)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
private async run(method: string, routePath: string, options: WhyOptions): Promise<void> {
|
|
24
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
25
|
+
const route = findRoute(manifest, method, routePath);
|
|
26
|
+
|
|
27
|
+
if (!route) {
|
|
28
|
+
const suggestion = suggestRoute(manifest.routes, method, routePath);
|
|
29
|
+
throw new CliError(`Route ${method.toUpperCase()} ${routePath} was not registered`, {
|
|
30
|
+
code: "ROUTE_NOT_FOUND",
|
|
31
|
+
hint: suggestion ? `Did you mean ${suggestion}?` : "Run `raiton routes` to list mounted routes.",
|
|
32
|
+
exitCode: ExitCode.USAGE,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const origin = {
|
|
37
|
+
route: `${route.method} ${route.path}`,
|
|
38
|
+
file: route.file,
|
|
39
|
+
line: route.line,
|
|
40
|
+
controller: route.controller,
|
|
41
|
+
handler: route.handler,
|
|
42
|
+
decorator: `@${route.method.charAt(0)}${route.method.slice(1).toLowerCase()}("${route.path}")`,
|
|
43
|
+
artifact: route.controller === "Application" ? "application" : "controller",
|
|
44
|
+
input: route.input,
|
|
45
|
+
output: route.output,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
if (options.json) {
|
|
49
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, ...origin}, true);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
print(`${origin.route}`);
|
|
54
|
+
print(` file: ${origin.file}${origin.line ? `:${origin.line}` : ""}`);
|
|
55
|
+
print(` controller: ${origin.controller}.${origin.handler}`);
|
|
56
|
+
print(` decorator: ${origin.decorator}`);
|
|
57
|
+
print(` artifact: ${origin.artifact}`);
|
|
58
|
+
if (origin.input) print(` input: ${origin.input}`);
|
|
59
|
+
if (origin.output) print(` output: ${origin.output}`);
|
|
60
|
+
}
|
|
61
|
+
}
|