@fuzdev/fuz_app 0.182.0 → 0.184.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/actions/CLAUDE.md +535 -1223
- package/dist/actions/action_codegen.d.ts +1 -1
- package/dist/actions/action_codegen.d.ts.map +1 -1
- package/dist/actions/action_codegen.js +3 -2
- package/dist/actions/connection_closer.d.ts +11 -9
- package/dist/actions/connection_closer.d.ts.map +1 -1
- package/dist/actions/connection_closer.js +11 -9
- package/dist/actions/frontend_rpc_client.d.ts +1 -1
- package/dist/actions/register_action_ws.d.ts +14 -1
- package/dist/actions/register_action_ws.d.ts.map +1 -1
- package/dist/actions/register_action_ws.js +2 -1
- package/dist/actions/ws_socket_session.d.ts +9 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +43 -19
- package/dist/auth/CLAUDE.md +430 -1024
- package/dist/auth/account_queries.d.ts +1 -1
- package/dist/auth/account_queries.js +1 -1
- package/dist/auth/account_routes.d.ts +9 -8
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +78 -75
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +32 -28
- package/dist/auth/api_token.d.ts +20 -3
- package/dist/auth/api_token.d.ts.map +1 -1
- package/dist/auth/api_token.js +28 -9
- package/dist/auth/api_token_queries.d.ts +2 -2
- package/dist/auth/api_token_queries.js +2 -2
- package/dist/auth/audit_emitter.d.ts +75 -84
- package/dist/auth/audit_emitter.d.ts.map +1 -1
- package/dist/auth/audit_emitter.js +83 -71
- package/dist/auth/audit_log_schema.d.ts +25 -14
- package/dist/auth/audit_log_schema.d.ts.map +1 -1
- package/dist/auth/audit_log_schema.js +23 -8
- package/dist/auth/auth_guard_resolver.d.ts +1 -1
- package/dist/auth/auth_guard_resolver.js +1 -1
- package/dist/auth/bearer_auth.d.ts +2 -5
- package/dist/auth/bearer_auth.d.ts.map +1 -1
- package/dist/auth/bearer_auth.js +4 -13
- package/dist/auth/bootstrap_account.d.ts +42 -26
- package/dist/auth/bootstrap_account.d.ts.map +1 -1
- package/dist/auth/bootstrap_account.js +36 -19
- package/dist/auth/bootstrap_routes.d.ts +20 -21
- package/dist/auth/bootstrap_routes.d.ts.map +1 -1
- package/dist/auth/bootstrap_routes.js +26 -31
- package/dist/auth/bootstrap_token_store.d.ts +3 -4
- package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
- package/dist/auth/bootstrap_token_store.js +1 -1
- package/dist/auth/daemon_token.d.ts +5 -1
- package/dist/auth/daemon_token.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.d.ts +12 -8
- package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
- package/dist/auth/daemon_token_middleware.js +15 -21
- package/dist/auth/deps.d.ts +19 -5
- package/dist/auth/deps.d.ts.map +1 -1
- package/dist/auth/deps.js +3 -2
- package/dist/auth/invite_queries.d.ts +51 -3
- package/dist/auth/invite_queries.d.ts.map +1 -1
- package/dist/auth/invite_queries.js +81 -6
- package/dist/auth/invite_schema.d.ts +2 -1
- package/dist/auth/invite_schema.d.ts.map +1 -1
- package/dist/auth/middleware.d.ts +2 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +3 -3
- package/dist/auth/request_context.d.ts +3 -3
- package/dist/auth/request_context.js +3 -3
- package/dist/auth/resolved_auth.d.ts +7 -7
- package/dist/auth/resolved_auth.d.ts.map +1 -1
- package/dist/auth/resolved_auth.js +4 -4
- package/dist/auth/role_grant_offer_actions.d.ts +27 -3
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +42 -35
- package/dist/auth/role_grant_offer_queries.d.ts +60 -4
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +79 -5
- package/dist/auth/role_grant_queries.d.ts +3 -52
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +5 -80
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +11 -22
- package/dist/auth/session_cookie.d.ts +82 -174
- package/dist/auth/session_cookie.d.ts.map +1 -1
- package/dist/auth/session_cookie.js +80 -130
- package/dist/auth/session_middleware.d.ts +8 -17
- package/dist/auth/session_middleware.d.ts.map +1 -1
- package/dist/auth/session_middleware.js +14 -23
- package/dist/auth/session_queries.d.ts +15 -17
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -20
- package/dist/auth/signup_routes.d.ts.map +1 -1
- package/dist/auth/signup_routes.js +93 -43
- package/dist/db/CLAUDE.md +5 -3
- package/dist/db/sql_columns.d.ts +1 -1
- package/dist/db/sql_columns.js +1 -1
- package/dist/dev/setup.d.ts +3 -1
- package/dist/dev/setup.d.ts.map +1 -1
- package/dist/dev/setup.js +3 -1
- package/dist/http/CLAUDE.md +315 -763
- package/dist/http/db_routes.d.ts +8 -23
- package/dist/http/db_routes.d.ts.map +1 -1
- package/dist/http/db_routes.js +73 -73
- package/dist/http/origin.d.ts +7 -8
- package/dist/http/origin.d.ts.map +1 -1
- package/dist/http/origin.js +7 -8
- package/dist/http/pending_effects.d.ts +118 -6
- package/dist/http/pending_effects.d.ts.map +1 -1
- package/dist/http/pending_effects.js +114 -6
- package/dist/http/route_result.d.ts +1 -1
- package/dist/http/route_spec.d.ts +14 -11
- package/dist/http/route_spec.d.ts.map +1 -1
- package/dist/realtime/sse.d.ts +4 -23
- package/dist/realtime/sse.d.ts.map +1 -1
- package/dist/realtime/sse.js +4 -25
- package/dist/server/app_backend.d.ts +4 -5
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +3 -1
- package/dist/server/app_server.d.ts +80 -16
- package/dist/server/app_server.d.ts.map +1 -1
- package/dist/server/app_server.js +113 -31
- package/dist/server/app_server_context.d.ts +1 -2
- package/dist/server/app_server_context.d.ts.map +1 -1
- package/dist/server/env.js +2 -2
- package/dist/testing/CLAUDE.md +265 -796
- package/dist/testing/admin_integration.d.ts +2 -3
- package/dist/testing/admin_integration.d.ts.map +1 -1
- package/dist/testing/admin_integration.js +3 -3
- package/dist/testing/adversarial_404.d.ts +6 -1
- package/dist/testing/adversarial_404.d.ts.map +1 -1
- package/dist/testing/adversarial_404.js +38 -17
- package/dist/testing/app_server.d.ts +23 -148
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +53 -131
- package/dist/testing/attack_surface.d.ts +1 -1
- package/dist/testing/attack_surface.d.ts.map +1 -1
- package/dist/testing/audit_completeness.d.ts +2 -3
- package/dist/testing/audit_completeness.d.ts.map +1 -1
- package/dist/testing/audit_completeness.js +1 -1
- package/dist/testing/audit_drift_guard.d.ts +11 -6
- package/dist/testing/audit_drift_guard.d.ts.map +1 -1
- package/dist/testing/audit_drift_guard.js +15 -8
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts +12 -9
- package/dist/testing/cross_backend/audit_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/audit_cross_helpers.js +13 -14
- package/dist/testing/cross_backend/capabilities.d.ts +9 -6
- package/dist/testing/cross_backend/capabilities.d.ts.map +1 -1
- package/dist/testing/cross_backend/capabilities.js +11 -7
- package/dist/testing/cross_backend/capability_mounts.d.ts +103 -0
- package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -0
- package/dist/testing/cross_backend/capability_mounts.js +428 -0
- package/dist/testing/cross_backend/cell_moderate.js +2 -2
- package/dist/testing/cross_backend/cell_relations.d.ts.map +1 -1
- package/dist/testing/cross_backend/cell_relations.js +12 -11
- package/dist/testing/cross_backend/conformance_principal.d.ts +54 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -0
- package/dist/testing/cross_backend/conformance_principal.js +283 -0
- package/dist/testing/cross_backend/conformance_table.d.ts +7 -56
- package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_table.js +6 -274
- package/dist/testing/cross_backend/cookie_attributes.js +1 -1
- package/dist/testing/cross_backend/credential_deadline.d.ts.map +1 -1
- package/dist/testing/cross_backend/credential_deadline.js +2 -0
- package/dist/testing/cross_backend/credential_wire.d.ts +1 -1
- package/dist/testing/cross_backend/credential_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/db_state_diff.d.ts +72 -0
- package/dist/testing/cross_backend/db_state_diff.d.ts.map +1 -0
- package/dist/testing/cross_backend/db_state_diff.js +444 -0
- package/dist/testing/cross_backend/declared_skips.d.ts +68 -0
- package/dist/testing/cross_backend/declared_skips.d.ts.map +1 -0
- package/dist/testing/cross_backend/declared_skips.js +132 -0
- package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
- package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
- package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_spine_surface.js +4 -9
- package/dist/testing/cross_backend/differential.d.ts +13 -5
- package/dist/testing/cross_backend/differential.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential.js +35 -11
- package/dist/testing/cross_backend/differential_normalize.d.ts +12 -0
- package/dist/testing/cross_backend/differential_normalize.d.ts.map +1 -1
- package/dist/testing/cross_backend/differential_normalize.js +16 -0
- package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
- package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
- package/dist/testing/cross_backend/full_spine_mount.js +45 -4
- package/dist/testing/cross_backend/in_process_setup.d.ts +28 -19
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +156 -142
- package/dist/testing/cross_backend/login_security.d.ts +12 -0
- package/dist/testing/cross_backend/login_security.d.ts.map +1 -1
- package/dist/testing/cross_backend/login_security.js +21 -4
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts +0 -2
- package/dist/testing/cross_backend/request_target_conformance_wire.d.ts.map +1 -1
- package/dist/testing/cross_backend/request_target_conformance_wire.js +3 -1
- package/dist/testing/cross_backend/revocation_drivers.d.ts +18 -5
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +18 -10
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts +1 -1
- package/dist/testing/cross_backend/role_grant_cross_helpers.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.d.ts.map +1 -1
- package/dist/testing/cross_backend/role_grant_offer_lifecycle.js +33 -1
- package/dist/testing/cross_backend/role_grant_participation.js +4 -4
- package/dist/testing/cross_backend/rpc_adversarial.js +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
- package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts +2 -2
- package/dist/testing/cross_backend/session_cap.d.ts.map +1 -1
- package/dist/testing/cross_backend/session_cap.js +22 -11
- package/dist/testing/cross_backend/setup.d.ts +32 -2
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +32 -1
- package/dist/testing/cross_backend/spine_suites.d.ts +125 -15
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +459 -62
- package/dist/testing/cross_backend/spine_surface_constants.d.ts +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_surface_constants.js +1 -0
- package/dist/testing/cross_backend/sse_round_trip.d.ts +9 -1
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +123 -27
- package/dist/testing/cross_backend/standard.d.ts +2 -3
- package/dist/testing/cross_backend/standard.d.ts.map +1 -1
- package/dist/testing/cross_backend/standard.js +3 -3
- package/dist/testing/cross_backend/testing_backdoor.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_backdoor.js +4 -2
- package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
- package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_credential_read.js +12 -12
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +84 -47
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +95 -63
- package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_core.js +2 -3
- package/dist/testing/cross_backend/transport_composition.d.ts +1 -1
- package/dist/testing/cross_backend/transport_composition.d.ts.map +1 -1
- package/dist/testing/cross_backend/transport_composition.js +7 -3
- package/dist/testing/cross_backend/ws_round_trip.d.ts +5 -0
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +54 -8
- package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
- package/dist/testing/daemon_token_rotation.js +2 -3
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +3 -0
- package/dist/testing/db.d.ts +0 -32
- package/dist/testing/db.d.ts.map +1 -1
- package/dist/testing/db.js +0 -86
- package/dist/testing/db_entities.d.ts +14 -0
- package/dist/testing/db_entities.d.ts.map +1 -1
- package/dist/testing/db_entities.js +17 -0
- package/dist/testing/db_invariant_queries.d.ts +259 -0
- package/dist/testing/db_invariant_queries.d.ts.map +1 -0
- package/dist/testing/db_invariant_queries.js +400 -0
- package/dist/testing/db_invariants.d.ts +106 -0
- package/dist/testing/db_invariants.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.d.ts +11 -0
- package/dist/testing/db_invariants.gen.sql.d.ts.map +1 -0
- package/dist/testing/db_invariants.gen.sql.js +13 -0
- package/dist/testing/db_invariants.js +141 -0
- package/dist/testing/db_invariants.sql +152 -0
- package/dist/testing/describe_db.d.ts +36 -0
- package/dist/testing/describe_db.d.ts.map +1 -0
- package/dist/testing/describe_db.js +71 -0
- package/dist/testing/integration.d.ts +8 -12
- package/dist/testing/integration.d.ts.map +1 -1
- package/dist/testing/integration.js +13 -17
- package/dist/testing/integration_helpers.d.ts +1 -1
- package/dist/testing/integration_helpers.d.ts.map +1 -1
- package/dist/testing/rate_limiting.d.ts +3 -4
- package/dist/testing/rate_limiting.d.ts.map +1 -1
- package/dist/testing/rate_limiting.js +6 -5
- package/dist/testing/role_grant_helpers.d.ts +1 -1
- package/dist/testing/role_grant_helpers.d.ts.map +1 -1
- package/dist/testing/round_trip.d.ts.map +1 -1
- package/dist/testing/round_trip.js +3 -0
- package/dist/testing/rpc_attack_surface.d.ts +8 -6
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +69 -6
- package/dist/testing/rpc_helpers.d.ts +1 -2
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +3 -3
- package/dist/testing/rpc_round_trip.d.ts +3 -4
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +4 -1
- package/dist/testing/sse_round_trip.d.ts +3 -4
- package/dist/testing/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/sse_round_trip.js +15 -6
- package/dist/testing/stubs.d.ts +9 -8
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +20 -13
- package/dist/testing/test_app.d.ts +168 -0
- package/dist/testing/test_app.d.ts.map +1 -0
- package/dist/testing/test_app.js +123 -0
- package/dist/testing/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/ws_round_trip.js +3 -0
- package/dist/ui/ui_format.d.ts.map +1 -1
- package/dist/ui/ui_format.js +1 -2
- 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
|
|
9
|
-
*
|
|
8
|
+
* writes that are already in flight (failure audit rows, api-token usage
|
|
9
|
+
* 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.
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* Producers go through `emit_after_commit(ctx, fn)`; the flush
|
|
15
15
|
* middleware is the only site that ever invokes the thunk, and it does
|
|
16
16
|
* so after the request handler (and its wrapping `db.transaction`)
|
|
17
|
-
* returns. Used for WS sends
|
|
17
|
+
* returns. Used for WS sends, a revocation's connection closes, a success
|
|
18
|
+
* audit row's listener fan-out, and any work that must observe a committed
|
|
18
19
|
* transaction.
|
|
19
20
|
*
|
|
20
21
|
* **Discard on rollback.** A `post_commit_effects` thunk is discarded if the
|
|
@@ -33,6 +34,11 @@
|
|
|
33
34
|
* ambiguous at the call site. With separate queues, the field name is
|
|
34
35
|
* the contract.
|
|
35
36
|
*
|
|
37
|
+
* A handler that opens its own transaction (a `transaction: false` route)
|
|
38
|
+
* runs it through `transaction_with_post_commit_rollback`, which discards
|
|
39
|
+
* what that transaction queued when it rolls back, even when the handler
|
|
40
|
+
* catches the failure and answers normally.
|
|
41
|
+
*
|
|
36
42
|
* Both `RouteContext` (HTTP routes) and `ActionContext` (RPC + WS
|
|
37
43
|
* actions) carry both queues by convention, so this module stays in
|
|
38
44
|
* `http/` (every transport depends on it).
|
|
@@ -83,8 +89,10 @@ export const emit_after_commit = (ctx, fn) => {
|
|
|
83
89
|
*
|
|
84
90
|
* Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
|
|
85
91
|
* 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
|
|
87
|
-
*
|
|
92
|
+
* their handler call in this so the discard contract lives in one place, and a
|
|
93
|
+
* handler that opens its own transaction runs it through
|
|
94
|
+
* `transaction_with_post_commit_rollback`, the same truncation around just
|
|
95
|
+
* that transaction. The Rust `fuz_actions` spine pins the same contract.
|
|
88
96
|
*
|
|
89
97
|
* `post_commit_effects` is `undefined` when a handler runs without the
|
|
90
98
|
* app-server pending-effects middleware (bare route / dispatch harnesses):
|
|
@@ -105,6 +113,29 @@ export const dispatch_with_post_commit_rollback = async (post_commit_effects, di
|
|
|
105
113
|
throw err;
|
|
106
114
|
}
|
|
107
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* Run `fn` in a transaction a handler opens on its own `db` (a route with
|
|
118
|
+
* `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
|
|
119
|
+
* connection), discarding the `post_commit_effects` `fn` queued when that
|
|
120
|
+
* transaction rolls back.
|
|
121
|
+
*
|
|
122
|
+
* `dispatch_with_post_commit_rollback` discards them only when the handler
|
|
123
|
+
* throws; a handler that catches its own transaction's failure and answers a
|
|
124
|
+
* refusal (signup's classified conflicts, bootstrap's undeletable token file)
|
|
125
|
+
* would otherwise leave a queued fan-out — a success row's announcement — to
|
|
126
|
+
* fire for writes that rolled back. The truncation is the same: back to the
|
|
127
|
+
* depth before the transaction, the error rethrown unchanged.
|
|
128
|
+
*
|
|
129
|
+
* @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
|
|
130
|
+
* @param fn - the transaction's work, given `ctx` with `db` the transaction
|
|
131
|
+
* @returns what `fn` returns, once the transaction has committed
|
|
132
|
+
* @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
|
|
133
|
+
*/
|
|
134
|
+
export const transaction_with_post_commit_rollback = (ctx, fn) => dispatch_with_post_commit_rollback(ctx.post_commit_effects, () => ctx.db.transaction((tx) => fn({
|
|
135
|
+
db: tx,
|
|
136
|
+
pending_effects: ctx.pending_effects,
|
|
137
|
+
post_commit_effects: ctx.post_commit_effects
|
|
138
|
+
})));
|
|
108
139
|
/**
|
|
109
140
|
* Drain an eager `pending_effects` queue: `Promise.allSettled` the
|
|
110
141
|
* in-flight handles, route every rejection through `log.error`, and
|
|
@@ -173,7 +204,9 @@ export const flush_post_commit_effects = async (effects, log) => {
|
|
|
173
204
|
* that needs a write awaits it itself. Eager rejections are logged and passed
|
|
174
205
|
* to `on_rejection` (the server's `on_effect_error`). The caller picks whether
|
|
175
206
|
* to await the returned promise — HTTP awaits it in test mode only, WS awaits
|
|
176
|
-
* it per frame after the reply is sent
|
|
207
|
+
* it per frame after the reply is sent — and hands it to its request's
|
|
208
|
+
* `AcceptedRequest.finish` either way, so `AppServer.close` waits for it.
|
|
209
|
+
* Never rejects.
|
|
177
210
|
*
|
|
178
211
|
* @param pending_effects - the eager queue of in-flight pool writes
|
|
179
212
|
* @param post_commit_effects - the deferred thunks queued by `emit_after_commit`
|
|
@@ -186,3 +219,78 @@ export const flush_request_effects = async (pending_effects, post_commit_effects
|
|
|
186
219
|
await flush_pending_effects(pending_effects, log, on_rejection);
|
|
187
220
|
await deferred;
|
|
188
221
|
};
|
|
222
|
+
/** Create an empty, open `RequestTracker`. */
|
|
223
|
+
export const create_request_tracker = () => {
|
|
224
|
+
const requests = new Set();
|
|
225
|
+
const flushes = new Set();
|
|
226
|
+
// removed on either outcome, so a flush that rejects despite the contract
|
|
227
|
+
// can't wedge shutdown or surface as an unhandled rejection
|
|
228
|
+
const hold = (set, promise) => {
|
|
229
|
+
set.add(promise);
|
|
230
|
+
const remove = () => {
|
|
231
|
+
set.delete(promise);
|
|
232
|
+
};
|
|
233
|
+
void promise.then(remove, remove);
|
|
234
|
+
};
|
|
235
|
+
// the removal reaction is registered first, so a settled promise is gone
|
|
236
|
+
// from its set by the time a pass resumes
|
|
237
|
+
const drain = async (set) => {
|
|
238
|
+
while (set.size > 0)
|
|
239
|
+
await Promise.allSettled(set);
|
|
240
|
+
};
|
|
241
|
+
let closed = false;
|
|
242
|
+
return {
|
|
243
|
+
accept: () => {
|
|
244
|
+
if (closed)
|
|
245
|
+
return null;
|
|
246
|
+
let release;
|
|
247
|
+
hold(requests, new Promise((resolve) => {
|
|
248
|
+
release = resolve;
|
|
249
|
+
}));
|
|
250
|
+
let finished = false;
|
|
251
|
+
return {
|
|
252
|
+
finish: (flush) => {
|
|
253
|
+
if (finished)
|
|
254
|
+
return;
|
|
255
|
+
finished = true;
|
|
256
|
+
if (!flush) {
|
|
257
|
+
release();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
hold(flushes, flush);
|
|
261
|
+
void flush.then(release, release);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
close: () => {
|
|
266
|
+
closed = true;
|
|
267
|
+
},
|
|
268
|
+
drain_inflight: () => drain(requests),
|
|
269
|
+
inflight_count: () => requests.size,
|
|
270
|
+
drain_flushes: () => drain(flushes),
|
|
271
|
+
flush_count: () => flushes.size
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* A view of `parent` with its own `close`: `accept` refuses once the view is
|
|
276
|
+
* closed and otherwise holds the request on `parent`; the drains and counts
|
|
277
|
+
* are `parent`'s, so they cover every server on the backend, not only the
|
|
278
|
+
* requests this view accepted. One server's admission over its backend's tracker —
|
|
279
|
+
* `AppServer.close` closes its view, so the backend's tracker stays open for
|
|
280
|
+
* a server assembled on it later.
|
|
281
|
+
*
|
|
282
|
+
* @param parent - the tracker requests are held on
|
|
283
|
+
*/
|
|
284
|
+
export const create_request_tracker_view = (parent) => {
|
|
285
|
+
let closed = false;
|
|
286
|
+
return {
|
|
287
|
+
accept: () => (closed ? null : parent.accept()),
|
|
288
|
+
close: () => {
|
|
289
|
+
closed = true;
|
|
290
|
+
},
|
|
291
|
+
drain_inflight: () => parent.drain_inflight(),
|
|
292
|
+
inflight_count: () => parent.inflight_count(),
|
|
293
|
+
drain_flushes: () => parent.drain_flushes(),
|
|
294
|
+
flush_count: () => parent.flush_count()
|
|
295
|
+
};
|
|
296
|
+
};
|
|
@@ -36,7 +36,7 @@ export interface RouteOkOptions {
|
|
|
36
36
|
* `Set-Cookie` header values, written in order after every `Set-Cookie`
|
|
37
37
|
* line the middleware put on the context — the session middleware's clear
|
|
38
38
|
* of a stale cookie first. Formatted by the caller
|
|
39
|
-
* (`
|
|
39
|
+
* (`sign_session_cookie`, `format_session_clear_cookie`); the framework
|
|
40
40
|
* treats them as opaque lines.
|
|
41
41
|
*/
|
|
42
42
|
readonly set_cookie?: ReadonlyArray<string>;
|
|
@@ -33,11 +33,12 @@ import type { ResolvedAuth } from '../auth/resolved_auth.js';
|
|
|
33
33
|
/**
|
|
34
34
|
* Two-phase auth guard set returned by `AuthGuardResolver`.
|
|
35
35
|
*
|
|
36
|
-
* `pre_authorization` runs before the authorization phase — the 401 check
|
|
37
|
-
* and the rule-3 token-scope refusal live here,
|
|
38
|
-
*
|
|
36
|
+
* `pre_authorization` runs before the authorization phase — the 401 check,
|
|
37
|
+
* the credential-type gate and the rule-3 token-scope refusal live here, each
|
|
38
|
+
* reading only what the auth middleware set, so a caller they turn away never
|
|
39
|
+
* reaches the actor resolution or the route's body.
|
|
39
40
|
* `post_authorization` runs after the authorization phase has populated
|
|
40
|
-
* `RequestContext` —
|
|
41
|
+
* `RequestContext` — the role check lives here because it reads
|
|
41
42
|
* `c.var.request_context.role_grants`.
|
|
42
43
|
*
|
|
43
44
|
* Both phases run ahead of body validation, which is why neither is named
|
|
@@ -89,13 +90,15 @@ export type RouteMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
|
89
90
|
* either.
|
|
90
91
|
*
|
|
91
92
|
* Audit writes run through `AppDeps.audit.emit(route, input)` (see
|
|
92
|
-
* `auth/audit_emitter.ts`).
|
|
93
|
-
*
|
|
94
|
-
*
|
|
93
|
+
* `auth/audit_emitter.ts`). A success row is written in the transaction of
|
|
94
|
+
* the change it reports — a refused INSERT fails the change, and with no
|
|
95
|
+
* transaction open `emit` throws — and a failure row on the pool it closes
|
|
96
|
+
* over, so a refused attempt's row survives the rollback.
|
|
95
97
|
*
|
|
96
|
-
* Routes whose body
|
|
97
|
-
* declare `transaction: false`
|
|
98
|
-
*
|
|
98
|
+
* Routes whose body opens its own transaction around just its writes
|
|
99
|
+
* (`/login`, `/password`, signup, bootstrap) declare `transaction: false`
|
|
100
|
+
* on the spec, which makes `route.db` the pool, and run that transaction
|
|
101
|
+
* through `transaction_with_post_commit_rollback`.
|
|
99
102
|
*
|
|
100
103
|
* @typeParam TAuth - `auth`, narrowed per route by `RequestContextForAuth`
|
|
101
104
|
* @typeParam TInput - the validated body
|
|
@@ -201,7 +204,7 @@ export interface RouteContext<TAuth extends RequestContext | null = RequestConte
|
|
|
201
204
|
db: Db;
|
|
202
205
|
/**
|
|
203
206
|
* Eager fire-and-forget queue — push the in-flight `Promise<void>` for
|
|
204
|
-
* pool writes already running (audit
|
|
207
|
+
* pool writes already running (failure audit rows, api-token usage
|
|
205
208
|
* tracking). The flush middleware drains via
|
|
206
209
|
* `flush_pending_effects` after the handler returns.
|
|
207
210
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route_spec.d.ts","sourceRoot":"","sources":["../../src/lib/http/route_spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEtE,OAAO,EAEN,KAAK,SAAS,EAEd,KAAK,UAAU,EACf,KAAK,KAAK,EACV,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAQ9B,MAAM,oBAAoB,CAA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stream on a request — what a route spec's
|
|
5
|
+
* `RouteContext.open_sse` gives it, answered by `route_sse` — and
|
|
6
|
+
* `SseNotification` is the notification shape, aligned with JSON-RPC 2.0.
|
|
6
7
|
*
|
|
7
8
|
* ## Outbound bound
|
|
8
9
|
*
|
|
@@ -66,7 +67,7 @@ export interface SseNotification {
|
|
|
66
67
|
/** Method-specific payload. */
|
|
67
68
|
params: unknown;
|
|
68
69
|
}
|
|
69
|
-
/** Options for `create_sse_stream
|
|
70
|
+
/** Options for `create_sse_stream`. */
|
|
70
71
|
export interface SseResponseOptions {
|
|
71
72
|
/**
|
|
72
73
|
* The account the stream belongs to, named in the warning logged when the
|
|
@@ -124,26 +125,6 @@ export interface OpenedSseStream<T> {
|
|
|
124
125
|
* (`validate_sse_keep_alive_ms`)
|
|
125
126
|
*/
|
|
126
127
|
export declare const create_sse_stream: <T = unknown>(c: Context, log: Logger, options?: SseResponseOptions) => OpenedSseStream<T>;
|
|
127
|
-
/**
|
|
128
|
-
* Create an SSE response for a Hono context: `create_sse_stream`, answered at
|
|
129
|
-
* once through the context with `SSE_RESPONSE_HEADERS` — the response
|
|
130
|
-
* Hono's `streamSSE` builds, so it carries the headers the middleware put on
|
|
131
|
-
* the context. For a handler outside the route-spec system; a route spec opens
|
|
132
|
-
* its stream through `RouteContext.open_sse` instead, which builds the
|
|
133
|
-
* response only when the route answers with it.
|
|
134
|
-
*
|
|
135
|
-
* @param log - logger for serialization and `on_close` listener errors, and
|
|
136
|
-
* for the warning when the stream ends on its outbound budget
|
|
137
|
-
* @param options - what the overflow warning names, and the keep-alive interval
|
|
138
|
-
* @returns object with the streaming `Response` and an `SseStream` controller
|
|
139
|
-
* @throws Error when `options.keep_alive_ms` is out of range
|
|
140
|
-
* (`validate_sse_keep_alive_ms`)
|
|
141
|
-
* @mutates `c` - writes `SSE_RESPONSE_HEADERS` on the context's headers
|
|
142
|
-
*/
|
|
143
|
-
export declare const create_sse_response: <T = unknown>(c: Context, log: Logger, options?: SseResponseOptions) => {
|
|
144
|
-
response: Response;
|
|
145
|
-
stream: SseStream<T>;
|
|
146
|
-
};
|
|
147
128
|
/** Spec for a push event — declares params schema, description, and channel. */
|
|
148
129
|
export interface EventSpec {
|
|
149
130
|
/** Event method name, used as the JSON-RPC notification `method`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/sse.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/lib/realtime/sse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAYrE;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACrC;;;;OAIG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACxB,wBAAwB;IACxB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC/B,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AA8DD,wEAAwE;AACxE,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,oDAAoD;IACpD,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB;;;;OAIG;IACH,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,GAAG,OAAO,EAC5C,GAAG,OAAO,EACV,KAAK,MAAM,EACX,UAAU,kBAAkB,KAC1B,eAAe,CAAC,CAAC,CAoGnB,CAAC;AAEF,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACzB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,MAAM,EAAE,SAAS,CAAC;IAClB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,GAAI,CAAC,SAAS,eAAe,EACrE,aAAa;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAAE,EAC9D,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,KAAK,MAAM,KACT;IAAE,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAmBjD,CAAC"}
|
package/dist/realtime/sse.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SSE (Server-Sent Events) streaming utilities for Hono.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* `create_sse_stream` opens a stream on a request — what a route spec's
|
|
5
|
+
* `RouteContext.open_sse` gives it, answered by `route_sse` — and
|
|
6
|
+
* `SseNotification` is the notification shape, aligned with JSON-RPC 2.0.
|
|
6
7
|
*
|
|
7
8
|
* ## Outbound bound
|
|
8
9
|
*
|
|
@@ -35,7 +36,7 @@ import { DEV } from 'esm-env';
|
|
|
35
36
|
import { parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
36
37
|
import { utf8_length } from '../actions/transports.js';
|
|
37
38
|
import { OutboundBudget } from './outbound_budget.js';
|
|
38
|
-
import { SSE_CONNECTED_COMMENT, SSE_KEEP_ALIVE_COMMENT, SSE_KEEP_ALIVE_INTERVAL_MS, SSE_OUTBOUND_QUEUE_BYTES,
|
|
39
|
+
import { SSE_CONNECTED_COMMENT, SSE_KEEP_ALIVE_COMMENT, SSE_KEEP_ALIVE_INTERVAL_MS, SSE_OUTBOUND_QUEUE_BYTES, validate_sse_keep_alive_ms } from './sse_constants.js';
|
|
39
40
|
const is_node_connection_stream = (value) => {
|
|
40
41
|
if (typeof value !== 'object' || value === null)
|
|
41
42
|
return false;
|
|
@@ -226,28 +227,6 @@ export const create_sse_stream = (c, log, options) => {
|
|
|
226
227
|
watch_client_disconnect(c, do_close);
|
|
227
228
|
return { stream, body: hono_stream.responseReadable };
|
|
228
229
|
};
|
|
229
|
-
/**
|
|
230
|
-
* Create an SSE response for a Hono context: `create_sse_stream`, answered at
|
|
231
|
-
* once through the context with `SSE_RESPONSE_HEADERS` — the response
|
|
232
|
-
* Hono's `streamSSE` builds, so it carries the headers the middleware put on
|
|
233
|
-
* the context. For a handler outside the route-spec system; a route spec opens
|
|
234
|
-
* its stream through `RouteContext.open_sse` instead, which builds the
|
|
235
|
-
* response only when the route answers with it.
|
|
236
|
-
*
|
|
237
|
-
* @param log - logger for serialization and `on_close` listener errors, and
|
|
238
|
-
* for the warning when the stream ends on its outbound budget
|
|
239
|
-
* @param options - what the overflow warning names, and the keep-alive interval
|
|
240
|
-
* @returns object with the streaming `Response` and an `SseStream` controller
|
|
241
|
-
* @throws Error when `options.keep_alive_ms` is out of range
|
|
242
|
-
* (`validate_sse_keep_alive_ms`)
|
|
243
|
-
* @mutates `c` - writes `SSE_RESPONSE_HEADERS` on the context's headers
|
|
244
|
-
*/
|
|
245
|
-
export const create_sse_response = (c, log, options) => {
|
|
246
|
-
const { stream, body } = create_sse_stream(c, log, options);
|
|
247
|
-
for (const [name, value] of Object.entries(SSE_RESPONSE_HEADERS))
|
|
248
|
-
c.header(name, value);
|
|
249
|
-
return { response: c.newResponse(body), stream };
|
|
250
|
-
};
|
|
251
230
|
/**
|
|
252
231
|
* Create a broadcaster that validates events in DEV mode.
|
|
253
232
|
*
|
|
@@ -141,9 +141,8 @@ export interface CreateAppBackendOptions {
|
|
|
141
141
|
/**
|
|
142
142
|
* Bound on the pool checkouts a request makes, in ms — the server env's
|
|
143
143
|
* `FUZ_DB_CHECKOUT_TIMEOUT_MS`. Default `DEFAULT_DB_CHECKOUT_TIMEOUT_MS`
|
|
144
|
-
* (5 s). A failed checkout answers 503 on every surface. Audit writes
|
|
145
|
-
* `db_audit_checkout_timeout_ms` instead
|
|
146
|
-
* waits on included. A checkout that waits and then connects can take about
|
|
144
|
+
* (5 s). A failed checkout answers 503 on every surface. Audit pool writes (failure
|
|
145
|
+
* rows) use `db_audit_checkout_timeout_ms` instead. A checkout that waits and then connects can take about
|
|
147
146
|
* twice the bound (`db/db_pg.ts`, "Checkout timeout"). Postgres only:
|
|
148
147
|
* PGlite and pglet have no pool, and a value passed with one is warned of
|
|
149
148
|
* at boot. Twin of the Rust `BaseServerEnv::db_checkout_timeout`.
|
|
@@ -152,8 +151,8 @@ export interface CreateAppBackendOptions {
|
|
|
152
151
|
/**
|
|
153
152
|
* Bound on the checkout behind each audit pool write, in ms — the server
|
|
154
153
|
* env's `FUZ_DB_AUDIT_CHECKOUT_TIMEOUT_MS`. Default
|
|
155
|
-
* `DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS` (30 s).
|
|
156
|
-
*
|
|
154
|
+
* `DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS` (30 s). No response waits on
|
|
155
|
+
* a pool write; `AppServer.close` drains them within its own bound. Postgres only, like
|
|
157
156
|
* `db_checkout_timeout_ms`. Twin of the Rust
|
|
158
157
|
* `BaseServerEnv::db_audit_checkout_timeout`.
|
|
159
158
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app_backend.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAkB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"app_backend.d.ts","sourceRoot":"","sources":["../../src/lib/server/app_backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAwB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAkB,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C,UAAU,CAyD7F,CAAC"}
|
|
@@ -18,6 +18,7 @@ import { run_migrations } from '../db/migrate.js';
|
|
|
18
18
|
import { AUTH_MIGRATION_NS } from '../auth/migrations.js';
|
|
19
19
|
import { create_db, is_pg_database_url } from '../db/create_db.js';
|
|
20
20
|
import { DEFAULT_DB_AUDIT_CHECKOUT_TIMEOUT_MS } from '../db/db_pg.js';
|
|
21
|
+
import { create_request_tracker } from '../http/pending_effects.js';
|
|
21
22
|
/**
|
|
22
23
|
* Trivial `AuditFactory` for consumers that don't compose `on_audit_event`
|
|
23
24
|
* or `audit_log_config`. Equivalent to
|
|
@@ -82,7 +83,8 @@ export const create_app_backend = async (options) => {
|
|
|
82
83
|
log,
|
|
83
84
|
audit,
|
|
84
85
|
connection_closer: options.connection_closer ?? create_realtime_closer(),
|
|
85
|
-
notification_sender: create_realtime_notification_sender()
|
|
86
|
+
notification_sender: create_realtime_notification_sender(),
|
|
87
|
+
request_tracker: create_request_tracker()
|
|
86
88
|
}
|
|
87
89
|
};
|
|
88
90
|
}
|
|
@@ -10,7 +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 {
|
|
13
|
+
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
14
14
|
import type { BootstrapTokenStore } from '../auth/bootstrap_token_store.js';
|
|
15
15
|
import { type EventSpec } from '../realtime/sse.js';
|
|
16
16
|
import { type AuditLogSse } from '../realtime/audit_log_sse.js';
|
|
@@ -24,11 +24,12 @@ import { type ServeStaticFactory } from './static.js';
|
|
|
24
24
|
import { type AppSurfaceSpec, type AppSurfaceDiagnostic, type RpcEndpointSpec } from '../http/surface.js';
|
|
25
25
|
import { type RouteSpec } from '../http/route_spec.js';
|
|
26
26
|
import type { MiddlewareCarveOut, MiddlewareSpec } from '../http/middleware_spec.js';
|
|
27
|
-
import { type BootstrapStatus
|
|
28
|
-
import { type EffectErrorContext } from '../http/pending_effects.js';
|
|
27
|
+
import { type BootstrapStatus } from '../auth/bootstrap_routes.js';
|
|
28
|
+
import { type EffectErrorContext, type RequestTracker } from '../http/pending_effects.js';
|
|
29
29
|
import { type WsEndpointSpec } from '../actions/ws_endpoint_spec.js';
|
|
30
30
|
import type { ConnectionRegistry } from '../actions/connection_registry.js';
|
|
31
31
|
import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
|
|
32
|
+
import type { AuditEmitter } from '../auth/audit_emitter.js';
|
|
32
33
|
/**
|
|
33
34
|
* Bootstrap configuration for `AppServerOptions.bootstrap`.
|
|
34
35
|
*
|
|
@@ -44,7 +45,7 @@ import { type AuthCleanupScheduleOptions } from '../auth/cleanup.js';
|
|
|
44
45
|
* Equivalent to omitting `bootstrap` entirely; the explicit mode is
|
|
45
46
|
* for documentation and reviewable intent at the wiring layer.
|
|
46
47
|
* - `surface_only` — route present, permanent 403 via
|
|
47
|
-
* `
|
|
48
|
+
* `is_bootstrap_available`. For tests asserting on the
|
|
48
49
|
* disabled-but-present wire shape.
|
|
49
50
|
* - `live` — route mounted, real token verification. Success path
|
|
50
51
|
* reachable. `token_store` is required.
|
|
@@ -68,8 +69,6 @@ export interface BootstrapLiveOptions {
|
|
|
68
69
|
token_store: BootstrapTokenStore;
|
|
69
70
|
/** Route prefix for bootstrap routes. Default `'/api/account'`; must sit under `/api/`. */
|
|
70
71
|
route_prefix?: string;
|
|
71
|
-
/** Called after a successful bootstrap commits (see `OnBootstrap`). */
|
|
72
|
-
on_bootstrap?: OnBootstrap;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Configuration for `create_app_server()`.
|
|
@@ -81,12 +80,11 @@ export interface AppServerOptions {
|
|
|
81
80
|
/** Pre-initialized backend from `create_app_backend()`. */
|
|
82
81
|
backend: AppBackend;
|
|
83
82
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* the `Set-Cookie` grammar cannot carry.
|
|
83
|
+
* The session cookie's name (`SESSION_COOKIE_NAME` is the spine default).
|
|
84
|
+
* Assembly throws on a name that is no RFC 6265 cookie-name, which the
|
|
85
|
+
* `Set-Cookie` grammar cannot carry.
|
|
88
86
|
*/
|
|
89
|
-
|
|
87
|
+
session_cookie_name: string;
|
|
90
88
|
/**
|
|
91
89
|
* Parsed allowed origin patterns, as `parse_allowed_origins` returns them
|
|
92
90
|
* (`validate_server_env`'s `allowed_origins`); assembly throws on a matcher
|
|
@@ -222,7 +220,14 @@ export interface AppServerOptions {
|
|
|
222
220
|
* error map declares its `413` and `400`; with `null` it is absent.
|
|
223
221
|
*/
|
|
224
222
|
max_body_size?: number | null;
|
|
225
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Daemon token state for keeper auth. Omit to disable. A null
|
|
225
|
+
* `keeper_account_id` is resolved from the database at assembly (an
|
|
226
|
+
* already-bootstrapped server), and a live bootstrap sets it once its
|
|
227
|
+
* account commits; the daemon leg never re-reads it per request, so a
|
|
228
|
+
* keeper seeded by another process (`seed_dev_account`) needs a restart,
|
|
229
|
+
* as on the Rust spine.
|
|
230
|
+
*/
|
|
226
231
|
daemon_token_state?: DaemonTokenState;
|
|
227
232
|
/** Bootstrap options. Omit to skip bootstrap status check and routes. */
|
|
228
233
|
bootstrap?: BootstrapServerOptions;
|
|
@@ -423,6 +428,16 @@ export interface AppServerOptions {
|
|
|
423
428
|
* Default `false` (production: true fire-and-forget).
|
|
424
429
|
*/
|
|
425
430
|
await_pending_effects?: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* How long `AppServer.close` waits for the work still in flight — each
|
|
433
|
+
* HTTP request and WS message accepted, until its handler has returned and
|
|
434
|
+
* its effect queues (failure audit rows, API token usage, post-commit
|
|
435
|
+
* thunks) have flushed, and every pool write of `deps.audit` — before it
|
|
436
|
+
* closes the database. What is still running then is given up on and
|
|
437
|
+
* logged. Default `DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS`; must be a positive
|
|
438
|
+
* number of ms.
|
|
439
|
+
*/
|
|
440
|
+
shutdown_drain_timeout_ms?: number;
|
|
426
441
|
/**
|
|
427
442
|
* Called when an eager pending effect rejects, on HTTP requests and on the
|
|
428
443
|
* frames of every WS endpoint the server mounts, in either
|
|
@@ -474,7 +489,24 @@ export interface AppServer {
|
|
|
474
489
|
* is left closing, so an upgrade or stream that registers afterward is
|
|
475
490
|
* born closed — refused at once rather than outliving the server — and
|
|
476
491
|
* a closed registry hosts no other server
|
|
477
|
-
* 3.
|
|
492
|
+
* 3. wait for the work still in flight on `deps.request_tracker` and
|
|
493
|
+
* `deps.audit`: every HTTP request and WS message accepted, until its
|
|
494
|
+
* handler has returned and its effect queues have flushed (failure
|
|
495
|
+
* audit rows, API token usage, post-commit thunks; production holds no
|
|
496
|
+
* HTTP response for them, and a WS reply is sent before its flush), and
|
|
497
|
+
* every pool write of the emitter — a handler still running when the
|
|
498
|
+
* close starts is waited for, then its flush. A WS handler's socket is
|
|
499
|
+
* closed in step 2, which aborts its `signal`; one that runs on is still
|
|
500
|
+
* waited for. Bounded by `shutdown_drain_timeout_ms`, logging what it
|
|
501
|
+
* gives up on. From here a request that arrives is refused — HTTP with
|
|
502
|
+
* 503 `service_unavailable`, and a WS message, on a socket step 2
|
|
503
|
+
* didn't end (a hand mount), with the `service_unavailable` JSON-RPC
|
|
504
|
+
* error — never run against the closing database. The Rust
|
|
505
|
+
* spine waits the same way for an HTTP request already dispatched, but
|
|
506
|
+
* drops a WS message's dispatch still in its handler with its socket
|
|
507
|
+
* loop, which rolls back; one whose commit has started finishes, its
|
|
508
|
+
* post-commit effects included
|
|
509
|
+
* 4. release what assembly acquired, last acquired first: remove the
|
|
478
510
|
* audit listeners `create_app_server` registered on `deps.audit` (the
|
|
479
511
|
* revocation guard, the audit-log SSE listener), the members it added
|
|
480
512
|
* to `deps.connection_closer` (each mounted connection registry, the
|
|
@@ -486,14 +518,17 @@ export interface AppServer {
|
|
|
486
518
|
* were before assembly, so a failed assembly can be retried on the same
|
|
487
519
|
* backend, and a backend whose `close` you own (a test harness) can
|
|
488
520
|
* host another server
|
|
489
|
-
*
|
|
521
|
+
* 5. close the database connection (`AppBackend.close`)
|
|
490
522
|
*
|
|
491
523
|
* Idempotent: a second call settles with the first one's outcome (a failed
|
|
492
|
-
* close is not retried), and concurrent calls share one shutdown.
|
|
524
|
+
* close is not retried), and concurrent calls share one shutdown. Never
|
|
525
|
+
* await it from a handler: its own request is held, so the drain waits on
|
|
526
|
+
* it until `shutdown_drain_timeout_ms`.
|
|
493
527
|
*
|
|
494
528
|
* Stop accepting new HTTP connections first — without awaiting the
|
|
495
529
|
* listener's full drain, since live WebSockets hold it open until `close`
|
|
496
|
-
* ends them — so no new request reaches a closed database.
|
|
530
|
+
* ends them — so no new request reaches a closed database. A request the
|
|
531
|
+
* app already accepted is waited for in step 3.
|
|
497
532
|
*/
|
|
498
533
|
close: () => Promise<void>;
|
|
499
534
|
}
|
|
@@ -522,6 +557,12 @@ export declare const require_audit_sse: (source: {
|
|
|
522
557
|
* `fuz_http` `DEFAULT_BODY_LIMIT_BYTES`.
|
|
523
558
|
*/
|
|
524
559
|
export declare const DEFAULT_BODY_LIMIT_BYTES: number;
|
|
560
|
+
/**
|
|
561
|
+
* Default bound on `AppServer.close`'s wait for the effects still in flight
|
|
562
|
+
* (`AppServerOptions.shutdown_drain_timeout_ms`). Twin of the Rust spine's
|
|
563
|
+
* `DEFAULT_DRAIN_TIMEOUT`.
|
|
564
|
+
*/
|
|
565
|
+
export declare const DEFAULT_SHUTDOWN_DRAIN_TIMEOUT_MS = 10000;
|
|
525
566
|
/**
|
|
526
567
|
* Each `AppServerOptions` rate-limiter field, with the defaults an omitted one
|
|
527
568
|
* is built from under `rate_limiters: 'enforced'` and the name its
|
|
@@ -675,5 +716,28 @@ export declare const collect_config_diagnostics: (input: ConfigDiagnosticsInput)
|
|
|
675
716
|
* @throws Error from any assembly step, after releasing what assembly acquired
|
|
676
717
|
*/
|
|
677
718
|
export declare const create_app_server: (options: AppServerOptions) => Promise<AppServer>;
|
|
719
|
+
/**
|
|
720
|
+
* What `drain_effects_on_shutdown` gave up on at its bound, each counted on
|
|
721
|
+
* its own: a request still waiting on its audit writes has those writes
|
|
722
|
+
* counted in `audit_writes` too, so the two are not summed.
|
|
723
|
+
*/
|
|
724
|
+
export interface ShutdownDrainGivenUp {
|
|
725
|
+
/**
|
|
726
|
+
* Requests still held — HTTP requests and WS messages alike, each with its
|
|
727
|
+
* handler or its effect flush still running.
|
|
728
|
+
*/
|
|
729
|
+
requests: number;
|
|
730
|
+
/** Pool writes of the audit emitter still in flight. */
|
|
731
|
+
audit_writes: number;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Wait for the requests held (HTTP requests and WS messages, one tracker —
|
|
735
|
+
* each until its handler has returned and its flush settled) and then the
|
|
736
|
+
* audit emitter's pool writes, until none is left or `timeout_ms` passes —
|
|
737
|
+
* then log an error naming what was given up on. Never rejects.
|
|
738
|
+
*
|
|
739
|
+
* @returns what was given up on, both counts `0` when everything settled
|
|
740
|
+
*/
|
|
741
|
+
export declare const drain_effects_on_shutdown: (requests: Pick<RequestTracker, "drain_inflight" | "inflight_count">, audit: Pick<AuditEmitter, "drain_inflight" | "inflight_count">, timeout_ms: number, log: Logger) => Promise<ShutdownDrainGivenUp>;
|
|
678
742
|
export {};
|
|
679
743
|
//# sourceMappingURL=app_server.d.ts.map
|