@warlock.js/core 5.30.0 → 5.31.0
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 +142 -36
- package/README.md +28 -23
- package/bin/source-load-hook.mjs +63 -0
- package/bin/warlock.js +102 -42
- package/esm/cli/commands/add.command.mjs +4 -2
- package/esm/cli/commands/add.command.mjs.map +1 -1
- package/esm/cli/commands/agents-md/agents-md-command.action.mjs +69 -0
- package/esm/cli/commands/agents-md/agents-md-command.action.mjs.map +1 -0
- package/esm/cli/commands/agents-md.command.mjs +38 -0
- package/esm/cli/commands/agents-md.command.mjs.map +1 -0
- package/esm/cli/commands/board/board-command.action.mjs +279 -0
- package/esm/cli/commands/board/board-command.action.mjs.map +1 -0
- package/esm/cli/commands/board.command.mjs +78 -0
- package/esm/cli/commands/board.command.mjs.map +1 -0
- package/esm/cli/commands/build.command.mjs +6 -1
- package/esm/cli/commands/build.command.mjs.map +1 -1
- package/esm/cli/commands/check/check-command.action.mjs +57 -0
- package/esm/cli/commands/check/check-command.action.mjs.map +1 -0
- package/esm/cli/commands/check/child-typecheck.mjs +66 -0
- package/esm/cli/commands/check/child-typecheck.mjs.map +1 -0
- package/esm/cli/commands/check/format-problems.mjs +43 -0
- package/esm/cli/commands/check/format-problems.mjs.map +1 -0
- package/esm/cli/commands/check/typecheck-command.action.mjs +61 -0
- package/esm/cli/commands/check/typecheck-command.action.mjs.map +1 -0
- package/esm/cli/commands/check.command.mjs +50 -0
- package/esm/cli/commands/check.command.mjs.map +1 -0
- package/esm/cli/commands/dev-server.command.mjs +9 -1
- package/esm/cli/commands/dev-server.command.mjs.map +1 -1
- package/esm/cli/commands/doctor/boot-for-diagnostics.mjs +8 -3
- package/esm/cli/commands/doctor/boot-for-diagnostics.mjs.map +1 -1
- package/esm/cli/commands/doctor/check.types.d.mts +76 -0
- package/esm/cli/commands/doctor/check.types.d.mts.map +1 -0
- package/esm/cli/commands/doctor/checks/config.check.mjs +1 -0
- package/esm/cli/commands/doctor/checks/config.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/connectors.check.mjs +2 -0
- package/esm/cli/commands/doctor/checks/connectors.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/handler-signature.check.mjs +1 -0
- package/esm/cli/commands/doctor/checks/handler-signature.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/health.check.mjs +3 -0
- package/esm/cli/commands/doctor/checks/health.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/jwt-secret.check.mjs +1 -0
- package/esm/cli/commands/doctor/checks/jwt-secret.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/locales-ts-deprecated.check.mjs +1 -0
- package/esm/cli/commands/doctor/checks/locales-ts-deprecated.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/optional-peers.check.mjs +1 -0
- package/esm/cli/commands/doctor/checks/optional-peers.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/release-hygiene.check.mjs +4 -0
- package/esm/cli/commands/doctor/checks/release-hygiene.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/checks/routes.check.mjs +3 -0
- package/esm/cli/commands/doctor/checks/routes.check.mjs.map +1 -1
- package/esm/cli/commands/doctor/doctor-command.action.mjs +14 -6
- package/esm/cli/commands/doctor/doctor-command.action.mjs.map +1 -1
- package/esm/cli/commands/doctor/format-report.mjs +30 -2
- package/esm/cli/commands/doctor/format-report.mjs.map +1 -1
- package/esm/cli/commands/doctor.command.mjs +4 -0
- package/esm/cli/commands/doctor.command.mjs.map +1 -1
- package/esm/cli/commands/explain/explain-command.action.mjs +64 -0
- package/esm/cli/commands/explain/explain-command.action.mjs.map +1 -0
- package/esm/cli/commands/explain.command.mjs +23 -0
- package/esm/cli/commands/explain.command.mjs.map +1 -0
- package/esm/cli/commands/generate/generate.command.mjs +124 -124
- package/esm/cli/commands/generate/generate.command.mjs.map +1 -1
- package/esm/cli/commands/generate/generators/endpoint.generator.mjs +311 -0
- package/esm/cli/commands/generate/generators/endpoint.generator.mjs.map +1 -0
- package/esm/cli/commands/generate/generators/migration.generator.mjs +1 -1
- package/esm/cli/commands/generate/generators/migration.generator.mjs.map +1 -1
- package/esm/cli/commands/generate/generators/model.generator.mjs +1 -1
- package/esm/cli/commands/generate/templates/endpoint-stubs.mjs +341 -0
- package/esm/cli/commands/generate/templates/endpoint-stubs.mjs.map +1 -0
- package/esm/cli/commands/generate/templates/stubs.mjs +19 -6
- package/esm/cli/commands/generate/templates/stubs.mjs.map +1 -1
- package/esm/cli/commands/generate/utils/endpoint-schema.mjs +137 -0
- package/esm/cli/commands/generate/utils/endpoint-schema.mjs.map +1 -0
- package/esm/cli/commands/generate/utils/name-parser.mjs +1 -1
- package/esm/cli/commands/generate/utils/name-parser.mjs.map +1 -1
- package/esm/cli/commands/generate/utils/prompt.mjs.map +1 -1
- package/esm/cli/commands/generate/utils/writer.mjs +38 -13
- package/esm/cli/commands/generate/utils/writer.mjs.map +1 -1
- package/esm/cli/commands/inspect/inspect-command.action.mjs +72 -0
- package/esm/cli/commands/inspect/inspect-command.action.mjs.map +1 -0
- package/esm/cli/commands/inspect.command.mjs +39 -0
- package/esm/cli/commands/inspect.command.mjs.map +1 -0
- package/esm/cli/commands/mcp/mcp-command.action.mjs +103 -0
- package/esm/cli/commands/mcp/mcp-command.action.mjs.map +1 -0
- package/esm/cli/commands/mcp.command.mjs +76 -0
- package/esm/cli/commands/mcp.command.mjs.map +1 -0
- package/esm/cli/commands/openapi-generator.action.mjs.map +1 -1
- package/esm/cli/commands/openapi-generator.command.mjs.map +1 -1
- package/esm/cli/commands/postman-generator.action.mjs.map +1 -1
- package/esm/cli/commands/postman-generator.command.mjs.map +1 -1
- package/esm/cli/commands/routes/routes-diff.action.mjs +1 -1
- package/esm/cli/commands/test.command.mjs +131 -0
- package/esm/cli/commands/test.command.mjs.map +1 -0
- package/esm/cli/commands/trace/trace-command.action.mjs +145 -0
- package/esm/cli/commands/trace/trace-command.action.mjs.map +1 -0
- package/esm/cli/commands/trace.command.mjs +60 -0
- package/esm/cli/commands/trace.command.mjs.map +1 -0
- package/esm/cli/commands/typecheck.command.mjs +40 -0
- package/esm/cli/commands/typecheck.command.mjs.map +1 -0
- package/esm/cli/commands/upgrade.command.mjs +46 -0
- package/esm/cli/commands/upgrade.command.mjs.map +1 -0
- package/esm/cli/flush-and-exit.mjs +34 -0
- package/esm/cli/flush-and-exit.mjs.map +1 -0
- package/esm/cli/framework-cli-commands.mjs +23 -1
- package/esm/cli/framework-cli-commands.mjs.map +1 -1
- package/esm/cli/parse-cli-args.mjs +1 -0
- package/esm/cli/parse-cli-args.mjs.map +1 -1
- package/esm/config/config-loader.d.mts.map +1 -1
- package/esm/config/config-loader.mjs +34 -13
- package/esm/config/config-loader.mjs.map +1 -1
- package/esm/config/config-schema.d.mts +67 -0
- package/esm/config/config-schema.d.mts.map +1 -0
- package/esm/config/config-schema.mjs +77 -0
- package/esm/config/config-schema.mjs.map +1 -0
- package/esm/config/index.d.mts +6 -0
- package/esm/config/index.mjs +1 -0
- package/esm/connectors/assert-no-reserved-connector-names.d.mts.map +1 -1
- package/esm/connectors/assert-no-reserved-connector-names.mjs +2 -1
- package/esm/connectors/assert-no-reserved-connector-names.mjs.map +1 -1
- package/esm/connectors/assert-unique-connector-names.d.mts.map +1 -1
- package/esm/connectors/assert-unique-connector-names.mjs +26 -2
- package/esm/connectors/assert-unique-connector-names.mjs.map +1 -1
- package/esm/connectors/http-connector.d.mts.map +1 -1
- package/esm/connectors/http-connector.mjs +3 -2
- package/esm/connectors/http-connector.mjs.map +1 -1
- package/esm/connectors/single-server-warnings.mjs.map +1 -1
- package/esm/connectors/socket-connector.d.mts.map +1 -1
- package/esm/connectors/socket-connector.mjs.map +1 -1
- package/esm/container/index.d.mts.map +1 -1
- package/esm/container/index.mjs.map +1 -1
- package/esm/database/migrate-action.mjs.map +1 -1
- package/esm/database/models/database-log/database-log.d.mts +0 -28
- package/esm/database/models/database-log/database-log.d.mts.map +1 -1
- package/esm/database/seeds/seeder.errors.d.mts +4 -0
- package/esm/database/seeds/seeder.errors.d.mts.map +1 -1
- package/esm/database/seeds/seeder.errors.mjs +2 -0
- package/esm/database/seeds/seeder.errors.mjs.map +1 -1
- package/esm/dev-server/boot-precondition-error.mjs +1 -0
- package/esm/dev-server/boot-precondition-error.mjs.map +1 -1
- package/esm/dev-server/create-worker.mjs +15 -9
- package/esm/dev-server/create-worker.mjs.map +1 -1
- package/esm/dev-server/dev-agent-tooling.mjs +135 -0
- package/esm/dev-server/dev-agent-tooling.mjs.map +1 -0
- package/esm/dev-server/dev-logger.mjs.map +1 -1
- package/esm/dev-server/development-server.mjs +8 -0
- package/esm/dev-server/development-server.mjs.map +1 -1
- package/esm/dev-server/files-orchestrator.mjs +4 -5
- package/esm/dev-server/files-orchestrator.mjs.map +1 -1
- package/esm/dev-server/files-watcher.mjs +1 -1
- package/esm/dev-server/health-checker/checkers/eslint-health-checker.mjs +2 -3
- package/esm/dev-server/health-checker/checkers/eslint-health-checker.mjs.map +1 -1
- package/esm/dev-server/health-checker/checkers/oxlint-health-checker.mjs +33 -0
- package/esm/dev-server/health-checker/checkers/oxlint-health-checker.mjs.map +1 -0
- package/esm/dev-server/health-checker/default-health-checkers.mjs +31 -0
- package/esm/dev-server/health-checker/default-health-checkers.mjs.map +1 -0
- package/esm/dev-server/health-checker/file-health-checker.contract.d.mts +9 -3
- package/esm/dev-server/health-checker/file-health-checker.contract.d.mts.map +1 -1
- package/esm/dev-server/health-checker/files-healthcare.manager.mjs +15 -4
- package/esm/dev-server/health-checker/files-healthcare.manager.mjs.map +1 -1
- package/esm/dev-server/health-checker/oxlint-runner.mjs +302 -0
- package/esm/dev-server/health-checker/oxlint-runner.mjs.map +1 -0
- package/esm/dev-server/health-checker/workers/oxlint-health.worker.d.mts +1 -0
- package/esm/dev-server/health-checker/workers/oxlint-health.worker.mjs +42 -0
- package/esm/dev-server/health-checker/workers/oxlint-health.worker.mjs.map +1 -0
- package/esm/dev-server/loader/loader-port-acks.mjs +1 -1
- package/esm/dev-server/loader/loader-port-acks.mjs.map +1 -1
- package/esm/dev-server/loader/register-loader.mjs +1 -1
- package/esm/dev-server/loader/register-loader.mjs.map +1 -1
- package/esm/dev-server/loader/resolve-hook.mjs +1 -1
- package/esm/dev-server/loader/transpile-cache.mjs +1 -1
- package/esm/dev-server/model-resource-typings.mjs.map +1 -1
- package/esm/dev-server/module-loader.mjs +1 -0
- package/esm/dev-server/module-loader.mjs.map +1 -1
- package/esm/dev-server/parse-imports.mjs +1 -1
- package/esm/dev-server/parse-imports.mjs.map +1 -1
- package/esm/dev-server/route-types-publisher.mjs +1 -1
- package/esm/dev-server/start-development-server.mjs.map +1 -1
- package/esm/dev-server/translation-keys-sources.mjs +1 -1
- package/esm/dev-server/translation-keys-sources.mjs.map +1 -1
- package/esm/dev-server/tsconfig-manager.mjs.map +1 -1
- package/esm/dev-server/type-generator.mjs +3 -3
- package/esm/dev-server/type-generator.mjs.map +1 -1
- package/esm/dev-server/types.d.mts.map +1 -1
- package/esm/errors/container-key-missing-error.mjs +1 -0
- package/esm/errors/container-key-missing-error.mjs.map +1 -1
- package/esm/errors/error-codes.d.mts +653 -0
- package/esm/errors/error-codes.d.mts.map +1 -0
- package/esm/errors/error-codes.mjs +634 -0
- package/esm/errors/error-codes.mjs.map +1 -0
- package/esm/errors/esbuild-binary-missing-error.mjs +1 -0
- package/esm/errors/esbuild-binary-missing-error.mjs.map +1 -1
- package/esm/errors/index.d.mts +3 -1
- package/esm/errors/index.mjs +3 -1
- package/esm/errors/unknown-locale-error.mjs +1 -0
- package/esm/errors/unknown-locale-error.mjs.map +1 -1
- package/esm/errors/warlock-error.d.mts +23 -0
- package/esm/errors/warlock-error.d.mts.map +1 -0
- package/esm/errors/warlock-error.mjs +22 -0
- package/esm/errors/warlock-error.mjs.map +1 -0
- package/esm/generations/add-command.action.mjs +19 -3
- package/esm/generations/add-command.action.mjs.map +1 -1
- package/esm/generations/features/access.feature.mjs +1 -1
- package/esm/generations/features/access.feature.mjs.map +1 -1
- package/esm/generations/features/bull-board.feature.mjs +1 -1
- package/esm/generations/features/bull-board.feature.mjs.map +1 -1
- package/esm/generations/features/mysql.feature.mjs.map +1 -1
- package/esm/generations/features/notifications.feature.mjs +5 -2
- package/esm/generations/features/notifications.feature.mjs.map +1 -1
- package/esm/generations/features/queue.feature.mjs +1 -1
- package/esm/generations/features/queue.feature.mjs.map +1 -1
- package/esm/generations/features/react-email.feature.mjs +1 -1
- package/esm/generations/features/react-email.feature.mjs.map +1 -1
- package/esm/generations/features/shadcn.feature.mjs +1 -1
- package/esm/generations/features/shadcn.feature.mjs.map +1 -1
- package/esm/generations/features/shared/link-ai-package-import.mjs +1 -1
- package/esm/generations/features/shared/link-ai-package-import.mjs.map +1 -1
- package/esm/generations/features/shared/merge-web-sitemap-config.mjs.map +1 -1
- package/esm/generations/features/shared/patch-tsconfig-include.mjs +1 -1
- package/esm/generations/features/shared/patch-tsconfig-include.mjs.map +1 -1
- package/esm/generations/features/shared/relocate-conflicting-home-route.mjs +1 -1
- package/esm/generations/features/shared/relocate-conflicting-home-route.mjs.map +1 -1
- package/esm/generations/features/sitemap.feature.mjs +1 -1
- package/esm/generations/features/sitemap.feature.mjs.map +1 -1
- package/esm/generations/features/tailwind.feature.mjs +1 -1
- package/esm/generations/features/tailwind.feature.mjs.map +1 -1
- package/esm/generations/features/test.feature.mjs +11 -6
- package/esm/generations/features/test.feature.mjs.map +1 -1
- package/esm/generations/features/web.feature.mjs +1 -1
- package/esm/generations/features/web.feature.mjs.map +1 -1
- package/esm/generations/generation-fs.mjs +73 -0
- package/esm/generations/generation-fs.mjs.map +1 -0
- package/esm/generations/generation-run.mjs +185 -0
- package/esm/generations/generation-run.mjs.map +1 -0
- package/esm/generations/stubs.mjs +155 -13
- package/esm/generations/stubs.mjs.map +1 -1
- package/esm/http/bounded-stream-queue.d.mts +10 -0
- package/esm/http/bounded-stream-queue.d.mts.map +1 -0
- package/esm/http/bounded-stream-queue.mjs +97 -0
- package/esm/http/bounded-stream-queue.mjs.map +1 -0
- package/esm/http/build-rate-limit-options.d.mts +13 -0
- package/esm/http/build-rate-limit-options.d.mts.map +1 -1
- package/esm/http/build-rate-limit-options.mjs.map +1 -1
- package/esm/http/conditional-request.d.mts +86 -0
- package/esm/http/conditional-request.d.mts.map +1 -0
- package/esm/http/conditional-request.mjs +121 -0
- package/esm/http/conditional-request.mjs.map +1 -0
- package/esm/http/csp.d.mts +2 -0
- package/esm/http/csp.d.mts.map +1 -1
- package/esm/http/csp.mjs +1 -0
- package/esm/http/csp.mjs.map +1 -1
- package/esm/http/csrf-origin-policy.mjs.map +1 -1
- package/esm/http/database/RequestLog.d.mts +24 -84
- package/esm/http/database/RequestLog.d.mts.map +1 -1
- package/esm/http/errors/errors.d.mts +2 -0
- package/esm/http/errors/errors.d.mts.map +1 -1
- package/esm/http/errors/errors.mjs +1 -0
- package/esm/http/errors/errors.mjs.map +1 -1
- package/esm/http/escape-header-value.d.mts +18 -0
- package/esm/http/escape-header-value.d.mts.map +1 -0
- package/esm/http/escape-header-value.mjs +27 -0
- package/esm/http/escape-header-value.mjs.map +1 -0
- package/esm/http/flush-pending-cookies.mjs.map +1 -1
- package/esm/http/index.d.mts +5 -2
- package/esm/http/index.mjs +4 -1
- package/esm/http/lazy-static.mjs +194 -0
- package/esm/http/lazy-static.mjs.map +1 -0
- package/esm/http/middleware/idempotency.middleware.mjs.map +1 -1
- package/esm/http/plugins.d.mts.map +1 -1
- package/esm/http/plugins.mjs +7 -4
- package/esm/http/plugins.mjs.map +1 -1
- package/esm/http/rate-limit-cache-store.mjs +2 -1
- package/esm/http/rate-limit-cache-store.mjs.map +1 -1
- package/esm/http/request-log-snapshot.d.mts +12 -5
- package/esm/http/request-log-snapshot.d.mts.map +1 -1
- package/esm/http/request-log-snapshot.mjs +83 -4
- package/esm/http/request-log-snapshot.mjs.map +1 -1
- package/esm/http/request.d.mts +2 -2
- package/esm/http/request.d.mts.map +1 -1
- package/esm/http/request.mjs +5 -4
- package/esm/http/request.mjs.map +1 -1
- package/esm/http/response.d.mts +11 -1
- package/esm/http/response.d.mts.map +1 -1
- package/esm/http/response.mjs +164 -76
- package/esm/http/response.mjs.map +1 -1
- package/esm/http/safe-redirect.d.mts +51 -0
- package/esm/http/safe-redirect.d.mts.map +1 -0
- package/esm/http/safe-redirect.mjs +80 -0
- package/esm/http/safe-redirect.mjs.map +1 -0
- package/esm/http/serialized.d.mts.map +1 -1
- package/esm/http/server.d.mts +3 -1
- package/esm/http/server.d.mts.map +1 -1
- package/esm/http/server.mjs +14 -4
- package/esm/http/server.mjs.map +1 -1
- package/esm/http/stream-transport.mjs +4 -2
- package/esm/http/stream-transport.mjs.map +1 -1
- package/esm/http/types.d.mts +44 -11
- package/esm/http/types.d.mts.map +1 -1
- package/esm/http/uploads/generate-image-variant.mjs +1 -1
- package/esm/http/uploads/generate-image-variants.d.mts +10 -7
- package/esm/http/uploads/generate-image-variants.d.mts.map +1 -1
- package/esm/http/uploads/generate-image-variants.mjs +61 -24
- package/esm/http/uploads/generate-image-variants.mjs.map +1 -1
- package/esm/http/uploads/image-variant-cache-entries.mjs +78 -0
- package/esm/http/uploads/image-variant-cache-entries.mjs.map +1 -0
- package/esm/http/uploads/image-variant-cache.mjs +72 -30
- package/esm/http/uploads/image-variant-cache.mjs.map +1 -1
- package/esm/http/uploads/image-variant-types.d.mts +2 -0
- package/esm/http/uploads/image-variant-types.d.mts.map +1 -1
- package/esm/http/uploads/image-variants-config-error.d.mts +3 -1
- package/esm/http/uploads/image-variants-config-error.d.mts.map +1 -1
- package/esm/http/uploads/image-variants-config-error.mjs +3 -2
- package/esm/http/uploads/image-variants-config-error.mjs.map +1 -1
- package/esm/http/uploads/load-variant-source.mjs +1 -1
- package/esm/http/uploads/load-variant-source.mjs.map +1 -1
- package/esm/http/uploads/purge-image-variants.d.mts +7 -2
- package/esm/http/uploads/purge-image-variants.d.mts.map +1 -1
- package/esm/http/uploads/purge-image-variants.mjs +16 -16
- package/esm/http/uploads/purge-image-variants.mjs.map +1 -1
- package/esm/http/uploads/remote-variant-source.mjs +115 -0
- package/esm/http/uploads/remote-variant-source.mjs.map +1 -0
- package/esm/http/uploads/resolve-image-variant.d.mts +3 -4
- package/esm/http/uploads/resolve-image-variant.d.mts.map +1 -1
- package/esm/http/uploads/resolve-image-variant.mjs +10 -18
- package/esm/http/uploads/resolve-image-variant.mjs.map +1 -1
- package/esm/http/uploads/resolve-image-variants-config.mjs +5 -3
- package/esm/http/uploads/resolve-image-variants-config.mjs.map +1 -1
- package/esm/http/uploads/resolve-remote-image-variant.mjs +89 -0
- package/esm/http/uploads/resolve-remote-image-variant.mjs.map +1 -0
- package/esm/http/uploads/trim-image-variant-cache.mjs +193 -0
- package/esm/http/uploads/trim-image-variant-cache.mjs.map +1 -0
- package/esm/http/uploads/uploaded-file.controller.d.mts +5 -3
- package/esm/http/uploads/uploaded-file.controller.d.mts.map +1 -1
- package/esm/http/uploads/uploaded-file.controller.mjs +16 -8
- package/esm/http/uploads/uploaded-file.controller.mjs.map +1 -1
- package/esm/http/uploads/variant-cache-key.mjs +1 -1
- package/esm/http/uploads-types.d.mts +6 -2
- package/esm/http/uploads-types.d.mts.map +1 -1
- package/esm/index.d.mts +17 -6
- package/esm/index.mjs +14 -3
- package/esm/localization/parse-locale-dictionary.d.mts +2 -0
- package/esm/localization/parse-locale-dictionary.d.mts.map +1 -1
- package/esm/localization/parse-locale-dictionary.mjs +1 -0
- package/esm/localization/parse-locale-dictionary.mjs.map +1 -1
- package/esm/mail/config.d.mts +12 -1
- package/esm/mail/config.d.mts.map +1 -1
- package/esm/mail/config.mjs +16 -1
- package/esm/mail/config.mjs.map +1 -1
- package/esm/mail/index.d.mts +1 -1
- package/esm/mail/index.mjs +1 -1
- package/esm/net/index.d.mts +2 -0
- package/esm/net/index.mjs +3 -0
- package/esm/openapi/build-openapi-document.d.mts.map +1 -1
- package/esm/openapi/build-openapi-document.mjs +8 -5
- package/esm/openapi/build-openapi-document.mjs.map +1 -1
- package/esm/openapi/error-responses.mjs +28 -2
- package/esm/openapi/error-responses.mjs.map +1 -1
- package/esm/openapi/postman/build-request-body.mjs.map +1 -1
- package/esm/openapi/postman/build-request-url.mjs.map +1 -1
- package/esm/openapi/postman/build-saved-responses.mjs.map +1 -1
- package/esm/openapi/postman/example-from-schema.d.mts.map +1 -1
- package/esm/openapi/postman/example-from-schema.mjs.map +1 -1
- package/esm/openapi/postman/openapi-to-postman-collection.d.mts.map +1 -1
- package/esm/openapi/postman/openapi-to-postman-collection.mjs.map +1 -1
- package/esm/openapi/postman/schema-refs.mjs.map +1 -1
- package/esm/openapi/postman/uuid-v5.mjs.map +1 -1
- package/esm/openapi/request-schemas.mjs.map +1 -1
- package/esm/openapi/response-schemas.mjs.map +1 -1
- package/esm/openapi/schema-registry.d.mts +1 -0
- package/esm/openapi/schema-registry.mjs.map +1 -1
- package/esm/openapi/security.mjs.map +1 -1
- package/esm/openapi/types.d.mts +3 -2
- package/esm/openapi/types.d.mts.map +1 -1
- package/esm/production/assert-generated-imports.mjs +1 -0
- package/esm/production/assert-generated-imports.mjs.map +1 -1
- package/esm/production/production-builder.mjs +12 -4
- package/esm/production/production-builder.mjs.map +1 -1
- package/esm/production/resolve-build-config.mjs +1 -0
- package/esm/production/resolve-build-config.mjs.map +1 -1
- package/esm/production/route-registration-child.mjs.map +1 -1
- package/esm/production/route-registration-snapshot.mjs.map +1 -1
- package/esm/repositories/contracts/query-builder.contract.d.mts.map +1 -1
- package/esm/repositories/contracts/types.d.mts.map +1 -1
- package/esm/repositories/repository.manager.mjs.map +1 -1
- package/esm/resource/resource.d.mts.map +1 -1
- package/esm/resource/resource.mjs.map +1 -1
- package/esm/resource/types.d.mts.map +1 -1
- package/esm/restful/restful.d.mts +5 -5
- package/esm/restful/restful.d.mts.map +1 -1
- package/esm/restful/restful.mjs.map +1 -1
- package/esm/router/build-route-rate-limit.mjs.map +1 -1
- package/esm/router/dev-dispatch.mjs +31 -12
- package/esm/router/dev-dispatch.mjs.map +1 -1
- package/esm/router/index.d.mts +4 -2
- package/esm/router/index.mjs +2 -0
- package/esm/router/log-request-lifecycle.mjs.map +1 -1
- package/esm/router/positional-handler-diagnostics.d.mts.map +1 -1
- package/esm/router/positional-handler-diagnostics.mjs.map +1 -1
- package/esm/router/resolve-route-rate-limit.mjs +47 -0
- package/esm/router/resolve-route-rate-limit.mjs.map +1 -0
- package/esm/router/resolve-route-validation.mjs +19 -0
- package/esm/router/resolve-route-validation.mjs.map +1 -0
- package/esm/router/route-guard-names.mjs +30 -0
- package/esm/router/route-guard-names.mjs.map +1 -0
- package/esm/router/route-name-taken-error.d.mts +14 -0
- package/esm/router/route-name-taken-error.d.mts.map +1 -0
- package/esm/router/route-name-taken-error.mjs +18 -0
- package/esm/router/route-name-taken-error.mjs.map +1 -0
- package/esm/router/router.d.mts +32 -13
- package/esm/router/router.d.mts.map +1 -1
- package/esm/router/router.mjs +71 -38
- package/esm/router/router.mjs.map +1 -1
- package/esm/router/types.d.mts +137 -17
- package/esm/router/types.d.mts.map +1 -1
- package/esm/router/unguarded-route-diagnostics.d.mts +40 -0
- package/esm/router/unguarded-route-diagnostics.d.mts.map +1 -0
- package/esm/router/unguarded-route-diagnostics.mjs +95 -0
- package/esm/router/unguarded-route-diagnostics.mjs.map +1 -0
- package/esm/storage/drivers/cloud-driver.d.mts.map +1 -1
- package/esm/storage/drivers/cloud-driver.mjs.map +1 -1
- package/esm/storage/drivers/local-driver.d.mts.map +1 -1
- package/esm/storage/drivers/local-driver.mjs.map +1 -1
- package/esm/storage/local-disk-roots.mjs +24 -0
- package/esm/storage/local-disk-roots.mjs.map +1 -0
- package/esm/storage/storage.d.mts +14 -0
- package/esm/storage/storage.d.mts.map +1 -1
- package/esm/storage/storage.mjs +22 -0
- package/esm/storage/storage.mjs.map +1 -1
- package/esm/storage/types.d.mts.map +1 -1
- package/esm/storage/utils/storage-not-initialized-error.d.mts +2 -0
- package/esm/storage/utils/storage-not-initialized-error.d.mts.map +1 -1
- package/esm/storage/utils/storage-not-initialized-error.mjs +1 -0
- package/esm/storage/utils/storage-not-initialized-error.mjs.map +1 -1
- package/esm/tests/authenticated-test-client.d.mts +32 -0
- package/esm/tests/authenticated-test-client.d.mts.map +1 -0
- package/esm/tests/authenticated-test-client.mjs +40 -0
- package/esm/tests/authenticated-test-client.mjs.map +1 -0
- package/esm/tests/factories.d.mts +59 -0
- package/esm/tests/factories.d.mts.map +1 -0
- package/esm/tests/factories.mjs +105 -0
- package/esm/tests/factories.mjs.map +1 -0
- package/esm/tests/fakes/cache-fake.d.mts +29 -0
- package/esm/tests/fakes/cache-fake.d.mts.map +1 -0
- package/esm/tests/fakes/cache-fake.mjs +79 -0
- package/esm/tests/fakes/cache-fake.mjs.map +1 -0
- package/esm/tests/fakes/clock-fake.d.mts +32 -0
- package/esm/tests/fakes/clock-fake.d.mts.map +1 -0
- package/esm/tests/fakes/clock-fake.mjs +69 -0
- package/esm/tests/fakes/clock-fake.mjs.map +1 -0
- package/esm/tests/fakes/fake-assertion-error.d.mts +13 -0
- package/esm/tests/fakes/fake-assertion-error.d.mts.map +1 -0
- package/esm/tests/fakes/fake-assertion-error.mjs +20 -0
- package/esm/tests/fakes/fake-assertion-error.mjs.map +1 -0
- package/esm/tests/fakes/ids-fake.d.mts +22 -0
- package/esm/tests/fakes/ids-fake.d.mts.map +1 -0
- package/esm/tests/fakes/ids-fake.mjs +57 -0
- package/esm/tests/fakes/ids-fake.mjs.map +1 -0
- package/esm/tests/fakes/index.d.mts +8 -0
- package/esm/tests/fakes/index.mjs +10 -0
- package/esm/tests/fakes/mail-fake.d.mts +41 -0
- package/esm/tests/fakes/mail-fake.d.mts.map +1 -0
- package/esm/tests/fakes/mail-fake.mjs +111 -0
- package/esm/tests/fakes/mail-fake.mjs.map +1 -0
- package/esm/tests/fakes/queue-fake.d.mts +48 -0
- package/esm/tests/fakes/queue-fake.d.mts.map +1 -0
- package/esm/tests/fakes/queue-fake.mjs +134 -0
- package/esm/tests/fakes/queue-fake.mjs.map +1 -0
- package/esm/tests/fakes/storage-fake.d.mts +31 -0
- package/esm/tests/fakes/storage-fake.d.mts.map +1 -0
- package/esm/tests/fakes/storage-fake.mjs +122 -0
- package/esm/tests/fakes/storage-fake.mjs.map +1 -0
- package/esm/tests/fakes/test-fakes.d.mts +39 -0
- package/esm/tests/fakes/test-fakes.d.mts.map +1 -0
- package/esm/tests/fakes/test-fakes.mjs +90 -0
- package/esm/tests/fakes/test-fakes.mjs.map +1 -0
- package/esm/tests/index.d.mts +14 -2
- package/esm/tests/index.mjs +15 -2
- package/esm/tests/snapshot-response.d.mts +34 -0
- package/esm/tests/snapshot-response.d.mts.map +1 -0
- package/esm/tests/snapshot-response.mjs +42 -0
- package/esm/tests/snapshot-response.mjs.map +1 -0
- package/esm/tests/start-http-development-server.d.mts +22 -0
- package/esm/tests/start-http-development-server.d.mts.map +1 -1
- package/esm/tests/start-http-development-server.mjs +36 -3
- package/esm/tests/start-http-development-server.mjs.map +1 -1
- package/esm/tests/test-helpers.d.mts +20 -1
- package/esm/tests/test-helpers.d.mts.map +1 -1
- package/esm/tests/test-helpers.mjs +40 -27
- package/esm/tests/test-helpers.mjs.map +1 -1
- package/esm/tests/test-http-server.d.mts +62 -0
- package/esm/tests/test-http-server.d.mts.map +1 -0
- package/esm/tests/test-http-server.mjs +119 -0
- package/esm/tests/test-http-server.mjs.map +1 -0
- package/esm/tests/vitest-setup.d.mts +11 -0
- package/esm/tests/vitest-setup.d.mts.map +1 -1
- package/esm/tests/vitest-setup.mjs +12 -4
- package/esm/tests/vitest-setup.mjs.map +1 -1
- package/esm/tooling/agents-md/agents-md-markers.d.mts +27 -0
- package/esm/tooling/agents-md/agents-md-markers.d.mts.map +1 -0
- package/esm/tooling/agents-md/agents-md-markers.mjs +59 -0
- package/esm/tooling/agents-md/agents-md-markers.mjs.map +1 -0
- package/esm/tooling/agents-md/agents-md-refresher.d.mts +36 -0
- package/esm/tooling/agents-md/agents-md-refresher.d.mts.map +1 -0
- package/esm/tooling/agents-md/agents-md-refresher.mjs +72 -0
- package/esm/tooling/agents-md/agents-md-refresher.mjs.map +1 -0
- package/esm/tooling/agents-md/index.mjs +7 -0
- package/esm/tooling/agents-md/installed-skills.d.mts +30 -0
- package/esm/tooling/agents-md/installed-skills.d.mts.map +1 -0
- package/esm/tooling/agents-md/installed-skills.mjs +74 -0
- package/esm/tooling/agents-md/installed-skills.mjs.map +1 -0
- package/esm/tooling/agents-md/render-agents-md.d.mts +33 -0
- package/esm/tooling/agents-md/render-agents-md.d.mts.map +1 -0
- package/esm/tooling/agents-md/render-agents-md.mjs +195 -0
- package/esm/tooling/agents-md/render-agents-md.mjs.map +1 -0
- package/esm/tooling/agents-md/write-agents-md.d.mts +33 -0
- package/esm/tooling/agents-md/write-agents-md.d.mts.map +1 -0
- package/esm/tooling/agents-md/write-agents-md.mjs +49 -0
- package/esm/tooling/agents-md/write-agents-md.mjs.map +1 -0
- package/esm/tooling/board/board-message.d.mts +31 -0
- package/esm/tooling/board/board-message.d.mts.map +1 -0
- package/esm/tooling/board/board-message.mjs +86 -0
- package/esm/tooling/board/board-message.mjs.map +1 -0
- package/esm/tooling/board/board.d.mts +109 -0
- package/esm/tooling/board/board.d.mts.map +1 -0
- package/esm/tooling/board/board.mjs +406 -0
- package/esm/tooling/board/board.mjs.map +1 -0
- package/esm/tooling/board/board.types.d.mts +72 -0
- package/esm/tooling/board/board.types.d.mts.map +1 -0
- package/esm/tooling/board/board.types.mjs +54 -0
- package/esm/tooling/board/board.types.mjs.map +1 -0
- package/esm/tooling/check/changed-files.d.mts +33 -0
- package/esm/tooling/check/changed-files.d.mts.map +1 -0
- package/esm/tooling/check/changed-files.mjs +73 -0
- package/esm/tooling/check/changed-files.mjs.map +1 -0
- package/esm/tooling/check/check-report.types.d.mts +62 -0
- package/esm/tooling/check/check-report.types.d.mts.map +1 -0
- package/esm/tooling/check/check-report.types.mjs +37 -0
- package/esm/tooling/check/check-report.types.mjs.map +1 -0
- package/esm/tooling/check/code-style-conventions.mjs +106 -0
- package/esm/tooling/check/code-style-conventions.mjs.map +1 -0
- package/esm/tooling/check/conventions-step.d.mts +34 -0
- package/esm/tooling/check/conventions-step.d.mts.map +1 -0
- package/esm/tooling/check/conventions-step.mjs +184 -0
- package/esm/tooling/check/conventions-step.mjs.map +1 -0
- package/esm/tooling/check/environment-step.d.mts +18 -0
- package/esm/tooling/check/environment-step.d.mts.map +1 -0
- package/esm/tooling/check/environment-step.mjs +78 -0
- package/esm/tooling/check/environment-step.mjs.map +1 -0
- package/esm/tooling/check/index.d.mts +8 -0
- package/esm/tooling/check/index.mjs +10 -0
- package/esm/tooling/check/lint-step.d.mts +19 -0
- package/esm/tooling/check/lint-step.d.mts.map +1 -0
- package/esm/tooling/check/lint-step.mjs +111 -0
- package/esm/tooling/check/lint-step.mjs.map +1 -0
- package/esm/tooling/check/request-input.mjs +132 -0
- package/esm/tooling/check/request-input.mjs.map +1 -0
- package/esm/tooling/check/run-check.d.mts +35 -0
- package/esm/tooling/check/run-check.d.mts.map +1 -0
- package/esm/tooling/check/run-check.mjs +192 -0
- package/esm/tooling/check/run-check.mjs.map +1 -0
- package/esm/tooling/check/run-tests.d.mts +48 -0
- package/esm/tooling/check/run-tests.d.mts.map +1 -0
- package/esm/tooling/check/run-tests.mjs +93 -0
- package/esm/tooling/check/run-tests.mjs.map +1 -0
- package/esm/tooling/check/security-conventions.mjs +648 -0
- package/esm/tooling/check/security-conventions.mjs.map +1 -0
- package/esm/tooling/check/source-ast.mjs +195 -0
- package/esm/tooling/check/source-ast.mjs.map +1 -0
- package/esm/tooling/check/source-files.mjs +27 -0
- package/esm/tooling/check/source-files.mjs.map +1 -0
- package/esm/tooling/check/tests-step.d.mts +34 -0
- package/esm/tooling/check/tests-step.d.mts.map +1 -0
- package/esm/tooling/check/tests-step.mjs +177 -0
- package/esm/tooling/check/tests-step.mjs.map +1 -0
- package/esm/tooling/dev-state/dev-server-state.d.mts +39 -0
- package/esm/tooling/dev-state/dev-server-state.d.mts.map +1 -0
- package/esm/tooling/dev-state/dev-server-state.mjs +67 -0
- package/esm/tooling/dev-state/dev-server-state.mjs.map +1 -0
- package/esm/tooling/devtools/devtools-client.d.mts +91 -0
- package/esm/tooling/devtools/devtools-client.d.mts.map +1 -0
- package/esm/tooling/devtools/devtools-client.mjs +155 -0
- package/esm/tooling/devtools/devtools-client.mjs.map +1 -0
- package/esm/tooling/generate/generation.d.mts +78 -0
- package/esm/tooling/generate/generation.d.mts.map +1 -0
- package/esm/tooling/generate/generation.mjs +123 -0
- package/esm/tooling/generate/generation.mjs.map +1 -0
- package/esm/tooling/generate/generator-spec.d.mts +57 -0
- package/esm/tooling/generate/generator-spec.d.mts.map +1 -0
- package/esm/tooling/generate/generator-spec.mjs +102 -0
- package/esm/tooling/generate/generator-spec.mjs.map +1 -0
- package/esm/tooling/generate/index.mjs +6 -0
- package/esm/tooling/generate/project-files.mjs +121 -0
- package/esm/tooling/generate/project-files.mjs.map +1 -0
- package/esm/tooling/generate/run-cli.d.mts +40 -0
- package/esm/tooling/generate/run-cli.d.mts.map +1 -0
- package/esm/tooling/generate/run-cli.mjs +93 -0
- package/esm/tooling/generate/run-cli.mjs.map +1 -0
- package/esm/tooling/generate/unified-diff.d.mts +37 -0
- package/esm/tooling/generate/unified-diff.d.mts.map +1 -0
- package/esm/tooling/generate/unified-diff.mjs +161 -0
- package/esm/tooling/generate/unified-diff.mjs.map +1 -0
- package/esm/tooling/index.d.mts +41 -0
- package/esm/tooling/index.mjs +45 -0
- package/esm/tooling/inspect/boot-for-inspect.d.mts +23 -0
- package/esm/tooling/inspect/boot-for-inspect.d.mts.map +1 -0
- package/esm/tooling/inspect/boot-for-inspect.mjs +63 -0
- package/esm/tooling/inspect/boot-for-inspect.mjs.map +1 -0
- package/esm/tooling/inspect/collect-config.mjs +77 -0
- package/esm/tooling/inspect/collect-config.mjs.map +1 -0
- package/esm/tooling/inspect/collect-models.d.mts +9 -0
- package/esm/tooling/inspect/collect-models.d.mts.map +1 -0
- package/esm/tooling/inspect/collect-models.mjs +154 -0
- package/esm/tooling/inspect/collect-models.mjs.map +1 -0
- package/esm/tooling/inspect/collect-packages.d.mts +10 -0
- package/esm/tooling/inspect/collect-packages.d.mts.map +1 -0
- package/esm/tooling/inspect/collect-packages.mjs +157 -0
- package/esm/tooling/inspect/collect-packages.mjs.map +1 -0
- package/esm/tooling/inspect/collect-pages.mjs +108 -0
- package/esm/tooling/inspect/collect-pages.mjs.map +1 -0
- package/esm/tooling/inspect/collect-routes.mjs +168 -0
- package/esm/tooling/inspect/collect-routes.mjs.map +1 -0
- package/esm/tooling/inspect/event-recorder.d.mts +37 -0
- package/esm/tooling/inspect/event-recorder.d.mts.map +1 -0
- package/esm/tooling/inspect/event-recorder.mjs +91 -0
- package/esm/tooling/inspect/event-recorder.mjs.map +1 -0
- package/esm/tooling/inspect/index.d.mts +7 -0
- package/esm/tooling/inspect/index.mjs +7 -0
- package/esm/tooling/inspect/inspect-app.d.mts +53 -0
- package/esm/tooling/inspect/inspect-app.d.mts.map +1 -0
- package/esm/tooling/inspect/inspect-app.mjs +92 -0
- package/esm/tooling/inspect/inspect-app.mjs.map +1 -0
- package/esm/tooling/inspect/inspect-report.schema.d.mts +15 -0
- package/esm/tooling/inspect/inspect-report.schema.d.mts.map +1 -0
- package/esm/tooling/inspect/inspect-report.schema.mjs +463 -0
- package/esm/tooling/inspect/inspect-report.schema.mjs.map +1 -0
- package/esm/tooling/inspect/inspect-report.types.d.mts +196 -0
- package/esm/tooling/inspect/inspect-report.types.d.mts.map +1 -0
- package/esm/tooling/inspect/inspect-report.types.mjs +33 -0
- package/esm/tooling/inspect/inspect-report.types.mjs.map +1 -0
- package/esm/tooling/mcp/create-mcp-context.d.mts +26 -0
- package/esm/tooling/mcp/create-mcp-context.d.mts.map +1 -0
- package/esm/tooling/mcp/create-mcp-context.mjs +75 -0
- package/esm/tooling/mcp/create-mcp-context.mjs.map +1 -0
- package/esm/tooling/mcp/db-schema.d.mts +49 -0
- package/esm/tooling/mcp/db-schema.d.mts.map +1 -0
- package/esm/tooling/mcp/db-schema.mjs +56 -0
- package/esm/tooling/mcp/db-schema.mjs.map +1 -0
- package/esm/tooling/mcp/docs-search.d.mts +72 -0
- package/esm/tooling/mcp/docs-search.d.mts.map +1 -0
- package/esm/tooling/mcp/docs-search.mjs +178 -0
- package/esm/tooling/mcp/docs-search.mjs.map +1 -0
- package/esm/tooling/mcp/index.mjs +9 -0
- package/esm/tooling/mcp/load-ai-tools.d.mts +62 -0
- package/esm/tooling/mcp/load-ai-tools.d.mts.map +1 -0
- package/esm/tooling/mcp/load-ai-tools.mjs +44 -0
- package/esm/tooling/mcp/load-ai-tools.mjs.map +1 -0
- package/esm/tooling/mcp/mcp-tools.d.mts +60 -0
- package/esm/tooling/mcp/mcp-tools.d.mts.map +1 -0
- package/esm/tooling/mcp/mcp-tools.mjs +513 -0
- package/esm/tooling/mcp/mcp-tools.mjs.map +1 -0
- package/esm/tooling/mcp/start-mcp-server.d.mts +56 -0
- package/esm/tooling/mcp/start-mcp-server.d.mts.map +1 -0
- package/esm/tooling/mcp/start-mcp-server.mjs +126 -0
- package/esm/tooling/mcp/start-mcp-server.mjs.map +1 -0
- package/esm/tooling/mcp/tool-input.d.mts +75 -0
- package/esm/tooling/mcp/tool-input.d.mts.map +1 -0
- package/esm/tooling/mcp/tool-input.mjs +72 -0
- package/esm/tooling/mcp/tool-input.mjs.map +1 -0
- package/esm/tooling/problem.d.mts +45 -0
- package/esm/tooling/problem.d.mts.map +1 -0
- package/esm/tooling/problem.mjs +28 -0
- package/esm/tooling/problem.mjs.map +1 -0
- package/esm/tooling/trace/trace-report.types.d.mts +71 -0
- package/esm/tooling/trace/trace-report.types.d.mts.map +1 -0
- package/esm/tooling/trace/trace-report.types.mjs +7 -0
- package/esm/tooling/trace/trace-report.types.mjs.map +1 -0
- package/esm/tooling/trace/trace-request.d.mts +83 -0
- package/esm/tooling/trace/trace-request.d.mts.map +1 -0
- package/esm/tooling/trace/trace-request.mjs +241 -0
- package/esm/tooling/trace/trace-request.mjs.map +1 -0
- package/esm/tooling/typecheck/index.d.mts +1 -0
- package/esm/tooling/typecheck/index.mjs +3 -0
- package/esm/tooling/typecheck/run-typecheck.d.mts +59 -0
- package/esm/tooling/typecheck/run-typecheck.d.mts.map +1 -0
- package/esm/tooling/typecheck/run-typecheck.mjs +153 -0
- package/esm/tooling/typecheck/run-typecheck.mjs.map +1 -0
- package/esm/upgrade/codemods/head-viewport.mjs +46 -0
- package/esm/upgrade/codemods/head-viewport.mjs.map +1 -0
- package/esm/upgrade/codemods/helpers.mjs +81 -0
- package/esm/upgrade/codemods/helpers.mjs.map +1 -0
- package/esm/upgrade/codemods/index.mjs +34 -0
- package/esm/upgrade/codemods/index.mjs.map +1 -0
- package/esm/upgrade/codemods/logger-sync-calls.mjs +57 -0
- package/esm/upgrade/codemods/logger-sync-calls.mjs.map +1 -0
- package/esm/upgrade/codemods/package-json.mjs +122 -0
- package/esm/upgrade/codemods/package-json.mjs.map +1 -0
- package/esm/upgrade/codemods/request-log-snapshot.mjs +82 -0
- package/esm/upgrade/codemods/request-log-snapshot.mjs.map +1 -0
- package/esm/upgrade/codemods/review-sites.mjs +262 -0
- package/esm/upgrade/codemods/review-sites.mjs.map +1 -0
- package/esm/upgrade/diff.mjs +119 -0
- package/esm/upgrade/diff.mjs.map +1 -0
- package/esm/upgrade/format-upgrade-report.mjs +32 -0
- package/esm/upgrade/format-upgrade-report.mjs.map +1 -0
- package/esm/upgrade/load-ts-morph.mjs +48 -0
- package/esm/upgrade/load-ts-morph.mjs.map +1 -0
- package/esm/upgrade/notes.mjs +16 -0
- package/esm/upgrade/notes.mjs.map +1 -0
- package/esm/upgrade/run-upgrade.mjs +246 -0
- package/esm/upgrade/run-upgrade.mjs.map +1 -0
- package/esm/upgrade/upgrade-command.action.mjs +37 -0
- package/esm/upgrade/upgrade-command.action.mjs.map +1 -0
- package/esm/upgrade/version.mjs +39 -0
- package/esm/upgrade/version.mjs.map +1 -0
- package/esm/use-cases/use-cases-registry.mjs.map +1 -1
- package/esm/utils/clock.d.mts +33 -0
- package/esm/utils/clock.d.mts.map +1 -0
- package/esm/utils/clock.mjs +27 -0
- package/esm/utils/clock.mjs.map +1 -0
- package/esm/utils/framework-vesion.mjs +1 -1
- package/esm/utils/framework-vesion.mjs.map +1 -1
- package/esm/utils/ids.d.mts +32 -0
- package/esm/utils/ids.d.mts.map +1 -0
- package/esm/utils/ids.mjs +33 -0
- package/esm/utils/ids.mjs.map +1 -0
- package/esm/utils/index.d.mts +3 -0
- package/esm/utils/index.mjs +3 -0
- package/esm/utils/runtime.d.mts +59 -0
- package/esm/utils/runtime.d.mts.map +1 -0
- package/esm/utils/runtime.mjs +85 -0
- package/esm/utils/runtime.mjs.map +1 -0
- package/esm/validation/index.d.mts +1 -1
- package/esm/validation/types.d.mts +57 -2
- package/esm/validation/types.d.mts.map +1 -1
- package/esm/validation/validateAll.mjs +19 -2
- package/esm/validation/validateAll.mjs.map +1 -1
- package/esm/validation/validation-failure-status.mjs +15 -0
- package/esm/validation/validation-failure-status.mjs.map +1 -0
- package/esm/validation/validators/file-validator.d.mts +0 -16
- package/esm/validation/validators/file-validator.d.mts.map +1 -1
- package/esm/warlock-config/bundle-config.mjs +1 -1
- package/esm/warlock-config/types.d.mts +27 -3
- package/esm/warlock-config/types.d.mts.map +1 -1
- package/llms-full.txt +3166 -736
- package/llms.txt +16 -6
- package/package.json +43 -13
- package/schemas/inspect-report.schema.json +554 -0
- package/skills/README.md +9 -0
- package/skills/add-connector/SKILL.md +26 -38
- package/skills/benchmark-code/SKILL.md +30 -24
- package/skills/build-restful/SKILL.md +14 -14
- package/skills/build-url/SKILL.md +18 -18
- package/skills/configure-app/SKILL.md +107 -14
- package/skills/create-controller/SKILL.md +25 -12
- package/skills/create-module/SKILL.md +3 -3
- package/skills/define-resource/SKILL.md +32 -29
- package/skills/encrypt-data/SKILL.md +21 -19
- package/skills/generate-openapi/SKILL.md +50 -24
- package/skills/hash-password/SKILL.md +2 -2
- package/skills/health-checks/SKILL.md +24 -7
- package/skills/index.md +9 -4
- package/skills/lower-stage3-decorators/SKILL.md +4 -4
- package/skills/make-endpoint/SKILL.md +110 -0
- package/skills/model-factories/SKILL.md +92 -0
- package/skills/process-image/SKILL.md +32 -30
- package/skills/register-route/SKILL.md +109 -10
- package/skills/request-memo/SKILL.md +1 -1
- package/skills/request-tracing/SKILL.md +4 -1
- package/skills/resolve-path/SKILL.md +45 -44
- package/skills/retry-operation/SKILL.md +20 -11
- package/skills/run-app/SKILL.md +106 -22
- package/skills/send-response/SKILL.md +179 -14
- package/skills/store-file/SKILL.md +93 -53
- package/skills/test-fakes/SKILL.md +123 -0
- package/skills/test-http/SKILL.md +125 -21
- package/skills/test-service/SKILL.md +41 -1
- package/skills/update-packages/SKILL.md +29 -18
- package/skills/upgrade-from-5-29/SKILL.md +413 -0
- package/skills/upload-file/SKILL.md +31 -33
- package/skills/use-app-context/SKILL.md +38 -31
- package/skills/use-middleware/SKILL.md +45 -25
- package/skills/use-model-transformers/SKILL.md +37 -28
- package/skills/use-repository/SKILL.md +2 -2
- package/skills/validate-input/SKILL.md +72 -28
- package/skills/warlock-agents-md/SKILL.md +96 -0
- package/skills/warlock-board/SKILL.md +123 -0
- package/skills/warlock-check/SKILL.md +132 -0
- package/skills/warlock-conventions/SKILL.md +115 -0
- package/skills/warlock-doctor/SKILL.md +55 -22
- package/skills/warlock-inspect/SKILL.md +134 -0
- package/skills/warlock-mcp/SKILL.md +120 -0
- package/skills/warlock-routes/SKILL.md +18 -11
- package/skills/warlock-trace/SKILL.md +81 -0
- package/skills/wire-socket/SKILL.md +8 -8
- package/skills/write-seeder/SKILL.md +46 -32
- package/skills/write-use-case/SKILL.md +40 -27
- package/esm/http/uploads/matches-if-none-match.mjs +0 -13
- package/esm/http/uploads/matches-if-none-match.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restful.d.mts","names":[],"sources":["../../../../../../../../packages/core/src/restful/restful.ts"],"mappings":";;;;;;;;uBASsB,OAAA,WAAkB,KAAA,aAAkB,aAAA;;;;YAI9C,UAAA,EAAY,iBAAA;;AAJxB;;YASY,UAAA;EAT4B;;;EAAA,UAc5B,eAAA;EAUU;;;EAAA,mBALD,UAAA,EAAY,iBAAA,CAAkB,CAAA;EA8BpB;;;EAAA,UAzBnB,QAAA,EAAU,MAAA;EAyBgC;;;;;EAb7C,KAAA;EA+C4C;;;EA1CtC,IAAA,CAAK,EAAA,WAAU,OAAA,CAAA,CAAA;EAmE0B;;;EA3DzC,IAAA;IAAO,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAAA,SAAA,
|
|
1
|
+
{"version":3,"file":"restful.d.mts","names":[],"sources":["../../../../../../../../packages/core/src/restful/restful.ts"],"mappings":";;;;;;;;uBASsB,OAAA,WAAkB,KAAA,aAAkB,aAAA;;;;YAI9C,UAAA,EAAY,iBAAA;;AAJxB;;YASY,UAAA;EAT4B;;;EAAA,UAc5B,eAAA;EAUU;;;EAAA,mBALD,UAAA,EAAY,iBAAA,CAAkB,CAAA;EA8BpB;;;EAAA,UAzBnB,QAAA,EAAU,MAAA;EAyBgC;;;;;EAb7C,KAAA;EA+C4C;;;EA1CtC,IAAA,CAAK,EAAA,WAAU,OAAA,CAAA,CAAA;EAmE0B;;;EA3DzC,IAAA;IAAO,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAAA,SAAA,QAAA,GAAA,MAAA;EAiHE;;;EA/EzC,GAAA;IAAM,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAAA,SAAA,QAAA,GAAA,MAAA;EAiIE;;;EAxGxC,MAAA;IAAS,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAAA;EA0JA;;;EApGzC,MAAA;IAAS,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAAA;EAqInB;;;EAnFtB,KAAA;IAAQ,OAAA;IAAS;EAAA,GAAY,WAAA,GAAW,OAA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A,EAAW,QAAA,EACX,OAAA,GAAU,CAAA,EACV,UAAA,GAAa,CAAA,GACZ,OAAA;EAUQ;;;EAAA,UAHK,MAAA,CACd,QAAA,EAAU,OAAA,EACV,SAAA,EAAW,QAAA,EACX,OAAA,EAAS,CAAA,EACT,UAAA,GAAa,CAAA,GACZ,OAAA;EASyE;;;;;EAAA,UAAlE,OAAA,CAAQ,MAAA,iCAAuC,OAAA,EAAS,OAAA,GAAU,aAAA;EA5bpB;;;;EAAA,UAydxC,cAAA,CACd,MAAA,UACA,OAAA,EAAS,OAAA,EACT,QAAA,EAAU,QAAA,EACV,OAAA,SAAa,OAAA,SAAA,QAAA,GAAA,MAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restful.mjs","names":[],"sources":["../../../../../../../../packages/core/src/restful/restful.ts"],"sourcesContent":["import type { GenericObject } from \"@mongez/reinforcements\";\nimport type { Model } from \"@warlock.js/cascade\";\nimport { log } from \"@warlock.js/logger\";\nimport type { Request, Response } from \"../http\";\nimport type { QueryBuilderContract, RepositoryManager } from \"../repositories\";\nimport type { HttpContext, RestfulMiddleware, RouteResource } from \"../router\";\n\nconst warnedUnvalidated = new WeakSet<object>();\n\nexport abstract class Restful<T extends Model> implements RouteResource {\n /**\n * Middleware for each method\n */\n protected middleware: RestfulMiddleware = {};\n\n /**\n * Record name\n */\n protected recordName = \"record\";\n\n /**\n * Records list name\n */\n protected recordsListName = \"records\";\n\n /**\n * Repository\n */\n protected abstract repository: RepositoryManager<T>;\n\n /**\n * Define what to be returned when a record is created|updated|deleted|patched\n */\n protected returnOn: Record<string, \"record\" | \"records\"> = {\n create: \"record\",\n update: \"record\",\n delete: \"record\",\n patch: \"record\",\n };\n\n /**\n * Enable fetching cache\n *\n * @default true\n */\n public cache = true;\n\n /**\n * Find record instance by id\n */\n public async find(id: number) {\n const findMethod = this.cache ? \"getCached\" : \"find\";\n return this.repository[findMethod](id);\n }\n\n /**\n * List records\n */\n public async list({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"list\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const responseDocument: GenericObject = {};\n\n const data = request.heavy();\n\n if (data.paginate === \"false\") {\n data.paginate = false;\n }\n\n const listMethod = this.cache ? \"listCached\" : \"list\";\n\n const { data: documents, pagination } = await this.repository[listMethod](data);\n\n responseDocument[this.recordsListName] = documents;\n\n if (pagination) {\n responseDocument.pagination = pagination;\n }\n\n return response.success(responseDocument);\n } catch (error: any) {\n log.error(\"restful\", \"list\", error);\n return response.serverError(error);\n }\n }\n\n /**\n * Get single record\n */\n public async get({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"get\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound();\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"get\", error);\n\n throw error;\n }\n }\n\n /**\n * Create a new record\n */\n public async create({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"create\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const model = this.repository.newModel();\n const beforeCreate = await this.beforeCreate(request, response, model);\n\n if (beforeCreate) {\n return beforeCreate;\n }\n\n const beforeSave = await this.beforeSave(request, response, model);\n\n if (beforeSave) {\n return beforeSave;\n }\n\n // Save the model the hooks received, so their changes are not discarded\n await model.save(this.payload(\"create\", request));\n\n const record = model;\n\n const createOutput = await this.onCreate(request, response, record);\n\n if (createOutput) {\n return createOutput;\n }\n\n const saveOutput = await this.onSave(request, response, record);\n\n if (saveOutput) {\n return saveOutput;\n }\n\n if (this.returnOn.create === \"records\") {\n return this.list({ request, response });\n }\n\n return response.successCreate({\n [this.recordName]: record,\n });\n } catch (error: Error | any) {\n log.error(\"restful\", \"create\", error);\n\n // let the request error handler decide the status; never leak DB messages as 400\n throw error;\n }\n }\n\n /**\n * Update record\n */\n public async update({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"update\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n // Find record\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound({\n error: \"Record not found\",\n });\n }\n\n const beforeOutput = await this.beforeUpdate(request, response, record);\n if (beforeOutput) {\n return beforeOutput;\n }\n\n const beforeSafe = await this.beforeSave(request, response, record);\n\n if (beforeSafe) {\n return beforeSafe;\n }\n\n const oldRecord = record.clone();\n\n await record.save(this.payload(\"update\", request));\n\n await this.onUpdate(request, response, record, oldRecord);\n await this.onSave(request, response, record, oldRecord);\n\n if (this.returnOn.update === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"update\", error);\n\n throw error;\n }\n }\n\n /**\n * Patch record\n */\n public async patch({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"patch\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound({\n error: \"Record not found\",\n });\n }\n\n const oldRecord = record.clone();\n\n const beforePatch = await this.beforePatch(request, response, record, oldRecord);\n\n if (beforePatch) {\n return beforePatch;\n }\n\n const beforeSave = await this.beforeSave(request, response, record, oldRecord);\n\n if (beforeSave) {\n return beforeSave;\n }\n\n await record.save(this.payload(\"patch\", request));\n\n await this.onPatch(request, response, record, oldRecord);\n await this.onSave(request, response, record, oldRecord);\n\n if (this.returnOn.patch === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"patch\", error);\n\n throw error;\n }\n }\n\n /**\n * Delete record\n */\n public async delete({ request, response }: HttpContext) {\n try {\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound();\n }\n\n const middlewareOutput = await this.callMiddleware(\"delete\", request, response, record);\n\n if (middlewareOutput) return middlewareOutput;\n\n await this.beforeDelete(request, response, record);\n\n await record.destroy();\n\n this.onDelete(request, response, record);\n\n if (this.returnOn.delete === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success();\n } catch (error: Error | any) {\n log.error(\"restful\", \"delete\", error);\n\n throw error;\n }\n }\n\n /**\n * Bulk delete records\n */\n public async bulkDelete({ request, response }: HttpContext) {\n try {\n const ids = request.input(\"id\");\n\n if (!Array.isArray(ids)) {\n return response.badRequest({\n error: \"id must be an array\",\n });\n }\n\n const records = await this.repository.all({\n perform: (query: QueryBuilderContract<T>) =>\n query.whereIn(\n \"id\",\n ids.map((id) => (/^\\d+$/.test(String(id)) ? Number(id) : id)),\n ),\n });\n\n await Promise.all(\n records.map(async (record) => {\n if (await this.callMiddleware(\"delete\", request, response, record)) {\n return;\n }\n\n await this.beforeDelete(request, response, record);\n await record.destroy();\n this.onDelete(request, response, record);\n }),\n );\n\n if (this.returnOn.delete === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n deleted: records.length,\n });\n } catch (error: Error | any) {\n log.error(\"restful\", \"bulkDelete\", error);\n\n throw error;\n }\n }\n\n /**\n * Before create\n */\n protected async beforeCreate(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * On create\n */\n protected async onCreate(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * Before update\n */\n protected async beforeUpdate(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On update\n */\n protected async onUpdate(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Before delete\n */\n protected async beforeDelete(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * On delete\n */\n protected async onDelete(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * Before patch\n */\n protected async beforePatch(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On patch\n */\n protected async onPatch(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Before save\n */\n protected async beforeSave(\n _request: Request,\n _response: Response,\n _record?: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On save\n */\n protected async onSave(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Data to persist: only the validated input.\n * Without a validation schema the raw input is kept (legacy behaviour)\n * and a one-time warning names the resource.\n */\n protected payload(action: \"create\" | \"update\" | \"patch\", request: Request): GenericObject {\n const validation = (this as any).validation;\n\n if (validation?.all || validation?.[action]) {\n return request.validated();\n }\n\n if (!warnedUnvalidated.has(this.constructor)) {\n warnedUnvalidated.add(this.constructor);\n\n log.warn(\n \"restful\",\n \"validation\",\n this.constructor.name + \" has no validation schema: \" + action + \" persists unvalidated request input. Define a validation schema to persist only validated fields.\",\n );\n }\n\n if (action === \"create\") return request.all();\n\n return action === \"update\" ? request.allExceptParams() : request.heavyExceptParams();\n }\n\n /**\n * Call middleware for the given method\n *\n */\n protected async callMiddleware(\n method: string,\n request: Request,\n response: Response,\n _record?: any,\n ) {\n if (!this.middleware[method]) return;\n\n for (const middleware of this.middleware[method]) {\n const output = await middleware({ request, response });\n\n if (output) {\n return output;\n }\n }\n\n return;\n }\n}\n"],"mappings":";;;AAOA,MAAM,oCAAoB,IAAI,QAAgB;AAE9C,IAAsB,UAAtB,MAAwE;;oBAI5B,CAAC;oBAKpB;yBAKK;kBAU+B;GACzD,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,OAAO;EACT;eAOe;;;;;CAKf,MAAa,KAAK,IAAY;EAC5B,MAAM,aAAa,KAAK,QAAQ,cAAc;EAC9C,OAAO,KAAK,WAAW,WAAW,CAAC,EAAE;CACvC;;;;CAKA,MAAa,KAAK,EAAE,SAAS,YAAyB;EACpD,IAAI;GACF,MAAM,mBAAmB,M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gB,YACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,QACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,WACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,OACd,UACA,WACA,SACA,YACc,CAEhB;;;;;;CAOA,AAAU,QAAQ,QAAuC,SAAiC;EACxF,MAAM,aAAc,KAAa;EAEjC,IAAI,YAAY,OAAO,aAAa,SAClC,OAAO,QAAQ,UAAU;EAG3B,IAAI,CAAC,kBAAkB,IAAI,KAAK,WAAW,GAAG;GAC5C,kBAAkB,IAAI,KAAK,WAAW;GAEtC,IAAI,KACF,WACA,cACA,KAAK,YAAY,OAAO,gCAAgC,SAAS,mGACnE;EACF;EAEA,IAAI,WAAW,UAAU,OAAO,QAAQ,IAAI;EAE5C,OAAO,WAAW,WAAW,QAAQ,gBAAgB,IAAI,QAAQ,kBAAkB;CACrF;;;;;CAMA,MAAgB,eACd,QACA,SACA,UACA,SACA;EACA,IAAI,CAAC,KAAK,WAAW,SAAS;EAE9B,KAAK,MAAM,cAAc,KAAK,WAAW,SAAS;GAChD,MAAM,SAAS,MAAM,WAAW;IAAE;IAAS;GAAS,CAAC;GAErD,IAAI,QACF,OAAO;EAEX;CAGF;AACF"}
|
|
1
|
+
{"version":3,"file":"restful.mjs","names":[],"sources":["../../../../../../../../packages/core/src/restful/restful.ts"],"sourcesContent":["import type { GenericObject } from \"@mongez/reinforcements\";\nimport type { Model } from \"@warlock.js/cascade\";\nimport { log } from \"@warlock.js/logger\";\nimport type { Request, Response } from \"../http\";\nimport type { QueryBuilderContract, RepositoryManager } from \"../repositories\";\nimport type { HttpContext, RestfulMiddleware, RouteResource } from \"../router\";\n\nconst warnedUnvalidated = new WeakSet<object>();\n\nexport abstract class Restful<T extends Model> implements RouteResource {\n /**\n * Middleware for each method\n */\n protected middleware: RestfulMiddleware = {};\n\n /**\n * Record name\n */\n protected recordName = \"record\";\n\n /**\n * Records list name\n */\n protected recordsListName = \"records\";\n\n /**\n * Repository\n */\n protected abstract repository: RepositoryManager<T>;\n\n /**\n * Define what to be returned when a record is created|updated|deleted|patched\n */\n protected returnOn: Record<string, \"record\" | \"records\"> = {\n create: \"record\",\n update: \"record\",\n delete: \"record\",\n patch: \"record\",\n };\n\n /**\n * Enable fetching cache\n *\n * @default true\n */\n public cache = true;\n\n /**\n * Find record instance by id\n */\n public async find(id: number) {\n const findMethod = this.cache ? \"getCached\" : \"find\";\n return this.repository[findMethod](id);\n }\n\n /**\n * List records\n */\n public async list({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"list\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const responseDocument: GenericObject = {};\n\n const data = request.heavy();\n\n if (data.paginate === \"false\") {\n data.paginate = false;\n }\n\n const listMethod = this.cache ? \"listCached\" : \"list\";\n\n const { data: documents, pagination } = await this.repository[listMethod](data);\n\n responseDocument[this.recordsListName] = documents;\n\n if (pagination) {\n responseDocument.pagination = pagination;\n }\n\n return response.success(responseDocument);\n } catch (error: any) {\n log.error(\"restful\", \"list\", error);\n return response.serverError(error);\n }\n }\n\n /**\n * Get single record\n */\n public async get({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"get\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound();\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"get\", error);\n\n throw error;\n }\n }\n\n /**\n * Create a new record\n */\n public async create({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"create\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const model = this.repository.newModel();\n const beforeCreate = await this.beforeCreate(request, response, model);\n\n if (beforeCreate) {\n return beforeCreate;\n }\n\n const beforeSave = await this.beforeSave(request, response, model);\n\n if (beforeSave) {\n return beforeSave;\n }\n\n // Save the model the hooks received, so their changes are not discarded\n await model.save(this.payload(\"create\", request));\n\n const record = model;\n\n const createOutput = await this.onCreate(request, response, record);\n\n if (createOutput) {\n return createOutput;\n }\n\n const saveOutput = await this.onSave(request, response, record);\n\n if (saveOutput) {\n return saveOutput;\n }\n\n if (this.returnOn.create === \"records\") {\n return this.list({ request, response });\n }\n\n return response.successCreate({\n [this.recordName]: record,\n });\n } catch (error: Error | any) {\n log.error(\"restful\", \"create\", error);\n\n // let the request error handler decide the status; never leak DB messages as 400\n throw error;\n }\n }\n\n /**\n * Update record\n */\n public async update({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"update\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n // Find record\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound({\n error: \"Record not found\",\n });\n }\n\n const beforeOutput = await this.beforeUpdate(request, response, record);\n if (beforeOutput) {\n return beforeOutput;\n }\n\n const beforeSafe = await this.beforeSave(request, response, record);\n\n if (beforeSafe) {\n return beforeSafe;\n }\n\n const oldRecord = record.clone();\n\n await record.save(this.payload(\"update\", request));\n\n await this.onUpdate(request, response, record, oldRecord);\n await this.onSave(request, response, record, oldRecord);\n\n if (this.returnOn.update === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"update\", error);\n\n throw error;\n }\n }\n\n /**\n * Patch record\n */\n public async patch({ request, response }: HttpContext) {\n try {\n const middlewareOutput = await this.callMiddleware(\"patch\", request, response);\n\n if (middlewareOutput) return middlewareOutput;\n\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound({\n error: \"Record not found\",\n });\n }\n\n const oldRecord = record.clone();\n\n const beforePatch = await this.beforePatch(request, response, record, oldRecord);\n\n if (beforePatch) {\n return beforePatch;\n }\n\n const beforeSave = await this.beforeSave(request, response, record, oldRecord);\n\n if (beforeSave) {\n return beforeSave;\n }\n\n await record.save(this.payload(\"patch\", request));\n\n await this.onPatch(request, response, record, oldRecord);\n await this.onSave(request, response, record, oldRecord);\n\n if (this.returnOn.patch === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n [this.recordName]: record,\n });\n } catch (error) {\n log.error(\"restful\", \"patch\", error);\n\n throw error;\n }\n }\n\n /**\n * Delete record\n */\n public async delete({ request, response }: HttpContext) {\n try {\n const record = await this.find(request.input(\"id\"));\n\n if (!record) {\n return response.notFound();\n }\n\n const middlewareOutput = await this.callMiddleware(\"delete\", request, response, record);\n\n if (middlewareOutput) return middlewareOutput;\n\n await this.beforeDelete(request, response, record);\n\n await record.destroy();\n\n this.onDelete(request, response, record);\n\n if (this.returnOn.delete === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success();\n } catch (error: Error | any) {\n log.error(\"restful\", \"delete\", error);\n\n throw error;\n }\n }\n\n /**\n * Bulk delete records\n */\n public async bulkDelete({ request, response }: HttpContext) {\n try {\n const ids = request.input(\"id\");\n\n if (!Array.isArray(ids)) {\n return response.badRequest({\n error: \"id must be an array\",\n });\n }\n\n const records = await this.repository.all({\n perform: (query: QueryBuilderContract<T>) =>\n query.whereIn(\n \"id\",\n ids.map((id) => (/^\\d+$/.test(String(id)) ? Number(id) : id)),\n ),\n });\n\n await Promise.all(\n records.map(async (record) => {\n if (await this.callMiddleware(\"delete\", request, response, record)) {\n return;\n }\n\n await this.beforeDelete(request, response, record);\n await record.destroy();\n this.onDelete(request, response, record);\n }),\n );\n\n if (this.returnOn.delete === \"records\") {\n return this.list({ request, response });\n }\n\n return response.success({\n deleted: records.length,\n });\n } catch (error: Error | any) {\n log.error(\"restful\", \"bulkDelete\", error);\n\n throw error;\n }\n }\n\n /**\n * Before create\n */\n protected async beforeCreate(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * On create\n */\n protected async onCreate(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * Before update\n */\n protected async beforeUpdate(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On update\n */\n protected async onUpdate(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Before delete\n */\n protected async beforeDelete(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * On delete\n */\n protected async onDelete(_request: Request, _response: Response, _record: T): Promise<any> {\n //\n }\n\n /**\n * Before patch\n */\n protected async beforePatch(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On patch\n */\n protected async onPatch(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Before save\n */\n protected async beforeSave(\n _request: Request,\n _response: Response,\n _record?: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * On save\n */\n protected async onSave(\n _request: Request,\n _response: Response,\n _record: T,\n _oldRecord?: T,\n ): Promise<any> {\n //\n }\n\n /**\n * Data to persist: only the validated input.\n * Without a validation schema the raw input is kept (legacy behaviour)\n * and a one-time warning names the resource.\n */\n protected payload(action: \"create\" | \"update\" | \"patch\", request: Request): GenericObject {\n const validation = (this as any).validation;\n\n if (validation?.all || validation?.[action]) {\n return request.validated();\n }\n\n if (!warnedUnvalidated.has(this.constructor)) {\n warnedUnvalidated.add(this.constructor);\n\n log.warn(\n \"restful\",\n \"validation\",\n this.constructor.name +\n \" has no validation schema: \" +\n action +\n \" persists unvalidated request input. Define a validation schema to persist only validated fields.\",\n );\n }\n\n if (action === \"create\") return request.all();\n\n return action === \"update\" ? request.allExceptParams() : request.heavyExceptParams();\n }\n\n /**\n * Call middleware for the given method\n *\n */\n protected async callMiddleware(\n method: string,\n request: Request,\n response: Response,\n _record?: any,\n ) {\n if (!this.middleware[method]) return;\n\n for (const middleware of this.middleware[method]) {\n const output = await middleware({ request, response });\n\n if (output) {\n return output;\n }\n }\n\n return;\n }\n}\n"],"mappings":";;;AAOA,MA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AAK;GAExC,MAAM;EACR;CACF;;;;CAKA,MAAgB,aAAa,UAAmB,WAAqB,SAA0B,CAE/F;;;;CAKA,MAAgB,SAAS,UAAmB,WAAqB,SAA0B,CAE3F;;;;CAKA,MAAgB,aACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,SACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,aAAa,UAAmB,WAAqB,SAA0B,CAE/F;;;;CAKA,MAAgB,SAAS,UAAmB,WAAqB,SAA0B,CAE3F;;;;CAKA,MAAgB,YACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,QACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,WACd,UACA,WACA,SACA,YACc,CAEhB;;;;CAKA,MAAgB,OACd,UACA,WACA,SACA,YACc,CAEhB;;;;;;CAOA,AAAU,QAAQ,QAAuC,SAAiC;EACxF,MAAM,aAAc,KAAa;EAEjC,IAAI,YAAY,OAAO,aAAa,SAClC,OAAO,QAAQ,UAAU;EAG3B,IAAI,CAAC,kBAAkB,IAAI,KAAK,WAAW,GAAG;GAC5C,kBAAkB,IAAI,KAAK,WAAW;GAEtC,IAAI,KACF,WACA,cACA,KAAK,YAAY,OACf,gCACA,SACA,mGACJ;EACF;EAEA,IAAI,WAAW,UAAU,OAAO,QAAQ,IAAI;EAE5C,OAAO,WAAW,WAAW,QAAQ,gBAAgB,IAAI,QAAQ,kBAAkB;CACrF;;;;;CAMA,MAAgB,eACd,QACA,SACA,UACA,SACA;EACA,IAAI,CAAC,KAAK,WAAW,SAAS;EAE9B,KAAK,MAAM,cAAc,KAAK,WAAW,SAAS;GAChD,MAAM,SAAS,MAAM,WAAW;IAAE;IAAS;GAAS,CAAC;GAErD,IAAI,QACF,OAAO;EAEX;CAGF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-route-rate-limit.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/build-route-rate-limit.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"build-route-rate-limit.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/build-route-rate-limit.ts"],"sourcesContent":["import type { RouteRateLimitOptions } from \"./types\";\n\n/**\n * Turn a route's `rateLimit` option into `@fastify/rate-limit` route config.\n * `errorMessage` is not a plugin option, so it is mapped to\n * `errorResponseBuilder`; the rest passes through unchanged.\n */\nexport function buildRouteRateLimit(rateLimit: RouteRateLimitOptions) {\n const { errorMessage, ...rest } = rateLimit;\n\n if (!errorMessage) {\n return rest;\n }\n\n return {\n ...rest,\n errorResponseBuilder: () => ({\n statusCode: 429,\n error: \"Too Many Requests\",\n message: errorMessage,\n }),\n };\n}\n"],"mappings":";;;;;;AAOA,SAAgB,oBAAoB,WAAkC;CACpE,MAAM,EAAE,cAAc,GAAG,SAAS;CAElC,IAAI,CAAC,cACH,OAAO;CAGT,OAAO;EACL,GAAG;EACH,6BAA6B;GAC3B,YAAY;GACZ,OAAO;GACP,SAAS;EACX;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveRouteRateLimit } from "./resolve-route-rate-limit.mjs";
|
|
2
2
|
|
|
3
3
|
//#region ../../packages/core/src/router/dev-dispatch.ts
|
|
4
4
|
/**
|
|
@@ -27,28 +27,47 @@ function buildNotFoundBody(method, url) {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Rate limiting for the dev wildcard dispatcher, with the same outcome per
|
|
31
|
+
* route as production registration.
|
|
31
32
|
*
|
|
32
33
|
* `@fastify/rate-limit` reads `config.rateLimit` in its `onRoute` hook, which
|
|
33
|
-
* never sees individual routes behind a wildcard.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* never sees individual routes behind a wildcard. The wildcard is therefore
|
|
35
|
+
* registered exempt (`config.rateLimit: false`) and each matched route is
|
|
36
|
+
* limited here through `server.rateLimit(options)`, resolved by the same
|
|
37
|
+
* `resolveRouteRateLimit` that `scan()` uses:
|
|
38
|
+
*
|
|
39
|
+
* - a route's own limit gets its own limiter (cached per route + method so
|
|
40
|
+
* counters survive across requests, and `all` routes count per verb as
|
|
41
|
+
* they do in production);
|
|
42
|
+
* - an exempt route (`rateLimit: false`, a passed-through
|
|
43
|
+
* `serverOptions.config.rateLimit: false`, or a static file route) is not
|
|
44
|
+
* limited;
|
|
45
|
+
* - every other route shares the global limiter and its bucket, the same one
|
|
46
|
+
* the plugin's `onRoute` hook gives routes registered on Fastify directly.
|
|
47
|
+
*
|
|
48
|
+
* Unmatched requests are not limited, like production's not-found handler.
|
|
37
49
|
*/
|
|
38
|
-
function createDevRateLimiter(server) {
|
|
50
|
+
function createDevRateLimiter(server, globalLimit) {
|
|
39
51
|
const limiters = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
let globalLimiter;
|
|
40
53
|
return async (route, request, reply) => {
|
|
41
|
-
const options = route.rateLimit;
|
|
42
54
|
const factory = server.rateLimit;
|
|
43
|
-
if (
|
|
44
|
-
|
|
55
|
+
if (typeof factory !== "function") return;
|
|
56
|
+
const setting = resolveRouteRateLimit(route);
|
|
57
|
+
if (setting === false) return;
|
|
58
|
+
if (setting === void 0) {
|
|
59
|
+
if (!globalLimit) return void 0;
|
|
60
|
+
globalLimiter ??= factory.call(server);
|
|
61
|
+
return globalLimiter(request, reply);
|
|
62
|
+
}
|
|
63
|
+
let byMethod = limiters.get(route);
|
|
45
64
|
if (!byMethod) {
|
|
46
65
|
byMethod = /* @__PURE__ */ new Map();
|
|
47
|
-
limiters.set(
|
|
66
|
+
limiters.set(route, byMethod);
|
|
48
67
|
}
|
|
49
68
|
let limiter = byMethod.get(request.method);
|
|
50
69
|
if (!limiter) {
|
|
51
|
-
limiter = factory.call(server,
|
|
70
|
+
limiter = factory.call(server, setting);
|
|
52
71
|
byMethod.set(request.method, limiter);
|
|
53
72
|
}
|
|
54
73
|
return limiter(request, reply);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-dispatch.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/dev-dispatch.ts"],"sourcesContent":["import type { FastifyInstance, FastifyReply, FastifyRequest } from \"fastify\";\nimport {
|
|
1
|
+
{"version":3,"file":"dev-dispatch.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/dev-dispatch.ts"],"sourcesContent":["import type { FastifyInstance, FastifyReply, FastifyRequest } from \"fastify\";\nimport { resolveRouteRateLimit } from \"./resolve-route-rate-limit\";\nimport type { Route } from \"./types\";\n\n/**\n * Every verb the dev wildcard answers. Mirrors what production registers per\n * route: `head`/`options` routes are ordinary registrations there, so the dev\n * dispatcher must be reachable for them too.\n */\nexport const DEV_DISPATCH_METHODS = [\n \"GET\",\n \"HEAD\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"PATCH\",\n \"OPTIONS\",\n] as const;\n\n/**\n * The body of an unmatched request — Fastify's own default 404 shape, so an\n * unknown URL looks the same in dev as it does in production.\n */\nexport function buildNotFoundBody(method: string, url: string) {\n return {\n message: `Route ${method}:${url} not found`,\n error: \"Not Found\",\n statusCode: 404,\n };\n}\n\ntype RateLimitHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<unknown>;\n\ntype RateLimitFactory = (options?: Record<string, unknown>) => RateLimitHandler;\n\n/**\n * Rate limiting for the dev wildcard dispatcher, with the same outcome per\n * route as production registration.\n *\n * `@fastify/rate-limit` reads `config.rateLimit` in its `onRoute` hook, which\n * never sees individual routes behind a wildcard. The wildcard is therefore\n * registered exempt (`config.rateLimit: false`) and each matched route is\n * limited here through `server.rateLimit(options)`, resolved by the same\n * `resolveRouteRateLimit` that `scan()` uses:\n *\n * - a route's own limit gets its own limiter (cached per route + method so\n * counters survive across requests, and `all` routes count per verb as\n * they do in production);\n * - an exempt route (`rateLimit: false`, a passed-through\n * `serverOptions.config.rateLimit: false`, or a static file route) is not\n * limited;\n * - every other route shares the global limiter and its bucket, the same one\n * the plugin's `onRoute` hook gives routes registered on Fastify directly.\n *\n * Unmatched requests are not limited, like production's not-found handler.\n */\nexport function createDevRateLimiter(server: FastifyInstance, globalLimit: boolean) {\n const limiters = new WeakMap<Route, Map<string, RateLimitHandler>>();\n let globalLimiter: RateLimitHandler | undefined;\n\n return async (route: Route, request: FastifyRequest, reply: FastifyReply) => {\n const factory = (server as unknown as { rateLimit?: RateLimitFactory }).rateLimit;\n\n if (typeof factory !== \"function\") {\n return undefined;\n }\n\n const setting = resolveRouteRateLimit(route);\n\n if (setting === false) {\n return undefined;\n }\n\n if (setting === undefined) {\n if (!globalLimit) return undefined;\n\n // No options: the plugin's own global params and store, so dev\n // requests share the bucket of routes registered on Fastify directly.\n globalLimiter ??= factory.call(server);\n\n return globalLimiter(request, reply);\n }\n\n let byMethod = limiters.get(route);\n\n if (!byMethod) {\n byMethod = new Map();\n limiters.set(route, byMethod);\n }\n\n // `all` routes are expanded per verb in production, each with its own counter.\n let limiter = byMethod.get(request.method);\n\n if (!limiter) {\n limiter = factory.call(server, setting);\n byMethod.set(request.method, limiter);\n }\n\n return limiter(request, reply);\n };\n}\n"],"mappings":";;;;;;;;AASA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,SAAgB,kBAAkB,QAAgB,KAAa;CAC7D,OAAO;EACL,SAAS,SAAS,OAAO,GAAG,IAAI;EAChC,OAAO;EACP,YAAY;CACd;AACF;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,qBAAqB,QAAyB,aAAsB;CAClF,MAAM,2BAAW,IAAI,QAA8C;CACnE,IAAI;CAEJ,OAAO,OAAO,OAAc,SAAyB,UAAwB;EAC3E,MAAM,UAAW,OAAuD;EAExE,IAAI,OAAO,YAAY,YACrB;EAGF,MAAM,UAAU,sBAAsB,KAAK;EAE3C,IAAI,YAAY,OACd;EAGF,IAAI,YAAY,QAAW;GACzB,IAAI,CAAC,aAAa,OAAO;GAIzB,kBAAkB,QAAQ,KAAK,MAAM;GAErC,OAAO,cAAc,SAAS,KAAK;EACrC;EAEA,IAAI,WAAW,SAAS,IAAI,KAAK;EAEjC,IAAI,CAAC,UAAU;GACb,2BAAW,IAAI,IAAI;GACnB,SAAS,IAAI,OAAO,QAAQ;EAC9B;EAGA,IAAI,UAAU,SAAS,IAAI,QAAQ,MAAM;EAEzC,IAAI,CAAC,SAAS;GACZ,UAAU,QAAQ,KAAK,QAAQ,OAAO;GACtC,SAAS,IAAI,QAAQ,QAAQ,OAAO;EACtC;EAEA,OAAO,QAAQ,SAAS,KAAK;CAC/B;AACF"}
|
package/esm/router/index.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { normalizeRoutePath } from "./normalize-route-path.mjs";
|
|
2
2
|
import { normalizeRequestPath } from "./normalize-request-path.mjs";
|
|
3
|
-
import { GroupedRoutesOptions, HttpContext, Middleware, MiddlewareResponse, NamedApiRoute, NamedApiRoutesOptions, PartialPick, RequestControllerContract, RequestHandler, RequestHandlerType, RequestHandlerValidation, RequestMethod, ResourceMethod, RestfulMiddleware, Route, RouteOptions, RouteResource, RouterGroupCallback, RouterStacks } from "./types.mjs";
|
|
3
|
+
import { GroupedRoutesOptions, HttpContext, Middleware, MiddlewareResponse, NamedApiRoute, NamedApiRoutesOptions, PartialPick, RequestControllerContract, RequestHandler, RequestHandlerType, RequestHandlerValidation, RequestMethod, ResourceMethod, RestfulMiddleware, Route, RouteOptions, RouteRateLimitOptions, RouteResource, RouterGroupCallback, RouterStacks, StaticMountOptions, ValidationFailureContext, ValidationFailureHandler, ValidationFailureResponse } from "./types.mjs";
|
|
4
4
|
import { PositionalHandlerSuspect, clearPositionalHandlerSuspects, describePositionalHandlerSuspect, forgetPositionalHandlerSuspects, inspectHandlerSignature, listPositionalHandlerSuspects, looksLikePositionalHandler, reportPositionalHandlerSuspects } from "./positional-handler-diagnostics.mjs";
|
|
5
5
|
import { matchesDerivedRouteName, routeNameMethodSuffix } from "./route-name-method-suffix.mjs";
|
|
6
|
+
import { RouteNameTakenError } from "./route-name-taken-error.mjs";
|
|
6
7
|
import { RouteRegistry } from "./route-registry.mjs";
|
|
7
|
-
import { Router, router } from "./router.mjs";
|
|
8
|
+
import { Router, router } from "./router.mjs";
|
|
9
|
+
import { AUTH_GUARD_MARKER, isAuthGuardMiddleware, isUnguardedMutatingRoute, markAuthGuard, reportUnguardedMutatingRoutes, resetUnguardedRouteReports } from "./unguarded-route-diagnostics.mjs";
|
package/esm/router/index.mjs
CHANGED
|
@@ -2,7 +2,9 @@ import { normalizeRoutePath } from "./normalize-route-path.mjs";
|
|
|
2
2
|
import { normalizeRequestPath } from "./normalize-request-path.mjs";
|
|
3
3
|
import { clearPositionalHandlerSuspects, describePositionalHandlerSuspect, forgetPositionalHandlerSuspects, inspectHandlerSignature, listPositionalHandlerSuspects, looksLikePositionalHandler, reportPositionalHandlerSuspects } from "./positional-handler-diagnostics.mjs";
|
|
4
4
|
import { matchesDerivedRouteName, routeNameMethodSuffix } from "./route-name-method-suffix.mjs";
|
|
5
|
+
import { RouteNameTakenError } from "./route-name-taken-error.mjs";
|
|
5
6
|
import { RouteRegistry } from "./route-registry.mjs";
|
|
7
|
+
import { AUTH_GUARD_MARKER, isAuthGuardMiddleware, isUnguardedMutatingRoute, markAuthGuard, reportUnguardedMutatingRoutes, resetUnguardedRouteReports } from "./unguarded-route-diagnostics.mjs";
|
|
6
8
|
import { Router, router } from "./router.mjs";
|
|
7
9
|
|
|
8
10
|
export { };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-request-lifecycle.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/log-request-lifecycle.ts"],"sourcesContent":["/**\n * Both ends of a request's log entry.\n *\n * ## Why the completion line exists\n *\n * The router logged `Starting Request: <id>` and nothing else. A request that\n * hung for thirty seconds and one that returned in two milliseconds produced\n * **byte-identical output**, so the log could not answer the one question\n * anyone opens it to ask.\n *\n * Note what \"detecting a hang\" actually means. Nothing can log the completion\n * of a request that never completes — the mechanism is the **absence** of a\n * completion line beside a start line that has one. That only works if the\n * completion line is emitted on every settled path, **including a throw**,\n * which is why the error path here is not an afterthought.\n *\n * ## Why the level tracks the status\n *\n * A handled 500 does not throw; it returns a response. Logging it at `info`\n * would bury the exact entries someone scanning the log is hunting for, so the\n * level is derived from the outcome: informational below 400, a warning for\n * client errors, an error for server errors and for anything that threw.\n *\n * ## Ports rather than a direct `log` import\n *\n * The behaviour worth pinning down is *which lines come out, in which order,\n * at which level, when the run throws*. Injecting the sink and the clock makes\n * that assertable without a server, a socket or a fake timer.\n *\n * ## Tracing\n *\n * This function is the single funnel for both the success and throw paths\n * (the try/catch below), and it already reads the settled status via\n * `descriptor.statusCode()` after the run settles — the natural place to\n * fire `onRequestStart` / `onRequestEnd`, since that is when the response is\n * actually written and a trace can record what really happened. Gated on\n * `isTracingEnabled()` before building any context object, so a disabled app\n * pays one boolean check and allocates nothing extra.\n */\nimport type { Request } from \"../http/request\";\nimport {
|
|
1
|
+
{"version":3,"file":"log-request-lifecycle.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/log-request-lifecycle.ts"],"sourcesContent":["/**\n * Both ends of a request's log entry.\n *\n * ## Why the completion line exists\n *\n * The router logged `Starting Request: <id>` and nothing else. A request that\n * hung for thirty seconds and one that returned in two milliseconds produced\n * **byte-identical output**, so the log could not answer the one question\n * anyone opens it to ask.\n *\n * Note what \"detecting a hang\" actually means. Nothing can log the completion\n * of a request that never completes — the mechanism is the **absence** of a\n * completion line beside a start line that has one. That only works if the\n * completion line is emitted on every settled path, **including a throw**,\n * which is why the error path here is not an afterthought.\n *\n * ## Why the level tracks the status\n *\n * A handled 500 does not throw; it returns a response. Logging it at `info`\n * would bury the exact entries someone scanning the log is hunting for, so the\n * level is derived from the outcome: informational below 400, a warning for\n * client errors, an error for server errors and for anything that threw.\n *\n * ## Ports rather than a direct `log` import\n *\n * The behaviour worth pinning down is *which lines come out, in which order,\n * at which level, when the run throws*. Injecting the sink and the clock makes\n * that assertable without a server, a socket or a fake timer.\n *\n * ## Tracing\n *\n * This function is the single funnel for both the success and throw paths\n * (the try/catch below), and it already reads the settled status via\n * `descriptor.statusCode()` after the run settles — the natural place to\n * fire `onRequestStart` / `onRequestEnd`, since that is when the response is\n * actually written and a trace can record what really happened. Gated on\n * `isTracingEnabled()` before building any context object, so a disabled app\n * pays one boolean check and allocates nothing extra.\n */\nimport type { Request } from \"../http/request\";\nimport {\n buildTracingContext,\n dispatchRequestEnd,\n dispatchRequestStart,\n isTracingEnabled,\n} from \"../http/tracing\";\n\nexport type RequestLogEntry = {\n module: string;\n action: string;\n message: string;\n /**\n * Typed as the logger accepts it, not as `unknown`. These entries exist to be\n * handed to `log.info` / `warn` / `error`, whose parameter is\n * `Record<string, any>` — `unknown` was not assignable, so the adapter in\n * router.ts could not compile even though every real caller passes an object.\n */\n context?: Record<string, any>;\n};\n\nexport type RequestLogPorts = {\n info(entry: RequestLogEntry): void;\n warn(entry: RequestLogEntry): void;\n error(entry: RequestLogEntry): void;\n /** Monotonic milliseconds. Called exactly twice per request. */\n now(): number;\n};\n\nexport type RequestLogDescriptor = {\n module: string;\n action: string;\n requestId: string;\n /**\n * Typed as the logger accepts it, not as `unknown`. These entries exist to be\n * handed to `log.info` / `warn` / `error`, whose parameter is\n * `Record<string, any>` — `unknown` was not assignable, so the adapter in\n * router.ts could not compile even though every real caller passes an object.\n */\n context?: Record<string, any>;\n /**\n * Read AFTER the run settles — the status is decided during the request, so\n * capturing it up front would report the default on every entry.\n */\n statusCode(): number | undefined;\n /**\n * The `Request` instance, when tracing needs it to build\n * the `TracingContext` for `onRequestStart` / `onRequestEnd`. Optional —\n * absent, tracing dispatch for this request is skipped, which is correct\n * for any non-HTTP caller of this same lifecycle wrapper.\n */\n request?: Request;\n};\n\ntype Level = \"info\" | \"warn\" | \"error\";\n\nfunction levelForStatus(statusCode: number | undefined): Level {\n // An unknown status is not evidence of a problem; saying \"error\" because we\n // failed to read a number would be inventing a defect.\n if (statusCode === undefined) return \"info\";\n\n if (statusCode >= 500) return \"error\";\n\n if (statusCode >= 400) return \"warn\";\n\n return \"info\";\n}\n\nexport async function logRequestLifecycle<TResult>(\n ports: RequestLogPorts,\n descriptor: RequestLogDescriptor,\n run: () => Promise<TResult>,\n): Promise<TResult> {\n const startedAt = ports.now();\n const tracingEnabled = isTracingEnabled();\n\n ports.info({\n module: descriptor.module,\n action: descriptor.action,\n message: `Starting Request: ${descriptor.requestId}`,\n context: descriptor.context,\n });\n\n if (tracingEnabled && descriptor.request) {\n dispatchRequestStart(buildTracingContext(descriptor.request));\n }\n\n const finish = (level: Level, outcome: string, error?: unknown): void => {\n const duration = Math.round(ports.now() - startedAt);\n\n ports[level]({\n module: descriptor.module,\n action: descriptor.action,\n message: `Completed Request: ${descriptor.requestId} — ${outcome} in ${duration}ms`,\n context: descriptor.context,\n });\n\n if (tracingEnabled && descriptor.request) {\n dispatchRequestEnd(buildTracingContext(descriptor.request), {\n status: descriptor.statusCode(),\n durationMs: duration,\n error,\n });\n }\n };\n\n try {\n const result = await run();\n\n const statusCode = descriptor.statusCode();\n\n finish(levelForStatus(statusCode), statusCode === undefined ? \"no status\" : String(statusCode));\n\n return result;\n } catch (error) {\n // The throw is reported and then re-thrown untouched: this function\n // observes the request, it does not own its error handling.\n finish(\"error\", `threw ${error instanceof Error ? error.name : typeof error}`, error);\n\n throw error;\n }\n}\n"],"mappings":";;;;AA+FA,SAAS,eAAe,YAAuC;CAG7D,IAAI,eAAe,QAAW,OAAO;CAErC,IAAI,cAAc,KAAK,OAAO;CAE9B,IAAI,cAAc,KAAK,OAAO;CAE9B,OAAO;AACT;AAEA,eAAsB,oBACpB,OACA,YACA,KACkB;CAClB,MAAM,YAAY,MAAM,IAAI;CAC5B,MAAM,iBAAiB,iBAAiB;CAExC,MAAM,KAAK;EACT,QAAQ,WAAW;EACnB,QAAQ,WAAW;EACnB,SAAS,qBAAqB,WAAW;EACzC,SAAS,WAAW;CACtB,CAAC;CAED,IAAI,kBAAkB,WAAW,SAC/B,qBAAqB,oBAAoB,WAAW,OAAO,CAAC;CAG9D,MAAM,UAAU,OAAc,SAAiB,UAA0B;EACvE,MAAM,WAAW,KAAK,MAAM,MAAM,IAAI,IAAI,SAAS;EAEnD,MAAM,MAAM,CAAC;GACX,QAAQ,WAAW;GACnB,QAAQ,WAAW;GACnB,SAAS,sBAAsB,WAAW,UAAU,KAAK,QAAQ,MAAM,SAAS;GAChF,SAAS,WAAW;EACtB,CAAC;EAED,IAAI,kBAAkB,WAAW,SAC/B,mBAAmB,oBAAoB,WAAW,OAAO,GAAG;GAC1D,QAAQ,WAAW,WAAW;GAC9B,YAAY;GACZ;EACF,CAAC;CAEL;CAEA,IAAI;EACF,MAAM,SAAS,MAAM,IAAI;EAEzB,MAAM,aAAa,WAAW,WAAW;EAEzC,OAAO,eAAe,UAAU,GAAG,eAAe,SAAY,cAAc,OAAO,UAAU,CAAC;EAE9F,OAAO;CACT,SAAS,OAAO;EAGd,OAAO,SAAS,SAAS,iBAAiB,QAAQ,MAAM,OAAO,OAAO,SAAS,KAAK;EAEpF,MAAM;CACR;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positional-handler-diagnostics.d.mts","names":[],"sources":["../../../../../../../../packages/core/src/router/positional-handler-diagnostics.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"positional-handler-diagnostics.d.mts","names":[],"sources":["../../../../../../../../packages/core/src/router/positional-handler-diagnostics.ts"],"mappings":";;;;AAiQsE;AAmBtE;;AAnBsE,KA7N1D,wBAAA;EAgPsE,kDA9OhF,MAAA,EAAQ,KAAK,YAuPC;EApPd,IAAA;EAGA,WAAA,UAiPgE;EA9OhE,UAAA;AAAA;;;AA4P4C;AAS9C;;;;AAAkF;AAclF;;;;;;;;;;;;;AAAsF;;;;;;;;;;;iBAtGtE,0BAAA,CAA2B,OAAgB;;;;;;;;;iBAmC3C,uBAAA,CACd,OAAA,WACA,KAAA;EAAS,MAAA,EAAQ,KAAK;EAAY,IAAA;EAAc,UAAA;AAAA;;;;iBAmBlC,6BAAA,aAA0C,wBAAwB;;;;;;iBASlE,+BAAA,CAAgC,UAAkB;;;;;iBAclD,8BAAA;;;;;;iBASA,gCAAA,CAAiC,OAAiC,EAAxB,wBAAwB;;;;;;;iBAclE,+BAAA,CAAgC,MAAA,GAAQ,IAAA,QAAY,GAAA,YAAkB,wBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positional-handler-diagnostics.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/positional-handler-diagnostics.ts"],"sourcesContent":["/**\n * Early detection of route handlers still written against the **v4 positional\n * signature** — `(request, response)` — after v5 moved to a single context\n * object, `({ request, response })`.\n *\n * ## Why this exists\n *\n * A v4 handler is not rejected anywhere. It registers fine, and the router\n * calls it with one argument, so `response` is simply `undefined`. The app only\n * breaks on the first request that reaches it, with:\n *\n * TypeError: Cannot read properties of undefined (reading 'success')\n *\n * That message names nothing the reader can act on — not the route, not the\n * handler, not the change to make. This module turns that late, opaque failure\n * into one explicit list printed at boot, and into a `warlock doctor` check.\n *\n * The break itself is intentional; nothing here restores the positional form.\n * Detection and diagnostics only.\n *\n * ## Why it warns and never throws\n *\n * The signal is a heuristic (see {@link looksLikePositionalHandler}), so a\n * false positive is possible in principle. Turning one into a boot failure\n * would take a working application down over a guess, which is strictly worse\n * than the problem being diagnosed. Everything on this path is therefore a\n * warning: nothing here throws, and nothing here changes how a handler is\n * called. A miss simply degrades to the old runtime `TypeError`.\n */\n\nimport { log } from \"@warlock.js/logger\";\nimport type { Route } from \"./types\";\n\n/**\n * One route whose handler looks like it was written for v4.\n */\nexport type PositionalHandlerSuspect = {\n /** HTTP method the route was registered under. */\n method: Route[\"method\"];\n\n /** Full route path, prefixes already applied. */\n path: string;\n\n /** Handler function name, or `\"(anonymous)\"` when it has none. */\n handlerName: string;\n\n /** Route file the route came from, when the router knows it. */\n sourceFile: string;\n};\n\n/**\n * Collected across the whole registration pass so the warning can be emitted\n * ONCE, as a single list, rather than one line per route (or — as before — one\n * mystery 500 per request).\n */\nconst suspects: PositionalHandlerSuspect[] = [];\n\n/**\n * Split the parameter list of a function's source into top-level parameters.\n *\n * Depth-aware and quote-aware, because a default value may itself contain\n * commas, parentheses, braces or strings — `(request, response = f(a, b))` is\n * two parameters, not three. Anything unbalanced returns `undefined`: refusing\n * to guess is what keeps a parse quirk from becoming a false warning.\n *\n * @param openIndex index of the `(` that opens the parameter list.\n */\nfunction splitTopLevelParameters(source: string, openIndex: number): string[] | undefined {\n const parameters: string[] = [];\n\n let depth = 0;\n let current = \"\";\n let quote = \"\";\n\n for (let index = openIndex; index < source.length; index++) {\n const char = source[index];\n\n if (quote) {\n if (char === \"\\\\\") {\n current += char + (source[index + 1] ?? \"\");\n index++;\n continue;\n }\n\n if (char === quote) {\n quote = \"\";\n }\n\n current += char;\n continue;\n }\n\n if (char === '\"' || char === \"'\" || char === \"`\") {\n quote = char;\n current += char;\n continue;\n }\n\n if (char === \"(\" || char === \"[\" || char === \"{\") {\n depth++;\n\n // The paren that opens the list is punctuation, not part of a parameter.\n if (depth === 1) continue;\n\n current += char;\n continue;\n }\n\n if (char === \")\" || char === \"]\" || char === \"}\") {\n depth--;\n\n if (depth === 0) {\n if (current.trim()) {\n parameters.push(current.trim());\n }\n\n return parameters;\n }\n\n current += char;\n continue;\n }\n\n if (char === \",\" && depth === 1) {\n parameters.push(current.trim());\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n // Never found the closing paren — treat the source as unreadable.\n return undefined;\n}\n\n/**\n * Read a function's declared parameters from its own source.\n *\n * Returns `undefined` whenever the source cannot be trusted, which callers must\n * treat as \"no information\" rather than \"no parameters\":\n *\n * - `Function.prototype.bind` replaces the body with `[native code]`, so every\n * `[Controller, \"method\"]` tuple handler lands here (the router binds them);\n * - native functions likewise;\n * - a class, whose first `(` belongs to a constructor or a method, not to a\n * parameter list;\n * - anything that fails to parse.\n */\nfunction readParameterList(handler: Function): string[] | undefined {\n let source: string;\n\n try {\n source = Function.prototype.toString.call(handler);\n } catch {\n return undefined;\n }\n\n if (source.includes(\"[native code]\")) return undefined;\n\n if (/^\\s*class[\\s{]/.test(source)) return undefined;\n\n // A single parameter needs no parentheses: `ctx => …`, `async ctx => …`.\n const bareArrow = source.match(/^\\s*(?:async\\s+)?([A-Za-z_$][\\w$]*)\\s*=>/);\n\n if (bareArrow) {\n const parameter = bareArrow[1];\n\n return parameter === undefined ? undefined : [parameter];\n }\n\n const openIndex = source.indexOf(\"(\");\n\n if (openIndex === -1) return undefined;\n\n return splitTopLevelParameters(source, openIndex);\n}\n\n/**\n * Whether a parameter is written as a destructuring pattern — `{ request }` or\n * `[a, b]` — as opposed to a plain name.\n */\nfunction isDestructured(parameter: string) {\n const start = parameter.trimStart();\n\n return start.startsWith(\"{\") || start.startsWith(\"[\");\n}\n\n/**\n * Does this handler look like it was written for the v4 positional signature?\n *\n * ## The signal, and what it misses\n *\n * `Function.length` alone is not enough, because it stops counting at the first\n * defaulted parameter:\n *\n * | handler | `.length` | actually |\n * | ---------------------------------- | --------- | -------- |\n * | `({ request, response }) => …` | 1 | v5 |\n * | `(ctx) => …` | 1 | v5 |\n * | `(request, response) => …` | 2 | v4 |\n * | `(request, response = x) => …` | 1 | v4 |\n *\n * So the primary signal is the function's own source: a handler is suspect when\n * it declares **two or more** parameters and the first is **not** destructured.\n * Reading the source catches the defaulted row that arity cannot, and rules out\n * the `({ … }, extra)` shape that arity would wrongly flag.\n *\n * When the source is unreadable — a bound or native function — this falls back\n * to `handler.length >= 2`, which `bind` preserves. That is a weaker signal but\n * never a wrong one for the common cases; it only loses the defaulted row.\n *\n * ## What is still missed, by design\n *\n * A one-parameter v4 handler (`(request) => …`) is indistinguishable from a v5\n * `(ctx) => …` and is deliberately not flagged — guessing there would produce\n * false positives on correct code. False positives against the canonical\n * `({ … })` form are essentially nil, and every miss simply leaves today's\n * behaviour in place.\n */\nexport function looksLikePositionalHandler(handler: unknown): boolean {\n if (typeof handler !== \"function\") return false;\n\n const parameters = readParameterList(handler);\n\n if (parameters) {\n const firstParameter = parameters[0];\n\n return parameters.length >= 2 && firstParameter !== undefined && !isDestructured(firstParameter);\n }\n\n return handler.length >= 2;\n}\n\n/**\n * The name to print for a handler.\n *\n * `Function.bind` prefixes the name with `\"bound \"`, and the router binds every\n * `[Controller, \"method\"]` tuple handler. The bare method name is what the user\n * actually wrote, so that is what gets printed.\n */\nfunction handlerDisplayName(handler: Function): string {\n return handler.name?.replace(/^bound /, \"\").trim() || \"(anonymous)\";\n}\n\n/**\n * Inspect one route's handler as it registers, recording it when it looks like\n * the v4 positional form. Called from `Router.add`, so the cost is paid once per\n * route at registration and never per request.\n *\n * Deliberately total: any unexpected failure in the heuristic is swallowed, so a\n * diagnostic can never be the reason a route fails to register.\n */\nexport function inspectHandlerSignature(\n handler: unknown,\n route: { method: Route[\"method\"]; path: string; sourceFile: string },\n) {\n try {\n if (!looksLikePositionalHandler(handler)) return;\n\n suspects.push({\n method: route.method,\n path: route.path,\n handlerName: handlerDisplayName(handler as Function),\n sourceFile: route.sourceFile,\n });\n } catch {\n // A diagnostic must never break registration.\n }\n}\n\n/**\n * Every suspect recorded so far, in registration order.\n */\nexport function listPositionalHandlerSuspects(): readonly PositionalHandlerSuspect[] {\n return suspects;\n}\n\n/**\n * Drop the suspects belonging to a route file. Kept in step with\n * `Router.removeRoutesBySourceFile` so an HMR reload that fixes a handler does\n * not keep reporting the version it replaced.\n */\nexport function forgetPositionalHandlerSuspects(sourceFile: string) {\n for (let index = suspects.length - 1; index >= 0; index--) {\n const suspect = suspects[index];\n\n if (suspect?.sourceFile === sourceFile) {\n suspects.splice(index, 1);\n }\n }\n}\n\n/**\n * Drop every recorded suspect. Intended for tests, which share the router\n * singleton.\n */\nexport function clearPositionalHandlerSuspects() {\n suspects.length = 0;\n}\n\n/**\n * The one-line diagnostic for a single route. Written for someone who has never\n * read Warlock's internals: it names the handler, the route, what is wrong, and\n * the exact edit that fixes it.\n */\nexport function describePositionalHandlerSuspect(suspect: PositionalHandlerSuspect): string {\n return (\n `Handler \"${suspect.handlerName}\" (${suspect.method} ${suspect.path}) looks like ` +\n `the v4 positional signature (request, response). ` +\n `v5 passes a single context object — change it to ({ request, response }).`\n );\n}\n\n/**\n * The full boot-time warning: every suspect, once, in one entry.\n *\n * One boot, one list — not one warning per route, and emphatically not one 500\n * per request. Returns the reported suspects so callers can assert on them.\n */\nexport function reportPositionalHandlerSuspects(logger: Pick<typeof log, \"warn\"> = log) {\n const reported = [...suspects];\n\n if (reported.length === 0) return reported;\n\n const headline =\n reported.length === 1\n ? \"1 route handler looks like the v4 positional signature.\"\n : `${reported.length} route handlers look like the v4 positional signature.`;\n\n logger.warn({\n module: \"router\",\n action: \"handlerSignature\",\n message:\n `${headline} Warlock v5 calls every route handler with a single context object, ` +\n `so a second parameter is always undefined and the request fails as soon as it is used:\\n` +\n reported.map((suspect) => ` - ${describePositionalHandlerSuspect(suspect)}`).join(\"\\n\"),\n context: { handlers: reported },\n });\n\n return reported;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,WAAuC,CAAC;;;;;;;;;;;AAY9C,SAAS,wBAAwB,QAAgB,WAAyC;CACxF,MAAM,aAAuB,CAAC;CAE9B,IAAI,QAAQ;CACZ,IAAI,UAAU;CACd,IAAI,QAAQ;CAEZ,KAAK,IAAI,QAAQ,WAAW,QAAQ,OAAO,QAAQ,SAAS;EAC1D,MAAM,OAAO,OAAO;EAEpB,IAAI,OAAO;GACT,IAAI,SAAS,MAAM;IACjB,WAAW,QAAQ,OAAO,QAAQ,MAAM;IACxC;IACA;GACF;GAEA,IAAI,SAAS,OACX,QAAQ;GAGV,WAAW;GACX;EACF;EAEA,IAAI,SAAS,QAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ;GACR,WAAW;GACX;EACF;EAEA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS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;AASA,SAAS,mBAAmB,SAA2B;CACrD,OAAO,QAAQ,MAAM,QAAQ,WAAW,EAAE,CAAC,CAAC,KAAK,KAAK;AACxD;;;;;;;;;AAUA,SAAgB,wBACd,SACA,OACA;CACA,IAAI;EACF,IAAI,CAAC,2BAA2B,OAAO,GAAG;EAE1C,SAAS,KAAK;GACZ,QAAQ,MAAM;GACd,MAAM,MAAM;GACZ,aAAa,mBAAmB,OAAmB;GACnD,YAAY,MAAM;EACpB,CAAC;CACH,QAAQ,CAER;AACF;;;;AAKA,SAAgB,gCAAqE;CACnF,OAAO;AACT;;;;;;AAOA,SAAgB,gCAAgC,YAAoB;CAClE,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,SAAS,GAAG,SAGhD,IAFgB,SAAS,MAEd,EAAE,eAAe,YAC1B,SAAS,OAAO,OAAO,CAAC;AAG9B;;;;;AAMA,SAAgB,iCAAiC;CAC/C,SAAS,SAAS;AACpB;;;;;;AAOA,SAAgB,iCAAiC,SAA2C;CAC1F,OACE,YAAY,QAAQ,YAAY,KAAK,QAAQ,OAAO,GAAG,QAAQ,KAAK;AAIxE;;;;;;;AAQA,SAAgB,gCAAgC,SAAmC,KAAK;CACtF,MAAM,WAAW,CAAC,GAAG,QAAQ;CAE7B,IAAI,SAAS,WAAW,GAAG,OAAO;CAElC,MAAM,WACJ,SAAS,WAAW,IAChB,4DACA,GAAG,SAAS,OAAO;CAEzB,OAAO,KAAK;EACV,QAAQ;EACR,QAAQ;EACR,SACE,GAAG,SAAS,gKAEZ,SAAS,KAAK,YAAY,OAAO,iCAAiC,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI;EACzF,SAAS,EAAE,UAAU,SAAS;CAChC,CAAC;CAED,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"positional-handler-diagnostics.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/positional-handler-diagnostics.ts"],"sourcesContent":["/**\n * Early detection of route handlers still written against the **v4 positional\n * signature** — `(request, response)` — after v5 moved to a single context\n * object, `({ request, response })`.\n *\n * ## Why this exists\n *\n * A v4 handler is not rejected anywhere. It registers fine, and the router\n * calls it with one argument, so `response` is simply `undefined`. The app only\n * breaks on the first request that reaches it, with:\n *\n * TypeError: Cannot read properties of undefined (reading 'success')\n *\n * That message names nothing the reader can act on — not the route, not the\n * handler, not the change to make. This module turns that late, opaque failure\n * into one explicit list printed at boot, and into a `warlock doctor` check.\n *\n * The break itself is intentional; nothing here restores the positional form.\n * Detection and diagnostics only.\n *\n * ## Why it warns and never throws\n *\n * The signal is a heuristic (see {@link looksLikePositionalHandler}), so a\n * false positive is possible in principle. Turning one into a boot failure\n * would take a working application down over a guess, which is strictly worse\n * than the problem being diagnosed. Everything on this path is therefore a\n * warning: nothing here throws, and nothing here changes how a handler is\n * called. A miss simply degrades to the old runtime `TypeError`.\n */\n\nimport { log } from \"@warlock.js/logger\";\nimport type { Route } from \"./types\";\n\n/**\n * One route whose handler looks like it was written for v4.\n */\nexport type PositionalHandlerSuspect = {\n /** HTTP method the route was registered under. */\n method: Route[\"method\"];\n\n /** Full route path, prefixes already applied. */\n path: string;\n\n /** Handler function name, or `\"(anonymous)\"` when it has none. */\n handlerName: string;\n\n /** Route file the route came from, when the router knows it. */\n sourceFile: string;\n};\n\n/**\n * Collected across the whole registration pass so the warning can be emitted\n * ONCE, as a single list, rather than one line per route (or — as before — one\n * mystery 500 per request).\n */\nconst suspects: PositionalHandlerSuspect[] = [];\n\n/**\n * Split the parameter list of a function's source into top-level parameters.\n *\n * Depth-aware and quote-aware, because a default value may itself contain\n * commas, parentheses, braces or strings — `(request, response = f(a, b))` is\n * two parameters, not three. Anything unbalanced returns `undefined`: refusing\n * to guess is what keeps a parse quirk from becoming a false warning.\n *\n * @param openIndex index of the `(` that opens the parameter list.\n */\nfunction splitTopLevelParameters(source: string, openIndex: number): string[] | undefined {\n const parameters: string[] = [];\n\n let depth = 0;\n let current = \"\";\n let quote = \"\";\n\n for (let index = openIndex; index < source.length; index++) {\n const char = source[index];\n\n if (quote) {\n if (char === \"\\\\\") {\n current += char + (source[index + 1] ?? \"\");\n index++;\n continue;\n }\n\n if (char === quote) {\n quote = \"\";\n }\n\n current += char;\n continue;\n }\n\n if (char === '\"' || char === \"'\" || char === \"`\") {\n quote = char;\n current += char;\n continue;\n }\n\n if (char === \"(\" || char === \"[\" || char === \"{\") {\n depth++;\n\n // The paren that opens the list is punctuation, not part of a parameter.\n if (depth === 1) continue;\n\n current += char;\n continue;\n }\n\n if (char === \")\" || char === \"]\" || char === \"}\") {\n depth--;\n\n if (depth === 0) {\n if (current.trim()) {\n parameters.push(current.trim());\n }\n\n return parameters;\n }\n\n current += char;\n continue;\n }\n\n if (char === \",\" && depth === 1) {\n parameters.push(current.trim());\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n // Never found the closing paren — treat the source as unreadable.\n return undefined;\n}\n\n/**\n * Read a function's declared parameters from its own source.\n *\n * Returns `undefined` whenever the source cannot be trusted, which callers must\n * treat as \"no information\" rather than \"no parameters\":\n *\n * - `Function.prototype.bind` replaces the body with `[native code]`, so every\n * `[Controller, \"method\"]` tuple handler lands here (the router binds them);\n * - native functions likewise;\n * - a class, whose first `(` belongs to a constructor or a method, not to a\n * parameter list;\n * - anything that fails to parse.\n */\nfunction readParameterList(handler: Function): string[] | undefined {\n let source: string;\n\n try {\n source = Function.prototype.toString.call(handler);\n } catch {\n return undefined;\n }\n\n if (source.includes(\"[native code]\")) return undefined;\n\n if (/^\\s*class[\\s{]/.test(source)) return undefined;\n\n // A single parameter needs no parentheses: `ctx => …`, `async ctx => …`.\n const bareArrow = source.match(/^\\s*(?:async\\s+)?([A-Za-z_$][\\w$]*)\\s*=>/);\n\n if (bareArrow) {\n const parameter = bareArrow[1];\n\n return parameter === undefined ? undefined : [parameter];\n }\n\n const openIndex = source.indexOf(\"(\");\n\n if (openIndex === -1) return undefined;\n\n return splitTopLevelParameters(source, openIndex);\n}\n\n/**\n * Whether a parameter is written as a destructuring pattern — `{ request }` or\n * `[a, b]` — as opposed to a plain name.\n */\nfunction isDestructured(parameter: string) {\n const start = parameter.trimStart();\n\n return start.startsWith(\"{\") || start.startsWith(\"[\");\n}\n\n/**\n * Does this handler look like it was written for the v4 positional signature?\n *\n * ## The signal, and what it misses\n *\n * `Function.length` alone is not enough, because it stops counting at the first\n * defaulted parameter:\n *\n * | handler | `.length` | actually |\n * | ---------------------------------- | --------- | -------- |\n * | `({ request, response }) => …` | 1 | v5 |\n * | `(ctx) => …` | 1 | v5 |\n * | `(request, response) => …` | 2 | v4 |\n * | `(request, response = x) => …` | 1 | v4 |\n *\n * So the primary signal is the function's own source: a handler is suspect when\n * it declares **two or more** parameters and the first is **not** destructured.\n * Reading the source catches the defaulted row that arity cannot, and rules out\n * the `({ … }, extra)` shape that arity would wrongly flag.\n *\n * When the source is unreadable — a bound or native function — this falls back\n * to `handler.length >= 2`, which `bind` preserves. That is a weaker signal but\n * never a wrong one for the common cases; it only loses the defaulted row.\n *\n * ## What is still missed, by design\n *\n * A one-parameter v4 handler (`(request) => …`) is indistinguishable from a v5\n * `(ctx) => …` and is deliberately not flagged — guessing there would produce\n * false positives on correct code. False positives against the canonical\n * `({ … })` form are essentially nil, and every miss simply leaves today's\n * behaviour in place.\n */\nexport function looksLikePositionalHandler(handler: unknown): boolean {\n if (typeof handler !== \"function\") return false;\n\n const parameters = readParameterList(handler);\n\n if (parameters) {\n const firstParameter = parameters[0];\n\n return (\n parameters.length >= 2 && firstParameter !== undefined && !isDestructured(firstParameter)\n );\n }\n\n return handler.length >= 2;\n}\n\n/**\n * The name to print for a handler.\n *\n * `Function.bind` prefixes the name with `\"bound \"`, and the router binds every\n * `[Controller, \"method\"]` tuple handler. The bare method name is what the user\n * actually wrote, so that is what gets printed.\n */\nfunction handlerDisplayName(handler: Function): string {\n return handler.name?.replace(/^bound /, \"\").trim() || \"(anonymous)\";\n}\n\n/**\n * Inspect one route's handler as it registers, recording it when it looks like\n * the v4 positional form. Called from `Router.add`, so the cost is paid once per\n * route at registration and never per request.\n *\n * Deliberately total: any unexpected failure in the heuristic is swallowed, so a\n * diagnostic can never be the reason a route fails to register.\n */\nexport function inspectHandlerSignature(\n handler: unknown,\n route: { method: Route[\"method\"]; path: string; sourceFile: string },\n) {\n try {\n if (!looksLikePositionalHandler(handler)) return;\n\n suspects.push({\n method: route.method,\n path: route.path,\n handlerName: handlerDisplayName(handler as Function),\n sourceFile: route.sourceFile,\n });\n } catch {\n // A diagnostic must never break registration.\n }\n}\n\n/**\n * Every suspect recorded so far, in registration order.\n */\nexport function listPositionalHandlerSuspects(): readonly PositionalHandlerSuspect[] {\n return suspects;\n}\n\n/**\n * Drop the suspects belonging to a route file. Kept in step with\n * `Router.removeRoutesBySourceFile` so an HMR reload that fixes a handler does\n * not keep reporting the version it replaced.\n */\nexport function forgetPositionalHandlerSuspects(sourceFile: string) {\n for (let index = suspects.length - 1; index >= 0; index--) {\n const suspect = suspects[index];\n\n if (suspect?.sourceFile === sourceFile) {\n suspects.splice(index, 1);\n }\n }\n}\n\n/**\n * Drop every recorded suspect. Intended for tests, which share the router\n * singleton.\n */\nexport function clearPositionalHandlerSuspects() {\n suspects.length = 0;\n}\n\n/**\n * The one-line diagnostic for a single route. Written for someone who has never\n * read Warlock's internals: it names the handler, the route, what is wrong, and\n * the exact edit that fixes it.\n */\nexport function describePositionalHandlerSuspect(suspect: PositionalHandlerSuspect): string {\n return (\n `Handler \"${suspect.handlerName}\" (${suspect.method} ${suspect.path}) looks like ` +\n `the v4 positional signature (request, response). ` +\n `v5 passes a single context object — change it to ({ request, response }).`\n );\n}\n\n/**\n * The full boot-time warning: every suspect, once, in one entry.\n *\n * One boot, one list — not one warning per route, and emphatically not one 500\n * per request. Returns the reported suspects so callers can assert on them.\n */\nexport function reportPositionalHandlerSuspects(logger: Pick<typeof log, \"warn\"> = log) {\n const reported = [...suspects];\n\n if (reported.length === 0) return reported;\n\n const headline =\n reported.length === 1\n ? \"1 route handler looks like the v4 positional signature.\"\n : `${reported.length} route handlers look like the v4 positional signature.`;\n\n logger.warn({\n module: \"router\",\n action: \"handlerSignature\",\n message:\n `${headline} Warlock v5 calls every route handler with a single context object, ` +\n `so a second parameter is always undefined and the request fails as soon as it is used:\\n` +\n reported.map((suspect) => ` - ${describePositionalHandlerSuspect(suspect)}`).join(\"\\n\"),\n context: { handlers: reported },\n });\n\n return reported;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,WAAuC,CAAC;;;;;;;;;;;AAY9C,SAAS,wBAAwB,QAAgB,WAAyC;CACxF,MAAM,aAAuB,CAAC;CAE9B,IAAI,QAAQ;CACZ,IAAI,UAAU;CACd,IAAI,QAAQ;CAEZ,KAAK,IAAI,QAAQ,WAAW,QAAQ,OAAO,QAAQ,SAAS;EAC1D,MAAM,OAAO,OAAO;EAEpB,IAAI,OAAO;GACT,IAAI,SAAS,MAAM;IACjB,WAAW,QAAQ,OAAO,QAAQ,MAAM;IACxC;IACA;GACF;GAEA,IAAI,SAAS,OACX,QAAQ;GAGV,WAAW;GACX;EACF;EAEA,IAAI,SAAS,QAAO,SAAS,OAAO,SAAS,KAAK;GAChD,QAAQ;GACR,WAAW;GACX;EACF;EAEA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD;GAGA,IAAI,UAAU,GAAG;GAEjB,WAAW;GACX;EACF;EAEA,IAAI,SAAS,OAAO,SAAS,OAAO,SAAS,KAAK;GAChD;GAEA,IAAI,UAAU,GAAG;IACf,IAAI,QAAQ,KAAK,GACf,WAAW,KAAK,QAAQ,KAAK,CAAC;IAGhC,OAAO;GACT;GAEA,WAAW;GACX;EACF;EAEA,IAAI,SAAS,OAAO,UAAU,GAAG;GAC/B,WAAW,KAAK,QAAQ,KAAK,CAAC;GAC9B,UAAU;GACV;EACF;EAEA,WAAW;CACb;AAIF;;;;;;;;;;;;;;AAeA,SAAS,kBAAkB,SAAyC;CAClE,IAAI;CAEJ,IAAI;EACF,SAAS,SAAS,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SAAS,GAAG,SAGhD,IAFgB,SAAS,MAEd,EAAE,eAAe,YAC1B,SAAS,OAAO,OAAO,CAAC;AAG9B;;;;;AAMA,SAAgB,iCAAiC;CAC/C,SAAS,SAAS;AACpB;;;;;;AAOA,SAAgB,iCAAiC,SAA2C;CAC1F,OACE,YAAY,QAAQ,YAAY,KAAK,QAAQ,OAAO,GAAG,QAAQ,KAAK;AAIxE;;;;;;;AAQA,SAAgB,gCAAgC,SAAmC,KAAK;CACtF,MAAM,WAAW,CAAC,GAAG,QAAQ;CAE7B,IAAI,SAAS,WAAW,GAAG,OAAO;CAElC,MAAM,WACJ,SAAS,WAAW,IAChB,4DACA,GAAG,SAAS,OAAO;CAEzB,OAAO,KAAK;EACV,QAAQ;EACR,QAAQ;EACR,SACE,GAAG,SAAS,gKAEZ,SAAS,KAAK,YAAY,OAAO,iCAAiC,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI;EACzF,SAAS,EAAE,UAAU,SAAS;CAChC,CAAC;CAED,OAAO;AACT"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { buildRouteRateLimit } from "./build-route-rate-limit.mjs";
|
|
2
|
+
import config from "@mongez/config";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/core/src/router/resolve-route-rate-limit.ts
|
|
5
|
+
/**
|
|
6
|
+
* Whether static files (the public folder, `router.directory()` mounts and
|
|
7
|
+
* `router.file()` routes) count against the global limiter. Off by default:
|
|
8
|
+
* one page load fetches many assets, which would spend a client's quota on
|
|
9
|
+
* files instead of pages and API calls. `http.rateLimit.staticFiles: true`
|
|
10
|
+
* opts them back in.
|
|
11
|
+
*/
|
|
12
|
+
function staticFilesAreRateLimited() {
|
|
13
|
+
return config.get("http.rateLimit.staticFiles") === true;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve a static mount's rate-limit setting: `true` keeps it under the
|
|
17
|
+
* global limiter, `false` exempts it, an object gives it its own limit, and
|
|
18
|
+
* leaving it unset follows `http.rateLimit.staticFiles`.
|
|
19
|
+
*/
|
|
20
|
+
function resolveStaticRateLimit(rateLimit) {
|
|
21
|
+
if (rateLimit === void 0) return staticFilesAreRateLimited() ? void 0 : false;
|
|
22
|
+
return resolveExplicitRateLimit(rateLimit);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a router route's rate-limit setting, identically for production
|
|
26
|
+
* registration and the development wildcard dispatcher.
|
|
27
|
+
*
|
|
28
|
+
* Precedence: the route's own `rateLimit` option, then a
|
|
29
|
+
* `serverOptions.config.rateLimit` passed through to Fastify, then the
|
|
30
|
+
* static-file default for `router.file()` routes, then the global policy.
|
|
31
|
+
*/
|
|
32
|
+
function resolveRouteRateLimit(route) {
|
|
33
|
+
if (route.rateLimit !== void 0) return resolveExplicitRateLimit(route.rateLimit);
|
|
34
|
+
const passedThrough = (route.serverOptions?.config)?.rateLimit;
|
|
35
|
+
if (passedThrough === false) return false;
|
|
36
|
+
if (typeof passedThrough === "object" && passedThrough !== null) return passedThrough;
|
|
37
|
+
if (route.$staticFile) return resolveStaticRateLimit(void 0);
|
|
38
|
+
}
|
|
39
|
+
function resolveExplicitRateLimit(rateLimit) {
|
|
40
|
+
if (rateLimit === true) return void 0;
|
|
41
|
+
if (rateLimit === false) return false;
|
|
42
|
+
return buildRouteRateLimit(rateLimit);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { resolveRouteRateLimit, resolveStaticRateLimit };
|
|
47
|
+
//# sourceMappingURL=resolve-route-rate-limit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-route-rate-limit.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/resolve-route-rate-limit.ts"],"sourcesContent":["import config from \"@mongez/config\";\nimport { buildRouteRateLimit } from \"./build-route-rate-limit\";\nimport type { Route, RouteRateLimitOptions } from \"./types\";\n\n/**\n * What `@fastify/rate-limit` reads from a route's `config.rateLimit`:\n * `false` exempts the route, an object gives it its own limit and bucket, and\n * `undefined` leaves it under the global policy.\n */\nexport type RouteRateLimitSetting = false | Record<string, unknown> | undefined;\n\n/**\n * Whether static files (the public folder, `router.directory()` mounts and\n * `router.file()` routes) count against the global limiter. Off by default:\n * one page load fetches many assets, which would spend a client's quota on\n * files instead of pages and API calls. `http.rateLimit.staticFiles: true`\n * opts them back in.\n */\nexport function staticFilesAreRateLimited(): boolean {\n return config.get(\"http.rateLimit.staticFiles\") === true;\n}\n\n/**\n * Resolve a static mount's rate-limit setting: `true` keeps it under the\n * global limiter, `false` exempts it, an object gives it its own limit, and\n * leaving it unset follows `http.rateLimit.staticFiles`.\n */\nexport function resolveStaticRateLimit(\n rateLimit: RouteRateLimitOptions | boolean | undefined,\n): RouteRateLimitSetting {\n if (rateLimit === undefined) {\n return staticFilesAreRateLimited() ? undefined : false;\n }\n\n return resolveExplicitRateLimit(rateLimit);\n}\n\n/**\n * Resolve a router route's rate-limit setting, identically for production\n * registration and the development wildcard dispatcher.\n *\n * Precedence: the route's own `rateLimit` option, then a\n * `serverOptions.config.rateLimit` passed through to Fastify, then the\n * static-file default for `router.file()` routes, then the global policy.\n */\nexport function resolveRouteRateLimit(\n route: Pick<Route, \"rateLimit\" | \"serverOptions\" | \"$staticFile\">,\n): RouteRateLimitSetting {\n if (route.rateLimit !== undefined) {\n return resolveExplicitRateLimit(route.rateLimit);\n }\n\n const passedThrough: unknown = (\n route.serverOptions?.config as { rateLimit?: unknown } | undefined\n )?.rateLimit;\n\n if (passedThrough === false) return false;\n\n if (typeof passedThrough === \"object\" && passedThrough !== null) {\n return passedThrough as Record<string, unknown>;\n }\n\n if (route.$staticFile) return resolveStaticRateLimit(undefined);\n\n return undefined;\n}\n\nfunction resolveExplicitRateLimit(\n rateLimit: RouteRateLimitOptions | boolean,\n): RouteRateLimitSetting {\n if (rateLimit === true) return undefined;\n\n if (rateLimit === false) return false;\n\n return buildRouteRateLimit(rateLimit);\n}\n"],"mappings":";;;;;;;;;;;AAkBA,SAAgB,4BAAqC;CACnD,OAAO,OAAO,IAAI,4BAA4B,MAAM;AACtD;;;;;;AAOA,SAAgB,uBACd,WACuB;CACvB,IAAI,cAAc,QAChB,OAAO,0BAA0B,IAAI,SAAY;CAGnD,OAAO,yBAAyB,SAAS;AAC3C;;;;;;;;;AAUA,SAAgB,sBACd,OACuB;CACvB,IAAI,MAAM,cAAc,QACtB,OAAO,yBAAyB,MAAM,SAAS;CAGjD,MAAM,iBACJ,MAAM,eAAe,OAAM,EAC1B;CAEH,IAAI,kBAAkB,OAAO,OAAO;CAEpC,IAAI,OAAO,kBAAkB,YAAY,kBAAkB,MACzD,OAAO;CAGT,IAAI,MAAM,aAAa,OAAO,uBAAuB,MAAS;AAGhE;AAEA,SAAS,yBACP,WACuB;CACvB,IAAI,cAAc,MAAM,OAAO;CAE/B,IAAI,cAAc,OAAO,OAAO;CAEhC,OAAO,oBAAoB,SAAS;AACtC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region ../../packages/core/src/router/resolve-route-validation.ts
|
|
2
|
+
/**
|
|
3
|
+
* The validation a route runs: the handler's own `validation`, with the
|
|
4
|
+
* route's `validation` option merged over it (route keys win).
|
|
5
|
+
*/
|
|
6
|
+
function resolveRouteValidation(route) {
|
|
7
|
+
const own = route.handler?.validation;
|
|
8
|
+
const routeLevel = route.validation;
|
|
9
|
+
if (!routeLevel) return own;
|
|
10
|
+
if (!own) return routeLevel;
|
|
11
|
+
return {
|
|
12
|
+
...own,
|
|
13
|
+
...routeLevel
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { resolveRouteValidation };
|
|
19
|
+
//# sourceMappingURL=resolve-route-validation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-route-validation.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/resolve-route-validation.ts"],"sourcesContent":["import type { RequestHandlerValidation, Route } from \"./types\";\n\n/**\n * The validation a route runs: the handler's own `validation`, with the\n * route's `validation` option merged over it (route keys win).\n */\nexport function resolveRouteValidation(\n route: Partial<Pick<Route, \"handler\" | \"validation\">>,\n): RequestHandlerValidation | undefined {\n const own = route.handler?.validation;\n const routeLevel = route.validation;\n\n if (!routeLevel) return own;\n\n if (!own) return routeLevel;\n\n return { ...own, ...routeLevel };\n}\n"],"mappings":";;;;;AAMA,SAAgB,uBACd,OACsC;CACtC,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,aAAa,MAAM;CAEzB,IAAI,CAAC,YAAY,OAAO;CAExB,IAAI,CAAC,KAAK,OAAO;CAEjB,OAAO;EAAE,GAAG;EAAK,GAAG;CAAW;AACjC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region ../../packages/core/src/router/route-guard-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* The names both route-guard checks share: the dev-server warning (which
|
|
4
|
+
* reads registered routes) and `warlock check`'s `WL9006` (which reads the
|
|
5
|
+
* source of `routes.ts` files). Keeping one definition means the two never
|
|
6
|
+
* disagree about what counts as a mutating route or an auth guard.
|
|
7
|
+
*
|
|
8
|
+
* Side-effect free: imports nothing.
|
|
9
|
+
*/
|
|
10
|
+
/** HTTP methods that change state; a route answering one needs a guard or `public: true`. */
|
|
11
|
+
const MUTATING_HTTP_METHODS = new Set([
|
|
12
|
+
"POST",
|
|
13
|
+
"PUT",
|
|
14
|
+
"PATCH",
|
|
15
|
+
"DELETE"
|
|
16
|
+
]);
|
|
17
|
+
/** Middleware named like this counts as a guard when it carries no marker. */
|
|
18
|
+
const GUARD_NAME_PATTERN = /auth|guard/i;
|
|
19
|
+
/** Whether an HTTP method (any case) mutates state: POST, PUT, PATCH or DELETE. */
|
|
20
|
+
function isMutatingHttpMethod(method) {
|
|
21
|
+
return MUTATING_HTTP_METHODS.has(method.toUpperCase());
|
|
22
|
+
}
|
|
23
|
+
/** Whether a middleware name reads as an auth guard: it contains `auth` or `guard`. */
|
|
24
|
+
function isAuthGuardName(name) {
|
|
25
|
+
return GUARD_NAME_PATTERN.test(name);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isAuthGuardName, isMutatingHttpMethod };
|
|
30
|
+
//# sourceMappingURL=route-guard-names.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-guard-names.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/route-guard-names.ts"],"sourcesContent":["/**\n * The names both route-guard checks share: the dev-server warning (which\n * reads registered routes) and `warlock check`'s `WL9006` (which reads the\n * source of `routes.ts` files). Keeping one definition means the two never\n * disagree about what counts as a mutating route or an auth guard.\n *\n * Side-effect free: imports nothing.\n */\n\n/** HTTP methods that change state; a route answering one needs a guard or `public: true`. */\nconst MUTATING_HTTP_METHODS: ReadonlySet<string> = new Set([\"POST\", \"PUT\", \"PATCH\", \"DELETE\"]);\n\n/** Middleware named like this counts as a guard when it carries no marker. */\nconst GUARD_NAME_PATTERN = /auth|guard/i;\n\n/** Whether an HTTP method (any case) mutates state: POST, PUT, PATCH or DELETE. */\nexport function isMutatingHttpMethod(method: string): boolean {\n return MUTATING_HTTP_METHODS.has(method.toUpperCase());\n}\n\n/** Whether a middleware name reads as an auth guard: it contains `auth` or `guard`. */\nexport function isAuthGuardName(name: string): boolean {\n return GUARD_NAME_PATTERN.test(name);\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,wBAA6C,IAAI,IAAI;CAAC;CAAQ;CAAO;CAAS;AAAQ,CAAC;;AAG7F,MAAM,qBAAqB;;AAG3B,SAAgB,qBAAqB,QAAyB;CAC5D,OAAO,sBAAsB,IAAI,OAAO,YAAY,CAAC;AACvD;;AAGA,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,mBAAmB,KAAK,IAAI;AACrC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WarlockError } from "../errors/warlock-error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/core/src/router/route-name-taken-error.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a route is registered under a name another route with the same
|
|
6
|
+
* method already claimed. Pages and API routes share one name namespace.
|
|
7
|
+
*/
|
|
8
|
+
declare class RouteNameTakenError extends WarlockError {
|
|
9
|
+
readonly routeName: string;
|
|
10
|
+
constructor(routeName: string, message: string);
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { RouteNameTakenError };
|
|
14
|
+
//# sourceMappingURL=route-name-taken-error.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-name-taken-error.d.mts","names":[],"sources":["../../../../../../../../packages/core/src/router/route-name-taken-error.ts"],"mappings":";;;;;AAMA;;cAAa,mBAAA,SAA4B,YAAY;EAAA,SAEjC,SAAA;cAAA,SAAA,UAChB,OAAA;AAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WarlockError } from "../errors/warlock-error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../packages/core/src/router/route-name-taken-error.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a route is registered under a name another route with the same
|
|
6
|
+
* method already claimed. Pages and API routes share one name namespace.
|
|
7
|
+
*/
|
|
8
|
+
var RouteNameTakenError = class extends WarlockError {
|
|
9
|
+
constructor(routeName, message) {
|
|
10
|
+
super("WL3001", message);
|
|
11
|
+
this.routeName = routeName;
|
|
12
|
+
this.name = "RouteNameTakenError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { RouteNameTakenError };
|
|
18
|
+
//# sourceMappingURL=route-name-taken-error.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-name-taken-error.mjs","names":[],"sources":["../../../../../../../../packages/core/src/router/route-name-taken-error.ts"],"sourcesContent":["import { WarlockError } from \"../errors/warlock-error\";\n\n/**\n * Thrown when a route is registered under a name another route with the same\n * method already claimed. Pages and API routes share one name namespace.\n */\nexport class RouteNameTakenError extends WarlockError {\n public constructor(\n public readonly routeName: string,\n message: string,\n ) {\n super(\"WL3001\", message);\n this.name = \"RouteNameTakenError\";\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAa,sBAAb,cAAyC,aAAa;CACpD,AAAO,YACL,AAAgB,WAChB,SACA;EACA,MAAM,UAAU,OAAO;EAHP;EAIhB,KAAK,OAAO;CACd;AACF"}
|
package/esm/router/router.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyInstance } from "../http/server.mjs";
|
|
2
|
-
import { GroupedRoutesOptions, NamedApiRoute, NamedApiRoutesOptions, RequestHandler, RequestHandlerType, ResourceMethod, Route, RouteOptions, RouteResource, RouterGroupCallback, RouterStacks } from "./types.mjs";
|
|
2
|
+
import { GroupedRoutesOptions, NamedApiRoute, NamedApiRoutesOptions, RequestHandler, RequestHandlerType, ResourceMethod, Route, RouteOptions, RouteResource, RouterGroupCallback, RouterStacks, StaticMountOptions } from "./types.mjs";
|
|
3
3
|
import { RouteBuilder } from "./route-builder.mjs";
|
|
4
4
|
import { FastifyHttpProxyOptions } from "@fastify/http-proxy";
|
|
5
5
|
import { FastifyStaticOptions } from "@fastify/static";
|
|
@@ -24,6 +24,11 @@ declare class Router {
|
|
|
24
24
|
* {@link routes}; mutations and collision checks use this isolated draft.
|
|
25
25
|
*/
|
|
26
26
|
private routeReplacementTransaction?;
|
|
27
|
+
/**
|
|
28
|
+
* Set by the dev server: whether to warn about mutating routes that have no
|
|
29
|
+
* auth middleware and no `public: true` (`http.warnUnguardedRoutes`).
|
|
30
|
+
*/
|
|
31
|
+
private warnUnguardedRoutes;
|
|
27
32
|
/**
|
|
28
33
|
* Router Instance
|
|
29
34
|
*/
|
|
@@ -31,7 +36,10 @@ declare class Router {
|
|
|
31
36
|
/**
|
|
32
37
|
* Static paths
|
|
33
38
|
*/
|
|
34
|
-
protected staticDirectories:
|
|
39
|
+
protected staticDirectories: {
|
|
40
|
+
options: FastifyStaticOptions;
|
|
41
|
+
rateLimit: StaticMountOptions["rateLimit"];
|
|
42
|
+
}[];
|
|
35
43
|
/**
|
|
36
44
|
* Event listeners
|
|
37
45
|
*/
|
|
@@ -59,32 +67,43 @@ declare class Router {
|
|
|
59
67
|
*/
|
|
60
68
|
redirect(from: string, to: string, redirectMode?: "temporary" | "permanent"): this;
|
|
61
69
|
/**
|
|
62
|
-
*
|
|
70
|
+
* Serve a static folder.
|
|
71
|
+
*
|
|
72
|
+
* Static mounts are exempt from the global rate limiter by default; set
|
|
73
|
+
* `http.rateLimit.staticFiles: true` to count every mount, or pass
|
|
74
|
+
* `{ rateLimit }` to decide for this mount alone: `true` counts it against
|
|
75
|
+
* the global limiter, `false` exempts it, and an object gives it its own
|
|
76
|
+
* limit and bucket.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* router.directory({ root: rootPath("docs"), prefix: "/docs/" });
|
|
80
|
+
* router.directory({ root: rootPath("exports"), prefix: "/exports/" }, { rateLimit: true });
|
|
63
81
|
*/
|
|
64
|
-
directory(options: FastifyStaticOptions): this;
|
|
82
|
+
directory(options: FastifyStaticOptions, mountOptions?: StaticMountOptions): this;
|
|
83
|
+
/** Declare static routes at boot; load the upstream sender on the first file request. */
|
|
84
|
+
protected registerStaticDirectories(server: FastifyInstance): void;
|
|
65
85
|
/**
|
|
66
|
-
* Register
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* that serves no static folder should not pay for it (WR-027).
|
|
86
|
+
* Register a GET route that serves a static file. Like `directory()`, it is
|
|
87
|
+
* exempt from the global rate limiter unless `http.rateLimit.staticFiles`
|
|
88
|
+
* or its own `rateLimit` says otherwise.
|
|
70
89
|
*/
|
|
71
|
-
protected
|
|
90
|
+
protected addStaticFileRoute(path: string, handler: RequestHandler, mountOptions?: StaticMountOptions): this;
|
|
72
91
|
/**
|
|
73
92
|
* Serve file
|
|
74
93
|
*/
|
|
75
|
-
file(path: string, location: string, cacheTime?: number): this;
|
|
94
|
+
file(path: string, location: string, cacheTime?: number, mountOptions?: StaticMountOptions): this;
|
|
76
95
|
/**
|
|
77
96
|
* Serve cached file, it will cache the file to 1 year by default
|
|
78
97
|
*/
|
|
79
|
-
cachedFile(path: string, location: string, cacheTime?: number): this;
|
|
98
|
+
cachedFile(path: string, location: string, cacheTime?: number, mountOptions?: StaticMountOptions): this;
|
|
80
99
|
/**
|
|
81
100
|
* Serve list of files
|
|
82
101
|
*/
|
|
83
|
-
files(files: Record<string, string>, cacheTime?: number): void;
|
|
102
|
+
files(files: Record<string, string>, cacheTime?: number, mountOptions?: StaticMountOptions): void;
|
|
84
103
|
/**
|
|
85
104
|
* Serve list of cached files, it will cache the file to 1 year by default
|
|
86
105
|
*/
|
|
87
|
-
cachedFiles(files: Record<string, string>, cacheTime?: number): void;
|
|
106
|
+
cachedFiles(files: Record<string, string>, cacheTime?: number, mountOptions?: StaticMountOptions): void;
|
|
88
107
|
/**
|
|
89
108
|
* Add proxy route
|
|
90
109
|
*/
|