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
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import {pathToFileURL} from "node:url";
|
|
4
|
+
import {ConfigurableInterface, ObservabilityConfigInterface} from "../../types/index.ts";
|
|
4
5
|
import {Logger} from "@protorians/logger";
|
|
5
6
|
import {Raiton} from "../raiton.ts";
|
|
7
|
+
import {ConfigFieldError, ConfigValidationError, validateConfig} from "./schema.ts";
|
|
8
|
+
|
|
9
|
+
function isConfigValidationError(error: any): error is ConfigValidationError {
|
|
10
|
+
return error instanceof ConfigValidationError
|
|
11
|
+
|| (error?.name === "ConfigValidationError" && Array.isArray(error?.errors));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ConfigLoadOptions {
|
|
15
|
+
/** Reload even when a configuration is already cached. */
|
|
16
|
+
force?: boolean;
|
|
17
|
+
}
|
|
6
18
|
|
|
7
19
|
export class RaitonConfig {
|
|
8
20
|
static readonly current: Map<keyof ConfigurableInterface, ConfigurableInterface[keyof ConfigurableInterface]> = new Map();
|
|
9
21
|
|
|
10
|
-
|
|
22
|
+
/** Field-scoped validation errors from the last load. */
|
|
23
|
+
static errors: ConfigFieldError[] = [];
|
|
24
|
+
|
|
25
|
+
/** Source file used by the last successful load. */
|
|
26
|
+
static source: string | null = null;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Documented loading order. TypeScript first so `raiton.config.ts` is the
|
|
30
|
+
* canonical file; JSON remains supported for tooling and generated projects.
|
|
31
|
+
*/
|
|
32
|
+
protected static _extensions: string[] = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs', '.json'];
|
|
11
33
|
|
|
12
34
|
static get<K extends keyof ConfigurableInterface>(key: K): ConfigurableInterface[K] | undefined {
|
|
13
35
|
return this.current.get(key) as ConfigurableInterface[K];
|
|
@@ -15,37 +37,133 @@ export class RaitonConfig {
|
|
|
15
37
|
|
|
16
38
|
static defaultConfig: ConfigurableInterface = {
|
|
17
39
|
rootDir: '.',
|
|
18
|
-
version: '0.0.1'
|
|
40
|
+
version: '0.0.1',
|
|
41
|
+
observability: {mode: 'off'},
|
|
42
|
+
validation: {responses: 'auto'},
|
|
43
|
+
shutdown: {timeoutMs: 10_000},
|
|
44
|
+
mcp: {exposeDestructive: false},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static reset(): void {
|
|
48
|
+
this.current.clear();
|
|
49
|
+
this.errors = [];
|
|
50
|
+
this.source = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static toObject(): ConfigurableInterface {
|
|
54
|
+
return Object.fromEntries(this.current.entries()) as unknown as ConfigurableInterface;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static assertValid(): void {
|
|
58
|
+
if (this.errors.length) throw new ConfigValidationError(this.errors);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static getObservability(): Required<ObservabilityConfigInterface> {
|
|
62
|
+
const config = this.get('observability') || {};
|
|
63
|
+
const envMode = process.env.RAITON_OBSERVABILITY as ObservabilityConfigInterface['mode'] | undefined;
|
|
64
|
+
const mode = envMode ?? config.mode ?? 'off';
|
|
65
|
+
return {
|
|
66
|
+
mode: (['off', 'metrics', 'traces', 'all'].includes(String(mode)) ? mode : 'off') as Required<ObservabilityConfigInterface>['mode'],
|
|
67
|
+
metricsPath: process.env.RAITON_METRICS_PATH || config.metricsPath || '/metrics',
|
|
68
|
+
otelEndpoint: process.env.RAITON_OTEL_ENDPOINT || config.otelEndpoint || '',
|
|
69
|
+
requestIdHeader: process.env.RAITON_REQUEST_ID_HEADER || config.requestIdHeader || 'x-request-id',
|
|
70
|
+
serviceName: config.serviceName || 'raiton',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static getShutdownTimeout(): number {
|
|
75
|
+
const env = process.env.RAITON_SHUTDOWN_TIMEOUT_MS;
|
|
76
|
+
if (env !== undefined && Number.isFinite(Number(env))) return Number(env);
|
|
77
|
+
return this.get('shutdown')?.timeoutMs ?? 10_000;
|
|
19
78
|
}
|
|
20
79
|
|
|
21
|
-
static
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
80
|
+
static shouldValidateResponses(isDevelopment: boolean): boolean {
|
|
81
|
+
const setting = this.get('validation')?.responses ?? 'auto';
|
|
82
|
+
if (setting === 'auto') return isDevelopment;
|
|
83
|
+
return setting === true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static async sync(workdir: string, options: ConfigLoadOptions = {}): Promise<Map<keyof ConfigurableInterface, ConfigurableInterface[keyof ConfigurableInterface]>> {
|
|
87
|
+
if (this.current.size && !options.force) return this.current;
|
|
88
|
+
|
|
89
|
+
this.reset();
|
|
90
|
+
|
|
91
|
+
let loaded: Record<string, any> = {};
|
|
92
|
+
let source: string | null = null;
|
|
93
|
+
let thrownErrors: ConfigFieldError[] | undefined;
|
|
94
|
+
|
|
95
|
+
for (const ext of this._extensions) {
|
|
96
|
+
const configPath = path.join(workdir, `${Raiton.identifier}.config${ext}`);
|
|
97
|
+
if (!fs.existsSync(configPath)) continue;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
if (ext === '.json') {
|
|
101
|
+
const content = fs.readFileSync(configPath, 'utf-8');
|
|
102
|
+
loaded = JSON.parse(content || '{}') || {};
|
|
103
|
+
} else {
|
|
104
|
+
const configModule = await import(pathToFileURL(configPath).href);
|
|
105
|
+
const config = await (configModule?.default ?? configModule);
|
|
106
|
+
loaded = (config && typeof config === 'object') ? config : {};
|
|
107
|
+
}
|
|
108
|
+
source = configPath;
|
|
109
|
+
break;
|
|
110
|
+
} catch (error: any) {
|
|
111
|
+
if (isConfigValidationError(error)) {
|
|
112
|
+
this.source = configPath;
|
|
113
|
+
thrownErrors = error.errors;
|
|
114
|
+
loaded = {...this.defaultConfig};
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
25
117
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
118
|
+
const detail = error?.message ?? String(error);
|
|
119
|
+
if (ext === '.ts' || ext === '.mts' || ext === '.cts') {
|
|
120
|
+
// On Node, native TypeScript imports may be unavailable.
|
|
121
|
+
// Try the next documented format.
|
|
122
|
+
Logger.warn(
|
|
123
|
+
`Failed to load ${path.basename(configPath)} on this runtime: ${detail}. ` +
|
|
124
|
+
`Raiton will try the next supported configuration format.`
|
|
125
|
+
);
|
|
30
126
|
} else {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
127
|
+
// A syntactically invalid JavaScript/JSON config must block
|
|
128
|
+
// startup rather than silently fall back to defaults.
|
|
129
|
+
Logger.error(`Failed to load ${path.basename(configPath)}: ${detail}`);
|
|
130
|
+
thrownErrors = [{
|
|
131
|
+
field: "config",
|
|
132
|
+
message: `Cannot load ${path.basename(configPath)}: ${detail}`,
|
|
133
|
+
}];
|
|
134
|
+
source = configPath;
|
|
135
|
+
loaded = {...this.defaultConfig};
|
|
136
|
+
break;
|
|
41
137
|
}
|
|
42
138
|
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (source) {
|
|
142
|
+
const merged = {...this.defaultConfig, ...loaded};
|
|
143
|
+
if (loaded.observability) merged.observability = {...this.defaultConfig.observability, ...loaded.observability};
|
|
144
|
+
if (loaded.validation) merged.validation = {...this.defaultConfig.validation, ...loaded.validation};
|
|
145
|
+
if (loaded.shutdown) merged.shutdown = {...this.defaultConfig.shutdown, ...loaded.shutdown};
|
|
146
|
+
if (loaded.mcp) merged.mcp = {...this.defaultConfig.mcp, ...loaded.mcp};
|
|
147
|
+
loaded = merged;
|
|
148
|
+
} else {
|
|
149
|
+
loaded = {...this.defaultConfig};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const [key, value] of Object.entries(loaded))
|
|
153
|
+
this.current.set(key as keyof ConfigurableInterface, value as ConfigurableInterface[keyof ConfigurableInterface]);
|
|
154
|
+
|
|
155
|
+
this.source = source;
|
|
156
|
+
const validation = validateConfig(loaded);
|
|
157
|
+
this.errors = thrownErrors ?? validation.errors;
|
|
43
158
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
159
|
+
if (this.errors.length) {
|
|
160
|
+
Logger.error(
|
|
161
|
+
`Invalid ${Raiton.identifier} configuration` +
|
|
162
|
+
(source ? ` in ${path.relative(workdir, source)}` : '') +
|
|
163
|
+
`: ${this.errors.map(error => `${error.field} (${error.message})`).join(', ')}`
|
|
164
|
+
);
|
|
48
165
|
}
|
|
49
166
|
|
|
167
|
+
return this.current;
|
|
50
168
|
}
|
|
51
|
-
}
|
|
169
|
+
}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import {ConfigurableInterface} from "../../types/config.ts";
|
|
2
2
|
import {JsonUtil} from "../../framework/utilities/index.ts";
|
|
3
|
+
import {ConfigValidationError, validateConfig} from "./schema.ts";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function mergeWithPackage(config: Partial<ConfigurableInterface>, workdir: string) {
|
|
6
|
+
let pkg: any = {};
|
|
7
|
+
try {
|
|
8
|
+
pkg = JsonUtil.import(workdir + '/package.json');
|
|
9
|
+
} catch {
|
|
10
|
+
pkg = {};
|
|
11
|
+
}
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
const merged = {
|
|
14
|
+
...config,
|
|
15
|
+
...(pkg.raitonConfig || {}),
|
|
16
|
+
rootDir: config.rootDir || pkg.raitonConfig?.rootDir || './',
|
|
17
|
+
version: config.version || pkg.raitonConfig?.version || pkg.version || '0.0.1',
|
|
18
|
+
} as ConfigurableInterface;
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
const validation = validateConfig(merged);
|
|
21
|
+
if (!validation.valid) throw new ConfigValidationError(validation.errors);
|
|
22
|
+
return merged;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Typed project configuration helper. It validates field types and ranges at
|
|
27
|
+
* definition time, before the application opens a listening port.
|
|
28
|
+
*/
|
|
29
|
+
export async function defineConfig<T extends Partial<ConfigurableInterface> = Partial<ConfigurableInterface>>(
|
|
30
|
+
config?: T,
|
|
31
|
+
): Promise<T & ConfigurableInterface> {
|
|
32
|
+
return mergeWithPackage(config ?? {}, process.cwd()) as T & ConfigurableInterface;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Synchronous variant for configuration files that cannot await. */
|
|
36
|
+
export function defineConfigSync<T extends Partial<ConfigurableInterface> = Partial<ConfigurableInterface>>(
|
|
37
|
+
config?: T,
|
|
38
|
+
): T & ConfigurableInterface {
|
|
39
|
+
return mergeWithPackage(config ?? {}, process.cwd()) as T & ConfigurableInterface;
|
|
40
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import type {ConfigurableInterface} from "../../types/config.ts";
|
|
2
|
+
|
|
3
|
+
export interface ConfigFieldError {
|
|
4
|
+
field: string;
|
|
5
|
+
message: string;
|
|
6
|
+
expected?: string;
|
|
7
|
+
received?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ConfigValidationResult {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
errors: ConfigFieldError[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function describe(value: unknown): string {
|
|
16
|
+
if (value === null) return "null";
|
|
17
|
+
if (Array.isArray(value)) return "array";
|
|
18
|
+
return typeof value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function checkBoolean(errors: ConfigFieldError[], config: any, field: string) {
|
|
22
|
+
if (config[field] !== undefined && typeof config[field] !== "boolean") {
|
|
23
|
+
errors.push({
|
|
24
|
+
field,
|
|
25
|
+
message: `${field} must be a boolean`,
|
|
26
|
+
expected: "boolean",
|
|
27
|
+
received: describe(config[field]),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function checkString(errors: ConfigFieldError[], config: any, field: string) {
|
|
33
|
+
if (config[field] !== undefined && typeof config[field] !== "string") {
|
|
34
|
+
errors.push({
|
|
35
|
+
field,
|
|
36
|
+
message: `${field} must be a string`,
|
|
37
|
+
expected: "string",
|
|
38
|
+
received: describe(config[field]),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Validate a project configuration loaded from `raiton.config.*`.
|
|
45
|
+
* Errors are field-scoped so startup can fail with actionable messages.
|
|
46
|
+
*/
|
|
47
|
+
export function validateConfig(input: Partial<ConfigurableInterface> | any): ConfigValidationResult {
|
|
48
|
+
const errors: ConfigFieldError[] = [];
|
|
49
|
+
const config = input ?? {};
|
|
50
|
+
|
|
51
|
+
if (config.rootDir !== undefined) {
|
|
52
|
+
if (typeof config.rootDir !== "string" || !config.rootDir.trim()) {
|
|
53
|
+
errors.push({
|
|
54
|
+
field: "rootDir",
|
|
55
|
+
message: "rootDir must be a non-empty string",
|
|
56
|
+
expected: "string",
|
|
57
|
+
received: describe(config.rootDir),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
checkString(errors, config, "version");
|
|
63
|
+
checkString(errors, config, "hostname");
|
|
64
|
+
checkString(errors, config, "pathname");
|
|
65
|
+
checkString(errors, config, "prefix");
|
|
66
|
+
checkBoolean(errors, config, "develop");
|
|
67
|
+
checkBoolean(errors, config, "verbose");
|
|
68
|
+
|
|
69
|
+
if (config.port !== undefined) {
|
|
70
|
+
if (!Number.isInteger(config.port) || config.port < 1 || config.port > 65535) {
|
|
71
|
+
errors.push({
|
|
72
|
+
field: "port",
|
|
73
|
+
message: "port must be an integer between 1 and 65535",
|
|
74
|
+
expected: "integer(1..65535)",
|
|
75
|
+
received: String(config.port),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (config.protocole !== undefined && !["http", "https"].includes(config.protocole)) {
|
|
81
|
+
errors.push({
|
|
82
|
+
field: "protocole",
|
|
83
|
+
message: "protocole must be 'http' or 'https'",
|
|
84
|
+
expected: "http|https",
|
|
85
|
+
received: String(config.protocole),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (config.artifacts !== undefined) {
|
|
90
|
+
if (typeof config.artifacts !== "object" || config.artifacts === null) {
|
|
91
|
+
errors.push({field: "artifacts", message: "artifacts must be an object"});
|
|
92
|
+
} else if (config.artifacts.types !== undefined
|
|
93
|
+
&& (!Array.isArray(config.artifacts.types)
|
|
94
|
+
|| config.artifacts.types.some((type: any) => typeof type !== "string"))) {
|
|
95
|
+
errors.push({
|
|
96
|
+
field: "artifacts.types",
|
|
97
|
+
message: "artifacts.types must be an array of strings",
|
|
98
|
+
expected: "string[]",
|
|
99
|
+
received: describe(config.artifacts.types),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (config.devPage !== undefined && config.devPage.path !== undefined
|
|
105
|
+
&& (typeof config.devPage.path !== "string" || !config.devPage.path.startsWith("/"))) {
|
|
106
|
+
errors.push({
|
|
107
|
+
field: "devPage.path",
|
|
108
|
+
message: "devPage.path must be an absolute path",
|
|
109
|
+
expected: "string starting with /",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (config.observability !== undefined) {
|
|
114
|
+
if (typeof config.observability !== "object" || config.observability === null) {
|
|
115
|
+
errors.push({field: "observability", message: "observability must be an object"});
|
|
116
|
+
} else {
|
|
117
|
+
const mode = config.observability.mode;
|
|
118
|
+
if (mode !== undefined && !["off", "metrics", "traces", "all"].includes(mode)) {
|
|
119
|
+
errors.push({
|
|
120
|
+
field: "observability.mode",
|
|
121
|
+
message: "observability.mode must be off, metrics, traces, or all",
|
|
122
|
+
expected: "off|metrics|traces|all",
|
|
123
|
+
received: String(mode),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (config.observability.metricsPath !== undefined
|
|
127
|
+
&& (typeof config.observability.metricsPath !== "string"
|
|
128
|
+
|| !config.observability.metricsPath.startsWith("/"))) {
|
|
129
|
+
errors.push({
|
|
130
|
+
field: "observability.metricsPath",
|
|
131
|
+
message: "observability.metricsPath must be an absolute path",
|
|
132
|
+
expected: "string starting with /",
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (config.validation !== undefined) {
|
|
139
|
+
if (typeof config.validation !== "object" || config.validation === null) {
|
|
140
|
+
errors.push({field: "validation", message: "validation must be an object"});
|
|
141
|
+
} else if (config.validation.responses !== undefined
|
|
142
|
+
&& typeof config.validation.responses !== "boolean"
|
|
143
|
+
&& config.validation.responses !== "auto") {
|
|
144
|
+
errors.push({
|
|
145
|
+
field: "validation.responses",
|
|
146
|
+
message: "validation.responses must be a boolean or 'auto'",
|
|
147
|
+
expected: "boolean|auto",
|
|
148
|
+
received: String(config.validation.responses),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (config.shutdown !== undefined) {
|
|
154
|
+
const timeout = config.shutdown?.timeoutMs;
|
|
155
|
+
if (timeout !== undefined && (!Number.isInteger(timeout) || timeout < 0)) {
|
|
156
|
+
errors.push({
|
|
157
|
+
field: "shutdown.timeoutMs",
|
|
158
|
+
message: "shutdown.timeoutMs must be a positive integer",
|
|
159
|
+
expected: "integer >= 0",
|
|
160
|
+
received: String(timeout),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (config.devPage !== undefined) {
|
|
166
|
+
checkBoolean(errors, config.devPage, "enabled");
|
|
167
|
+
checkString(errors, config.devPage, "path");
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (config.mcp !== undefined) {
|
|
171
|
+
checkBoolean(errors, config.mcp, "exposeDestructive");
|
|
172
|
+
const rate = config.mcp?.rateLimitPerMinute;
|
|
173
|
+
if (rate !== undefined && (!Number.isInteger(rate) || rate < 0)) {
|
|
174
|
+
errors.push({
|
|
175
|
+
field: "mcp.rateLimitPerMinute",
|
|
176
|
+
message: "mcp.rateLimitPerMinute must be a non-negative integer",
|
|
177
|
+
expected: "integer >= 0",
|
|
178
|
+
received: String(rate),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {valid: errors.length === 0, errors};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export class ConfigValidationError extends Error {
|
|
187
|
+
constructor(public readonly errors: ConfigFieldError[]) {
|
|
188
|
+
super(`Invalid Raiton configuration:\n${errors.map(error => `- ${error.field}: ${error.message}`).join("\n")}`);
|
|
189
|
+
this.name = "ConfigValidationError";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* JSON Schema published for editors (autocomplete) and external validators.
|
|
195
|
+
*/
|
|
196
|
+
export function getConfigJsonSchema(): Record<string, any> {
|
|
197
|
+
return {
|
|
198
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
199
|
+
$id: "https://raiton.protorians.dev/schemas/config-1.0.0.json",
|
|
200
|
+
title: "Raiton project configuration",
|
|
201
|
+
type: "object",
|
|
202
|
+
additionalProperties: true,
|
|
203
|
+
properties: {
|
|
204
|
+
rootDir: {type: "string", minLength: 1, default: "./source"},
|
|
205
|
+
version: {type: "string"},
|
|
206
|
+
port: {type: "integer", minimum: 1, maximum: 65535},
|
|
207
|
+
hostname: {type: "string"},
|
|
208
|
+
protocole: {enum: ["http", "https"]},
|
|
209
|
+
pathname: {type: "string"},
|
|
210
|
+
prefix: {type: "string"},
|
|
211
|
+
develop: {type: "boolean"},
|
|
212
|
+
verbose: {type: "boolean"},
|
|
213
|
+
artifacts: {
|
|
214
|
+
type: "object",
|
|
215
|
+
properties: {
|
|
216
|
+
types: {type: "array", items: {type: "string"}, uniqueItems: true},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
observability: {
|
|
220
|
+
type: "object",
|
|
221
|
+
properties: {
|
|
222
|
+
mode: {enum: ["off", "metrics", "traces", "all"], default: "off"},
|
|
223
|
+
metricsPath: {type: "string", pattern: "^/"},
|
|
224
|
+
otelEndpoint: {type: "string", format: "uri"},
|
|
225
|
+
requestIdHeader: {type: "string"},
|
|
226
|
+
serviceName: {type: "string"},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
validation: {
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {
|
|
232
|
+
responses: {oneOf: [{type: "boolean"}, {const: "auto"}]},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
shutdown: {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {timeoutMs: {type: "integer", minimum: 0, default: 10000}},
|
|
238
|
+
},
|
|
239
|
+
devPage: {
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: {
|
|
242
|
+
enabled: {type: "boolean"},
|
|
243
|
+
path: {type: "string", pattern: "^/"},
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
mcp: {
|
|
247
|
+
type: "object",
|
|
248
|
+
properties: {
|
|
249
|
+
exposeDestructive: {type: "boolean", default: false},
|
|
250
|
+
rateLimitPerMinute: {type: "integer", minimum: 0},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
docs: {
|
|
254
|
+
type: "object",
|
|
255
|
+
properties: {
|
|
256
|
+
dir: {type: "string"},
|
|
257
|
+
lang: {enum: ["fr", "en"]},
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
required: ["rootDir"],
|
|
262
|
+
};
|
|
263
|
+
}
|
|
@@ -7,9 +7,8 @@ import {compileMcp} from "../mcp/builder.ts";
|
|
|
7
7
|
import {compileScheduler} from "../scheduler/builder.ts";
|
|
8
8
|
import {RaitonThread} from "../thread.ts";
|
|
9
9
|
import {Injection} from "../injection/index.ts";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {METADATA_KEYS} from "../../framework/constants/index.ts";
|
|
10
|
+
import {Artifacts, type ArtifactClassification} from "../../framework/artifacts.ts";
|
|
11
|
+
import {METADATA_KEYS} from "../../framework/constants/decorators.constant.ts";
|
|
13
12
|
import path from "node:path";
|
|
14
13
|
import {ControllerRouteTracker} from "./tracker.ts";
|
|
15
14
|
|
|
@@ -21,15 +20,21 @@ export class ControllerBuilder {
|
|
|
21
20
|
const output: any[] = []
|
|
22
21
|
const timestamp = Date.now()
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
// One classification per file, reused by both passes. The source
|
|
24
|
+
// directory is read exactly once.
|
|
25
|
+
const entries = files.map(file => {
|
|
25
26
|
const filename = path.join(workdir, file);
|
|
26
|
-
|
|
27
|
+
return {filename, classification: Artifacts.classify(filename)}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
for (const {filename, classification} of entries) {
|
|
27
31
|
if (classification?.channel !== 'hmr:di') continue;
|
|
28
32
|
await this.loadDiArtifact(filename, 1, timestamp);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
for (const
|
|
32
|
-
|
|
35
|
+
for (const {filename, classification} of entries) {
|
|
36
|
+
if (!classification) continue;
|
|
37
|
+
output.push(await this.build<any>({filename, version: 1, timestamp}, classification))
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
return output.filter(f => typeof f !== 'undefined');
|
|
@@ -49,11 +54,21 @@ export class ControllerBuilder {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
static async build<T>(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
+
static async build<T>(
|
|
58
|
+
{filename, version, timestamp}: BuilderHMRDeclarationInterface,
|
|
59
|
+
classification?: ArtifactClassification | null,
|
|
60
|
+
): Promise<T | undefined> {
|
|
61
|
+
const resolvedClassification = classification === undefined
|
|
62
|
+
? Artifacts.classify(filename)
|
|
63
|
+
: classification
|
|
64
|
+
|
|
65
|
+
if (!resolvedClassification)
|
|
66
|
+
return undefined;
|
|
67
|
+
|
|
68
|
+
const isController = resolvedClassification.channel === 'hmr:controller';
|
|
69
|
+
const isSocket = resolvedClassification.channel === 'hmr:socket';
|
|
70
|
+
const isMcp = resolvedClassification.channel === 'hmr:mcp';
|
|
71
|
+
const isScheduler = resolvedClassification.channel === 'hmr:scheduler';
|
|
57
72
|
|
|
58
73
|
if (!isController && !isSocket && !isMcp && !isScheduler)
|
|
59
74
|
return undefined;
|
|
@@ -87,6 +102,17 @@ export class ControllerBuilder {
|
|
|
87
102
|
const app = RaitonThread.current?.application
|
|
88
103
|
if (!app) return
|
|
89
104
|
|
|
105
|
+
const rootScope = (app as any).root
|
|
106
|
+
|
|
107
|
+
// A controller edit may rename the class. Remove routes tracked under
|
|
108
|
+
// the previous name(s) for this file before compiling the new class.
|
|
109
|
+
if (rootScope?.router && filename) {
|
|
110
|
+
for (const previousName of Injection.getArtifactNames(filename)) {
|
|
111
|
+
ControllerRouteTracker.removeRoutes(previousName, rootScope.router)
|
|
112
|
+
Injection.invalidateCascade(previousName)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
90
116
|
for (const mod of Object.values(modulo)) {
|
|
91
117
|
const name = (mod && typeof mod === 'object' && 'name' in mod) ? mod.name : (
|
|
92
118
|
typeof mod === 'function' ? mod.name ?? mod.constructor.name : undefined
|
|
@@ -94,7 +120,6 @@ export class ControllerBuilder {
|
|
|
94
120
|
|
|
95
121
|
if (typeof name === 'string' && typeof mod === 'function') {
|
|
96
122
|
Injection.invalidateCascade(name)
|
|
97
|
-
const rootScope = (app as any).root
|
|
98
123
|
if (rootScope?.router) {
|
|
99
124
|
ControllerRouteTracker.removeRoutes(name, rootScope.router)
|
|
100
125
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {ApplicationInterface} from "../../types/application.ts";
|
|
2
|
-
import {getControllerMetadata} from "
|
|
3
|
-
import {createHandler} from "../router/
|
|
2
|
+
import {getControllerMetadata} from "./metadata.ts";
|
|
3
|
+
import {createHandler} from "../router/handler.ts";
|
|
4
4
|
import {Injection} from "../injection/index.ts";
|
|
5
5
|
import {ControllerMetaInterface} from "../../types/index.ts";
|
|
6
6
|
import {ControllerRouteTracker} from "./tracker.ts";
|
|
7
|
+
import {CacheManager} from "../../framework/cache/cache.ts";
|
|
7
8
|
|
|
8
9
|
export function compileController(
|
|
9
10
|
ControllerClass: any,
|
|
@@ -20,11 +21,17 @@ export function compileController(
|
|
|
20
21
|
|
|
21
22
|
const routes: any[] = []
|
|
22
23
|
for (const route of metadata.routes) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// HMR: a modified handler must never be served from the previous
|
|
25
|
+
// @Cache entry.
|
|
26
|
+
CacheManager.invalidateRoute(`${metadata.prefix ?? ''}${route.path}`)
|
|
27
|
+
const handler = createHandler(instance, route, metadata)
|
|
28
|
+
const path = `${metadata.prefix ?? ''}${route.path}`
|
|
29
|
+
// `Application.route()` intentionally returns `this` for chaining, so
|
|
30
|
+
// use the router directly to track the actual Route (HMR needs to
|
|
31
|
+
// remove it by identity).
|
|
32
|
+
const registered = rootScope?.router
|
|
33
|
+
? rootScope.router.add(route.method as any, path, handler)
|
|
34
|
+
: app.route(route.method as any, path, handler)
|
|
28
35
|
routes.push(registered)
|
|
29
36
|
}
|
|
30
37
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ControllerMetaInterface} from "../../types/index.ts";
|
|
2
|
-
import {METADATA_KEYS} from "../../framework/
|
|
2
|
+
import {METADATA_KEYS} from "../../framework/constants/decorators.constant.ts";
|
|
3
3
|
import "reflect-metadata";
|
|
4
4
|
|
|
5
5
|
export function getControllerMetadata(target: any): ControllerMetaInterface {
|