@ultimat3/db 24.0.0 → 25.0.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.
@@ -1,50 +0,0 @@
1
- // Single responsibility: a `ReservableClient` whose pin is countable, wrapped over any `DbClient`.
2
- // The leak it exists to catch is invisible to the recording client — the statements are identical
3
- // whether or not the reservation ever came back, and only the counter says which happened. Shared
4
- // rather than copied: a second copy of a fixture asserts less than the first, silently.
5
-
6
- import type { DbClient, ReservableClient } from './client';
7
-
8
- /** Pins taken and pins given back. A leak is `reserves > releases`; the fix makes them equal. */
9
- export interface PinCounts {
10
- reserves: number;
11
- releases: number;
12
- }
13
-
14
- export interface ReservableFake {
15
- readonly client: ReservableClient;
16
- readonly pins: PinCounts;
17
- }
18
-
19
- /**
20
- * Wrap `inner` in a pool that counts its reservations. `release()` is idempotent and
21
- * `[Symbol.dispose]` is the same call, exactly as both real drivers are — so a double release
22
- * counts once and only a genuine leak leaves the counters uneven.
23
- */
24
- export function reservableOver(inner: DbClient): ReservableFake {
25
- const pins: PinCounts = { reserves: 0, releases: 0 };
26
- return {
27
- pins,
28
- client: {
29
- query: (fragment) => inner.query(fragment),
30
- one: (fragment) => inner.one(fragment),
31
- execute: (fragment) => inner.execute(fragment),
32
- reserve: async () => {
33
- pins.reserves += 1;
34
- let held = true;
35
- const release = (): void => {
36
- if (!held) return;
37
- held = false;
38
- pins.releases += 1;
39
- };
40
- return {
41
- query: (fragment) => inner.query(fragment),
42
- one: (fragment) => inner.one(fragment),
43
- execute: (fragment) => inner.execute(fragment),
44
- release,
45
- [Symbol.dispose]: release,
46
- };
47
- },
48
- },
49
- };
50
- }