jishushell 0.6.18 → 0.7.3
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/apps/anythingllm-container.yaml +1 -0
- package/apps/browserless-chromium-container.yaml +1 -0
- package/apps/filebrowser-container.yaml +1 -0
- package/apps/hermes-container.yaml +1 -7
- package/apps/immich-container-lite.yaml +337 -0
- package/apps/immich-container.yaml +371 -0
- package/apps/jishu-kb-container.yaml +26 -21
- package/apps/ollama-binary.yaml +1 -0
- package/apps/ollama-cpu-container.yaml +1 -0
- package/apps/ollama-with-hollama-binary.yaml +2 -0
- package/apps/openclaw-binary.yaml +4 -8
- package/apps/openclaw-container.yaml +1 -7
- package/apps/openclaw-with-ollama-container.yaml +1 -0
- package/apps/openclaw-with-searxng-container.yaml +20 -0
- package/apps/searxng-container.yaml +20 -0
- package/apps/weknora-container.yaml +5 -0
- package/dependencies/jishushell-panel-0.7.3.tgz +0 -0
- package/dist/cli/core.js +1 -1
- package/dist/cli/core.js.map +1 -1
- package/dist/cli/doctor.js +96 -0
- package/dist/cli/doctor.js.map +1 -1
- package/dist/config.d.ts +9 -1
- package/dist/config.js +72 -2
- package/dist/config.js.map +1 -1
- package/dist/install.js +60 -19
- package/dist/install.js.map +1 -1
- package/dist/routes/admin.d.ts +2 -0
- package/dist/routes/admin.js +72 -0
- package/dist/routes/admin.js.map +1 -0
- package/dist/routes/docker.d.ts +2 -0
- package/dist/routes/docker.js +58 -0
- package/dist/routes/docker.js.map +1 -0
- package/dist/routes/file-mounts.js +5 -8
- package/dist/routes/file-mounts.js.map +1 -1
- package/dist/routes/instances.d.ts +0 -14
- package/dist/routes/instances.js +44 -1184
- package/dist/routes/instances.js.map +1 -1
- package/dist/server.d.ts +6 -0
- package/dist/server.js +53 -20
- package/dist/server.js.map +1 -1
- package/dist/services/app-common/catalog-service.js +15 -5
- package/dist/services/app-common/catalog-service.js.map +1 -1
- package/dist/services/app-common/delete-service.js +5 -0
- package/dist/services/app-common/delete-service.js.map +1 -1
- package/dist/services/app-common/instance-store.js +3 -0
- package/dist/services/app-common/instance-store.js.map +1 -1
- package/dist/services/app-common/lifecycle-service.js +12 -4
- package/dist/services/app-common/lifecycle-service.js.map +1 -1
- package/dist/services/app-common/ownership.d.ts +3 -0
- package/dist/services/app-common/ownership.js +11 -0
- package/dist/services/app-common/ownership.js.map +1 -0
- package/dist/services/app-common/runtime-facts.js +2 -0
- package/dist/services/app-common/runtime-facts.js.map +1 -1
- package/dist/services/app-common/spec-materializer.d.ts +0 -1
- package/dist/services/app-common/spec-materializer.js +21 -87
- package/dist/services/app-common/spec-materializer.js.map +1 -1
- package/dist/services/app-common/status-refresh.js +25 -13
- package/dist/services/app-common/status-refresh.js.map +1 -1
- package/dist/services/app-modules/browserless/routes.js +5 -3
- package/dist/services/app-modules/browserless/routes.js.map +1 -1
- package/dist/services/capabilities/contract.d.ts +1 -2
- package/dist/services/capabilities/contract.js +0 -10
- package/dist/services/capabilities/contract.js.map +1 -1
- package/dist/services/capabilities/endpoint-validator.js +0 -1
- package/dist/services/capabilities/endpoint-validator.js.map +1 -1
- package/dist/services/capabilities/health.js +1 -1
- package/dist/services/capabilities/health.js.map +1 -1
- package/dist/services/capability-proxy/http.d.ts +7 -0
- package/dist/services/capability-proxy/http.js +555 -0
- package/dist/services/capability-proxy/http.js.map +1 -0
- package/dist/services/capability-proxy/terminal.d.ts +4 -0
- package/dist/services/capability-proxy/terminal.js +179 -0
- package/dist/services/capability-proxy/terminal.js.map +1 -0
- package/dist/services/connections/admin.js +19 -9
- package/dist/services/connections/admin.js.map +1 -1
- package/dist/services/connections/apply.d.ts +3 -9
- package/dist/services/connections/apply.js +0 -29
- package/dist/services/connections/apply.js.map +1 -1
- package/dist/services/connections/transactor.js +2 -2
- package/dist/services/connections/transactor.js.map +1 -1
- package/dist/services/files/bootstrap.d.ts +7 -0
- package/dist/services/files/bootstrap.js +16 -0
- package/dist/services/files/bootstrap.js.map +1 -0
- package/dist/services/files/photos/upload-page.d.ts +2 -0
- package/dist/services/files/photos/upload-page.js +248 -0
- package/dist/services/files/photos/upload-page.js.map +1 -0
- package/dist/services/files/photos/upload-store.d.ts +74 -0
- package/dist/services/files/photos/upload-store.js +432 -0
- package/dist/services/files/photos/upload-store.js.map +1 -0
- package/dist/services/http/proxy-utils.d.ts +7 -0
- package/dist/services/http/proxy-utils.js +29 -0
- package/dist/services/http/proxy-utils.js.map +1 -0
- package/dist/services/http/request-utils.d.ts +3 -0
- package/dist/services/http/request-utils.js +23 -0
- package/dist/services/http/request-utils.js.map +1 -0
- package/dist/services/instances/manager.d.ts +6 -5
- package/dist/services/instances/manager.js +45 -51
- package/dist/services/instances/manager.js.map +1 -1
- package/dist/services/instances/pairing.d.ts +17 -0
- package/dist/services/instances/pairing.js +53 -0
- package/dist/services/instances/pairing.js.map +1 -0
- package/dist/services/instances/status.d.ts +2 -0
- package/dist/services/instances/status.js +11 -0
- package/dist/services/instances/status.js.map +1 -0
- package/dist/services/integrations/hermes/integration.d.ts +1 -1
- package/dist/services/integrations/hermes/integration.js +7 -8
- package/dist/services/integrations/hermes/integration.js.map +1 -1
- package/dist/services/integrations/immich/client.d.ts +93 -0
- package/dist/services/integrations/immich/client.js +458 -0
- package/dist/services/integrations/immich/client.js.map +1 -0
- package/dist/services/integrations/immich/config.d.ts +15 -0
- package/dist/services/integrations/immich/config.js +178 -0
- package/dist/services/integrations/immich/config.js.map +1 -0
- package/dist/services/integrations/immich/discovery.d.ts +9 -0
- package/dist/services/integrations/immich/discovery.js +101 -0
- package/dist/services/integrations/immich/discovery.js.map +1 -0
- package/dist/services/integrations/immich/gallery-renderer.d.ts +5 -0
- package/dist/services/integrations/immich/gallery-renderer.js +150 -0
- package/dist/services/integrations/immich/gallery-renderer.js.map +1 -0
- package/dist/services/integrations/immich/immich-shim.d.ts +11 -0
- package/dist/services/integrations/immich/immich-shim.js +439 -0
- package/dist/services/integrations/immich/immich-shim.js.map +1 -0
- package/dist/services/integrations/immich/integration.d.ts +18 -0
- package/dist/services/integrations/immich/integration.js +64 -0
- package/dist/services/integrations/immich/integration.js.map +1 -0
- package/dist/services/integrations/immich/photo-library.d.ts +4 -0
- package/dist/services/integrations/immich/photo-library.js +63 -0
- package/dist/services/integrations/immich/photo-library.js.map +1 -0
- package/dist/services/integrations/immich/review-executor.d.ts +3 -0
- package/dist/services/integrations/immich/review-executor.js +41 -0
- package/dist/services/integrations/immich/review-executor.js.map +1 -0
- package/dist/services/integrations/immich/review-session-service.d.ts +27 -0
- package/dist/services/integrations/immich/review-session-service.js +206 -0
- package/dist/services/integrations/immich/review-session-service.js.map +1 -0
- package/dist/services/integrations/immich/review-store.d.ts +47 -0
- package/dist/services/integrations/immich/review-store.js +347 -0
- package/dist/services/integrations/immich/review-store.js.map +1 -0
- package/dist/services/integrations/immich/routes.d.ts +7 -0
- package/dist/services/integrations/immich/routes.js +363 -0
- package/dist/services/integrations/immich/routes.js.map +1 -0
- package/dist/services/integrations/immich/types.d.ts +186 -0
- package/dist/services/integrations/immich/types.js +2 -0
- package/dist/services/integrations/immich/types.js.map +1 -0
- package/dist/services/integrations/index.d.ts +1 -0
- package/dist/services/integrations/index.js +1 -0
- package/dist/services/integrations/index.js.map +1 -1
- package/dist/services/integrations/installable/installers/integration.js +113 -7
- package/dist/services/integrations/installable/installers/integration.js.map +1 -1
- package/dist/services/integrations/jishukb/integration.d.ts +3 -1
- package/dist/services/integrations/jishukb/integration.js +121 -10
- package/dist/services/integrations/jishukb/integration.js.map +1 -1
- package/dist/services/integrations/openclaw/integration.d.ts +21 -7
- package/dist/services/integrations/openclaw/integration.js +385 -158
- package/dist/services/integrations/openclaw/integration.js.map +1 -1
- package/dist/services/integrations/openclaw/jishukb-native-mcp.d.ts +58 -0
- package/dist/services/integrations/openclaw/jishukb-native-mcp.js +373 -0
- package/dist/services/integrations/openclaw/jishukb-native-mcp.js.map +1 -0
- package/dist/services/integrations/openclaw/jishukb-shim.d.ts +8 -4
- package/dist/services/integrations/openclaw/jishukb-shim.js +624 -17
- package/dist/services/integrations/openclaw/jishukb-shim.js.map +1 -1
- package/dist/services/integrations/openclaw/mcporter.d.ts +13 -0
- package/dist/services/integrations/openclaw/mcporter.js +31 -0
- package/dist/services/integrations/openclaw/mcporter.js.map +1 -1
- package/dist/services/integrations/openclaw/native-mcp.d.ts +48 -0
- package/dist/services/integrations/openclaw/native-mcp.js +125 -0
- package/dist/services/integrations/openclaw/native-mcp.js.map +1 -0
- package/dist/services/integrations/openclaw/routes.js +4 -1
- package/dist/services/integrations/openclaw/routes.js.map +1 -1
- package/dist/services/integrations/types.d.ts +5 -17
- package/dist/services/repair/runtime-repair.js +68 -1
- package/dist/services/repair/runtime-repair.js.map +1 -1
- package/dist/services/runtime/docker-network.d.ts +8 -0
- package/dist/services/runtime/docker-network.js +123 -0
- package/dist/services/runtime/docker-network.js.map +1 -0
- package/dist/services/runtime/driver-registry.d.ts +4 -0
- package/dist/services/runtime/driver-registry.js.map +1 -1
- package/dist/services/runtime/drivers/nomad.d.ts +1 -0
- package/dist/services/runtime/drivers/nomad.js +35 -5
- package/dist/services/runtime/drivers/nomad.js.map +1 -1
- package/dist/services/runtime/service-manager.d.ts +2 -0
- package/dist/services/runtime/service-manager.js +18 -0
- package/dist/services/runtime/service-manager.js.map +1 -0
- package/dist/services/runtime/types.d.ts +1 -0
- package/dist/services/runtime/workload-compiler.js +29 -4
- package/dist/services/runtime/workload-compiler.js.map +1 -1
- package/dist/services/setup/setup-manager.js +29 -73
- package/dist/services/setup/setup-manager.js.map +1 -1
- package/dist/services/system/runtime-ownership.d.ts +36 -0
- package/dist/services/system/runtime-ownership.js +250 -0
- package/dist/services/system/runtime-ownership.js.map +1 -0
- package/dist/services/system/system-reconciler.js +53 -0
- package/dist/services/system/system-reconciler.js.map +1 -1
- package/dist/types.d.ts +19 -3
- package/dist/utils/path-safety.js +1 -1
- package/dist/utils/service-user.d.ts +13 -0
- package/dist/utils/service-user.js +129 -0
- package/dist/utils/service-user.js.map +1 -0
- package/install/jishu-install.sh +0 -1
- package/node_modules/brace-expansion/dist/commonjs/index.js +24 -14
- package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js +24 -14
- package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
- package/node_modules/brace-expansion/package.json +2 -2
- package/node_modules/fast-uri/index.js +1 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/security.test.js +28 -0
- package/node_modules/fastify/SECURITY.md +1 -1
- package/node_modules/fastify/SPONSORS.md +6 -4
- package/node_modules/fastify/docs/Guides/Database.md +0 -28
- package/node_modules/fastify/docs/Guides/Ecosystem.md +13 -2
- package/node_modules/fastify/docs/Guides/Serverless.md +2 -2
- package/node_modules/fastify/docs/Guides/Write-Plugin.md +1 -1
- package/node_modules/fastify/docs/Reference/Encapsulation.md +27 -26
- package/node_modules/fastify/docs/Reference/Errors.md +10 -4
- package/node_modules/fastify/docs/Reference/HTTP2.md +10 -10
- package/node_modules/fastify/docs/Reference/Hooks.md +4 -4
- package/node_modules/fastify/docs/Reference/Index.md +14 -16
- package/node_modules/fastify/docs/Reference/LTS.md +12 -13
- package/node_modules/fastify/docs/Reference/Lifecycle.md +9 -8
- package/node_modules/fastify/docs/Reference/Logging.md +44 -39
- package/node_modules/fastify/docs/Reference/Middleware.md +21 -25
- package/node_modules/fastify/docs/Reference/Principles.md +2 -2
- package/node_modules/fastify/docs/Reference/Reply.md +6 -1
- package/node_modules/fastify/docs/Reference/Request.md +27 -16
- package/node_modules/fastify/docs/Reference/Routes.md +5 -2
- package/node_modules/fastify/docs/Reference/Server.md +31 -3
- package/node_modules/fastify/docs/Reference/Type-Providers.md +29 -5
- package/node_modules/fastify/docs/Reference/Validation-and-Serialization.md +15 -2
- package/node_modules/fastify/docs/Reference/Warnings.md +7 -6
- package/node_modules/fastify/eslint.config.js +7 -2
- package/node_modules/fastify/fastify.d.ts +8 -3
- package/node_modules/fastify/fastify.js +43 -14
- package/node_modules/fastify/lib/content-type-parser.js +13 -1
- package/node_modules/fastify/lib/decorate.js +11 -3
- package/node_modules/fastify/lib/error-handler.js +4 -3
- package/node_modules/fastify/lib/error-serializer.js +59 -59
- package/node_modules/fastify/lib/errors.js +16 -1
- package/node_modules/fastify/lib/four-oh-four.js +14 -9
- package/node_modules/fastify/lib/handle-request.js +11 -5
- package/node_modules/fastify/lib/plugin-override.js +2 -1
- package/node_modules/fastify/lib/plugin-utils.js +5 -5
- package/node_modules/fastify/lib/reply.js +63 -8
- package/node_modules/fastify/lib/request.js +14 -4
- package/node_modules/fastify/lib/route.js +20 -6
- package/node_modules/fastify/lib/schema-controller.js +1 -1
- package/node_modules/fastify/lib/schemas.js +37 -30
- package/node_modules/fastify/lib/symbols.js +3 -1
- package/node_modules/fastify/lib/validation.js +1 -13
- package/node_modules/fastify/lib/warnings.js +3 -3
- package/node_modules/fastify/package.json +13 -15
- package/node_modules/fastify/scripts/validate-ecosystem-links.js +1 -0
- package/node_modules/fastify/test/bundler/esbuild/package.json +1 -1
- package/node_modules/fastify/test/close-pipelining.test.js +1 -2
- package/node_modules/fastify/test/custom-http-server.test.js +38 -0
- package/node_modules/fastify/test/decorator-instance-properties.test.js +63 -0
- package/node_modules/fastify/test/diagnostics-channel/async-error-handler.test.js +74 -0
- package/node_modules/fastify/test/hooks.test.js +23 -0
- package/node_modules/fastify/test/http-methods/get.test.js +1 -1
- package/node_modules/fastify/test/http2/plain.test.js +135 -0
- package/node_modules/fastify/test/http2/secure-with-fallback.test.js +1 -1
- package/node_modules/fastify/test/https/https.test.js +1 -2
- package/node_modules/fastify/test/internals/errors.test.js +31 -1
- package/node_modules/fastify/test/internals/plugin.test.js +3 -1
- package/node_modules/fastify/test/internals/request.test.js +27 -3
- package/node_modules/fastify/test/internals/schema-controller-perf.test.js +33 -0
- package/node_modules/fastify/test/logger/logging.test.js +18 -1
- package/node_modules/fastify/test/logger/options.test.js +38 -1
- package/node_modules/fastify/test/reply-error.test.js +1 -1
- package/node_modules/fastify/test/reply-trailers.test.js +70 -0
- package/node_modules/fastify/test/request-media-type.test.js +105 -0
- package/node_modules/fastify/test/route-prefix.test.js +34 -0
- package/node_modules/fastify/test/router-options.test.js +222 -11
- package/node_modules/fastify/test/schema-serialization.test.js +108 -0
- package/node_modules/fastify/test/schema-validation.test.js +24 -0
- package/node_modules/fastify/test/scripts/validate-ecosystem-links.test.js +40 -57
- package/node_modules/fastify/test/throw.test.js +14 -0
- package/node_modules/fastify/test/trust-proxy.test.js +21 -0
- package/node_modules/fastify/test/types/content-type-parser.tst.ts +70 -0
- package/node_modules/fastify/test/types/{decorate-request-reply.test-d.ts → decorate-request-reply.tst.ts} +4 -4
- package/node_modules/fastify/test/types/{dummy-plugin.ts → dummy-plugin.mts} +1 -1
- package/node_modules/fastify/test/types/errors.tst.ts +91 -0
- package/node_modules/fastify/test/types/fastify.tst.ts +351 -0
- package/node_modules/fastify/test/types/hooks.tst.ts +578 -0
- package/node_modules/fastify/test/types/instance.tst.ts +597 -0
- package/node_modules/fastify/test/types/{logger.test-d.ts → logger.tst.ts} +61 -62
- package/node_modules/fastify/test/types/plugin.tst.ts +96 -0
- package/node_modules/fastify/test/types/register.tst.ts +245 -0
- package/node_modules/fastify/test/types/reply.tst.ts +297 -0
- package/node_modules/fastify/test/types/request.tst.ts +199 -0
- package/node_modules/fastify/test/types/route.tst.ts +576 -0
- package/node_modules/fastify/test/types/{schema.test-d.ts → schema.tst.ts} +22 -22
- package/node_modules/fastify/test/types/{serverFactory.test-d.ts → serverFactory.tst.ts} +4 -4
- package/node_modules/fastify/test/types/tsconfig.json +9 -0
- package/node_modules/fastify/test/types/{type-provider.test-d.ts → type-provider.tst.ts} +256 -250
- package/node_modules/fastify/test/types/using.tst.ts +14 -0
- package/node_modules/fastify/types/errors.d.ts +3 -0
- package/node_modules/fastify/types/request.d.ts +23 -2
- package/node_modules/jishushell-panel/output/public/assets/{ApiKeyField-NKcbHjNz.js → ApiKeyField-Ce5d1xna.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/{Dashboard-Da1fL38t.js → Dashboard-BXame3yg.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/{HermesChatPanel-DZvmYsoh.js → HermesChatPanel-BHZtPCJd.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/{HermesConfigForm-BLUWlKwm.js → HermesConfigForm-CB3GbNX9.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/{InitPassword-BAKsshzk.js → InitPassword-Boab9F6g.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/InstanceDetail-DrIWCqo-.js +14 -0
- package/node_modules/jishushell-panel/output/public/assets/{Login-DHeOmwI8.js → Login-CzpOkNau.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/NewInstance-CANXyCcL.js +1 -0
- package/node_modules/jishushell-panel/output/public/assets/{ProviderRecommendations-H0ByEYF0.js → ProviderRecommendations-BABo9VOC.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/Settings-CKp5XxFh.js +1 -0
- package/node_modules/jishushell-panel/output/public/assets/Setup-C7xVDPow.js +1 -0
- package/node_modules/jishushell-panel/output/public/assets/{WeixinLoginPanel-D-T6BxkQ.js → WeixinLoginPanel-B765Xz4C.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/{index-ERt6_ngA.js → index-Bs6DSbiR.js} +6 -6
- package/node_modules/jishushell-panel/output/public/assets/{registry-DF93EzIb.js → registry-sWIZsIEF.js} +2 -2
- package/node_modules/jishushell-panel/output/public/assets/{usePolling-DeoThIQn.js → usePolling-D4IDOQd_.js} +1 -1
- package/node_modules/jishushell-panel/output/public/assets/vendor-i18n-Df8aUdv8.js +1 -0
- package/node_modules/jishushell-panel/output/public/assets/{vendor-react-Cc84NArf.js → vendor-react-0L0rjmYG.js} +3 -3
- package/node_modules/jishushell-panel/output/public/index.html +3 -3
- package/node_modules/jishushell-panel/package.json +1 -1
- package/node_modules/semver/classes/range.js +6 -2
- package/node_modules/semver/package.json +1 -1
- package/package.json +4 -4
- package/scripts/check-app-spec.mjs +4 -12
- package/scripts/check-architecture-boundaries.mjs +178 -0
- package/scripts/pack-gui-and-send-pi.sh +5 -3
- package/dependencies/jishushell-panel-0.6.18.tgz +0 -0
- package/dist/services/connections/suggestions.d.ts +0 -27
- package/dist/services/connections/suggestions.js +0 -124
- package/dist/services/connections/suggestions.js.map +0 -1
- package/node_modules/fastify/test/types/content-type-parser.test-d.ts +0 -72
- package/node_modules/fastify/test/types/errors.test-d.ts +0 -90
- package/node_modules/fastify/test/types/fastify.test-d.ts +0 -352
- package/node_modules/fastify/test/types/hooks.test-d.ts +0 -550
- package/node_modules/fastify/test/types/import.ts +0 -2
- package/node_modules/fastify/test/types/instance.test-d.ts +0 -588
- package/node_modules/fastify/test/types/plugin.test-d.ts +0 -97
- package/node_modules/fastify/test/types/register.test-d.ts +0 -237
- package/node_modules/fastify/test/types/reply.test-d.ts +0 -254
- package/node_modules/fastify/test/types/request.test-d.ts +0 -188
- package/node_modules/fastify/test/types/route.test-d.ts +0 -553
- package/node_modules/fastify/test/types/using.test-d.ts +0 -17
- package/node_modules/jishushell-panel/output/public/assets/InstanceDetail-Dgyc_TX5.js +0 -14
- package/node_modules/jishushell-panel/output/public/assets/NewInstance-CIy0cYtp.js +0 -1
- package/node_modules/jishushell-panel/output/public/assets/Settings-DAT-UMfP.js +0 -1
- package/node_modules/jishushell-panel/output/public/assets/Setup-g3uckFYR.js +0 -1
- package/node_modules/jishushell-panel/output/public/assets/vendor-i18n-CS8DFbkQ.js +0 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer'
|
|
2
|
+
import { expect } from 'tstyche'
|
|
3
|
+
import fastify, {
|
|
4
|
+
FastifyContextConfig,
|
|
5
|
+
FastifyReply,
|
|
6
|
+
FastifyRequest,
|
|
7
|
+
FastifySchema,
|
|
8
|
+
FastifyTypeProviderDefault,
|
|
9
|
+
RawRequestDefaultExpression,
|
|
10
|
+
RouteHandler,
|
|
11
|
+
RouteHandlerMethod
|
|
12
|
+
} from '../../fastify.js'
|
|
13
|
+
import { FastifyInstance } from '../../types/instance.js'
|
|
14
|
+
import { FastifyBaseLogger } from '../../types/logger.js'
|
|
15
|
+
import { ResolveReplyTypeWithRouteGeneric } from '../../types/reply.js'
|
|
16
|
+
import { FastifyRouteConfig, RouteGenericInterface } from '../../types/route.js'
|
|
17
|
+
import { ContextConfigDefault, RawReplyDefaultExpression, RawServerDefault } from '../../types/utils.js'
|
|
18
|
+
|
|
19
|
+
type DefaultSerializationFunction = (payload: { [key: string]: unknown }) => string
|
|
20
|
+
type DefaultFastifyReplyWithCode<Code extends number> = FastifyReply<RouteGenericInterface, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault, FastifySchema, FastifyTypeProviderDefault, ResolveReplyTypeWithRouteGeneric<RouteGenericInterface['Reply'], Code, FastifySchema, FastifyTypeProviderDefault>>
|
|
21
|
+
|
|
22
|
+
const getHandler: RouteHandlerMethod = function (_request, reply) {
|
|
23
|
+
expect(reply.raw).type.toBe<RawReplyDefaultExpression>()
|
|
24
|
+
expect(reply.log).type.toBe<FastifyBaseLogger>()
|
|
25
|
+
expect(reply.request).type.toBe<
|
|
26
|
+
FastifyRequest<RouteGenericInterface, RawServerDefault, RawRequestDefaultExpression>
|
|
27
|
+
>()
|
|
28
|
+
expect(reply.code).type.toBe<<Code extends number>(statusCode: Code) => DefaultFastifyReplyWithCode<Code>>()
|
|
29
|
+
expect(reply.status).type.toBe<<Code extends number>(statusCode: Code) => DefaultFastifyReplyWithCode<Code>>()
|
|
30
|
+
expect(reply.code(100 as number).send).type.toBe<(...args: [payload?: unknown]) => FastifyReply>()
|
|
31
|
+
expect(reply.elapsedTime).type.toBe<number>()
|
|
32
|
+
expect(reply.statusCode).type.toBe<number>()
|
|
33
|
+
expect(reply.sent).type.toBe<boolean>()
|
|
34
|
+
expect(reply.writeEarlyHints).type.toBe<
|
|
35
|
+
(hints: Record<string, string | string[]>, callback?: (() => void) | undefined) => void
|
|
36
|
+
>()
|
|
37
|
+
expect(reply.send).type.toBe<((...args: [payload?: unknown]) => FastifyReply)>()
|
|
38
|
+
expect(reply.header).type.toBeAssignableTo<(key: string, value: any) => FastifyReply>()
|
|
39
|
+
expect(reply.headers).type.toBeAssignableTo<(values: { [key: string]: any }) => FastifyReply>()
|
|
40
|
+
expect(reply.getHeader).type.toBeAssignableTo<(key: string) => number | string | string[] | undefined>()
|
|
41
|
+
expect(reply.getHeaders).type.toBeAssignableTo<() => { [key: string]: number | string | string[] | undefined }>()
|
|
42
|
+
expect(reply.removeHeader).type.toBeAssignableTo<(key: string) => FastifyReply>()
|
|
43
|
+
expect(reply.hasHeader).type.toBeAssignableTo<(key: string) => boolean>()
|
|
44
|
+
expect(reply.redirect).type.toBe<(url: string, statusCode?: number) => FastifyReply>()
|
|
45
|
+
expect(reply.hijack).type.toBe<() => FastifyReply>()
|
|
46
|
+
expect(reply.callNotFound).type.toBe<() => void>()
|
|
47
|
+
expect(reply.type).type.toBe<(contentType: string) => FastifyReply>()
|
|
48
|
+
expect(reply.serializer).type.toBe<(fn: (payload: any) => string) => FastifyReply>()
|
|
49
|
+
expect(reply.serialize).type.toBe<(payload: any) => string | ArrayBuffer | Buffer>()
|
|
50
|
+
expect(reply.then).type.toBe<(fulfilled: () => void, rejected: (err: Error) => void) => void>()
|
|
51
|
+
expect(reply.trailer).type.toBe<
|
|
52
|
+
(
|
|
53
|
+
key: string,
|
|
54
|
+
fn: ((reply: FastifyReply, payload: string | Buffer | null) => Promise<string>) |
|
|
55
|
+
((reply: FastifyReply, payload: string | Buffer | null,
|
|
56
|
+
done: (err: Error | null, value?: string) => void) => void)
|
|
57
|
+
) => FastifyReply
|
|
58
|
+
>()
|
|
59
|
+
expect(reply.hasTrailer).type.toBe<(key: string) => boolean>()
|
|
60
|
+
expect(reply.removeTrailer).type.toBe<(key: string) => FastifyReply>()
|
|
61
|
+
expect(reply.server).type.toBe<FastifyInstance>()
|
|
62
|
+
expect(reply.getSerializationFunction).type.toBeAssignableTo<
|
|
63
|
+
((httpStatus: string) => DefaultSerializationFunction | undefined)
|
|
64
|
+
>()
|
|
65
|
+
expect(reply.getSerializationFunction).type.toBeAssignableTo<
|
|
66
|
+
((schema: { [key: string]: unknown }) => DefaultSerializationFunction | undefined)
|
|
67
|
+
>()
|
|
68
|
+
expect(reply.compileSerializationSchema).type.toBeAssignableTo<
|
|
69
|
+
((schema: { [key: string]: unknown }, httpStatus?: string) => DefaultSerializationFunction)
|
|
70
|
+
>()
|
|
71
|
+
expect(reply.serializeInput).type.toBeAssignableTo<
|
|
72
|
+
((input: { [key: string]: unknown }, schema: { [key: string]: unknown }, httpStatus?: string) => unknown)
|
|
73
|
+
>()
|
|
74
|
+
expect(reply.serializeInput).type.toBeAssignableTo<
|
|
75
|
+
((input: { [key: string]: unknown }, httpStatus: string) => unknown)
|
|
76
|
+
>()
|
|
77
|
+
expect(reply.routeOptions.config).type.toBe<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>()
|
|
78
|
+
expect(reply.getDecorator<string>('foo')).type.toBe<string>()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface ReplyPayload {
|
|
82
|
+
Reply: {
|
|
83
|
+
test: boolean;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface ReplyArrayPayload {
|
|
88
|
+
Reply: string[]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface ReplyUnion {
|
|
92
|
+
Reply: {
|
|
93
|
+
success: boolean;
|
|
94
|
+
} | {
|
|
95
|
+
error: string;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface ReplyHttpCodes {
|
|
100
|
+
Reply: {
|
|
101
|
+
'1xx': number,
|
|
102
|
+
200: 'abc',
|
|
103
|
+
201: boolean,
|
|
104
|
+
300: { foo: string },
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface InvalidReplyHttpCodes {
|
|
109
|
+
Reply: {
|
|
110
|
+
'1xx': number,
|
|
111
|
+
200: string,
|
|
112
|
+
999: boolean,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface ReplyVoid {
|
|
117
|
+
Reply: void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface ReplyUndefined {
|
|
121
|
+
Reply: undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Issue #5534 scenario: 204 No Content should allow empty send(), 201 Created should require payload
|
|
125
|
+
// Note: `204: undefined` gets converted to `unknown` via UndefinedToUnknown in type-provider.d.ts,
|
|
126
|
+
// meaning send() is optional but send({}) is also allowed. Use `void` instead of `undefined`
|
|
127
|
+
// if you want stricter "no payload allowed" semantics.
|
|
128
|
+
interface ReplyHttpCodesWithNoContent {
|
|
129
|
+
Reply: {
|
|
130
|
+
201: { id: string };
|
|
131
|
+
204: undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const typedHandler: RouteHandler<ReplyPayload> = async (request, reply) => {
|
|
136
|
+
// When Reply type is specified, send() requires a payload argument
|
|
137
|
+
expect(reply.send).type.toBe<((...args: [payload: ReplyPayload['Reply']]) => FastifyReply<ReplyPayload, RawServerDefault, RawRequestDefaultExpression<RawServerDefault>, RawReplyDefaultExpression<RawServerDefault>>)>()
|
|
138
|
+
expect(reply.code(100).send).type.toBe<((...args: [payload: ReplyPayload['Reply']]) => FastifyReply<ReplyPayload, RawServerDefault, RawRequestDefaultExpression<RawServerDefault>, RawReplyDefaultExpression<RawServerDefault>>)>()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const server = fastify()
|
|
142
|
+
server.get('/get', getHandler)
|
|
143
|
+
server.get('/typed', typedHandler)
|
|
144
|
+
server.get<ReplyPayload>('/get-generic-send', async function handler (request, reply) {
|
|
145
|
+
reply.send({ test: true })
|
|
146
|
+
})
|
|
147
|
+
// When Reply type is specified, send() requires a payload - calling without arguments should error
|
|
148
|
+
server.get<ReplyPayload>('/get-generic-send-missing-payload', async function handler (request, reply) {
|
|
149
|
+
reply
|
|
150
|
+
// @ts-expect-error Expected 1 arguments, but got 0.
|
|
151
|
+
.send()
|
|
152
|
+
})
|
|
153
|
+
server.get<ReplyPayload>('/get-generic-return', async function handler (request, reply) {
|
|
154
|
+
return { test: false }
|
|
155
|
+
})
|
|
156
|
+
server.get<ReplyPayload>('/get-generic-send-error', async function handler (request, reply) {
|
|
157
|
+
reply.send({
|
|
158
|
+
// @ts-expect-error 'foo' does not exist in type '{ test: boolean; }'.
|
|
159
|
+
foo: 'bar'
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
// @ts-expect-error No overload matches this call.
|
|
163
|
+
server.get<ReplyPayload>('/get-generic-return-error', async function handler (request, reply) {
|
|
164
|
+
return { foo: 'bar' }
|
|
165
|
+
})
|
|
166
|
+
server.get<ReplyUnion>('/get-generic-union-send', async function handler (request, reply) {
|
|
167
|
+
if (0 as number === 0) {
|
|
168
|
+
reply.send({ success: true })
|
|
169
|
+
} else {
|
|
170
|
+
reply.send({ error: 'error' })
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
server.get<ReplyUnion>('/get-generic-union-return', async function handler (request, reply) {
|
|
174
|
+
if (0 as number === 0) {
|
|
175
|
+
return { success: true }
|
|
176
|
+
} else {
|
|
177
|
+
return { error: 'error' }
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
server.get<ReplyUnion>('/get-generic-union-send-error-1', async function handler (request, reply) {
|
|
181
|
+
reply.send({
|
|
182
|
+
// @ts-expect-error 'successes' does not exist in type '{ success: boolean; } | { error: string; }'.
|
|
183
|
+
successes: true
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
server.get<ReplyUnion>('/get-generic-union-send-error-2', async function handler (request, reply) {
|
|
187
|
+
reply.send({
|
|
188
|
+
// @ts-expect-error Type 'number' is not assignable to type 'string'.
|
|
189
|
+
error: 500
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
// @ts-expect-error No overload matches this call.
|
|
193
|
+
server.get<ReplyUnion>('/get-generic-union-return-error-1', async function handler (request, reply) {
|
|
194
|
+
return { successes: true }
|
|
195
|
+
})
|
|
196
|
+
// @ts-expect-error No overload matches this call.
|
|
197
|
+
server.get<ReplyUnion>('/get-generic-union-return-error-2', async function handler (request, reply) {
|
|
198
|
+
return { error: 500 }
|
|
199
|
+
})
|
|
200
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send', async function handler (request, reply) {
|
|
201
|
+
reply.code(200).send('abc')
|
|
202
|
+
reply.code(201).send(true)
|
|
203
|
+
reply.code(300).send({ foo: 'bar' })
|
|
204
|
+
reply.code(101).send(123)
|
|
205
|
+
})
|
|
206
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send-error-1', async function handler (request, reply) {
|
|
207
|
+
reply.code(200)
|
|
208
|
+
// @ts-expect-error Argument of type '"def"' is not assignable to parameter of type '"abc"'.
|
|
209
|
+
.send('def')
|
|
210
|
+
})
|
|
211
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send-error-2', async function handler (request, reply) {
|
|
212
|
+
reply.code(201)
|
|
213
|
+
// @ts-expect-error Argument of type 'number' is not assignable to parameter of type 'boolean'.
|
|
214
|
+
.send(0)
|
|
215
|
+
})
|
|
216
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send-error-3', async function handler (request, reply) {
|
|
217
|
+
reply.code(300).send({
|
|
218
|
+
// @ts-expect-error Type 'number' is not assignable to type 'string'.
|
|
219
|
+
foo: 123
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send-error-4', async function handler (request, reply) {
|
|
223
|
+
reply.code(100)
|
|
224
|
+
// @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'number'.
|
|
225
|
+
.send('asdasd')
|
|
226
|
+
})
|
|
227
|
+
server.get<ReplyHttpCodes>('/get-generic-http-codes-send-error-5', async function handler (request, reply) {
|
|
228
|
+
reply
|
|
229
|
+
// @ts-expect-error Argument of type '401' is not assignable to parameter of type '100 | 101 | 102 | ... | 300'.
|
|
230
|
+
.code(401).send({
|
|
231
|
+
// @ts-expect-error Type 'number' is not assignable to type 'string'.
|
|
232
|
+
foo: 123
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
server.get<ReplyArrayPayload>('/get-generic-array-send', async function handler (request, reply) {
|
|
236
|
+
reply.code(200).send([''])
|
|
237
|
+
})
|
|
238
|
+
server.get<InvalidReplyHttpCodes>('get-invalid-http-codes-reply-error', async function handler (request, reply) {
|
|
239
|
+
reply.code(200)
|
|
240
|
+
// @ts-expect-error Argument of type 'string' is not assignable to parameter of type '{ '1xx': number; 200: string; 999: boolean; }'.
|
|
241
|
+
.send('')
|
|
242
|
+
})
|
|
243
|
+
server.get<InvalidReplyHttpCodes>('get-invalid-http-codes-reply-error', async function handler (request, reply) {
|
|
244
|
+
reply.code(200).send({
|
|
245
|
+
'1xx': 0,
|
|
246
|
+
200: '',
|
|
247
|
+
999: false
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
const httpHeaderHandler: RouteHandlerMethod = function (_request, reply) {
|
|
252
|
+
// accept is a header provided by @types/node
|
|
253
|
+
reply.getHeader('accept')
|
|
254
|
+
expect(reply.getHeaders()).type.toHaveProperty('accept')
|
|
255
|
+
reply.hasHeader('accept')
|
|
256
|
+
reply.header('accept', 'test')
|
|
257
|
+
reply.headers({ accept: 'test' })
|
|
258
|
+
reply.removeHeader('accept')
|
|
259
|
+
|
|
260
|
+
// x-fastify-test is not a header provided by @types/node
|
|
261
|
+
// and should not result in a typing error
|
|
262
|
+
reply.getHeader('x-fastify-test')
|
|
263
|
+
expect(reply.getHeaders()).type.toHaveProperty('x-fastify-test')
|
|
264
|
+
reply.hasHeader('x-fastify-test')
|
|
265
|
+
reply.header('x-fastify-test', 'test')
|
|
266
|
+
reply.headers({ 'x-fastify-test': 'test' })
|
|
267
|
+
reply.removeHeader('x-fastify-test')
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Test: send() without arguments is valid when no Reply type is specified (default unknown)
|
|
271
|
+
server.get('/get-no-type-send-empty', async function handler (request, reply) {
|
|
272
|
+
reply.send()
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
// Test: send() without arguments is valid when Reply type is void
|
|
276
|
+
server.get<ReplyVoid>('/get-void-send-empty', async function handler (request, reply) {
|
|
277
|
+
reply.send()
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
// Test: send() without arguments is valid when Reply type is undefined
|
|
281
|
+
server.get<ReplyUndefined>('/get-undefined-send-empty', async function handler (request, reply) {
|
|
282
|
+
reply.send()
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
// Issue #5534 scenario: HTTP status codes with 204 No Content
|
|
286
|
+
server.get<ReplyHttpCodesWithNoContent>('/get-http-codes-no-content', async function handler (request, reply) {
|
|
287
|
+
// 204 No Content - send() without payload is valid because Reply is undefined
|
|
288
|
+
reply.code(204).send()
|
|
289
|
+
// 201 Created - send() requires payload
|
|
290
|
+
reply.code(201).send({ id: '123' })
|
|
291
|
+
})
|
|
292
|
+
// 201 Created without payload should error
|
|
293
|
+
server.get<ReplyHttpCodesWithNoContent>('/get-http-codes-201-missing-payload', async function handler (request, reply) {
|
|
294
|
+
reply.code(201)
|
|
295
|
+
// @ts-expect-error Expected 1 arguments, but got 0.
|
|
296
|
+
.send()
|
|
297
|
+
})
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { expect } from 'tstyche'
|
|
2
|
+
import fastify, {
|
|
3
|
+
ContextConfigDefault,
|
|
4
|
+
FastifyContextConfig,
|
|
5
|
+
FastifyLogFn,
|
|
6
|
+
FastifySchema,
|
|
7
|
+
FastifyTypeProviderDefault,
|
|
8
|
+
RawReplyDefaultExpression,
|
|
9
|
+
RawRequestDefaultExpression,
|
|
10
|
+
RawServerDefault,
|
|
11
|
+
RequestBodyDefault,
|
|
12
|
+
RequestGenericInterface,
|
|
13
|
+
RouteHandler,
|
|
14
|
+
RouteHandlerMethod,
|
|
15
|
+
SafePromiseLike
|
|
16
|
+
} from '../../fastify.js'
|
|
17
|
+
import { FastifyInstance } from '../../types/instance.js'
|
|
18
|
+
import { FastifyBaseLogger } from '../../types/logger.js'
|
|
19
|
+
import { FastifyReply } from '../../types/reply.js'
|
|
20
|
+
import { FastifyRequest, RequestRouteOptions, ValidationFunction } from '../../types/request.js'
|
|
21
|
+
import { FastifyRouteConfig, RouteGenericInterface } from '../../types/route.js'
|
|
22
|
+
import { RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from '../../types/utils.js'
|
|
23
|
+
|
|
24
|
+
interface RequestBody {
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface RequestQuerystring {
|
|
29
|
+
from: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface RequestParams {
|
|
33
|
+
id: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface RequestHeaders {
|
|
37
|
+
'x-foobar': string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface RequestData extends RequestGenericInterface {
|
|
41
|
+
Body: RequestBody;
|
|
42
|
+
Querystring: RequestQuerystring;
|
|
43
|
+
Params: RequestParams;
|
|
44
|
+
Headers: RequestHeaders;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Handler = RouteHandler<RequestData>
|
|
48
|
+
|
|
49
|
+
type CustomRequest = FastifyRequest<{
|
|
50
|
+
Body: RequestBody | undefined;
|
|
51
|
+
Querystring: RequestQuerystring;
|
|
52
|
+
Params: RequestParams;
|
|
53
|
+
Headers: RequestHeaders;
|
|
54
|
+
}>
|
|
55
|
+
|
|
56
|
+
type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'
|
|
57
|
+
type ExpectedGetValidationFunction = (input: { [key: string]: unknown }) => boolean
|
|
58
|
+
|
|
59
|
+
interface CustomLoggerInterface extends FastifyBaseLogger {
|
|
60
|
+
foo: FastifyLogFn; // custom severity logger method
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const getHandler: RouteHandler = function (request, _reply) {
|
|
64
|
+
expect(request.url).type.toBe<string>()
|
|
65
|
+
expect(request.originalUrl).type.toBe<string>()
|
|
66
|
+
expect(request.method).type.toBe<string>()
|
|
67
|
+
expect(request.routeOptions).type.toBe<Readonly<RequestRouteOptions>>()
|
|
68
|
+
expect(request.is404).type.toBe<boolean>()
|
|
69
|
+
expect(request.hostname).type.toBe<string>()
|
|
70
|
+
expect(request.host).type.toBe<string>()
|
|
71
|
+
expect(request.port).type.toBe<number | null>()
|
|
72
|
+
expect(request.ip).type.toBe<string>()
|
|
73
|
+
expect(request.ips).type.toBe<string[] | undefined>()
|
|
74
|
+
expect(request.raw).type.toBe<RawRequestDefaultExpression>()
|
|
75
|
+
expect(request.body).type.toBe<RequestBodyDefault>()
|
|
76
|
+
expect(request.params).type.toBe<RequestParamsDefault>()
|
|
77
|
+
expect(request.routeOptions.config).type.toBe<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>()
|
|
78
|
+
expect(request.routeOptions.schema).type.toBe<FastifySchema | undefined>()
|
|
79
|
+
expect(request.routeOptions.handler).type.toBe<RouteHandlerMethod>()
|
|
80
|
+
expect(request.routeOptions.url).type.toBe<string | undefined>()
|
|
81
|
+
expect(request.routeOptions.version).type.toBe<string | undefined>()
|
|
82
|
+
|
|
83
|
+
expect(request.headers).type.toBe<RequestHeadersDefault & RawRequestDefaultExpression['headers']>()
|
|
84
|
+
request.headers = {}
|
|
85
|
+
|
|
86
|
+
expect(request.query).type.toBe<RequestQuerystringDefault>()
|
|
87
|
+
expect(request.id).type.toBe<string>()
|
|
88
|
+
expect(request.log).type.toBe<FastifyBaseLogger>()
|
|
89
|
+
expect(request.socket).type.toBe<RawRequestDefaultExpression['socket']>()
|
|
90
|
+
expect(request.signal).type.toBe<AbortSignal>()
|
|
91
|
+
expect(request.validationError).type.toBe<Error & { validation: any; validationContext: string } | undefined>()
|
|
92
|
+
expect(request.server).type.toBe<FastifyInstance>()
|
|
93
|
+
expect(request.getValidationFunction).type.toBeAssignableTo<
|
|
94
|
+
(httpPart: HTTPRequestPart) => ExpectedGetValidationFunction | undefined
|
|
95
|
+
>()
|
|
96
|
+
expect(request.getValidationFunction).type.toBeAssignableTo<
|
|
97
|
+
(schema: { [key: string]: unknown }) => ExpectedGetValidationFunction | undefined
|
|
98
|
+
>()
|
|
99
|
+
expect(request.getValidationFunction('body')).type.toBe<ValidationFunction | undefined>()
|
|
100
|
+
expect(request.getValidationFunction({ type: 'object' })).type.toBe<ValidationFunction | undefined>()
|
|
101
|
+
expect(request.validateInput).type.toBeAssignableTo<
|
|
102
|
+
(input: { [key: string]: unknown }, schema: { [key: string]: unknown }, httpPart?: HTTPRequestPart) => boolean
|
|
103
|
+
>()
|
|
104
|
+
expect(request.validateInput).type.toBeAssignableTo<
|
|
105
|
+
(input: { [key: string]: unknown }, httpPart?: HTTPRequestPart) => boolean
|
|
106
|
+
>()
|
|
107
|
+
expect(request.getDecorator<string>('foo')).type.toBe<string>()
|
|
108
|
+
expect(request.setDecorator('foo', 'hello')).type.toBe<void>()
|
|
109
|
+
expect(request.setDecorator<string>('foo', 'hello')).type.toBe<void>()
|
|
110
|
+
expect(request.setDecorator<string>).type.not.toBeCallableWith('foo', true)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const getHandlerWithCustomLogger: RouteHandlerMethod<
|
|
114
|
+
RawServerDefault,
|
|
115
|
+
RawRequestDefaultExpression,
|
|
116
|
+
RawReplyDefaultExpression,
|
|
117
|
+
RouteGenericInterface,
|
|
118
|
+
ContextConfigDefault,
|
|
119
|
+
FastifySchema,
|
|
120
|
+
FastifyTypeProviderDefault,
|
|
121
|
+
CustomLoggerInterface
|
|
122
|
+
> = function (request, _reply) {
|
|
123
|
+
expect(request.log).type.toBe<CustomLoggerInterface>()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const postHandler: Handler = function (request) {
|
|
127
|
+
expect(request.body).type.toBe<RequestBody>()
|
|
128
|
+
expect(request.params).type.toBe<RequestParams>()
|
|
129
|
+
expect(
|
|
130
|
+
request.headers
|
|
131
|
+
).type.toBe<RequestHeaders & RawRequestDefaultExpression['headers']>()
|
|
132
|
+
expect(request.query).type.toBe<RequestQuerystring>()
|
|
133
|
+
expect(request.body.content).type.toBe<string>()
|
|
134
|
+
expect(request.query.from).type.toBe<string>()
|
|
135
|
+
expect(request.params.id).type.toBe<number>()
|
|
136
|
+
expect(request.headers['x-foobar']).type.toBe<string>()
|
|
137
|
+
expect(request.server).type.toBe<FastifyInstance>()
|
|
138
|
+
expect(request.routeOptions.config).type.toBe<FastifyContextConfig & FastifyRouteConfig>()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function putHandler (request: CustomRequest, reply: FastifyReply) {
|
|
142
|
+
expect(request.body).type.toBe<RequestBody | undefined>()
|
|
143
|
+
expect(request.params).type.toBe<RequestParams>()
|
|
144
|
+
expect(request.headers).type.toBe<RequestHeaders & RawRequestDefaultExpression['headers']>()
|
|
145
|
+
expect(request.query).type.toBe<RequestQuerystring>()
|
|
146
|
+
if (request.body === undefined) {
|
|
147
|
+
expect(request.body).type.toBe<undefined>()
|
|
148
|
+
} else {
|
|
149
|
+
expect(request.body.content).type.toBe<string>()
|
|
150
|
+
}
|
|
151
|
+
expect(request.query.from).type.toBe<string>()
|
|
152
|
+
expect(request.params.id).type.toBe<number>()
|
|
153
|
+
expect(request.headers['x-foobar']).type.toBe<string>()
|
|
154
|
+
expect(request.server).type.toBe<FastifyInstance>()
|
|
155
|
+
expect(request.routeOptions.config).type.toBe<ContextConfigDefault & FastifyRouteConfig & FastifyContextConfig>()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const server = fastify()
|
|
159
|
+
server.get('/get', getHandler)
|
|
160
|
+
server.post('/post', postHandler)
|
|
161
|
+
server.put('/put', putHandler)
|
|
162
|
+
|
|
163
|
+
const customLogger: CustomLoggerInterface = {
|
|
164
|
+
level: 'info',
|
|
165
|
+
silent: () => { },
|
|
166
|
+
info: () => { },
|
|
167
|
+
warn: () => { },
|
|
168
|
+
error: () => { },
|
|
169
|
+
fatal: () => { },
|
|
170
|
+
trace: () => { },
|
|
171
|
+
debug: () => { },
|
|
172
|
+
foo: () => { }, // custom severity logger method
|
|
173
|
+
child: () => customLogger
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const serverWithCustomLogger = fastify({ loggerInstance: customLogger })
|
|
177
|
+
|
|
178
|
+
expect(serverWithCustomLogger).type.not.toBeAssignableTo<
|
|
179
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
180
|
+
& Promise<
|
|
181
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
182
|
+
>
|
|
183
|
+
>()
|
|
184
|
+
|
|
185
|
+
expect(serverWithCustomLogger).type.toBeAssignableTo<
|
|
186
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
187
|
+
& PromiseLike<
|
|
188
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
189
|
+
>
|
|
190
|
+
>()
|
|
191
|
+
|
|
192
|
+
expect(serverWithCustomLogger).type.toBe<
|
|
193
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
194
|
+
& SafePromiseLike<
|
|
195
|
+
FastifyInstance<RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, CustomLoggerInterface>
|
|
196
|
+
>
|
|
197
|
+
>()
|
|
198
|
+
|
|
199
|
+
serverWithCustomLogger.get('/get', getHandlerWithCustomLogger)
|