@fuzdev/fuz_app 0.180.0 → 0.182.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/dist/actions/CLAUDE.md +38 -20
- package/dist/actions/action_rpc.d.ts +25 -6
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +56 -48
- package/dist/actions/action_types.d.ts +31 -13
- package/dist/actions/action_types.d.ts.map +1 -1
- package/dist/actions/action_types.js +1 -1
- package/dist/actions/notification_sender.d.ts +83 -0
- package/dist/actions/notification_sender.d.ts.map +1 -0
- package/dist/actions/notification_sender.js +85 -0
- package/dist/actions/perform_action.d.ts +13 -4
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +27 -18
- package/dist/actions/register_action_ws.d.ts +20 -2
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +17 -5
- package/dist/actions/ws_socket_session.d.ts +3 -0
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -2
- package/dist/auth/CLAUDE.md +84 -59
- package/dist/auth/account_actions.d.ts.map +1 -1
- package/dist/auth/account_actions.js +30 -3
- package/dist/auth/account_queries.d.ts +213 -2
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +255 -2
- package/dist/auth/account_route_schema.d.ts +26 -16
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +10 -24
- package/dist/auth/account_routes.d.ts +5 -7
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +110 -89
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +117 -25
- package/dist/auth/api_token_queries.d.ts +29 -12
- package/dist/auth/api_token_queries.d.ts.map +1 -1
- package/dist/auth/api_token_queries.js +42 -27
- package/dist/auth/audit_log_route_schema.d.ts +1 -1
- package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.d.ts +1 -1
- package/dist/auth/audit_log_routes.d.ts.map +1 -1
- package/dist/auth/audit_log_routes.js +10 -12
- package/dist/auth/audit_log_schema.js +4 -4
- package/dist/auth/bearer_auth.d.ts +4 -3
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +37 -32
- package/dist/auth/bootstrap_account.d.ts +65 -37
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +115 -66
- package/dist/auth/bootstrap_route_schema.d.ts +6 -2
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +7 -2
- package/dist/auth/bootstrap_routes.d.ts +50 -33
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +109 -87
- package/dist/auth/bootstrap_token_store.d.ts +60 -0
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -0
- package/dist/auth/bootstrap_token_store.js +39 -0
- package/dist/auth/credential_headers.d.ts +71 -0
- package/dist/auth/credential_headers.d.ts.map +1 -0
- package/dist/auth/credential_headers.js +100 -0
- package/dist/auth/daemon_token.d.ts +13 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +14 -2
- package/dist/auth/daemon_token_middleware.d.ts +10 -11
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +39 -30
- package/dist/auth/deps.d.ts +10 -11
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/invite_queries.d.ts +18 -0
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +24 -0
- package/dist/auth/request_context.d.ts +97 -76
- package/dist/auth/request_context.d.ts.map +1 -1
- package/dist/auth/request_context.js +93 -104
- package/dist/auth/resolved_auth.d.ts +10 -5
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +5 -3
- package/dist/auth/role_grant_offer_actions.d.ts +7 -11
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +97 -106
- package/dist/auth/role_grant_offer_ddl.d.ts +7 -1
- package/dist/auth/role_grant_offer_ddl.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_ddl.js +9 -2
- package/dist/auth/role_grant_offer_notifications.d.ts +87 -38
- package/dist/auth/role_grant_offer_notifications.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_notifications.js +75 -22
- package/dist/auth/role_grant_offer_queries.d.ts +143 -9
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +266 -66
- package/dist/auth/role_grant_offer_schema.js +1 -1
- package/dist/auth/role_grant_queries.d.ts +57 -10
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +81 -22
- package/dist/auth/role_grant_sql.d.ts +21 -0
- package/dist/auth/role_grant_sql.d.ts.map +1 -1
- package/dist/auth/role_grant_sql.js +21 -0
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +9 -2
- package/dist/auth/session_cookie.d.ts +105 -25
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +124 -15
- package/dist/auth/session_middleware.d.ts +83 -54
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +92 -66
- package/dist/auth/session_queries.d.ts +95 -14
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +98 -19
- package/dist/auth/signup_route_schema.d.ts +5 -5
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +4 -4
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +17 -14
- package/dist/auth/standard_rpc_actions.d.ts +6 -19
- package/dist/auth/standard_rpc_actions.d.ts.map +1 -1
- package/dist/auth/standard_rpc_actions.js +5 -6
- package/dist/auth/token_scope.d.ts +6 -8
- package/dist/auth/token_scope.d.ts.map +1 -1
- package/dist/auth/token_scope.js +6 -9
- package/dist/dev/setup.d.ts +6 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +42 -34
- package/dist/hono_context.d.ts +21 -0
- package/dist/hono_context.d.ts.map +1 -1
- package/dist/hono_context.js +17 -0
- package/dist/http/CLAUDE.md +156 -48
- package/dist/http/auth_shape.d.ts +4 -4
- package/dist/http/common_routes.js +1 -1
- package/dist/http/db_routes.d.ts +4 -3
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +14 -14
- package/dist/http/dev_route_error_check.d.ts +6 -3
- package/dist/http/dev_route_error_check.d.ts.map +1 -1
- package/dist/http/dev_route_error_check.js +6 -3
- package/dist/http/dev_set_cookie_check.d.ts +53 -0
- package/dist/http/dev_set_cookie_check.d.ts.map +1 -0
- package/dist/http/dev_set_cookie_check.js +80 -0
- package/dist/http/error_schemas.d.ts +45 -22
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +53 -26
- package/dist/http/header_lines.d.ts +42 -0
- package/dist/http/header_lines.d.ts.map +1 -0
- package/dist/http/header_lines.js +80 -0
- package/dist/http/host.d.ts +12 -9
- package/dist/http/host.d.ts.map +1 -1
- package/dist/http/host.js +25 -20
- package/dist/http/origin.d.ts +7 -22
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +11 -25
- package/dist/http/proxy.d.ts +1 -0
- package/dist/http/proxy.d.ts.map +1 -1
- package/dist/http/proxy.js +3 -0
- package/dist/http/request_headers.d.ts +95 -0
- package/dist/http/request_headers.d.ts.map +1 -0
- package/dist/http/request_headers.js +110 -0
- package/dist/http/request_target.d.ts +134 -0
- package/dist/http/request_target.d.ts.map +1 -0
- package/dist/http/request_target.js +193 -0
- package/dist/http/route_error_check.d.ts +4 -11
- package/dist/http/route_error_check.d.ts.map +1 -1
- package/dist/http/route_error_check.js +4 -21
- package/dist/http/route_result.d.ts +127 -23
- package/dist/http/route_result.d.ts.map +1 -1
- package/dist/http/route_result.js +97 -19
- package/dist/http/route_spec.d.ts +299 -83
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +548 -71
- package/dist/http/simple_request.d.ts +19 -14
- package/dist/http/simple_request.d.ts.map +1 -1
- package/dist/http/simple_request.js +17 -29
- package/dist/http/surface.d.ts +2 -0
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +4 -1
- package/dist/realtime/outbound_budget.d.ts +1 -2
- package/dist/realtime/outbound_budget.d.ts.map +1 -1
- package/dist/realtime/outbound_budget.js +1 -2
- package/dist/realtime/sse.d.ts +47 -17
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +115 -93
- package/dist/realtime/sse_constants.d.ts +7 -1
- package/dist/realtime/sse_constants.d.ts.map +1 -1
- package/dist/realtime/sse_constants.js +12 -1
- package/dist/realtime/sse_registry.d.ts +3 -3
- package/dist/realtime/sse_registry.js +3 -3
- package/dist/runtime/deps.d.ts +20 -4
- package/dist/runtime/deps.d.ts.map +1 -1
- package/dist/runtime/mock.d.ts +7 -1
- package/dist/runtime/mock.d.ts.map +1 -1
- package/dist/runtime/mock.js +33 -3
- package/dist/runtime/node.d.ts.map +1 -1
- package/dist/runtime/node.js +2 -1
- package/dist/runtime/secure_file.d.ts +71 -10
- package/dist/runtime/secure_file.d.ts.map +1 -1
- package/dist/runtime/secure_file.js +91 -11
- package/dist/server/app_backend.d.ts +0 -8
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +4 -4
- package/dist/server/app_server.d.ts +54 -33
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +69 -41
- package/dist/server/serve_fact_route.d.ts +3 -3
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +59 -55
- package/dist/server/static.d.ts +20 -0
- package/dist/server/static.d.ts.map +1 -1
- package/dist/server/static.js +56 -8
- package/dist/server/unmatched_route.d.ts +42 -0
- package/dist/server/unmatched_route.d.ts.map +1 -0
- package/dist/server/unmatched_route.js +64 -0
- package/dist/testing/CLAUDE.md +406 -1202
- package/dist/testing/app_server.d.ts +3 -1
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +5 -9
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +3 -2
- package/dist/testing/cross_backend/account_lifecycle.d.ts +11 -4
- package/dist/testing/cross_backend/account_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/account_lifecycle.js +320 -6
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts +4 -1
- package/dist/testing/cross_backend/build_test_backend_paths.d.ts.map +1 -1
- package/dist/testing/cross_backend/build_test_backend_paths.js +1 -1
- package/dist/testing/cross_backend/capabilities.d.ts +68 -5
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +20 -4
- package/dist/testing/cross_backend/cell_gated_create.js +1 -1
- package/dist/testing/cross_backend/conformance_case.d.ts +63 -21
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.d.ts +54 -12
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +179 -23
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +7 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/create_dual_spawn_global_setup.js +3 -3
- package/dist/testing/cross_backend/credential_conformance.d.ts +196 -0
- package/dist/testing/cross_backend/credential_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance.js +296 -0
- package/dist/testing/cross_backend/credential_conformance.json +1284 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts +40 -0
- package/dist/testing/cross_backend/credential_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_conformance_wire.js +293 -0
- package/dist/testing/cross_backend/credential_header_robustness.d.ts +1 -3
- package/dist/testing/cross_backend/credential_header_robustness.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_header_robustness.js +24 -55
- package/dist/testing/cross_backend/credential_wire.d.ts +112 -0
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/credential_wire.js +188 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +22 -2
- package/dist/testing/cross_backend/default_spine_surface.d.ts +1 -26
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +3 -7
- package/dist/testing/cross_backend/differential.d.ts +1 -1
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +3 -2
- package/dist/testing/cross_backend/differential_normalize.d.ts +23 -6
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +11 -5
- package/dist/testing/cross_backend/full_spine_mount.d.ts +4 -10
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +11 -4
- package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/identity_parity.js +4 -0
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +78 -4
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +13 -10
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +2 -2
- package/dist/testing/cross_backend/request_header_conformance.d.ts +174 -0
- package/dist/testing/cross_backend/request_header_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance.js +196 -0
- package/dist/testing/cross_backend/request_header_conformance.json +1158 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts +39 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_header_conformance_wire.js +284 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts +298 -0
- package/dist/testing/cross_backend/request_target_conformance.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance.js +186 -0
- package/dist/testing/cross_backend/request_target_conformance.json +3765 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +32 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -0
- package/dist/testing/cross_backend/request_target_conformance_wire.js +278 -0
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +173 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts +5 -4
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_notification_ws.js +185 -31
- package/dist/testing/cross_backend/rpc_adversarial.d.ts +6 -4
- package/dist/testing/cross_backend/rpc_adversarial.d.ts.map +1 -1
- package/dist/testing/cross_backend/rpc_adversarial.js +5 -2
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +6 -7
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +4 -5
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +82 -34
- package/dist/testing/cross_backend/session_cookie_effect.d.ts +43 -0
- package/dist/testing/cross_backend/session_cookie_effect.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_cookie_effect.js +103 -0
- package/dist/testing/cross_backend/session_login.d.ts +24 -0
- package/dist/testing/cross_backend/session_login.d.ts.map +1 -0
- package/dist/testing/cross_backend/session_login.js +31 -0
- package/dist/testing/cross_backend/setup.d.ts +117 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +193 -9
- package/dist/testing/cross_backend/simple_request.d.ts.map +1 -1
- package/dist/testing/cross_backend/simple_request.js +5 -0
- package/dist/testing/cross_backend/spine_suites.d.ts +9 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +88 -5
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +8 -5
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +205 -64
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +5 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +165 -0
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -0
- package/dist/testing/cross_backend/testing_credential_read.js +175 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +19 -0
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +22 -6
- package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
- package/dist/testing/cross_backend/token_lifetime.js +58 -2
- package/dist/testing/cross_backend/transport_composition.d.ts +2 -4
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +13 -10
- package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/ts_spine_backend_config.js +5 -3
- package/dist/testing/cross_backend/ws_endpoint.d.ts +11 -1
- package/dist/testing/cross_backend/ws_endpoint.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_endpoint.js +19 -2
- package/dist/testing/cross_backend/ws_role_gated.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_role_gated.js +2 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +28 -12
- package/dist/testing/cross_backend/xfail.d.ts +44 -11
- package/dist/testing/cross_backend/xfail.d.ts.map +1 -1
- package/dist/testing/cross_backend/xfail.js +68 -23
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +4 -3
- package/dist/testing/integration.d.ts +1 -2
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +14 -8
- package/dist/testing/integration_helpers.d.ts +50 -3
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +87 -9
- package/dist/testing/middleware.d.ts +3 -1
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +14 -7
- package/dist/testing/resolved_auth.d.ts +3 -1
- package/dist/testing/resolved_auth.d.ts.map +1 -1
- package/dist/testing/resolved_auth.js +4 -4
- package/dist/testing/round_trip.d.ts +6 -2
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +17 -6
- package/dist/testing/rpc_envelope_cases.d.ts.map +1 -1
- package/dist/testing/rpc_envelope_cases.js +7 -0
- package/dist/testing/rpc_helpers.d.ts +4 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +6 -1
- package/dist/testing/rpc_round_trip.d.ts +13 -2
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +25 -6
- package/dist/testing/schema_generators.d.ts +2 -2
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +4 -4
- package/dist/testing/stubs.d.ts +2 -2
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +13 -10
- package/dist/testing/transports/fetch_transport.d.ts +6 -3
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +31 -19
- package/dist/testing/transports/raw_http.d.ts +61 -1
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +61 -1
- package/dist/testing/transports/ws_raw_client.d.ts +20 -0
- package/dist/testing/transports/ws_raw_client.d.ts.map +1 -1
- package/dist/testing/transports/ws_raw_client.js +10 -4
- package/dist/testing/transports/ws_transport.d.ts +21 -1
- package/dist/testing/transports/ws_transport.d.ts.map +1 -1
- package/dist/testing/transports/ws_transport.js +58 -20
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +8 -4
- package/package.json +1 -1
package/dist/http/route_spec.js
CHANGED
|
@@ -22,14 +22,21 @@ import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
|
22
22
|
import { format_route_key } from './surface_query.js';
|
|
23
23
|
import { is_db_checkout_error } from '../db/db_checkout_error.js';
|
|
24
24
|
import { ERROR_INVALID_JSON_BODY, ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_ROUTE_PARAMS, ERROR_INVALID_QUERY_PARAMS, ERROR_INTERNAL_ERROR, ERROR_SERVICE_UNAVAILABLE, ERROR_UNSUPPORTED_CONTENT_TYPE } from './error_schemas.js';
|
|
25
|
+
import { read_content_type } from './request_headers.js';
|
|
25
26
|
import { is_post_content_type_refused } from './simple_request.js';
|
|
26
27
|
import { jsonrpc_error_code_to_http_status, jsonrpc_error_code_to_name, dev_only, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
|
|
27
28
|
import { is_null_schema, scan_json_value } from './schema_helpers.js';
|
|
28
29
|
import { is_json_response } from './route_error_check.js';
|
|
29
30
|
import { dispatch_with_post_commit_rollback } from './pending_effects.js';
|
|
31
|
+
import { ROUTE_RAW_REFUSED_HEADERS } from './route_result.js';
|
|
32
|
+
import { SSE_RESPONSE_HEADERS } from '../realtime/sse_constants.js';
|
|
30
33
|
import { assert_route_auth_acting_biconditional, assert_route_auth_invariants } from './auth_shape.js';
|
|
31
34
|
import { assert_validation_schema, to_wire_issues } from '../schema_issues.js';
|
|
32
35
|
import { read_json_body } from './json_text.js';
|
|
36
|
+
import { get_client_ip } from './client_ip.js';
|
|
37
|
+
import { get_header_lines } from './header_lines.js';
|
|
38
|
+
import { read_request_query_pairs, read_request_route_params, to_query_record } from './request_target.js';
|
|
39
|
+
import { CONNECTION_IP_KEY, has_test_context_preset, RESOLVED_AUTH_KEY } from '../hono_context.js';
|
|
33
40
|
/**
|
|
34
41
|
* Define a route: its handler is checked against the route's `output`,
|
|
35
42
|
* `errors`, `auth`, and `rate_limit` (`TypedRouteHandler`), and the spec is
|
|
@@ -38,11 +45,21 @@ import { read_json_body } from './json_text.js';
|
|
|
38
45
|
* A literal `errors` list is read as given; a list typed
|
|
39
46
|
* `Array<RestErrorDef>` is refused (`KnownRouteErrors`).
|
|
40
47
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
48
|
+
* The handler's `route` is typed from the spec (`TypedRouteContext`). Where
|
|
49
|
+
* that types `route.auth` non-null — the route requires an account or an
|
|
50
|
+
* actor — the stored handler checks it before it runs and throws when it is
|
|
51
|
+
* missing anyway (a spread of the spec whose `auth` was rewritten, a harness
|
|
52
|
+
* that skipped the gate), which the error catch answers 500: a handler never
|
|
53
|
+
* runs on a request context its type promised and the request lacks.
|
|
54
|
+
*
|
|
55
|
+
* @param spec - the route, its handler returning `route_ok`, `route_fail`, `route_raw`, or `route_sse`
|
|
56
|
+
* @returns `spec`, its handler behind that check where the route requires one
|
|
43
57
|
*/
|
|
44
58
|
// @__NO_SIDE_EFFECTS__
|
|
45
|
-
export const define_route = (spec) =>
|
|
59
|
+
export const define_route = (spec) => {
|
|
60
|
+
const handler = guard_route_auth(spec.auth, spec.handler);
|
|
61
|
+
return (handler === spec.handler ? spec : { ...spec, handler });
|
|
62
|
+
};
|
|
46
63
|
/**
|
|
47
64
|
* Define a route minus its handler, keeping the types `attach_route_handler`
|
|
48
65
|
* checks its handler against.
|
|
@@ -53,55 +70,392 @@ export const define_route = (spec) => spec;
|
|
|
53
70
|
// @__NO_SIDE_EFFECTS__
|
|
54
71
|
export const define_route_shape = (shape) => shape;
|
|
55
72
|
/**
|
|
56
|
-
* Attach a handler to a route shape (`define_route_shape`), checked
|
|
57
|
-
* `define_route` checks one.
|
|
73
|
+
* Attach a handler to a route shape (`define_route_shape`), checked and
|
|
74
|
+
* guarded as `define_route` checks and guards one.
|
|
58
75
|
*
|
|
59
76
|
* @param shape - the route without `handler`
|
|
60
|
-
* @param handler - the handler, returning `route_ok`, `route_fail`, or `
|
|
77
|
+
* @param handler - the handler, returning `route_ok`, `route_fail`, `route_raw`, or `route_sse`
|
|
61
78
|
* @returns a new spec, `shape` with `handler`
|
|
62
79
|
*/
|
|
63
80
|
// @__NO_SIDE_EFFECTS__
|
|
64
|
-
export const attach_route_handler = (shape, handler) => ({
|
|
81
|
+
export const attach_route_handler = (shape, handler) => ({
|
|
82
|
+
...shape,
|
|
83
|
+
handler: guard_route_auth(shape.auth, handler)
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* The handler behind the check its `route.auth` type promises: a route that
|
|
87
|
+
* requires an actor gets a request context with one, a route that requires
|
|
88
|
+
* an account a request context — else the call throws, naming what was
|
|
89
|
+
* missing. Any other route's handler is returned as it is.
|
|
90
|
+
*/
|
|
91
|
+
const guard_route_auth = (auth, handler) => {
|
|
92
|
+
const requires_actor = auth.actor === 'required';
|
|
93
|
+
if (!requires_actor && auth.account !== 'required')
|
|
94
|
+
return handler;
|
|
95
|
+
return (route) => {
|
|
96
|
+
if (route.auth === null || (requires_actor && route.auth.actor === null)) {
|
|
97
|
+
throw new Error(`a route handler typed for ${requires_actor ? 'an acting actor' : 'an account'} ran with ${route.auth === null ? 'no request context' : 'no acting actor'} — the route's auth gate did not run`);
|
|
98
|
+
}
|
|
99
|
+
return handler(route);
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/** `SSE_RESPONSE_HEADERS` less the `Connection` that keeps a stream open, for a `HEAD`. */
|
|
103
|
+
const SSE_HEAD_RESPONSE_HEADERS = Object.freeze(Object.fromEntries(Object.entries(SSE_RESPONSE_HEADERS).filter(([name]) => name.toLowerCase() !== 'connection')));
|
|
104
|
+
/** A `Content-Length` value: a decimal integer with no leading zero. */
|
|
105
|
+
const CONTENT_LENGTH_PATTERN = /^(0|[1-9]\d*)$/;
|
|
106
|
+
/** The statuses a response may not carry a body on. */
|
|
107
|
+
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
108
|
+
/**
|
|
109
|
+
* The statuses a response may not declare a `Content-Length` on: 204 (RFC
|
|
110
|
+
* 9110 §8.6) and 205, whose response has no content (§15.3.6). A 304 may,
|
|
111
|
+
* naming the size the selected representation would have (§8.6, §15.4.5), so
|
|
112
|
+
* it keeps the rules of a null body.
|
|
113
|
+
*/
|
|
114
|
+
const NO_CONTENT_LENGTH_STATUSES = new Set([204, 205]);
|
|
115
|
+
const ROUTE_RAW_REFUSED = new Set(ROUTE_RAW_REFUSED_HEADERS);
|
|
116
|
+
/** A status a `Response` can be built with, 200 to 599. */
|
|
117
|
+
const is_route_status = (status) => typeof status === 'number' && Number.isInteger(status) && status >= 200 && status <= 599;
|
|
118
|
+
const is_route_raw_body = (body) => body === null ||
|
|
119
|
+
typeof body === 'string' ||
|
|
120
|
+
body instanceof Uint8Array ||
|
|
121
|
+
body instanceof ReadableStream;
|
|
122
|
+
/**
|
|
123
|
+
* Whether a view's resizable buffer shrank below it: such a view reads as
|
|
124
|
+
* empty (`byteLength` 0) and every runtime would answer it as zero bytes, so
|
|
125
|
+
* nothing but this tells it from bytes that are empty. Every method that
|
|
126
|
+
* validates a view (`at` among them) throws on one out of bounds.
|
|
127
|
+
*/
|
|
128
|
+
const is_view_out_of_bounds = (view) => {
|
|
129
|
+
if (view.byteLength !== 0)
|
|
130
|
+
return false;
|
|
131
|
+
try {
|
|
132
|
+
view.at(0);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
65
139
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
140
|
+
* Prepare the response for a handler's result, checking everything it can see
|
|
141
|
+
* that would keep it from being built or framed as declared, so
|
|
142
|
+
* `emit_route_response` fails only on a stream disturbed past what a check
|
|
143
|
+
* can see (`route_raw`). Runs inside
|
|
144
|
+
* the route's transaction: a result it refuses throws, the transaction rolls
|
|
145
|
+
* back, and the post-commit effects are discarded. Serializes a success's or
|
|
146
|
+
* a failure's JSON body here for the same reason. Writes nothing.
|
|
147
|
+
*
|
|
148
|
+
* - a success — `value` as JSON, its `set_cookie` lines kept for the emit
|
|
149
|
+
* - a failure — its body as JSON at its status, with the headers its
|
|
150
|
+
* definition derives (`Retry-After`); a failure carrying `set_cookie` is
|
|
151
|
+
* refused, since a refusal never sets a cookie
|
|
152
|
+
* - a raw answer — checked by the rules `route_raw` lists
|
|
153
|
+
* - an SSE answer — its stream must be one `RouteContext.open_sse` opened for
|
|
154
|
+
* this request (`opened_sse`), and the route may not have asked to close the
|
|
155
|
+
* connection (`SSE_RESPONSE_HEADERS` keep it alive)
|
|
156
|
+
*
|
|
157
|
+
* A raw or failure result whose headers name one of the route's
|
|
158
|
+
* `response_headers`, or an SSE answer on a route declaring one of
|
|
159
|
+
* `SSE_RESPONSE_HEADERS`, is refused: the declared header is the route's on
|
|
160
|
+
* every answer.
|
|
70
161
|
*
|
|
71
|
-
* @param c - the Hono context
|
|
72
162
|
* @param result - the handler's result
|
|
73
|
-
* @
|
|
163
|
+
* @param options - the request's label for refusals, the streams it opened, and what the route declared or asked of the response
|
|
164
|
+
* @returns the prepared response
|
|
165
|
+
* @throws TypeError when `result` is not a result the factories made — a `Response`, a success without a JSON value, a failure without its status or definition, a raw answer its rules refuse, a stream this request did not open, `undefined` or `null` — or conflicts with the route's `response_headers` or its `close_connection`
|
|
74
166
|
*/
|
|
75
|
-
export const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
167
|
+
export const prepare_route_response = (result, options) => {
|
|
168
|
+
const { label, opened_sse, response_header_names, close_requested = false } = options;
|
|
169
|
+
const refuse = (reason) => {
|
|
170
|
+
throw new TypeError(`${label}: a route handler returned ${reason} — return \`route_ok\`, \`route_fail\`, \`route_raw\`, or \`route_sse\``);
|
|
171
|
+
};
|
|
172
|
+
const prepared = prepare_result(result, label, opened_sse, refuse);
|
|
173
|
+
if (prepared.kind === 'sse') {
|
|
174
|
+
if (close_requested) {
|
|
175
|
+
return refuse('an SSE stream after asking to close the connection');
|
|
176
|
+
}
|
|
177
|
+
if (response_header_names) {
|
|
178
|
+
for (const name of Object.keys(SSE_RESPONSE_HEADERS)) {
|
|
179
|
+
if (response_header_names.has(name.toLowerCase())) {
|
|
180
|
+
return refuse(`an SSE stream on a route declaring \`${name.toLowerCase()}\``);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (response_header_names && prepared.headers && result.ok !== true) {
|
|
186
|
+
// a success's only headers are `JSON_HEADERS`, which no declaration may name
|
|
187
|
+
for (const name of Object.keys(prepared.headers)) {
|
|
188
|
+
if (response_header_names.has(name.toLowerCase())) {
|
|
189
|
+
return refuse(`a header \`${name.toLowerCase()}\` the route declares in \`response_headers\``);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return prepared;
|
|
194
|
+
};
|
|
195
|
+
const prepare_result = (result, label, opened_sse, refuse) => {
|
|
196
|
+
// each branch checks the fields it reads, so a malformed or nullish result
|
|
197
|
+
// falls through to the refusal — a `Response` has its own `ok` and
|
|
198
|
+
// `status`, but no `value`, `def`, `headers` record, or `stream`
|
|
199
|
+
if (result instanceof Response)
|
|
200
|
+
return refuse('a Response');
|
|
80
201
|
if (result?.ok === true) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
202
|
+
// a function, symbol, or `undefined` is no JSON value: `JSON.stringify`
|
|
203
|
+
// writes nothing for it, which would answer an empty 200
|
|
204
|
+
const text = JSON.stringify(result.value);
|
|
205
|
+
if (typeof text !== 'string')
|
|
206
|
+
return refuse('a success without a JSON value');
|
|
207
|
+
const set_cookie = check_header_lines(result.set_cookie, label);
|
|
208
|
+
return { kind: 'body', status: undefined, body: text, headers: JSON_HEADERS, set_cookie };
|
|
209
|
+
}
|
|
210
|
+
if (result?.ok === 'raw')
|
|
211
|
+
return prepare_raw(result, refuse);
|
|
212
|
+
if (result?.ok === 'sse') {
|
|
213
|
+
const body = opened_sse.get(result.stream);
|
|
214
|
+
if (!body)
|
|
215
|
+
return refuse('an SSE stream this request did not open');
|
|
216
|
+
return { kind: 'sse', stream: result.stream, body };
|
|
217
|
+
}
|
|
218
|
+
if (result && !result.ok && result.def !== undefined && is_route_status(result.status)) {
|
|
219
|
+
if ('set_cookie' in result)
|
|
220
|
+
return refuse('a failure carrying a cookie');
|
|
221
|
+
const derived = result.def.headers?.(result.body);
|
|
222
|
+
const headers = check_header_record({ ...JSON_HEADERS, ...derived }, refuse);
|
|
223
|
+
return {
|
|
224
|
+
kind: 'body',
|
|
225
|
+
status: result.status,
|
|
226
|
+
body: JSON.stringify(result.body),
|
|
227
|
+
headers,
|
|
228
|
+
set_cookie: []
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return refuse('a malformed result');
|
|
232
|
+
};
|
|
233
|
+
/** The headers `c.json` writes, a success's and a failure's. */
|
|
234
|
+
const JSON_HEADERS = Object.freeze({
|
|
235
|
+
'Content-Type': 'application/json'
|
|
236
|
+
});
|
|
237
|
+
const prepare_raw = (raw, refuse) => {
|
|
238
|
+
const { status, body } = raw;
|
|
239
|
+
if (!is_route_status(status))
|
|
240
|
+
return refuse(`a raw answer at status ${String(status)}`);
|
|
241
|
+
if (!is_route_raw_body(body))
|
|
242
|
+
return refuse('a raw answer whose body is no `RouteRawBody`');
|
|
243
|
+
// what a `Response` can't be built from, or a runtime can't write
|
|
244
|
+
if (body instanceof ReadableStream && body.locked) {
|
|
245
|
+
return refuse('a raw answer whose stream body is locked');
|
|
246
|
+
}
|
|
247
|
+
if (body instanceof Uint8Array && body.buffer instanceof ArrayBuffer && body.buffer.detached) {
|
|
248
|
+
return refuse('a raw answer whose bytes are detached');
|
|
249
|
+
}
|
|
250
|
+
if (body instanceof Uint8Array && is_view_out_of_bounds(body)) {
|
|
251
|
+
return refuse('a raw answer whose bytes are out of their shrunk buffer');
|
|
252
|
+
}
|
|
253
|
+
if (body !== null && NULL_BODY_STATUSES.has(status)) {
|
|
254
|
+
return refuse(`a raw answer with a body at null-body status ${status}`);
|
|
255
|
+
}
|
|
256
|
+
if (typeof raw.headers !== 'object' || raw.headers === null) {
|
|
257
|
+
return refuse('a raw answer without a headers record');
|
|
258
|
+
}
|
|
259
|
+
const headers = check_header_record(raw.headers, refuse);
|
|
260
|
+
const names = Object.keys(headers).map((name) => name.toLowerCase());
|
|
261
|
+
for (const name of names) {
|
|
262
|
+
if (ROUTE_RAW_REFUSED.has(name))
|
|
263
|
+
return refuse(`a raw answer carrying \`${name}\``);
|
|
264
|
+
}
|
|
265
|
+
if (body !== null && !names.includes('content-type')) {
|
|
266
|
+
return refuse('a raw answer with a body and no `Content-Type`');
|
|
267
|
+
}
|
|
268
|
+
const length_name = Object.keys(headers).find((name) => name.toLowerCase() === 'content-length');
|
|
269
|
+
if (length_name !== undefined) {
|
|
270
|
+
if (NO_CONTENT_LENGTH_STATUSES.has(status)) {
|
|
271
|
+
return refuse(`a raw answer with a \`Content-Length\` at status ${status}`);
|
|
272
|
+
}
|
|
273
|
+
const length = headers[length_name];
|
|
274
|
+
if (typeof length !== 'string' || !CONTENT_LENGTH_PATTERN.test(length)) {
|
|
275
|
+
return refuse('a raw answer whose `Content-Length` is not a decimal integer without a leading zero');
|
|
276
|
+
}
|
|
277
|
+
if (!Number.isSafeInteger(Number(length))) {
|
|
278
|
+
return refuse(`a raw answer whose \`Content-Length\` ${length} is past the safe integer range`);
|
|
279
|
+
}
|
|
280
|
+
// a null or stream body declares a size it does not carry (`HEAD`,
|
|
281
|
+
// `X-Accel-Redirect`); a body in hand must be exactly that size
|
|
282
|
+
const byte_length = typeof body === 'string'
|
|
283
|
+
? new TextEncoder().encode(body).byteLength
|
|
284
|
+
: body instanceof Uint8Array
|
|
285
|
+
? body.byteLength
|
|
286
|
+
: null;
|
|
287
|
+
if (byte_length !== null && Number(length) !== byte_length) {
|
|
288
|
+
return refuse(`a raw answer whose \`Content-Length\` ${length} is not its body's ${byte_length} bytes`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
kind: 'body',
|
|
293
|
+
status,
|
|
294
|
+
body,
|
|
295
|
+
headers: names.length === 0 ? undefined : headers,
|
|
296
|
+
set_cookie: []
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* A header record copied, each name once in any case, each value one a
|
|
301
|
+
* `Headers` accepts — so building the response from it cannot throw.
|
|
302
|
+
*/
|
|
303
|
+
const check_header_record = (record, refuse) => {
|
|
304
|
+
const copy = {};
|
|
305
|
+
const seen = new Set();
|
|
306
|
+
const trial = new Headers();
|
|
307
|
+
for (const [name, value] of Object.entries(record)) {
|
|
308
|
+
const lower = name.toLowerCase();
|
|
309
|
+
if (seen.has(lower))
|
|
310
|
+
return refuse(`headers naming \`${lower}\` twice`);
|
|
311
|
+
seen.add(lower);
|
|
312
|
+
const values = typeof value === 'string' ? [value] : value;
|
|
313
|
+
if (!Array.isArray(values) || !values.every((v) => typeof v === 'string')) {
|
|
314
|
+
return refuse(`a header \`${name}\` that is no string or list of strings`);
|
|
315
|
+
}
|
|
316
|
+
// an empty value a runtime writes its own way (Bun adds a line of its own)
|
|
317
|
+
if (values.length === 0 || values.includes('')) {
|
|
318
|
+
return refuse(`a header \`${name}\` with an empty value`);
|
|
319
|
+
}
|
|
320
|
+
try {
|
|
321
|
+
for (const v of values)
|
|
322
|
+
trial.append(name, v);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return refuse(`a header \`${name}\` a \`Headers\` refuses`);
|
|
84
326
|
}
|
|
327
|
+
copy[name] = typeof value === 'string' ? value : [...values];
|
|
85
328
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
329
|
+
return copy;
|
|
330
|
+
};
|
|
331
|
+
// a success's `Set-Cookie` lines, each a string a `Headers` accepts
|
|
332
|
+
const check_header_lines = (lines, label) => {
|
|
333
|
+
if (!Array.isArray(lines)) {
|
|
334
|
+
throw new TypeError(`${label}: a route success whose \`set_cookie\` is no list`);
|
|
335
|
+
}
|
|
336
|
+
const trial = new Headers();
|
|
337
|
+
for (const line of lines) {
|
|
338
|
+
if (typeof line !== 'string') {
|
|
339
|
+
throw new TypeError(`${label}: a route success whose \`set_cookie\` holds a non-string`);
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
trial.append('set-cookie', line);
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
throw new TypeError(`${label}: a route success whose \`set_cookie\` holds a line a \`Headers\` refuses`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return lines;
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Build the response `prepare_route_response` prepared — the one place a route
|
|
352
|
+
* result becomes a `Response`, and only once the route's transaction has
|
|
353
|
+
* committed, so nothing a handler returned reaches the wire for writes that
|
|
354
|
+
* rolled back. Built through the Hono context (`c.body`), so the headers the
|
|
355
|
+
* middleware put on the context — the session middleware's clear of a stale
|
|
356
|
+
* cookie — lead, and a success's `Set-Cookie` lines follow them in order.
|
|
357
|
+
* A success is written as `c.json` writes it, a failure as
|
|
358
|
+
* `c.json(body, status, headers)` does, and an SSE stream with
|
|
359
|
+
* `SSE_RESPONSE_HEADERS`.
|
|
360
|
+
*
|
|
361
|
+
* The prepare checked everything it can see. What it can't — a stream body
|
|
362
|
+
* read and released, unlocked yet disturbed — makes the `Response` constructor
|
|
363
|
+
* throw here, after the commit; `apply_route_specs` rethrows that as an error
|
|
364
|
+
* naming the route and the commit, which the error catch logs and answers 500.
|
|
365
|
+
*
|
|
366
|
+
* A `HEAD` request — which Hono answers by running the `GET` route and
|
|
367
|
+
* dropping the body unread, never cancelling it — gets a stream's status and
|
|
368
|
+
* headers alone, and the stream released here: an SSE stream is closed, so
|
|
369
|
+
* its `on_close` listeners run and a registry drops it, and a raw stream body
|
|
370
|
+
* is cancelled, which releases its source (`route_raw`). An SSE answer to a
|
|
371
|
+
* `HEAD` leaves out `SSE_RESPONSE_HEADERS`' `Connection: keep-alive`, which
|
|
372
|
+
* keeps a stream's connection open and would hold one with no stream on it
|
|
373
|
+
* past a client's `Connection: close` (`@hono/node-server` honors it). Text and bytes are
|
|
374
|
+
* built as for a `GET` — Hono drops them, and an outer layer that reads the
|
|
375
|
+
* answer (the DEV error check) still sees its body.
|
|
376
|
+
*
|
|
377
|
+
* @param c - the Hono context
|
|
378
|
+
* @param prepared - what `prepare_route_response` returned
|
|
379
|
+
* @returns the response
|
|
380
|
+
* @throws TypeError when the runtime refuses to build a response from a prepared body
|
|
381
|
+
*/
|
|
382
|
+
export const emit_route_response = (c, prepared) => {
|
|
383
|
+
const head = c.req.method === 'HEAD';
|
|
384
|
+
if (prepared.kind === 'sse') {
|
|
385
|
+
if (head) {
|
|
386
|
+
prepared.stream.close();
|
|
387
|
+
cancel_unread(prepared.body);
|
|
388
|
+
return c.body(null, undefined, SSE_HEAD_RESPONSE_HEADERS);
|
|
389
|
+
}
|
|
390
|
+
return c.body(prepared.body, undefined, SSE_RESPONSE_HEADERS);
|
|
89
391
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
392
|
+
const { status, headers, set_cookie } = prepared;
|
|
393
|
+
let { body } = prepared;
|
|
394
|
+
if (head && body instanceof ReadableStream) {
|
|
395
|
+
cancel_unread(body);
|
|
396
|
+
body = null;
|
|
93
397
|
}
|
|
94
|
-
|
|
398
|
+
const data = body;
|
|
399
|
+
if (set_cookie.length === 0)
|
|
400
|
+
return c.body(data, status, headers);
|
|
401
|
+
// the `ResponseInit` form appends its `set-cookie` lines to the context's
|
|
402
|
+
// headers, after the middleware's, where a header record would replace them
|
|
403
|
+
const init = {
|
|
404
|
+
status,
|
|
405
|
+
headers: set_cookie.map((line) => ['set-cookie', line])
|
|
406
|
+
};
|
|
407
|
+
return c.body(data, init, headers);
|
|
408
|
+
};
|
|
409
|
+
/**
|
|
410
|
+
* The header names `RouteSpec.response_headers` may not declare, lowercase:
|
|
411
|
+
* `ROUTE_RAW_REFUSED_HEADERS`, which are the server's or a success's, and the
|
|
412
|
+
* two a body determines.
|
|
413
|
+
*/
|
|
414
|
+
const RESPONSE_HEADERS_REFUSED = new Set([
|
|
415
|
+
...ROUTE_RAW_REFUSED_HEADERS,
|
|
416
|
+
'content-type',
|
|
417
|
+
'content-length'
|
|
418
|
+
]);
|
|
419
|
+
// throws unless `response_headers` holds a header a response can carry on
|
|
420
|
+
// every answer: by the raw rules (`check_header_record`), one string per name,
|
|
421
|
+
// and no name `RESPONSE_HEADERS_REFUSED` lists
|
|
422
|
+
const assert_response_headers = (record, route_key) => {
|
|
423
|
+
if (record === undefined)
|
|
424
|
+
return;
|
|
425
|
+
const refuse = (reason) => {
|
|
426
|
+
throw new Error(`Route "${route_key}": response_headers holds ${reason}`);
|
|
427
|
+
};
|
|
428
|
+
if (typeof record !== 'object' || record === null || Array.isArray(record)) {
|
|
429
|
+
refuse('no headers record');
|
|
430
|
+
}
|
|
431
|
+
check_header_record(record, refuse);
|
|
432
|
+
for (const [name, value] of Object.entries(record)) {
|
|
433
|
+
if (typeof value !== 'string')
|
|
434
|
+
refuse(`a header \`${name}\` that is no string`);
|
|
435
|
+
if (RESPONSE_HEADERS_REFUSED.has(name.toLowerCase())) {
|
|
436
|
+
refuse(`\`${name.toLowerCase()}\`, which a route may not declare for every answer`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
/**
|
|
441
|
+
* The route's first stage: write its `response_headers` on the context, ahead
|
|
442
|
+
* of everything else on the route, so every answer built through the context
|
|
443
|
+
* from here — a refusal, the handler's result, the error catch's — carries
|
|
444
|
+
* them. Empty when the route declares none.
|
|
445
|
+
*/
|
|
446
|
+
const create_response_headers_entry = (record) => {
|
|
447
|
+
if (record === undefined)
|
|
448
|
+
return [];
|
|
449
|
+
const entries = Object.entries(record);
|
|
450
|
+
if (entries.length === 0)
|
|
451
|
+
return [];
|
|
452
|
+
const write = async (c, next) => {
|
|
453
|
+
for (const [name, value] of entries)
|
|
454
|
+
c.header(name, value);
|
|
455
|
+
await next();
|
|
456
|
+
};
|
|
457
|
+
return [write];
|
|
95
458
|
};
|
|
96
|
-
export function get_route_input(c, _schema) {
|
|
97
|
-
return c.get('validated_input');
|
|
98
|
-
}
|
|
99
|
-
export function get_route_params(c, _schema) {
|
|
100
|
-
return c.get('validated_params');
|
|
101
|
-
}
|
|
102
|
-
export function get_route_query(c, _schema) {
|
|
103
|
-
return c.get('validated_query');
|
|
104
|
-
}
|
|
105
459
|
/**
|
|
106
460
|
* Create the content-type check for a route spec: a `POST` whose
|
|
107
461
|
* `Content-Type` the route refuses (`is_post_content_type_refused` — anything
|
|
@@ -117,7 +471,7 @@ const create_content_type_check = (spec) => {
|
|
|
117
471
|
return [];
|
|
118
472
|
const raw_body = spec.raw_body ?? false;
|
|
119
473
|
const check = async (c, next) => {
|
|
120
|
-
if (is_post_content_type_refused(c
|
|
474
|
+
if (is_post_content_type_refused(read_content_type(get_header_lines(c, 'content-type')), raw_body)) {
|
|
121
475
|
return c.json({ error: ERROR_UNSUPPORTED_CONTENT_TYPE }, 415);
|
|
122
476
|
}
|
|
123
477
|
await next();
|
|
@@ -127,9 +481,9 @@ const create_content_type_check = (spec) => {
|
|
|
127
481
|
/**
|
|
128
482
|
* Create input validation middleware for a route spec.
|
|
129
483
|
*
|
|
130
|
-
* Returns an empty array for
|
|
131
|
-
*
|
|
132
|
-
*
|
|
484
|
+
* Returns an empty array for null-input routes (no body expected; every
|
|
485
|
+
* `GET`, as `apply_route_specs` refuses a `GET` with an input). For other
|
|
486
|
+
* routes with input
|
|
133
487
|
* schemas, returns a middleware that parses and validates the JSON body,
|
|
134
488
|
* storing the result on the context as `validated_input`. A body that parses
|
|
135
489
|
* but holds U+0000 in a string or key is `invalid_request_body` ahead of the
|
|
@@ -141,9 +495,7 @@ const create_content_type_check = (spec) => {
|
|
|
141
495
|
*
|
|
142
496
|
* @mutates `c.var.validated_input` - set to the parsed and validated body on success
|
|
143
497
|
*/
|
|
144
|
-
const create_input_validation = (input_schema
|
|
145
|
-
if (method === 'GET')
|
|
146
|
-
return [];
|
|
498
|
+
const create_input_validation = (input_schema) => {
|
|
147
499
|
if (is_null_schema(input_schema))
|
|
148
500
|
return [];
|
|
149
501
|
const validate = async (c, next) => {
|
|
@@ -174,8 +526,11 @@ const create_input_validation = (input_schema, method) => {
|
|
|
174
526
|
* Create params validation middleware for a route spec.
|
|
175
527
|
*
|
|
176
528
|
* Returns an empty array when no params schema is defined.
|
|
177
|
-
* For routes with params schemas, returns a middleware that
|
|
178
|
-
* `
|
|
529
|
+
* For routes with params schemas, returns a middleware that reads the params
|
|
530
|
+
* strictly (`read_request_route_params`) and validates them against the
|
|
531
|
+
* schema, storing the result on the context as `validated_params`. A path
|
|
532
|
+
* holding an escape that doesn't decode is refused whatever the schema, so a
|
|
533
|
+
* free-text param never receives an undecodable escape as text.
|
|
179
534
|
*
|
|
180
535
|
* @mutates `c.var.validated_params` - set to the parsed and validated path params on success
|
|
181
536
|
*/
|
|
@@ -183,8 +538,10 @@ const create_params_validation = (params_schema) => {
|
|
|
183
538
|
if (!params_schema)
|
|
184
539
|
return [];
|
|
185
540
|
const validate = async (c, next) => {
|
|
186
|
-
const raw_params = c
|
|
187
|
-
|
|
541
|
+
const raw_params = read_request_route_params(c);
|
|
542
|
+
if (!raw_params.ok)
|
|
543
|
+
return c.json({ error: ERROR_INVALID_ROUTE_PARAMS }, 400);
|
|
544
|
+
const result = parse(params_schema, raw_params.value);
|
|
188
545
|
if (!result.ok) {
|
|
189
546
|
return c.json({
|
|
190
547
|
error: ERROR_INVALID_ROUTE_PARAMS,
|
|
@@ -200,8 +557,11 @@ const create_params_validation = (params_schema) => {
|
|
|
200
557
|
* Create query params validation middleware for a route spec.
|
|
201
558
|
*
|
|
202
559
|
* Returns an empty array when no query schema is defined.
|
|
203
|
-
* For routes with query schemas, returns a middleware that
|
|
204
|
-
* `
|
|
560
|
+
* For routes with query schemas, returns a middleware that reads the query
|
|
561
|
+
* strictly (`read_request_query_pairs`) and validates its record
|
|
562
|
+
* (`to_query_record` — each name's first value) against the schema, storing
|
|
563
|
+
* the result on the context as `validated_query`. A query holding an escape
|
|
564
|
+
* that doesn't decode, in any key or value, is refused before the schema.
|
|
205
565
|
*
|
|
206
566
|
* @mutates `c.var.validated_query` - set to the parsed and validated query params on success
|
|
207
567
|
*/
|
|
@@ -209,8 +569,10 @@ const create_query_validation = (query_schema) => {
|
|
|
209
569
|
if (!query_schema)
|
|
210
570
|
return [];
|
|
211
571
|
const validate = async (c, next) => {
|
|
212
|
-
const raw_query = c
|
|
213
|
-
|
|
572
|
+
const raw_query = read_request_query_pairs(c);
|
|
573
|
+
if (!raw_query.ok)
|
|
574
|
+
return c.json({ error: ERROR_INVALID_QUERY_PARAMS }, 400);
|
|
575
|
+
const result = parse(query_schema, to_query_record(raw_query.value));
|
|
214
576
|
if (!result.ok) {
|
|
215
577
|
return c.json({
|
|
216
578
|
error: ERROR_INVALID_QUERY_PARAMS,
|
|
@@ -376,7 +738,8 @@ const build_rest_error_body = (err) => {
|
|
|
376
738
|
* runs the optional authorization phase to resolve the acting actor + build
|
|
377
739
|
* the request context, wraps handler with DEV-only output
|
|
378
740
|
* validation, builds each response from its handler's result
|
|
379
|
-
* (`
|
|
741
|
+
* (`prepare_route_response` inside the transaction, `emit_route_response`
|
|
742
|
+
* after it), wraps with error catch layer (a thrown JSON-RPC error,
|
|
380
743
|
* recognized via `to_thrown_jsonrpc_error`, maps to its status; any other
|
|
381
744
|
* throw to a 500), and registers the route.
|
|
382
745
|
*
|
|
@@ -393,10 +756,14 @@ const build_rest_error_body = (err) => {
|
|
|
393
756
|
* route rather than carry its payload, and the authorization phase reads
|
|
394
757
|
* `acting` off the query on GETs).
|
|
395
758
|
*
|
|
396
|
-
* Each handler receives a `RouteContext`
|
|
397
|
-
*
|
|
398
|
-
* - `
|
|
399
|
-
*
|
|
759
|
+
* Each handler receives a `RouteContext` and nothing else: built from the
|
|
760
|
+
* Hono context once every stage before the handler has run, with `db`
|
|
761
|
+
* transaction-scoped when `RouteSpec.transaction` is true and the pool
|
|
762
|
+
* otherwise, and `open_sse` opening through `options.open_sse`.
|
|
763
|
+
*
|
|
764
|
+
* A route's `response_headers` are written on the context by its first
|
|
765
|
+
* stage, ahead of the content-type check, so every answer the route gives
|
|
766
|
+
* carries them; a record off their rules throws at registration.
|
|
400
767
|
*
|
|
401
768
|
* Also enforces the auth shape's registry-time invariants: the cross-axis
|
|
402
769
|
* invariants 1, 3, and 4 (`assert_route_auth_invariants`), and invariant 2:
|
|
@@ -411,19 +778,22 @@ const build_rest_error_body = (err) => {
|
|
|
411
778
|
* `errors` entry an error definition (`rest_error`): anything else throws
|
|
412
779
|
* naming the route and the slot. A `params` or `query`
|
|
413
780
|
* must be an object schema (`get_schema_entries`), as the path params and
|
|
414
|
-
* query string are an object: one that isn't throws naming the route.
|
|
781
|
+
* query string are an object: one that isn't throws naming the route. A
|
|
782
|
+
* `GET` carries no body, so its `input` must be a null schema
|
|
783
|
+
* (`is_null_schema`): any other throws naming the route.
|
|
415
784
|
*
|
|
416
785
|
* In DEV each handler's 2xx JSON responses are checked against its `output`.
|
|
417
786
|
* Error responses are checked by the DEV error check
|
|
418
787
|
* (`create_dev_route_error_check`), which `create_app_server` mounts outermost.
|
|
419
788
|
*
|
|
420
789
|
* @param resolve_auth_guards - maps `RouteAuth` to middleware — use `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`
|
|
421
|
-
* @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
|
|
422
790
|
* @param db - used for transaction wrapping and `RouteContext`
|
|
791
|
+
* @param options - the authorization phase and the SSE opener
|
|
423
792
|
* @mutates `app`
|
|
424
|
-
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value that is no schema or an `errors` entry is not a definition, if any spec violates a cross-axis auth invariant or the actor-acting biconditional,
|
|
793
|
+
* @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value that is no schema or an `errors` entry is not a definition, if a `GET` declares an `input` other than `literal(null)`, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, if a `params` or `query` is not an object schema, or if `response_headers` is off its rules
|
|
425
794
|
*/
|
|
426
|
-
export const apply_route_specs = (app, specs, resolve_auth_guards, log, db,
|
|
795
|
+
export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, options) => {
|
|
796
|
+
const { authorize, open_sse } = options ?? {};
|
|
427
797
|
const registered = new Set();
|
|
428
798
|
for (const spec of specs) {
|
|
429
799
|
const route_key = format_route_key(spec);
|
|
@@ -432,15 +802,18 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
432
802
|
}
|
|
433
803
|
registered.add(route_key);
|
|
434
804
|
assert_schema_slots(spec, route_key);
|
|
805
|
+
assert_get_has_no_input(spec, route_key);
|
|
435
806
|
assert_object_slot(spec.params, 'params', route_key);
|
|
436
807
|
assert_object_slot(spec.query, 'query', route_key);
|
|
808
|
+
assert_response_headers(spec.response_headers, route_key);
|
|
437
809
|
assert_route_auth_invariants(spec.auth, `Route "${route_key}"`);
|
|
438
810
|
assert_route_auth_acting_biconditional(spec.auth, { input: spec.input, query: spec.query }, `Route "${route_key}"`);
|
|
439
811
|
const { pre_authorization: pre_authorization_guards, post_authorization: post_authorization_guards } = resolve_auth_guards(spec.auth);
|
|
812
|
+
const response_headers_entry = create_response_headers_entry(spec.response_headers);
|
|
440
813
|
const content_type_check = create_content_type_check(spec);
|
|
441
814
|
const params_validation = create_params_validation(spec.params);
|
|
442
815
|
const query_validation = create_query_validation(spec.query);
|
|
443
|
-
const input_validation = create_input_validation(spec.input
|
|
816
|
+
const input_validation = create_input_validation(spec.input);
|
|
444
817
|
const authorization = authorize
|
|
445
818
|
? [
|
|
446
819
|
async (c, next) => {
|
|
@@ -460,26 +833,122 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
|
|
|
460
833
|
// those effects would announce state that never committed. The eager
|
|
461
834
|
// `pending_effects` queue (attempt audits, run outside the transaction) is
|
|
462
835
|
// untouched. Shared with the action dispatcher (actions/perform_action.ts)
|
|
463
|
-
// via `dispatch_with_post_commit_rollback`. The response is
|
|
464
|
-
// the dispatch, so a result that can't become one
|
|
465
|
-
//
|
|
466
|
-
// commit and
|
|
836
|
+
// via `dispatch_with_post_commit_rollback`. The response is prepared
|
|
837
|
+
// inside the dispatch, so a result that can't become one throws before
|
|
838
|
+
// the commit and rolls back; it is built after the dispatch returns, so a
|
|
839
|
+
// commit that fails answers the error catch's 500 and nothing the handler
|
|
840
|
+
// returned — no cookie for a session that rolled back.
|
|
841
|
+
const response_header_names = new Set(Object.keys(spec.response_headers ?? {}).map((name) => name.toLowerCase()));
|
|
842
|
+
const has_input = !is_null_schema(spec.input);
|
|
467
843
|
let handler = async (c) => {
|
|
844
|
+
const label = `${c.req.method} ${c.req.path}`;
|
|
845
|
+
const opened_sse = new Map();
|
|
846
|
+
// what the handler returned, and the stream body the response took
|
|
847
|
+
let returned;
|
|
848
|
+
let answered_body = null;
|
|
849
|
+
// `close_connection` asks; the header is written once, on whichever
|
|
850
|
+
// answer the route gives — the emitted result or the error catch's
|
|
851
|
+
let close_requested = false;
|
|
468
852
|
const route_context = {
|
|
853
|
+
auth: c.var.request_context ?? null,
|
|
854
|
+
credential: c.get(RESOLVED_AUTH_KEY) ?? null,
|
|
855
|
+
client_ip: get_client_ip(c),
|
|
856
|
+
connection_ip: c.get(CONNECTION_IP_KEY) ?? null,
|
|
857
|
+
signal: c.req.raw.signal,
|
|
858
|
+
input: has_input ? c.var.validated_input : null,
|
|
859
|
+
params: spec.params ? c.var.validated_params : undefined,
|
|
860
|
+
query: spec.query ? c.var.validated_query : undefined,
|
|
861
|
+
has_test_context_preset: has_test_context_preset(c),
|
|
862
|
+
request: c.req.raw,
|
|
863
|
+
query_pairs: read_request_query_pairs(c),
|
|
864
|
+
read_json_body: () => read_json_body(c.req),
|
|
865
|
+
header_lines: (name) => get_header_lines(c, name),
|
|
866
|
+
close_connection: () => {
|
|
867
|
+
close_requested = true;
|
|
868
|
+
},
|
|
469
869
|
pending_effects: c.var.pending_effects,
|
|
470
|
-
post_commit_effects: c.var.post_commit_effects
|
|
870
|
+
post_commit_effects: c.var.post_commit_effects,
|
|
871
|
+
open_sse: (sse_options) => {
|
|
872
|
+
if (!open_sse) {
|
|
873
|
+
throw new Error(`${label}: the route opened an SSE stream, and \`apply_route_specs\` was given no \`open_sse\``);
|
|
874
|
+
}
|
|
875
|
+
const { log: stream_log = log, ...rest } = sse_options ?? {};
|
|
876
|
+
const { stream, body } = open_sse(c, stream_log, rest);
|
|
877
|
+
opened_sse.set(stream, body);
|
|
878
|
+
return stream;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
// the handler, then the prepare, on the route's `db` — the transaction's
|
|
882
|
+
// when it runs in one
|
|
883
|
+
const run = async (route_db) => {
|
|
884
|
+
returned = await inner({ ...route_context, db: route_db });
|
|
885
|
+
return prepare_route_response(returned, {
|
|
886
|
+
label,
|
|
887
|
+
opened_sse,
|
|
888
|
+
response_header_names,
|
|
889
|
+
close_requested
|
|
890
|
+
});
|
|
471
891
|
};
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
892
|
+
try {
|
|
893
|
+
const prepared = await dispatch_with_post_commit_rollback(c.var.post_commit_effects, async () => (use_transaction ? db.transaction(run) : run(db)));
|
|
894
|
+
if (close_requested)
|
|
895
|
+
c.header('Connection', 'close');
|
|
896
|
+
// after the commit: a failure here answers the error catch's 500 for
|
|
897
|
+
// work that committed, so the error names that
|
|
898
|
+
let response;
|
|
899
|
+
try {
|
|
900
|
+
response = emit_route_response(c, prepared);
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
throw new Error(`${label}: the response could not be built after the route committed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
904
|
+
}
|
|
905
|
+
if (prepared.kind === 'sse' || prepared.body instanceof ReadableStream) {
|
|
906
|
+
answered_body = prepared.body;
|
|
907
|
+
}
|
|
908
|
+
return response;
|
|
909
|
+
}
|
|
910
|
+
catch (error) {
|
|
911
|
+
// the error catch answers through the context, so it carries the close
|
|
912
|
+
if (close_requested)
|
|
913
|
+
c.header('Connection', 'close');
|
|
914
|
+
throw error;
|
|
915
|
+
}
|
|
916
|
+
finally {
|
|
917
|
+
// a body no response took has no reader: an SSE stream opened and not
|
|
918
|
+
// answered with is closed, and a raw stream body refused or rolled
|
|
919
|
+
// back is cancelled, so its source (a file handle, a child process)
|
|
920
|
+
// is released
|
|
921
|
+
for (const [stream, body] of opened_sse) {
|
|
922
|
+
if (body !== answered_body) {
|
|
923
|
+
stream.close();
|
|
924
|
+
cancel_unread(body);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const raw_body = raw_stream_body(returned);
|
|
928
|
+
if (raw_body && raw_body !== answered_body)
|
|
929
|
+
cancel_unread(raw_body);
|
|
930
|
+
}
|
|
475
931
|
};
|
|
476
932
|
// Step 2: error catch layer — a thrown error becomes its REST body here
|
|
477
933
|
handler = wrap_error_catch(handler, log);
|
|
478
934
|
// Step 3: output validation of a 2xx body
|
|
479
935
|
handler = wrap_output_validation(handler, spec.output, log);
|
|
480
|
-
app.on(spec.method, [spec.path], ...content_type_check, ...params_validation, ...query_validation, ...pre_authorization_guards, ...authorization, ...post_authorization_guards, ...input_validation, handler);
|
|
936
|
+
app.on(spec.method, [spec.path], ...response_headers_entry, ...content_type_check, ...params_validation, ...query_validation, ...pre_authorization_guards, ...authorization, ...post_authorization_guards, ...input_validation, handler);
|
|
481
937
|
}
|
|
482
938
|
};
|
|
939
|
+
// a handler result's raw stream body, if it is one
|
|
940
|
+
const raw_stream_body = (result) => {
|
|
941
|
+
if (typeof result !== 'object' || result === null)
|
|
942
|
+
return null;
|
|
943
|
+
const { ok, body } = result;
|
|
944
|
+
return ok === 'raw' && body instanceof ReadableStream ? body : null;
|
|
945
|
+
};
|
|
946
|
+
// cancel a body nothing reads; a locked one is its reader's to end
|
|
947
|
+
const cancel_unread = (body) => {
|
|
948
|
+
if (body.locked)
|
|
949
|
+
return;
|
|
950
|
+
body.cancel().catch(() => { });
|
|
951
|
+
};
|
|
483
952
|
// throws unless every schema slot holds a fuz_schema schema and every
|
|
484
953
|
// `errors` entry is a definition; `params` and `query` may be absent
|
|
485
954
|
const assert_schema_slots = (spec, route_key) => {
|
|
@@ -501,6 +970,14 @@ const assert_schema_slots = (spec, route_key) => {
|
|
|
501
970
|
}
|
|
502
971
|
}
|
|
503
972
|
};
|
|
973
|
+
// throws when a `GET` declares an input: a `GET` carries no body, so nothing
|
|
974
|
+
// would validate it, and the handler's `input` and the surface's
|
|
975
|
+
// `input_schema` would both describe a value that never arrives
|
|
976
|
+
const assert_get_has_no_input = (spec, route_key) => {
|
|
977
|
+
if (spec.method !== 'GET' || is_null_schema(spec.input))
|
|
978
|
+
return;
|
|
979
|
+
throw new Error(`Route "${route_key}": input is not \`literal(null)\` — a GET carries no body; declare its fields on \`query\``);
|
|
980
|
+
};
|
|
504
981
|
// throws unless a `params` / `query` is an object schema under any wrappers
|
|
505
982
|
const assert_object_slot = (schema, slot, route_key) => {
|
|
506
983
|
if (schema === undefined || get_schema_entries(schema))
|