@fuzdev/fuz_app 0.182.0 → 0.183.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 (191) hide show
  1. package/README.md +2 -0
  2. package/dist/actions/CLAUDE.md +4 -4
  3. package/dist/auth/CLAUDE.md +58 -34
  4. package/dist/auth/account_routes.d.ts +5 -3
  5. package/dist/auth/account_routes.d.ts.map +1 -1
  6. package/dist/auth/account_routes.js +71 -66
  7. package/dist/auth/admin_actions.d.ts.map +1 -1
  8. package/dist/auth/admin_actions.js +22 -17
  9. package/dist/auth/audit_emitter.d.ts +75 -84
  10. package/dist/auth/audit_emitter.d.ts.map +1 -1
  11. package/dist/auth/audit_emitter.js +83 -71
  12. package/dist/auth/audit_log_schema.d.ts +10 -5
  13. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  14. package/dist/auth/audit_log_schema.js +22 -6
  15. package/dist/auth/bootstrap_account.d.ts +31 -13
  16. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  17. package/dist/auth/bootstrap_account.js +34 -15
  18. package/dist/auth/bootstrap_routes.d.ts +1 -1
  19. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  20. package/dist/auth/bootstrap_routes.js +7 -14
  21. package/dist/auth/deps.d.ts +8 -5
  22. package/dist/auth/deps.d.ts.map +1 -1
  23. package/dist/auth/deps.js +3 -2
  24. package/dist/auth/resolved_auth.d.ts +7 -7
  25. package/dist/auth/resolved_auth.d.ts.map +1 -1
  26. package/dist/auth/resolved_auth.js +4 -4
  27. package/dist/auth/role_grant_offer_actions.d.ts +25 -1
  28. package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
  29. package/dist/auth/role_grant_offer_actions.js +40 -33
  30. package/dist/auth/role_grant_offer_queries.d.ts +60 -4
  31. package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
  32. package/dist/auth/role_grant_offer_queries.js +79 -5
  33. package/dist/auth/role_grant_queries.d.ts +3 -52
  34. package/dist/auth/role_grant_queries.d.ts.map +1 -1
  35. package/dist/auth/role_grant_queries.js +5 -80
  36. package/dist/auth/self_service_role_actions.d.ts.map +1 -1
  37. package/dist/auth/self_service_role_actions.js +11 -22
  38. package/dist/auth/session_queries.d.ts +6 -3
  39. package/dist/auth/session_queries.d.ts.map +1 -1
  40. package/dist/auth/session_queries.js +20 -11
  41. package/dist/auth/signup_routes.d.ts.map +1 -1
  42. package/dist/auth/signup_routes.js +90 -38
  43. package/dist/db/sql_columns.d.ts +1 -1
  44. package/dist/db/sql_columns.js +1 -1
  45. package/dist/http/CLAUDE.md +15 -10
  46. package/dist/http/db_routes.d.ts +7 -22
  47. package/dist/http/db_routes.d.ts.map +1 -1
  48. package/dist/http/db_routes.js +72 -72
  49. package/dist/http/pending_effects.d.ts +42 -4
  50. package/dist/http/pending_effects.d.ts.map +1 -1
  51. package/dist/http/pending_effects.js +34 -4
  52. package/dist/server/app_server.d.ts +43 -2
  53. package/dist/server/app_server.d.ts.map +1 -1
  54. package/dist/server/app_server.js +57 -3
  55. package/dist/testing/CLAUDE.md +255 -786
  56. package/dist/testing/adversarial_404.d.ts +6 -1
  57. package/dist/testing/adversarial_404.d.ts.map +1 -1
  58. package/dist/testing/adversarial_404.js +38 -17
  59. package/dist/testing/app_server.d.ts +20 -140
  60. package/dist/testing/app_server.d.ts.map +1 -1
  61. package/dist/testing/app_server.js +45 -124
  62. package/dist/testing/audit_drift_guard.d.ts +11 -6
  63. package/dist/testing/audit_drift_guard.d.ts.map +1 -1
  64. package/dist/testing/audit_drift_guard.js +15 -8
  65. package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
  66. package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
  67. package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
  68. package/dist/testing/cross_backend/capabilities.d.ts +9 -6
  69. package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
  70. package/dist/testing/cross_backend/capabilities.js +11 -7
  71. package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
  72. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
  73. package/dist/testing/cross_backend/capability_mounts.js +423 -0
  74. package/dist/testing/cross_backend/cell_moderate.js +2 -2
  75. package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
  76. package/dist/testing/cross_backend/cell_relations.js +12 -11
  77. package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
  78. package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
  79. package/dist/testing/cross_backend/conformance_principal.js +283 -0
  80. package/dist/testing/cross_backend/conformance_table.d.ts +2 -50
  81. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  82. package/dist/testing/cross_backend/conformance_table.js +2 -270
  83. package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
  84. package/dist/testing/cross_backend/credential_deadline.js +2 -0
  85. package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
  86. package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
  87. package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
  88. package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
  89. package/dist/testing/cross_backend/db_state_diff.js +444 -0
  90. package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
  91. package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
  92. package/dist/testing/cross_backend/declared_skips.js +132 -0
  93. package/dist/testing/cross_backend/differential.d.ts +11 -2
  94. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  95. package/dist/testing/cross_backend/differential.js +35 -11
  96. package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
  97. package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
  98. package/dist/testing/cross_backend/differential_normalize.js +16 -0
  99. package/dist/testing/cross_backend/in_process_setup.d.ts +22 -12
  100. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  101. package/dist/testing/cross_backend/in_process_setup.js +151 -134
  102. package/dist/testing/cross_backend/login_security.d.ts +12 -0
  103. package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
  104. package/dist/testing/cross_backend/login_security.js +21 -4
  105. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
  106. package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
  107. package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
  108. package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
  109. package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
  110. package/dist/testing/cross_backend/revocation_drivers.js +18 -10
  111. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
  112. package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
  113. package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
  114. package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
  115. package/dist/testing/cross_backend/role_grant_participation.js +4 -4
  116. package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
  117. package/dist/testing/cross_backend/session_cap.d.ts +2 -2
  118. package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
  119. package/dist/testing/cross_backend/session_cap.js +22 -11
  120. package/dist/testing/cross_backend/setup.d.ts +31 -1
  121. package/dist/testing/cross_backend/setup.d.ts.map +1 -1
  122. package/dist/testing/cross_backend/setup.js +32 -1
  123. package/dist/testing/cross_backend/spine_suites.d.ts +123 -12
  124. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  125. package/dist/testing/cross_backend/spine_suites.js +454 -57
  126. package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
  127. package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
  128. package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
  129. package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
  130. package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
  131. package/dist/testing/cross_backend/sse_round_trip.js +123 -27
  132. package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
  133. package/dist/testing/cross_backend/testing_backdoor.js +4 -2
  134. package/dist/testing/cross_backend/testing_reset_actions.d.ts +59 -27
  135. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/testing_reset_actions.js +66 -42
  137. package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
  138. package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
  139. package/dist/testing/cross_backend/transport_composition.js +7 -3
  140. package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
  141. package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
  142. package/dist/testing/cross_backend/ws_round_trip.js +54 -8
  143. package/dist/testing/data_exposure.d.ts.map +1 -1
  144. package/dist/testing/data_exposure.js +3 -0
  145. package/dist/testing/db.d.ts +0 -32
  146. package/dist/testing/db.d.ts.map +1 -1
  147. package/dist/testing/db.js +0 -86
  148. package/dist/testing/db_entities.d.ts +14 -0
  149. package/dist/testing/db_entities.d.ts.map +1 -1
  150. package/dist/testing/db_entities.js +17 -0
  151. package/dist/testing/db_invariant_queries.d.ts +259 -0
  152. package/dist/testing/db_invariant_queries.d.ts.map +1 -0
  153. package/dist/testing/db_invariant_queries.js +400 -0
  154. package/dist/testing/db_invariants.d.ts +106 -0
  155. package/dist/testing/db_invariants.d.ts.map +1 -0
  156. package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
  157. package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
  158. package/dist/testing/db_invariants.gen.sql.js +13 -0
  159. package/dist/testing/db_invariants.js +141 -0
  160. package/dist/testing/db_invariants.sql +152 -0
  161. package/dist/testing/describe_db.d.ts +36 -0
  162. package/dist/testing/describe_db.d.ts.map +1 -0
  163. package/dist/testing/describe_db.js +71 -0
  164. package/dist/testing/integration.d.ts +6 -9
  165. package/dist/testing/integration.d.ts.map +1 -1
  166. package/dist/testing/integration.js +9 -13
  167. package/dist/testing/integration_helpers.d.ts +1 -1
  168. package/dist/testing/integration_helpers.d.ts.map +1 -1
  169. package/dist/testing/rate_limiting.d.ts +1 -1
  170. package/dist/testing/rate_limiting.d.ts.map +1 -1
  171. package/dist/testing/rate_limiting.js +3 -2
  172. package/dist/testing/role_grant_helpers.d.ts +1 -1
  173. package/dist/testing/role_grant_helpers.d.ts.map +1 -1
  174. package/dist/testing/round_trip.d.ts.map +1 -1
  175. package/dist/testing/round_trip.js +3 -0
  176. package/dist/testing/rpc_attack_surface.d.ts +8 -6
  177. package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
  178. package/dist/testing/rpc_attack_surface.js +69 -6
  179. package/dist/testing/rpc_round_trip.d.ts +1 -1
  180. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  181. package/dist/testing/rpc_round_trip.js +3 -0
  182. package/dist/testing/sse_round_trip.d.ts +1 -1
  183. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  184. package/dist/testing/sse_round_trip.js +13 -4
  185. package/dist/testing/stubs.d.ts +4 -2
  186. package/dist/testing/stubs.d.ts.map +1 -1
  187. package/dist/testing/stubs.js +10 -5
  188. package/dist/testing/test_app.d.ts +166 -0
  189. package/dist/testing/test_app.d.ts.map +1 -0
  190. package/dist/testing/test_app.js +124 -0
  191. package/package.json +1 -1
@@ -5,8 +5,8 @@
5
5
  * by their timing contract:
6
6
  *
7
7
  * - `pending_effects: Array<Promise<void>>` — eager. Producers push pool
8
- * writes that are already in flight (audit emits, session-touch UPDATE,
9
- * api-token usage tracking). The pool write is rollback-resilient by
8
+ * writes that are already in flight (failure audit rows, session-touch
9
+ * UPDATE, api-token usage tracking). The pool write is rollback-resilient by
10
10
  * virtue of running outside the request transaction; pushing the
11
11
  * in-flight handle lets test mode (`await_pending_effects: true`) await
12
12
  * it.
@@ -33,6 +33,11 @@
33
33
  * ambiguous at the call site. With separate queues, the field name is
34
34
  * the contract.
35
35
  *
36
+ * A handler that opens its own transaction (a `transaction: false` route)
37
+ * runs it through `transaction_with_post_commit_rollback`, which discards
38
+ * what that transaction queued when it rolls back, even when the handler
39
+ * catches the failure and answers normally.
40
+ *
36
41
  * Both `RouteContext` (HTTP routes) and `ActionContext` (RPC + WS
37
42
  * actions) carry both queues by convention, so this module stays in
38
43
  * `http/` (every transport depends on it).
@@ -40,6 +45,7 @@
40
45
  * @module
41
46
  */
42
47
  import type { Logger } from '@fuzdev/fuz_util/log.ts';
48
+ import type { Db } from '../db/db.js';
43
49
  /**
44
50
  * Context passed to `on_effect_error` when an eager pending effect rejects.
45
51
  */
@@ -102,8 +108,10 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
102
108
  *
103
109
  * Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
104
110
  * action dispatcher (`actions/perform_action.ts`, the RPC + WS path) — wrap
105
- * their handler call in this so the discard contract lives in one place. The
106
- * Rust `fuz_actions` spine pins the same contract.
111
+ * their handler call in this so the discard contract lives in one place, and a
112
+ * handler that opens its own transaction runs it through
113
+ * `transaction_with_post_commit_rollback`, the same truncation around just
114
+ * that transaction. The Rust `fuz_actions` spine pins the same contract.
107
115
  *
108
116
  * `post_commit_effects` is `undefined` when a handler runs without the
109
117
  * app-server pending-effects middleware (bare route / dispatch harnesses):
@@ -114,6 +122,36 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
114
122
  * @mutates `post_commit_effects` - truncated to its pre-dispatch depth on throw
115
123
  */
116
124
  export declare const dispatch_with_post_commit_rollback: <T>(post_commit_effects: Array<() => void | Promise<void>> | undefined, dispatch: () => T | Promise<T>) => Promise<Awaited<T>>;
125
+ /**
126
+ * A request's `db` and its two side-effect queues — what a handler that opens
127
+ * its own transaction hands `transaction_with_post_commit_rollback`, and what
128
+ * that transaction's callback gets back with `db` swapped for the transaction.
129
+ * `RouteContext` and `ActionContext` satisfy it, and so does the callback's
130
+ * context, so either can be passed to `AuditEmitter.emit`.
131
+ */
132
+ export interface RequestEffectsContext extends EmitAfterCommitContext {
133
+ db: Db;
134
+ pending_effects: Array<Promise<void>>;
135
+ }
136
+ /**
137
+ * Run `fn` in a transaction a handler opens on its own `db` (a route with
138
+ * `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
139
+ * connection), discarding the `post_commit_effects` `fn` queued when that
140
+ * transaction rolls back.
141
+ *
142
+ * `dispatch_with_post_commit_rollback` discards them only when the handler
143
+ * throws; a handler that catches its own transaction's failure and answers a
144
+ * refusal (signup's classified conflicts, bootstrap's undeletable token file)
145
+ * would otherwise leave a queued fan-out — a success row's announcement — to
146
+ * fire for writes that rolled back. The truncation is the same: back to the
147
+ * depth before the transaction, the error rethrown unchanged.
148
+ *
149
+ * @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
150
+ * @param fn - the transaction's work, given `ctx` with `db` the transaction
151
+ * @returns what `fn` returns, once the transaction has committed
152
+ * @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
153
+ */
154
+ export declare const transaction_with_post_commit_rollback: <T>(ctx: RequestEffectsContext, fn: (tx_ctx: RequestEffectsContext) => Promise<T>) => Promise<Awaited<T>>;
117
155
  /**
118
156
  * Drain an eager `pending_effects` queue: `Promise.allSettled` the
119
157
  * in-flight handles, route every rejection through `log.error`, and
@@ -1 +1 @@
1
- {"version":3,"file":"pending_effects.d.ts","sourceRoot":"","sources":["../../src/lib/http/pending_effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;CACb;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACtC,mBAAmB,EAAE,KAAK,C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C,MAAM,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC,CAAC,KAC/C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CASnB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,GACjC,SAAS,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EACrC,KAAK,MAAM,EACX,eAAe,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KACtC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,aAAa,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAClD,KAAK,MAAM,KACT,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,qBAAqB,GACjC,iBAAiB,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAC7C,qBAAqB,aAAa,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAC9D,KAAK,MAAM,EACX,eAAe,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KACtC,OAAO,CAAC,IAAI,CAKd,CAAC"}
@@ -5,8 +5,8 @@
5
5
  * by their timing contract:
6
6
  *
7
7
  * - `pending_effects: Array<Promise<void>>` — eager. Producers push pool
8
- * writes that are already in flight (audit emits, session-touch UPDATE,
9
- * api-token usage tracking). The pool write is rollback-resilient by
8
+ * writes that are already in flight (failure audit rows, session-touch
9
+ * UPDATE, api-token usage tracking). The pool write is rollback-resilient by
10
10
  * virtue of running outside the request transaction; pushing the
11
11
  * in-flight handle lets test mode (`await_pending_effects: true`) await
12
12
  * it.
@@ -33,6 +33,11 @@
33
33
  * ambiguous at the call site. With separate queues, the field name is
34
34
  * the contract.
35
35
  *
36
+ * A handler that opens its own transaction (a `transaction: false` route)
37
+ * runs it through `transaction_with_post_commit_rollback`, which discards
38
+ * what that transaction queued when it rolls back, even when the handler
39
+ * catches the failure and answers normally.
40
+ *
36
41
  * Both `RouteContext` (HTTP routes) and `ActionContext` (RPC + WS
37
42
  * actions) carry both queues by convention, so this module stays in
38
43
  * `http/` (every transport depends on it).
@@ -83,8 +88,10 @@ export const emit_after_commit = (ctx, fn) => {
83
88
  *
84
89
  * Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
85
90
  * action dispatcher (`actions/perform_action.ts`, the RPC + WS path) — wrap
86
- * their handler call in this so the discard contract lives in one place. The
87
- * Rust `fuz_actions` spine pins the same contract.
91
+ * their handler call in this so the discard contract lives in one place, and a
92
+ * handler that opens its own transaction runs it through
93
+ * `transaction_with_post_commit_rollback`, the same truncation around just
94
+ * that transaction. The Rust `fuz_actions` spine pins the same contract.
88
95
  *
89
96
  * `post_commit_effects` is `undefined` when a handler runs without the
90
97
  * app-server pending-effects middleware (bare route / dispatch harnesses):
@@ -105,6 +112,29 @@ export const dispatch_with_post_commit_rollback = async (post_commit_effects, di
105
112
  throw err;
106
113
  }
107
114
  };
115
+ /**
116
+ * Run `fn` in a transaction a handler opens on its own `db` (a route with
117
+ * `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
118
+ * connection), discarding the `post_commit_effects` `fn` queued when that
119
+ * transaction rolls back.
120
+ *
121
+ * `dispatch_with_post_commit_rollback` discards them only when the handler
122
+ * throws; a handler that catches its own transaction's failure and answers a
123
+ * refusal (signup's classified conflicts, bootstrap's undeletable token file)
124
+ * would otherwise leave a queued fan-out — a success row's announcement — to
125
+ * fire for writes that rolled back. The truncation is the same: back to the
126
+ * depth before the transaction, the error rethrown unchanged.
127
+ *
128
+ * @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
129
+ * @param fn - the transaction's work, given `ctx` with `db` the transaction
130
+ * @returns what `fn` returns, once the transaction has committed
131
+ * @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
132
+ */
133
+ export const transaction_with_post_commit_rollback = (ctx, fn) => dispatch_with_post_commit_rollback(ctx.post_commit_effects, () => ctx.db.transaction((tx) => fn({
134
+ db: tx,
135
+ pending_effects: ctx.pending_effects,
136
+ post_commit_effects: ctx.post_commit_effects
137
+ })));
108
138
  /**
109
139
  * Drain an eager `pending_effects` queue: `Promise.allSettled` the
110
140
  * in-flight handles, route every rejection through `log.error`, and
@@ -10,6 +10,7 @@
10
10
  import { Hono, type Context } from 'hono';
11
11
  import type { UpgradeWebSocket } from 'hono/ws';
12
12
  import type { AnySchema } from '@fuzdev/fuz_schema/schema.ts';
13
+ import type { Logger } from '@fuzdev/fuz_util/log.ts';
13
14
  import { type SessionOptions } from '../auth/session_cookie.js';
14
15
  import type { BootstrapTokenStore } from '../auth/bootstrap_token_store.js';
15
16
  import { type EventSpec } from '../realtime/sse.js';
@@ -29,6 +30,7 @@ import { type EffectErrorContext } from '../http/pending_effects.js';
29
30
  import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
30
31
  import type { ConnectionRegistry } from '../actions/connection_registry.js';
31
32
  import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
33
+ import type { AuditEmitter } from '../auth/audit_emitter.js';
32
34
  /**
33
35
  * Bootstrap configuration for `AppServerOptions.bootstrap`.
34
36
  *
@@ -423,6 +425,15 @@ export interface AppServerOptions {
423
425
  * Default `false` (production: true fire-and-forget).
424
426
  */
425
427
  await_pending_effects?: boolean;
428
+ /**
429
+ * How long `AppServer.close` waits for the effects still in flight — each
430
+ * request's unflushed `pending_effects` (failure audit rows, the session
431
+ * touch, token usage) and every pool write of `deps.audit` — before it
432
+ * closes the database. What is still running then is given up on and
433
+ * logged. Default `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive
434
+ * number of ms.
435
+ */
436
+ shutdown_drain_timeout_ms?: number;
426
437
  /**
427
438
  * Called when an eager pending effect rejects, on HTTP requests and on the
428
439
  * frames of every WS endpoint the server mounts, in either
@@ -474,7 +485,12 @@ export interface AppServer {
474
485
  * is left closing, so an upgrade or stream that registers afterward is
475
486
  * born closed — refused at once rather than outliving the server — and
476
487
  * a closed registry hosts no other server
477
- * 3. release what assembly acquired, last acquired first: remove the
488
+ * 3. wait for the effects still in flight — the unflushed
489
+ * `pending_effects` of requests already answered (failure audit rows,
490
+ * the session touch, token usage; production does not hold a response
491
+ * for them) and every pool write of `deps.audit` — bounded by
492
+ * `shutdown_drain_timeout_ms`, logging what it gives up on
493
+ * 4. release what assembly acquired, last acquired first: remove the
478
494
  * audit listeners `create_app_server` registered on `deps.audit` (the
479
495
  * revocation guard, the audit-log SSE listener), the members it added
480
496
  * to `deps.connection_closer` (each mounted connection registry, the
@@ -486,7 +502,7 @@ export interface AppServer {
486
502
  * were before assembly, so a failed assembly can be retried on the same
487
503
  * backend, and a backend whose `close` you own (a test harness) can
488
504
  * host another server
489
- * 4. close the database connection (`AppBackend.close`)
505
+ * 5. close the database connection (`AppBackend.close`)
490
506
  *
491
507
  * Idempotent: a second call settles with the first one's outcome (a failed
492
508
  * close is not retried), and concurrent calls share one shutdown.
@@ -522,6 +538,12 @@ export declare const require_audit_sse: (source: {
522
538
  * `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
523
539
  */
524
540
  export declare const DEFAULT_BODY_LIMIT_BYTES: number;
541
+ /**
542
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
543
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
544
+ * `DEFAULT_DRAIN_TIMEOUT`.
545
+ */
546
+ export declare const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10000;
525
547
  /**
526
548
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
527
549
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -675,5 +697,24 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
675
697
  * @throws Error from any assembly step, after releasing what assembly acquired
676
698
  */
677
699
  export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
700
+ /**
701
+ * What `drain_effects_on_shutdown` gave up on at its bound, each counted on
702
+ * its own: a request flush still waiting on its audit writes has those
703
+ * writes counted in `audit_writes` too, so the two are not summed.
704
+ */
705
+ export interface ShutdownDrainGivenUp {
706
+ /** Request flushes still running. */
707
+ request_flushes: number;
708
+ /** Pool writes of the audit emitter still in flight. */
709
+ audit_writes: number;
710
+ }
711
+ /**
712
+ * Wait for the request flushes in flight and then the audit emitter's pool
713
+ * writes, until none is left or `timeout_ms` passes — then log an error naming
714
+ * what was given up on. Never rejects.
715
+ *
716
+ * @returns what was given up on, both counts `0` when everything settled
717
+ */
718
+ export declare const drain_effects_on_shutdown: (inflight_flushes: ReadonlySet<Promise<void>>, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
678
719
  export {};
679
720
  //# sourceMappingURL=app_server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app_server.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,EAKN,KAAK,cAAc,EACnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIN,KAAK,WAAW,EAChB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACN,WAAW,EAMX,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EA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
72
72
  export const DEFAULT_BODY_LIMIT_BYTES = 1024 * 1024;
73
+ /**
74
+ * Default bound on `AppServer.close`'s wait for the effects still in flight
75
+ * (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
76
+ * `DEFAULT_DRAIN_TIMEOUT`.
77
+ */
78
+ export const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10_000;
73
79
  /**
74
80
  * Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
75
81
  * is built from under `rate_limiters: 'enforced'` and the name its
@@ -235,6 +241,39 @@ export const create_app_server = async (options) => {
235
241
  throw error;
236
242
  }
237
243
  };
244
+ /**
245
+ * Wait for the request flushes in flight and then the audit emitter's pool
246
+ * writes, until none is left or `timeout_ms` passes — then log an error naming
247
+ * what was given up on. Never rejects.
248
+ *
249
+ * @returns what was given up on, both counts `0` when everything settled
250
+ */
251
+ export const drain_effects_on_shutdown = async (inflight_flushes, audit, timeout_ms, log) => {
252
+ const drain = async () => {
253
+ // wait for zero: a flush's post-commit thunk can start another write
254
+ while (inflight_flushes.size > 0)
255
+ await Promise.allSettled(inflight_flushes);
256
+ await audit.drain_inflight();
257
+ };
258
+ let timer;
259
+ const timed_out = new Promise((resolve) => {
260
+ timer = setTimeout(resolve, timeout_ms);
261
+ });
262
+ try {
263
+ await Promise.race([drain(), timed_out]);
264
+ }
265
+ finally {
266
+ clearTimeout(timer);
267
+ }
268
+ const given_up = {
269
+ request_flushes: inflight_flushes.size,
270
+ audit_writes: audit.inflight_count()
271
+ };
272
+ if (given_up.request_flushes === 0 && given_up.audit_writes === 0)
273
+ return given_up;
274
+ log.error(`create_app_server: shutdown gave up after ${timeout_ms}ms on effects still running — ${given_up.request_flushes} request flush(es), ${given_up.audit_writes} audit row write(s)`);
275
+ return given_up;
276
+ };
238
277
  /**
239
278
  * Run `releases` last-first and empty it. Each runs in its own `try`, so one
240
279
  * that throws is logged and the rest still run.
@@ -293,6 +332,10 @@ const assemble_app_server = async (options, releases) => {
293
332
  const body_limit_spec = options.max_body_size === null
294
333
  ? null
295
334
  : create_body_limit_middleware_spec(options.max_body_size ?? DEFAULT_BODY_LIMIT_BYTES);
335
+ const shutdown_drain_timeout_ms = options.shutdown_drain_timeout_ms ?? DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS;
336
+ if (!(shutdown_drain_timeout_ms > 0 && Number.isFinite(shutdown_drain_timeout_ms))) {
337
+ throw new Error(`create_app_server: shutdown_drain_timeout_ms must be a positive number of ms, got ${shutdown_drain_timeout_ms}`);
338
+ }
296
339
  // Rate limiters — the ones built here are the server's to dispose, on
297
340
  // close or when assembly fails.
298
341
  const { mode: rate_limiter_mode, limiters: rate_limiters, built: built_rate_limiters } = resolve_rate_limiters(options);
@@ -559,6 +602,10 @@ const assemble_app_server = async (options, releases) => {
559
602
  // writes to settle — a revocation's connection close must not sit behind
560
603
  // a slow audit INSERT.
561
604
  const on_effect_error = options.on_effect_error;
605
+ // The flushes production leaves running past the response — what
606
+ // shutdown waits on before the database closes. Each removes itself as it
607
+ // settles; none rejects.
608
+ const inflight_flushes = new Set();
562
609
  app.use('*', async (c, next) => {
563
610
  c.set('pending_effects', []);
564
611
  c.set('post_commit_effects', []);
@@ -575,10 +622,13 @@ const assemble_app_server = async (options, releases) => {
575
622
  path: c.req.path
576
623
  };
577
624
  const flushed = flush_request_effects(eager, deferred, log, on_effect_error ? (reason) => on_effect_error(reason, error_ctx) : undefined);
578
- if (options.await_pending_effects)
625
+ if (options.await_pending_effects) {
579
626
  await flushed;
580
- else
581
- void flushed;
627
+ }
628
+ else {
629
+ inflight_flushes.add(flushed);
630
+ void flushed.then(() => inflight_flushes.delete(flushed));
631
+ }
582
632
  }
583
633
  }
584
634
  });
@@ -675,6 +725,10 @@ const assemble_app_server = async (options, releases) => {
675
725
  catch (error) {
676
726
  log.error('create_app_server: closing live connections on shutdown failed:', error);
677
727
  }
728
+ // then the effects still in flight, so a failure row or a session touch
729
+ // a request already answered started is not lost to the closing pool —
730
+ // bounded, as the Rust spine's shutdown drain is
731
+ await drain_effects_on_shutdown(inflight_flushes, deps.audit, shutdown_drain_timeout_ms, log);
678
732
  // then what assembly acquired — the audit listeners and closer members
679
733
  // this server added, and the limiters it built
680
734
  run_releases(releases, log, 'shutdown');