@vibesdotdev/localdb 0.0.1 → 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 (199) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +134 -112
  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 +79 -106
  156. package/SPEC.md +0 -119
  157. package/dist/core/error-context.d.ts +0 -2
  158. package/dist/core/error-context.d.ts.map +0 -1
  159. package/dist/core/error-context.js +0 -17
  160. package/dist/core/error-context.js.map +0 -1
  161. package/dist/core/runtime.d.ts +0 -3
  162. package/dist/core/runtime.d.ts.map +0 -1
  163. package/dist/core/runtime.js +0 -17
  164. package/dist/core/runtime.js.map +0 -1
  165. package/dist/localdb.cloud.plugin.d.ts +0 -17
  166. package/dist/localdb.cloud.plugin.d.ts.map +0 -1
  167. package/dist/localdb.cloud.plugin.js +0 -23
  168. package/dist/localdb.cloud.plugin.js.map +0 -1
  169. package/src/cli/commands/_shared.consumer.ts +0 -20
  170. package/src/cli/commands/migrate/dev.localdb.migrate.cli-command.descriptor.ts +0 -20
  171. package/src/cli/commands/migrate/dev.localdb.migrate.cli-command.impl.consumer.ts +0 -97
  172. package/src/cli/commands/namespaces/dev.localdb.namespaces.cli-command.descriptor.ts +0 -17
  173. package/src/cli/commands/namespaces/dev.localdb.namespaces.cli-command.impl.ts +0 -46
  174. package/src/cli/commands/pools/dev.localdb.pools.cli-command.descriptor.ts +0 -16
  175. package/src/cli/commands/pools/dev.localdb.pools.cli-command.impl.ts +0 -37
  176. package/src/cli/commands/query/dev.localdb.query.cli-command.descriptor.ts +0 -21
  177. package/src/cli/commands/query/dev.localdb.query.cli-command.impl.consumer.ts +0 -69
  178. package/src/cli/commands/status/dev.localdb.status.cli-command.descriptor.ts +0 -20
  179. package/src/cli/commands/status/dev.localdb.status.cli-command.impl.consumer.ts +0 -93
  180. package/src/core/connection-pool.ts +0 -240
  181. package/src/core/database.ts +0 -419
  182. package/src/core/error-context.ts +0 -19
  183. package/src/core/migration-registry.ts +0 -321
  184. package/src/core/runtime.ts +0 -17
  185. package/src/dev.localdb.cli-group.descriptor.ts +0 -20
  186. package/src/dev.localdb.context.descriptor.ts +0 -13
  187. package/src/dev.localdb.context.impl.consumer.ts +0 -12
  188. package/src/index.ts +0 -28
  189. package/src/localdb.cloud.plugin.ts +0 -24
  190. package/src/localdb.plugin.ts +0 -43
  191. package/src/migrations/atlas/001-initial-schema.sql +0 -173
  192. package/src/migrations/atlas/002-lang-server-fields.sql +0 -12
  193. package/src/migrations/atlas/003-config-id-dedup.sql +0 -31
  194. package/src/migrations/atlas/004-fix-on-conflict-constraints.sql +0 -25
  195. package/src/migrations/atlas/005-diagnostics.sql +0 -66
  196. package/src/migrations/atlas/006-diagnostic-summaries.sql +0 -65
  197. package/src/migrations/atlas/007-diagnostic-slice.sql +0 -83
  198. package/src/migrations/load-sql.ts +0 -133
  199. package/src/schemas/api.ts +0 -92
@@ -1,115 +1,130 @@
1
1
  /**
2
2
  * SQL Migration Loader
3
3
  *
4
- * Utility for loading SQL migration files from the filesystem.
5
- * Uses Bun's file API for fast synchronous reads.
4
+ * Reads an owner's migration SQL files from the absolute directory the owner
5
+ * passes (PM and Workspace pass their own `migrations/<namespace>` directory),
6
+ * through the runtime's filesystem (`filesystem/adapter`). LocalDB ships no SQL
7
+ * of its own, so there is no package-relative lookup.
6
8
  */
7
- import { existsSync, readdirSync, readFileSync } from 'node:fs';
8
- import { dirname, join } from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
- import { isLocaldbServerRuntime } from "../core/runtime.js";
11
- const isServerRuntime = isLocaldbServerRuntime();
12
- const __dirname = isServerRuntime ? dirname(fileURLToPath(import.meta.url)) : '';
13
- function throwIfBrowser() {
14
- if (!isServerRuntime) {
15
- throw new Error('SQL migrations are not available in browser builds');
9
+ import { CapabilityError } from '@vibesdotdev/kernel';
10
+ import * as z from 'zod/v4';
11
+ import { fileSystemOf } from "../core/host-kinds.js";
12
+ /** The owner's migration directory; a relative path is refused rather than resolved against a guessed base. */
13
+ function migrationDirectory(files, directory) {
14
+ if (!files.isAbsolute(directory)) {
15
+ throw new CapabilityError(`Migration directory must be an absolute path: ${directory}`, 'INVALID_INPUT', {
16
+ reason: 'migration-directory-relative',
17
+ retryable: false,
18
+ details: { directory }
19
+ });
16
20
  }
21
+ return directory;
17
22
  }
23
+ const SqlTextSchema = z.string();
18
24
  /**
19
- * Load a SQL migration file by namespace and filename (async)
25
+ * Load a SQL migration file from an owner's migration directory, through the
26
+ * runtime's filesystem.
20
27
  *
21
- * @param namespace - The migration namespace (atlas, session, external)
28
+ * @param runtime - The runtime the owner was handed
29
+ * @param directory - The owner's absolute migration directory
22
30
  * @param filename - The SQL filename (e.g., '001-initial-schema.sql')
23
- * @returns Promise resolving to the SQL content as a string
31
+ * @returns The SQL content; every failure rejects (`INVALID_INPUT
32
+ * migration-directory-relative`, `NOT_FOUND migration-file-missing`, or the
33
+ * filesystem's own refusal)
24
34
  */
25
- export function loadMigrationSQL(namespace, filename) {
26
- throwIfBrowser();
27
- const namespaceDir = resolveMigrationNamespaceDir(namespace);
28
- if (!namespaceDir) {
29
- throw new Error(`Migration namespace not found: ${namespace}`);
35
+ export async function loadMigrationSQL(runtime, directory, filename) {
36
+ const files = await fileSystemOf(runtime);
37
+ const filePath = files.join(migrationDirectory(files, directory), filename);
38
+ if (!(await files.exists(filePath))) {
39
+ throw new CapabilityError(`Migration file not found: ${filePath}`, 'NOT_FOUND', {
40
+ reason: 'migration-file-missing',
41
+ details: { directory, filename }
42
+ });
30
43
  }
31
- const filePath = join(namespaceDir, filename);
32
- if (!existsSync(filePath)) {
33
- throw new Error(`Migration file not found: ${filePath}`);
34
- }
35
- return Bun.file(filePath).text();
44
+ return SqlTextSchema.parse(await files.readFile(filePath, 'utf-8'));
36
45
  }
37
46
  /**
38
- * Synchronously load a SQL migration file
39
- * Uses Node's fs.readFileSync for truly synchronous reads
47
+ * List the SQL files in an owner's migration directory, sorted by version,
48
+ * through the runtime's filesystem. A directory that does not exist lists
49
+ * nothing.
40
50
  *
41
- * @param namespace - The migration namespace (atlas, session, external)
42
- * @param filename - The SQL filename (e.g., '001-initial-schema.sql')
43
- * @returns The SQL content as a string
51
+ * @param runtime - The runtime the owner was handed
52
+ * @param directory - The owner's absolute migration directory
53
+ * @returns SQL filenames sorted by their numeric version prefix
44
54
  */
45
- export function loadMigrationSQLSync(namespace, filename) {
46
- throwIfBrowser();
47
- const namespaceDir = resolveMigrationNamespaceDir(namespace);
48
- if (!namespaceDir) {
49
- throw new Error(`Migration namespace not found: ${namespace}`);
50
- }
51
- const filePath = join(namespaceDir, filename);
52
- if (!existsSync(filePath)) {
53
- throw new Error(`Migration file not found: ${filePath}`);
54
- }
55
- return readFileSync(filePath, 'utf-8');
56
- }
57
- /**
58
- * List all SQL files in a namespace directory
59
- *
60
- * @param namespace - The migration namespace (atlas, session, external)
61
- * @returns Array of SQL filenames sorted by version number
62
- */
63
- export function listMigrationFiles(namespace) {
64
- throwIfBrowser();
65
- const dirPath = resolveMigrationNamespaceDir(namespace);
66
- if (!dirPath || !existsSync(dirPath)) {
55
+ export async function listMigrationFiles(runtime, directory) {
56
+ const files = await fileSystemOf(runtime);
57
+ const dirPath = migrationDirectory(files, directory);
58
+ if (!(await files.exists(dirPath))) {
67
59
  return [];
68
60
  }
69
- return readdirSync(dirPath)
70
- .filter((f) => f.endsWith('.sql') && !f.startsWith('.'))
71
- .sort((a, b) => {
72
- // Extract version numbers (e.g., '001' from '001-initial-schema.sql')
73
- const versionA = parseInt(a.split('-')[0], 10);
74
- const versionB = parseInt(b.split('-')[0], 10);
75
- return versionA - versionB;
61
+ return (await files.list(dirPath))
62
+ .map((entry) => entry.name)
63
+ .filter((name) => name.endsWith('.sql') && !name.startsWith('.'))
64
+ .sort((a, b) => leadingVersion(a) - leadingVersion(b));
65
+ }
66
+ /** The numeric prefix of a migration filename ('001-initial-schema.sql' and '001_init.sql' are both 1). */
67
+ function leadingVersion(filename) {
68
+ return Number.parseInt(filename, 10);
69
+ }
70
+ const MigrationFilenameSchema = z.string();
71
+ /** The typed refusal of a migration filename that is not a string with a leading `<digits>-` version. */
72
+ function filenameInvalid(message, details, cause) {
73
+ return new CapabilityError(message, 'INVALID_INPUT', {
74
+ reason: 'migration-filename-invalid',
75
+ retryable: false,
76
+ details,
77
+ cause
76
78
  });
77
79
  }
78
- function resolveMigrationNamespaceDir(namespace) {
79
- // If the namespace is already an absolute path that exists, use it directly.
80
- // External packages (e.g. PM) pass their own migration directory as a full path.
81
- if (namespace.startsWith('/') && existsSync(namespace)) {
82
- return namespace;
80
+ /**
81
+ * Read a migration filename once: a string, or the typed refusal. Zod's string
82
+ * check throws on a revoked Proxy; that throw is the refusal's cause.
83
+ */
84
+ function readFilename(filename) {
85
+ let error;
86
+ try {
87
+ const parsed = MigrationFilenameSchema.safeParse(filename);
88
+ if (parsed.success)
89
+ return parsed.data;
90
+ error = parsed.error;
83
91
  }
84
- // Bundled migrations are loaded from the package-local migrations directory.
85
- const bundledPath = join(__dirname, namespace);
86
- if (existsSync(bundledPath)) {
87
- return bundledPath;
92
+ catch (cause) {
93
+ throw new CapabilityError('Invalid migration filename format: it could not be read', 'INVALID_INPUT', {
94
+ reason: 'migration-filename-invalid',
95
+ retryable: false,
96
+ cause
97
+ });
88
98
  }
89
- return null;
99
+ throw filenameInvalid('Invalid migration filename format: not a string', {}, error);
90
100
  }
91
101
  /**
92
102
  * Parse version number from a migration filename
93
103
  *
94
104
  * @param filename - The SQL filename (e.g., '001-initial-schema.sql')
95
- * @returns The version number
105
+ * @returns The version number; a filename without a leading `<digits>-`, or
106
+ * whose version is not a safe integer, refuses `INVALID_INPUT
107
+ * migration-filename-invalid`
96
108
  */
97
109
  export function parseVersionFromFilename(filename) {
98
- const match = filename.match(/^(\d+)-/);
99
- if (!match) {
100
- throw new Error(`Invalid migration filename format: ${filename}`);
101
- }
102
- return parseInt(match[1], 10);
110
+ const text = readFilename(filename);
111
+ const digits = /^(\d+)-/.exec(text)?.[1];
112
+ const version = digits === undefined ? Number.NaN : Number.parseInt(digits, 10);
113
+ if (!Number.isSafeInteger(version))
114
+ throw filenameInvalid(`Invalid migration filename format: ${text}`, { filename: text });
115
+ return version;
103
116
  }
104
117
  /**
105
118
  * Parse migration name from a filename
106
119
  *
107
120
  * @param filename - The SQL filename (e.g., '001-initial-schema.sql')
108
- * @returns The migration name (e.g., 'initial_schema')
121
+ * @returns The migration name (e.g., 'initial_schema'); a filename that is not
122
+ * a string refuses `INVALID_INPUT migration-filename-invalid`
109
123
  */
110
124
  export function parseMigrationName(filename) {
125
+ const text = readFilename(filename);
111
126
  // Remove version prefix and .sql extension
112
- const withoutVersion = filename.replace(/^\d+-/, '');
127
+ const withoutVersion = text.replace(/^\d+-/, '');
113
128
  const withoutExtension = withoutVersion.replace(/\.sql$/, '');
114
129
  // Convert hyphens to underscores
115
130
  return withoutExtension.replace(/-/g, '_');
@@ -1 +1 @@
1
- {"version":3,"file":"load-sql.js","sourceRoot":"","sources":["../../src/migrations/load-sql.ts"],"names":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AAC;AAC5C,CAAC"}
package/dist/pool.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** Explicit physical-owner composition and implementation entrypoint. */
2
+ export { SQLiteConnectionPool, createConnectionPool, shareConnectionPool } from './core/connection-pool.ts';
3
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EACN,oBAAoB,EAAE,oBAAoB,EAAE,mBAAmB,EAC/D,MAAM,2BAA2B,CAAC"}
package/dist/pool.js ADDED
@@ -0,0 +1,3 @@
1
+ /** Explicit physical-owner composition and implementation entrypoint. */
2
+ export { SQLiteConnectionPool, createConnectionPool, shareConnectionPool } from "./core/connection-pool.js";
3
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EACN,oBAAoB,EAAE,oBAAoB,EAAE,mBAAmB,EAC/D,MAAM,2BAA2B,CAAC"}
@@ -1,35 +1,60 @@
1
- import type { Database } from 'bun:sqlite';
2
- export type LocaldbBinding = string | number | bigint | boolean | null | Uint8Array;
3
- export interface LocaldbQuery<T> {
4
- all(...params: LocaldbBinding[]): T[];
5
- get(...params: LocaldbBinding[]): T | null;
1
+ import type { Disposer, RuntimeRef } from '@vibesdotdev/kernel';
2
+ import type { SqliteConnection } from '../driver/sqlite-driver.ts';
3
+ import type { SlowStatementRecorder } from '../core/slow-statement.ts';
4
+ import type { WalCheckpointMode, WalCheckpointOutcome } from '../core/wal-policy.ts';
5
+ /** The connection LocalDB hands out: the host's `localdb/sqlite-driver` connection. */
6
+ export type LocaldbRawDatabase = SqliteConnection;
7
+ import type { Migration, NamespaceDatabaseLocation, RegisterMigrationsOptions, ReplaceMigrationsOptions } from './migrations.ts';
8
+ export * from './migrations.ts';
9
+ export interface DatabaseOptions {
10
+ namespace: string;
11
+ dbPath: string;
12
+ consumer?: string;
13
+ skipMigrations?: boolean;
14
+ usePool?: boolean;
6
15
  }
7
- export interface LocaldbStatementResult {
8
- changes: number;
9
- lastInsertRowid: number | bigint | null;
10
- }
11
- export interface LocaldbStatement {
12
- run(...params: LocaldbBinding[]): LocaldbStatementResult;
13
- get<T>(...params: LocaldbBinding[]): T;
14
- all<T>(...params: LocaldbBinding[]): T[];
15
- }
16
- export interface LocaldbRawDatabase {
17
- exec(sql: string): void;
18
- query<T>(sql: string): LocaldbQuery<T>;
19
- prepare(sql: string): LocaldbStatement;
20
- run(sql: string, ...params: LocaldbBinding[]): LocaldbStatementResult;
21
- }
22
- export type MigrationFunction = (db: Database) => void | Promise<void>;
23
- export interface Migration {
24
- version: number;
25
- name: string;
26
- up: MigrationFunction;
27
- down?: MigrationFunction;
16
+ export type WalCheckpointTrigger = 'idle' | 'release' | 'close' | 'shutdown';
17
+ /** Physical connection state shared per path; logical migration ownership belongs to the runtime API. */
18
+ export interface PooledConnection {
19
+ db: SqliteConnection;
20
+ slowStatements: SlowStatementRecorder;
21
+ refCount: number;
22
+ lastUsed: number;
23
+ createdAt: number;
24
+ consumer: string;
25
+ readonly holders: Set<RuntimeRef>;
26
+ maintenance?: {
27
+ readonly runtime: RuntimeRef;
28
+ readonly signal: AbortSignal;
29
+ readonly stop: Disposer;
30
+ };
31
+ transactionObservedAt?: number;
32
+ consecutiveCheckpointBusy: number;
33
+ lastCheckpoint?: WalCheckpointOutcome & {
34
+ at: number;
35
+ trigger: WalCheckpointTrigger;
36
+ };
37
+ nextCheckpointMode: WalCheckpointMode;
38
+ nextIdleCheckpointAt: number;
28
39
  }
29
- export interface LocalDatabase {
40
+ import type { LocalDatabase } from '../core/database.ts';
41
+ export type { LocalDatabase };
42
+ /**
43
+ * One managed database. Every call that can report something takes the runtime
44
+ * it serves: that runtime's Logging reports it (C083a), never an ambient one.
45
+ */
46
+ export interface LocalDatabaseContract {
30
47
  initialize(): Promise<void>;
31
- getDatabase(): Database;
32
- close(): void;
48
+ getDatabase(): SqliteConnection;
49
+ /** Give this instance's connection back, reported on the releasing runtime. */
50
+ close(runtime: RuntimeRef): void;
51
+ /**
52
+ * Check if database is healthy. A health probe answers false, with the
53
+ * reason logged on the probing runtime.
54
+ */
55
+ healthCheck(runtime: RuntimeRef): boolean;
56
+ /** Get migration status for this database. */
57
+ getMigrationStatus(): DatabaseMigrationStatus;
33
58
  }
34
59
  export interface ConnectionStats {
35
60
  total: number;
@@ -40,43 +65,92 @@ export interface ConnectionStats {
40
65
  refCount: number;
41
66
  ageMs: number;
42
67
  consumer: string;
68
+ /** Whether a live persistent runtime runs this connection's maintenance tick. */
69
+ maintained: boolean;
70
+ /** Runtimes recorded as holding this connection; ended ones are dropped on the next acquisition. */
71
+ holders: number;
72
+ /** Consecutive WAL checkpoints that came back busy or incomplete (D-WAL). */
73
+ consecutiveCheckpointBusy: number;
74
+ /** Most recent observed WAL checkpoint; absent until the first one runs. */
75
+ lastCheckpoint?: {
76
+ at: number;
77
+ trigger: 'idle' | 'release' | 'close' | 'shutdown';
78
+ status: 'complete' | 'busy' | 'not-wal';
79
+ mode: 'TRUNCATE' | 'RESTART';
80
+ busy: number;
81
+ log: number;
82
+ checkpointed: number;
83
+ };
43
84
  }>;
44
85
  }
86
+ /** A namespace's tracked schema version in one database, and the newest version this build knows. */
87
+ export interface MigrationVersions {
88
+ tracked: number | null;
89
+ current: number;
90
+ }
91
+ /** One registered migration and whether a database has applied it. */
92
+ export interface MigrationApplication {
93
+ version: number;
94
+ name: string;
95
+ applied: boolean;
96
+ }
97
+ /** A namespace's migration state in one database. */
98
+ export interface DatabaseMigrationStatus {
99
+ namespace: string;
100
+ currentVersion: number;
101
+ targetVersion: number;
102
+ pendingMigrations: number;
103
+ migrations: MigrationApplication[];
104
+ }
105
+ /** A registered namespace's target version (per-database state is reported by `getDatabaseStatus`). */
106
+ export interface NamespaceMigrationStatus {
107
+ namespace: string;
108
+ currentVersion: number;
109
+ targetVersion: number;
110
+ pendingMigrations: number;
111
+ }
45
112
  export interface MigrationRegistryApi {
46
- listNamespaces(): string[];
47
- getMigrations(namespace: string): Migration[];
48
- getDatabaseStatus(db: Database, namespace: string): {
49
- namespace: string;
50
- currentVersion: number;
51
- targetVersion: number;
52
- pendingMigrations: number;
53
- migrations: Array<{
54
- version: number;
55
- name: string;
56
- applied: boolean;
57
- }>;
58
- };
59
- needsMigration(db: Database, namespace: string): boolean;
60
- runMigrations(db: Database, namespace: string): Promise<void>;
61
- getStatus(): Array<{
62
- namespace: string;
63
- currentVersion: number;
64
- targetVersion: number;
65
- pendingMigrations: number;
66
- }>;
113
+ listNamespaces(runtime: RuntimeRef): string[];
114
+ getNamespaceLocation(runtime: RuntimeRef, namespace: string): NamespaceDatabaseLocation | undefined;
115
+ getMigrations(runtime: RuntimeRef, namespace: string): Migration[];
116
+ replaceMigrations(runtime: RuntimeRef, namespace: string, migrations: Migration[], options: ReplaceMigrationsOptions): boolean;
117
+ getDatabaseStatus(runtime: RuntimeRef, db: SqliteConnection, namespace: string): DatabaseMigrationStatus;
118
+ needsMigration(runtime: RuntimeRef, db: SqliteConnection, namespace: string): boolean;
119
+ runMigrations(runtime: RuntimeRef, db: SqliteConnection, namespace: string): Promise<void>;
120
+ getStatus(runtime: RuntimeRef): NamespaceMigrationStatus[];
67
121
  }
68
122
  export interface ConnectionPoolApi {
123
+ getConnection(runtime: RuntimeRef, dbPath: string, consumer?: string): Promise<SqliteConnection>;
124
+ releaseConnection(runtime: RuntimeRef, dbPath: string): void;
125
+ retain(runtime: RuntimeRef, dbPath: string): void;
126
+ closeConnection(runtime: RuntimeRef, dbPath: string, force?: boolean): boolean;
127
+ maintain(runtime: RuntimeRef, now?: number): void;
69
128
  getStats(): ConnectionStats;
70
- closeAll(): void;
129
+ closeAll(runtime: RuntimeRef, retainedPaths?: ReadonlySet<string>): void;
130
+ withDatabasePathLock<T>(dbPath: string, task: () => Promise<T>): Promise<T>;
131
+ assertCanReplaceDatabase(runtime: RuntimeRef, dbPath: string, ownedConnection?: SqliteConnection): void;
132
+ releaseOrphanedConnection(dbPath: string): boolean;
133
+ ownsConnection(dbPath: string, db: SqliteConnection): boolean;
71
134
  }
135
+ /**
136
+ * The `localdb` manager. Every call that opens, registers, releases or closes
137
+ * takes the runtime it serves first: that runtime's Logging reports the call,
138
+ * and a connection it opens is maintained on its lifecycle when it is
139
+ * persistent.
140
+ */
72
141
  export interface LocaldbApi {
73
- registerMigrations(namespace: string, migrations: Migration[]): void;
74
- getDatabase(namespace: string, dbPath: string, consumer?: string): Promise<LocalDatabase>;
75
- getRawDatabase(dbPath: string, consumer?: string): Database;
76
- releaseDatabase(namespace: string, dbPath: string): Promise<void>;
77
- getPoolStats(): ConnectionStats;
78
- getMigrationStatus(): ReturnType<MigrationRegistryApi['getStatus']>;
79
- listNamespaces(): string[];
80
- closeAll(): Promise<void>;
142
+ registerMigrations(runtime: RuntimeRef, namespace: string, migrations: Migration[], options?: RegisterMigrationsOptions): void;
143
+ getNamespaceLocation(namespace: string, runtime?: RuntimeRef): NamespaceDatabaseLocation | undefined;
144
+ replaceMigrations(runtime: RuntimeRef, namespace: string, migrations: Migration[], options: ReplaceMigrationsOptions): boolean;
145
+ getDatabase(runtime: RuntimeRef, namespace: string, dbPath: string, consumer?: string): Promise<LocalDatabase>;
146
+ getRawDatabase(runtime: RuntimeRef, dbPath: string, consumer?: string): Promise<SqliteConnection>;
147
+ releaseDatabase(runtime: RuntimeRef, namespace: string, dbPath: string): Promise<void>;
148
+ /** Archive and rebuild only when the caller exclusively owns the physical database. */
149
+ resetDatabase(runtime: RuntimeRef, namespace: string, dbPath: string, consumer?: string): Promise<LocalDatabase>;
150
+ /** Pool statistics for `runtime`'s pool; a missing runtime is refused `INVALID_INPUT localdb-runtime-required`. */
151
+ getPoolStats(runtime?: RuntimeRef): ConnectionStats;
152
+ getMigrationStatus(runtime?: RuntimeRef): NamespaceMigrationStatus[];
153
+ listNamespaces(runtime?: RuntimeRef): string[];
154
+ closeAll(runtime: RuntimeRef): Promise<void>;
81
155
  }
82
156
  //# sourceMappingURL=api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/schemas/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;AAEpF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC9B,GAAG,CAAC,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,CAAC;IACtC,GAAG,CAAC,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAChC,GAAG,CAAC,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC;IACzD,GAAG,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,CAAC;IACvC,GAAG,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACvC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC;CACtE;AAED,MA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G,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export * from "./migrations.js";
2
2
  //# sourceMappingURL=api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/schemas/api.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/schemas/api.ts"],"names":[],"mappings":"AASA,cAAc,iBAAiB,CAAC"}