@fuzdev/fuz_app 0.163.0 → 0.165.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/README.md +2 -1
- package/dist/actions/action_event_data.d.ts +1 -1
- package/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +4 -0
- package/dist/actions/action_spec.d.ts +3 -3
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/auth/CLAUDE.md +1 -1
- package/dist/auth/account_route_schema.d.ts +3 -27
- package/dist/auth/account_route_schema.d.ts.map +1 -1
- package/dist/auth/account_route_schema.js +6 -20
- package/dist/auth/admin_action_specs.d.ts +56 -56
- 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_route_schema.js +4 -5
- package/dist/auth/audit_log_schema.d.ts +18 -18
- package/dist/auth/bootstrap_route_schema.d.ts +1 -30
- package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
- package/dist/auth/bootstrap_route_schema.js +3 -8
- package/dist/auth/daemon_token.d.ts +4 -4
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token.js +3 -3
- package/dist/auth/daemon_token_middleware.d.ts +1 -1
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +5 -5
- package/dist/auth/middleware.js +4 -4
- package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
- package/dist/auth/signup_route_schema.d.ts.map +1 -1
- package/dist/auth/signup_route_schema.js +3 -7
- package/dist/db/CLAUDE.md +2 -1
- package/dist/db/file_fact_url.d.ts +11 -6
- package/dist/db/file_fact_url.d.ts.map +1 -1
- package/dist/db/file_fact_url.js +5 -5
- package/dist/db/schema_ready.d.ts +0 -5
- package/dist/db/schema_ready.d.ts.map +1 -1
- package/dist/db/schema_ready.js +0 -5
- package/dist/http/CLAUDE.md +105 -71
- package/dist/http/auth_shape.d.ts +48 -29
- package/dist/http/auth_shape.d.ts.map +1 -1
- package/dist/http/auth_shape.js +12 -85
- package/dist/http/body_limit.d.ts +12 -0
- package/dist/http/body_limit.d.ts.map +1 -1
- package/dist/http/body_limit.js +15 -0
- package/dist/http/body_limit_schema.d.ts +20 -0
- package/dist/http/body_limit_schema.d.ts.map +1 -0
- package/dist/http/body_limit_schema.js +20 -0
- package/dist/http/common_routes.d.ts +1 -1
- package/dist/http/common_routes.d.ts.map +1 -1
- package/dist/http/common_routes.js +11 -14
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +59 -69
- package/dist/http/dev_route_error_check.d.ts +70 -0
- package/dist/http/dev_route_error_check.d.ts.map +1 -0
- package/dist/http/dev_route_error_check.js +119 -0
- package/dist/http/error_schemas.d.ts +365 -189
- package/dist/http/error_schemas.d.ts.map +1 -1
- package/dist/http/error_schemas.js +256 -149
- package/dist/http/health_schema.d.ts +10 -6
- package/dist/http/health_schema.d.ts.map +1 -1
- package/dist/http/health_schema.js +3 -3
- package/dist/http/middleware_spec.d.ts +8 -3
- package/dist/http/middleware_spec.d.ts.map +1 -1
- package/dist/http/origin.d.ts +12 -43
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +10 -6
- package/dist/http/route_error_check.d.ts +179 -0
- package/dist/http/route_error_check.d.ts.map +1 -0
- package/dist/http/route_error_check.js +283 -0
- package/dist/http/route_errors.d.ts +80 -0
- package/dist/http/route_errors.d.ts.map +1 -0
- package/dist/http/route_errors.js +83 -0
- package/dist/http/route_spec.d.ts +33 -17
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/http/route_spec.js +48 -62
- package/dist/http/schema_helpers.d.ts +15 -34
- package/dist/http/schema_helpers.d.ts.map +1 -1
- package/dist/http/schema_helpers.js +11 -47
- package/dist/http/surface.d.ts +19 -12
- package/dist/http/surface.d.ts.map +1 -1
- package/dist/http/surface.js +25 -38
- package/dist/http/surface_query.d.ts +11 -2
- package/dist/http/surface_query.d.ts.map +1 -1
- package/dist/http/surface_query.js +7 -1
- package/dist/primitive_schemas_fuz.d.ts +17 -3
- package/dist/primitive_schemas_fuz.d.ts.map +1 -1
- package/dist/primitive_schemas_fuz.js +13 -3
- package/dist/rate_limiter.d.ts +13 -0
- package/dist/rate_limiter.d.ts.map +1 -1
- package/dist/rate_limiter.js +20 -2
- package/dist/schema_issues.d.ts +29 -11
- package/dist/schema_issues.d.ts.map +1 -1
- package/dist/schema_issues.js +11 -10
- package/dist/schema_meta.d.ts +8 -1
- package/dist/schema_meta.d.ts.map +1 -1
- package/dist/schema_meta.js +2 -1
- package/dist/server/app_server.d.ts +3 -1
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +24 -10
- package/dist/server/serve_fact_route.d.ts.map +1 -1
- package/dist/server/serve_fact_route.js +8 -31
- package/dist/server/surface_route.d.ts.map +1 -1
- package/dist/server/surface_route.js +5 -6
- package/dist/server/x_accel.d.ts +12 -7
- package/dist/server/x_accel.d.ts.map +1 -1
- package/dist/server/x_accel.js +7 -9
- package/dist/testing/CLAUDE.md +105 -61
- package/dist/testing/admin_integration.js +2 -2
- package/dist/testing/adversarial_404.d.ts +4 -18
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +20 -52
- package/dist/testing/adversarial_headers.d.ts +3 -4
- package/dist/testing/adversarial_headers.d.ts.map +1 -1
- package/dist/testing/adversarial_headers.js +8 -6
- package/dist/testing/adversarial_input.d.ts.map +1 -1
- package/dist/testing/adversarial_input.js +20 -19
- package/dist/testing/assertions.d.ts +46 -14
- package/dist/testing/assertions.d.ts.map +1 -1
- package/dist/testing/assertions.js +73 -16
- package/dist/testing/attack_surface.d.ts +17 -35
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/attack_surface.js +36 -95
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +2 -1
- package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
- package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
- package/dist/testing/cross_backend/action_manifest.js +11 -11
- package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
- package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_crud.js +2 -1
- package/dist/testing/cross_backend/conformance_table.js +1 -1
- package/dist/testing/cross_backend/fact_serving.js +3 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +11 -4
- package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
- package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
- package/dist/testing/cross_backend/origin_conformance.js +21 -21
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
- package/dist/testing/cross_backend/setup.d.ts +13 -0
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +24 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/standard.d.ts +31 -0
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +9 -3
- package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
- package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_origin_check.js +16 -13
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/data_exposure.d.ts +7 -0
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +8 -7
- package/dist/testing/error_coverage.d.ts +53 -61
- package/dist/testing/error_coverage.d.ts.map +1 -1
- package/dist/testing/error_coverage.js +86 -119
- package/dist/testing/integration.d.ts +28 -1
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +54 -29
- package/dist/testing/integration_helpers.d.ts +37 -9
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/integration_helpers.js +75 -40
- package/dist/testing/middleware.d.ts +3 -5
- package/dist/testing/middleware.d.ts.map +1 -1
- package/dist/testing/middleware.js +5 -4
- package/dist/testing/middleware_gate_probes.d.ts +90 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
- package/dist/testing/middleware_gate_probes.js +179 -0
- package/dist/testing/rate_limiting.d.ts +1 -1
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +5 -4
- package/dist/testing/round_trip.d.ts +7 -0
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +8 -5
- package/dist/testing/schema_generators.d.ts +40 -11
- package/dist/testing/schema_generators.d.ts.map +1 -1
- package/dist/testing/schema_generators.js +71 -17
- package/dist/testing/stubs.d.ts +10 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +15 -5
- package/dist/testing/surface_invariants.d.ts +36 -115
- package/dist/testing/surface_invariants.d.ts.map +1 -1
- package/dist/testing/surface_invariants.js +106 -269
- package/dist/testing/transports/raw_http.d.ts +10 -2
- package/dist/testing/transports/raw_http.d.ts.map +1 -1
- package/dist/testing/transports/raw_http.js +10 -4
- package/dist/ui/CLAUDE.md +4 -2
- package/dist/ui/auth_state.svelte.d.ts.map +1 -1
- package/dist/ui/auth_state.svelte.js +2 -8
- package/dist/ui/backend_probe.svelte.js +3 -3
- package/dist/ui/table_state.svelte.d.ts.map +1 -1
- package/dist/ui/table_state.svelte.js +1 -8
- package/dist/ui/ui_fetch.d.ts +12 -2
- package/dist/ui/ui_fetch.d.ts.map +1 -1
- package/dist/ui/ui_fetch.js +22 -4
- package/package.json +1 -1
package/dist/http/CLAUDE.md
CHANGED
|
@@ -9,17 +9,20 @@ guards live in `auth/` and consume these primitives. Routes and actions in
|
|
|
9
9
|
other domains should do the same — extend, don't special-case.
|
|
10
10
|
|
|
11
11
|
For the design rationale behind declarative routes, DEV-only output
|
|
12
|
-
validation, the
|
|
12
|
+
validation, the route error map, and fire-and-forget
|
|
13
13
|
effects, see ../../../docs/architecture.md.
|
|
14
14
|
|
|
15
15
|
## Module Map
|
|
16
16
|
|
|
17
17
|
- `http/route_spec.ts` — `RouteSpec` + `apply_route_specs`, validation pipeline, transactions.
|
|
18
|
-
- `http/auth_shape.ts` — canonical `RouteAuth`
|
|
19
|
-
- `http/error_schemas.ts` — `ERROR_*` constants,
|
|
20
|
-
- `http/
|
|
18
|
+
- `http/auth_shape.ts` — canonical `RouteAuth` type + `AuthAxisState` + predicates + the registration-time checks: `assert_route_auth_invariants` (the cross-axis invariants 1, 3, 4) and `assert_route_auth_acting_biconditional` (invariant 2), both run by `apply_route_specs` and `compile_action_registry` on every spec.
|
|
19
|
+
- `http/error_schemas.ts` — `ERROR_*` constants, the per-code REST error definitions (`rest_error`, `REST_*`), `derive_route_errors`, `to_error_schemas`.
|
|
20
|
+
- `http/route_errors.ts` — the route error map: `RouteErrorMap`, `resolve_route_error_map`, `resolve_app_route_error_maps`, `get_route_error_map`.
|
|
21
|
+
- `http/route_error_check.ts` — `check_route_error` (whether an error response is one its route's map declares, the rule the DEV error check and `assert_response_matches_spec` share; `ALWAYS_ACCEPTED_ERRORS`, `is_error_status`, `format_route_error_check`) `is_json_response`, and the test helpers' hono-free route lookup (`split_route_template` and `parse_route_param`, a template read segment by segment as Hono's `getPattern` reads it; `compile_route_path`; `compile_route_param_pattern`, a `{re}` grouped and anchored as `compile_route_path` reads it — Hono's RegExpRouter reading, stricter than TrieRouter's ungrouped `^re$`; `decode_route_path`, a path as Hono's router decodes it; `to_mounted_routes`; `find_mounted_route`), whose reading `resolve_valid_path` also fills params by. Hono-free and `esm-env`-free.
|
|
22
|
+
- `http/dev_route_error_check.ts` — `create_dev_route_error_check({route_specs, route_error_maps, log})`: the DEV-only outer error check, `null` outside DEV; `create_route_lookup`, its lookup by Hono's own router.
|
|
23
|
+
- `http/schema_helpers.ts` — shared schema introspection (null/void/strict/surface/middleware-applies), and `to_void_params` / `to_input_params` / `json_has_own_proto_key` / `safe_parse_dropping_unknown_keys`.
|
|
21
24
|
- `http/middleware_spec.ts` — `MiddlewareSpec` interface.
|
|
22
|
-
- `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth.
|
|
25
|
+
- `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts, as `create_body_limit_middleware_spec(max_size)`, a `MiddlewareSpec` at `'*'` ahead of the other middleware, absent with `max_body_size: null`. Its hono-free shape, `body_limit_middleware_shape` (`http/body_limit_schema.ts`), declares its `413` `payload_too_large` and `400` `invalid_content_length`, so every route's error map carries both; `create_test_app_surface_spec` lists the same shape with a stub handler. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth. After the header `413` Node and Bun close at once (the header is what makes them — Bun 1.4.3 is the tested floor, an older Bun kept the connection and served the next request) and Deno closes once the declared body has arrived (../../../docs/security.md §Body Size Limiting).
|
|
23
26
|
- `http/surface.ts` — `AppSurface`, `AppSurfaceSpec`, `generate_app_surface`, diagnostics.
|
|
24
27
|
- `http/surface_query.ts` — pure filters/groupings over `AppSurface`.
|
|
25
28
|
- `http/proxy.ts` — trusted-proxy middleware, CIDR parsing, rightmost-first XFF resolution. Pulls `hono/utils/ipaddr` for CIDR matching.
|
|
@@ -29,7 +32,7 @@ effects, see ../../../docs/architecture.md.
|
|
|
29
32
|
- `http/jsonrpc.ts` — JSON-RPC 2.0 envelope schemas (MCP superset), `JsonrpcErrorCode`, `_meta`.
|
|
30
33
|
- `http/jsonrpc_errors.ts` — `ThrownJsonrpcError`, `jsonrpc_errors` throwers, HTTP-status mappings.
|
|
31
34
|
- `http/jsonrpc_helpers.ts` — message builders, type guards, input/result normalizers, and `classify_jsonrpc_message`, the one envelope classifier both transports run.
|
|
32
|
-
- `http/health_schema.ts` — `HEALTH_PATH` + the `HealthResponse` schema, browser-safe, shared by the health route spec and the client probe (`ui/backend_probe.svelte.ts`).
|
|
35
|
+
- `http/health_schema.ts` — `HEALTH_PATH` + the `HealthResponse` schema (a fuz_schema `object`), browser-safe, shared by the health route spec and the client probe (`ui/backend_probe.svelte.ts`).
|
|
33
36
|
- `http/common_routes.ts` — health check + readiness probe (`/ready` schema-drift deploy gate) + authenticated server-status route specs (the surface explorer route lives in `server/surface_route.ts`).
|
|
34
37
|
- `http/db_routes.ts` — allowlist-gated keeper-only table browser route specs (`public` schema, minus the `NON_BROWSABLE_TABLES` credential floor).
|
|
35
38
|
- `http/pending_effects.ts` — `emit_after_commit` + `dispatch_with_post_commit_rollback` (the shared rollback-discard wrapper both dispatch sites use) + `flush_request_effects` (the one two-queue flush HTTP and WS share, over `flush_pending_effects` + `flush_post_commit_effects`) + `EffectErrorContext` + `EmitAfterCommitContext`.
|
|
@@ -55,7 +58,8 @@ consumers.
|
|
|
55
58
|
- `mints_credential?: boolean` — the route issues a session cookie while declaring no auth (login, signup, bootstrap); assembly refuses it outside `AUTH_MIDDLEWARE_PATH`, as it does any route whose `auth.account` is not `'none'` (`assert_credential_routes_in_auth_scope` in `auth/middleware.ts`)
|
|
56
59
|
- `reads_credential?: boolean` — the handler reads the resolved account while the route declares no auth gate, answering an anonymous caller itself (account status, the cell-scoped fact read, `create_rpc_endpoint`'s pair, whose dispatcher gates per action); held inside `AUTH_MIDDLEWARE_PATH` by the same assertion. Such a handler reads the account through `get_public_account_id` (`auth/request_context.ts`), which answers a scope-narrowed token as anonymous — the RPC pair excepted, its dispatcher gating each method
|
|
57
60
|
- `rate_limit?: RateLimitKey` — metadata only (`'ip' | 'account' | 'both'`); auto-derives 429
|
|
58
|
-
- `errors?:
|
|
61
|
+
- `errors?: ReadonlyArray<RestErrorDef>` — the handler's own error definitions (`rest_error`); joins the route error map beside the derived and middleware ones
|
|
62
|
+
- `jsonrpc?: boolean` — the route answers JSON-RPC envelopes, not REST bodies; set by `create_rpc_endpoint`, read by the DEV error check and `assert_response_matches_spec`
|
|
59
63
|
- `transaction?: boolean` — declarative transaction wrapping (see below)
|
|
60
64
|
|
|
61
65
|
Every schema field takes a Zod or a `@fuzdev/fuz_schema` schema
|
|
@@ -115,10 +119,10 @@ wrapper). See `auth/signup_routes.ts`.
|
|
|
115
119
|
3. **Pre-authorization auth guards** — every gate that reads only what the auth middleware set, in coarse-to-fine order: `require_auth` (401 `ERROR_AUTHENTICATION_REQUIRED`) when `auth.account === 'required'` or `auth.actor === 'required'`; `require_credential_types(types)` (403 `ERROR_CREDENTIAL_TYPE_REQUIRED` with `required_credential_types: ReadonlyArray<string>`) when `auth.credential_types?.length`; `require_token_scope(capability)` (403 `ERROR_TOKEN_SCOPE_REQUIRED` with `required_scope`, the token-scope refusal) when `auth.required_scope` names a capability. All fire before any body parsing — so a caller they refuse never sees route-shape information from input parse failures — and before actor resolution, so a wrong channel costs no DB work and never learns account state (e.g. that the account is multi-actor). The `AuthGuardResolver` (e.g. `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`) returns this set as `pre_authorization: Array<MiddlewareHandler>`.
|
|
116
120
|
4. **Authorization phase** — when `spec.auth.actor !== 'none'`, resolves the acting actor against the resolved credential's account (`get_resolved_auth`, set by the auth middleware) plus the `acting` selector (`validated_query.acting` on GETs; read off the raw body on mutations, since body validation now runs after the gates), builds `RequestContext` via `build_request_context`, and sets `REQUEST_CONTEXT_KEY`. When `auth.account !== 'none' && auth.actor === 'none'`, an account-only context is built. Resolution failures return 400 `ERROR_ACTOR_REQUIRED` (with `available[]`) or `ERROR_ACTOR_NOT_ON_ACCOUNT` (or 500 `ERROR_NO_ACTORS_ON_ACCOUNT` on signup-invariant violation, 500 `ERROR_ACCOUNT_VANISHED` on torn account/actor reads after a successful resolve). Public routes (`account: 'none' && actor: 'none'`) skip this phase entirely.
|
|
117
121
|
5. **Post-authorization auth guards** — `require_role(roles)` (403 `ERROR_INSUFFICIENT_PERMISSIONS` with `required_roles: ReadonlyArray<string>`) when `auth.roles?.length`. The only gate in this phase, because it is the only one that reads `REQUEST_CONTEXT_KEY` (populated by step 4) rather than the auth middleware's own context vars. Multi-role specs admit any-of via `has_any_scoped_role(ctx, roles, null)`.
|
|
118
|
-
6. **Input validation** — JSON body parsed + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Every schema refusal's `issues` are `WireIssue`s (`to_wire_issues`, `schema_issues.ts`), sent under DEV only (`dev_only`). Skipped on GET and `z.null()`
|
|
122
|
+
6. **Input validation** — JSON body parsed + validated; mismatch returns 400 `ERROR_INVALID_JSON_BODY` (not JSON) or `ERROR_INVALID_REQUEST_BODY` (schema failure with `issues`). Every schema refusal's `issues` are `WireIssue`s (`to_wire_issues`, `schema_issues.ts`), sent under DEV only (`dev_only`). Skipped on GET and on a null input (`is_null_schema`: `z.null()` or `literal(null)`). The validated input lands on `c.var.validated_input`.
|
|
119
123
|
7. **Handler** — wrapped in transaction when `use_transaction` (see above), receives `RouteContext`
|
|
120
|
-
8. **Error catch** — catches a thrown JSON-RPC error (`ThrownJsonrpcError`, recognized by brand through `to_thrown_jsonrpc_error`, so one from a second fuz_app copy maps too; a foreign error class carrying a JSON-RPC `code` falls to the generic path) → maps to HTTP status + the flat REST
|
|
121
|
-
9. **DEV-only output
|
|
124
|
+
8. **Error catch** — catches a thrown JSON-RPC error (`ThrownJsonrpcError`, recognized by brand through `to_thrown_jsonrpc_error`, so one from a second fuz_app copy maps too; a foreign error class carrying a JSON-RPC `code` falls to the generic path) → maps to HTTP status + the flat REST error body (`{error: <reason>, message?, ...rest_data}`); catches generic `Error` → 500 `{error: 'internal_error', message?}` (message only in DEV). The reason string comes from `err.data.reason` when set (consumer-supplied canonical reason override) or from `jsonrpc_error_code_to_name(err.code)` (e.g. `-32003 → 'not_found'`). The flat shape matches what middleware and direct handlers emit — REST callers see one envelope across every emit site, while the JSON-RPC dispatcher keeps its own `{jsonrpc, id, error: {code, message, data}}` envelope on the RPC mount.
|
|
125
|
+
9. **DEV-only output validation** — a 2xx JSON body against `spec.output` (see below); error responses are the outer DEV error check's
|
|
122
126
|
|
|
123
127
|
**Ordering: 401 → authz → 403 → 400 → handler.** Mirrors the RPC dispatcher
|
|
124
128
|
(`actions/action_rpc.ts`) so HTTP RPC and REST fail with the same priority, and
|
|
@@ -146,17 +150,17 @@ schema in scope.
|
|
|
146
150
|
are the contract with external callers.
|
|
147
151
|
|
|
148
152
|
**Output and error schemas are validated DEV-only** via `DEV` from
|
|
149
|
-
`esm-env
|
|
153
|
+
`esm-env`, each in one place:
|
|
150
154
|
|
|
151
|
-
-
|
|
152
|
-
- On
|
|
153
|
-
-
|
|
154
|
-
- Always accepts a 500 `{error: 'internal_error'}`: the error catch answers it for any generic throw, so no route declares it
|
|
155
|
-
- **Logs on mismatch, returns the response unchanged** — never throws, never mutates the body
|
|
155
|
+
- **Output** — `wrap_output_validation`, per route: a 2xx JSON body against `spec.output`. Skips non-`application/json` responses so SSE doesn't hang on `.json()`.
|
|
156
|
+
- **Errors** — `create_dev_route_error_check` (`http/dev_route_error_check.ts`), one outer middleware `create_app_server` mounts outermost (`app.use('*')`, first after `onError`), so it sees what every layer answers — a middleware's refusal (body limit, origin, auth guards) as much as a handler's or the error catch's. After the request it finds the route with Hono's own router (`create_route_lookup`: the `SmartRouter` over a `RegExpRouter` and a `TrieRouter` that `new Hono()` builds, the route specs added in mount order, the first match the route, `HEAD` read as `GET`) and checks a JSON body at 400 and up against the route's error map (`check_route_error`, `http/route_error_check.ts`): a status the map lacks logs `Undeclared error status (S): METHOD path`, a body off the status's schema `Error schema mismatch (S): METHOD path`. Always accepted: a 500 `internal_error` and a 503 `service_unavailable` (`ALWAYS_ACCEPTED_ERRORS`, which the catch layers answer on any route). On a `jsonrpc` route (the pair `create_rpc_endpoint` builds) a JSON-RPC error envelope is skipped (`is_jsonrpc_error_response`): the endpoint answers its refusals as envelopes, which no REST error definition describes, and the dispatch core checks its own outputs. On any other route an envelope-shaped body is checked. Skipped: non-JSON responses (`is_json_response`, the gate both checks run), and a request no route spec matches — an unmatched path's 404 is Hono's plain text, with no JSON convention to hold it to. `assert_response_matches_spec` runs the same `check_route_error`.
|
|
157
|
+
- **Logs on mismatch, returns the response unchanged** — never throws (a throw inside the error check, its logger's included, is swallowed), never mutates the body
|
|
156
158
|
|
|
157
|
-
Production short-circuits
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
Production short-circuits: `wrap_output_validation` returns the handler
|
|
160
|
+
unwrapped and `create_dev_route_error_check` returns `null`, so nothing is
|
|
161
|
+
mounted — no parse work on the hot path. Uniform across all three
|
|
162
|
+
action-handler surfaces (REST, RPC, WS); see ../../../docs/architecture.md
|
|
163
|
+
§DEV-only Output Validation.
|
|
160
164
|
|
|
161
165
|
### Helpers
|
|
162
166
|
|
|
@@ -167,39 +171,63 @@ WS); see ../../../docs/architecture.md §DEV-only Output Validation.
|
|
|
167
171
|
|
|
168
172
|
`http/error_schemas.ts` is the **declarative** error surface:
|
|
169
173
|
|
|
170
|
-
- `ERROR_*` `snake_case` string constants — single source of truth;
|
|
171
|
-
- `
|
|
172
|
-
- `
|
|
173
|
-
- `
|
|
174
|
+
- `ERROR_*` `snake_case` string constants (`ERROR_FORBIDDEN_HOST` / `REST_FORBIDDEN_HOST` the Rust spine's host gate, which the TS spine lacks) — single source of truth for codes; they double as JSON-RPC `data.reason`s, so they carry no HTTP status
|
|
175
|
+
- `rest_error(status, code, fields?, headers?)` → `RestErrorDef<S, C, F>` — one code at one status; the code must be a code, `REST_ERROR_CODE_PATTERN` (`^[a-z][a-z0-9_]*$`, `is_rest_error_code`) — a throw at definition, and a literal plainly off it (prose, uppercase, a leading digit) a type error — so prose goes in `message`; its body `loose_object({error: literal(code), ...fields})` as `.schema`; `headers` derives response headers from a body (`Retry-After`). Status and code must be literals. One `REST_*` definition per code a route or middleware answers (`REST_TABLE_NOT_FOUND`, `REST_RATE_LIMIT_EXCEEDED`, …); a code with a second body shape gets a second definition (`REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`, `/account/status`'s 401 with `bootstrap_available`)
|
|
176
|
+
- `to_error_schemas(defs)` — a status map from definitions: one schema at a status maps to it, more to a `union` in list order
|
|
177
|
+
- `ErrorSchemas = Record<number, AnySchema>` — a status map, what `to_error_schemas` groups definitions into: one schema at a status, or a `union` of them
|
|
178
|
+
- `same_rest_error(a, b)` / `dedupe_rest_errors(defs)` — a definition is the same as another when it is the same object, or the same status, code, `headers`, and field schemas; a list keeps the first of each
|
|
179
|
+
- `RateLimitKey` (`rate_limiter.ts`) — `'ip' | 'account' | 'both'`
|
|
174
180
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
(`required_roles`, `required_credential_types`, `retry_after`, `detail`) are diagnostic.
|
|
179
|
-
|
|
180
|
-
Pair every schema with the `z.infer` type export.
|
|
181
|
-
|
|
182
|
-
### Three-layer error-schema merge
|
|
183
|
-
|
|
184
|
-
`merge_error_schemas(spec, middleware_errors?)` (in `http/schema_helpers.ts`)
|
|
185
|
-
merges three layers, later overrides earlier at the same status code; an
|
|
186
|
-
entry left `undefined` is absent (`strip_undefined_error_schemas`), so it
|
|
187
|
-
overrides nothing:
|
|
181
|
+
`RouteSpec.errors` and `MiddlewareSpec.errors` are lists of definitions
|
|
182
|
+
(`ReadonlyArray<RestErrorDef>`), so a Zod error entry is impossible by type,
|
|
183
|
+
and `apply_route_specs` refuses anything else at registration.
|
|
188
184
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
185
|
+
All error bodies are loose objects — intentional because multiple
|
|
186
|
+
producers (middleware + handler) can emit different extra fields at the
|
|
187
|
+
same status code, and a thrown error flattens its `data` into the body. The
|
|
188
|
+
`error` code is the contract; extra keys (`required_roles`,
|
|
189
|
+
`required_credential_types`, `retry_after`, `message`) are diagnostic.
|
|
190
|
+
|
|
191
|
+
A body's type is its definition's: `Infer<typeof REST_X.schema>`, or `RestErrorBody<C, F>`.
|
|
192
|
+
|
|
193
|
+
### The route error map
|
|
194
|
+
|
|
195
|
+
A route's declared errors are **one map**, built by
|
|
196
|
+
`resolve_route_error_map(spec, middleware_specs?)` (in `http/route_errors.ts`):
|
|
197
|
+
the union of three layers, in order, where nothing replaces anything — a
|
|
198
|
+
definition at a status another layer declares is one more branch there, and a
|
|
199
|
+
repeat (`same_rest_error`) counts once. Two shapes of one code at one status
|
|
200
|
+
(`REST_AUTHENTICATION_REQUIRED` and `REST_AUTHENTICATION_REQUIRED_BOOTSTRAP`)
|
|
201
|
+
are both kept, a union of their bodies. The result, `RouteErrorMap`, holds the
|
|
202
|
+
definitions (`defs`) and the status map they group into (`schemas`):
|
|
203
|
+
|
|
204
|
+
1. **Derived** — `derive_route_errors({method, auth, has_input?, has_params?, has_query?, rate_limit?})`, narrowed to the slots the route has:
|
|
205
|
+
- a body — `input` not null, `method` not `GET` (the input middleware skips a `GET`) → 400 `invalid_request_body`, `invalid_json_body`
|
|
206
|
+
- `params` → 400 `invalid_route_params`; `query` → 400 `invalid_query_params`
|
|
207
|
+
- `auth.actor !== 'none'` → 400 `actor_required`, `actor_not_on_account`, 500 `no_actors_on_account`, `account_vanished` — what the dispatcher's authorization phase emits on routes whose input declares `acting?: ActingActor` (per registry-time invariant 2)
|
|
208
|
+
- `auth.account === 'required'` or `auth.actor === 'required'` → 401 `authentication_required` (`REST_AUTHENTICATION_REQUIRED`), the only body the pre-authorization gate answers
|
|
209
|
+
- `auth.required_scope` → 403 `token_scope_required`; `auth.credential_types?.length` → 403 `credential_type_required`; `auth.roles?.length` → 403 `insufficient_permissions` — in the order the gates fire, each carrying what the route demanded
|
|
210
|
+
- `rate_limit` → 429 `rate_limit_exceeded` (`retry_after`, a non-negative integer of seconds)
|
|
211
|
+
- every `POST` → 415 `unsupported_content_type`
|
|
212
|
+
2. **Middleware** — the definitions of each `MiddlewareSpec` that runs on the route (`middleware_spec_applies`: its path, less its carve-outs), in list order — the body limit's 413 and 400, the origin check's 403 `forbidden_origin`, a consumer layer's own
|
|
213
|
+
3. **Explicit** — `RouteSpec.errors`, the handler's own codes (a 404, a 409, a second 401)
|
|
214
|
+
|
|
215
|
+
`resolve_app_route_error_maps(route_specs, middleware_specs)` builds every
|
|
216
|
+
route's map keyed `METHOD path` (`format_route_key`); `create_app_surface_spec`
|
|
217
|
+
builds it once and carries it as `AppSurfaceSpec.route_error_maps`, and
|
|
218
|
+
`create_app_server` hands the same maps to the DEV error check. Every reader
|
|
219
|
+
reads it: the surface (status-keyed, a status's definitions an `anyOf`), the
|
|
220
|
+
DEV error check, `assert_response_matches_spec`, error coverage
|
|
221
|
+
(`ErrorCoverageCollector`, which reads codes from `defs`), `describe_adversarial_auth`,
|
|
222
|
+
`describe_adversarial_404`, and `assert_error_schema_valid`.
|
|
223
|
+
`get_route_error_map(route_error_maps, spec)` reads a map, or without one resolves the
|
|
224
|
+
route alone; given a map with no entry for the route, it throws naming the key.
|
|
225
|
+
|
|
226
|
+
Routes typically only declare `errors` for handler-specific codes (404, 409,
|
|
227
|
+
422): what the framework answers is derived, and what a middleware layer
|
|
228
|
+
answers is the layer's.
|
|
229
|
+
|
|
230
|
+
The derived actor codes read `spec.auth.actor !== 'none'` directly — per
|
|
203
231
|
registry-time invariant 2 (`actor !== 'none' ⟺ input declares acting?: ActingActor`),
|
|
204
232
|
the auth-shape axis is the single source of truth.
|
|
205
233
|
|
|
@@ -207,9 +235,10 @@ the auth-shape axis is the single source of truth.
|
|
|
207
235
|
above is sound because the framework authors the errors at fixed
|
|
208
236
|
middleware sites — 401 from `require_auth`, 400 from
|
|
209
237
|
`create_input_validation`, 403 from `require_role` /
|
|
210
|
-
`require_credential_types`, 429 from rate limiters
|
|
211
|
-
documents the framework's
|
|
212
|
-
|
|
238
|
+
`require_credential_types`, 429 from rate limiters — and narrows each to
|
|
239
|
+
the slots that reach those sites. Auto-derivation documents the framework's
|
|
240
|
+
own emissions; consumers add their handler's codes in `RouteSpec.errors`,
|
|
241
|
+
beside them.
|
|
213
242
|
|
|
214
243
|
The same auto-derivation pattern is **not** appropriate for
|
|
215
244
|
consumer-authored inputs (or handler outputs). A consumer's spec declares
|
|
@@ -242,9 +271,9 @@ confirmation.
|
|
|
242
271
|
(input validation) and `http/surface.ts` (surface generation).
|
|
243
272
|
|
|
244
273
|
**Import `is_null_schema`, `is_void_schema`, `to_void_params`, `to_input_params`, `is_strict_object_schema`, `schema_to_surface`,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
274
|
+
and `middleware_applies` from `http/schema_helpers.ts`, and the route error map from
|
|
275
|
+
`http/route_errors.ts`.** `http/surface.ts` only imports and re-uses them for
|
|
276
|
+
generation logic.
|
|
248
277
|
|
|
249
278
|
Key helpers:
|
|
250
279
|
|
|
@@ -257,9 +286,8 @@ Key helpers:
|
|
|
257
286
|
- `is_strict_object_schema(schema)` — detects `z.strictObject()` by checking `schema.def.catchall instanceof z.ZodNever`, or a fuz_schema `object` (not `strip_object` / `loose_object`); a fuz_schema `pipe` is read through to its first schema when no stage is a `transform` (so a refined `object` reads strict), while any Zod `ZodPipe` — even `O.pipe(O)` with no transform — reads not strict
|
|
258
287
|
- `schema_to_surface(schema, {io?, source?, on_unrepresentable?}?)` — throws first on a value of neither library (`assert_validation_schema`, naming `source`, so an assembled app's slot of neither library fails boot as registration would refuse it, not as an unwritable JSON Schema); Zod or fuz_schema → JSON Schema (`z.toJSONSchema` or fuz_schema's `to_json_schema`, by `is_schema`), on the side `io` names (`'output'` by default), with `$schema` and `default` keys stripped recursively (defaults may be non-deterministic; `$schema` is snapshot noise). `null` for a null or void schema. A part JSON Schema can't say (an output-side transform, a `z.custom()`, a fuz_schema `check`) is left out or written as `{}` (`unrepresentable: 'any'`) and reported to `on_unrepresentable`; a schema with nothing describable (`{}` from a schema other than `z.unknown()` / `z.any()`) or one an emitter refuses outright throws, prefixed with `source` — so a root-level transform output (`z.unknown().transform(f)` included), `z.custom()` or `z.date()` fails server assembly. It never answers `null` for a failure, which would read as "no input" and drop the schema from every suite that reads the surface
|
|
259
288
|
- `middleware_applies(mw_path, route_path)` — Hono pattern matching: `'*'`, exact, `'/api/*'` prefix (handles `prefix.slice(0, -1)` so `/api/*` also matches the bare `/api`)
|
|
260
|
-
- `
|
|
261
|
-
- `
|
|
262
|
-
- `strip_undefined_error_schemas(errors)` — an error-schema map without its `undefined` entries, what the merge and `collect_middleware_errors` read each layer through
|
|
289
|
+
- `middleware_carves_out(spec, route_path)` — one of the layer's `carve_outs` applies to the route; the carve-out half of `middleware_spec_applies`, which `assert_full_middleware_stack` reads to relax a carved-out route's expected stack
|
|
290
|
+
- `middleware_spec_applies(spec, route_path)` — the layer runs on the route: its `path` applies and none of its `carve_outs` does; what the route error map takes middleware definitions by
|
|
263
291
|
|
|
264
292
|
## Surface Generation
|
|
265
293
|
|
|
@@ -285,7 +313,7 @@ params and query on the input side (what the server accepts, so a
|
|
|
285
313
|
event params on the output side — with an `info` diagnostic (category
|
|
286
314
|
`schema`, `source` naming the route or method and side) for each schema
|
|
287
315
|
part of which is left out or written as `{}`, throws naming the same source for one
|
|
288
|
-
that can't be written,
|
|
316
|
+
that can't be written, writes each route's error map (`route_error_maps`) status by status, derives `is_mutation`
|
|
289
317
|
and `transaction` from method/spec, and surfaces RPC methods with their
|
|
290
318
|
`RouteAuth` directly (same shape on both `ActionSpec.auth` and
|
|
291
319
|
`RouteSpec.auth`, no translation step).
|
|
@@ -300,16 +328,16 @@ No side effects, no state — filters and groupings over `AppSurface`:
|
|
|
300
328
|
- `filter_protected_routes` / `filter_public_routes`
|
|
301
329
|
- `filter_role_routes` / `filter_keeper_routes` / `filter_credential_gated_routes` (any `auth.credential_types` gate — superset of keeper)
|
|
302
330
|
- `filter_routes_with_input` / `filter_routes_with_params` / `filter_routes_with_query`
|
|
303
|
-
- `format_route_key(route)` → `'METHOD /path'`
|
|
331
|
+
- `format_route_key(route)` → `'METHOD /path'`, of a surface route or a route spec — the key of the route error maps, and every `METHOD path` label
|
|
304
332
|
- `surface_auth_summary(surface)` — counts per auth bucket (`none`, `keeper`, `role`, `credential`, `authenticated`, `optional`, `other`), roles and credential channels broken out by name; multi-role / multi-channel specs count once per name. One private categorizer decides the bucket: keeper is tested before the role bucket and the general credential bucket after it — keeper is an authority _level_ and names the route, a session gate is a _channel_ restriction over the authority the route already declares (so the audit SSE stream counts under `role`)
|
|
305
333
|
|
|
306
334
|
The per-route auth predicates these filters compose over (`is_public_auth`,
|
|
307
335
|
`is_role_auth`, `is_credential_gated_auth`, `is_keeper_auth`,
|
|
308
336
|
`is_plain_authenticated_auth`, plus `needs_actor`) live
|
|
309
|
-
in `http/auth_shape.ts` next to the canonical `RouteAuth`
|
|
337
|
+
in `http/auth_shape.ts` next to the canonical `RouteAuth` type — import
|
|
310
338
|
them from there, not from this module. Same predicates back the
|
|
311
339
|
dispatcher's authorization phase, the route-spec auth-guard resolver,
|
|
312
|
-
`
|
|
340
|
+
`derive_route_errors`'s actor codes, and the testing harnesses.
|
|
313
341
|
|
|
314
342
|
Consumer code (tests, attack-surface helpers, `SurfaceExplorer.svelte`)
|
|
315
343
|
should reach for these rather than inlining `.filter` chains.
|
|
@@ -323,7 +351,7 @@ interface MiddlewareSpec {
|
|
|
323
351
|
name: string;
|
|
324
352
|
path: string; // Hono pattern — '*', exact, or '/api/*'
|
|
325
353
|
handler: MiddlewareHandler;
|
|
326
|
-
errors?:
|
|
354
|
+
errors?: ReadonlyArray<RestErrorDef>; // definitions this layer may answer with
|
|
327
355
|
}
|
|
328
356
|
```
|
|
329
357
|
|
|
@@ -355,7 +383,7 @@ Origin allowlisting for locally-running services — **not** the CSRF layer.
|
|
|
355
383
|
CSRF is handled by `SameSite: strict` on session cookies (`auth/session_middleware.ts`).
|
|
356
384
|
|
|
357
385
|
- `parse_allowed_origins(raw)` — comma-separated entries → `Result<{origins: Array<RegExp>}, {errors: Array<AllowedOriginsError>}>`; every refused entry is reported (`{kind, index, entry}`, 1-based), a blank value is `{kind: 'no_origins'}`
|
|
358
|
-
- `OriginPatternErrorKind` / `AllowedOriginsErrorKind` — the refusal kinds, wire names shared with the Rust spine; `ALLOWED_ORIGINS_ERROR_MESSAGES` the reason per kind, `format_allowed_origins_error` one refusal as a boot-error line (entry quoted and escaped)
|
|
386
|
+
- `OriginPatternErrorKind` / `AllowedOriginsErrorKind` — the refusal kinds, fuz_schema `one_of`s whose `def` is the names, wire names shared with the Rust spine; `ALLOWED_ORIGINS_ERROR_MESSAGES` the reason per kind, `format_allowed_origins_error` one refusal as a boot-error line (entry quoted and escaped)
|
|
359
387
|
- `should_allow_origin(origin, patterns)` — case-insensitive match; a value that isn't visible ASCII matches nothing
|
|
360
388
|
- `verify_request_source(allowed_patterns, carve_outs?)` — Hono handler: `Origin` present → must match allowlist or 403 `ERROR_FORBIDDEN_ORIGIN`; no `Origin` → allow through (curl, CLI, token auth is primary control). A repeated `Origin` reaches it joined (`a, b`) and is refused. A request whose path a `carve_outs` entry (`MiddlewareCarveOut`, `{path, reason}`) matches passes unchecked
|
|
361
389
|
- `is_browser_context(c)` — true when `Origin` or `Referer` is present (`!== undefined`, so empty-string counts). The bearer + daemon-token middleware discard their credential when true; twin of the Rust spine's `bearer_auth::is_browser_context`. Distinct from `verify_request_source` (allowlist gate) — this only detects browser context
|
|
@@ -567,7 +595,7 @@ auth-domain dependencies:
|
|
|
567
595
|
|
|
568
596
|
- `create_health_route_spec()` — `GET /health` (`HEALTH_PATH`), public, returns `{status: 'ok'}` (`HealthResponse`, both from `http/health_schema.ts`). Infrastructure endpoint for uptime monitors, and what `ui/backend_probe.svelte.ts` reads
|
|
569
597
|
- `create_ready_route_spec({expected, log})` — `GET /ready`, public, the deploy gate. Introspects the live DB's columns (`db/schema_ready.ts`) and compares against the committed `expected` column map: `200 {ready: true}` on match, else `503 {error: 'schema_drift' | 'db_unreachable'}`. Detailed drift logs server-side only (minimal body — no schema leak, mirrors why `/api/surface` is admin-only). Throws at assembly on an empty `expected` (fail-loud). Opt-in like `/health`; pair with `load_expected_schema(url)` — loads + URL-caches a consumer's committed `expected_schema.json` and throws on an empty map
|
|
570
|
-
- `create_server_status_route_spec({version, get_uptime_ms})` — `GET /api/server/status`, authenticated, returns `{version, uptime_ms}`
|
|
598
|
+
- `create_server_status_route_spec({version, get_uptime_ms})` — `GET /api/server/status`, authenticated, returns `{version, uptime_ms}` (`uptime_ms` a non-negative integer)
|
|
571
599
|
|
|
572
600
|
Auth-aware variants (account status, bootstrap status) live in `auth/` —
|
|
573
601
|
`http/common_routes.ts` stays generic.
|
|
@@ -588,10 +616,16 @@ table browser; the factory is domain-agnostic.
|
|
|
588
616
|
- `DELETE /tables/:name/rows/:id` — delete by PK, compared typed as `"<pk>" = $1` (twinning the Rust spine — the untyped text-format param makes PG coerce the id with the PK type's input function, so the delete index-scans and follows the column type's semantics; an uncoercible id — 22P02/22003 — is the same clean 404 as a typed miss). `RETURNING "<pk>"::text` feeds the audit trail the row's canonical PK rendering. Returns 400 if the table is excluded by policy (`ERROR_TABLE_NOT_DELETABLE`) or has no single-column PK (`ERROR_TABLE_NO_PRIMARY_KEY`), 404 if row missing (`ERROR_ROW_NOT_FOUND`) or table missing/unbrowsable (`ERROR_TABLE_NOT_FOUND`), 409 on a referencing-row refusal (pg error `23503` foreign_key_violation, or `23001` restrict_violation — PG 18+ raises the latter for `ON DELETE RESTRICT`)
|
|
589
617
|
|
|
590
618
|
Every route declares `acting?: ActingActor` on its `query` (registry-time
|
|
591
|
-
invariant 2). The
|
|
592
|
-
|
|
593
|
-
`
|
|
594
|
-
`
|
|
619
|
+
invariant 2). The routes' schemas are `@fuzdev/fuz_schema`: the queries
|
|
620
|
+
`object`s over the twin `ActingActor`, and the counts and positions they
|
|
621
|
+
answer with (`row_count`, `total`, `offset`, `limit`) non-negative integers.
|
|
622
|
+
`GET /tables/:name`'s paging params are each a `query_int`:
|
|
623
|
+
`pipe(string, regex(/^[+-]?\d+$/), transform(Number))`, then `safe_integer`
|
|
624
|
+
and its bounds, under a default — the spellings the Rust twin's
|
|
625
|
+
`str::parse::<i64>` reads, so `""`, `" 5"`, `"1e2"`, `"5.0"` and `"0x10"` are
|
|
626
|
+
refused on both. The surface writes each as a string with that `pattern`,
|
|
627
|
+
its bounds in the `description`, and notes the steps it can't say as an
|
|
628
|
+
`info` diagnostic.
|
|
595
629
|
|
|
596
630
|
**The allowlist gates everything.** `DbRouteOptions.browsable_tables` is
|
|
597
631
|
required with no "all" escape hatch — the table list shows only listed tables,
|
|
@@ -674,4 +708,4 @@ Interfaces exported for consumer use: `TableInfo`, `TableWithCount`,
|
|
|
674
708
|
- **Middleware ordering** is assembled by `create_app_server` — see the root ../../../CLAUDE.md §Middleware Ordering. The invariants `http/` needs consumers to uphold: trusted-proxy runs before auth/rate-limit; origin verification runs before session parsing; `client_ip` must be set before any handler or rate limiter reads it
|
|
675
709
|
- **No re-exports.** Import every symbol from its canonical source module. `http/surface.ts` no longer re-exports schema helpers — go through `http/schema_helpers.ts`
|
|
676
710
|
- **Input/output schemas align with SAES.** When wiring RPC via `actions/action_rpc.ts`, the same Zod types flow through unchanged (see `actions/CLAUDE.md` §Single JSON-RPC 2.0 endpoint)
|
|
677
|
-
- **Error modules are complementary, not redundant.** `http/error_schemas.ts` is
|
|
711
|
+
- **Error modules are complementary, not redundant.** `http/error_schemas.ts` is declaration-first (for routes and surface); `http/jsonrpc_errors.ts` is throw-first (for handlers and the catch layer). A single `ERROR_*` code can be raised either way depending on whether the handler needs to also attach diagnostic fields
|
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
* invariant 2 (the `actor !== 'none' ⟺ input or query declares
|
|
29
29
|
* acting?: ActingActor` biconditional), which introspects the spec's
|
|
30
30
|
* input/query schemas, by `assert_route_auth_acting_biconditional`. Specs
|
|
31
|
-
* are plain objects that no registration path parses, so
|
|
32
|
-
*
|
|
31
|
+
* are plain objects that no registration path parses, so both checks live in
|
|
32
|
+
* code rather than on a schema.
|
|
33
33
|
*
|
|
34
34
|
* @module
|
|
35
35
|
*/
|
|
36
36
|
import { z } from 'zod';
|
|
37
|
+
import { type Infer } from '@fuzdev/fuz_schema/schema.ts';
|
|
37
38
|
import type { ValidationSchema } from '../schema_issues.js';
|
|
38
39
|
/**
|
|
39
40
|
* `acting` field shared by every input that needs the caller's acting actor.
|
|
@@ -104,19 +105,14 @@ export declare const parse_acting: (value: unknown) => string | undefined;
|
|
|
104
105
|
* credential; the authorization phase 4xx for `actor === 'required'`
|
|
105
106
|
* without an actor binding).
|
|
106
107
|
*/
|
|
107
|
-
export declare const AuthAxisState:
|
|
108
|
-
|
|
109
|
-
none: "none";
|
|
110
|
-
required: "required";
|
|
111
|
-
}>;
|
|
112
|
-
export type AuthAxisState = z.infer<typeof AuthAxisState>;
|
|
108
|
+
export declare const AuthAxisState: import("@fuzdev/fuz_schema/schema.ts").Schema<"optional" | "none" | "required", "optional" | "none" | "required", "one_of", readonly ["none", "optional", "required"]>;
|
|
109
|
+
export type AuthAxisState = Infer<typeof AuthAxisState>;
|
|
113
110
|
/**
|
|
114
111
|
* The canonical auth shape used by both `ActionSpec.auth` and
|
|
115
112
|
* `RouteSpec.auth`.
|
|
116
113
|
*
|
|
117
114
|
* Cross-axis registry invariants, checked at registration by
|
|
118
|
-
* `assert_route_auth_invariants
|
|
119
|
-
* same check, when a caller parses an auth shape):
|
|
115
|
+
* `assert_route_auth_invariants`:
|
|
120
116
|
*
|
|
121
117
|
* 1. **Roles imply actor.** `roles?.length` ⟹ `actor === 'required'`.
|
|
122
118
|
* Role checks read the actor's role_grants, so a role-gated spec without
|
|
@@ -132,26 +128,49 @@ export type AuthAxisState = z.infer<typeof AuthAxisState>;
|
|
|
132
128
|
*
|
|
133
129
|
* Invariant 2 — the `actor !== 'none' ⟺ input or query declares
|
|
134
130
|
* acting?: ActingActor` biconditional — needs introspection of the
|
|
135
|
-
* spec's input/query schemas, so it is checked at registration
|
|
136
|
-
*
|
|
137
|
-
* below.
|
|
131
|
+
* spec's input/query schemas, so it is checked separately at registration.
|
|
132
|
+
* See `assert_route_auth_acting_biconditional` below.
|
|
138
133
|
*/
|
|
139
|
-
export
|
|
140
|
-
account:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
134
|
+
export interface RouteAuth {
|
|
135
|
+
account: AuthAxisState;
|
|
136
|
+
actor: AuthAxisState;
|
|
137
|
+
roles?: ReadonlyArray<string> | undefined;
|
|
138
|
+
credential_types?: ReadonlyArray<string> | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* The capability a **narrowed** api token's scope must admit to reach this
|
|
141
|
+
* route, in the `<section>:<id>` vocabulary a denial reports back as
|
|
142
|
+
* `required_scope`:
|
|
143
|
+
*
|
|
144
|
+
* - `surface:<name>` — a non-RPC surface, refused to every narrowed token
|
|
145
|
+
* whatever its method list says (token scoping's rule that a narrowed
|
|
146
|
+
* token is RPC-only). `surface:audit_stream`, `surface:fact_bare`,
|
|
147
|
+
* `surface:account_verify`, and `surface:app_surface` are the spine's
|
|
148
|
+
* route-spec ones; a consumer names its own without registering it.
|
|
149
|
+
*
|
|
150
|
+
* The `rpc:<method>` arm of that vocabulary is the dispatcher's per-method
|
|
151
|
+
* gate, which a route never reaches, so a route may not declare it.
|
|
152
|
+
*
|
|
153
|
+
* Declaring it makes the guard resolver mount the refusal ahead of the role
|
|
154
|
+
* gate, instead of the route hand-rolling the check in its handler (which
|
|
155
|
+
* the auth phase has already role-gated by then, so a narrowed token whose
|
|
156
|
+
* account lacks the role would be told about the role rather than about the
|
|
157
|
+
* scope).
|
|
158
|
+
*
|
|
159
|
+
* Opt-in rather than blanket: no narrowed token reaches login (which reads
|
|
160
|
+
* no credential) or logout and the password change (session-only), the
|
|
161
|
+
* RPC endpoint runs its own per-method check inside the dispatcher, the
|
|
162
|
+
* `reads_credential` routes that answer anonymous callers (account status,
|
|
163
|
+
* the cell-scoped fact read) can't take the field and answer a narrowed
|
|
164
|
+
* token as anonymous in their handler (`get_public_account_id`), and the
|
|
165
|
+
* server-status route admits a narrowed token by design — and all are
|
|
166
|
+
* route specs too.
|
|
167
|
+
*
|
|
168
|
+
* Typed as a plain string here to keep `http/` from importing `auth/`; the
|
|
169
|
+
* resolver checks it at registration and throws on anything but a
|
|
170
|
+
* well-formed `surface:<name>`.
|
|
171
|
+
*/
|
|
172
|
+
required_scope?: string | undefined;
|
|
173
|
+
}
|
|
155
174
|
/**
|
|
156
175
|
* True iff the route is fully public — both account and actor axes
|
|
157
176
|
* are `'none'`. Public routes skip the dispatcher's authorization
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"auth_shape.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/auth_shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAA4B,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AASpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,WAAW,gNAAkE,CAAC;AAC3F,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,MAAM,GAAG,SAGtD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,wKAA2C,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAuDxD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,aAAa,CAAC;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC1C,gBAAgB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACpC;AAUD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,SAAS,KAAG,OACA,CAAC;AAElD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,KAAG,OAAgC,CAAC;AAE/E,wEAAwE;AACxE,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,KAAG,OAA+B,CAAC;AAE/E,8FAA8F;AAC9F,eAAO,MAAM,wBAAwB,GAAI,MAAM,SAAS,KAAG,OAC3B,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,SAAS,KAAG,OACQ,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,SAAS,KAAG,OACwB,CAAC;AAEvF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,4BAA4B,GAAI,MAAM,SAAS,EAAE,SAAS,MAAM,KAAG,IAM/E,CAAC;AAYF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,4BAA4B,GAAI,QAAQ,gBAAgB,KAAG,OAKvE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,sCAAsC,GAClD,MAAM,SAAS,EACf,OAAO,WAAW,EAClB,SAAS,MAAM,KACb,IAmBF,CAAC"}
|
package/dist/http/auth_shape.js
CHANGED
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
* invariant 2 (the `actor !== 'none' ⟺ input or query declares
|
|
29
29
|
* acting?: ActingActor` biconditional), which introspects the spec's
|
|
30
30
|
* input/query schemas, by `assert_route_auth_acting_biconditional`. Specs
|
|
31
|
-
* are plain objects that no registration path parses, so
|
|
32
|
-
*
|
|
31
|
+
* are plain objects that no registration path parses, so both checks live in
|
|
32
|
+
* code rather than on a schema.
|
|
33
33
|
*
|
|
34
34
|
* @module
|
|
35
35
|
*/
|
|
36
36
|
import { z } from 'zod';
|
|
37
|
-
import { is_schema, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
37
|
+
import { is_schema, one_of, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
38
38
|
import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
|
|
39
39
|
import { Uuid } from '../primitive_schemas.js';
|
|
40
40
|
import { ACTING_ACTOR_DESCRIPTION, ActingActor as ActingActorFuz } from '../primitive_schemas_fuz.js';
|
|
@@ -110,11 +110,10 @@ export const parse_acting = (value) => {
|
|
|
110
110
|
* credential; the authorization phase 4xx for `actor === 'required'`
|
|
111
111
|
* without an actor binding).
|
|
112
112
|
*/
|
|
113
|
-
export const AuthAxisState =
|
|
113
|
+
export const AuthAxisState = one_of(['none', 'optional', 'required']);
|
|
114
114
|
/**
|
|
115
115
|
* The cross-axis invariants 1, 3, and 4 an auth shape breaks, in that order —
|
|
116
|
-
* the
|
|
117
|
-
* `RouteAuth` schema's `.superRefine`.
|
|
116
|
+
* the implementation behind `assert_route_auth_invariants`.
|
|
118
117
|
*/
|
|
119
118
|
const route_auth_invariant_violations = (auth) => {
|
|
120
119
|
const violations = [];
|
|
@@ -149,83 +148,11 @@ const route_auth_invariant_violations = (auth) => {
|
|
|
149
148
|
}
|
|
150
149
|
return violations;
|
|
151
150
|
};
|
|
152
|
-
/**
|
|
153
|
-
* The canonical auth shape used by both `ActionSpec.auth` and
|
|
154
|
-
* `RouteSpec.auth`.
|
|
155
|
-
*
|
|
156
|
-
* Cross-axis registry invariants, checked at registration by
|
|
157
|
-
* `assert_route_auth_invariants` (and by this schema's `.superRefine`, the
|
|
158
|
-
* same check, when a caller parses an auth shape):
|
|
159
|
-
*
|
|
160
|
-
* 1. **Roles imply actor.** `roles?.length` ⟹ `actor === 'required'`.
|
|
161
|
-
* Role checks read the actor's role_grants, so a role-gated spec without
|
|
162
|
-
* a resolved actor would have nothing to check.
|
|
163
|
-
* 3. **No accountless actors yet.** `account === 'none' && actor !== 'none'`
|
|
164
|
-
* is invalid in v1. The credential resolver always binds account before
|
|
165
|
-
* actor today; agent-token / group-actor credentials will lift this.
|
|
166
|
-
* 4. **Unrestricted is leaf.** `account === 'none' && actor === 'none'`
|
|
167
|
-
* ⟹ no `roles`, no `credential_types` (nothing left to gate). The same
|
|
168
|
-
* rule covers `required_scope`, but enforcing it needs the capability
|
|
169
|
-
* vocabulary from `auth/`, so it lives with the other `required_scope`
|
|
170
|
-
* check in `fuz_auth_guard_resolver`.
|
|
171
|
-
*
|
|
172
|
-
* Invariant 2 — the `actor !== 'none' ⟺ input or query declares
|
|
173
|
-
* acting?: ActingActor` biconditional — needs introspection of the
|
|
174
|
-
* spec's input/query schemas, so it is checked at registration time,
|
|
175
|
-
* not on this schema. See `assert_route_auth_acting_biconditional`
|
|
176
|
-
* below.
|
|
177
|
-
*/
|
|
178
|
-
export const RouteAuth = z
|
|
179
|
-
.strictObject({
|
|
180
|
-
account: AuthAxisState,
|
|
181
|
-
actor: AuthAxisState,
|
|
182
|
-
roles: z.array(z.string()).readonly().optional(),
|
|
183
|
-
credential_types: z.array(z.string()).readonly().optional(),
|
|
184
|
-
/**
|
|
185
|
-
* The capability a **narrowed** api token's scope must admit to reach this
|
|
186
|
-
* route, in the `<section>:<id>` vocabulary a denial reports back as
|
|
187
|
-
* `required_scope`:
|
|
188
|
-
*
|
|
189
|
-
* - `surface:<name>` — a non-RPC surface, refused to every narrowed token
|
|
190
|
-
* whatever its method list says (token scoping's rule that a narrowed
|
|
191
|
-
* token is RPC-only). `surface:audit_stream`, `surface:fact_bare`,
|
|
192
|
-
* `surface:account_verify`, and `surface:app_surface` are the spine's
|
|
193
|
-
* route-spec ones; a consumer names its own without registering it.
|
|
194
|
-
*
|
|
195
|
-
* The `rpc:<method>` arm of that vocabulary is the dispatcher's per-method
|
|
196
|
-
* gate, which a route never reaches, so a route may not declare it.
|
|
197
|
-
*
|
|
198
|
-
* Declaring it makes the guard resolver mount the refusal ahead of the role
|
|
199
|
-
* gate, instead of the route hand-rolling the check in its handler (which
|
|
200
|
-
* the auth phase has already role-gated by then, so a narrowed token whose
|
|
201
|
-
* account lacks the role would be told about the role rather than about the
|
|
202
|
-
* scope).
|
|
203
|
-
*
|
|
204
|
-
* Opt-in rather than blanket: no narrowed token reaches login (which reads
|
|
205
|
-
* no credential) or logout and the password change (session-only), the
|
|
206
|
-
* RPC endpoint runs its own per-method check inside the dispatcher, the
|
|
207
|
-
* `reads_credential` routes that answer anonymous callers (account status,
|
|
208
|
-
* the cell-scoped fact read) can't take the field and answer a narrowed
|
|
209
|
-
* token as anonymous in their handler (`get_public_account_id`), and the
|
|
210
|
-
* server-status route admits a narrowed token by design — and all are
|
|
211
|
-
* route specs too.
|
|
212
|
-
*
|
|
213
|
-
* Typed as a plain string here to keep `http/` from importing `auth/`; the
|
|
214
|
-
* resolver checks it at registration and throws on anything but a
|
|
215
|
-
* well-formed `surface:<name>`.
|
|
216
|
-
*/
|
|
217
|
-
required_scope: z.string().optional()
|
|
218
|
-
})
|
|
219
|
-
.superRefine((value, ctx) => {
|
|
220
|
-
for (const { path, message } of route_auth_invariant_violations(value)) {
|
|
221
|
-
ctx.addIssue({ code: 'custom', message, path: [path] });
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
151
|
// --- Predicates over the flat-record shape ---
|
|
225
152
|
//
|
|
226
153
|
// Pure derived reads of `RouteAuth`. Live here so every consumer that
|
|
227
154
|
// branches on the shape (the dispatcher's authorization phase, route
|
|
228
|
-
// guards, `
|
|
155
|
+
// guards, `derive_route_errors`, `surface_query`, the surface explorer
|
|
229
156
|
// UI, and the testing harnesses) goes through one source of truth
|
|
230
157
|
// instead of inlining axis comparisons that drift over time.
|
|
231
158
|
/**
|
|
@@ -294,12 +221,12 @@ export const assert_route_auth_invariants = (auth, context) => {
|
|
|
294
221
|
// --- Registry-time invariant 2 enforcement ---
|
|
295
222
|
//
|
|
296
223
|
// The biconditional `auth.actor !== 'none' ⟺ input (or query, on REST
|
|
297
|
-
// GETs) declares acting?: ActingActor`.
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
224
|
+
// GETs) declares acting?: ActingActor`. Checked apart from the cross-axis
|
|
225
|
+
// invariants because it introspects the spec's input/query schemas for
|
|
226
|
+
// reference equality with the canonical `ActingActor` schema above.
|
|
227
|
+
// Enforced at registration time by every dispatcher loop
|
|
228
|
+
// (`apply_route_specs`, `compile_action_registry` for `create_rpc_endpoint`
|
|
229
|
+
// + `register_action_ws`).
|
|
303
230
|
/**
|
|
304
231
|
* Whether a schema declares the canonical `acting?: ActingActor` field.
|
|
305
232
|
* Reference-equality on the exported `ActingActor` schema of the input's
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
* @module
|
|
65
65
|
*/
|
|
66
66
|
import type { MiddlewareHandler } from 'hono';
|
|
67
|
+
import type { MiddlewareSpec } from './middleware_spec.js';
|
|
67
68
|
/**
|
|
68
69
|
* Create the body size limit middleware.
|
|
69
70
|
*
|
|
@@ -73,4 +74,15 @@ import type { MiddlewareHandler } from 'hono';
|
|
|
73
74
|
* compares false against every length and would admit any body
|
|
74
75
|
*/
|
|
75
76
|
export declare const create_body_limit_middleware: (max_size: number) => MiddlewareHandler;
|
|
77
|
+
/**
|
|
78
|
+
* Create the body size limit as a middleware spec — `body_limit_middleware_shape`
|
|
79
|
+
* at `'*'` with its handler — which `create_app_server` mounts ahead of the
|
|
80
|
+
* other middleware, so every route's error map carries the limit's `413` and
|
|
81
|
+
* `400`.
|
|
82
|
+
*
|
|
83
|
+
* @param max_size - the largest accepted body, in bytes; a safe integer, `0` or more
|
|
84
|
+
* @returns the spec, its handler `create_body_limit_middleware(max_size)`
|
|
85
|
+
* @throws Error when `max_size` is not a safe integer `0` or more
|
|
86
|
+
*/
|
|
87
|
+
export declare const create_body_limit_middleware_spec: (max_size: number) => MiddlewareSpec;
|
|
76
88
|
//# sourceMappingURL=body_limit.d.ts.map
|