raiton 6.8.8-beta.24 → 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 +50 -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 +33575 -21723
- 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 +92 -19
- 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,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema-first contracts.
|
|
3
|
+
*
|
|
4
|
+
* A single TypeBox schema feeds runtime validation, TypeScript inference and
|
|
5
|
+
* documentation generation. The `t` facade exposes:
|
|
6
|
+
* - the lower-case builder API documented by Raiton (`t.object`, `t.string`);
|
|
7
|
+
* - chainable constraints (`t.string().min(2).email()`);
|
|
8
|
+
* - `t.infer<S>()` for compile-time inference.
|
|
9
|
+
*
|
|
10
|
+
* Chain methods are attached as non-enumerable properties so schemas stay
|
|
11
|
+
* pure JSON Schema for OpenAPI, the manifest and `JSON.stringify`.
|
|
12
|
+
*/
|
|
13
|
+
import {Type, type Static, type TSchema, type TOptional} from "@sinclair/typebox";
|
|
14
|
+
|
|
15
|
+
declare module "@sinclair/typebox" {
|
|
16
|
+
interface TSchema {
|
|
17
|
+
/** Minimum string length, number value, array items or object properties. */
|
|
18
|
+
min(value: number): this;
|
|
19
|
+
/** Maximum string length, number value, array items or object properties. */
|
|
20
|
+
max(value: number): this;
|
|
21
|
+
email(): this;
|
|
22
|
+
url(): this;
|
|
23
|
+
uuid(): this;
|
|
24
|
+
regex(pattern: RegExp | string): this;
|
|
25
|
+
length(value: number): this;
|
|
26
|
+
optional(): TOptional<this>;
|
|
27
|
+
default(value: unknown): this;
|
|
28
|
+
describe(value: string): this;
|
|
29
|
+
example(value: unknown): this;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type {TSchema, Static};
|
|
34
|
+
export type Infer<S extends TSchema> = Static<S>;
|
|
35
|
+
export {Type};
|
|
36
|
+
|
|
37
|
+
function cloneSchema(schema: TSchema): TSchema {
|
|
38
|
+
return {...schema};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function setFormat(schema: TSchema, format: string): TSchema {
|
|
42
|
+
const next = cloneSchema(schema);
|
|
43
|
+
(next as any).format = format;
|
|
44
|
+
return next;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function decorate<T extends TSchema>(schema: T): T {
|
|
48
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
49
|
+
|
|
50
|
+
const define = (name: string, value: Function) => {
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(schema, name)) return;
|
|
52
|
+
Object.defineProperty(schema, name, {
|
|
53
|
+
value,
|
|
54
|
+
enumerable: false,
|
|
55
|
+
configurable: true,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
define("min", (value: number) => {
|
|
60
|
+
const next = cloneSchema(schema) as any;
|
|
61
|
+
if (next.type === "string") next.minLength = value;
|
|
62
|
+
else if (next.type === "array") next.minItems = value;
|
|
63
|
+
else if (next.type === "object") next.minProperties = value;
|
|
64
|
+
else next.minimum = value;
|
|
65
|
+
return decorate(next);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
define("max", (value: number) => {
|
|
69
|
+
const next = cloneSchema(schema) as any;
|
|
70
|
+
if (next.type === "string") next.maxLength = value;
|
|
71
|
+
else if (next.type === "array") next.maxItems = value;
|
|
72
|
+
else if (next.type === "object") next.maxProperties = value;
|
|
73
|
+
else next.maximum = value;
|
|
74
|
+
return decorate(next);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
define("length", (value: number) => {
|
|
78
|
+
const next = cloneSchema(schema) as any;
|
|
79
|
+
if (next.type === "string") {
|
|
80
|
+
next.minLength = value;
|
|
81
|
+
next.maxLength = value;
|
|
82
|
+
} else if (next.type === "array") {
|
|
83
|
+
next.minItems = value;
|
|
84
|
+
next.maxItems = value;
|
|
85
|
+
}
|
|
86
|
+
return decorate(next);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
define("email", () => decorate(setFormat(schema, "email")));
|
|
90
|
+
define("url", () => decorate(setFormat(schema, "uri")));
|
|
91
|
+
define("uuid", () => decorate(setFormat(schema, "uuid")));
|
|
92
|
+
|
|
93
|
+
define("regex", (pattern: RegExp | string) => {
|
|
94
|
+
const next = cloneSchema(schema) as any;
|
|
95
|
+
next.pattern = typeof pattern === "string" ? pattern : pattern.source;
|
|
96
|
+
return decorate(next);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
define("optional", () => decorate(Type.Optional(schema) as any));
|
|
100
|
+
|
|
101
|
+
define("default", (value: unknown) => {
|
|
102
|
+
const next = cloneSchema(schema) as any;
|
|
103
|
+
next.default = value;
|
|
104
|
+
return decorate(next);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
define("describe", (value: string) => {
|
|
108
|
+
const next = cloneSchema(schema) as any;
|
|
109
|
+
next.description = value;
|
|
110
|
+
return decorate(next);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
define("example", (value: unknown) => {
|
|
114
|
+
const next = cloneSchema(schema) as any;
|
|
115
|
+
next.examples = [value];
|
|
116
|
+
return decorate(next);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return schema;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const LOWERCASE_METHODS = {
|
|
123
|
+
string: "String",
|
|
124
|
+
number: "Number",
|
|
125
|
+
integer: "Integer",
|
|
126
|
+
boolean: "Boolean",
|
|
127
|
+
object: "Object",
|
|
128
|
+
array: "Array",
|
|
129
|
+
optional: "Optional",
|
|
130
|
+
readonly: "Readonly",
|
|
131
|
+
readonlyOptional: "ReadonlyOptional",
|
|
132
|
+
record: "Record",
|
|
133
|
+
any: "Any",
|
|
134
|
+
unknown: "Unknown",
|
|
135
|
+
never: "Never",
|
|
136
|
+
null: "Null",
|
|
137
|
+
undefined: "Undefined",
|
|
138
|
+
union: "Union",
|
|
139
|
+
literal: "Literal",
|
|
140
|
+
enum: "Enum",
|
|
141
|
+
intersect: "Intersect",
|
|
142
|
+
tuple: "Tuple",
|
|
143
|
+
ref: "Ref",
|
|
144
|
+
partial: "Partial",
|
|
145
|
+
required: "Required",
|
|
146
|
+
pick: "Pick",
|
|
147
|
+
omit: "Omit",
|
|
148
|
+
keyof: "KeyOf",
|
|
149
|
+
composite: "Composite",
|
|
150
|
+
const: "Const",
|
|
151
|
+
date: "Date",
|
|
152
|
+
function: "Function",
|
|
153
|
+
constructor: "Constructor",
|
|
154
|
+
promise: "Promise",
|
|
155
|
+
symbol: "Symbol",
|
|
156
|
+
bigint: "BigInt",
|
|
157
|
+
uint8array: "Uint8Array",
|
|
158
|
+
this: "This",
|
|
159
|
+
recursive: "Recursive",
|
|
160
|
+
asyncIterator: "AsyncIterator",
|
|
161
|
+
iterator: "Iterator",
|
|
162
|
+
} as const;
|
|
163
|
+
|
|
164
|
+
type LowercaseMethods = {
|
|
165
|
+
[K in keyof typeof LOWERCASE_METHODS]:
|
|
166
|
+
(typeof Type)[Extract<(typeof LOWERCASE_METHODS)[K], keyof typeof Type>];
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
type InferMethod = {
|
|
170
|
+
infer: <S extends TSchema>(schema: S) => Static<S>;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const facade: any = {infer: undefined};
|
|
174
|
+
|
|
175
|
+
// TypeBox exposes builder methods on a frozen class instance. Copy the method
|
|
176
|
+
// functions onto a plain facade and wrap them so every produced schema carries
|
|
177
|
+
// the chainable Raiton API.
|
|
178
|
+
for (let prototype = Object.getPrototypeOf(Type); prototype && prototype !== Object.prototype; prototype = Object.getPrototypeOf(prototype)) {
|
|
179
|
+
for (const name of Object.getOwnPropertyNames(prototype)) {
|
|
180
|
+
if (name === "constructor" || name in facade) continue;
|
|
181
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
|
|
182
|
+
if (typeof descriptor?.value === "function") {
|
|
183
|
+
facade[name] = (...args: any[]) => decorate((Type as any)[name](...args));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
for (const [lowercase, pascal] of Object.entries(LOWERCASE_METHODS)) {
|
|
189
|
+
facade[lowercase] = (...args: any[]) => decorate((Type as any)[pascal](...args));
|
|
190
|
+
}
|
|
191
|
+
facade.infer = undefined;
|
|
192
|
+
|
|
193
|
+
export const t = facade as typeof Type & LowercaseMethods & InferMethod;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
import {Security
|
|
1
|
+
import {Security} from "../framework/plugins/security/index.ts";
|
|
2
|
+
import {bodyParserPlugin} from "../framework/plugins/body-parser.plugin.ts";
|
|
2
3
|
import {PluginScope} from './plugins/scope.ts'
|
|
3
4
|
import {RequestContext} from './context.ts'
|
|
4
5
|
import {ApplicationConfigInterface, ApplicationInterface} from "../types/application.ts";
|
|
5
|
-
import {HttpException
|
|
6
|
+
import {HttpException} from "../framework/exceptions/http-exception.ts";
|
|
7
|
+
import {HttpMethod} from "../framework/enums/http-method.enum.ts";
|
|
8
|
+
import {ThrowableResponse} from "../framework/responses/http-throwable.ts";
|
|
9
|
+
import {HttpStatus} from "../framework/enums/http-status.enum.ts";
|
|
6
10
|
import {RouteHandlerCallable} from "../types/index.ts";
|
|
7
11
|
import {Logger} from "@protorians/logger";
|
|
8
12
|
import {RaitonConfig} from "./config/index.ts";
|
|
13
|
+
import {Raiton} from "./raiton.ts";
|
|
9
14
|
import {Artifacts} from "../framework/artifacts.ts";
|
|
10
15
|
import {Injection} from "./injection/index.ts";
|
|
11
16
|
import {HttpsConfigInterface, resolveHttpsConfig} from "../framework/utilities/https.util.ts";
|
|
17
|
+
import {observabilityPlugin} from "../framework/observability/plugin.ts";
|
|
18
|
+
import {devPagePlugin, watchDevPageHmr} from "../framework/plugins/dev.plugin.ts";
|
|
19
|
+
import {shutdown} from "../framework/observability/shutdown.ts";
|
|
20
|
+
import {resolveRequestId} from "../framework/observability/request.ts";
|
|
21
|
+
import {enrichErrorPayload, errorPayload} from "../framework/errors/catalog.ts";
|
|
22
|
+
import {suggestRoute} from "../framework/utilities/route-suggestion.util.ts";
|
|
12
23
|
|
|
13
24
|
export class Application implements ApplicationInterface {
|
|
14
25
|
private root: PluginScope
|
|
15
26
|
private _resolvedHttps: HttpsConfigInterface | undefined
|
|
27
|
+
private readonly _observability = RaitonConfig.getObservability()
|
|
28
|
+
private readonly _plugins = new Set<string>()
|
|
16
29
|
|
|
17
30
|
readonly version: string = RaitonConfig.get('version') || '0.0.1'
|
|
18
31
|
|
|
@@ -40,9 +53,32 @@ export class Application implements ApplicationInterface {
|
|
|
40
53
|
this.register(Security.headers)
|
|
41
54
|
this.register(bodyParserPlugin())
|
|
42
55
|
|
|
56
|
+
const observability = this._observability
|
|
57
|
+
if (observability.mode !== 'off') {
|
|
58
|
+
this.register(observabilityPlugin(observability))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Development page: never mounted in production (HMR/develop only).
|
|
62
|
+
const devPage = RaitonConfig.get('devPage')
|
|
63
|
+
if (this.development && devPage?.enabled !== false) {
|
|
64
|
+
this.register(devPagePlugin({path: devPage?.path ?? '/__dev'}))
|
|
65
|
+
watchDevPageHmr()
|
|
66
|
+
}
|
|
67
|
+
|
|
43
68
|
return this;
|
|
44
69
|
}
|
|
45
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Development mode follows HMR, explicit `develop`, or NODE_ENV.
|
|
73
|
+
*/
|
|
74
|
+
public get development(): boolean {
|
|
75
|
+
return Boolean(
|
|
76
|
+
this.config.develop
|
|
77
|
+
|| Raiton.thread?.builder?.options?.hmr
|
|
78
|
+
|| process.env.NODE_ENV === 'development'
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
46
82
|
public get hostname(): string {
|
|
47
83
|
const protocol = this._resolvedHttps?.enabled
|
|
48
84
|
? 'https'
|
|
@@ -74,11 +110,21 @@ export class Application implements ApplicationInterface {
|
|
|
74
110
|
}
|
|
75
111
|
|
|
76
112
|
register(plugin: any): this {
|
|
113
|
+
if (plugin && typeof plugin === 'object' && typeof plugin.name === 'string') {
|
|
114
|
+
if (this._plugins.has(plugin.name)) return this
|
|
115
|
+
this._plugins.add(plugin.name)
|
|
116
|
+
}
|
|
77
117
|
this.root.register(plugin)
|
|
78
118
|
return this
|
|
79
119
|
}
|
|
80
120
|
|
|
81
121
|
use(mw: any): this {
|
|
122
|
+
// Plugin objects are installed once by name (idempotent body parser,
|
|
123
|
+
// security and observability registration).
|
|
124
|
+
if (mw && typeof mw === 'object' && typeof mw.name === 'string' && typeof mw.setup === 'function') {
|
|
125
|
+
if (this._plugins.has(mw.name)) return this
|
|
126
|
+
this._plugins.add(mw.name)
|
|
127
|
+
}
|
|
82
128
|
this.root.use(mw)
|
|
83
129
|
return this
|
|
84
130
|
}
|
|
@@ -121,98 +167,194 @@ export class Application implements ApplicationInterface {
|
|
|
121
167
|
return this.route(HttpMethod.TRACE, path, handler, version)
|
|
122
168
|
}
|
|
123
169
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
`Incoming request: ${req.method} ${req.url}`
|
|
130
|
-
)
|
|
170
|
+
private parseRequestUrl(url: string | undefined): URL {
|
|
171
|
+
try {
|
|
172
|
+
return new URL(url || '/', this.hostname)
|
|
173
|
+
} catch {
|
|
174
|
+
return new URL('/', this.hostname)
|
|
131
175
|
}
|
|
176
|
+
}
|
|
132
177
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
const req = context.req;
|
|
138
|
-
const reply = context.reply;
|
|
139
|
-
|
|
140
|
-
const url = new URL(req.url, this.hostname)
|
|
141
|
-
let pathname = url.pathname
|
|
178
|
+
async handle(req: any, reply: any): Promise<any> {
|
|
179
|
+
const release = shutdown.track()
|
|
180
|
+
const observability = this._observability
|
|
181
|
+
const requestId = resolveRequestId(req, observability.requestIdHeader)
|
|
142
182
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
183
|
+
try {
|
|
184
|
+
const ctx = new RequestContext(req, reply)
|
|
185
|
+
ctx.state.requestId = requestId
|
|
186
|
+
// Parse the URL once per request: the body parser, middleware and
|
|
187
|
+
// router all reuse this instance instead of parsing it again.
|
|
188
|
+
const requestUrl = this.parseRequestUrl(req.url)
|
|
189
|
+
ctx.state.url = requestUrl
|
|
190
|
+
|
|
191
|
+
// During graceful shutdown, new requests are rejected immediately
|
|
192
|
+
// while already-tracked requests are allowed to finish.
|
|
193
|
+
if (shutdown.isDraining) {
|
|
194
|
+
try {
|
|
195
|
+
reply.status(HttpStatus.SERVICE_UNAVAILABLE)
|
|
196
|
+
reply.send(errorPayload('SERVICE_UNAVAILABLE', {requestId}))
|
|
197
|
+
} catch {
|
|
198
|
+
// Ignore transport errors during shutdown.
|
|
151
199
|
}
|
|
200
|
+
return
|
|
152
201
|
}
|
|
153
202
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} else {
|
|
161
|
-
if (this.config.verbose) {
|
|
162
|
-
Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`)
|
|
163
|
-
}
|
|
164
|
-
reply.status(404)
|
|
165
|
-
return reply.send(RaitonResponses('Not Found', null, HttpStatus.NOT_FOUND, {error: false}))
|
|
166
|
-
}
|
|
203
|
+
// Always expose the correlation id, even when metrics/traces are
|
|
204
|
+
// disabled: it is cheap and makes production logs actionable.
|
|
205
|
+
try {
|
|
206
|
+
reply.header(observability.requestIdHeader, requestId)
|
|
207
|
+
} catch {
|
|
208
|
+
// A mock reply may not implement `header`; ignore.
|
|
167
209
|
}
|
|
168
210
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
211
|
+
if (this.config.verbose) {
|
|
212
|
+
Logger.info(
|
|
213
|
+
`Incoming request: ${req.method} ${req.url}`
|
|
214
|
+
)
|
|
215
|
+
}
|
|
173
216
|
|
|
174
|
-
if (
|
|
217
|
+
if (this.root.hooks.has('onRequest')) {
|
|
218
|
+
await this.root.hooks.run('onRequest', ctx)
|
|
219
|
+
}
|
|
220
|
+
const notFound = (pathname: string) => {
|
|
175
221
|
if (this.config.verbose) {
|
|
176
|
-
Logger.warn(`Route not found: ${req.method} ${pathname}`)
|
|
222
|
+
Logger.warn(`Route not found: ${req.method} ${pathname} request_id=${requestId}`)
|
|
223
|
+
}
|
|
224
|
+
const body: any = errorPayload('NOT_FOUND', {
|
|
225
|
+
message: 'Not Found',
|
|
226
|
+
requestId,
|
|
227
|
+
})
|
|
228
|
+
if (this.development) {
|
|
229
|
+
const candidates = this.root.router.getRoutes().filter(route =>
|
|
230
|
+
!(route.handler as any)?._raitonInternal
|
|
231
|
+
&& !route.path.startsWith('/__dev')
|
|
232
|
+
&& !route.path.startsWith('/metrics')
|
|
233
|
+
)
|
|
234
|
+
const suggestion = suggestRoute(candidates, req.method, pathname)
|
|
235
|
+
if (suggestion) body.suggestion = suggestion
|
|
177
236
|
}
|
|
178
|
-
reply.status(
|
|
179
|
-
return reply.send(
|
|
237
|
+
reply.status(HttpStatus.NOT_FOUND)
|
|
238
|
+
return reply.send(body)
|
|
180
239
|
}
|
|
181
240
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
241
|
+
const handler: any = async (param: any) => {
|
|
242
|
+
const context = param.context ?? param;
|
|
243
|
+
const req = context.req;
|
|
244
|
+
const reply = context.reply;
|
|
245
|
+
|
|
246
|
+
const url = (context.state?.url as URL | undefined) ?? new URL(req.url, this.hostname)
|
|
247
|
+
let pathname = url.pathname
|
|
248
|
+
|
|
249
|
+
if (this.config.prefix) {
|
|
250
|
+
const prefix = this.config.prefix.endsWith('/') ? this.config.prefix.slice(0, -1) : this.config.prefix
|
|
251
|
+
if (pathname === prefix) {
|
|
252
|
+
pathname = '/'
|
|
253
|
+
} else if (pathname.startsWith(prefix + '/')) {
|
|
254
|
+
pathname = pathname.substring(prefix.length) || '/'
|
|
255
|
+
} else if (this.config.verbose) {
|
|
256
|
+
Logger.warn(`Request out of application prefix: ${pathname} (expected: ${prefix}/*)`)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
185
259
|
|
|
186
|
-
if (
|
|
187
|
-
|
|
260
|
+
if (this.config.pathname && this.config.pathname !== '/') {
|
|
261
|
+
const appPathname = this.config.pathname.endsWith('/') ? this.config.pathname : `${this.config.pathname}/`
|
|
262
|
+
if (pathname.startsWith(appPathname)) {
|
|
263
|
+
pathname = pathname.substring(appPathname.length - 1) || '/'
|
|
264
|
+
} else if (pathname === this.config.pathname) {
|
|
265
|
+
pathname = '/'
|
|
266
|
+
} else {
|
|
267
|
+
if (this.config.verbose) {
|
|
268
|
+
Logger.warn(`Request out of application pathname: ${pathname} (expected prefix: ${this.config.pathname})`)
|
|
269
|
+
}
|
|
270
|
+
return notFound(pathname)
|
|
271
|
+
}
|
|
188
272
|
}
|
|
189
|
-
|
|
190
|
-
|
|
273
|
+
|
|
274
|
+
const resolved = this.root.router.resolve(
|
|
275
|
+
req.method,
|
|
276
|
+
pathname
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
if (!resolved) {
|
|
280
|
+
const pathRoute = this.root.router.matchPath(pathname)
|
|
281
|
+
if (pathRoute) {
|
|
282
|
+
reply.status(HttpStatus.METHOD_NOT_ALLOWED)
|
|
283
|
+
return reply.send({
|
|
284
|
+
...errorPayload('METHOD_NOT_ALLOWED', {requestId}),
|
|
285
|
+
allowed: [pathRoute.method],
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
return notFound(pathname)
|
|
191
289
|
}
|
|
192
290
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
291
|
+
const route = resolved.route
|
|
292
|
+
context.state.matchedRoutePath = route.version
|
|
293
|
+
? `/${route.version}${route.path}`
|
|
294
|
+
: route.path
|
|
295
|
+
|
|
296
|
+
try {
|
|
297
|
+
// Parameters are request-scoped: never read them from the
|
|
298
|
+
// shared Route instance.
|
|
299
|
+
(context as any).params = resolved.params;
|
|
300
|
+
let responses = await route.handler(context)
|
|
301
|
+
|
|
302
|
+
if (responses instanceof ThrowableResponse) {
|
|
303
|
+
context.reply.status(responses.statusCode ?? 500)
|
|
304
|
+
}
|
|
305
|
+
if (responses instanceof HttpException) {
|
|
306
|
+
context.reply.status(responses.statusCode ?? 500)
|
|
307
|
+
}
|
|
308
|
+
// Plain response objects may carry a status (health checks,
|
|
309
|
+
// generated controllers returning `RaitonResponses`).
|
|
310
|
+
if (responses && typeof responses === "object" && typeof responses.statusCode === "number") {
|
|
311
|
+
try {
|
|
312
|
+
context.reply.status(responses.statusCode)
|
|
313
|
+
} catch {
|
|
314
|
+
// Mock replies without status tracking.
|
|
315
|
+
}
|
|
316
|
+
if (responses.statusCode >= 400 && responses.error === true) {
|
|
317
|
+
responses = enrichErrorPayload(responses, responses.statusCode, requestId);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
context.reply.send(responses)
|
|
322
|
+
} catch (e: any) {
|
|
323
|
+
Logger.info(`${req.method} ${req.url} request_id=${requestId}`)
|
|
324
|
+
Logger.error(`Failed to execute handle request_id=${requestId}`, e.message ?? e)
|
|
325
|
+
if (this.development) {
|
|
326
|
+
console.error(e)
|
|
327
|
+
}
|
|
328
|
+
context.reply.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
329
|
+
context.reply.send(errorPayload('INTERNAL_SERVER_ERROR', {
|
|
330
|
+
requestId,
|
|
331
|
+
...(this.development ? {details: {message: String(e?.message ?? e)}} : {}),
|
|
332
|
+
}))
|
|
199
333
|
}
|
|
200
|
-
context.reply.status(500)
|
|
201
|
-
context.reply.send(RaitonResponses('Internal Server Error', null, HttpStatus.INTERNAL_SERVER_ERROR, {error: true}))
|
|
202
334
|
}
|
|
203
|
-
}
|
|
204
335
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
Logger.
|
|
212
|
-
|
|
213
|
-
|
|
336
|
+
try {
|
|
337
|
+
await this.root.middleware.run(ctx, handler)
|
|
338
|
+
if (this.root.hooks.has('onResponse')) {
|
|
339
|
+
await this.root.hooks.run('onResponse', ctx)
|
|
340
|
+
}
|
|
341
|
+
} catch (err: any) {
|
|
342
|
+
Logger.info(`${req.method} ${req.url} request_id=${requestId}`)
|
|
343
|
+
if (err instanceof HttpException || err instanceof ThrowableResponse) {
|
|
344
|
+
Logger.error(`Server error request_id=${requestId}`, err.message ?? err);
|
|
345
|
+
const status = err.statusCode ?? 500;
|
|
346
|
+
ctx.reply.status(status)
|
|
347
|
+
return ctx.reply.send(enrichErrorPayload(err.render(), status, requestId))
|
|
348
|
+
}
|
|
349
|
+
const body = errorPayload('INTERNAL_SERVER_ERROR', {
|
|
350
|
+
requestId,
|
|
351
|
+
...(this.development ? {details: {message: String(err?.message ?? err)}} : {}),
|
|
352
|
+
})
|
|
353
|
+
ctx.reply.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
354
|
+
return ctx.reply.send(body)
|
|
214
355
|
}
|
|
215
|
-
|
|
356
|
+
} finally {
|
|
357
|
+
release()
|
|
216
358
|
}
|
|
217
359
|
}
|
|
218
360
|
}
|
package/source/core/builder.ts
CHANGED
|
@@ -10,9 +10,9 @@ import {watch} from "fs";
|
|
|
10
10
|
import {LBadge, Logger} from "@protorians/logger";
|
|
11
11
|
import {Throwable} from "../framework/exceptions/index.ts";
|
|
12
12
|
import {Artifacts, HMR_CHANNELS, HmrChannel} from "../framework/artifacts.ts";
|
|
13
|
-
import {build} from "esbuild";
|
|
14
13
|
import {execSync, spawn, spawnSync} from "node:child_process";
|
|
15
14
|
import {isNodeUsed} from "../bin/constants.ts";
|
|
15
|
+
import {invalidateManifest} from "../manifest/manifest.ts";
|
|
16
16
|
|
|
17
17
|
export class RaitonBuilder implements BuilderInterface {
|
|
18
18
|
protected _source: string | null = null;
|
|
@@ -56,6 +56,9 @@ export class RaitonBuilder implements BuilderInterface {
|
|
|
56
56
|
const classification = Artifacts.classify(filename)
|
|
57
57
|
if (!classification) return
|
|
58
58
|
|
|
59
|
+
// Any source change makes the cached inventory stale.
|
|
60
|
+
invalidateManifest()
|
|
61
|
+
|
|
59
62
|
// Sur Node, le rechargement d'artefacts TypeScript en mémoire n'est pas
|
|
60
63
|
// possible (import() natif des fichiers .ts). On bascule alors sur le
|
|
61
64
|
// redémarrage de processus via IPC RESTART géré par la commande `develop`.
|
|
@@ -251,6 +254,7 @@ export class RaitonBuilder implements BuilderInterface {
|
|
|
251
254
|
const outfile = this.bootstrapperFile
|
|
252
255
|
if (!outfile) throw new Error('Bootstrapper file not found')
|
|
253
256
|
|
|
257
|
+
const {build} = await import("esbuild")
|
|
254
258
|
await build({
|
|
255
259
|
entryPoints: [this.bootstrapper],
|
|
256
260
|
bundle: true,
|
|
@@ -289,7 +293,7 @@ export class RaitonBuilder implements BuilderInterface {
|
|
|
289
293
|
Raiton.thread = thread;
|
|
290
294
|
const app = await bootstrapper.default(thread);
|
|
291
295
|
|
|
292
|
-
if (!this.options.serve) await this.build(thread)
|
|
296
|
+
if (!this.options.serve && this.options.compile !== false) await this.build(thread)
|
|
293
297
|
|
|
294
298
|
return app;
|
|
295
299
|
}
|