@fuzdev/fuz_app 0.162.0 → 0.164.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 (280) 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 +39 -36
  8. package/dist/auth/account_action_specs.d.ts +441 -115
  9. package/dist/auth/account_action_specs.d.ts.map +1 -1
  10. package/dist/auth/account_action_specs.js +47 -46
  11. package/dist/auth/account_route_schema.d.ts +98 -62
  12. package/dist/auth/account_route_schema.d.ts.map +1 -1
  13. package/dist/auth/account_route_schema.js +45 -45
  14. package/dist/auth/account_routes.js +1 -1
  15. package/dist/auth/account_schema.d.ts +54 -27
  16. package/dist/auth/account_schema.d.ts.map +1 -1
  17. package/dist/auth/account_schema.js +16 -18
  18. package/dist/auth/admin_action_specs.d.ts +76 -76
  19. package/dist/auth/admin_action_specs.js +2 -4
  20. package/dist/auth/admin_actions.d.ts +4 -4
  21. package/dist/auth/admin_actions.d.ts.map +1 -1
  22. package/dist/auth/admin_actions.js +3 -3
  23. package/dist/auth/all_cell_actions.d.ts +3 -3
  24. package/dist/auth/all_cell_actions.d.ts.map +1 -1
  25. package/dist/auth/all_cell_actions.js +1 -1
  26. package/dist/auth/api_token.d.ts +4 -4
  27. package/dist/auth/api_token.d.ts.map +1 -1
  28. package/dist/auth/api_token.js +3 -3
  29. package/dist/auth/audit_log_route_schema.d.ts +1 -1
  30. package/dist/auth/audit_log_route_schema.d.ts.map +1 -1
  31. package/dist/auth/audit_log_route_schema.js +4 -5
  32. package/dist/auth/audit_log_schema.d.ts +46 -66
  33. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  34. package/dist/auth/audit_log_schema.js +34 -30
  35. package/dist/auth/bootstrap_route_schema.d.ts +146 -52
  36. package/dist/auth/bootstrap_route_schema.d.ts.map +1 -1
  37. package/dist/auth/bootstrap_route_schema.js +33 -19
  38. package/dist/auth/cell_grant_action_specs.d.ts +1 -1
  39. package/dist/auth/cell_grant_action_specs.js +1 -1
  40. package/dist/auth/cell_grant_actions.d.ts +4 -4
  41. package/dist/auth/cell_grant_actions.d.ts.map +1 -1
  42. package/dist/auth/cell_grant_actions.js +1 -1
  43. package/dist/auth/credential_type_schema.d.ts +16 -29
  44. package/dist/auth/credential_type_schema.d.ts.map +1 -1
  45. package/dist/auth/credential_type_schema.js +14 -18
  46. package/dist/auth/daemon_token.d.ts +4 -4
  47. package/dist/auth/daemon_token.d.ts.map +1 -1
  48. package/dist/auth/daemon_token.js +3 -3
  49. package/dist/auth/daemon_token_middleware.d.ts +1 -1
  50. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  51. package/dist/auth/daemon_token_middleware.js +5 -5
  52. package/dist/auth/grant_path_schema.d.ts +15 -29
  53. package/dist/auth/grant_path_schema.d.ts.map +1 -1
  54. package/dist/auth/grant_path_schema.js +13 -17
  55. package/dist/auth/middleware.js +4 -4
  56. package/dist/auth/migrations.js +1 -1
  57. package/dist/auth/name_schema.d.ts +7 -6
  58. package/dist/auth/name_schema.d.ts.map +1 -1
  59. package/dist/auth/name_schema.js +8 -9
  60. package/dist/auth/password.d.ts +15 -7
  61. package/dist/auth/password.d.ts.map +1 -1
  62. package/dist/auth/password.js +16 -9
  63. package/dist/auth/role_grant_offer_action_specs.d.ts +2 -2
  64. package/dist/auth/role_grant_offer_action_specs.js +2 -2
  65. package/dist/auth/role_grant_offer_actions.d.ts +4 -4
  66. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  67. package/dist/auth/role_grant_offer_actions.js +3 -3
  68. package/dist/auth/role_grant_offer_notifications.js +2 -2
  69. package/dist/auth/role_grant_offer_schema.d.ts +2 -2
  70. package/dist/auth/role_grant_offer_schema.js +2 -2
  71. package/dist/auth/role_schema.d.ts +47 -55
  72. package/dist/auth/role_schema.d.ts.map +1 -1
  73. package/dist/auth/role_schema.js +29 -35
  74. package/dist/auth/scope_kind_schema.d.ts +22 -26
  75. package/dist/auth/scope_kind_schema.d.ts.map +1 -1
  76. package/dist/auth/scope_kind_schema.js +19 -19
  77. package/dist/auth/self_service_role_action_specs.js +1 -1
  78. package/dist/auth/self_service_role_actions.d.ts +6 -6
  79. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  80. package/dist/auth/self_service_role_actions.js +7 -6
  81. package/dist/auth/signup_route_schema.d.ts +71 -21
  82. package/dist/auth/signup_route_schema.d.ts.map +1 -1
  83. package/dist/auth/signup_route_schema.js +17 -19
  84. package/dist/auth/standard_rpc_actions.d.ts +1 -1
  85. package/dist/auth/standard_rpc_actions.js +1 -1
  86. package/dist/auth/token_lifetime.d.ts +33 -9
  87. package/dist/auth/token_lifetime.d.ts.map +1 -1
  88. package/dist/auth/token_lifetime.js +8 -7
  89. package/dist/auth/token_scope.d.ts +99 -25
  90. package/dist/auth/token_scope.d.ts.map +1 -1
  91. package/dist/auth/token_scope.js +57 -35
  92. package/dist/db/CLAUDE.md +2 -1
  93. package/dist/db/file_fact_url.d.ts +11 -6
  94. package/dist/db/file_fact_url.d.ts.map +1 -1
  95. package/dist/db/file_fact_url.js +5 -5
  96. package/dist/db/schema_ready.d.ts +0 -5
  97. package/dist/db/schema_ready.d.ts.map +1 -1
  98. package/dist/db/schema_ready.js +0 -5
  99. package/dist/http/CLAUDE.md +104 -71
  100. package/dist/http/auth_shape.d.ts +48 -29
  101. package/dist/http/auth_shape.d.ts.map +1 -1
  102. package/dist/http/auth_shape.js +12 -85
  103. package/dist/http/body_limit.d.ts +12 -0
  104. package/dist/http/body_limit.d.ts.map +1 -1
  105. package/dist/http/body_limit.js +15 -0
  106. package/dist/http/body_limit_schema.d.ts +20 -0
  107. package/dist/http/body_limit_schema.d.ts.map +1 -0
  108. package/dist/http/body_limit_schema.js +20 -0
  109. package/dist/http/common_routes.d.ts +1 -1
  110. package/dist/http/common_routes.d.ts.map +1 -1
  111. package/dist/http/common_routes.js +11 -14
  112. package/dist/http/db_routes.d.ts.map +1 -1
  113. package/dist/http/db_routes.js +59 -69
  114. package/dist/http/dev_route_error_check.d.ts +70 -0
  115. package/dist/http/dev_route_error_check.d.ts.map +1 -0
  116. package/dist/http/dev_route_error_check.js +119 -0
  117. package/dist/http/error_schemas.d.ts +365 -189
  118. package/dist/http/error_schemas.d.ts.map +1 -1
  119. package/dist/http/error_schemas.js +256 -149
  120. package/dist/http/health_schema.d.ts +10 -6
  121. package/dist/http/health_schema.d.ts.map +1 -1
  122. package/dist/http/health_schema.js +3 -3
  123. package/dist/http/middleware_spec.d.ts +8 -3
  124. package/dist/http/middleware_spec.d.ts.map +1 -1
  125. package/dist/http/origin.d.ts +12 -43
  126. package/dist/http/origin.d.ts.map +1 -1
  127. package/dist/http/origin.js +10 -6
  128. package/dist/http/route_error_check.d.ts +158 -0
  129. package/dist/http/route_error_check.d.ts.map +1 -0
  130. package/dist/http/route_error_check.js +247 -0
  131. package/dist/http/route_errors.d.ts +80 -0
  132. package/dist/http/route_errors.d.ts.map +1 -0
  133. package/dist/http/route_errors.js +83 -0
  134. package/dist/http/route_spec.d.ts +33 -17
  135. package/dist/http/route_spec.d.ts.map +1 -1
  136. package/dist/http/route_spec.js +48 -62
  137. package/dist/http/schema_helpers.d.ts +0 -33
  138. package/dist/http/schema_helpers.d.ts.map +1 -1
  139. package/dist/http/schema_helpers.js +0 -45
  140. package/dist/http/surface.d.ts +19 -12
  141. package/dist/http/surface.d.ts.map +1 -1
  142. package/dist/http/surface.js +25 -38
  143. package/dist/http/surface_query.d.ts +11 -2
  144. package/dist/http/surface_query.d.ts.map +1 -1
  145. package/dist/http/surface_query.js +7 -1
  146. package/dist/primitive_schemas.d.ts +2 -19
  147. package/dist/primitive_schemas.d.ts.map +1 -1
  148. package/dist/primitive_schemas.js +2 -20
  149. package/dist/primitive_schemas_fuz.d.ts +39 -5
  150. package/dist/primitive_schemas_fuz.d.ts.map +1 -1
  151. package/dist/primitive_schemas_fuz.js +36 -7
  152. package/dist/rate_limiter.d.ts +13 -0
  153. package/dist/rate_limiter.d.ts.map +1 -1
  154. package/dist/rate_limiter.js +20 -2
  155. package/dist/schema_issues.d.ts +29 -11
  156. package/dist/schema_issues.d.ts.map +1 -1
  157. package/dist/schema_issues.js +11 -10
  158. package/dist/schema_meta.d.ts +8 -1
  159. package/dist/schema_meta.d.ts.map +1 -1
  160. package/dist/schema_meta.js +2 -1
  161. package/dist/server/app_server.d.ts +3 -1
  162. package/dist/server/app_server.d.ts.map +1 -1
  163. package/dist/server/app_server.js +24 -10
  164. package/dist/server/serve_fact_route.d.ts.map +1 -1
  165. package/dist/server/serve_fact_route.js +8 -31
  166. package/dist/server/surface_route.d.ts.map +1 -1
  167. package/dist/server/surface_route.js +5 -6
  168. package/dist/server/x_accel.d.ts +12 -7
  169. package/dist/server/x_accel.d.ts.map +1 -1
  170. package/dist/server/x_accel.js +7 -9
  171. package/dist/testing/CLAUDE.md +55 -44
  172. package/dist/testing/admin_integration.d.ts +3 -3
  173. package/dist/testing/admin_integration.d.ts.map +1 -1
  174. package/dist/testing/admin_integration.js +2 -2
  175. package/dist/testing/adversarial_404.d.ts +4 -18
  176. package/dist/testing/adversarial_404.d.ts.map +1 -1
  177. package/dist/testing/adversarial_404.js +19 -51
  178. package/dist/testing/adversarial_headers.d.ts +3 -4
  179. package/dist/testing/adversarial_headers.d.ts.map +1 -1
  180. package/dist/testing/adversarial_headers.js +8 -6
  181. package/dist/testing/adversarial_input.d.ts.map +1 -1
  182. package/dist/testing/adversarial_input.js +18 -17
  183. package/dist/testing/assertions.d.ts +33 -11
  184. package/dist/testing/assertions.d.ts.map +1 -1
  185. package/dist/testing/assertions.js +52 -12
  186. package/dist/testing/attack_surface.d.ts +5 -35
  187. package/dist/testing/attack_surface.d.ts.map +1 -1
  188. package/dist/testing/attack_surface.js +29 -91
  189. package/dist/testing/auth_apps.d.ts.map +1 -1
  190. package/dist/testing/auth_apps.js +2 -1
  191. package/dist/testing/cross_backend/action_manifest.d.ts +126 -56
  192. package/dist/testing/cross_backend/action_manifest.d.ts.map +1 -1
  193. package/dist/testing/cross_backend/action_manifest.js +11 -11
  194. package/dist/testing/cross_backend/action_manifest_parity.d.ts +1 -1
  195. package/dist/testing/cross_backend/action_manifest_parity.d.ts.map +1 -1
  196. package/dist/testing/cross_backend/cell_crud.d.ts.map +1 -1
  197. package/dist/testing/cross_backend/cell_crud.js +2 -1
  198. package/dist/testing/cross_backend/conformance_table.js +1 -1
  199. package/dist/testing/cross_backend/default_spine_surface.d.ts +2 -2
  200. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  201. package/dist/testing/cross_backend/default_spine_surface.js +2 -2
  202. package/dist/testing/cross_backend/fact_serving.js +3 -3
  203. package/dist/testing/cross_backend/identity_parity.d.ts.map +1 -1
  204. package/dist/testing/cross_backend/identity_parity.js +39 -6
  205. package/dist/testing/cross_backend/origin_conformance.d.ts +278 -102
  206. package/dist/testing/cross_backend/origin_conformance.d.ts.map +1 -1
  207. package/dist/testing/cross_backend/origin_conformance.js +21 -21
  208. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -3
  209. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  210. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +7 -1
  211. package/dist/testing/cross_backend/setup.d.ts +14 -1
  212. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  213. package/dist/testing/cross_backend/setup.js +68 -48
  214. package/dist/testing/cross_backend/spine_suites.d.ts +3 -3
  215. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  216. package/dist/testing/cross_backend/standard.d.ts +4 -4
  217. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  218. package/dist/testing/cross_backend/testing_origin_check.d.ts +147 -71
  219. package/dist/testing/cross_backend/testing_origin_check.d.ts.map +1 -1
  220. package/dist/testing/cross_backend/testing_origin_check.js +16 -13
  221. package/dist/testing/cross_backend/testing_reset_actions.d.ts +70 -27
  222. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  223. package/dist/testing/cross_backend/token_lifetime.d.ts.map +1 -1
  224. package/dist/testing/cross_backend/token_lifetime.js +34 -1
  225. package/dist/testing/data_exposure.d.ts.map +1 -1
  226. package/dist/testing/data_exposure.js +5 -4
  227. package/dist/testing/error_coverage.d.ts +24 -34
  228. package/dist/testing/error_coverage.d.ts.map +1 -1
  229. package/dist/testing/error_coverage.js +46 -89
  230. package/dist/testing/integration.d.ts.map +1 -1
  231. package/dist/testing/integration.js +6 -14
  232. package/dist/testing/integration_helpers.d.ts +37 -9
  233. package/dist/testing/integration_helpers.d.ts.map +1 -1
  234. package/dist/testing/integration_helpers.js +86 -40
  235. package/dist/testing/middleware.d.ts +3 -5
  236. package/dist/testing/middleware.d.ts.map +1 -1
  237. package/dist/testing/middleware.js +5 -4
  238. package/dist/testing/rate_limiting.d.ts +1 -1
  239. package/dist/testing/rate_limiting.d.ts.map +1 -1
  240. package/dist/testing/rate_limiting.js +5 -4
  241. package/dist/testing/round_trip.d.ts.map +1 -1
  242. package/dist/testing/round_trip.js +5 -3
  243. package/dist/testing/schema_generators.d.ts +10 -3
  244. package/dist/testing/schema_generators.d.ts.map +1 -1
  245. package/dist/testing/schema_generators.js +23 -11
  246. package/dist/testing/stubs.d.ts +10 -1
  247. package/dist/testing/stubs.d.ts.map +1 -1
  248. package/dist/testing/stubs.js +15 -5
  249. package/dist/testing/surface_invariants.d.ts +36 -115
  250. package/dist/testing/surface_invariants.d.ts.map +1 -1
  251. package/dist/testing/surface_invariants.js +106 -269
  252. package/dist/testing/token_scope_fixtures.d.ts +24 -0
  253. package/dist/testing/token_scope_fixtures.d.ts.map +1 -0
  254. package/dist/testing/token_scope_fixtures.js +49 -0
  255. package/dist/testing/transports/bootstrap.d.ts +1 -1
  256. package/dist/testing/transports/bootstrap.d.ts.map +1 -1
  257. package/dist/testing/transports/bootstrap.js +13 -12
  258. package/dist/ui/BootstrapForm.svelte +4 -2
  259. package/dist/ui/BootstrapForm.svelte.d.ts.map +1 -1
  260. package/dist/ui/CLAUDE.md +4 -2
  261. package/dist/ui/SignupForm.svelte +4 -2
  262. package/dist/ui/SignupForm.svelte.d.ts.map +1 -1
  263. package/dist/ui/auth_state.svelte.d.ts.map +1 -1
  264. package/dist/ui/auth_state.svelte.js +2 -8
  265. package/dist/ui/backend_probe.svelte.js +3 -3
  266. package/dist/ui/table_state.svelte.d.ts.map +1 -1
  267. package/dist/ui/table_state.svelte.js +1 -8
  268. package/dist/ui/ui_fetch.d.ts +12 -2
  269. package/dist/ui/ui_fetch.d.ts.map +1 -1
  270. package/dist/ui/ui_fetch.js +22 -4
  271. package/package.json +1 -1
  272. package/dist/auth/audit_log_schema_fuz.d.ts +0 -53
  273. package/dist/auth/audit_log_schema_fuz.d.ts.map +0 -1
  274. package/dist/auth/audit_log_schema_fuz.js +0 -50
  275. package/dist/auth/role_schema_fuz.d.ts +0 -30
  276. package/dist/auth/role_schema_fuz.d.ts.map +0 -1
  277. package/dist/auth/role_schema_fuz.js +0 -30
  278. package/dist/auth/scope_kind_schema_fuz.d.ts +0 -31
  279. package/dist/auth/scope_kind_schema_fuz.d.ts.map +0 -1
  280. package/dist/auth/scope_kind_schema_fuz.js +0 -31
@@ -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 neither check
32
- * can live only on a schema.
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: z.ZodEnum<{
108
- optional: "optional";
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` (and by this schema's `.superRefine`, the
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 time,
136
- * not on this schema. See `assert_route_auth_acting_biconditional`
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 declare const RouteAuth: z.ZodObject<{
140
- account: z.ZodEnum<{
141
- optional: "optional";
142
- none: "none";
143
- required: "required";
144
- }>;
145
- actor: z.ZodEnum<{
146
- optional: "optional";
147
- none: "none";
148
- required: "required";
149
- }>;
150
- roles: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
151
- credential_types: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
152
- required_scope: z.ZodOptional<z.ZodString>;
153
- }, z.core.$strict>;
154
- export type RouteAuth = z.infer<typeof RouteAuth>;
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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AClD,MAAM,SAAS,EACf,OAAO,WAAW,EAClB,SAAS,MAAM,KACb,IAmBF,CAAC"}
@@ -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 neither check
32
- * can live only on a schema.
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 = z.enum(['none', 'optional', 'required']);
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 one implementation behind `assert_route_auth_invariants` and 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, `merge_error_schemas`, `surface_query`, the surface explorer
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`. Cannot live on the `RouteAuth`
298
- // schema's `.superRefine` because it requires introspecting the spec's
299
- // input/query schemas for reference equality with the canonical
300
- // `ActingActor` schema above. Enforced at registration time by every
301
- // dispatcher loop (`apply_route_specs`, `compile_action_registry` for
302
- // `create_rpc_endpoint` + `register_action_ws`).
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
@@ -1 +1 @@
1
- {"version":3,"file":"body_limit.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/body_limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAQ9C;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,MAAM,KAAG,iBA6B/D,CAAC"}
1
+ {"version":3,"file":"body_limit.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/body_limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAI9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,MAAM,KAAG,iBA6B/D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,KAAG,cAGnE,CAAC"}
@@ -65,6 +65,7 @@
65
65
  */
66
66
  import { bodyLimit } from 'hono/body-limit';
67
67
  import { ERROR_INVALID_CONTENT_LENGTH, ERROR_PAYLOAD_TOO_LARGE } from './error_schemas.js';
68
+ import { body_limit_middleware_shape } from './body_limit_schema.js';
68
69
  /** A well-formed `Content-Length` value: one or more ASCII digits and nothing else. */
69
70
  const CONTENT_LENGTH_DIGITS = /^[0-9]+$/;
70
71
  /**
@@ -103,3 +104,17 @@ export const create_body_limit_middleware = (max_size) => {
103
104
  return streaming_limit(c, next);
104
105
  };
105
106
  };
107
+ /**
108
+ * Create the body size limit as a middleware spec — `body_limit_middleware_shape`
109
+ * at `'*'` with its handler — which `create_app_server` mounts ahead of the
110
+ * other middleware, so every route's error map carries the limit's `413` and
111
+ * `400`.
112
+ *
113
+ * @param max_size - the largest accepted body, in bytes; a safe integer, `0` or more
114
+ * @returns the spec, its handler `create_body_limit_middleware(max_size)`
115
+ * @throws Error when `max_size` is not a safe integer `0` or more
116
+ */
117
+ export const create_body_limit_middleware_spec = (max_size) => ({
118
+ ...body_limit_middleware_shape,
119
+ handler: create_body_limit_middleware(max_size)
120
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The body size limit's middleware shape minus its handler — hono-free data,
3
+ * so the surface builders that never mount the limit (`testing/stubs.ts`)
4
+ * declare it without importing `hono/body-limit`.
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * The body limit's middleware spec minus its handler: at `'*'`, ahead of the
10
+ * other middleware, answering `413` `payload_too_large` past the cap and
11
+ * `400` `invalid_content_length` to a `Content-Length` it cannot read.
12
+ * `create_body_limit_middleware_spec` (`http/body_limit.ts`) spreads it and
13
+ * attaches the live handler.
14
+ */
15
+ export declare const body_limit_middleware_shape: {
16
+ readonly name: "body_limit";
17
+ readonly path: "*";
18
+ readonly errors: readonly [import("./error_schemas.js").RestErrorDef<413, "payload_too_large", Record<never, never>>, import("./error_schemas.js").RestErrorDef<400, "invalid_content_length", Record<never, never>>];
19
+ };
20
+ //# sourceMappingURL=body_limit_schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body_limit_schema.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/body_limit_schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;CAIY,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The body size limit's middleware shape minus its handler — hono-free data,
3
+ * so the surface builders that never mount the limit (`testing/stubs.ts`)
4
+ * declare it without importing `hono/body-limit`.
5
+ *
6
+ * @module
7
+ */
8
+ import { REST_INVALID_CONTENT_LENGTH, REST_PAYLOAD_TOO_LARGE } from './error_schemas.js';
9
+ /**
10
+ * The body limit's middleware spec minus its handler: at `'*'`, ahead of the
11
+ * other middleware, answering `413` `payload_too_large` past the cap and
12
+ * `400` `invalid_content_length` to a `Content-Length` it cannot read.
13
+ * `create_body_limit_middleware_spec` (`http/body_limit.ts`) spreads it and
14
+ * attaches the live handler.
15
+ */
16
+ export const body_limit_middleware_shape = {
17
+ name: 'body_limit',
18
+ path: '*',
19
+ errors: [REST_PAYLOAD_TOO_LARGE, REST_INVALID_CONTENT_LENGTH]
20
+ };
@@ -67,7 +67,7 @@ export declare const create_ready_route_spec: (options: ReadyRouteOptions) => Ro
67
67
  export interface ServerStatusOptions {
68
68
  /** Application version string. */
69
69
  version: string;
70
- /** Returns milliseconds since server start. */
70
+ /** Returns whole milliseconds since server start, which the route's output requires. */
71
71
  get_uptime_ms: () => number;
72
72
  }
73
73
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"common_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/common_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAIN,KAAK,cAAc,EACnB,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,QAAO,SAQ1C,CAAC;AAKH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,GAAG,MAAM,KAAG,cAkBxD,CAAC;AAEF,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,QAAQ,EAAE,cAAc,CAAC;IACzB,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,iBAAiB,KAAG,SAoCpE,CAAC;AAEF,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IACnC,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,aAAa,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,mBAAmB,KAAG,SAQ7E,CAAC"}
1
+ {"version":3,"file":"common_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/common_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQjD,OAAO,EAGN,KAAK,cAAc,EACnB,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,QAAO,SAQ1C,CAAC;AAKH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,GAAG,MAAM,KAAG,cAkBxD,CAAC;AAEF,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IACjC;;;;OAIG;IACH,QAAQ,EAAE,cAAc,CAAC;IACzB,gFAAgF;IAChF,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,iBAAiB,KAAG,SAgCpE,CAAC;AAEF,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IACnC,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,aAAa,EAAE,MAAM,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,mBAAmB,KAAG,SAQ7E,CAAC"}
@@ -7,9 +7,10 @@
7
7
  * @module
8
8
  */
9
9
  import { readFileSync } from 'node:fs';
10
- import { z } from 'zod';
10
+ import { integer, literal, loose_object, min_value, number, object, pipe, string } from '@fuzdev/fuz_schema/schema.ts';
11
11
  import { HEALTH_PATH, HealthResponse } from './health_schema.js';
12
- import { check_schema_drift, format_schema_drift, READY_ERROR } from '../db/schema_ready.js';
12
+ import { ERROR_DB_UNREACHABLE, ERROR_SCHEMA_DRIFT, REST_DB_UNREACHABLE, REST_SCHEMA_DRIFT } from './error_schemas.js';
13
+ import { check_schema_drift, format_schema_drift } from '../db/schema_ready.js';
13
14
  /**
14
15
  * Create a public health check route spec.
15
16
  *
@@ -22,7 +23,7 @@ export const create_health_route_spec = () => ({
22
23
  auth: { account: 'none', actor: 'none' },
23
24
  handler: (c) => c.json({ status: 'ok' }),
24
25
  description: 'Health check',
25
- input: z.null(),
26
+ input: literal(null),
26
27
  output: HealthResponse
27
28
  });
28
29
  /** Module-level cache of loaded expected-schema fixtures, keyed by URL. */
@@ -91,13 +92,9 @@ export const create_ready_route_spec = (options) => {
91
92
  path: '/ready',
92
93
  auth: { account: 'none', actor: 'none' },
93
94
  description: 'Readiness probe — verifies the live DB schema matches the expected column map',
94
- input: z.null(),
95
- output: z.strictObject({ ready: z.literal(true) }),
96
- errors: {
97
- 503: z.strictObject({
98
- error: z.enum([READY_ERROR.schema_drift, READY_ERROR.db_unreachable])
99
- })
100
- },
95
+ input: literal(null),
96
+ output: object({ ready: literal(true) }),
97
+ errors: [REST_SCHEMA_DRIFT, REST_DB_UNREACHABLE],
101
98
  handler: async (c, route) => {
102
99
  try {
103
100
  const drift = await check_schema_drift(route.db, options.expected);
@@ -106,11 +103,11 @@ export const create_ready_route_spec = (options) => {
106
103
  // Detailed drift goes to the server log only — the public body stays a
107
104
  // minimal error code so the endpoint doesn't leak schema structure.
108
105
  options.log?.error(`[ready] schema drift detected:\n${format_schema_drift(drift)}`);
109
- return c.json({ error: READY_ERROR.schema_drift }, 503);
106
+ return c.json({ error: ERROR_SCHEMA_DRIFT }, 503);
110
107
  }
111
108
  catch (err) {
112
109
  options.log?.error('[ready] readiness check failed (db unreachable?):', err);
113
- return c.json({ error: READY_ERROR.db_unreachable }, 503);
110
+ return c.json({ error: ERROR_DB_UNREACHABLE }, 503);
114
111
  }
115
112
  }
116
113
  };
@@ -127,6 +124,6 @@ export const create_server_status_route_spec = (options) => ({
127
124
  auth: { account: 'required', actor: 'none' },
128
125
  handler: (c) => c.json({ version: options.version, uptime_ms: options.get_uptime_ms() }),
129
126
  description: 'Server version and uptime',
130
- input: z.null(),
131
- output: z.looseObject({ version: z.string(), uptime_ms: z.number() })
127
+ input: literal(null),
128
+ output: loose_object({ version: string, uptime_ms: pipe(number, integer, min_value(0)) })
132
129
  });
@@ -1 +1 @@
1
- {"version":3,"file":"db_routes.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD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;IACH,oBAAoB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CAC7C;AA2CD;;GAEG;AACH,eAAO,MAAM,qBAAqB,GACjC,MAAM,WAAW,EACjB,SAAS,cAAc,KACrB,KAAK,CAAC,SAAS,CAqWjB,CAAC"}
@@ -9,16 +9,37 @@
9
9
  *
10
10
  * @module
11
11
  */
12
- import { z } from 'zod';
13
- import { object } from '@fuzdev/fuz_schema/schema.ts';
14
- import { ActingActor as ActingActorFuz } from '../primitive_schemas_fuz.js';
12
+ import { meta } from '@fuzdev/fuz_schema/meta.ts';
13
+ import { array, boolean, integer, literal, loose_object, max_value, min_value, nullable, number, object, pipe, record, regex, safe_integer, string, transform, unknown, with_default } from '@fuzdev/fuz_schema/schema.ts';
14
+ import { ActingActor } from '../primitive_schemas_fuz.js';
15
15
  import { get_route_params, get_route_query } from './route_spec.js';
16
- import { ActingActor } from './auth_shape.js';
17
- import { ForeignKeyError, ERROR_TABLE_NOT_FOUND, ERROR_TABLE_NO_PRIMARY_KEY, ERROR_TABLE_NOT_DELETABLE, ERROR_ROW_NOT_FOUND, ERROR_FOREIGN_KEY_VIOLATION, ERROR_INVALID_ROUTE_PARAMS, ERROR_DATABASE_CONNECTION_FAILED } from './error_schemas.js';
16
+ import { ERROR_TABLE_NOT_FOUND, ERROR_TABLE_NO_PRIMARY_KEY, ERROR_TABLE_NOT_DELETABLE, ERROR_ROW_NOT_FOUND, ERROR_FOREIGN_KEY_VIOLATION, ERROR_DATABASE_CONNECTION_FAILED, REST_DATABASE_CONNECTION_FAILED, REST_FOREIGN_KEY_VIOLATION, REST_ROW_NOT_FOUND, REST_TABLE_NO_PRIMARY_KEY, REST_TABLE_NOT_DELETABLE, REST_TABLE_NOT_FOUND } from './error_schemas.js';
18
17
  import { assert_valid_sql_identifier, VALID_SQL_IDENTIFIER } from '../db/sql_identifier.js';
19
18
  import { pg_error_code } from '../db/pg_error.js';
20
19
  import { get_client_ip } from './client_ip.js';
21
20
  import { emit_after_commit } from './pending_effects.js';
21
+ // the spellings `query_int` reads as an integer: decimal digits with an optional sign
22
+ const QUERY_INT_PATTERN = /^[+-]?\d+$/;
23
+ /**
24
+ * A strict integer query param with bounds and a default — accepts exactly
25
+ * the spellings the Rust twin's `str::parse::<i64>` does (`[+-]?digits`), so
26
+ * the twins refuse the same ones (`""`, `" 5"`, `"1e2"`, `"5.0"`, `"0x10"`),
27
+ * then a safe integer within `[min, max]`. An absent param is `fallback`.
28
+ *
29
+ * The surface writes it as a string with `QUERY_INT_PATTERN`, its bounds in
30
+ * the description: the steps after the `transform` read a number JSON Schema
31
+ * can't say the string becomes.
32
+ *
33
+ * @param min - the least integer accepted
34
+ * @param max - the greatest integer accepted
35
+ * @param fallback - the value of an absent param
36
+ * @returns the query param schema, whose output is a number
37
+ */
38
+ const query_int = (min, max, fallback) => meta(with_default(pipe(pipe(string, regex(QUERY_INT_PATTERN), transform(Number)), safe_integer, min_value(min), max_value(max)), fallback), { description: `an integer from ${min} to ${max}, as decimal digits with an optional sign` });
39
+ /** A count or position the db routes answer with: a non-negative integer. */
40
+ const Count = pipe(number, integer, min_value(0));
41
+ /** A table name in a path: a valid SQL identifier. */
42
+ const TableName = pipe(string, regex(VALID_SQL_IDENTIFIER));
22
43
  /** Default page size for `GET /tables/:name` rows. */
23
44
  export const DB_TABLE_ROWS_DEFAULT_LIMIT = 100;
24
45
  /** Maximum page size for `GET /tables/:name` rows. */
@@ -142,16 +163,6 @@ export const create_db_route_specs = (deps, options) => {
142
163
  await set_statement_timeout(db);
143
164
  return query_table_exists(db, name);
144
165
  };
145
- /**
146
- * Strict integer query param — accepts exactly what the Rust twin's
147
- * `str::parse::<i64>` does (`[+-]?digits`), so the twins refuse the same
148
- * spellings (`z.coerce` alone admits `""`, `" 5"`, `"1e2"`, `"5.0"`).
149
- */
150
- const query_int = (bounds, fallback) => z.preprocess((v) => v === undefined
151
- ? undefined
152
- : typeof v === 'string' && /^[+-]?\d+$/.test(v)
153
- ? Number(v)
154
- : Number.NaN, bounds.default(fallback));
155
166
  return [
156
167
  {
157
168
  method: 'GET',
@@ -163,12 +174,10 @@ export const create_db_route_specs = (deps, options) => {
163
174
  credential_types: ['daemon_token']
164
175
  },
165
176
  description: 'Database health and stats',
166
- query: object({ acting: ActingActorFuz }),
167
- input: z.null(),
168
- output: z.looseObject({ connected: z.boolean() }),
169
- errors: {
170
- 503: z.looseObject({ error: z.literal(ERROR_DATABASE_CONNECTION_FAILED) })
171
- },
177
+ query: object({ acting: ActingActor }),
178
+ input: literal(null),
179
+ output: loose_object({ connected: boolean }),
180
+ errors: [REST_DATABASE_CONNECTION_FAILED],
172
181
  handler: async (c, route) => {
173
182
  try {
174
183
  await route.db.query('SELECT 1');
@@ -206,10 +215,10 @@ export const create_db_route_specs = (deps, options) => {
206
215
  credential_types: ['daemon_token']
207
216
  },
208
217
  description: 'List browsable tables with row counts',
209
- query: object({ acting: ActingActorFuz }),
210
- input: z.null(),
211
- output: z.looseObject({
212
- tables: z.array(z.strictObject({ name: z.string(), row_count: z.number() }))
218
+ query: object({ acting: ActingActor }),
219
+ input: literal(null),
220
+ output: loose_object({
221
+ tables: array(object({ name: string, row_count: Count }))
213
222
  }),
214
223
  transaction: true,
215
224
  handler: async (c, route) => {
@@ -242,32 +251,22 @@ export const create_db_route_specs = (deps, options) => {
242
251
  credential_types: ['daemon_token']
243
252
  },
244
253
  description: 'Get table columns and rows (paginated)',
245
- params: z.strictObject({ name: z.string().regex(VALID_SQL_IDENTIFIER) }),
246
- // Zod, unlike the `{acting}`-only queries here: its paging params are
247
- // `query_int`'s Zod preprocess, which stays with the rest of these
248
- // routes' Zod schemas
249
- query: z.strictObject({
254
+ params: object({ name: TableName }),
255
+ query: object({
250
256
  acting: ActingActor,
251
- offset: query_int(z.number().int().min(0), 0),
252
- limit: query_int(z.number().int().min(1).max(DB_TABLE_ROWS_LIMIT_MAX), DB_TABLE_ROWS_DEFAULT_LIMIT)
257
+ offset: query_int(0, Number.MAX_SAFE_INTEGER, 0),
258
+ limit: query_int(1, DB_TABLE_ROWS_LIMIT_MAX, DB_TABLE_ROWS_DEFAULT_LIMIT)
253
259
  }),
254
- input: z.null(),
255
- errors: {
256
- 400: z.looseObject({ error: z.literal(ERROR_INVALID_ROUTE_PARAMS) }),
257
- 404: z.looseObject({ error: z.literal(ERROR_TABLE_NOT_FOUND) })
258
- },
259
- output: z.looseObject({
260
- columns: z.array(z.strictObject({
261
- column_name: z.string(),
262
- data_type: z.string(),
263
- is_nullable: z.string()
264
- })),
265
- rows: z.array(z.record(z.string(), z.unknown())),
266
- total: z.number(),
267
- offset: z.number(),
268
- limit: z.number(),
269
- primary_key: z.string().nullable(),
270
- deletable: z.boolean()
260
+ input: literal(null),
261
+ errors: [REST_TABLE_NOT_FOUND],
262
+ output: loose_object({
263
+ columns: array(object({ column_name: string, data_type: string, is_nullable: string })),
264
+ rows: array(record(unknown)),
265
+ total: Count,
266
+ offset: Count,
267
+ limit: Count,
268
+ primary_key: nullable(string),
269
+ deletable: boolean
271
270
  }),
272
271
  transaction: true,
273
272
  handler: async (c, route) => {
@@ -331,26 +330,17 @@ export const create_db_route_specs = (deps, options) => {
331
330
  credential_types: ['daemon_token']
332
331
  },
333
332
  description: 'Delete a row by primary key',
334
- params: z.strictObject({
335
- name: z.string().regex(VALID_SQL_IDENTIFIER),
336
- id: z.string()
337
- }),
338
- query: object({ acting: ActingActorFuz }),
339
- input: z.null(),
340
- output: z.looseObject({ success: z.boolean() }),
341
- errors: {
342
- 400: z.looseObject({
343
- error: z.enum([
344
- ERROR_INVALID_ROUTE_PARAMS,
345
- ERROR_TABLE_NO_PRIMARY_KEY,
346
- ERROR_TABLE_NOT_DELETABLE
347
- ])
348
- }),
349
- 404: z.looseObject({
350
- error: z.enum([ERROR_TABLE_NOT_FOUND, ERROR_ROW_NOT_FOUND])
351
- }),
352
- 409: ForeignKeyError
353
- },
333
+ params: object({ name: TableName, id: string }),
334
+ query: object({ acting: ActingActor }),
335
+ input: literal(null),
336
+ output: loose_object({ success: boolean }),
337
+ errors: [
338
+ REST_TABLE_NOT_DELETABLE,
339
+ REST_TABLE_NO_PRIMARY_KEY,
340
+ REST_TABLE_NOT_FOUND,
341
+ REST_ROW_NOT_FOUND,
342
+ REST_FOREIGN_KEY_VIOLATION
343
+ ],
354
344
  handler: async (c, route) => {
355
345
  const { name, id } = get_route_params(c);
356
346
  // Same allowlist gate and masking as the detail route — an