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,139 @@
|
|
|
1
|
+
import {Logger} from "@protorians/logger";
|
|
2
|
+
|
|
3
|
+
/** Version of the stable CLI JSON envelope. */
|
|
4
|
+
export const CLI_JSON_SCHEMA_VERSION = "1.0.0";
|
|
5
|
+
|
|
6
|
+
export enum ExitCode {
|
|
7
|
+
SUCCESS = 0,
|
|
8
|
+
USAGE = 1,
|
|
9
|
+
PREREQUISITE_MISSING = 2,
|
|
10
|
+
FILE_CONFLICT = 3,
|
|
11
|
+
DIAGNOSTIC_FAILED = 4,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CliErrorOptions {
|
|
15
|
+
code?: string;
|
|
16
|
+
hint?: string;
|
|
17
|
+
docsUrl?: string;
|
|
18
|
+
location?: string;
|
|
19
|
+
exitCode?: ExitCode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Stable CLI error shape shared by every command:
|
|
24
|
+
* `{ code, message, hint, docsUrl, location? }`.
|
|
25
|
+
*/
|
|
26
|
+
export class CliError extends Error {
|
|
27
|
+
public readonly code: string;
|
|
28
|
+
public readonly hint: string;
|
|
29
|
+
public readonly docsUrl: string;
|
|
30
|
+
public readonly location?: string;
|
|
31
|
+
public readonly exitCode: ExitCode;
|
|
32
|
+
|
|
33
|
+
constructor(message: string, options: CliErrorOptions = {}) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.name = "CliError";
|
|
36
|
+
this.code = options.code ?? "COMMAND_FAILED";
|
|
37
|
+
this.hint = options.hint ?? "Run `raiton --help` to inspect available commands.";
|
|
38
|
+
this.docsUrl = options.docsUrl ?? "https://github.com/protorians/raiton/blob/main/docs/user-guide/cli.md";
|
|
39
|
+
this.location = options.location;
|
|
40
|
+
this.exitCode = options.exitCode ?? ExitCode.USAGE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toJSON() {
|
|
44
|
+
return {
|
|
45
|
+
code: this.code,
|
|
46
|
+
message: this.message,
|
|
47
|
+
hint: this.hint,
|
|
48
|
+
docsUrl: this.docsUrl,
|
|
49
|
+
...(this.location ? {location: this.location} : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function fail(error: unknown, json = false): void {
|
|
55
|
+
const cliError = error instanceof CliError
|
|
56
|
+
? error
|
|
57
|
+
: new CliError(
|
|
58
|
+
error instanceof Error ? error.message : String(error),
|
|
59
|
+
{
|
|
60
|
+
code: "COMMAND_FAILED",
|
|
61
|
+
hint: "Check the command arguments and the project configuration.",
|
|
62
|
+
exitCode: ExitCode.USAGE,
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
if (json) {
|
|
67
|
+
process.stdout.write(JSON.stringify({
|
|
68
|
+
error: true,
|
|
69
|
+
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
70
|
+
...cliError.toJSON(),
|
|
71
|
+
}, null, 2) + "\n");
|
|
72
|
+
} else {
|
|
73
|
+
Logger.error(`${cliError.code}: ${cliError.message}`);
|
|
74
|
+
Logger.info(`Hint: ${cliError.hint}`);
|
|
75
|
+
Logger.info(`Docs: ${cliError.docsUrl}`);
|
|
76
|
+
if (cliError.location) Logger.info(`Location: ${cliError.location}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
process.exitCode = cliError.exitCode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function printJson(value: unknown): void {
|
|
83
|
+
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function print(value: unknown, json = false): void {
|
|
87
|
+
if (json) printJson(value);
|
|
88
|
+
else if (typeof value === "string") process.stdout.write(value + "\n");
|
|
89
|
+
else process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Redirect incidental framework logs to stderr while a machine-readable
|
|
94
|
+
* command runs, so `--json` always emits exactly one valid JSON document on
|
|
95
|
+
* stdout.
|
|
96
|
+
*/
|
|
97
|
+
export async function silenceStdout<T>(callable: () => Promise<T> | T): Promise<T> {
|
|
98
|
+
const originalWrite = process.stdout.write.bind(process.stdout);
|
|
99
|
+
const originalLog = console.log;
|
|
100
|
+
|
|
101
|
+
const redirect = (...args: any[]) => {
|
|
102
|
+
process.stderr.write(args.map(value => typeof value === "string" ? value : JSON.stringify(value)).join(" ") + "\n");
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
(process.stdout as any).write = (chunk: any, encoding?: any, callback?: any) => {
|
|
106
|
+
if (typeof encoding === "function") {
|
|
107
|
+
return process.stderr.write(chunk, encoding);
|
|
108
|
+
}
|
|
109
|
+
return process.stderr.write(chunk, encoding, callback);
|
|
110
|
+
};
|
|
111
|
+
console.log = redirect;
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
return await callable();
|
|
115
|
+
} finally {
|
|
116
|
+
(process.stdout as any).write = originalWrite;
|
|
117
|
+
console.log = originalLog;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function isInteractive(): boolean {
|
|
122
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function ensureNonInteractive(required: Record<string, any>): void {
|
|
126
|
+
const missing = Object.entries(required)
|
|
127
|
+
.filter(([, value]) => value === undefined || value === null || value === "")
|
|
128
|
+
.map(([key]) => key);
|
|
129
|
+
if (missing.length) {
|
|
130
|
+
throw new CliError(
|
|
131
|
+
`Missing required option(s): ${missing.join(", ")}`,
|
|
132
|
+
{
|
|
133
|
+
code: "MISSING_OPTION",
|
|
134
|
+
hint: `Provide ${missing.map(key => `--${key}`).join(", ")} in non-interactive mode.`,
|
|
135
|
+
exitCode: ExitCode.USAGE,
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
import ArtifactCommand from "../commands/artifact.command.ts";
|
|
2
2
|
import BuildCommand from "../commands/build.command.ts";
|
|
3
|
+
import ClientCommand from "../commands/client.command.ts";
|
|
4
|
+
import ContractCommand from "../commands/contract.command.ts";
|
|
3
5
|
import DevelopCommand from "../commands/develop.command.ts";
|
|
4
|
-
import
|
|
6
|
+
import DocsCommand from "../commands/docs.command.ts";
|
|
7
|
+
import DoctorCommand from "../commands/doctor.command.ts";
|
|
8
|
+
import GenerateCommand from "../commands/generate.command.ts";
|
|
9
|
+
import InspectCommand from "../commands/inspect.command.ts";
|
|
10
|
+
import McpCommand from "../commands/mcp.command.ts";
|
|
11
|
+
import NewCommand from "../commands/new.command.ts";
|
|
12
|
+
import OpenApiCommand from "../commands/openapi.command.ts";
|
|
13
|
+
import RoutesCommand from "../commands/routes.command.ts";
|
|
5
14
|
import StartCommand from "../commands/start.command.ts";
|
|
15
|
+
import WhyCommand from "../commands/why.command.ts";
|
|
6
16
|
import type {Command} from "commander";
|
|
7
17
|
import type {RaitonCommand} from "../core/index.ts";
|
|
8
18
|
|
|
9
19
|
export type RaitonCommandConstructor = new (cli: Command, workdir: string, appdir: string) => RaitonCommand;
|
|
10
20
|
|
|
11
21
|
export const RaitonCommandsRegistry: RaitonCommandConstructor[] = [
|
|
22
|
+
NewCommand,
|
|
23
|
+
GenerateCommand,
|
|
12
24
|
ArtifactCommand,
|
|
25
|
+
RoutesCommand,
|
|
26
|
+
InspectCommand,
|
|
27
|
+
WhyCommand,
|
|
28
|
+
DoctorCommand,
|
|
29
|
+
OpenApiCommand,
|
|
30
|
+
ClientCommand,
|
|
31
|
+
ContractCommand,
|
|
32
|
+
McpCommand,
|
|
33
|
+
DocsCommand,
|
|
13
34
|
BuildCommand,
|
|
14
35
|
DevelopCommand,
|
|
15
|
-
GraftsCommand,
|
|
16
36
|
StartCommand,
|
|
17
|
-
];
|
|
37
|
+
];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {CliError, ExitCode} from "./cli-output.ts";
|
|
4
|
+
|
|
5
|
+
export interface GeneratedFile {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface WriteOptions {
|
|
11
|
+
force?: boolean;
|
|
12
|
+
dryRun?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface WriteResult {
|
|
16
|
+
files: string[];
|
|
17
|
+
conflicts: string[];
|
|
18
|
+
written: string[];
|
|
19
|
+
dryRun: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Write generated files without ever overwriting an existing file unless
|
|
24
|
+
* `force` is explicit. `dryRun` returns the same plan without touching disk.
|
|
25
|
+
*/
|
|
26
|
+
export function writeFiles(baseDir: string, files: GeneratedFile[], options: WriteOptions = {}): WriteResult {
|
|
27
|
+
const resolved = files.map(file => ({
|
|
28
|
+
...file,
|
|
29
|
+
absolute: path.resolve(baseDir, file.path),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const conflicts = resolved
|
|
33
|
+
.filter(file => fs.existsSync(file.absolute))
|
|
34
|
+
.map(file => path.relative(baseDir, file.absolute));
|
|
35
|
+
|
|
36
|
+
if (conflicts.length && !options.force) {
|
|
37
|
+
throw new CliError(
|
|
38
|
+
`Refusing to overwrite existing file(s): ${conflicts.join(", ")}`,
|
|
39
|
+
{
|
|
40
|
+
code: "FILE_CONFLICT",
|
|
41
|
+
hint: "Choose another target, or pass --force to overwrite explicitly.",
|
|
42
|
+
docsUrl: "https://github.com/protorians/raiton/blob/main/docs/user-guide/cli.md",
|
|
43
|
+
exitCode: ExitCode.FILE_CONFLICT,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.dryRun) {
|
|
49
|
+
return {
|
|
50
|
+
files: resolved.map(file => file.path),
|
|
51
|
+
conflicts,
|
|
52
|
+
written: [],
|
|
53
|
+
dryRun: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const written: string[] = [];
|
|
58
|
+
for (const file of resolved) {
|
|
59
|
+
fs.mkdirSync(path.dirname(file.absolute), {recursive: true});
|
|
60
|
+
fs.writeFileSync(file.absolute, file.content, "utf-8");
|
|
61
|
+
written.push(file.path);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
files: resolved.map(file => file.path),
|
|
66
|
+
conflicts,
|
|
67
|
+
written,
|
|
68
|
+
dryRun: false,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function isDirectoryEmpty(directory: string): boolean {
|
|
73
|
+
if (!fs.existsSync(directory)) return true;
|
|
74
|
+
return fs.readdirSync(directory).filter(name => name !== ".DS_Store").length === 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function readJsonFile<T = any>(filename: string): T {
|
|
78
|
+
if (!fs.existsSync(filename)) {
|
|
79
|
+
throw new CliError(`File not found: ${filename}`, {
|
|
80
|
+
code: "FILE_NOT_FOUND",
|
|
81
|
+
hint: "Check the path and try again.",
|
|
82
|
+
location: filename,
|
|
83
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(fs.readFileSync(filename, "utf-8"));
|
|
88
|
+
} catch (error: any) {
|
|
89
|
+
throw new CliError(`Invalid JSON in ${filename}: ${error.message}`, {
|
|
90
|
+
code: "INVALID_JSON",
|
|
91
|
+
hint: "Fix the file or regenerate it with `raiton inspect --out`.",
|
|
92
|
+
location: filename,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function kebab(value: string): string {
|
|
2
|
+
return value
|
|
3
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
4
|
+
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
5
|
+
.replace(/^-+|-+$/g, "")
|
|
6
|
+
.toLowerCase() || "app";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function pascal(value: string): string {
|
|
10
|
+
return kebab(value)
|
|
11
|
+
.split("-")
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map(part => part[0].toUpperCase() + part.slice(1))
|
|
14
|
+
.join("") || "App";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function camel(value: string): string {
|
|
18
|
+
const result = pascal(value);
|
|
19
|
+
return result ? result[0].toLowerCase() + result.slice(1) : "app";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function plural(value: string): string {
|
|
23
|
+
if (/s$/i.test(value)) return value;
|
|
24
|
+
if (/[^aeiou]y$/i.test(value)) return `${value.slice(0, -1)}ies`;
|
|
25
|
+
return `${value}s`;
|
|
26
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import {CliError, ExitCode, silenceStdout} from "./cli-output.ts";
|
|
4
|
+
import {introspectProject, type Introspection} from "../manifest/introspect.ts";
|
|
5
|
+
import type {ProjectManifest, ProjectRouteManifest} from "../manifest/schema.ts";
|
|
6
|
+
|
|
7
|
+
export async function loadProject(workdir: string, json = false): Promise<Introspection> {
|
|
8
|
+
const {RaitonConfig} = await import("../core/config/config.ts");
|
|
9
|
+
await RaitonConfig.sync(workdir, {force: true});
|
|
10
|
+
const rootDir = RaitonConfig.get("rootDir") || "./source";
|
|
11
|
+
const bootstrapper = path.resolve(workdir, rootDir, "main.ts");
|
|
12
|
+
const candidates = [bootstrapper];
|
|
13
|
+
|
|
14
|
+
if (!candidates.some(candidate => fs.existsSync(candidate))) {
|
|
15
|
+
throw new CliError("Project entry point source/main.ts was not found", {
|
|
16
|
+
code: "PREREQUISITE_MISSING",
|
|
17
|
+
hint: "Create source/main.ts or set rootDir in raiton.config.ts.",
|
|
18
|
+
location: workdir,
|
|
19
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
return json
|
|
25
|
+
? await silenceStdout(() => introspectProject(workdir))
|
|
26
|
+
: await introspectProject(workdir);
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
if (error instanceof CliError) throw error;
|
|
29
|
+
throw new CliError(error?.message ?? String(error), {
|
|
30
|
+
code: "INTROSPECTION_FAILED",
|
|
31
|
+
hint: "Fix the bootstrapper or configuration, then run `raiton doctor`.",
|
|
32
|
+
location: workdir,
|
|
33
|
+
exitCode: ExitCode.PREREQUISITE_MISSING,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RouteRow {
|
|
39
|
+
method: string;
|
|
40
|
+
path: string;
|
|
41
|
+
handler: string;
|
|
42
|
+
source: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function routeRows(manifest: ProjectManifest): RouteRow[] {
|
|
46
|
+
return manifest.routes.map(route => ({
|
|
47
|
+
method: route.method,
|
|
48
|
+
path: route.path,
|
|
49
|
+
handler: `${route.controller}.${route.handler}`,
|
|
50
|
+
source: `${route.file}${route.line ? `:${route.line}` : ""}`,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function printTable(rows: RouteRow[]): string {
|
|
55
|
+
if (!rows.length) return "No route registered.";
|
|
56
|
+
const widths = {
|
|
57
|
+
method: Math.max(6, ...rows.map(row => row.method.length)),
|
|
58
|
+
path: Math.max(4, ...rows.map(row => row.path.length)),
|
|
59
|
+
handler: Math.max(7, ...rows.map(row => row.handler.length)),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const line = (row: RouteRow) =>
|
|
63
|
+
`${row.method.padEnd(widths.method)} ${row.path.padEnd(widths.path)} ${row.handler.padEnd(widths.handler)} ${row.source}`;
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
`${"METHOD".padEnd(widths.method)} ${"PATH".padEnd(widths.path)} ${"HANDLER".padEnd(widths.handler)} SOURCE`,
|
|
67
|
+
`${"-".repeat(widths.method)} ${"-".repeat(widths.path)} ${"-".repeat(widths.handler)} ${"-".repeat(6)}`,
|
|
68
|
+
...rows.map(line),
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function findRoute(manifest: ProjectManifest, method: string, routePath: string): ProjectRouteManifest | undefined {
|
|
73
|
+
const normalized = routePath.replace(/\/+$/, "") || "/";
|
|
74
|
+
return manifest.routes.find(route =>
|
|
75
|
+
route.method.toUpperCase() === method.toUpperCase()
|
|
76
|
+
&& (route.path.replace(/\/+$/, "") || "/") === normalized
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -1,28 +1,43 @@
|
|
|
1
|
-
import {RaitonCommand
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
2
|
+
import {CLI_JSON_SCHEMA_VERSION, fail, print} from "../bin/cli-output.ts";
|
|
3
|
+
import {RaitonConfig} from "../core/config/config.ts";
|
|
4
|
+
import {generateManifest} from "../manifest/manifest.ts";
|
|
4
5
|
|
|
6
|
+
interface ArtifactOptions {
|
|
7
|
+
dump?: boolean;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
export default class ArtifactCommand extends RaitonCommand {
|
|
7
|
-
public readonly name
|
|
8
|
-
public readonly description
|
|
12
|
+
public readonly name = "artifact";
|
|
13
|
+
public readonly description = "Inspect artifacts detected in the project";
|
|
9
14
|
|
|
10
15
|
public register(): void {
|
|
11
16
|
this.cli
|
|
12
|
-
.command(
|
|
17
|
+
.command("artifact")
|
|
13
18
|
.alias("art")
|
|
14
19
|
.description(this.description)
|
|
15
|
-
.option("--dump
|
|
16
|
-
.option("--
|
|
17
|
-
.
|
|
18
|
-
.option("--clear", "Clear all artifacts")
|
|
19
|
-
.action(this.run.bind(this));
|
|
20
|
+
.option("--dump", "Dump artifacts detected by the project scanner")
|
|
21
|
+
.option("--json", "Emit a machine-readable list on stdout")
|
|
22
|
+
.action((options: ArtifactOptions) => this.run(options).catch(error => fail(error, options.json)));
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
private async run(options: ArtifactOptions): Promise<void> {
|
|
26
|
+
await RaitonConfig.sync(this.workdir, {force: true});
|
|
27
|
+
const manifest = generateManifest({refresh: true, workdir: this.workdir});
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
if (options.json) {
|
|
30
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, artifacts: manifest.artifacts, types: RaitonConfig.get("artifacts")?.types ?? []}, true);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
26
33
|
|
|
34
|
+
if (!manifest.artifacts.length) {
|
|
35
|
+
print("No artifact detected. Use documented suffixes such as `.controller.ts` or `.service.ts`.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
print(`Detected artifact types (${manifest.artifacts.length}):`);
|
|
40
|
+
for (const artifact of manifest.artifacts) print(` - ${artifact}`);
|
|
41
|
+
print("Create one with `raiton generate <type> <name>`.");
|
|
27
42
|
}
|
|
28
|
-
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import {RaitonCommand} from "../core/command.ts";
|
|
3
|
+
import {CLI_JSON_SCHEMA_VERSION, fail, print} from "../bin/cli-output.ts";
|
|
4
|
+
import {loadProject} from "../bin/project-utils.ts";
|
|
5
|
+
import {generateClient} from "../manifest/client.ts";
|
|
6
|
+
import {writeFiles} from "../bin/file-utils.ts";
|
|
7
|
+
|
|
8
|
+
interface ClientOptions {
|
|
9
|
+
out?: string;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
name?: string;
|
|
12
|
+
force?: boolean;
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class ClientCommand extends RaitonCommand {
|
|
18
|
+
public readonly name = "client";
|
|
19
|
+
public readonly description = "Generate a typed TypeScript client from the route contracts";
|
|
20
|
+
|
|
21
|
+
public register(): void {
|
|
22
|
+
this.cli
|
|
23
|
+
.command("client")
|
|
24
|
+
.description(this.description)
|
|
25
|
+
.option("--out <directory>", "Output directory", "./sdk")
|
|
26
|
+
.option("--name <name>", "Generated error/class prefix", "RaitonClient")
|
|
27
|
+
.option("--base-url <url>", "Default base URL written in the client", "")
|
|
28
|
+
.option("--force", "Overwrite an existing client")
|
|
29
|
+
.option("--dry-run", "Print the file plan without writing")
|
|
30
|
+
.option("--json", "Emit a machine-readable result on stdout")
|
|
31
|
+
.action((options: ClientOptions) => this.run(options).catch(error => fail(error, options.json)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private async run(options: ClientOptions): Promise<void> {
|
|
35
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
36
|
+
const content = generateClient(manifest, {
|
|
37
|
+
name: options.name,
|
|
38
|
+
baseUrl: options.baseUrl || undefined,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const outDir = options.out ?? "./sdk";
|
|
42
|
+
const result = writeFiles(path.resolve(this.workdir, outDir), [
|
|
43
|
+
{path: "index.ts", content},
|
|
44
|
+
], {
|
|
45
|
+
force: options.force,
|
|
46
|
+
dryRun: options.dryRun,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const payload = {
|
|
50
|
+
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
51
|
+
status: options.dryRun ? "planned" : "generated",
|
|
52
|
+
output: path.resolve(this.workdir, outDir),
|
|
53
|
+
routes: manifest.routes.length,
|
|
54
|
+
files: result.files,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (options.json) {
|
|
58
|
+
print(payload, true);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
print(`${options.dryRun ? "Would generate" : "Generated"} typed client (${manifest.routes.length} route(s)) in ${payload.output}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
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 {checkContracts} from "../manifest/contract.ts";
|
|
7
|
+
import {readJsonFile} from "../bin/file-utils.ts";
|
|
8
|
+
|
|
9
|
+
interface CheckOptions {
|
|
10
|
+
baseline: string;
|
|
11
|
+
json?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface SnapshotOptions {
|
|
15
|
+
out: string;
|
|
16
|
+
json?: boolean;
|
|
17
|
+
force?: boolean;
|
|
18
|
+
dryRun?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default class ContractCommand extends RaitonCommand {
|
|
22
|
+
public readonly name = "contract";
|
|
23
|
+
public readonly description = "Check published route contracts for breaking changes";
|
|
24
|
+
|
|
25
|
+
public register(): void {
|
|
26
|
+
const command = this.cli
|
|
27
|
+
.command("contract")
|
|
28
|
+
.description(this.description);
|
|
29
|
+
|
|
30
|
+
command
|
|
31
|
+
.command("check")
|
|
32
|
+
.description("Compare current contracts to a baseline")
|
|
33
|
+
.requiredOption("--baseline <file>", "Baseline manifest or OpenAPI document")
|
|
34
|
+
.option("--json", "Emit a machine-readable result on stdout")
|
|
35
|
+
.action((options: CheckOptions) => this.check(options).catch(error => fail(error, options.json)));
|
|
36
|
+
|
|
37
|
+
command
|
|
38
|
+
.command("snapshot")
|
|
39
|
+
.description("Write the current contracts as a baseline manifest")
|
|
40
|
+
.requiredOption("--out <file>", "Output manifest file")
|
|
41
|
+
.option("--force", "Overwrite an existing baseline")
|
|
42
|
+
.option("--dry-run", "Print the output plan without writing")
|
|
43
|
+
.option("--json", "Emit a machine-readable result on stdout")
|
|
44
|
+
.action((options: SnapshotOptions) => this.snapshot(options).catch(error => fail(error, options.json)));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private async check(options: CheckOptions): Promise<void> {
|
|
48
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
49
|
+
const baselineFile = path.resolve(this.workdir, options.baseline);
|
|
50
|
+
const baseline = readJsonFile(baselineFile);
|
|
51
|
+
const result = checkContracts(manifest, baseline);
|
|
52
|
+
|
|
53
|
+
if (options.json) {
|
|
54
|
+
print({
|
|
55
|
+
schemaVersion: CLI_JSON_SCHEMA_VERSION,
|
|
56
|
+
compatible: result.compatible,
|
|
57
|
+
checked: result.checked,
|
|
58
|
+
breaking: result.breaking,
|
|
59
|
+
}, true);
|
|
60
|
+
} else {
|
|
61
|
+
if (result.compatible) {
|
|
62
|
+
print(`Contracts compatible (${result.checked} route(s) checked).`);
|
|
63
|
+
} else {
|
|
64
|
+
print(`Breaking contract change(s) detected:`);
|
|
65
|
+
for (const change of result.breaking) {
|
|
66
|
+
print(` [${change.kind}] ${change.route}${change.field ? ` · ${change.field}` : ""}: ${change.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!result.compatible) {
|
|
72
|
+
process.exitCode = ExitCode.USAGE;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private async snapshot(options: SnapshotOptions): Promise<void> {
|
|
77
|
+
const {manifest} = await loadProject(this.workdir, options.json);
|
|
78
|
+
const filename = path.resolve(this.workdir, options.out);
|
|
79
|
+
if (fs.existsSync(filename) && !options.force) {
|
|
80
|
+
throw new CliError(`Refusing to overwrite existing baseline: ${path.relative(this.workdir, filename)}`, {
|
|
81
|
+
code: "FILE_CONFLICT",
|
|
82
|
+
hint: "Pass --force to overwrite the contract baseline explicitly.",
|
|
83
|
+
location: filename,
|
|
84
|
+
exitCode: ExitCode.FILE_CONFLICT,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (options.dryRun) {
|
|
88
|
+
if (options.json) {
|
|
89
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, status: "planned", file: path.relative(this.workdir, filename)}, true);
|
|
90
|
+
} else {
|
|
91
|
+
print(`Would write contract baseline to ${path.relative(process.cwd(), filename)}`);
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
fs.mkdirSync(path.dirname(filename), {recursive: true});
|
|
96
|
+
fs.writeFileSync(filename, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
|
|
97
|
+
|
|
98
|
+
if (options.json) {
|
|
99
|
+
print({schemaVersion: CLI_JSON_SCHEMA_VERSION, status: "snapshot", file: filename, routes: manifest.routes.length}, true);
|
|
100
|
+
} else {
|
|
101
|
+
print(`Contract baseline written to ${path.relative(process.cwd(), filename)}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|