@adaptic/backend 0.0.1041 → 0.0.1043
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/esm/auth/authorization-map.d.ts +23 -1
- package/esm/auth/authorization-map.d.ts.map +1 -1
- package/esm/auth/authorization-map.js.map +1 -1
- package/esm/auth/authorization-map.mjs +24 -1
- package/esm/health.d.ts +65 -2
- package/esm/health.d.ts.map +1 -1
- package/esm/health.js.map +1 -1
- package/esm/health.mjs +141 -4
- package/esm/prismaClient.d.ts +38 -0
- package/esm/prismaClient.d.ts.map +1 -1
- package/esm/prismaClient.js.map +1 -1
- package/esm/prismaClient.mjs +59 -6
- package/health.cjs +178 -7
- package/health.d.ts +65 -2
- package/package.json +1 -1
- package/prismaClient.cjs +67 -11
- package/prismaClient.d.ts +38 -0
|
@@ -57,7 +57,29 @@ export declare const IR_MODELS: readonly EnhanceModelName[];
|
|
|
57
57
|
*
|
|
58
58
|
* Decorating them changes NO behaviour while the checker is in shadow — a
|
|
59
59
|
* would-deny is logged and counted and then allowed. What it changes is that
|
|
60
|
-
* the exposure becomes measurable.
|
|
60
|
+
* the exposure becomes measurable.
|
|
61
|
+
*
|
|
62
|
+
* `Fund` joined them on 2026-09-27, and it is the one admission that corrects a
|
|
63
|
+
* belief rather than adding a surface. The exposure is an unauthenticated
|
|
64
|
+
* request receiving HTTP 200 with every fund's P&L — measured on the deployed
|
|
65
|
+
* API by Sophie Nguyen at 02:42Z and independently by James Kirkland at
|
|
66
|
+
* 09:46:56Z, not inferred from the schema. `Fund` carries `aum`,
|
|
67
|
+
* `navPerShare` and `highWaterMarkNav`.
|
|
68
|
+
*
|
|
69
|
+
* The belief it corrects: this gap was being treated as something the
|
|
70
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` flip would close. **It would not have.** `Fund`
|
|
71
|
+
* was in neither list, so its reads were never decorated, so the checker never
|
|
72
|
+
* ran for them — and per the paragraph above, a query the checker never runs
|
|
73
|
+
* for is a query it cannot even count. Waiting for the enforcement flip would
|
|
74
|
+
* have closed the four models here and left every fund's P&L answering to
|
|
75
|
+
* anyone, with nothing in the would-deny ratio to show it. Coverage and
|
|
76
|
+
* enforcement are separate axes and only one of them was being tracked.
|
|
77
|
+
*
|
|
78
|
+
* `FundAssignment` is a candidate and is deliberately NOT admitted here. It
|
|
79
|
+
* reveals which accounts belong to which fund, which is structural rather than
|
|
80
|
+
* P&L, and no anonymous probe of it has been run. Admitting it on inspection
|
|
81
|
+
* would break the criterion this list is built on — by measurement, not by
|
|
82
|
+
* reading the schema. Measure it, then admit it. Enforcement cannot be argued from a
|
|
61
83
|
* would-deny ratio that reflects only surfaces nobody ever authenticated to,
|
|
62
84
|
* and the measurement has to exist before the decision does.
|
|
63
85
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-map.d.ts","sourceRoot":"","sources":["../../../src/auth/authorization-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AAIzC,yEAAyE;AACzE,KAAK,gBAAgB,GAAG,MAAM,mBAAmB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,gBAAgB,EAMhD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"authorization-map.d.ts","sourceRoot":"","sources":["../../../src/auth/authorization-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AAIzC,yEAAyE;AACzE,KAAK,gBAAgB,GAAG,MAAM,mBAAmB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,gBAAgB,EAMhD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,eAAO,MAAM,yBAAyB,EAAE,SAAS,gBAAgB,EAMhE,CAAC;AAmCF,mEAAmE;AACnE,MAAM,WAAW,uBAAuB;IACtC,yDAAyD;IACzD,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,oDAAoD;IACpD,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,4FAA4F;IAC5F,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,0EAA0E;IAC1E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAmBD,6DAA6D;AAC7D,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,IAAI,qBAAqB,CAoEnE;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,IAAI,uBAAuB,CAcrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-map.js","sourceRoot":"","sources":["../../../src/auth/authorization-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,wBAAwB,GAEzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAgC;IACpD,UAAU;IACV,SAAS;IACT,qBAAqB;IACrB,kBAAkB;IAClB,aAAa;CACd,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"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,OAAO;QACL,GAAG;QACH,OAAO,EAAE;YACP,kBAAkB,EAAE,SAAS,CAAC,MAAM;YACpC,oBAAoB;YACpB,kBAAkB;YAClB,gBAAgB;YAChB,cAAc;SACf;KACF,CAAC;AACJ,CAAC;AAED,IAAI,cAAmD,CAAC;AAExD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B;IACzC,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,2BAA2B,EAAE,CAAC;IACvD,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,IAAI,CACT,yGAAyG,EACzG,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAC3C,CAAC;IACJ,CAAC;IACD,cAAc,GAAG,OAAO,CAAC;IACzB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -65,7 +65,29 @@ export const IR_MODELS = [
|
|
|
65
65
|
*
|
|
66
66
|
* Decorating them changes NO behaviour while the checker is in shadow — a
|
|
67
67
|
* would-deny is logged and counted and then allowed. What it changes is that
|
|
68
|
-
* the exposure becomes measurable.
|
|
68
|
+
* the exposure becomes measurable.
|
|
69
|
+
*
|
|
70
|
+
* `Fund` joined them on 2026-09-27, and it is the one admission that corrects a
|
|
71
|
+
* belief rather than adding a surface. The exposure is an unauthenticated
|
|
72
|
+
* request receiving HTTP 200 with every fund's P&L — measured on the deployed
|
|
73
|
+
* API by Sophie Nguyen at 02:42Z and independently by James Kirkland at
|
|
74
|
+
* 09:46:56Z, not inferred from the schema. `Fund` carries `aum`,
|
|
75
|
+
* `navPerShare` and `highWaterMarkNav`.
|
|
76
|
+
*
|
|
77
|
+
* The belief it corrects: this gap was being treated as something the
|
|
78
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` flip would close. **It would not have.** `Fund`
|
|
79
|
+
* was in neither list, so its reads were never decorated, so the checker never
|
|
80
|
+
* ran for them — and per the paragraph above, a query the checker never runs
|
|
81
|
+
* for is a query it cannot even count. Waiting for the enforcement flip would
|
|
82
|
+
* have closed the four models here and left every fund's P&L answering to
|
|
83
|
+
* anyone, with nothing in the would-deny ratio to show it. Coverage and
|
|
84
|
+
* enforcement are separate axes and only one of them was being tracked.
|
|
85
|
+
*
|
|
86
|
+
* `FundAssignment` is a candidate and is deliberately NOT admitted here. It
|
|
87
|
+
* reveals which accounts belong to which fund, which is structural rather than
|
|
88
|
+
* P&L, and no anonymous probe of it has been run. Admitting it on inspection
|
|
89
|
+
* would break the criterion this list is built on — by measurement, not by
|
|
90
|
+
* reading the schema. Measure it, then admit it. Enforcement cannot be argued from a
|
|
69
91
|
* would-deny ratio that reflects only surfaces nobody ever authenticated to,
|
|
70
92
|
* and the measurement has to exist before the decision does.
|
|
71
93
|
*/
|
|
@@ -74,6 +96,7 @@ export const TENANT_SCOPED_READ_MODELS = [
|
|
|
74
96
|
'OrgMembership',
|
|
75
97
|
'User',
|
|
76
98
|
'AuditLog',
|
|
99
|
+
'Fund',
|
|
77
100
|
];
|
|
78
101
|
/**
|
|
79
102
|
* Action-name prefixes that MUTATE. Everything else on a generated CRUD
|
package/esm/health.d.ts
CHANGED
|
@@ -1,4 +1,62 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
type DatabaseCheck = 'recent-query' | 'probe';
|
|
3
|
+
/**
|
|
4
|
+
* How recently a query must have completed for `/health` to accept it as
|
|
5
|
+
* proof the database is answering, without issuing a query of its own.
|
|
6
|
+
*
|
|
7
|
+
* Derived from the heartbeat rather than set by hand: it tolerates every
|
|
8
|
+
* heartbeat but the last before reconnection being missed, plus half an
|
|
9
|
+
* interval of slack — `(MAX_HEARTBEAT_FAILURES - 0.5) * HEARTBEAT_INTERVAL_MS`,
|
|
10
|
+
* 75s at the current 3 x 30s. That keeps it longer than one heartbeat interval,
|
|
11
|
+
* so an idle process that the heartbeat keeps refreshing never goes stale, and
|
|
12
|
+
* shorter than the reconnect point, so a database that has stopped answering
|
|
13
|
+
* reads as disconnected before the heartbeat gives up on the client.
|
|
14
|
+
*
|
|
15
|
+
* A saturated pool still completes queries, each bounded by the statement
|
|
16
|
+
* timeout, so saturation alone does not let it go stale — provided that
|
|
17
|
+
* timeout is shorter than this window (see
|
|
18
|
+
* {@link warnIfStatementTimeoutDefeatsFreshness}).
|
|
19
|
+
*/
|
|
20
|
+
export declare const DB_SUCCESS_FRESHNESS_MS: number;
|
|
21
|
+
/**
|
|
22
|
+
* Warn when the configured statement timeout is not shorter than the
|
|
23
|
+
* freshness window.
|
|
24
|
+
*
|
|
25
|
+
* The case for trusting a recent success under saturation is that every query
|
|
26
|
+
* on a busy pool finishes or fails within the statement timeout, so completed
|
|
27
|
+
* queries keep arriving inside {@link DB_SUCCESS_FRESHNESS_MS}. A timeout at or
|
|
28
|
+
* above the window breaks that: a pool full of long-running statements can go
|
|
29
|
+
* a whole window without a completion and `/health` would fall back to a probe
|
|
30
|
+
* that cannot get a connection. A value that is not a positive integer (unset
|
|
31
|
+
* timeouts parse from the default; `0` disables the timeout in Postgres) is
|
|
32
|
+
* treated the same way, since it bounds nothing.
|
|
33
|
+
*
|
|
34
|
+
* @param statementTimeoutMs - The resolved statement timeout (injectable for tests).
|
|
35
|
+
* @returns True if a warning was logged.
|
|
36
|
+
*/
|
|
37
|
+
export declare function warnIfStatementTimeoutDefeatsFreshness(statementTimeoutMs?: number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Budget for the fallback probe when no recent success exists. Well under the
|
|
40
|
+
* 10s pool wait so a saturated pool yields an answer inside the platform's
|
|
41
|
+
* probe timeout rather than hanging the request.
|
|
42
|
+
*/
|
|
43
|
+
export declare const HEALTH_PROBE_TIMEOUT_MS = 2000;
|
|
44
|
+
/**
|
|
45
|
+
* Decide whether the database is answering this process, without depending
|
|
46
|
+
* on a free pool connection when there is already evidence that it is.
|
|
47
|
+
*
|
|
48
|
+
* A query that completed within {@link DB_SUCCESS_FRESHNESS_MS} is taken as
|
|
49
|
+
* that evidence and no query is issued. Only when there is none (startup, or a
|
|
50
|
+
* database that has stopped answering) does it fall back to a bounded probe.
|
|
51
|
+
*
|
|
52
|
+
* @param now - Current epoch ms (injectable for tests).
|
|
53
|
+
* @returns The database status, how it was decided, and the success age.
|
|
54
|
+
*/
|
|
55
|
+
export declare function checkDatabaseReadiness(now?: number): Promise<{
|
|
56
|
+
database: 'connected' | 'disconnected';
|
|
57
|
+
databaseCheck: DatabaseCheck;
|
|
58
|
+
lastQuerySucceededSecondsAgo: number | null;
|
|
59
|
+
}>;
|
|
2
60
|
/**
|
|
3
61
|
* Creates an Express router with health-probe endpoints.
|
|
4
62
|
*
|
|
@@ -9,11 +67,16 @@ import { Router } from 'express';
|
|
|
9
67
|
* is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
|
|
10
68
|
* startup probes and load-balancer readiness.
|
|
11
69
|
* - `GET /health` — Full health snapshot including memory usage and database
|
|
12
|
-
* status. Returns 503 when the database
|
|
13
|
-
*
|
|
70
|
+
* status. Returns 503 only when the database has stopped answering this
|
|
71
|
+
* process: a query that completed within the freshness window counts as
|
|
72
|
+
* proof without taking a pool connection, so a saturated-but-working pool
|
|
73
|
+
* reads as healthy. With no recent success it falls back to a bounded
|
|
74
|
+
* probe (see {@link checkDatabaseReadiness}). Kept for backward
|
|
75
|
+
* compatibility with existing Railway/uptime checks.
|
|
14
76
|
*
|
|
15
77
|
* All endpoints should be mounted before auth middleware so they remain
|
|
16
78
|
* accessible without authentication.
|
|
17
79
|
*/
|
|
18
80
|
export declare function createHealthRouter(): Router;
|
|
81
|
+
export {};
|
|
19
82
|
//# sourceMappingURL=health.d.ts.map
|
package/esm/health.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAgDpD,KAAK,aAAa,GAAG,cAAc,GAAG,OAAO,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,QACoB,CAAC;AAEzD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sCAAsC,CACpD,kBAAkB,GAAE,MAAoC,GACvD,OAAO,CAgBT;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,OAAQ,CAAC;AAqD7C;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAC1C,GAAG,GAAE,MAAmB,GACvB,OAAO,CAAC;IACT,QAAQ,EAAE,WAAW,GAAG,cAAc,CAAC;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C,CAAC,CAuBD;AAkBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAuD3C"}
|
package/esm/health.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,MAAM,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,MAAM,EAAE,EACb,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAA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AAmB;YAC3B,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU;YACrC,OAAO,EAAE,YAAY;YACrB,OAAO,EAAE,eAAe;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;YACnD,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;gBAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAC;gBACxD,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;aAC3D;YACD,QAAQ,EAAE,cAAc;YACxB,aAAa,EAAE,SAAS,CAAC,aAAa;YACtC,4BAA4B,EAAE,SAAS,CAAC,4BAA4B;SACrE,CAAC;QAEF,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/esm/health.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import prisma from './prismaClient.mjs';
|
|
2
|
+
import prisma, { getLastQuerySucceededAt, HEARTBEAT_INTERVAL_MS, MAX_HEARTBEAT_FAILURES, resolveStatementTimeoutMs, } from './prismaClient.mjs';
|
|
3
3
|
import { logger } from './utils/logger.mjs';
|
|
4
4
|
const SERVICE_NAME = 'backend-legacy';
|
|
5
5
|
/**
|
|
@@ -18,6 +18,135 @@ function getPackageVersion() {
|
|
|
18
18
|
const PACKAGE_VERSION = getPackageVersion();
|
|
19
19
|
/** Tracks the process start time for uptime calculation */
|
|
20
20
|
const startedAt = Date.now();
|
|
21
|
+
/**
|
|
22
|
+
* How recently a query must have completed for `/health` to accept it as
|
|
23
|
+
* proof the database is answering, without issuing a query of its own.
|
|
24
|
+
*
|
|
25
|
+
* Derived from the heartbeat rather than set by hand: it tolerates every
|
|
26
|
+
* heartbeat but the last before reconnection being missed, plus half an
|
|
27
|
+
* interval of slack — `(MAX_HEARTBEAT_FAILURES - 0.5) * HEARTBEAT_INTERVAL_MS`,
|
|
28
|
+
* 75s at the current 3 x 30s. That keeps it longer than one heartbeat interval,
|
|
29
|
+
* so an idle process that the heartbeat keeps refreshing never goes stale, and
|
|
30
|
+
* shorter than the reconnect point, so a database that has stopped answering
|
|
31
|
+
* reads as disconnected before the heartbeat gives up on the client.
|
|
32
|
+
*
|
|
33
|
+
* A saturated pool still completes queries, each bounded by the statement
|
|
34
|
+
* timeout, so saturation alone does not let it go stale — provided that
|
|
35
|
+
* timeout is shorter than this window (see
|
|
36
|
+
* {@link warnIfStatementTimeoutDefeatsFreshness}).
|
|
37
|
+
*/
|
|
38
|
+
export const DB_SUCCESS_FRESHNESS_MS = (MAX_HEARTBEAT_FAILURES - 0.5) * HEARTBEAT_INTERVAL_MS;
|
|
39
|
+
/**
|
|
40
|
+
* Warn when the configured statement timeout is not shorter than the
|
|
41
|
+
* freshness window.
|
|
42
|
+
*
|
|
43
|
+
* The case for trusting a recent success under saturation is that every query
|
|
44
|
+
* on a busy pool finishes or fails within the statement timeout, so completed
|
|
45
|
+
* queries keep arriving inside {@link DB_SUCCESS_FRESHNESS_MS}. A timeout at or
|
|
46
|
+
* above the window breaks that: a pool full of long-running statements can go
|
|
47
|
+
* a whole window without a completion and `/health` would fall back to a probe
|
|
48
|
+
* that cannot get a connection. A value that is not a positive integer (unset
|
|
49
|
+
* timeouts parse from the default; `0` disables the timeout in Postgres) is
|
|
50
|
+
* treated the same way, since it bounds nothing.
|
|
51
|
+
*
|
|
52
|
+
* @param statementTimeoutMs - The resolved statement timeout (injectable for tests).
|
|
53
|
+
* @returns True if a warning was logged.
|
|
54
|
+
*/
|
|
55
|
+
export function warnIfStatementTimeoutDefeatsFreshness(statementTimeoutMs = resolveStatementTimeoutMs()) {
|
|
56
|
+
if (Number.isFinite(statementTimeoutMs) &&
|
|
57
|
+
statementTimeoutMs > 0 &&
|
|
58
|
+
statementTimeoutMs < DB_SUCCESS_FRESHNESS_MS) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
logger.warn('DATABASE_STATEMENT_TIMEOUT_MS is not shorter than the /health freshness window — a saturated pool can read as disconnected', {
|
|
62
|
+
statementTimeoutMs,
|
|
63
|
+
freshnessWindowMs: DB_SUCCESS_FRESHNESS_MS,
|
|
64
|
+
});
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Budget for the fallback probe when no recent success exists. Well under the
|
|
69
|
+
* 10s pool wait so a saturated pool yields an answer inside the platform's
|
|
70
|
+
* probe timeout rather than hanging the request.
|
|
71
|
+
*/
|
|
72
|
+
export const HEALTH_PROBE_TIMEOUT_MS = 2_000;
|
|
73
|
+
/** The one probe query this module may have outstanding on the pool. */
|
|
74
|
+
let outstandingProbe;
|
|
75
|
+
/**
|
|
76
|
+
* Probe the live client with `SELECT 1`, giving up after `timeoutMs`.
|
|
77
|
+
*
|
|
78
|
+
* Reads `global.prisma` rather than the module-level import, because the
|
|
79
|
+
* heartbeat's reconnect path replaces `global.prisma` and the import stays
|
|
80
|
+
* pinned to the original (by then disconnected) client.
|
|
81
|
+
*
|
|
82
|
+
* At most one probe query is ever outstanding: a caller that arrives while a
|
|
83
|
+
* previous probe is still queued on the pool waits on that same query instead
|
|
84
|
+
* of adding another waiter, so frequent health checks cannot themselves deepen
|
|
85
|
+
* a saturated pool's queue.
|
|
86
|
+
*
|
|
87
|
+
* @param timeoutMs - How long to wait for the probe before calling it failed.
|
|
88
|
+
* @returns True if the probe completed within the budget.
|
|
89
|
+
*/
|
|
90
|
+
async function probeLiveClient(timeoutMs) {
|
|
91
|
+
if (!outstandingProbe) {
|
|
92
|
+
const client = global.prisma ?? prisma;
|
|
93
|
+
outstandingProbe = Promise.resolve(client.$queryRaw `SELECT 1`).finally(() => {
|
|
94
|
+
outstandingProbe = undefined;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
const probe = outstandingProbe;
|
|
98
|
+
let timer;
|
|
99
|
+
const timedOut = new Promise((resolve) => {
|
|
100
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
101
|
+
});
|
|
102
|
+
try {
|
|
103
|
+
return await Promise.race([
|
|
104
|
+
probe.then(() => true, (dbError) => {
|
|
105
|
+
logger.warn('Health check: database probe failed', {
|
|
106
|
+
error: dbError instanceof Error ? dbError.message : String(dbError),
|
|
107
|
+
});
|
|
108
|
+
return false;
|
|
109
|
+
}),
|
|
110
|
+
timedOut,
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Decide whether the database is answering this process, without depending
|
|
119
|
+
* on a free pool connection when there is already evidence that it is.
|
|
120
|
+
*
|
|
121
|
+
* A query that completed within {@link DB_SUCCESS_FRESHNESS_MS} is taken as
|
|
122
|
+
* that evidence and no query is issued. Only when there is none (startup, or a
|
|
123
|
+
* database that has stopped answering) does it fall back to a bounded probe.
|
|
124
|
+
*
|
|
125
|
+
* @param now - Current epoch ms (injectable for tests).
|
|
126
|
+
* @returns The database status, how it was decided, and the success age.
|
|
127
|
+
*/
|
|
128
|
+
export async function checkDatabaseReadiness(now = Date.now()) {
|
|
129
|
+
const lastSuccess = getLastQuerySucceededAt();
|
|
130
|
+
const ageMs = lastSuccess === undefined ? undefined : now - lastSuccess;
|
|
131
|
+
if (ageMs !== undefined && ageMs <= DB_SUCCESS_FRESHNESS_MS) {
|
|
132
|
+
return {
|
|
133
|
+
database: 'connected',
|
|
134
|
+
databaseCheck: 'recent-query',
|
|
135
|
+
lastQuerySucceededSecondsAgo: Math.max(0, Math.floor(ageMs / 1000)),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const answered = await probeLiveClient(HEALTH_PROBE_TIMEOUT_MS);
|
|
139
|
+
// A successful probe goes through the same client extension and refreshes
|
|
140
|
+
// the stamp; report the age as it stands after the probe.
|
|
141
|
+
const after = getLastQuerySucceededAt();
|
|
142
|
+
return {
|
|
143
|
+
database: answered ? 'connected' : 'disconnected',
|
|
144
|
+
databaseCheck: 'probe',
|
|
145
|
+
lastQuerySucceededSecondsAgo: after === undefined
|
|
146
|
+
? null
|
|
147
|
+
: Math.max(0, Math.floor((Date.now() - after) / 1000)),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
21
150
|
/**
|
|
22
151
|
* Checks database connectivity by issuing a lightweight query.
|
|
23
152
|
* Returns 'connected' or 'disconnected'. Never throws.
|
|
@@ -44,13 +173,18 @@ async function checkDatabase() {
|
|
|
44
173
|
* is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
|
|
45
174
|
* startup probes and load-balancer readiness.
|
|
46
175
|
* - `GET /health` — Full health snapshot including memory usage and database
|
|
47
|
-
* status. Returns 503 when the database
|
|
48
|
-
*
|
|
176
|
+
* status. Returns 503 only when the database has stopped answering this
|
|
177
|
+
* process: a query that completed within the freshness window counts as
|
|
178
|
+
* proof without taking a pool connection, so a saturated-but-working pool
|
|
179
|
+
* reads as healthy. With no recent success it falls back to a bounded
|
|
180
|
+
* probe (see {@link checkDatabaseReadiness}). Kept for backward
|
|
181
|
+
* compatibility with existing Railway/uptime checks.
|
|
49
182
|
*
|
|
50
183
|
* All endpoints should be mounted before auth middleware so they remain
|
|
51
184
|
* accessible without authentication.
|
|
52
185
|
*/
|
|
53
186
|
export function createHealthRouter() {
|
|
187
|
+
warnIfStatementTimeoutDefeatsFreshness();
|
|
54
188
|
const router = Router();
|
|
55
189
|
router.get('/livez', (_req, res) => {
|
|
56
190
|
res.status(200).json({
|
|
@@ -73,7 +207,8 @@ export function createHealthRouter() {
|
|
|
73
207
|
});
|
|
74
208
|
});
|
|
75
209
|
router.get('/health', async (_req, res) => {
|
|
76
|
-
const
|
|
210
|
+
const readiness = await checkDatabaseReadiness();
|
|
211
|
+
const databaseStatus = readiness.database;
|
|
77
212
|
const isHealthy = databaseStatus === 'connected';
|
|
78
213
|
const statusCode = isHealthy ? 200 : 503;
|
|
79
214
|
const memoryUsage = process.memoryUsage();
|
|
@@ -89,6 +224,8 @@ export function createHealthRouter() {
|
|
|
89
224
|
heapTotal: Math.round(memoryUsage.heapTotal / 1024 / 1024),
|
|
90
225
|
},
|
|
91
226
|
database: databaseStatus,
|
|
227
|
+
databaseCheck: readiness.databaseCheck,
|
|
228
|
+
lastQuerySucceededSecondsAgo: readiness.lastQuerySucceededSecondsAgo,
|
|
92
229
|
};
|
|
93
230
|
res.status(statusCode).json(body);
|
|
94
231
|
});
|
package/esm/prismaClient.d.ts
CHANGED
|
@@ -29,6 +29,28 @@ export declare const DEFAULT_FIND_MANY_TAKE = 50000;
|
|
|
29
29
|
* @returns The row ceiling to apply to an unqualified `findMany`.
|
|
30
30
|
*/
|
|
31
31
|
export declare function resolveFindManyTake(): number;
|
|
32
|
+
/**
|
|
33
|
+
* When a query on this process's Prisma client last completed successfully.
|
|
34
|
+
*
|
|
35
|
+
* This is the evidence `/health` uses for "the database is answering this
|
|
36
|
+
* process". It is recorded as a side effect of ordinary traffic and of the
|
|
37
|
+
* heartbeat, so reading it never needs a pool connection — which is the point:
|
|
38
|
+
* a pool that is saturated but still completing work keeps this fresh, and a
|
|
39
|
+
* database that has stopped answering lets it go stale.
|
|
40
|
+
*
|
|
41
|
+
* @returns Epoch milliseconds of the last success, or undefined if none yet.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getLastQuerySucceededAt(): number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Run a query and stamp the success time if it resolves.
|
|
46
|
+
*
|
|
47
|
+
* A rejected query leaves the stamp alone; any completed round trip, including
|
|
48
|
+
* one issued by a caller that has since given up waiting on it, refreshes it.
|
|
49
|
+
*
|
|
50
|
+
* @param run - Executes the underlying operation.
|
|
51
|
+
* @returns Whatever the operation returned.
|
|
52
|
+
*/
|
|
53
|
+
export declare function stampQuerySuccess<T>(run: () => Promise<T>): Promise<T>;
|
|
32
54
|
/**
|
|
33
55
|
* Apply the unqualified-`findMany` ceiling to a Prisma client.
|
|
34
56
|
*
|
|
@@ -47,6 +69,22 @@ export declare function resolveFindManyTake(): number;
|
|
|
47
69
|
* @returns The client with the ceiling applied.
|
|
48
70
|
*/
|
|
49
71
|
export declare function withFindManyGuard(client: PrismaClient): PrismaClient;
|
|
72
|
+
/** Default statement timeout (30s) prevents hung queries from blocking pool slots indefinitely */
|
|
73
|
+
export declare const DEFAULT_STATEMENT_TIMEOUT_MS = 30000;
|
|
74
|
+
/** Heartbeat interval: how often we verify the DB connection is alive */
|
|
75
|
+
export declare const HEARTBEAT_INTERVAL_MS = 30000;
|
|
76
|
+
/** Consecutive heartbeat failures before triggering client reconnection */
|
|
77
|
+
export declare const MAX_HEARTBEAT_FAILURES = 3;
|
|
78
|
+
/**
|
|
79
|
+
* Resolve the per-statement timeout appended to a direct Postgres URL.
|
|
80
|
+
*
|
|
81
|
+
* Parsed exactly as the URL builder has always parsed it, so a value that is
|
|
82
|
+
* not a positive integer comes back as-is (NaN, 0, negative) for the caller to
|
|
83
|
+
* judge rather than being silently replaced.
|
|
84
|
+
*
|
|
85
|
+
* @returns The statement timeout in milliseconds.
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveStatementTimeoutMs(): number;
|
|
50
88
|
declare const prisma: PrismaClient;
|
|
51
89
|
/**
|
|
52
90
|
* Starts the periodic database heartbeat monitor.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prismaClient.d.ts","sourceRoot":"","sources":["../../src/prismaClient.ts"],"names":[],"mappings":"AA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() {
|
|
|
42
42
|
}
|
|
43
43
|
return parsed;
|
|
44
44
|
}
|
|
45
|
+
/** Wall-clock ms of the most recent query that completed successfully, or undefined before the first. */
|
|
46
|
+
let lastQuerySucceededAt;
|
|
47
|
+
/**
|
|
48
|
+
* When a query on this process's Prisma client last completed successfully.
|
|
49
|
+
*
|
|
50
|
+
* This is the evidence `/health` uses for "the database is answering this
|
|
51
|
+
* process". It is recorded as a side effect of ordinary traffic and of the
|
|
52
|
+
* heartbeat, so reading it never needs a pool connection — which is the point:
|
|
53
|
+
* a pool that is saturated but still completing work keeps this fresh, and a
|
|
54
|
+
* database that has stopped answering lets it go stale.
|
|
55
|
+
*
|
|
56
|
+
* @returns Epoch milliseconds of the last success, or undefined if none yet.
|
|
57
|
+
*/
|
|
58
|
+
export function getLastQuerySucceededAt() {
|
|
59
|
+
return lastQuerySucceededAt;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Run a query and stamp the success time if it resolves.
|
|
63
|
+
*
|
|
64
|
+
* A rejected query leaves the stamp alone; any completed round trip, including
|
|
65
|
+
* one issued by a caller that has since given up waiting on it, refreshes it.
|
|
66
|
+
*
|
|
67
|
+
* @param run - Executes the underlying operation.
|
|
68
|
+
* @returns Whatever the operation returned.
|
|
69
|
+
*/
|
|
70
|
+
export async function stampQuerySuccess(run) {
|
|
71
|
+
const result = await run();
|
|
72
|
+
lastQuerySucceededAt = Date.now();
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
45
75
|
/**
|
|
46
76
|
* Apply the unqualified-`findMany` ceiling to a Prisma client.
|
|
47
77
|
*
|
|
@@ -61,7 +91,18 @@ export function resolveFindManyTake() {
|
|
|
61
91
|
*/
|
|
62
92
|
export function withFindManyGuard(client) {
|
|
63
93
|
const ceiling = resolveFindManyTake();
|
|
64
|
-
|
|
94
|
+
// The success stamp rides this wrapper because it is the one applied at both
|
|
95
|
+
// client assignment sites (initial and reconnect), so the stamp survives a
|
|
96
|
+
// reconnect without the reconnect path having to know about it.
|
|
97
|
+
const stamped = client.$extends({
|
|
98
|
+
name: 'query-success-stamp',
|
|
99
|
+
query: {
|
|
100
|
+
async $allOperations({ args, query }) {
|
|
101
|
+
return stampQuerySuccess(() => query(args));
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const extended = stamped.$extends({
|
|
65
106
|
name: 'find-many-ceiling',
|
|
66
107
|
query: {
|
|
67
108
|
$allModels: {
|
|
@@ -85,11 +126,24 @@ export function withFindManyGuard(client) {
|
|
|
85
126
|
return extended;
|
|
86
127
|
}
|
|
87
128
|
/** Default statement timeout (30s) prevents hung queries from blocking pool slots indefinitely */
|
|
88
|
-
const DEFAULT_STATEMENT_TIMEOUT_MS = 30000;
|
|
129
|
+
export const DEFAULT_STATEMENT_TIMEOUT_MS = 30000;
|
|
89
130
|
/** Heartbeat interval: how often we verify the DB connection is alive */
|
|
90
|
-
const HEARTBEAT_INTERVAL_MS = 30000;
|
|
131
|
+
export const HEARTBEAT_INTERVAL_MS = 30000;
|
|
91
132
|
/** Consecutive heartbeat failures before triggering client reconnection */
|
|
92
|
-
const MAX_HEARTBEAT_FAILURES = 3;
|
|
133
|
+
export const MAX_HEARTBEAT_FAILURES = 3;
|
|
134
|
+
/**
|
|
135
|
+
* Resolve the per-statement timeout appended to a direct Postgres URL.
|
|
136
|
+
*
|
|
137
|
+
* Parsed exactly as the URL builder has always parsed it, so a value that is
|
|
138
|
+
* not a positive integer comes back as-is (NaN, 0, negative) for the caller to
|
|
139
|
+
* judge rather than being silently replaced.
|
|
140
|
+
*
|
|
141
|
+
* @returns The statement timeout in milliseconds.
|
|
142
|
+
*/
|
|
143
|
+
export function resolveStatementTimeoutMs() {
|
|
144
|
+
return parseInt(process.env.DATABASE_STATEMENT_TIMEOUT_MS ||
|
|
145
|
+
String(DEFAULT_STATEMENT_TIMEOUT_MS), 10);
|
|
146
|
+
}
|
|
93
147
|
/** Heartbeat query timeout (5s) — shorter than pool timeout to detect issues early */
|
|
94
148
|
const HEARTBEAT_TIMEOUT_MS = 5000;
|
|
95
149
|
/**
|
|
@@ -198,8 +252,7 @@ function buildDatabaseUrl() {
|
|
|
198
252
|
poolTimeoutMs: poolTimeout,
|
|
199
253
|
environment: process.env.NODE_ENV || 'development',
|
|
200
254
|
});
|
|
201
|
-
const statementTimeoutMs =
|
|
202
|
-
String(DEFAULT_STATEMENT_TIMEOUT_MS), 10);
|
|
255
|
+
const statementTimeoutMs = resolveStatementTimeoutMs();
|
|
203
256
|
return `${baseUrl}${separator}connection_limit=${poolSize}&pool_timeout=${Math.floor(poolTimeout / 1000)}&statement_timeout=${statementTimeoutMs}&idle_in_transaction_session_timeout=${statementTimeoutMs}`;
|
|
204
257
|
}
|
|
205
258
|
// Create a singleton that works in all environments
|
package/health.cjs
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
5
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HEALTH_PROBE_TIMEOUT_MS = exports.DB_SUCCESS_FRESHNESS_MS = void 0;
|
|
37
|
+
exports.warnIfStatementTimeoutDefeatsFreshness = warnIfStatementTimeoutDefeatsFreshness;
|
|
38
|
+
exports.checkDatabaseReadiness = checkDatabaseReadiness;
|
|
6
39
|
exports.createHealthRouter = createHealthRouter;
|
|
7
40
|
const express_1 = require("express");
|
|
8
|
-
const prismaClient_1 =
|
|
41
|
+
const prismaClient_1 = __importStar(require("./prismaClient.cjs"));
|
|
9
42
|
const logger_1 = require("./utils/logger.cjs");
|
|
10
43
|
const SERVICE_NAME = 'backend-legacy';
|
|
11
44
|
/**
|
|
@@ -24,6 +57,136 @@ function getPackageVersion() {
|
|
|
24
57
|
const PACKAGE_VERSION = getPackageVersion();
|
|
25
58
|
/** Tracks the process start time for uptime calculation */
|
|
26
59
|
const startedAt = Date.now();
|
|
60
|
+
/**
|
|
61
|
+
* How recently a query must have completed for `/health` to accept it as
|
|
62
|
+
* proof the database is answering, without issuing a query of its own.
|
|
63
|
+
*
|
|
64
|
+
* Derived from the heartbeat rather than set by hand: it tolerates every
|
|
65
|
+
* heartbeat but the last before reconnection being missed, plus half an
|
|
66
|
+
* interval of slack — `(MAX_HEARTBEAT_FAILURES - 0.5) * HEARTBEAT_INTERVAL_MS`,
|
|
67
|
+
* 75s at the current 3 x 30s. That keeps it longer than one heartbeat interval,
|
|
68
|
+
* so an idle process that the heartbeat keeps refreshing never goes stale, and
|
|
69
|
+
* shorter than the reconnect point, so a database that has stopped answering
|
|
70
|
+
* reads as disconnected before the heartbeat gives up on the client.
|
|
71
|
+
*
|
|
72
|
+
* A saturated pool still completes queries, each bounded by the statement
|
|
73
|
+
* timeout, so saturation alone does not let it go stale — provided that
|
|
74
|
+
* timeout is shorter than this window (see
|
|
75
|
+
* {@link warnIfStatementTimeoutDefeatsFreshness}).
|
|
76
|
+
*/
|
|
77
|
+
exports.DB_SUCCESS_FRESHNESS_MS = (prismaClient_1.MAX_HEARTBEAT_FAILURES - 0.5) * prismaClient_1.HEARTBEAT_INTERVAL_MS;
|
|
78
|
+
/**
|
|
79
|
+
* Warn when the configured statement timeout is not shorter than the
|
|
80
|
+
* freshness window.
|
|
81
|
+
*
|
|
82
|
+
* The case for trusting a recent success under saturation is that every query
|
|
83
|
+
* on a busy pool finishes or fails within the statement timeout, so completed
|
|
84
|
+
* queries keep arriving inside {@link DB_SUCCESS_FRESHNESS_MS}. A timeout at or
|
|
85
|
+
* above the window breaks that: a pool full of long-running statements can go
|
|
86
|
+
* a whole window without a completion and `/health` would fall back to a probe
|
|
87
|
+
* that cannot get a connection. A value that is not a positive integer (unset
|
|
88
|
+
* timeouts parse from the default; `0` disables the timeout in Postgres) is
|
|
89
|
+
* treated the same way, since it bounds nothing.
|
|
90
|
+
*
|
|
91
|
+
* @param statementTimeoutMs - The resolved statement timeout (injectable for tests).
|
|
92
|
+
* @returns True if a warning was logged.
|
|
93
|
+
*/
|
|
94
|
+
function warnIfStatementTimeoutDefeatsFreshness(statementTimeoutMs = (0, prismaClient_1.resolveStatementTimeoutMs)()) {
|
|
95
|
+
if (Number.isFinite(statementTimeoutMs) &&
|
|
96
|
+
statementTimeoutMs > 0 &&
|
|
97
|
+
statementTimeoutMs < exports.DB_SUCCESS_FRESHNESS_MS) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
logger_1.logger.warn('DATABASE_STATEMENT_TIMEOUT_MS is not shorter than the /health freshness window — a saturated pool can read as disconnected', {
|
|
101
|
+
statementTimeoutMs,
|
|
102
|
+
freshnessWindowMs: exports.DB_SUCCESS_FRESHNESS_MS,
|
|
103
|
+
});
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Budget for the fallback probe when no recent success exists. Well under the
|
|
108
|
+
* 10s pool wait so a saturated pool yields an answer inside the platform's
|
|
109
|
+
* probe timeout rather than hanging the request.
|
|
110
|
+
*/
|
|
111
|
+
exports.HEALTH_PROBE_TIMEOUT_MS = 2000;
|
|
112
|
+
/** The one probe query this module may have outstanding on the pool. */
|
|
113
|
+
let outstandingProbe;
|
|
114
|
+
/**
|
|
115
|
+
* Probe the live client with `SELECT 1`, giving up after `timeoutMs`.
|
|
116
|
+
*
|
|
117
|
+
* Reads `global.prisma` rather than the module-level import, because the
|
|
118
|
+
* heartbeat's reconnect path replaces `global.prisma` and the import stays
|
|
119
|
+
* pinned to the original (by then disconnected) client.
|
|
120
|
+
*
|
|
121
|
+
* At most one probe query is ever outstanding: a caller that arrives while a
|
|
122
|
+
* previous probe is still queued on the pool waits on that same query instead
|
|
123
|
+
* of adding another waiter, so frequent health checks cannot themselves deepen
|
|
124
|
+
* a saturated pool's queue.
|
|
125
|
+
*
|
|
126
|
+
* @param timeoutMs - How long to wait for the probe before calling it failed.
|
|
127
|
+
* @returns True if the probe completed within the budget.
|
|
128
|
+
*/
|
|
129
|
+
async function probeLiveClient(timeoutMs) {
|
|
130
|
+
var _a;
|
|
131
|
+
if (!outstandingProbe) {
|
|
132
|
+
const client = (_a = global.prisma) !== null && _a !== void 0 ? _a : prismaClient_1.default;
|
|
133
|
+
outstandingProbe = Promise.resolve(client.$queryRaw `SELECT 1`).finally(() => {
|
|
134
|
+
outstandingProbe = undefined;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const probe = outstandingProbe;
|
|
138
|
+
let timer;
|
|
139
|
+
const timedOut = new Promise((resolve) => {
|
|
140
|
+
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
141
|
+
});
|
|
142
|
+
try {
|
|
143
|
+
return await Promise.race([
|
|
144
|
+
probe.then(() => true, (dbError) => {
|
|
145
|
+
logger_1.logger.warn('Health check: database probe failed', {
|
|
146
|
+
error: dbError instanceof Error ? dbError.message : String(dbError),
|
|
147
|
+
});
|
|
148
|
+
return false;
|
|
149
|
+
}),
|
|
150
|
+
timedOut,
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Decide whether the database is answering this process, without depending
|
|
159
|
+
* on a free pool connection when there is already evidence that it is.
|
|
160
|
+
*
|
|
161
|
+
* A query that completed within {@link DB_SUCCESS_FRESHNESS_MS} is taken as
|
|
162
|
+
* that evidence and no query is issued. Only when there is none (startup, or a
|
|
163
|
+
* database that has stopped answering) does it fall back to a bounded probe.
|
|
164
|
+
*
|
|
165
|
+
* @param now - Current epoch ms (injectable for tests).
|
|
166
|
+
* @returns The database status, how it was decided, and the success age.
|
|
167
|
+
*/
|
|
168
|
+
async function checkDatabaseReadiness(now = Date.now()) {
|
|
169
|
+
const lastSuccess = (0, prismaClient_1.getLastQuerySucceededAt)();
|
|
170
|
+
const ageMs = lastSuccess === undefined ? undefined : now - lastSuccess;
|
|
171
|
+
if (ageMs !== undefined && ageMs <= exports.DB_SUCCESS_FRESHNESS_MS) {
|
|
172
|
+
return {
|
|
173
|
+
database: 'connected',
|
|
174
|
+
databaseCheck: 'recent-query',
|
|
175
|
+
lastQuerySucceededSecondsAgo: Math.max(0, Math.floor(ageMs / 1000)),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const answered = await probeLiveClient(exports.HEALTH_PROBE_TIMEOUT_MS);
|
|
179
|
+
// A successful probe goes through the same client extension and refreshes
|
|
180
|
+
// the stamp; report the age as it stands after the probe.
|
|
181
|
+
const after = (0, prismaClient_1.getLastQuerySucceededAt)();
|
|
182
|
+
return {
|
|
183
|
+
database: answered ? 'connected' : 'disconnected',
|
|
184
|
+
databaseCheck: 'probe',
|
|
185
|
+
lastQuerySucceededSecondsAgo: after === undefined
|
|
186
|
+
? null
|
|
187
|
+
: Math.max(0, Math.floor((Date.now() - after) / 1000)),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
27
190
|
/**
|
|
28
191
|
* Checks database connectivity by issuing a lightweight query.
|
|
29
192
|
* Returns 'connected' or 'disconnected'. Never throws.
|
|
@@ -50,13 +213,18 @@ async function checkDatabase() {
|
|
|
50
213
|
* is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
|
|
51
214
|
* startup probes and load-balancer readiness.
|
|
52
215
|
* - `GET /health` — Full health snapshot including memory usage and database
|
|
53
|
-
* status. Returns 503 when the database
|
|
54
|
-
*
|
|
216
|
+
* status. Returns 503 only when the database has stopped answering this
|
|
217
|
+
* process: a query that completed within the freshness window counts as
|
|
218
|
+
* proof without taking a pool connection, so a saturated-but-working pool
|
|
219
|
+
* reads as healthy. With no recent success it falls back to a bounded
|
|
220
|
+
* probe (see {@link checkDatabaseReadiness}). Kept for backward
|
|
221
|
+
* compatibility with existing Railway/uptime checks.
|
|
55
222
|
*
|
|
56
223
|
* All endpoints should be mounted before auth middleware so they remain
|
|
57
224
|
* accessible without authentication.
|
|
58
225
|
*/
|
|
59
226
|
function createHealthRouter() {
|
|
227
|
+
warnIfStatementTimeoutDefeatsFreshness();
|
|
60
228
|
const router = (0, express_1.Router)();
|
|
61
229
|
router.get('/livez', (_req, res) => {
|
|
62
230
|
res.status(200).json({
|
|
@@ -79,7 +247,8 @@ function createHealthRouter() {
|
|
|
79
247
|
});
|
|
80
248
|
});
|
|
81
249
|
router.get('/health', async (_req, res) => {
|
|
82
|
-
const
|
|
250
|
+
const readiness = await checkDatabaseReadiness();
|
|
251
|
+
const databaseStatus = readiness.database;
|
|
83
252
|
const isHealthy = databaseStatus === 'connected';
|
|
84
253
|
const statusCode = isHealthy ? 200 : 503;
|
|
85
254
|
const memoryUsage = process.memoryUsage();
|
|
@@ -95,6 +264,8 @@ function createHealthRouter() {
|
|
|
95
264
|
heapTotal: Math.round(memoryUsage.heapTotal / 1024 / 1024),
|
|
96
265
|
},
|
|
97
266
|
database: databaseStatus,
|
|
267
|
+
databaseCheck: readiness.databaseCheck,
|
|
268
|
+
lastQuerySucceededSecondsAgo: readiness.lastQuerySucceededSecondsAgo,
|
|
98
269
|
};
|
|
99
270
|
res.status(statusCode).json(body);
|
|
100
271
|
});
|
package/health.d.ts
CHANGED
|
@@ -1,4 +1,62 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
type DatabaseCheck = 'recent-query' | 'probe';
|
|
3
|
+
/**
|
|
4
|
+
* How recently a query must have completed for `/health` to accept it as
|
|
5
|
+
* proof the database is answering, without issuing a query of its own.
|
|
6
|
+
*
|
|
7
|
+
* Derived from the heartbeat rather than set by hand: it tolerates every
|
|
8
|
+
* heartbeat but the last before reconnection being missed, plus half an
|
|
9
|
+
* interval of slack — `(MAX_HEARTBEAT_FAILURES - 0.5) * HEARTBEAT_INTERVAL_MS`,
|
|
10
|
+
* 75s at the current 3 x 30s. That keeps it longer than one heartbeat interval,
|
|
11
|
+
* so an idle process that the heartbeat keeps refreshing never goes stale, and
|
|
12
|
+
* shorter than the reconnect point, so a database that has stopped answering
|
|
13
|
+
* reads as disconnected before the heartbeat gives up on the client.
|
|
14
|
+
*
|
|
15
|
+
* A saturated pool still completes queries, each bounded by the statement
|
|
16
|
+
* timeout, so saturation alone does not let it go stale — provided that
|
|
17
|
+
* timeout is shorter than this window (see
|
|
18
|
+
* {@link warnIfStatementTimeoutDefeatsFreshness}).
|
|
19
|
+
*/
|
|
20
|
+
export declare const DB_SUCCESS_FRESHNESS_MS: number;
|
|
21
|
+
/**
|
|
22
|
+
* Warn when the configured statement timeout is not shorter than the
|
|
23
|
+
* freshness window.
|
|
24
|
+
*
|
|
25
|
+
* The case for trusting a recent success under saturation is that every query
|
|
26
|
+
* on a busy pool finishes or fails within the statement timeout, so completed
|
|
27
|
+
* queries keep arriving inside {@link DB_SUCCESS_FRESHNESS_MS}. A timeout at or
|
|
28
|
+
* above the window breaks that: a pool full of long-running statements can go
|
|
29
|
+
* a whole window without a completion and `/health` would fall back to a probe
|
|
30
|
+
* that cannot get a connection. A value that is not a positive integer (unset
|
|
31
|
+
* timeouts parse from the default; `0` disables the timeout in Postgres) is
|
|
32
|
+
* treated the same way, since it bounds nothing.
|
|
33
|
+
*
|
|
34
|
+
* @param statementTimeoutMs - The resolved statement timeout (injectable for tests).
|
|
35
|
+
* @returns True if a warning was logged.
|
|
36
|
+
*/
|
|
37
|
+
export declare function warnIfStatementTimeoutDefeatsFreshness(statementTimeoutMs?: number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Budget for the fallback probe when no recent success exists. Well under the
|
|
40
|
+
* 10s pool wait so a saturated pool yields an answer inside the platform's
|
|
41
|
+
* probe timeout rather than hanging the request.
|
|
42
|
+
*/
|
|
43
|
+
export declare const HEALTH_PROBE_TIMEOUT_MS = 2000;
|
|
44
|
+
/**
|
|
45
|
+
* Decide whether the database is answering this process, without depending
|
|
46
|
+
* on a free pool connection when there is already evidence that it is.
|
|
47
|
+
*
|
|
48
|
+
* A query that completed within {@link DB_SUCCESS_FRESHNESS_MS} is taken as
|
|
49
|
+
* that evidence and no query is issued. Only when there is none (startup, or a
|
|
50
|
+
* database that has stopped answering) does it fall back to a bounded probe.
|
|
51
|
+
*
|
|
52
|
+
* @param now - Current epoch ms (injectable for tests).
|
|
53
|
+
* @returns The database status, how it was decided, and the success age.
|
|
54
|
+
*/
|
|
55
|
+
export declare function checkDatabaseReadiness(now?: number): Promise<{
|
|
56
|
+
database: 'connected' | 'disconnected';
|
|
57
|
+
databaseCheck: DatabaseCheck;
|
|
58
|
+
lastQuerySucceededSecondsAgo: number | null;
|
|
59
|
+
}>;
|
|
2
60
|
/**
|
|
3
61
|
* Creates an Express router with health-probe endpoints.
|
|
4
62
|
*
|
|
@@ -9,11 +67,16 @@ import { Router } from 'express';
|
|
|
9
67
|
* is reachable (`SELECT 1`), HTTP 503 otherwise. Suitable for Cloud Run
|
|
10
68
|
* startup probes and load-balancer readiness.
|
|
11
69
|
* - `GET /health` — Full health snapshot including memory usage and database
|
|
12
|
-
* status. Returns 503 when the database
|
|
13
|
-
*
|
|
70
|
+
* status. Returns 503 only when the database has stopped answering this
|
|
71
|
+
* process: a query that completed within the freshness window counts as
|
|
72
|
+
* proof without taking a pool connection, so a saturated-but-working pool
|
|
73
|
+
* reads as healthy. With no recent success it falls back to a bounded
|
|
74
|
+
* probe (see {@link checkDatabaseReadiness}). Kept for backward
|
|
75
|
+
* compatibility with existing Railway/uptime checks.
|
|
14
76
|
*
|
|
15
77
|
* All endpoints should be mounted before auth middleware so they remain
|
|
16
78
|
* accessible without authentication.
|
|
17
79
|
*/
|
|
18
80
|
export declare function createHealthRouter(): Router;
|
|
81
|
+
export {};
|
|
19
82
|
//# sourceMappingURL=health.d.ts.map
|
package/package.json
CHANGED
package/prismaClient.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_FIND_MANY_TAKE = void 0;
|
|
3
|
+
exports.MAX_HEARTBEAT_FAILURES = exports.HEARTBEAT_INTERVAL_MS = exports.DEFAULT_STATEMENT_TIMEOUT_MS = exports.DEFAULT_FIND_MANY_TAKE = void 0;
|
|
4
4
|
exports.resolveFindManyTake = resolveFindManyTake;
|
|
5
|
+
exports.getLastQuerySucceededAt = getLastQuerySucceededAt;
|
|
6
|
+
exports.stampQuerySuccess = stampQuerySuccess;
|
|
5
7
|
exports.withFindManyGuard = withFindManyGuard;
|
|
8
|
+
exports.resolveStatementTimeoutMs = resolveStatementTimeoutMs;
|
|
6
9
|
exports.startConnectionHealthMonitor = startConnectionHealthMonitor;
|
|
7
10
|
exports.stopConnectionHealthMonitor = stopConnectionHealthMonitor;
|
|
8
11
|
exports.disconnectWithTimeout = disconnectWithTimeout;
|
|
@@ -50,6 +53,36 @@ function resolveFindManyTake() {
|
|
|
50
53
|
}
|
|
51
54
|
return parsed;
|
|
52
55
|
}
|
|
56
|
+
/** Wall-clock ms of the most recent query that completed successfully, or undefined before the first. */
|
|
57
|
+
let lastQuerySucceededAt;
|
|
58
|
+
/**
|
|
59
|
+
* When a query on this process's Prisma client last completed successfully.
|
|
60
|
+
*
|
|
61
|
+
* This is the evidence `/health` uses for "the database is answering this
|
|
62
|
+
* process". It is recorded as a side effect of ordinary traffic and of the
|
|
63
|
+
* heartbeat, so reading it never needs a pool connection — which is the point:
|
|
64
|
+
* a pool that is saturated but still completing work keeps this fresh, and a
|
|
65
|
+
* database that has stopped answering lets it go stale.
|
|
66
|
+
*
|
|
67
|
+
* @returns Epoch milliseconds of the last success, or undefined if none yet.
|
|
68
|
+
*/
|
|
69
|
+
function getLastQuerySucceededAt() {
|
|
70
|
+
return lastQuerySucceededAt;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Run a query and stamp the success time if it resolves.
|
|
74
|
+
*
|
|
75
|
+
* A rejected query leaves the stamp alone; any completed round trip, including
|
|
76
|
+
* one issued by a caller that has since given up waiting on it, refreshes it.
|
|
77
|
+
*
|
|
78
|
+
* @param run - Executes the underlying operation.
|
|
79
|
+
* @returns Whatever the operation returned.
|
|
80
|
+
*/
|
|
81
|
+
async function stampQuerySuccess(run) {
|
|
82
|
+
const result = await run();
|
|
83
|
+
lastQuerySucceededAt = Date.now();
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
53
86
|
/**
|
|
54
87
|
* Apply the unqualified-`findMany` ceiling to a Prisma client.
|
|
55
88
|
*
|
|
@@ -69,7 +102,18 @@ function resolveFindManyTake() {
|
|
|
69
102
|
*/
|
|
70
103
|
function withFindManyGuard(client) {
|
|
71
104
|
const ceiling = resolveFindManyTake();
|
|
72
|
-
|
|
105
|
+
// The success stamp rides this wrapper because it is the one applied at both
|
|
106
|
+
// client assignment sites (initial and reconnect), so the stamp survives a
|
|
107
|
+
// reconnect without the reconnect path having to know about it.
|
|
108
|
+
const stamped = client.$extends({
|
|
109
|
+
name: 'query-success-stamp',
|
|
110
|
+
query: {
|
|
111
|
+
async $allOperations({ args, query }) {
|
|
112
|
+
return stampQuerySuccess(() => query(args));
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const extended = stamped.$extends({
|
|
73
117
|
name: 'find-many-ceiling',
|
|
74
118
|
query: {
|
|
75
119
|
$allModels: {
|
|
@@ -93,11 +137,24 @@ function withFindManyGuard(client) {
|
|
|
93
137
|
return extended;
|
|
94
138
|
}
|
|
95
139
|
/** Default statement timeout (30s) prevents hung queries from blocking pool slots indefinitely */
|
|
96
|
-
|
|
140
|
+
exports.DEFAULT_STATEMENT_TIMEOUT_MS = 30000;
|
|
97
141
|
/** Heartbeat interval: how often we verify the DB connection is alive */
|
|
98
|
-
|
|
142
|
+
exports.HEARTBEAT_INTERVAL_MS = 30000;
|
|
99
143
|
/** Consecutive heartbeat failures before triggering client reconnection */
|
|
100
|
-
|
|
144
|
+
exports.MAX_HEARTBEAT_FAILURES = 3;
|
|
145
|
+
/**
|
|
146
|
+
* Resolve the per-statement timeout appended to a direct Postgres URL.
|
|
147
|
+
*
|
|
148
|
+
* Parsed exactly as the URL builder has always parsed it, so a value that is
|
|
149
|
+
* not a positive integer comes back as-is (NaN, 0, negative) for the caller to
|
|
150
|
+
* judge rather than being silently replaced.
|
|
151
|
+
*
|
|
152
|
+
* @returns The statement timeout in milliseconds.
|
|
153
|
+
*/
|
|
154
|
+
function resolveStatementTimeoutMs() {
|
|
155
|
+
return parseInt(process.env.DATABASE_STATEMENT_TIMEOUT_MS ||
|
|
156
|
+
String(exports.DEFAULT_STATEMENT_TIMEOUT_MS), 10);
|
|
157
|
+
}
|
|
101
158
|
/** Heartbeat query timeout (5s) — shorter than pool timeout to detect issues early */
|
|
102
159
|
const HEARTBEAT_TIMEOUT_MS = 5000;
|
|
103
160
|
/**
|
|
@@ -206,8 +263,7 @@ function buildDatabaseUrl() {
|
|
|
206
263
|
poolTimeoutMs: poolTimeout,
|
|
207
264
|
environment: process.env.NODE_ENV || 'development',
|
|
208
265
|
});
|
|
209
|
-
const statementTimeoutMs =
|
|
210
|
-
String(DEFAULT_STATEMENT_TIMEOUT_MS), 10);
|
|
266
|
+
const statementTimeoutMs = resolveStatementTimeoutMs();
|
|
211
267
|
return `${baseUrl}${separator}connection_limit=${poolSize}&pool_timeout=${Math.floor(poolTimeout / 1000)}&statement_timeout=${statementTimeoutMs}&idle_in_transaction_session_timeout=${statementTimeoutMs}`;
|
|
212
268
|
}
|
|
213
269
|
// Create a singleton that works in all environments
|
|
@@ -347,7 +403,7 @@ async function heartbeat() {
|
|
|
347
403
|
consecutiveFailures: heartbeatFailures,
|
|
348
404
|
error: errorMessage,
|
|
349
405
|
});
|
|
350
|
-
if (heartbeatFailures >= MAX_HEARTBEAT_FAILURES) {
|
|
406
|
+
if (heartbeatFailures >= exports.MAX_HEARTBEAT_FAILURES) {
|
|
351
407
|
logger_1.logger.error('Database heartbeat exceeded failure threshold, reconnecting Prisma client', {
|
|
352
408
|
consecutiveFailures: heartbeatFailures,
|
|
353
409
|
});
|
|
@@ -417,12 +473,12 @@ function startConnectionHealthMonitor() {
|
|
|
417
473
|
if (heartbeatTimer)
|
|
418
474
|
return () => stopConnectionHealthMonitor();
|
|
419
475
|
logger_1.logger.info('Starting database connection health monitor', {
|
|
420
|
-
intervalMs: HEARTBEAT_INTERVAL_MS,
|
|
421
|
-
failureThreshold: MAX_HEARTBEAT_FAILURES,
|
|
476
|
+
intervalMs: exports.HEARTBEAT_INTERVAL_MS,
|
|
477
|
+
failureThreshold: exports.MAX_HEARTBEAT_FAILURES,
|
|
422
478
|
});
|
|
423
479
|
heartbeatTimer = setInterval(() => {
|
|
424
480
|
void heartbeat();
|
|
425
|
-
}, HEARTBEAT_INTERVAL_MS);
|
|
481
|
+
}, exports.HEARTBEAT_INTERVAL_MS);
|
|
426
482
|
// Run an initial heartbeat immediately
|
|
427
483
|
void heartbeat();
|
|
428
484
|
return () => stopConnectionHealthMonitor();
|
package/prismaClient.d.ts
CHANGED
|
@@ -29,6 +29,28 @@ export declare const DEFAULT_FIND_MANY_TAKE = 50000;
|
|
|
29
29
|
* @returns The row ceiling to apply to an unqualified `findMany`.
|
|
30
30
|
*/
|
|
31
31
|
export declare function resolveFindManyTake(): number;
|
|
32
|
+
/**
|
|
33
|
+
* When a query on this process's Prisma client last completed successfully.
|
|
34
|
+
*
|
|
35
|
+
* This is the evidence `/health` uses for "the database is answering this
|
|
36
|
+
* process". It is recorded as a side effect of ordinary traffic and of the
|
|
37
|
+
* heartbeat, so reading it never needs a pool connection — which is the point:
|
|
38
|
+
* a pool that is saturated but still completing work keeps this fresh, and a
|
|
39
|
+
* database that has stopped answering lets it go stale.
|
|
40
|
+
*
|
|
41
|
+
* @returns Epoch milliseconds of the last success, or undefined if none yet.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getLastQuerySucceededAt(): number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Run a query and stamp the success time if it resolves.
|
|
46
|
+
*
|
|
47
|
+
* A rejected query leaves the stamp alone; any completed round trip, including
|
|
48
|
+
* one issued by a caller that has since given up waiting on it, refreshes it.
|
|
49
|
+
*
|
|
50
|
+
* @param run - Executes the underlying operation.
|
|
51
|
+
* @returns Whatever the operation returned.
|
|
52
|
+
*/
|
|
53
|
+
export declare function stampQuerySuccess<T>(run: () => Promise<T>): Promise<T>;
|
|
32
54
|
/**
|
|
33
55
|
* Apply the unqualified-`findMany` ceiling to a Prisma client.
|
|
34
56
|
*
|
|
@@ -47,6 +69,22 @@ export declare function resolveFindManyTake(): number;
|
|
|
47
69
|
* @returns The client with the ceiling applied.
|
|
48
70
|
*/
|
|
49
71
|
export declare function withFindManyGuard(client: PrismaClient): PrismaClient;
|
|
72
|
+
/** Default statement timeout (30s) prevents hung queries from blocking pool slots indefinitely */
|
|
73
|
+
export declare const DEFAULT_STATEMENT_TIMEOUT_MS = 30000;
|
|
74
|
+
/** Heartbeat interval: how often we verify the DB connection is alive */
|
|
75
|
+
export declare const HEARTBEAT_INTERVAL_MS = 30000;
|
|
76
|
+
/** Consecutive heartbeat failures before triggering client reconnection */
|
|
77
|
+
export declare const MAX_HEARTBEAT_FAILURES = 3;
|
|
78
|
+
/**
|
|
79
|
+
* Resolve the per-statement timeout appended to a direct Postgres URL.
|
|
80
|
+
*
|
|
81
|
+
* Parsed exactly as the URL builder has always parsed it, so a value that is
|
|
82
|
+
* not a positive integer comes back as-is (NaN, 0, negative) for the caller to
|
|
83
|
+
* judge rather than being silently replaced.
|
|
84
|
+
*
|
|
85
|
+
* @returns The statement timeout in milliseconds.
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveStatementTimeoutMs(): number;
|
|
50
88
|
declare const prisma: PrismaClient;
|
|
51
89
|
/**
|
|
52
90
|
* Starts the periodic database heartbeat monitor.
|