@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.
Files changed (199) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/action_event_data.d.ts +1 -1
  3. package/dist/actions/action_rpc.d.ts.map +1 -1
  4. package/dist/actions/action_rpc.js +4 -0
  5. package/dist/actions/action_spec.d.ts +3 -3
  6. package/dist/actions/action_spec.d.ts.map +1 -1
  7. package/dist/auth/CLAUDE.md +1 -1
  8. package/dist/auth/account_route_schema.d.ts +3 -27
  9. package/dist/auth/account_route_schema.d.ts.map +1 -1
  10. package/dist/auth/account_route_schema.js +6 -20
  11. package/dist/auth/admin_action_specs.d.ts +56 -56
  12. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  13. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  14. package/dist/auth/audit_log_route_schema.js +4 -5
  15. package/dist/auth/audit_log_schema.d.ts +18 -18
  16. package/dist/auth/bootstrap_route_schema.d.ts +1 -30
  17. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  18. package/dist/auth/bootstrap_route_schema.js +3 -8
  19. package/dist/auth/daemon_token.d.ts +4 -4
  20. package/dist/auth/daemon_token.d.ts.map +1 -1
  21. package/dist/auth/daemon_token.js +3 -3
  22. package/dist/auth/daemon_token_middleware.d.ts +1 -1
  23. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  24. package/dist/auth/daemon_token_middleware.js +5 -5
  25. package/dist/auth/middleware.js +4 -4
  26. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  27. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  28. package/dist/auth/signup_route_schema.js +3 -7
  29. package/dist/db/CLAUDE.md +2 -1
  30. package/dist/db/file_fact_url.d.ts +11 -6
  31. package/dist/db/file_fact_url.d.ts.map +1 -1
  32. package/dist/db/file_fact_url.js +5 -5
  33. package/dist/db/schema_ready.d.ts +0 -5
  34. package/dist/db/schema_ready.d.ts.map +1 -1
  35. package/dist/db/schema_ready.js +0 -5
  36. package/dist/http/CLAUDE.md +105 -71
  37. package/dist/http/auth_shape.d.ts +48 -29
  38. package/dist/http/auth_shape.d.ts.map +1 -1
  39. package/dist/http/auth_shape.js +12 -85
  40. package/dist/http/body_limit.d.ts +12 -0
  41. package/dist/http/body_limit.d.ts.map +1 -1
  42. package/dist/http/body_limit.js +15 -0
  43. package/dist/http/body_limit_schema.d.ts +20 -0
  44. package/dist/http/body_limit_schema.d.ts.map +1 -0
  45. package/dist/http/body_limit_schema.js +20 -0
  46. package/dist/http/common_routes.d.ts +1 -1
  47. package/dist/http/common_routes.d.ts.map +1 -1
  48. package/dist/http/common_routes.js +11 -14
  49. package/dist/http/db_routes.d.ts.map +1 -1
  50. package/dist/http/db_routes.js +59 -69
  51. package/dist/http/dev_route_error_check.d.ts +70 -0
  52. package/dist/http/dev_route_error_check.d.ts.map +1 -0
  53. package/dist/http/dev_route_error_check.js +119 -0
  54. package/dist/http/error_schemas.d.ts +365 -189
  55. package/dist/http/error_schemas.d.ts.map +1 -1
  56. package/dist/http/error_schemas.js +256 -149
  57. package/dist/http/health_schema.d.ts +10 -6
  58. package/dist/http/health_schema.d.ts.map +1 -1
  59. package/dist/http/health_schema.js +3 -3
  60. package/dist/http/middleware_spec.d.ts +8 -3
  61. package/dist/http/middleware_spec.d.ts.map +1 -1
  62. package/dist/http/origin.d.ts +12 -43
  63. package/dist/http/origin.d.ts.map +1 -1
  64. package/dist/http/origin.js +10 -6
  65. package/dist/http/route_error_check.d.ts +179 -0
  66. package/dist/http/route_error_check.d.ts.map +1 -0
  67. package/dist/http/route_error_check.js +283 -0
  68. package/dist/http/route_errors.d.ts +80 -0
  69. package/dist/http/route_errors.d.ts.map +1 -0
  70. package/dist/http/route_errors.js +83 -0
  71. package/dist/http/route_spec.d.ts +33 -17
  72. package/dist/http/route_spec.d.ts.map +1 -1
  73. package/dist/http/route_spec.js +48 -62
  74. package/dist/http/schema_helpers.d.ts +15 -34
  75. package/dist/http/schema_helpers.d.ts.map +1 -1
  76. package/dist/http/schema_helpers.js +11 -47
  77. package/dist/http/surface.d.ts +19 -12
  78. package/dist/http/surface.d.ts.map +1 -1
  79. package/dist/http/surface.js +25 -38
  80. package/dist/http/surface_query.d.ts +11 -2
  81. package/dist/http/surface_query.d.ts.map +1 -1
  82. package/dist/http/surface_query.js +7 -1
  83. package/dist/primitive_schemas_fuz.d.ts +17 -3
  84. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  85. package/dist/primitive_schemas_fuz.js +13 -3
  86. package/dist/rate_limiter.d.ts +13 -0
  87. package/dist/rate_limiter.d.ts.map +1 -1
  88. package/dist/rate_limiter.js +20 -2
  89. package/dist/schema_issues.d.ts +29 -11
  90. package/dist/schema_issues.d.ts.map +1 -1
  91. package/dist/schema_issues.js +11 -10
  92. package/dist/schema_meta.d.ts +8 -1
  93. package/dist/schema_meta.d.ts.map +1 -1
  94. package/dist/schema_meta.js +2 -1
  95. package/dist/server/app_server.d.ts +3 -1
  96. package/dist/server/app_server.d.ts.map +1 -1
  97. package/dist/server/app_server.js +24 -10
  98. package/dist/server/serve_fact_route.d.ts.map +1 -1
  99. package/dist/server/serve_fact_route.js +8 -31
  100. package/dist/server/surface_route.d.ts.map +1 -1
  101. package/dist/server/surface_route.js +5 -6
  102. package/dist/server/x_accel.d.ts +12 -7
  103. package/dist/server/x_accel.d.ts.map +1 -1
  104. package/dist/server/x_accel.js +7 -9
  105. package/dist/testing/CLAUDE.md +105 -61
  106. package/dist/testing/admin_integration.js +2 -2
  107. package/dist/testing/adversarial_404.d.ts +4 -18
  108. package/dist/testing/adversarial_404.d.ts.map +1 -1
  109. package/dist/testing/adversarial_404.js +20 -52
  110. package/dist/testing/adversarial_headers.d.ts +3 -4
  111. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  112. package/dist/testing/adversarial_headers.js +8 -6
  113. package/dist/testing/adversarial_input.d.ts.map +1 -1
  114. package/dist/testing/adversarial_input.js +20 -19
  115. package/dist/testing/assertions.d.ts +46 -14
  116. package/dist/testing/assertions.d.ts.map +1 -1
  117. package/dist/testing/assertions.js +73 -16
  118. package/dist/testing/attack_surface.d.ts +17 -35
  119. package/dist/testing/attack_surface.d.ts.map +1 -1
  120. package/dist/testing/attack_surface.js +36 -95
  121. package/dist/testing/auth_apps.d.ts.map +1 -1
  122. package/dist/testing/auth_apps.js +2 -1
  123. package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
  124. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  125. package/dist/testing/cross_backend/action_manifest.js +11 -11
  126. package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
  127. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  128. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  129. package/dist/testing/cross_backend/cell_crud.js +2 -1
  130. package/dist/testing/cross_backend/conformance_table.js +1 -1
  131. package/dist/testing/cross_backend/fact_serving.js +3 -3
  132. package/dist/testing/cross_backend/in_process_setup.d.ts +7 -3
  133. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  134. package/dist/testing/cross_backend/in_process_setup.js +11 -4
  135. package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
  136. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  137. package/dist/testing/cross_backend/origin_conformance.js +21 -21
  138. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  139. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
  140. package/dist/testing/cross_backend/setup.d.ts +13 -0
  141. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/setup.js +24 -7
  143. package/dist/testing/cross_backend/spine_suites.d.ts +3 -2
  144. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  145. package/dist/testing/cross_backend/spine_suites.js +5 -2
  146. package/dist/testing/cross_backend/standard.d.ts +31 -0
  147. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  148. package/dist/testing/cross_backend/standard.js +9 -3
  149. package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
  150. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  151. package/dist/testing/cross_backend/testing_origin_check.js +16 -13
  152. package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
  153. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  154. package/dist/testing/data_exposure.d.ts +7 -0
  155. package/dist/testing/data_exposure.d.ts.map +1 -1
  156. package/dist/testing/data_exposure.js +8 -7
  157. package/dist/testing/error_coverage.d.ts +53 -61
  158. package/dist/testing/error_coverage.d.ts.map +1 -1
  159. package/dist/testing/error_coverage.js +86 -119
  160. package/dist/testing/integration.d.ts +28 -1
  161. package/dist/testing/integration.d.ts.map +1 -1
  162. package/dist/testing/integration.js +54 -29
  163. package/dist/testing/integration_helpers.d.ts +37 -9
  164. package/dist/testing/integration_helpers.d.ts.map +1 -1
  165. package/dist/testing/integration_helpers.js +75 -40
  166. package/dist/testing/middleware.d.ts +3 -5
  167. package/dist/testing/middleware.d.ts.map +1 -1
  168. package/dist/testing/middleware.js +5 -4
  169. package/dist/testing/middleware_gate_probes.d.ts +90 -0
  170. package/dist/testing/middleware_gate_probes.d.ts.map +1 -0
  171. package/dist/testing/middleware_gate_probes.js +179 -0
  172. package/dist/testing/rate_limiting.d.ts +1 -1
  173. package/dist/testing/rate_limiting.d.ts.map +1 -1
  174. package/dist/testing/rate_limiting.js +5 -4
  175. package/dist/testing/round_trip.d.ts +7 -0
  176. package/dist/testing/round_trip.d.ts.map +1 -1
  177. package/dist/testing/round_trip.js +8 -5
  178. package/dist/testing/schema_generators.d.ts +40 -11
  179. package/dist/testing/schema_generators.d.ts.map +1 -1
  180. package/dist/testing/schema_generators.js +71 -17
  181. package/dist/testing/stubs.d.ts +10 -1
  182. package/dist/testing/stubs.d.ts.map +1 -1
  183. package/dist/testing/stubs.js +15 -5
  184. package/dist/testing/surface_invariants.d.ts +36 -115
  185. package/dist/testing/surface_invariants.d.ts.map +1 -1
  186. package/dist/testing/surface_invariants.js +106 -269
  187. package/dist/testing/transports/raw_http.d.ts +10 -2
  188. package/dist/testing/transports/raw_http.d.ts.map +1 -1
  189. package/dist/testing/transports/raw_http.js +10 -4
  190. package/dist/ui/CLAUDE.md +4 -2
  191. package/dist/ui/auth_state.svelte.d.ts.map +1 -1
  192. package/dist/ui/auth_state.svelte.js +2 -8
  193. package/dist/ui/backend_probe.svelte.js +3 -3
  194. package/dist/ui/table_state.svelte.d.ts.map +1 -1
  195. package/dist/ui/table_state.svelte.js +1 -8
  196. package/dist/ui/ui_fetch.d.ts +12 -2
  197. package/dist/ui/ui_fetch.d.ts.map +1 -1
  198. package/dist/ui/ui_fetch.js +22 -4
  199. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ /**
2
+ * A route's error map: every error definition it can answer with — derived
3
+ * from its slots (`derive_route_errors`), declared by each middleware layer
4
+ * that runs on it, and its own `errors` — and the status map they group into.
5
+ *
6
+ * Built once per app (`resolve_app_route_error_maps`, carried as
7
+ * `AppSurfaceSpec.route_error_maps`) and read by every reader of a route's
8
+ * declared errors: the surface, the DEV error check, the test helpers, error
9
+ * coverage, and the attack-surface suite. The maps are keyed `METHOD path`
10
+ * (`format_route_key`).
11
+ *
12
+ * @module
13
+ */
14
+ import type { RouteAuth } from './auth_shape.js';
15
+ import type { RouteMethod } from './route_spec.js';
16
+ import { type ErrorSchemas, type RestErrorDef } from './error_schemas.js';
17
+ import type { MiddlewareSpec } from './middleware_spec.js';
18
+ import type { RateLimitKey } from '../rate_limiter.js';
19
+ import type { ValidationSchema } from '../schema_issues.js';
20
+ /**
21
+ * A route's error map: every error definition the route can answer with, and
22
+ * the status map they group into. Built by `resolve_route_error_map`, and read by
23
+ * every reader of a route's declared errors — the surface, the DEV error
24
+ * check, the test helpers, error coverage, and the attack-surface suite.
25
+ */
26
+ export interface RouteErrorMap {
27
+ /**
28
+ * The definitions, in order — derived, then each applying middleware's, then
29
+ * the route's own — with each repeat left out (`dedupe_rest_errors`). Two
30
+ * shapes of one code at one status are both kept.
31
+ */
32
+ readonly defs: ReadonlyArray<RestErrorDef>;
33
+ /** The definitions grouped by status (`to_error_schemas`): one schema, or a `union` of them. */
34
+ readonly schemas: ErrorSchemas;
35
+ }
36
+ /** What `resolve_route_error_map` reads of a route spec. */
37
+ export interface RouteErrorMapSpec {
38
+ readonly method: RouteMethod;
39
+ readonly path: string;
40
+ readonly auth: RouteAuth;
41
+ readonly input: ValidationSchema;
42
+ readonly params?: ValidationSchema;
43
+ readonly query?: ValidationSchema;
44
+ readonly rate_limit?: RateLimitKey;
45
+ readonly errors?: ReadonlyArray<RestErrorDef>;
46
+ }
47
+ /**
48
+ * Resolve a route's error map: the union of the definitions derived from it
49
+ * (`derive_route_errors`, narrowed to the slots it has), those of each
50
+ * middleware layer that runs on it (`middleware_spec_applies`), in list order,
51
+ * and its own `errors`. Nothing replaces anything: a definition at a status
52
+ * another layer declares is one more branch there, and a repeat counts once.
53
+ *
54
+ * @param spec - the route spec
55
+ * @param middleware_specs - the app's middleware layers, of which those that apply to the route contribute
56
+ * @returns the route's error map
57
+ */
58
+ export declare const resolve_route_error_map: (spec: RouteErrorMapSpec, middleware_specs?: ReadonlyArray<Pick<MiddlewareSpec, "path" | "carve_outs" | "errors">> | null) => RouteErrorMap;
59
+ /**
60
+ * Resolve every route's error map (`resolve_route_error_map`) against one
61
+ * middleware list, keyed by `format_route_key` (`METHOD path`).
62
+ *
63
+ * @param route_specs - the app's routes
64
+ * @param middleware_specs - the app's middleware layers
65
+ * @returns each route's error map
66
+ */
67
+ export declare const resolve_app_route_error_maps: (route_specs: ReadonlyArray<RouteErrorMapSpec>, middleware_specs?: ReadonlyArray<Pick<MiddlewareSpec, "path" | "carve_outs" | "errors">> | null) => Map<string, RouteErrorMap>;
68
+ /**
69
+ * A route's error map from a map built by `resolve_app_route_error_maps`, or,
70
+ * with no map, resolved from the route alone — without middleware.
71
+ *
72
+ * @param route_error_maps - the app's route error maps, if the caller has them
73
+ * @param spec - the route spec
74
+ * @returns the route's error map
75
+ * @throws Error naming the route's key when a map is given with no entry for
76
+ * the route — a map built over other routes, which would silently drop the
77
+ * middleware's definitions
78
+ */
79
+ export declare const get_route_error_map: (route_error_maps: ReadonlyMap<string, RouteErrorMap> | null | undefined, spec: RouteErrorMapSpec) => RouteErrorMap;
80
+ //# sourceMappingURL=route_errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAIN,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IAC3C,gGAAgG;IAChG,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;CAC/B;AAED,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,GACnC,MAAM,iBAAiB,EACvB,mBAAmB,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,KAC7F,aAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GACxC,aAAa,aAAa,CAAC,iBAAiB,CAAC,EAC7C,mBAAmB,aAAa,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,KAC7F,GAAG,CAAC,MAAM,EAAE,aAAa,CAM3B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC/B,kBAAkB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,GAAG,SAAS,EACvE,MAAM,iBAAiB,KACrB,aAQF,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * A route's error map: every error definition it can answer with — derived
3
+ * from its slots (`derive_route_errors`), declared by each middleware layer
4
+ * that runs on it, and its own `errors` — and the status map they group into.
5
+ *
6
+ * Built once per app (`resolve_app_route_error_maps`, carried as
7
+ * `AppSurfaceSpec.route_error_maps`) and read by every reader of a route's
8
+ * declared errors: the surface, the DEV error check, the test helpers, error
9
+ * coverage, and the attack-surface suite. The maps are keyed `METHOD path`
10
+ * (`format_route_key`).
11
+ *
12
+ * @module
13
+ */
14
+ import { dedupe_rest_errors, derive_route_errors, to_error_schemas } from './error_schemas.js';
15
+ import { is_null_schema, middleware_spec_applies } from './schema_helpers.js';
16
+ import { format_route_key } from './surface_query.js';
17
+ /**
18
+ * Resolve a route's error map: the union of the definitions derived from it
19
+ * (`derive_route_errors`, narrowed to the slots it has), those of each
20
+ * middleware layer that runs on it (`middleware_spec_applies`), in list order,
21
+ * and its own `errors`. Nothing replaces anything: a definition at a status
22
+ * another layer declares is one more branch there, and a repeat counts once.
23
+ *
24
+ * @param spec - the route spec
25
+ * @param middleware_specs - the app's middleware layers, of which those that apply to the route contribute
26
+ * @returns the route's error map
27
+ */
28
+ export const resolve_route_error_map = (spec, middleware_specs) => {
29
+ const all = derive_route_errors({
30
+ method: spec.method,
31
+ auth: spec.auth,
32
+ has_input: !is_null_schema(spec.input),
33
+ has_params: spec.params !== undefined,
34
+ has_query: spec.query !== undefined,
35
+ rate_limit: spec.rate_limit
36
+ });
37
+ if (middleware_specs) {
38
+ for (const mw of middleware_specs) {
39
+ if (mw.errors && middleware_spec_applies(mw, spec.path))
40
+ all.push(...mw.errors);
41
+ }
42
+ }
43
+ if (spec.errors)
44
+ all.push(...spec.errors);
45
+ const defs = dedupe_rest_errors(all);
46
+ return { defs, schemas: to_error_schemas(defs) };
47
+ };
48
+ /**
49
+ * Resolve every route's error map (`resolve_route_error_map`) against one
50
+ * middleware list, keyed by `format_route_key` (`METHOD path`).
51
+ *
52
+ * @param route_specs - the app's routes
53
+ * @param middleware_specs - the app's middleware layers
54
+ * @returns each route's error map
55
+ */
56
+ export const resolve_app_route_error_maps = (route_specs, middleware_specs) => {
57
+ const route_error_maps = new Map();
58
+ for (const spec of route_specs) {
59
+ route_error_maps.set(format_route_key(spec), resolve_route_error_map(spec, middleware_specs));
60
+ }
61
+ return route_error_maps;
62
+ };
63
+ /**
64
+ * A route's error map from a map built by `resolve_app_route_error_maps`, or,
65
+ * with no map, resolved from the route alone — without middleware.
66
+ *
67
+ * @param route_error_maps - the app's route error maps, if the caller has them
68
+ * @param spec - the route spec
69
+ * @returns the route's error map
70
+ * @throws Error naming the route's key when a map is given with no entry for
71
+ * the route — a map built over other routes, which would silently drop the
72
+ * middleware's definitions
73
+ */
74
+ export const get_route_error_map = (route_error_maps, spec) => {
75
+ if (route_error_maps == null)
76
+ return resolve_route_error_map(spec);
77
+ const key = format_route_key(spec);
78
+ const route_error_map = route_error_maps.get(key);
79
+ if (!route_error_map) {
80
+ throw new Error(`get_route_error_map: the route error maps have no entry for '${key}'`);
81
+ }
82
+ return route_error_map;
83
+ };
@@ -18,7 +18,8 @@ import type { z } from 'zod';
18
18
  import { type AnySchema } from '@fuzdev/fuz_schema/schema.ts';
19
19
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
20
20
  import type { Db } from '../db/db.js';
21
- import { type RouteErrorSchemas, type RateLimitKey } from './error_schemas.js';
21
+ import { type RestErrorDef } from './error_schemas.js';
22
+ import type { RateLimitKey } from '../rate_limiter.js';
22
23
  import type { MiddlewareSpec } from './middleware_spec.js';
23
24
  import { type RouteAuth } from './auth_shape.js';
24
25
  import { type ValidationOutput, type ValidationSchema } from '../schema_issues.js';
@@ -162,6 +163,15 @@ export interface RouteSpec {
162
163
  * misleading `null` body.
163
164
  */
164
165
  raw_body?: boolean;
166
+ /**
167
+ * The route answers JSON-RPC 2.0 envelopes, its refusals included, not REST
168
+ * bodies — the pair `create_rpc_endpoint` builds. A JSON-RPC error envelope
169
+ * it answers is left out of the DEV error check and
170
+ * `assert_response_matches_spec`: no REST error definition describes one,
171
+ * and the dispatch core checks its own outputs. On any other route an
172
+ * envelope-shaped body is checked like any error body.
173
+ */
174
+ jsonrpc?: boolean;
165
175
  /**
166
176
  * Marks a route that issues a credential — a session cookie — while
167
177
  * declaring no auth itself: login, signup, bootstrap. A forged cross-site
@@ -194,21 +204,23 @@ export interface RouteSpec {
194
204
  /**
195
205
  * Rate limit key type — declares what this route's rate limiter is keyed on.
196
206
  *
197
- * When set, 429 (`RateLimitError`) is auto-derived in `derive_error_schemas`.
207
+ * When set, 429 `rate_limit_exceeded` is derived (`derive_route_errors`).
198
208
  * The actual `RateLimiter` instance is still wired imperatively in the handler —
199
209
  * this field is metadata for surface introspection and policy invariants.
200
210
  */
201
211
  rate_limit?: RateLimitKey;
202
212
  /**
203
- * Handler-specific error response schemas keyed by HTTP status code.
213
+ * The handler's error definitions (`rest_error`), one per code it answers
214
+ * with (a 404 for not-found, a 409 for a conflict).
204
215
  *
205
- * Middleware errors (auth 401/403, validation 400, rate limit 429) are
206
- * auto-derived from `auth`, `input`, and `rate_limit`. Declare handler-specific
207
- * errors here (e.g., 404 for not-found, 409 for conflicts).
208
- *
209
- * Explicit entries override auto-derived ones for the same status code.
216
+ * What the framework's own middleware answers (the input 400s, auth
217
+ * 401/403, rate limit 429) is derived from `method`, `auth`, the input
218
+ * slots, and `rate_limit` (`derive_route_errors`), and the middleware
219
+ * layers declare their own. The route's error map
220
+ * (`resolve_route_error_map`) is the union of all three: a definition here at
221
+ * a status another layer declares adds a branch there and replaces nothing.
210
222
  */
211
- errors?: RouteErrorSchemas;
223
+ errors?: ReadonlyArray<RestErrorDef>;
212
224
  /**
213
225
  * Whether to wrap the handler in a database transaction.
214
226
  *
@@ -270,7 +282,7 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
270
282
  * For each spec: resolves auth to guards via the provided resolver,
271
283
  * adds input validation middleware (for routes with non-null input schemas),
272
284
  * runs the optional authorization phase to resolve the acting actor + build
273
- * the request context, wraps handler with DEV-only output and error
285
+ * the request context, wraps handler with DEV-only output
274
286
  * validation, wraps with error catch layer (a thrown JSON-RPC error,
275
287
  * recognized via `to_thrown_jsonrpc_error`, maps to its status; any other
276
288
  * throw to a 500), and registers the route.
@@ -301,18 +313,22 @@ export declare const apply_middleware_specs: (app: Hono, specs: Array<Middleware
301
313
  * registries (`compile_action_registry`) share the same helper with
302
314
  * `input` only — `ActionSpec` has no `query` shape.
303
315
  *
304
- * Every schema slot (`params`, `query`, `input`, `output`, each `errors`
305
- * entry) must hold a Zod or a `@fuzdev/fuz_schema` schema
306
- * (`assert_validation_schema`): a value of neither library throws naming the
307
- * route and the slot. A `@fuzdev/fuz_schema` `params` or `query` must be an
308
- * object schema (`get_schema_entries`), as the path params and query string
309
- * are an object: one that isn't throws naming the route.
316
+ * Every schema slot (`params`, `query`, `input`, `output`) must hold a Zod
317
+ * or a `@fuzdev/fuz_schema` schema (`assert_validation_schema`), and every
318
+ * `errors` entry an error definition (`rest_error`): anything else throws
319
+ * naming the route and the slot. A `@fuzdev/fuz_schema` `params` or `query`
320
+ * must be an object schema (`get_schema_entries`), as the path params and
321
+ * query string are an object: one that isn't throws naming the route.
322
+ *
323
+ * In DEV each handler's 2xx JSON responses are checked against its `output`.
324
+ * Error responses are checked by the DEV error check
325
+ * (`create_dev_route_error_check`), which `create_app_server` mounts outermost.
310
326
  *
311
327
  * @param resolve_auth_guards - maps `RouteAuth` to middleware — use `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`
312
328
  * @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
313
329
  * @param db - used for transaction wrapping and `RouteContext`
314
330
  * @mutates `app`
315
- * @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value of neither library, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a fuz_schema `params` or `query` is not an object schema
331
+ * @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value of neither library or an `errors` entry is not a definition, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a fuz_schema `params` or `query` is not an object schema
316
332
  */
317
333
  export declare const apply_route_specs: (app: Hono, specs: Array<RouteSpec>, resolve_auth_guards: AuthGuardResolver, log: Logger, db: Db, authorize?: AuthorizationHandler) => void;
318
334
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"route_spec.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,KAAK,E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,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACvB,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAK5D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EAC1D,CAAC,EAAE,OAAO,EACV,MAAM,EAAE,CAAC,GACP,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACvB,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAK7D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,gBAAgB,EACzD,CAAC,EAAE,OAAO,EACV,MAAM,EAAE,CAAC,GACP,gBAAgB,CAAC,CAAC,CAAC,CAAC;AACvB,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;AAkL5D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,IAAI,EAAE,OAAO,KAAK,CAAC,cAAc,CAAC,KAAG,IAIhF,CAAC;AAsGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,eAAO,MAAM,iBAAiB,GAC7B,KAAK,IAAI,EACT,OAAO,KAAK,CAAC,SAAS,CAAC,EACvB,qBAAqB,iBAAiB,EACtC,KAAK,MAAM,EACX,IAAI,EAAE,EACN,YAAY,oBAAoB,KAC9B,IAyEF,CAAC;AAmCF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,EAAE,OAAO,KAAK,CAAC,SAAS,CAAC,KAAG,KAAK,CAAC,SAAS,CAK3F,CAAC"}
@@ -16,11 +16,13 @@
16
16
  import { DEV } from 'esm-env';
17
17
  import { is_schema } from '@fuzdev/fuz_schema/schema.ts';
18
18
  import { get_schema_entries } from '@fuzdev/fuz_schema/introspect.ts';
19
+ import { format_route_key } from './surface_query.js';
19
20
  import { is_db_checkout_error } from '../db/db_checkout_error.js';
20
- import { ERROR_INVALID_JSON_BODY, ERROR_INVALID_REQUEST_BODY, ERROR_INVALID_ROUTE_PARAMS, ERROR_INVALID_QUERY_PARAMS, ERROR_SERVICE_UNAVAILABLE, ERROR_UNSUPPORTED_CONTENT_TYPE } from './error_schemas.js';
21
+ 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';
21
22
  import { is_post_content_type_refused } from './simple_request.js';
22
23
  import { jsonrpc_error_code_to_http_status, jsonrpc_error_code_to_name, dev_only, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
23
- import { is_null_schema, merge_error_schemas } from './schema_helpers.js';
24
+ import { is_null_schema } from './schema_helpers.js';
25
+ import { is_json_response } from './route_error_check.js';
24
26
  import { dispatch_with_post_commit_rollback } from './pending_effects.js';
25
27
  import { assert_route_auth_acting_biconditional, assert_route_auth_invariants } from './auth_shape.js';
26
28
  import { assert_validation_schema, parse_any, to_wire_issues } from '../schema_issues.js';
@@ -150,41 +152,29 @@ const create_query_validation = (query_schema) => {
150
152
  };
151
153
  return [validate];
152
154
  };
153
- /** Whether a JSON body is the catch layer's `{error: 'internal_error'}` shape. */
154
- const is_internal_error_body = (body) => body !== null &&
155
- typeof body === 'object' &&
156
- body.error === 'internal_error';
157
- /** Whether a JSON body is the catch layer's failed-checkout `{error: 'service_unavailable'}`. */
158
- const is_service_unavailable_body = (body) => body !== null &&
159
- typeof body === 'object' &&
160
- body.error === ERROR_SERVICE_UNAVAILABLE;
161
155
  /**
162
- * Wrap a handler with DEV-only output and error validation.
156
+ * Wrap a handler with DEV-only output validation.
163
157
  *
164
- * In development, validates 2xx JSON responses against the output schema
165
- * and non-2xx responses against declared error schemas. Wraps the error
166
- * catch layer, so the body built from a thrown error is validated too — except
167
- * a 500 `internal_error` and a failed checkout's 503 `service_unavailable`,
168
- * which the catch layer can answer on any route and so are always accepted.
169
- * Each schema is Zod or `@fuzdev/fuz_schema`, parsed with `parse_any`; the
170
- * log carries the library's own issues.
171
- * Logs an error for mismatches and returns the response unchanged —
172
- * does not throw. Non-JSON responses (SSE, binary) are skipped. In
173
- * production, returns the handler unchanged.
158
+ * In development, validates 2xx JSON responses against the output schema,
159
+ * logging an error on a mismatch and returning the response unchanged — it
160
+ * never throws. Non-2xx responses are the DEV error check's
161
+ * (`create_dev_route_error_check`), which `create_app_server` mounts
162
+ * outermost so it sees what every layer answers. Non-JSON responses (SSE,
163
+ * binary) are skipped. The schema is Zod or `@fuzdev/fuz_schema`, parsed
164
+ * with `parse_any`; the log carries the library's own issues. In production,
165
+ * returns the handler unchanged.
174
166
  */
175
- const wrap_output_validation = (handler, output_schema, error_schemas, log) => {
167
+ const wrap_output_validation = (handler, output_schema, log) => {
176
168
  if (!DEV)
177
169
  return handler;
178
- if (is_null_schema(output_schema) && !error_schemas)
170
+ if (is_null_schema(output_schema))
179
171
  return handler;
180
172
  return async (c, next) => {
181
173
  const response = await handler(c, next);
182
- // Only validate JSON responses — streaming responses (SSE) would hang on .json().
183
- const content_type = response.headers.get('Content-Type');
184
- if (!content_type?.includes('application/json'))
174
+ if (!response.ok)
185
175
  return response;
186
- const schema = response.ok ? output_schema : error_schemas?.[response.status];
187
- if (!schema)
176
+ // Only validate JSON responses — streaming responses (SSE) would hang on .json().
177
+ if (!is_json_response(response))
188
178
  return response;
189
179
  let body;
190
180
  try {
@@ -194,20 +184,9 @@ const wrap_output_validation = (handler, output_schema, error_schemas, log) => {
194
184
  // clone() or json() failed on a response claiming application/json
195
185
  return response;
196
186
  }
197
- // the catch layer can answer `internal_error` on any route, so no route
198
- // declares it — checking it against a route's 500 schema would only
199
- // misreport a schema problem the route can't fix
200
- if (response.status === 500 && is_internal_error_body(body))
201
- return response;
202
- // the same for a failed pool checkout's 503, which any route can answer
203
- if (response.status === 503 && is_service_unavailable_body(body))
204
- return response;
205
- const result = parse_any(schema, body);
187
+ const result = parse_any(output_schema, body);
206
188
  if (!result.ok) {
207
- const label = response.ok
208
- ? 'Output schema mismatch'
209
- : `Error schema mismatch (${response.status})`;
210
- log.error(`${label}: ${c.req.method} ${c.req.path}`, result.issues);
189
+ log.error(`Output schema mismatch: ${c.req.method} ${c.req.path}`, result.issues);
211
190
  }
212
191
  return response;
213
192
  };
@@ -227,7 +206,7 @@ export const apply_middleware_specs = (app, specs) => {
227
206
  *
228
207
  * Catches a thrown JSON-RPC error — a `ThrownJsonrpcError` from any copy of
229
208
  * fuz_app, recognized by its brand (`to_thrown_jsonrpc_error`) — and maps it
230
- * to a flat REST `ApiError` body (`{error: <reason>, message?, ...rest_data}`)
209
+ * to a flat REST error body (`{error: <reason>, message?, ...rest_data}`)
231
210
  * at the matching HTTP status.
232
211
  * A failed pool checkout (`DbCheckoutError`) answers the flat 503
233
212
  * `{error: 'service_unavailable'}` with no `message`, byte for byte the Rust
@@ -252,7 +231,7 @@ export const apply_middleware_specs = (app, specs) => {
252
231
  * REST callers key on HTTP status + `error` reason, and the JSON-RPC code
253
232
  * is recoverable via `http_status_to_jsonrpc_error_code(status)` on the
254
233
  * rare consumer that wants it. Keeping the shape transport-shaped (REST
255
- * emits ApiError; JSON-RPC dispatcher emits the JSON-RPC envelope) avoids
234
+ * emits the flat body; JSON-RPC dispatcher emits the JSON-RPC envelope) avoids
256
235
  * a hybrid envelope that has to be normalized on the way out.
257
236
  */
258
237
  const wrap_error_catch = (handler, log) => {
@@ -278,7 +257,7 @@ const wrap_error_catch = (handler, log) => {
278
257
  // validation-issue redaction), production gets the bare error code.
279
258
  log.error('Unhandled handler error', err);
280
259
  const body = {
281
- error: 'internal_error',
260
+ error: ERROR_INTERNAL_ERROR,
282
261
  message: dev_only(() => (err instanceof Error ? err.message : undefined))
283
262
  };
284
263
  return c.json(body, 500);
@@ -325,7 +304,7 @@ const build_rest_error_body = (err) => {
325
304
  * For each spec: resolves auth to guards via the provided resolver,
326
305
  * adds input validation middleware (for routes with non-null input schemas),
327
306
  * runs the optional authorization phase to resolve the acting actor + build
328
- * the request context, wraps handler with DEV-only output and error
307
+ * the request context, wraps handler with DEV-only output
329
308
  * validation, wraps with error catch layer (a thrown JSON-RPC error,
330
309
  * recognized via `to_thrown_jsonrpc_error`, maps to its status; any other
331
310
  * throw to a 500), and registers the route.
@@ -356,23 +335,27 @@ const build_rest_error_body = (err) => {
356
335
  * registries (`compile_action_registry`) share the same helper with
357
336
  * `input` only — `ActionSpec` has no `query` shape.
358
337
  *
359
- * Every schema slot (`params`, `query`, `input`, `output`, each `errors`
360
- * entry) must hold a Zod or a `@fuzdev/fuz_schema` schema
361
- * (`assert_validation_schema`): a value of neither library throws naming the
362
- * route and the slot. A `@fuzdev/fuz_schema` `params` or `query` must be an
363
- * object schema (`get_schema_entries`), as the path params and query string
364
- * are an object: one that isn't throws naming the route.
338
+ * Every schema slot (`params`, `query`, `input`, `output`) must hold a Zod
339
+ * or a `@fuzdev/fuz_schema` schema (`assert_validation_schema`), and every
340
+ * `errors` entry an error definition (`rest_error`): anything else throws
341
+ * naming the route and the slot. A `@fuzdev/fuz_schema` `params` or `query`
342
+ * must be an object schema (`get_schema_entries`), as the path params and
343
+ * query string are an object: one that isn't throws naming the route.
344
+ *
345
+ * In DEV each handler's 2xx JSON responses are checked against its `output`.
346
+ * Error responses are checked by the DEV error check
347
+ * (`create_dev_route_error_check`), which `create_app_server` mounts outermost.
365
348
  *
366
349
  * @param resolve_auth_guards - maps `RouteAuth` to middleware — use `fuz_auth_guard_resolver` from `auth/auth_guard_resolver.ts`
367
350
  * @param authorize - optional authorization phase; runs after the pre-authorization guards and before the post-authorization guards
368
351
  * @param db - used for transaction wrapping and `RouteContext`
369
352
  * @mutates `app`
370
- * @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value of neither library, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a fuz_schema `params` or `query` is not an object schema
353
+ * @throws Error if two specs share the same `method` + `path` (each combination must be unique), if a schema slot holds a value of neither library or an `errors` entry is not a definition, if any spec violates a cross-axis auth invariant or the actor-acting biconditional, or if a fuz_schema `params` or `query` is not an object schema
371
354
  */
372
355
  export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, authorize) => {
373
356
  const registered = new Set();
374
357
  for (const spec of specs) {
375
- const route_key = `${spec.method} ${spec.path}`;
358
+ const route_key = format_route_key(spec);
376
359
  if (registered.has(route_key)) {
377
360
  throw new Error(`Duplicate route: ${route_key} — each method+path combination must be unique`);
378
361
  }
@@ -387,7 +370,6 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
387
370
  const params_validation = create_params_validation(spec.params);
388
371
  const query_validation = create_query_validation(spec.query);
389
372
  const input_validation = create_input_validation(spec.input, spec.method);
390
- const merged_errors = merge_error_schemas(spec, null);
391
373
  const authorization = authorize
392
374
  ? [
393
375
  async (c, next) => {
@@ -418,13 +400,13 @@ export const apply_route_specs = (app, specs, resolve_auth_guards, log, db, auth
418
400
  };
419
401
  // Step 2: error catch layer — a thrown error becomes its REST body here
420
402
  handler = wrap_error_catch(handler, log);
421
- // Step 3: output validation, outside the catch so thrown-error bodies are checked too
422
- handler = wrap_output_validation(handler, spec.output, merged_errors, log);
403
+ // Step 3: output validation of a 2xx body
404
+ handler = wrap_output_validation(handler, spec.output, log);
423
405
  app.on(spec.method, [spec.path], ...content_type_check, ...params_validation, ...query_validation, ...pre_authorization_guards, ...authorization, ...post_authorization_guards, ...input_validation, handler);
424
406
  }
425
407
  };
426
- // throws unless every schema slot holds a Zod or fuz_schema schema; `params`,
427
- // `query` and an `errors` entry may be absent
408
+ // throws unless every schema slot holds a Zod or fuz_schema schema and every
409
+ // `errors` entry is a definition; `params` and `query` may be absent
428
410
  const assert_schema_slots = (spec, route_key) => {
429
411
  const label = `Route "${route_key}"`;
430
412
  if (spec.params !== undefined)
@@ -433,10 +415,14 @@ const assert_schema_slots = (spec, route_key) => {
433
415
  assert_validation_schema(spec.query, `${label}: query`);
434
416
  assert_validation_schema(spec.input, `${label}: input`);
435
417
  assert_validation_schema(spec.output, `${label}: output`);
436
- if (spec.errors) {
437
- for (const [status, schema] of Object.entries(spec.errors)) {
438
- if (schema !== undefined)
439
- assert_validation_schema(schema, `${label}: errors.${status}`);
418
+ if (spec.errors !== undefined) {
419
+ if (!Array.isArray(spec.errors)) {
420
+ throw new Error(`${label}: errors is not a list of error definitions (\`rest_error\`)`);
421
+ }
422
+ for (const [i, def] of spec.errors.entries()) {
423
+ if (!is_schema(def?.schema)) {
424
+ throw new Error(`${label}: errors[${i}] is not an error definition (\`rest_error\`)`);
425
+ }
440
426
  }
441
427
  }
442
428
  };
@@ -7,9 +7,6 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import type { RouteAuth } from './auth_shape.js';
11
- import type { RouteMethod } from './route_spec.js';
12
- import { type RateLimitKey, type RouteErrorSchemas } from './error_schemas.js';
13
10
  import { type ParseAnyResult, type ValidationOutput, type ValidationSchema } from '../schema_issues.js';
14
11
  /**
15
12
  * Check if a schema is exactly `z.null()`, or a `@fuzdev/fuz_schema`
@@ -225,9 +222,23 @@ export declare const middleware_applies: (mw_path: string, route_path: string) =
225
222
  * @param b - the other
226
223
  */
227
224
  export declare const middleware_paths_overlap: (a: string, b: string) => boolean;
225
+ /**
226
+ * Check if a middleware layer carves a route path out: one of its
227
+ * `carve_outs` applies to it (`middleware_applies`), whether or not its own
228
+ * `path` does.
229
+ *
230
+ * @param spec - the layer's optional `carve_outs`
231
+ * @param route_path - the route path to check
232
+ */
233
+ export declare const middleware_carves_out: (spec: {
234
+ readonly carve_outs?: ReadonlyArray<{
235
+ readonly path: string;
236
+ }> | null;
237
+ }, route_path: string) => boolean;
228
238
  /**
229
239
  * Check if a middleware layer runs on a route path: its `path` pattern
230
- * applies (`middleware_applies`) and none of its `carve_outs` does.
240
+ * applies (`middleware_applies`) and none of its `carve_outs` does
241
+ * (`middleware_carves_out`).
231
242
  *
232
243
  * @param spec - the layer's `path` and optional `carve_outs`
233
244
  * @param route_path - the route path to check
@@ -238,34 +249,4 @@ export declare const middleware_spec_applies: (spec: {
238
249
  readonly path: string;
239
250
  }> | null;
240
251
  }, route_path: string) => boolean;
241
- /**
242
- * Copy an error-schema map without its entries left `undefined`, so a
243
- * status declared `undefined` reads as absent: it overrides nothing beneath
244
- * it in a merge.
245
- *
246
- * @param errors - a route's or middleware's error schemas, keyed by status
247
- * @returns the entries that hold a schema
248
- */
249
- export declare const strip_undefined_error_schemas: (errors: RouteErrorSchemas) => Record<number, ValidationSchema>;
250
- /**
251
- * Merge auto-derived, middleware, and explicit error schemas for a route spec.
252
- *
253
- * Merge order: derived -> middleware -> explicit route errors.
254
- * Later layers override earlier ones for the same status code; an entry left
255
- * `undefined` is absent (`strip_undefined_error_schemas`), so it leaves the
256
- * layer beneath it in place.
257
- *
258
- * @param spec - the route spec (reads `method`, `auth`, `input`, `params`, `query`, `rate_limit`, `errors`)
259
- * @param middleware_errors - errors contributed by middleware whose path matches the route
260
- * @returns merged error schemas, or `null` if empty
261
- */
262
- export declare const merge_error_schemas: (spec: {
263
- method: RouteMethod;
264
- auth: RouteAuth;
265
- input: ValidationSchema;
266
- params?: ValidationSchema;
267
- query?: ValidationSchema;
268
- rate_limit?: RateLimitKey;
269
- errors?: RouteErrorSchemas;
270
- }, middleware_errors?: RouteErrorSchemas | null) => Record<number, ValidationSchema> | null;
271
252
  //# sourceMappingURL=schema_helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/schema_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAQH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,C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