@vibesdotdev/localdb 0.0.2 → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +123 -2
  3. package/dist/cli/commands/_shared.consumer.d.ts +1 -3
  4. package/dist/cli/commands/_shared.consumer.d.ts.map +1 -1
  5. package/dist/cli/commands/_shared.consumer.js +1 -11
  6. package/dist/cli/commands/_shared.consumer.js.map +1 -1
  7. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.descriptor.js +1 -1
  8. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.descriptor.js.map +1 -1
  9. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.d.ts +9 -3
  10. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.d.ts.map +1 -1
  11. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.js +59 -45
  12. package/dist/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.js.map +1 -1
  13. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.descriptor.js +1 -1
  14. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.descriptor.js.map +1 -1
  15. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.d.ts +8 -3
  16. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.d.ts.map +1 -1
  17. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.js +12 -10
  18. package/dist/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.js.map +1 -1
  19. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.descriptor.js +1 -1
  20. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.descriptor.js.map +1 -1
  21. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.impl.d.ts +6 -3
  22. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.impl.d.ts.map +1 -1
  23. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.impl.js +8 -7
  24. package/dist/cli/commands/pools/dev.localdb.pools.cli-command.impl.js.map +1 -1
  25. package/dist/cli/commands/query/dev.localdb.query.cli-command.descriptor.js +1 -1
  26. package/dist/cli/commands/query/dev.localdb.query.cli-command.descriptor.js.map +1 -1
  27. package/dist/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.d.ts +13 -3
  28. package/dist/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.d.ts.map +1 -1
  29. package/dist/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.js +66 -51
  30. package/dist/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.js.map +1 -1
  31. package/dist/cli/commands/status/dev.localdb.status.cli-command.descriptor.js +1 -1
  32. package/dist/cli/commands/status/dev.localdb.status.cli-command.descriptor.js.map +1 -1
  33. package/dist/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.d.ts +9 -3
  34. package/dist/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.d.ts.map +1 -1
  35. package/dist/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.js +41 -29
  36. package/dist/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.js.map +1 -1
  37. package/dist/cli/inputs.d.ts +25 -0
  38. package/dist/cli/inputs.d.ts.map +1 -0
  39. package/dist/cli/inputs.js +81 -0
  40. package/dist/cli/inputs.js.map +1 -0
  41. package/dist/cli/types.d.ts +45 -0
  42. package/dist/cli/types.d.ts.map +1 -0
  43. package/dist/cli/types.js +14 -0
  44. package/dist/cli/types.js.map +1 -0
  45. package/dist/core/connection-pool.d.ts +204 -46
  46. package/dist/core/connection-pool.d.ts.map +1 -1
  47. package/dist/core/connection-pool.js +610 -101
  48. package/dist/core/connection-pool.js.map +1 -1
  49. package/dist/core/database.d.ts +243 -63
  50. package/dist/core/database.d.ts.map +1 -1
  51. package/dist/core/database.js +937 -203
  52. package/dist/core/database.js.map +1 -1
  53. package/dist/core/holders.d.ts +15 -0
  54. package/dist/core/holders.d.ts.map +1 -0
  55. package/dist/core/holders.js +4 -0
  56. package/dist/core/holders.js.map +1 -0
  57. package/dist/core/host-kinds.d.ts +22 -0
  58. package/dist/core/host-kinds.d.ts.map +1 -0
  59. package/dist/core/host-kinds.js +52 -0
  60. package/dist/core/host-kinds.js.map +1 -0
  61. package/dist/core/live-runtime.d.ts +17 -0
  62. package/dist/core/live-runtime.d.ts.map +1 -0
  63. package/dist/core/live-runtime.js +28 -0
  64. package/dist/core/live-runtime.js.map +1 -0
  65. package/dist/core/migration-registry.d.ts +115 -80
  66. package/dist/core/migration-registry.d.ts.map +1 -1
  67. package/dist/core/migration-registry.js +340 -199
  68. package/dist/core/migration-registry.js.map +1 -1
  69. package/dist/core/open-connection.d.ts +11 -0
  70. package/dist/core/open-connection.d.ts.map +1 -0
  71. package/dist/core/open-connection.js +70 -0
  72. package/dist/core/open-connection.js.map +1 -0
  73. package/dist/core/outcome.d.ts +21 -0
  74. package/dist/core/outcome.d.ts.map +1 -0
  75. package/dist/core/outcome.js +22 -0
  76. package/dist/core/outcome.js.map +1 -0
  77. package/dist/core/pool-api.d.ts +19 -0
  78. package/dist/core/pool-api.d.ts.map +1 -0
  79. package/dist/core/pool-api.js +59 -0
  80. package/dist/core/pool-api.js.map +1 -0
  81. package/dist/core/slow-statement.d.ts +81 -0
  82. package/dist/core/slow-statement.d.ts.map +1 -0
  83. package/dist/core/slow-statement.js +149 -0
  84. package/dist/core/slow-statement.js.map +1 -0
  85. package/dist/core/wal-policy.d.ts +86 -0
  86. package/dist/core/wal-policy.d.ts.map +1 -0
  87. package/dist/core/wal-policy.js +115 -0
  88. package/dist/core/wal-policy.js.map +1 -0
  89. package/dist/dev.localdb.cli-group.descriptor.d.ts +1 -1
  90. package/dist/dev.localdb.cli-group.descriptor.d.ts.map +1 -1
  91. package/dist/dev.localdb.context.descriptor.d.ts +15 -1
  92. package/dist/dev.localdb.context.descriptor.d.ts.map +1 -1
  93. package/dist/dev.localdb.context.descriptor.js +1 -1
  94. package/dist/dev.localdb.context.descriptor.js.map +1 -1
  95. package/dist/dev.localdb.context.impl.consumer.d.ts +12 -5
  96. package/dist/dev.localdb.context.impl.consumer.d.ts.map +1 -1
  97. package/dist/dev.localdb.context.impl.consumer.js +14 -5
  98. package/dist/dev.localdb.context.impl.consumer.js.map +1 -1
  99. package/dist/driver/sqlite-driver.base.d.ts +107 -0
  100. package/dist/driver/sqlite-driver.base.d.ts.map +1 -0
  101. package/dist/driver/sqlite-driver.base.js +426 -0
  102. package/dist/driver/sqlite-driver.base.js.map +1 -0
  103. package/dist/driver/sqlite-driver.d.ts +154 -0
  104. package/dist/driver/sqlite-driver.d.ts.map +1 -0
  105. package/dist/driver/sqlite-driver.js +103 -0
  106. package/dist/driver/sqlite-driver.js.map +1 -0
  107. package/dist/index.d.ts +11 -5
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +8 -4
  110. package/dist/index.js.map +1 -1
  111. package/dist/localdb.client.descriptor.d.ts +10 -0
  112. package/dist/localdb.client.descriptor.d.ts.map +1 -0
  113. package/dist/localdb.client.descriptor.js +13 -0
  114. package/dist/localdb.client.descriptor.js.map +1 -0
  115. package/dist/localdb.client.impl.consumer.d.ts +11 -0
  116. package/dist/localdb.client.impl.consumer.d.ts.map +1 -0
  117. package/dist/localdb.client.impl.consumer.js +11 -0
  118. package/dist/localdb.client.impl.consumer.js.map +1 -0
  119. package/dist/localdb.plugin.d.ts +2 -2
  120. package/dist/localdb.plugin.d.ts.map +1 -1
  121. package/dist/localdb.plugin.js +58 -10
  122. package/dist/localdb.plugin.js.map +1 -1
  123. package/dist/location.d.ts +6 -0
  124. package/dist/location.d.ts.map +1 -0
  125. package/dist/location.js +6 -0
  126. package/dist/location.js.map +1 -0
  127. package/dist/migrations/load-sql.d.ts +25 -21
  128. package/dist/migrations/load-sql.d.ts.map +1 -1
  129. package/dist/migrations/load-sql.js +91 -76
  130. package/dist/migrations/load-sql.js.map +1 -1
  131. package/dist/pool.d.ts +3 -0
  132. package/dist/pool.d.ts.map +1 -0
  133. package/dist/pool.js +3 -0
  134. package/dist/pool.js.map +1 -0
  135. package/dist/schemas/api.d.ts +133 -59
  136. package/dist/schemas/api.d.ts.map +1 -1
  137. package/dist/schemas/api.js +1 -1
  138. package/dist/schemas/api.js.map +1 -1
  139. package/dist/schemas/migrations.d.ts +123 -0
  140. package/dist/schemas/migrations.d.ts.map +1 -0
  141. package/dist/schemas/migrations.js +55 -0
  142. package/dist/schemas/migrations.js.map +1 -0
  143. package/dist/schemas/pool.d.ts +27 -0
  144. package/dist/schemas/pool.d.ts.map +1 -0
  145. package/dist/schemas/pool.js +7 -0
  146. package/dist/schemas/pool.js.map +1 -0
  147. package/dist/schemas/sqlite-driver-base.d.ts +50 -0
  148. package/dist/schemas/sqlite-driver-base.d.ts.map +1 -0
  149. package/dist/schemas/sqlite-driver-base.js +2 -0
  150. package/dist/schemas/sqlite-driver-base.js.map +1 -0
  151. package/dist/testing/sqlite-driver-conformance.d.ts +42 -0
  152. package/dist/testing/sqlite-driver-conformance.d.ts.map +1 -0
  153. package/dist/testing/sqlite-driver-conformance.js +471 -0
  154. package/dist/testing/sqlite-driver-conformance.js.map +1 -0
  155. package/package.json +78 -104
  156. package/dist/core/error-context.d.ts +0 -2
  157. package/dist/core/error-context.d.ts.map +0 -1
  158. package/dist/core/error-context.js +0 -17
  159. package/dist/core/error-context.js.map +0 -1
  160. package/dist/core/runtime.d.ts +0 -3
  161. package/dist/core/runtime.d.ts.map +0 -1
  162. package/dist/core/runtime.js +0 -17
  163. package/dist/core/runtime.js.map +0 -1
  164. package/dist/localdb.cloud.plugin.d.ts +0 -17
  165. package/dist/localdb.cloud.plugin.d.ts.map +0 -1
  166. package/dist/localdb.cloud.plugin.js +0 -23
  167. package/dist/localdb.cloud.plugin.js.map +0 -1
  168. package/src/cli/commands/_shared.consumer.ts +0 -20
  169. package/src/cli/commands/migrate/dev.localdb.migrate.cli-command.descriptor.ts +0 -20
  170. package/src/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.ts +0 -97
  171. package/src/cli/commands/namespaces/dev.localdb.namespaces.cli-command.descriptor.ts +0 -17
  172. package/src/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.ts +0 -46
  173. package/src/cli/commands/pools/dev.localdb.pools.cli-command.descriptor.ts +0 -16
  174. package/src/cli/commands/pools/dev.localdb.pools.cli-command.impl.ts +0 -37
  175. package/src/cli/commands/query/dev.localdb.query.cli-command.descriptor.ts +0 -21
  176. package/src/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.ts +0 -69
  177. package/src/cli/commands/status/dev.localdb.status.cli-command.descriptor.ts +0 -20
  178. package/src/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.ts +0 -93
  179. package/src/core/connection-pool.ts +0 -240
  180. package/src/core/database.ts +0 -419
  181. package/src/core/error-context.ts +0 -19
  182. package/src/core/migration-registry.ts +0 -321
  183. package/src/core/runtime.ts +0 -17
  184. package/src/dev.localdb.cli-group.descriptor.ts +0 -20
  185. package/src/dev.localdb.context.descriptor.ts +0 -13
  186. package/src/dev.localdb.context.impl.consumer.ts +0 -12
  187. package/src/index.ts +0 -28
  188. package/src/localdb.cloud.plugin.ts +0 -24
  189. package/src/localdb.plugin.ts +0 -43
  190. package/src/migrations/atlas/001-initial-schema.sql +0 -173
  191. package/src/migrations/atlas/002-lang-server-fields.sql +0 -12
  192. package/src/migrations/atlas/003-config-id-dedup.sql +0 -31
  193. package/src/migrations/atlas/004-fix-on-conflict-constraints.sql +0 -25
  194. package/src/migrations/atlas/005-diagnostics.sql +0 -66
  195. package/src/migrations/atlas/006-diagnostic-summaries.sql +0 -65
  196. package/src/migrations/atlas/007-diagnostic-slice.sql +0 -83
  197. package/src/migrations/load-sql.ts +0 -133
  198. package/src/schemas/api.ts +0 -92
@@ -7,78 +7,236 @@
7
7
  * Features:
8
8
  * - Singleton pattern per database path
9
9
  * - Automatic WAL mode and busy timeout configuration
10
+ * - A bounded WAL (D-WAL, see `wal-policy.ts`): `journal_size_limit`; one
11
+ * non-blocking checkpoint attempt per idle window (TRUNCATE, falling back to
12
+ * RESTART after a busy attempt) with busy attempts backing off by whole
13
+ * windows; an attempt on release to zero references and at close; observed
14
+ * `(busy, log, checkpointed)` results with busy outcomes logged; and a bound
15
+ * on how long a transaction may stay open
10
16
  * - Connection reuse across consumers
11
- * - Safe cleanup on process exit
17
+ * - Slow-statement reporting: a statement at or over `SLOW_STATEMENT_MS` on any
18
+ * pooled connection is recorded with its operation and table, and the tick
19
+ * reports it (see `slow-statement.ts`) — value-free, and never from the
20
+ * statement's own path
21
+ * - Explicit, host-owned cleanup
12
22
  * - Connection statistics and monitoring
23
+ *
24
+ * The pool never deletes a raw `-wal` or `-shm` file.
25
+ *
26
+ * Hosts sharing one pool have at most one connection per path: two connections to one
27
+ * file on the same thread can wait on each other inside SQLite's synchronous
28
+ * busy handler. A composition root that boots several runtimes in one process
29
+ * creates the pool explicitly (`createConnectionPool`) and hands it to every
30
+ * runtime it boots (`shareConnectionPool`), so those runtimes — including
31
+ * reload-generation forks, which inherit the registration — share the one
32
+ * connection per path. A process that boots a single runtime uses the
33
+ * runtime-owned default the LocalDB plugin registers instead. Each call
34
+ * reports on the runtime it was handed (C083a), never on an ambient default.
35
+ *
36
+ * Maintenance is owned by a runtime lifecycle (RC07). A connection records the
37
+ * runtimes that acquired it and runs its maintenance tick on the lifecycle of
38
+ * one of them that is live and persistent; when that lifecycle ends, the tick
39
+ * ends with it and moves to the next live persistent holder. The reload
40
+ * generation dispatcher reads whichever generation serves: it stays a holder
41
+ * while it serves a live one, so its tick follows it from a retiring
42
+ * generation to the next. A connection no persistent runtime
43
+ * holds gets no tick: it checkpoints on release to zero references and on
44
+ * close/shutdown instead, until a persistent runtime acquires it again.
13
45
  */
14
- import { Database } from 'bun:sqlite';
15
- export interface PooledConnection {
16
- db: Database;
17
- refCount: number;
18
- lastUsed: number;
19
- createdAt: number;
20
- consumer: string;
21
- }
22
- export interface ConnectionStats {
23
- total: number;
24
- active: number;
25
- idle: number;
26
- connections: Array<{
27
- path: string;
28
- refCount: number;
29
- ageMs: number;
30
- consumer: string;
31
- }>;
32
- }
33
- declare class SQLiteConnectionPool {
46
+ import { type RuntimeRef } from '@vibesdotdev/kernel';
47
+ export { PoolDescriptorSchema, type PoolDescriptor } from '../schemas/pool.ts';
48
+ import type { ConnectionStats } from '../schemas/api.ts';
49
+ import type { SqliteConnection } from '../driver/sqlite-driver.ts';
50
+ export type { ConnectionStats, PooledConnection, WalCheckpointTrigger } from '../schemas/api.ts';
51
+ export declare class SQLiteConnectionPool {
34
52
  private connections;
35
- private cleanupInterval?;
53
+ /** Physical path custody spans every runtime-local manager using this pool. */
54
+ private readonly databasePathLocks;
36
55
  private readonly STALE_THRESHOLD_MS;
37
- private readonly CLEANUP_INTERVAL_MS;
38
- constructor();
56
+ /** Opens in flight, by path: concurrent first acquisitions share one connection. */
57
+ private readonly opening;
58
+ /** Serialize managed initialization, migration, release and reset against the same physical file. */
59
+ withDatabasePathLock<T>(dbPath: string, task: () => Promise<T>): Promise<T>;
60
+ /**
61
+ * Get or create a database connection with optimal configuration, opened
62
+ * through the SQLite driver the calling runtime's host registered. The
63
+ * calling runtime becomes a holder of the connection and reports the open.
64
+ * A runtime whose disposal began is refused before any connection opens
65
+ * (`CANCELLED` `runtime-disposed`), and again if it began while the open
66
+ * was in flight. Cancellation before publication closes the startup handle.
67
+ */
68
+ getConnection(runtime: RuntimeRef, dbPath: string, consumer?: string): Promise<SqliteConnection>;
69
+ /** Open and pool the connection at `dbPath` with the LocalDB pragmas, through the runtime's driver. */
70
+ private open;
71
+ /**
72
+ * Record `runtime` as a holder of the pooled connection at `dbPath`, so its
73
+ * maintenance can run on (or move to) that runtime. No connection there:
74
+ * nothing to hold.
75
+ */
76
+ retain(runtime: RuntimeRef, dbPath: string): void;
77
+ private hold;
39
78
  /**
40
- * Get or create a database connection with optimal configuration
79
+ * Keep the connection's tick on a live persistent holder. A tick whose
80
+ * lifecycle (the one it started on) is still live, on a runtime that still
81
+ * holds the connection, stays where it is;
82
+ * otherwise the first live persistent holder takes it, and holders that
83
+ * ended are dropped.
41
84
  */
42
- getConnection(dbPath: string, consumer?: string): Database;
85
+ private ensureMaintenance;
43
86
  /**
44
- * Configure database with optimal settings for concurrent access
87
+ * Run the connection's tick on the lifecycle `runtime` reads now. The tick
88
+ * ends when that lifecycle ends (it clears every interval). At that moment
89
+ * the runtime is dropped as a holder unless it now reads a live lifecycle
90
+ * (the reload generation dispatcher, whose `lifecycle` follows whichever
91
+ * generation serves), and the tick moves to the next live persistent
92
+ * holder, that runtime included.
45
93
  */
46
- private configureDatabase;
94
+ private maintainOn;
95
+ /** One maintenance tick for one connection. It never throws into the timer: a failure is logged with its cause. */
96
+ private tick;
47
97
  /**
48
98
  * Release a connection (decrement reference count)
49
99
  * Connection remains in pool for reuse
50
100
  */
51
- releaseConnection(dbPath: string): void;
101
+ releaseConnection(runtime: RuntimeRef, dbPath: string): void;
52
102
  /**
53
- * Close a specific connection immediately
54
- * Only closes if reference count is zero (unless forced)
103
+ * Run one observed, non-blocking checkpoint attempt and record its outcome,
104
+ * reported on `runtime`. A busy attempt is logged at warn (a run of
105
+ * {@link WAL_BUSY_STARVATION_THRESHOLD} at error, as starvation), switches
106
+ * the next attempt's mode, and backs the connection off by whole windows. A
107
+ * checkpoint SQLite itself rejects is logged at error with its cause and
108
+ * never blocks the caller's close or tick.
55
109
  */
56
- closeConnection(dbPath: string, force?: boolean): boolean;
110
+ private observeCheckpoint;
57
111
  /**
58
- * Clean up stale connections (unused for 30+ minutes with zero references)
112
+ * Bound how long a pooled connection may sit inside a transaction. SQLite
113
+ * is synchronous, so a transaction a tick can observe spans an `await`; one
114
+ * older than {@link MAX_TRANSACTION_AGE_MS} pins every WAL frame written
115
+ * after it began, in every process. It is rolled back and reported; the
116
+ * owner's later COMMIT then fails loudly rather than the WAL growing silently.
117
+ *
118
+ * @returns whether the connection is still inside a transaction.
59
119
  */
60
- private cleanupStale;
120
+ private enforceTransactionBound;
61
121
  /**
62
- * Start periodic cleanup
122
+ * Report the statements this window recorded as slow, on `runtime` and once
123
+ * per connection. Each report carries the connection's consumer and database
124
+ * with the statement's operation and table; a window that recorded more than
125
+ * it kept says so rather than reading as a complete count.
63
126
  */
64
- private startCleanup;
127
+ private reportSlowStatements;
65
128
  /**
66
- * Stop periodic cleanup
129
+ * One idle window for one connection: report what it recorded as slow, bound
130
+ * an open transaction, close the connection when it has been unused for 30+
131
+ * minutes with zero references, or make at most one observed checkpoint
132
+ * attempt when it is not inside a transaction and not backing off. Every step
133
+ * reports its own failure.
67
134
  */
68
- private stopCleanup;
135
+ private maintainConnection;
69
136
  /**
70
- * Close all connections (typically on shutdown)
137
+ * One maintenance pass over every pooled connection, reported on `runtime`.
138
+ * Each connection's lifecycle tick runs the same window for that connection
139
+ * alone; hosts and tests may call this directly.
71
140
  */
72
- closeAll(): void;
141
+ maintain(runtime: RuntimeRef, now?: number): void;
73
142
  /**
74
- * Get pool statistics
143
+ * Close one pooled connection and remove it from the pool, reported on
144
+ * `runtime`. A connection still inside a transaction is closed without a
145
+ * checkpoint, and SQLite discards that transaction: the discard is
146
+ * reported, never silent. A close SQLite refuses throws
147
+ * `localdb-close-failed` (the original error as `cause`) and the connection
148
+ * stays pooled, still maintained, for a retry.
75
149
  */
76
- getStats(): ConnectionStats;
150
+ private closePooled;
77
151
  /**
78
- * Register process exit handlers for cleanup
152
+ * Refuse destructive replacement while another lifecycle or pooled reference
153
+ * holds the file. Only the requesting instance's actual open connection may
154
+ * account for one reference; legacy/raw borrowers keep their custody too.
155
+ * Call under the database path lock, before releasing or closing anything.
79
156
  */
80
- private registerExitHandlers;
157
+ assertCanReplaceDatabase(runtime: RuntimeRef, dbPath: string, ownedConnection?: SqliteConnection): void;
158
+ /**
159
+ * Give back one pooled reference no live runtime holds: every recorded
160
+ * holder ended (or none is recorded) while the reference count is still
161
+ * nonzero — typically a client of a runtime that ended without releasing.
162
+ * Returns whether a reference was given back. A connection another live
163
+ * runtime still holds is never touched.
164
+ */
165
+ releaseOrphanedConnection(dbPath: string): boolean;
166
+ /**
167
+ * Close a specific connection immediately. Only closes if the reference
168
+ * count is zero, unless forced. Returns whether it closed; a close SQLite
169
+ * refuses throws `localdb-close-failed` and leaves the connection pooled.
170
+ */
171
+ closeConnection(runtime: RuntimeRef, dbPath: string, force?: boolean): boolean;
172
+ /**
173
+ * Give back every connection `runtime` holds (typically at its disposal),
174
+ * reported on `runtime`; runtimes that ended hold nothing. A connection
175
+ * another live runtime still holds (another root, or the root a disposing
176
+ * reload generation was forked from) stays pooled for it, its maintenance moving to that
177
+ * holder; every other connection closes. Every close is attempted; the ones
178
+ * SQLite refuses stay pooled and are reported together in one AggregateError
179
+ * so the runtime owner can report them and retry.
180
+ */
181
+ closeAll(runtime: RuntimeRef, retainedPaths?: ReadonlySet<string>): void;
182
+ /** Whether a managed handle still names the pooled connection at this path. */
183
+ ownsConnection(dbPath: string, db: SqliteConnection): boolean;
184
+ /**
185
+ * Get pool statistics
186
+ */
187
+ getStats(): ConnectionStats;
81
188
  }
82
- export declare const connectionPool: SQLiteConnectionPool;
83
- export {};
189
+ /**
190
+ * The `localdb/pool` kind: the process's physical SQLite connections, owned
191
+ * through the kernel. The pool holds live host handles, so — unlike migration
192
+ * declarations, which each runtime owns separately — runtimes that must open
193
+ * the same file share one pool instance resolved from the runtime they are
194
+ * handed. No module-level pool instance exists: every instance is created
195
+ * explicitly (`createConnectionPool`, the plugin default, or a shared owner a
196
+ * composition root registers) and resolved through the kernel below.
197
+ */
198
+ export declare const LOCALDB_POOL_KIND = "localdb/pool";
199
+ /** The runtime-owned default pool, created per root runtime by the LocalDB plugin. */
200
+ export declare const DEFAULT_POOL_ID = "pool";
201
+ /**
202
+ * An explicitly shared pool, handed to each runtime by the composition root
203
+ * that boots them. Preferred over the default whenever it is registered.
204
+ */
205
+ export declare const SHARED_POOL_ID = "shared";
206
+ /** The kind LocalDB registers; an implementation that is not a pool is refused `implementation-invalid`. */
207
+ export declare const poolKind: import("@vibesdotdev/kernel").RuntimeKindDescriptorRecord<SQLiteConnectionPool>;
208
+ /**
209
+ * Create the physical connection pool a composition root hands to the runtimes
210
+ * it boots. One pool per process per database set: every runtime handed the
211
+ * same pool shares the one connection per path.
212
+ */
213
+ export declare function createConnectionPool(): SQLiteConnectionPool;
214
+ /**
215
+ * Resolve the runtime's physical connection pool through the kernel on every
216
+ * call, so current selection, invalidation, and implementation caching remain
217
+ * owned by the runtime: an explicitly shared pool when the composition root
218
+ * registered one, else the runtime-owned default the LocalDB plugin
219
+ * registered. Anything else (a refused loader, an invalid implementation)
220
+ * propagates unwrapped.
221
+ */
222
+ export declare function poolOf(runtime: RuntimeRef): Promise<SQLiteConnectionPool>;
223
+ /**
224
+ * The already-resolved pool, or `undefined` when no resolution warmed the
225
+ * kernel cache yet. Synchronous cover for call sites that hold no async
226
+ * context after an async call resolved the pool first.
227
+ */
228
+ export declare function tryPoolOf(runtime: RuntimeRef): SQLiteConnectionPool | undefined;
229
+ /**
230
+ * Register the runtime-owned default pool, unless one is already registered:
231
+ * reload-generation forks inherit their root's registrations, so they keep
232
+ * sharing the root's pool instead of minting a second connection per path.
233
+ */
234
+ export declare function ensureDefaultPool(runtime: RuntimeRef): void;
235
+ /**
236
+ * Hand one explicitly created pool to a runtime: every runtime the
237
+ * composition root boots against the same database files shares the one
238
+ * connection per path. Fork generations inherit the registration, so they
239
+ * share it too.
240
+ */
241
+ export declare function shareConnectionPool(runtime: RuntimeRef, pool: SQLiteConnectionPool): void;
84
242
  //# sourceMappingURL=connection-pool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection-pool.d.ts","sourceRoot":"","sources":["../../src/core/connection-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,WAAW,gBAAgB;IAChC,EAAE,EAAE,QA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