@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
package/dist/http/db_routes.d.ts
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
13
|
-
import { type Uuid } from '../primitive_schemas.js';
|
|
14
13
|
import type { Db, DbType } from '../db/db.js';
|
|
15
14
|
import { type RouteSpec } from './route_spec.js';
|
|
15
|
+
import type { AuditEmitter } from '../auth/audit_emitter.js';
|
|
16
16
|
/**
|
|
17
17
|
* Table metadata from `information_schema`.
|
|
18
18
|
*/
|
|
@@ -79,7 +79,7 @@ export declare const NON_BROWSABLE_TABLES: ReadonlyArray<string>;
|
|
|
79
79
|
* (`create_revocation_guard`) closes live connections by listening to audit
|
|
80
80
|
* events, so a raw row delete here is invisible to it.
|
|
81
81
|
* - `bootstrap_lock` — deleting the singleton closes bootstrap for good:
|
|
82
|
-
* `
|
|
82
|
+
* `is_bootstrap_available` reads a missing row as unavailable (logged as an
|
|
83
83
|
* error), so a database that has not bootstrapped never can until the row
|
|
84
84
|
* is restored.
|
|
85
85
|
* - `app_settings` — deleting the singleton makes every settings read throw.
|
|
@@ -93,31 +93,16 @@ export declare const NON_BROWSABLE_TABLES: ReadonlyArray<string>;
|
|
|
93
93
|
*/
|
|
94
94
|
export declare const NON_DELETABLE_TABLES: ReadonlyArray<string>;
|
|
95
95
|
/**
|
|
96
|
-
* Capabilities the db routes need — a narrow
|
|
97
|
-
* (`auth/deps.ts`)
|
|
98
|
-
* `auth/audit_emitter.ts` `AuditEmitter` (and therefore `AppDeps.audit` /
|
|
99
|
-
* `RouteFactoryDeps.audit`) satisfies `audit` structurally.
|
|
96
|
+
* Capabilities the db routes need — a narrow slice of `AppDeps`
|
|
97
|
+
* (`auth/deps.ts`); `AppDeps.audit` / `RouteFactoryDeps.audit` satisfy it.
|
|
100
98
|
*/
|
|
101
99
|
export interface DbRouteDeps {
|
|
102
100
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* written on the pool because the request transaction has ended by then.
|
|
107
|
-
* The flush awaits the returned promise.
|
|
101
|
+
* The row-`DELETE` handler writes its `db_admin_row_delete` success row in
|
|
102
|
+
* the route's transaction, after the delete, so the row and the delete
|
|
103
|
+
* commit together or not at all.
|
|
108
104
|
*/
|
|
109
|
-
audit:
|
|
110
|
-
emit_pool: (input: {
|
|
111
|
-
event_type: 'db_admin_row_delete';
|
|
112
|
-
account_id: Uuid | null;
|
|
113
|
-
ip: string;
|
|
114
|
-
metadata: {
|
|
115
|
-
table: string;
|
|
116
|
-
pk_column: string;
|
|
117
|
-
id: string;
|
|
118
|
-
};
|
|
119
|
-
}) => Promise<void>;
|
|
120
|
-
};
|
|
105
|
+
audit: Pick<AuditEmitter, 'emit'>;
|
|
121
106
|
}
|
|
122
107
|
/**
|
|
123
108
|
* Per-factory configuration for db routes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db_routes.d.ts","sourceRoot":"","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"db_routes.d.ts","sourceRoot":"","sources":["../../src/lib/http/db_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAwBtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgB/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,WAAW,EAAE,MAAM,CAAC;CACpB;AAED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|
14
14
|
import { ActingActor } from '../primitive_schemas.js';
|
|
15
15
|
import { define_route } from './route_spec.js';
|
|
16
16
|
import { route_fail, route_ok } from './route_result.js';
|
|
17
|
+
import { transaction_with_post_commit_rollback } from './pending_effects.js';
|
|
17
18
|
import { 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
19
|
import { assert_valid_sql_identifier, VALID_SQL_IDENTIFIER } from '../db/sql_identifier.js';
|
|
19
20
|
import { pg_error_code } from '../db/pg_error.js';
|
|
20
|
-
import { emit_after_commit } from './pending_effects.js';
|
|
21
21
|
// the spellings `query_int` reads as an integer: decimal digits with an optional sign
|
|
22
22
|
const QUERY_INT_PATTERN = /^[+-]?\d+$/;
|
|
23
23
|
/**
|
|
@@ -84,7 +84,7 @@ export const NON_BROWSABLE_TABLES = Object.freeze([
|
|
|
84
84
|
* (`create_revocation_guard`) closes live connections by listening to audit
|
|
85
85
|
* events, so a raw row delete here is invisible to it.
|
|
86
86
|
* - `bootstrap_lock` — deleting the singleton closes bootstrap for good:
|
|
87
|
-
* `
|
|
87
|
+
* `is_bootstrap_available` reads a missing row as unavailable (logged as an
|
|
88
88
|
* error), so a database that has not bootstrapped never can until the row
|
|
89
89
|
* is restored.
|
|
90
90
|
* - `app_settings` — deleting the singleton makes every settings read throw.
|
|
@@ -367,82 +367,82 @@ export const create_db_route_specs = (deps, options) => {
|
|
|
367
367
|
return route_fail(REST_TABLE_NO_PRIMARY_KEY);
|
|
368
368
|
}
|
|
369
369
|
const pk_column = pk_columns[0];
|
|
370
|
-
// The
|
|
371
|
-
//
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
await
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
370
|
+
// The delete and its audit row are one transaction: the route's, or —
|
|
371
|
+
// remounted with `transaction: false` — one opened here around just
|
|
372
|
+
// them, so the row is written with the delete either way.
|
|
373
|
+
const delete_row = async (tx_ctx) => {
|
|
374
|
+
// The refusals below answer from a failed DELETE, which on PostgreSQL
|
|
375
|
+
// aborts the route's transaction — its COMMIT would come back as a
|
|
376
|
+
// ROLLBACK, which the pg driver throws on (`db/db_pg.ts`). A savepoint
|
|
377
|
+
// keeps the refusal's failure out of the transaction.
|
|
378
|
+
await tx_ctx.db.query('SAVEPOINT db_admin_row_delete');
|
|
379
|
+
let deleted_id;
|
|
380
|
+
try {
|
|
381
|
+
// Typed PK compare, twinning the Rust spine: `$1` travels as an
|
|
382
|
+
// untyped text-format parameter, so PG infers the PK column's
|
|
383
|
+
// type and coerces the id with that type's input function —
|
|
384
|
+
// index-scan deletes and canonical per-type semantics (citext
|
|
385
|
+
// case-insensitivity, char(n) padding, any valid uuid spelling).
|
|
386
|
+
// An id that cannot be a value of the PK type errors at bind
|
|
387
|
+
// (22P02/22003), mapped below to the same 404 as a typed miss.
|
|
388
|
+
// `RETURNING "<pk>"::text` reads back only the PK cell — the
|
|
389
|
+
// deleted row's other values (e.g. a bytea column) are never
|
|
390
|
+
// materialized — so the audit trail records the row's canonical
|
|
391
|
+
// PK rendering rather than whatever spelling the URL supplied.
|
|
392
|
+
const pk_ident = assert_valid_sql_identifier(pk_column);
|
|
393
|
+
const result = await tx_ctx.db.query(`DELETE FROM "${assert_valid_sql_identifier(name)}" WHERE "${pk_ident}" = $1 RETURNING "${pk_ident}"::text AS pk_text`, [id]);
|
|
394
|
+
if (result.length === 0) {
|
|
395
|
+
return route_fail(REST_ROW_NOT_FOUND);
|
|
396
|
+
}
|
|
397
|
+
deleted_id = result[0].pk_text;
|
|
398
|
+
}
|
|
399
|
+
catch (err) {
|
|
400
|
+
const code = pg_error_code(err);
|
|
401
|
+
// 22P02 invalid_text_representation / 22003 numeric_value_out_of_range
|
|
402
|
+
// / 22021 character_not_in_repertoire: the id cannot be coerced
|
|
403
|
+
// to the PK column's type — or cannot even be a text value (a
|
|
404
|
+
// NUL byte, rejected by the server encoding whatever the PK
|
|
405
|
+
// type) — so no row can match; answer with the same masked 404
|
|
406
|
+
// as a typed miss.
|
|
407
|
+
const uncoercible = code === '22P02' || code === '22003' || code === '22021';
|
|
408
|
+
// 23503 foreign_key_violation / 23001 restrict_violation — the
|
|
409
|
+
// same referencing-row refusal. Which one depends on the
|
|
410
|
+
// constraint: `ON DELETE RESTRICT` raises 23001 on PG 18, PGlite
|
|
411
|
+
// and pglet (23503 on PG ≤17), and `NO ACTION` — the default,
|
|
412
|
+
// when the constraint names no action — raises 23503 on all of
|
|
413
|
+
// them.
|
|
414
|
+
const referenced = code === '23503' || code === '23001';
|
|
415
|
+
// anything else fails the request, and the route's transaction
|
|
416
|
+
// rolls back whole
|
|
417
|
+
if (!uncoercible && !referenced)
|
|
418
|
+
throw err;
|
|
419
|
+
// the refusal answers normally, so the transaction must commit
|
|
420
|
+
await tx_ctx.db.query('ROLLBACK TO SAVEPOINT db_admin_row_delete');
|
|
421
|
+
if (uncoercible) {
|
|
422
|
+
return route_fail(REST_ROW_NOT_FOUND);
|
|
423
|
+
}
|
|
424
|
+
const pg_err = err;
|
|
425
|
+
log?.warn('Foreign key violation:', pg_err.detail, pg_err.constraint);
|
|
426
|
+
return route_fail(REST_FOREIGN_KEY_VIOLATION);
|
|
395
427
|
}
|
|
396
|
-
const deleted_id = result[0].pk_text;
|
|
397
428
|
// The trail for the trail-adjacent surface: every successful row
|
|
398
|
-
// delete through this endpoint is audited
|
|
399
|
-
//
|
|
400
|
-
//
|
|
401
|
-
//
|
|
402
|
-
//
|
|
403
|
-
//
|
|
404
|
-
|
|
405
|
-
// is claimed.
|
|
406
|
-
const account_id = route.auth.account.id;
|
|
407
|
-
const ip = route.client_ip;
|
|
408
|
-
emit_after_commit(route, () => deps.audit.emit_pool({
|
|
429
|
+
// delete through this endpoint is audited, in the route's
|
|
430
|
+
// transaction, so the row commits with the delete or neither does.
|
|
431
|
+
// Outside the savepoint's `try`, so a refused audit write fails the
|
|
432
|
+
// request (and rolls the delete back) rather than reading as a row
|
|
433
|
+
// refusal. Account-grain attribution — the browser is a raw storage
|
|
434
|
+
// surface, so no actor is claimed.
|
|
435
|
+
await deps.audit.emit(tx_ctx, {
|
|
409
436
|
event_type: 'db_admin_row_delete',
|
|
410
|
-
account_id,
|
|
411
|
-
ip,
|
|
437
|
+
account_id: route.auth.account.id,
|
|
438
|
+
ip: route.client_ip,
|
|
412
439
|
metadata: { table: name, pk_column, id: deleted_id }
|
|
413
|
-
})
|
|
440
|
+
});
|
|
414
441
|
return route_ok({ success: true });
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
// / 22021 character_not_in_repertoire: the id cannot be coerced
|
|
420
|
-
// to the PK column's type — or cannot even be a text value (a
|
|
421
|
-
// NUL byte, rejected by the server encoding whatever the PK
|
|
422
|
-
// type) — so no row can match; answer with the same masked 404
|
|
423
|
-
// as a typed miss.
|
|
424
|
-
const uncoercible = code === '22P02' || code === '22003' || code === '22021';
|
|
425
|
-
// 23503 foreign_key_violation / 23001 restrict_violation — the
|
|
426
|
-
// same referencing-row refusal. Which one depends on the
|
|
427
|
-
// constraint: `ON DELETE RESTRICT` raises 23001 on PG 18, PGlite
|
|
428
|
-
// and pglet (23503 on PG ≤17), and `NO ACTION` — the default,
|
|
429
|
-
// when the constraint names no action — raises 23503 on all of
|
|
430
|
-
// them.
|
|
431
|
-
const referenced = code === '23503' || code === '23001';
|
|
432
|
-
// anything else fails the request, and the route's transaction
|
|
433
|
-
// rolls back whole
|
|
434
|
-
if (!uncoercible && !referenced)
|
|
435
|
-
throw err;
|
|
436
|
-
// the refusal answers normally, so the transaction must commit
|
|
437
|
-
if (savepoint)
|
|
438
|
-
await route.db.query('ROLLBACK TO SAVEPOINT db_admin_row_delete');
|
|
439
|
-
if (uncoercible) {
|
|
440
|
-
return route_fail(REST_ROW_NOT_FOUND);
|
|
441
|
-
}
|
|
442
|
-
const pg_err = err;
|
|
443
|
-
log?.warn('Foreign key violation:', pg_err.detail, pg_err.constraint);
|
|
444
|
-
return route_fail(REST_FOREIGN_KEY_VIOLATION);
|
|
445
|
-
}
|
|
442
|
+
};
|
|
443
|
+
return route.db.in_transaction
|
|
444
|
+
? delete_row(route)
|
|
445
|
+
: transaction_with_post_commit_rollback(route, delete_row);
|
|
446
446
|
}
|
|
447
447
|
})
|
|
448
448
|
];
|
package/dist/http/origin.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Request source verification middleware for API protection.
|
|
3
3
|
*
|
|
4
|
-
* Verifies requests carry an `Origin` the server allows, or none.
|
|
5
|
-
* CSRF
|
|
6
|
-
* (
|
|
7
|
-
* (`http/simple_request.ts`)
|
|
8
|
-
* include every other port on the same host
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* the WebSocket upgrade, which is never preflighted.
|
|
4
|
+
* Verifies requests carry an `Origin` the server allows, or none. The origin
|
|
5
|
+
* check is one of three CSRF layers, beside `SameSite: strict` session
|
|
6
|
+
* cookies (`auth/session_middleware.ts`) and the JSON-only `POST` refusal
|
|
7
|
+
* (`http/simple_request.ts`): `SameSite` alone admits same-site pages, which
|
|
8
|
+
* include every other port on the same host, and the origin check refuses an
|
|
9
|
+
* untrusted page's request before any handler runs. It is the only one of the
|
|
10
|
+
* three that guards the WebSocket upgrade, which is never preflighted.
|
|
12
11
|
*
|
|
13
12
|
* The allowlist grammar is shared with the Rust spine entry for entry:
|
|
14
13
|
* `parse_allowed_origins` accepts and refuses the same entries, naming each
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"origin.d.ts","sourceRoot":"","sources":["../../src/lib/http/origin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI/D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,mWAiBjC,CAAC;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,uBAAuB,iXAAwD,CAAC;AAC7F,MAAM,MAAM,uBAAuB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAE5E,wDAAwD;AACxD,eAAO,MAAM,8BAA8B,EAAE,QAAQ,CAAC,MAAM,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAwB5F,CAAC;AAEF,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GAAI,OAAO,mBAAmB,KAAG,MAOzE,CAAC;AAKF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAKxC,CAAC;AAUL;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,qBAAqB,GACjC,KAAK,MAAM,KACT,MAAM,CACR;IAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;CAAE,EAC1D;IAAE,MAAM,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;CAAE,CAqBtC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uFAAuF;IACvF,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACnD,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;CAC1C;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,aAAa,GAAG,SAGlE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,MAAM,EACd,kBAAkB,aAAa,CAAC,MAAM,CAAC,KACrC,OAAqF,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,qBAAqB,GAEhC,kBAAkB,aAAa,CAAC,MAAM,CAAC,EACvC,aAAY,aAAa,CAAC,kBAAkB,CAAM,KAChD,OAcF,CAAC"}
|
package/dist/http/origin.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Request source verification middleware for API protection.
|
|
3
3
|
*
|
|
4
|
-
* Verifies requests carry an `Origin` the server allows, or none.
|
|
5
|
-
* CSRF
|
|
6
|
-
* (
|
|
7
|
-
* (`http/simple_request.ts`)
|
|
8
|
-
* include every other port on the same host
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* the WebSocket upgrade, which is never preflighted.
|
|
4
|
+
* Verifies requests carry an `Origin` the server allows, or none. The origin
|
|
5
|
+
* check is one of three CSRF layers, beside `SameSite: strict` session
|
|
6
|
+
* cookies (`auth/session_middleware.ts`) and the JSON-only `POST` refusal
|
|
7
|
+
* (`http/simple_request.ts`): `SameSite` alone admits same-site pages, which
|
|
8
|
+
* include every other port on the same host, and the origin check refuses an
|
|
9
|
+
* untrusted page's request before any handler runs. It is the only one of the
|
|
10
|
+
* three that guards the WebSocket upgrade, which is never preflighted.
|
|
12
11
|
*
|
|
13
12
|
* The allowlist grammar is shared with the Rust spine entry for entry:
|
|
14
13
|
* `parse_allowed_origins` accepts and refuses the same entries, naming each
|
|
@@ -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).
|
|
@@ -40,6 +46,7 @@
|
|
|
40
46
|
* @module
|
|
41
47
|
*/
|
|
42
48
|
import type { Logger } from '@fuzdev/fuz_util/log.ts';
|
|
49
|
+
import type { Db } from '../db/db.js';
|
|
43
50
|
/**
|
|
44
51
|
* Context passed to `on_effect_error` when an eager pending effect rejects.
|
|
45
52
|
*/
|
|
@@ -102,8 +109,10 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
|
|
|
102
109
|
*
|
|
103
110
|
* Both dispatch sites — the REST route wrapper (`http/route_spec.ts`) and the
|
|
104
111
|
* 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
|
|
106
|
-
*
|
|
112
|
+
* their handler call in this so the discard contract lives in one place, and a
|
|
113
|
+
* handler that opens its own transaction runs it through
|
|
114
|
+
* `transaction_with_post_commit_rollback`, the same truncation around just
|
|
115
|
+
* that transaction. The Rust `fuz_actions` spine pins the same contract.
|
|
107
116
|
*
|
|
108
117
|
* `post_commit_effects` is `undefined` when a handler runs without the
|
|
109
118
|
* app-server pending-effects middleware (bare route / dispatch harnesses):
|
|
@@ -114,6 +123,36 @@ export declare const emit_after_commit: (ctx: EmitAfterCommitContext, fn: () =>
|
|
|
114
123
|
* @mutates `post_commit_effects` - truncated to its pre-dispatch depth on throw
|
|
115
124
|
*/
|
|
116
125
|
export declare const dispatch_with_post_commit_rollback: <T>(post_commit_effects: Array<() => void | Promise<void>> | undefined, dispatch: () => T | Promise<T>) => Promise<Awaited<T>>;
|
|
126
|
+
/**
|
|
127
|
+
* A request's `db` and its two side-effect queues — what a handler that opens
|
|
128
|
+
* its own transaction hands `transaction_with_post_commit_rollback`, and what
|
|
129
|
+
* that transaction's callback gets back with `db` swapped for the transaction.
|
|
130
|
+
* `RouteContext` and `ActionContext` satisfy it, and so does the callback's
|
|
131
|
+
* context, so either can be passed to `AuditEmitter.emit`.
|
|
132
|
+
*/
|
|
133
|
+
export interface RequestEffectsContext extends EmitAfterCommitContext {
|
|
134
|
+
db: Db;
|
|
135
|
+
pending_effects: Array<Promise<void>>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Run `fn` in a transaction a handler opens on its own `db` (a route with
|
|
139
|
+
* `transaction: false`, which keeps its rate-limit waits and Argon2 work off a
|
|
140
|
+
* connection), discarding the `post_commit_effects` `fn` queued when that
|
|
141
|
+
* transaction rolls back.
|
|
142
|
+
*
|
|
143
|
+
* `dispatch_with_post_commit_rollback` discards them only when the handler
|
|
144
|
+
* throws; a handler that catches its own transaction's failure and answers a
|
|
145
|
+
* refusal (signup's classified conflicts, bootstrap's undeletable token file)
|
|
146
|
+
* would otherwise leave a queued fan-out — a success row's announcement — to
|
|
147
|
+
* fire for writes that rolled back. The truncation is the same: back to the
|
|
148
|
+
* depth before the transaction, the error rethrown unchanged.
|
|
149
|
+
*
|
|
150
|
+
* @param ctx - the request's `db` and queues; `ctx.db` must not already be a transaction
|
|
151
|
+
* @param fn - the transaction's work, given `ctx` with `db` the transaction
|
|
152
|
+
* @returns what `fn` returns, once the transaction has committed
|
|
153
|
+
* @mutates `ctx.post_commit_effects` - truncated to its pre-transaction depth on rollback
|
|
154
|
+
*/
|
|
155
|
+
export declare const transaction_with_post_commit_rollback: <T>(ctx: RequestEffectsContext, fn: (tx_ctx: RequestEffectsContext) => Promise<T>) => Promise<Awaited<T>>;
|
|
117
156
|
/**
|
|
118
157
|
* Drain an eager `pending_effects` queue: `Promise.allSettled` the
|
|
119
158
|
* in-flight handles, route every rejection through `log.error`, and
|
|
@@ -146,7 +185,9 @@ export declare const flush_post_commit_effects: (effects: ReadonlyArray<() => vo
|
|
|
146
185
|
* that needs a write awaits it itself. Eager rejections are logged and passed
|
|
147
186
|
* to `on_rejection` (the server's `on_effect_error`). The caller picks whether
|
|
148
187
|
* to await the returned promise — HTTP awaits it in test mode only, WS awaits
|
|
149
|
-
* it per frame after the reply is sent
|
|
188
|
+
* it per frame after the reply is sent — and hands it to its request's
|
|
189
|
+
* `AcceptedRequest.finish` either way, so `AppServer.close` waits for it.
|
|
190
|
+
* Never rejects.
|
|
150
191
|
*
|
|
151
192
|
* @param pending_effects - the eager queue of in-flight pool writes
|
|
152
193
|
* @param post_commit_effects - the deferred thunks queued by `emit_after_commit`
|
|
@@ -154,4 +195,75 @@ export declare const flush_post_commit_effects: (effects: ReadonlyArray<() => vo
|
|
|
154
195
|
* @param on_rejection - optional fan-out for each eager rejection
|
|
155
196
|
*/
|
|
156
197
|
export declare const flush_request_effects: (pending_effects: ReadonlyArray<Promise<void>>, post_commit_effects: ReadonlyArray<() => void | Promise<void>>, log: Logger, on_rejection?: (reason: unknown) => void) => Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Every request the server accepted — an HTTP request, a WS message accepted
|
|
200
|
+
* for dispatch — held from acceptance until its handler has returned and its
|
|
201
|
+
* effect flush has settled, so `AppServer.close` can wait for both before the
|
|
202
|
+
* database closes. One tracker per backend (`AppDeps.request_tracker`), shared
|
|
203
|
+
* by every transport, so a request is held the same way whichever transport
|
|
204
|
+
* accepted it. Its `drain_inflight` / `inflight_count` match `AuditEmitter`'s,
|
|
205
|
+
* the other set the shutdown drain waits on.
|
|
206
|
+
*
|
|
207
|
+
* The flushes are held apart as well, for a drain that must not wait on a
|
|
208
|
+
* running handler — `_testing_drain_effects`, whose own request is one: a
|
|
209
|
+
* flush is tracked only once its handler has returned, so a drain waiting on
|
|
210
|
+
* flushes never waits on itself.
|
|
211
|
+
*/
|
|
212
|
+
export interface RequestTracker {
|
|
213
|
+
/**
|
|
214
|
+
* Hold a request from the moment it is accepted, before its handler runs.
|
|
215
|
+
* Call before any work that can throw, and end it with
|
|
216
|
+
* `AcceptedRequest.finish` on every path. Answers `null` once the tracker
|
|
217
|
+
* is closed: the request is refused, never run.
|
|
218
|
+
*
|
|
219
|
+
* @mutates the tracker - adds the request, removed once it finishes and its flush settles
|
|
220
|
+
*/
|
|
221
|
+
accept: () => AcceptedRequest | null;
|
|
222
|
+
/**
|
|
223
|
+
* Refuse every later `accept`, so nothing new starts against a database
|
|
224
|
+
* about to close. Requests already held are kept and still drained.
|
|
225
|
+
* Idempotent.
|
|
226
|
+
*/
|
|
227
|
+
close: () => void;
|
|
228
|
+
/**
|
|
229
|
+
* Wait until no request is held — handler or flush — not for a snapshot:
|
|
230
|
+
* a request accepted while waiting is awaited too. Never rejects.
|
|
231
|
+
*
|
|
232
|
+
* Never call it from inside a request: the caller is held, so it waits on
|
|
233
|
+
* itself forever. A request awaits `drain_flushes` instead.
|
|
234
|
+
*/
|
|
235
|
+
drain_inflight: () => Promise<void>;
|
|
236
|
+
/** How many requests are held: a handler still running, or a flush. */
|
|
237
|
+
inflight_count: () => number;
|
|
238
|
+
/**
|
|
239
|
+
* Wait until no flush is running — not for a snapshot, and never for a
|
|
240
|
+
* handler still running. Never rejects. The one drain a request may await:
|
|
241
|
+
* its own flush starts only after its handler returns.
|
|
242
|
+
*/
|
|
243
|
+
drain_flushes: () => Promise<void>;
|
|
244
|
+
/** How many flushes are running — of requests whose handler has returned. */
|
|
245
|
+
flush_count: () => number;
|
|
246
|
+
}
|
|
247
|
+
/** A request `RequestTracker.accept` holds. */
|
|
248
|
+
export interface AcceptedRequest {
|
|
249
|
+
/**
|
|
250
|
+
* End the request once its handler has returned: it is released when
|
|
251
|
+
* `flush` settles, at once with no flush. `flush` must never reject —
|
|
252
|
+
* `flush_request_effects` doesn't. A second call does nothing.
|
|
253
|
+
*/
|
|
254
|
+
finish: (flush: Promise<void> | null) => void;
|
|
255
|
+
}
|
|
256
|
+
/** Create an empty, open `RequestTracker`. */
|
|
257
|
+
export declare const create_request_tracker: () => RequestTracker;
|
|
258
|
+
/**
|
|
259
|
+
* A view of `parent` with its own `close`: `accept` refuses once the view is
|
|
260
|
+
* closed and otherwise holds the request on `parent`; the drains and counts
|
|
261
|
+
* are `parent`'s, so they cover every server on the backend, not only the
|
|
262
|
+
* requests this view accepted. One server's admission over its backend's tracker —
|
|
263
|
+
* `AppServer.close` closes its view, so the backend's tracker stays open for
|
|
264
|
+
* a server assembled on it later.
|
|
265
|
+
*
|
|
266
|
+
* @param parent - the tracker requests are held on
|
|
267
|
+
*/
|
|
268
|
+
export declare const create_request_tracker_view: (parent: RequestTracker) => RequestTracker;
|
|
157
269
|
//# sourceMappingURL=pending_effects.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pending_effects.d.ts","sourceRoot":"","sources":["../../src/lib/http/pending_effects.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pending_effects.d.ts","sourceRoot":"","sources":["../../src/lib/http/pending_effects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC;;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,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CACvD;AAED;;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