@minnowdb/core 0.2.1 → 0.4.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.
Files changed (270) hide show
  1. package/README.md +23 -32
  2. package/dist/block-format/block.d.ts +32 -13
  3. package/dist/block-format/block.js +179 -55
  4. package/dist/block-format/checksum.d.ts +2 -1
  5. package/dist/block-format/checksum.js +5 -2
  6. package/dist/block-format/codecs.d.ts +7 -2
  7. package/dist/block-format/codecs.js +53 -12
  8. package/dist/block-format/column.d.ts +3 -2
  9. package/dist/block-format/column.js +96 -30
  10. package/dist/block-format/index.d.ts +2 -2
  11. package/dist/block-format/index.js +2 -2
  12. package/dist/block-format/physical.d.ts +8 -2
  13. package/dist/block-format/physical.js +14 -6
  14. package/dist/block-format/types.d.ts +7 -3
  15. package/dist/block-format/types.js +0 -1
  16. package/dist/block-format/unicode.d.ts +11 -0
  17. package/dist/block-format/unicode.js +46 -0
  18. package/dist/date-value.d.ts +15 -0
  19. package/dist/date-value.js +64 -0
  20. package/dist/engine/artifact-cache.d.ts +2 -1
  21. package/dist/engine/artifact-cache.js +5 -1
  22. package/dist/engine/batch.d.ts +11 -3
  23. package/dist/engine/batch.js +17 -7
  24. package/dist/engine/buffered-writer.d.ts +2 -1
  25. package/dist/engine/buffered-writer.js +34 -9
  26. package/dist/engine/cache-limits.d.ts +25 -0
  27. package/dist/engine/cache-limits.js +25 -0
  28. package/dist/engine/catalog.d.ts +24 -5
  29. package/dist/engine/catalog.js +34 -7
  30. package/dist/engine/client.d.ts +29 -7
  31. package/dist/engine/client.js +216 -40
  32. package/dist/engine/database.d.ts +224 -39
  33. package/dist/engine/database.js +7475 -1539
  34. package/dist/engine/defaults.d.ts +4 -8
  35. package/dist/engine/defaults.js +46 -22
  36. package/dist/engine/errors.d.ts +19 -1
  37. package/dist/engine/errors.js +32 -2
  38. package/dist/engine/fts.d.ts +0 -6
  39. package/dist/engine/fts.js +41 -14
  40. package/dist/engine/group-index.d.ts +0 -1
  41. package/dist/engine/group-index.js +6 -11
  42. package/dist/engine/index.d.ts +16 -10
  43. package/dist/engine/index.js +12 -9
  44. package/dist/engine/join-index.d.ts +0 -1
  45. package/dist/engine/join-index.js +2 -2
  46. package/dist/engine/keyed-live.d.ts +57 -0
  47. package/dist/engine/keyed-live.js +226 -0
  48. package/dist/engine/live-api.d.ts +4 -0
  49. package/dist/engine/live-api.js +4 -0
  50. package/dist/engine/live.d.ts +43 -26
  51. package/dist/engine/live.js +504 -126
  52. package/dist/engine/memory.d.ts +2 -1
  53. package/dist/engine/memory.js +3 -2
  54. package/dist/engine/optimizer.d.ts +0 -1
  55. package/dist/engine/optimizer.js +262 -27
  56. package/dist/engine/query-api.d.ts +3 -0
  57. package/dist/engine/query-api.js +3 -0
  58. package/dist/engine/query-cache.d.ts +1 -2
  59. package/dist/engine/query-cache.js +7 -5
  60. package/dist/engine/query.d.ts +134 -29
  61. package/dist/engine/query.js +1668 -372
  62. package/dist/engine/result-wire.d.ts +0 -1
  63. package/dist/engine/result-wire.js +2 -2
  64. package/dist/engine/schema-wire.d.ts +6 -3
  65. package/dist/engine/schema-wire.js +40 -34
  66. package/dist/engine/schema.d.ts +156 -80
  67. package/dist/engine/schema.js +570 -108
  68. package/dist/engine/sort-keys.d.ts +4 -4
  69. package/dist/engine/sort-keys.js +44 -29
  70. package/dist/engine/sql-domains.d.ts +31 -0
  71. package/dist/engine/sql-domains.js +585 -0
  72. package/dist/engine/sql-driver.d.ts +19 -0
  73. package/dist/engine/sql-driver.js +1 -0
  74. package/dist/engine/sql-json.d.ts +7 -9
  75. package/dist/engine/sql-json.js +75 -15
  76. package/dist/engine/sql-semantics.d.ts +8 -3
  77. package/dist/engine/sql-semantics.js +458 -30
  78. package/dist/engine/typed-live.d.ts +67 -0
  79. package/dist/engine/typed-live.js +349 -0
  80. package/dist/engine/vector.d.ts +12 -2
  81. package/dist/engine/vector.js +635 -119
  82. package/dist/engine/worker-host.d.ts +9 -2
  83. package/dist/engine/worker-host.js +620 -152
  84. package/dist/engine/worker.d.ts +0 -1
  85. package/dist/engine/worker.js +3 -3
  86. package/dist/engine/write-block-planner.d.ts +18 -0
  87. package/dist/engine/write-block-planner.js +112 -0
  88. package/dist/index.d.ts +0 -1
  89. package/dist/index.js +0 -1
  90. package/dist/plan/index.d.ts +3 -4
  91. package/dist/plan/index.js +3 -4
  92. package/dist/storage/index.d.ts +1 -1
  93. package/dist/storage/index.js +1 -1
  94. package/dist/storage/indexeddb.d.ts +99 -51
  95. package/dist/storage/indexeddb.js +13448 -2660
  96. package/dist/storage/memory.d.ts +64 -57
  97. package/dist/storage/memory.js +1042 -128
  98. package/dist/storage/opfs/files.d.ts +18 -7
  99. package/dist/storage/opfs/files.js +115 -28
  100. package/dist/storage/opfs/index.d.ts +1 -1
  101. package/dist/storage/opfs/index.js +1 -1
  102. package/dist/storage/opfs/leader.d.ts +409 -75
  103. package/dist/storage/opfs/leader.js +4621 -650
  104. package/dist/storage/opfs/rpc.d.ts +15 -3
  105. package/dist/storage/opfs/rpc.js +224 -2
  106. package/dist/storage/opfs/snapshot-ledger.d.ts +40 -0
  107. package/dist/storage/opfs/snapshot-ledger.js +281 -0
  108. package/dist/storage/opfs/store.d.ts +33 -99
  109. package/dist/storage/opfs/store.js +453 -364
  110. package/dist/storage/persistence.d.ts +37 -0
  111. package/dist/storage/persistence.js +78 -0
  112. package/dist/storage/snapshot-stream.d.ts +24 -0
  113. package/dist/storage/snapshot-stream.js +897 -0
  114. package/dist/storage/snapshot.d.ts +9 -85
  115. package/dist/storage/snapshot.js +33 -265
  116. package/dist/storage/toolkit/extents.d.ts +41 -7
  117. package/dist/storage/toolkit/extents.js +402 -39
  118. package/dist/storage/toolkit/index.d.ts +4 -5
  119. package/dist/storage/toolkit/index.js +28 -4
  120. package/dist/storage/toolkit/record-core.d.ts +182 -55
  121. package/dist/storage/toolkit/record-core.js +6158 -1331
  122. package/dist/storage/toolkit/sync-file.d.ts +10 -1
  123. package/dist/storage/toolkit/sync-file.js +50 -2
  124. package/dist/storage/toolkit/wal.d.ts +23 -5
  125. package/dist/storage/toolkit/wal.js +89 -27
  126. package/dist/storage/toolkit/wire.d.ts +15 -2
  127. package/dist/storage/toolkit/wire.js +199 -10
  128. package/dist/storage/types.d.ts +1439 -204
  129. package/dist/storage/types.js +1745 -141
  130. package/dist/testing/block-store-conformance.d.ts +0 -1
  131. package/dist/testing/block-store-conformance.js +1009 -119
  132. package/dist/testing/index.d.ts +46 -26
  133. package/dist/testing/index.js +112 -57
  134. package/dist/testing/opfs-shim.d.ts +13 -3
  135. package/dist/testing/opfs-shim.js +40 -6
  136. package/dist/testing/simulator.d.ts +97 -0
  137. package/dist/testing/simulator.js +591 -0
  138. package/dist/testing/sqllogictest.d.ts +89 -0
  139. package/dist/testing/sqllogictest.js +434 -0
  140. package/dist/transactions/index.d.ts +92 -16
  141. package/dist/transactions/index.js +1074 -236
  142. package/dist/worker-protocol/index.d.ts +3 -2
  143. package/dist/worker-protocol/index.js +2 -5
  144. package/package.json +53 -3
  145. package/postgres-feature-profile.json +223 -0
  146. package/sql-feature-matrix.json +172 -252
  147. package/dist/block-format/block.d.ts.map +0 -1
  148. package/dist/block-format/block.js.map +0 -1
  149. package/dist/block-format/checksum.d.ts.map +0 -1
  150. package/dist/block-format/checksum.js.map +0 -1
  151. package/dist/block-format/codecs.d.ts.map +0 -1
  152. package/dist/block-format/codecs.js.map +0 -1
  153. package/dist/block-format/column.d.ts.map +0 -1
  154. package/dist/block-format/column.js.map +0 -1
  155. package/dist/block-format/index.d.ts.map +0 -1
  156. package/dist/block-format/index.js.map +0 -1
  157. package/dist/block-format/physical.d.ts.map +0 -1
  158. package/dist/block-format/physical.js.map +0 -1
  159. package/dist/block-format/types.d.ts.map +0 -1
  160. package/dist/block-format/types.js.map +0 -1
  161. package/dist/engine/artifact-cache.d.ts.map +0 -1
  162. package/dist/engine/artifact-cache.js.map +0 -1
  163. package/dist/engine/batch.d.ts.map +0 -1
  164. package/dist/engine/batch.js.map +0 -1
  165. package/dist/engine/buffered-writer.d.ts.map +0 -1
  166. package/dist/engine/buffered-writer.js.map +0 -1
  167. package/dist/engine/catalog.d.ts.map +0 -1
  168. package/dist/engine/catalog.js.map +0 -1
  169. package/dist/engine/client.d.ts.map +0 -1
  170. package/dist/engine/client.js.map +0 -1
  171. package/dist/engine/coordinator.d.ts +0 -17
  172. package/dist/engine/coordinator.d.ts.map +0 -1
  173. package/dist/engine/coordinator.js +0 -60
  174. package/dist/engine/coordinator.js.map +0 -1
  175. package/dist/engine/database.d.ts.map +0 -1
  176. package/dist/engine/database.js.map +0 -1
  177. package/dist/engine/defaults.d.ts.map +0 -1
  178. package/dist/engine/defaults.js.map +0 -1
  179. package/dist/engine/errors.d.ts.map +0 -1
  180. package/dist/engine/errors.js.map +0 -1
  181. package/dist/engine/fts.d.ts.map +0 -1
  182. package/dist/engine/fts.js.map +0 -1
  183. package/dist/engine/group-index.d.ts.map +0 -1
  184. package/dist/engine/group-index.js.map +0 -1
  185. package/dist/engine/index.d.ts.map +0 -1
  186. package/dist/engine/index.js.map +0 -1
  187. package/dist/engine/join-index.d.ts.map +0 -1
  188. package/dist/engine/join-index.js.map +0 -1
  189. package/dist/engine/live.d.ts.map +0 -1
  190. package/dist/engine/live.js.map +0 -1
  191. package/dist/engine/memory.d.ts.map +0 -1
  192. package/dist/engine/memory.js.map +0 -1
  193. package/dist/engine/optimizer.d.ts.map +0 -1
  194. package/dist/engine/optimizer.js.map +0 -1
  195. package/dist/engine/query-cache.d.ts.map +0 -1
  196. package/dist/engine/query-cache.js.map +0 -1
  197. package/dist/engine/query.d.ts.map +0 -1
  198. package/dist/engine/query.js.map +0 -1
  199. package/dist/engine/result-wire.d.ts.map +0 -1
  200. package/dist/engine/result-wire.js.map +0 -1
  201. package/dist/engine/schema-wire.d.ts.map +0 -1
  202. package/dist/engine/schema-wire.js.map +0 -1
  203. package/dist/engine/schema.d.ts.map +0 -1
  204. package/dist/engine/schema.js.map +0 -1
  205. package/dist/engine/sort-keys.d.ts.map +0 -1
  206. package/dist/engine/sort-keys.js.map +0 -1
  207. package/dist/engine/sql-json.d.ts.map +0 -1
  208. package/dist/engine/sql-json.js.map +0 -1
  209. package/dist/engine/sql-semantics.d.ts.map +0 -1
  210. package/dist/engine/sql-semantics.js.map +0 -1
  211. package/dist/engine/vector.d.ts.map +0 -1
  212. package/dist/engine/vector.js.map +0 -1
  213. package/dist/engine/worker-host.d.ts.map +0 -1
  214. package/dist/engine/worker-host.js.map +0 -1
  215. package/dist/engine/worker.d.ts.map +0 -1
  216. package/dist/engine/worker.js.map +0 -1
  217. package/dist/index.d.ts.map +0 -1
  218. package/dist/index.js.map +0 -1
  219. package/dist/plan/index.d.ts.map +0 -1
  220. package/dist/plan/index.js.map +0 -1
  221. package/dist/storage/fixture-shape.d.ts +0 -42
  222. package/dist/storage/fixture-shape.d.ts.map +0 -1
  223. package/dist/storage/fixture-shape.js +0 -146
  224. package/dist/storage/fixture-shape.js.map +0 -1
  225. package/dist/storage/index.d.ts.map +0 -1
  226. package/dist/storage/index.js.map +0 -1
  227. package/dist/storage/indexeddb.d.ts.map +0 -1
  228. package/dist/storage/indexeddb.js.map +0 -1
  229. package/dist/storage/memory.d.ts.map +0 -1
  230. package/dist/storage/memory.js.map +0 -1
  231. package/dist/storage/opfs/files.d.ts.map +0 -1
  232. package/dist/storage/opfs/files.js.map +0 -1
  233. package/dist/storage/opfs/index.d.ts.map +0 -1
  234. package/dist/storage/opfs/index.js.map +0 -1
  235. package/dist/storage/opfs/leader.d.ts.map +0 -1
  236. package/dist/storage/opfs/leader.js.map +0 -1
  237. package/dist/storage/opfs/rpc.d.ts.map +0 -1
  238. package/dist/storage/opfs/rpc.js.map +0 -1
  239. package/dist/storage/opfs/store.d.ts.map +0 -1
  240. package/dist/storage/opfs/store.js.map +0 -1
  241. package/dist/storage/snapshot.d.ts.map +0 -1
  242. package/dist/storage/snapshot.js.map +0 -1
  243. package/dist/storage/toolkit/extents.d.ts.map +0 -1
  244. package/dist/storage/toolkit/extents.js.map +0 -1
  245. package/dist/storage/toolkit/index.d.ts.map +0 -1
  246. package/dist/storage/toolkit/index.js.map +0 -1
  247. package/dist/storage/toolkit/record-core.d.ts.map +0 -1
  248. package/dist/storage/toolkit/record-core.js.map +0 -1
  249. package/dist/storage/toolkit/sync-file.d.ts.map +0 -1
  250. package/dist/storage/toolkit/sync-file.js.map +0 -1
  251. package/dist/storage/toolkit/wal.d.ts.map +0 -1
  252. package/dist/storage/toolkit/wal.js.map +0 -1
  253. package/dist/storage/toolkit/wire.d.ts.map +0 -1
  254. package/dist/storage/toolkit/wire.js.map +0 -1
  255. package/dist/storage/types.d.ts.map +0 -1
  256. package/dist/storage/types.js.map +0 -1
  257. package/dist/testing/block-store-conformance.d.ts.map +0 -1
  258. package/dist/testing/block-store-conformance.js.map +0 -1
  259. package/dist/testing/index.d.ts.map +0 -1
  260. package/dist/testing/index.js.map +0 -1
  261. package/dist/testing/opfs-shim.d.ts.map +0 -1
  262. package/dist/testing/opfs-shim.js.map +0 -1
  263. package/dist/testing/seeds.d.ts +0 -11
  264. package/dist/testing/seeds.d.ts.map +0 -1
  265. package/dist/testing/seeds.js +0 -50
  266. package/dist/testing/seeds.js.map +0 -1
  267. package/dist/transactions/index.d.ts.map +0 -1
  268. package/dist/transactions/index.js.map +0 -1
  269. package/dist/worker-protocol/index.d.ts.map +0 -1
  270. package/dist/worker-protocol/index.js.map +0 -1
@@ -1,18 +1,35 @@
1
1
  import { type BatchRow, type BatchValue, type InsertBatchInput } from "./batch.js";
2
2
  import { BufferedTableWriter, type BufferedWriterOptions } from "./buffered-writer.js";
3
- export { attachLifecycleFlush, BufferedTableWriter, type BufferedFlushResult, type BufferedWriterOptions, type LifecycleDocumentTarget, type LifecycleFlushOptions, type LifecycleFlushRequester, type LifecyclePageTarget, } from "./buffered-writer.js";
4
- import { CompactionJobCancelledError, CompactionMemoryBudgetError, CompactionWriteAmplificationError, MissingKeyError, SqlCompileError, UniqueConstraintError } from "./errors.js";
3
+ export { attachLifecycleFlush, BufferedTableWriter, MAX_BUFFERED_WRITER_PENDING_ADDS, type BufferedFlushResult, type BufferedWriterOptions, type LifecycleDocumentTarget, type LifecycleFlushOptions, type LifecycleFlushRequester, type LifecyclePageTarget, } from "./buffered-writer.js";
4
+ import { CompactionJobCancelledError, CompactionMemoryBudgetError, CompactionWriteAmplificationError, MaintenanceBacklogError, MissingKeyError, SqlCompileError, UniqueConstraintError, VisibleSegmentCursorStaleError } from "./errors.js";
5
5
  import { type Compression } from "../block-format/index.js";
6
- import { type BlockStore, type ColumnDefault, type CompactionJobRecord, type CompactionJobState, type GarbageCollectionJobRecord, type GarbageCollectionJobState, type SimpleDataType, type SnapshotExportProgress, type SnapshotLoadProgress } from "../storage/index.js";
7
- import { type CompiledQuery, type CompiledStatement, type ForeignKeyDefinition, type QueryResult, type QueryRow, type QueryValue } from "./query.js";
6
+ import { type BlockStore, type ColumnDefault, CompactionBacklogError, type CompactionJobRecord, type CompactionJobState, type GarbageCollectionJobRecord, type GarbageCollectionJobState, type SimpleDataType, type SqlDomain, type StorageIntegrityMode, type StorageIntegrityReport, type StorageStats, type InterruptedSnapshotImport, type InterruptedSnapshotImportAbortResult, TableInUseError } from "../storage/types.js";
7
+ import type { SnapshotExportProgress, SnapshotLoadProgress } from "../storage/snapshot.js";
8
+ import { type CompiledQuery, type CompiledStatement, type ForeignKeyDefinition, type QueryResult, type QueryRow, type QueryValue, type UniqueConstraintDefinition } from "./query.js";
8
9
  import { LiveQuerySet, type LiveQuerySetOptions } from "./live.js";
9
10
  import { type Catalog } from "./catalog.js";
10
11
  import { type AnyTable, type MigrationStep, type SchemaDefinition } from "./schema.js";
12
+ /** Nested SQL savepoints and their total cloned transaction state are both hard bounded. */
13
+ export declare const MAX_TRANSACTION_SAVEPOINTS = 64;
14
+ export declare const MAX_TRANSACTION_SAVEPOINT_BYTES: number;
15
+ /** Outstanding simple writes retained by one database instance before callers must await. */
16
+ export declare const MAX_DATABASE_PENDING_WRITES = 64;
17
+ /** Concurrent direct reads retained by one database instance. Reads still execute in parallel. */
18
+ export declare const MAX_DATABASE_ACTIVE_READS = 256;
19
+ export declare class DatabaseReadBacklogError extends Error {
20
+ readonly limit: number;
21
+ readonly name = "DatabaseReadBacklogError";
22
+ constructor(limit?: number);
23
+ }
11
24
  export interface ColumnDefinition {
12
25
  name: string;
13
26
  type: SimpleDataType;
27
+ /** SQL integer-domain guard; ordinary API number columns remain finite Float64 values. */
28
+ integer?: true;
29
+ /** PostgreSQL logical domain over the primitive storage type. */
30
+ sqlDomain?: SqlDomain;
14
31
  nullable?: boolean;
15
- /** Fills null-or-absent slots at insert time; never applied at read time. */
32
+ /** Fills omitted or SQL DEFAULT slots at insert time; never applied at read time. */
16
33
  defaultValue?: ColumnDefault;
17
34
  /** String columns only: the closed set of values writes must draw from. */
18
35
  enumValues?: readonly string[];
@@ -33,6 +50,14 @@ export interface MigrateOptions {
33
50
  */
34
51
  readonly schemaOwnsDatabase?: boolean;
35
52
  }
53
+ export interface MigrateResult {
54
+ createdTables: string[];
55
+ alteredTables: string[];
56
+ droppedTables: string[];
57
+ replacedViews: string[];
58
+ droppedViews: string[];
59
+ steps: MigrationStep[];
60
+ }
36
61
  export interface CreateTableInput {
37
62
  name: string;
38
63
  columns: readonly ColumnDefinition[];
@@ -43,9 +68,13 @@ export interface CreateTableInput {
43
68
  }>;
44
69
  /** Marks the table as created from a schema, which lets a later migration drop it. */
45
70
  managed?: boolean;
46
- /** Single-column references to another table's unique key (E141-04). */
71
+ /** References to a parent PRIMARY/unique row-addressing key. */
47
72
  foreignKeys?: readonly ForeignKeyDefinition[];
48
73
  uniqueKey?: string;
74
+ /** PostgreSQL composite PRIMARY KEY, backed by a hidden canonical tuple locator. */
75
+ compositePrimaryKey?: readonly string[];
76
+ /** Independently enforced PostgreSQL UNIQUE constraints. */
77
+ uniqueConstraints?: readonly UniqueConstraintDefinition[];
49
78
  }
50
79
  export type { BatchRow, BatchValue, ColumnarBatch, InsertBatchInput } from "./batch.js";
51
80
  export interface InsertBatchResult {
@@ -67,7 +96,9 @@ export interface UpsertBatchResult extends InsertBatchResult {
67
96
  updatedRowCount: number;
68
97
  }
69
98
  export interface UpdateBatchInput {
99
+ /** Stable ordinary arrays; do not mutate or expose changing accessors until the write settles. */
70
100
  keys: readonly BatchValue[];
101
+ /** Stable ordinary arrays; do not mutate or expose changing accessors until the write settles. */
71
102
  changes: Readonly<Record<string, readonly BatchValue[]>>;
72
103
  }
73
104
  export interface UpdateBatchResult {
@@ -145,9 +176,7 @@ export interface WriteSession {
145
176
  * Read-your-writes: the query observes the pre-scope snapshot PLUS everything this scope
146
177
  * has staged so far, ordered after all committed data — without publishing anything.
147
178
  */
148
- query(sql: string, options?: {
149
- params?: QueryOptions["params"];
150
- }): Promise<QueryResult>;
179
+ query(sql: string, options?: QueryOptions): Promise<QueryResult>;
151
180
  /** Runs a SELECT, INSERT, UPDATE, or DELETE inside this write scope. */
152
181
  execute(sql: string, params?: readonly QueryValue[]): Promise<ExecuteResult>;
153
182
  insertBatch(tableName: string, input: InsertBatchInput): Promise<StagedWriteResult>;
@@ -165,6 +194,27 @@ export interface QueryExecutionStats {
165
194
  */
166
195
  readonly peakMemoryBytes: number;
167
196
  }
197
+ export interface MaintenanceStatus {
198
+ readonly autoCollectionEnabled: boolean;
199
+ readonly collectionRunning: boolean;
200
+ readonly collectionRequested: boolean;
201
+ /** Commits since collection last proved there was no immediately reclaimable work. */
202
+ readonly pendingCommitDebt: number;
203
+ readonly consecutiveFailures: number;
204
+ /** In-memory posting-tail retry markers; bounded and cleared with their catalog owner. */
205
+ readonly postingDeltaTailMarkers: number;
206
+ /** SQL text caches retain only inputs below the fixed cacheability ceiling. */
207
+ readonly retainedPlanEntries: number;
208
+ readonly retainedStatementEntries: number;
209
+ readonly lastStartedAt: Date | null;
210
+ readonly lastCompletedAt: Date | null;
211
+ readonly nextRetryAt: Date | null;
212
+ readonly lastError: {
213
+ readonly name: string;
214
+ readonly message: string;
215
+ readonly at: Date;
216
+ } | null;
217
+ }
168
218
  export interface QueryOptions {
169
219
  /**
170
220
  * Called once with what this execution cost, before the result is returned. Additive and
@@ -201,7 +251,14 @@ export interface QueryOptions {
201
251
  /** Maximum rows encoded in each merged spill page. */
202
252
  readonly spillPageRows?: number;
203
253
  }
254
+ export interface QueryCursorOptions extends QueryOptions {
255
+ /** Maximum rows in one yielded result batch. Defaults to the vector scan batch size. */
256
+ readonly batchRows?: number;
257
+ /** Cancels the scan and releases its snapshot lease. */
258
+ readonly signal?: AbortSignal;
259
+ }
204
260
  export interface DeleteBatchInput {
261
+ /** Stable ordinary array; do not mutate or expose changing accessors until the write settles. */
205
262
  keys: readonly BatchValue[];
206
263
  }
207
264
  export interface DeleteBatchResult {
@@ -215,8 +272,6 @@ export interface DeleteBatchResult {
215
272
  metrics: WriteMetrics;
216
273
  }
217
274
  export interface CompactTableOptions {
218
- /** @deprecated Use minimumLevel0Segments. */
219
- minimumSegments?: number;
220
275
  /** Minimum L0 segments promoted; one also permits a direct L0 -> L2 promotion. */
221
276
  minimumLevel0Segments?: number;
222
277
  /** Target maximum L0 segments promoted by one job. Equal-order groups remain indivisible. */
@@ -327,6 +382,7 @@ export interface CollectGarbageStepOptions {
327
382
  /** See `CollectGarbageOptions.retainRecentVersions`; applies when this step plans a job. */
328
383
  retainRecentVersions?: number;
329
384
  }
385
+ export declare const MAX_GARBAGE_COLLECTION_RETAIN_RECENT_VERSIONS = 1024;
330
386
  export interface GarbageCollectionResult {
331
387
  jobId: string;
332
388
  prunedManifestCount: number;
@@ -359,7 +415,7 @@ export interface TableDefinition {
359
415
  uniqueKey?: string;
360
416
  }
361
417
  export type DatabaseRow = Record<string, Exclude<BatchValue, null> | null>;
362
- export { CompactionJobCancelledError, CompactionMemoryBudgetError, CompactionWriteAmplificationError, MissingKeyError, SqlCompileError, UniqueConstraintError, };
418
+ export { CompactionBacklogError, CompactionJobCancelledError, CompactionMemoryBudgetError, CompactionWriteAmplificationError, MaintenanceBacklogError, MissingKeyError, SqlCompileError, TableInUseError, UniqueConstraintError, VisibleSegmentCursorStaleError, };
363
419
  export interface MinnowDatabaseOptions {
364
420
  /**
365
421
  * Block codec for newly written blocks; defaults to "gzip", which is also what compaction
@@ -373,12 +429,20 @@ export interface MinnowDatabaseOptions {
373
429
  * storage quota; the browser usually makes the opposite trade worth it.
374
430
  */
375
431
  compression?: Compression;
432
+ /**
433
+ * Target maximum uncompressed bytes in a newly written column block. `rowsPerBlock` remains a
434
+ * second ceiling. A single value may exceed this target when it still fits the format's 64 MiB
435
+ * hard limit. Defaults to 2 MiB, matching compaction output.
436
+ */
437
+ targetBlockBytes?: number;
376
438
  rowsPerBlock?: number;
377
439
  maxCommitRetries?: number;
378
440
  now?: () => Date;
379
441
  createId?: () => string;
380
442
  /** Durable spill-owner lease lifetime; renewed while a spilling query runs. */
381
443
  spillOwnerLeaseMs?: number;
444
+ /** Durable active-writer deadline; renewed every third while the writer is live. */
445
+ transactionOwnerLeaseMs?: number;
382
446
  /**
383
447
  * How long a statement-level transaction (`BEGIN` … `COMMIT`) may sit untouched before it
384
448
  * rolls itself back; 30 seconds by default. A scope nobody ever closes would otherwise hold
@@ -394,6 +458,12 @@ export interface MinnowDatabaseOptions {
394
458
  * LRU. 0 disables the pool. Defaults to 64 MiB.
395
459
  */
396
460
  bufferPoolBytes?: number;
461
+ /**
462
+ * Default modeled execution-memory budget for every query, including mutation selection,
463
+ * triggers, subqueries, and read-your-writes scopes. Eligible sorts and groups spill
464
+ * automatically. Defaults to 64 MiB; `null` explicitly restores unbounded mode.
465
+ */
466
+ executionMemoryBudgetBytes?: number | null;
397
467
  /**
398
468
  * Visible-row threshold at which a full-text MATCH on an unindexed append-only column
399
469
  * schedules a background index build (fire-and-forget; correctness never waits on it).
@@ -412,10 +482,15 @@ export interface MinnowDatabaseOptions {
412
482
  * Background collection: a garbage-collection pass after every background fold, and one
413
483
  * every 64 commits, each keeping the 64 most recent versions readable. Without it the
414
484
  * blocks a fold supersedes and the manifest every commit writes stay on disk until the
415
- * caller runs `collectGarbage`. Defaults to `autoCompact`; false leaves collection to the
416
- * caller.
485
+ * caller runs `collectGarbage`. Defaults to true independently of compaction; false leaves
486
+ * collection to the caller.
417
487
  */
418
488
  autoCollect?: boolean;
489
+ /**
490
+ * Successful commits tolerated while automatic collection is failing before a foreground
491
+ * write assists and, if maintenance still fails, is refused. Defaults to 4096.
492
+ */
493
+ autoCollectDebtLimitCommits?: number;
419
494
  /**
420
495
  * Defaults for every compaction this database plans, background folds included. A call's
421
496
  * own `CompactTableOptions` override them.
@@ -440,10 +515,33 @@ export type ExecuteResult = {
440
515
  } | {
441
516
  kind: "create-table";
442
517
  table: string;
518
+ } | {
519
+ kind: "create-type";
520
+ name: string;
521
+ } | {
522
+ kind: "create-sequence";
523
+ name: string;
524
+ } | {
525
+ kind: "create-index";
526
+ index: string;
527
+ table: string;
528
+ /** First key column, retained for compatibility with the original single-column result. */
529
+ column: string;
530
+ columns: string[];
531
+ unique: boolean;
532
+ } | {
533
+ kind: "drop-index";
534
+ index: string;
535
+ dropped: boolean;
443
536
  } | {
444
537
  kind: "add-column";
445
538
  table: string;
446
539
  column: string;
540
+ } | {
541
+ kind: "drop-column";
542
+ table: string;
543
+ column: string;
544
+ dropped: boolean;
447
545
  } | {
448
546
  kind: "drop-table";
449
547
  table: string;
@@ -455,7 +553,8 @@ export type ExecuteResult = {
455
553
  version?: number;
456
554
  } | {
457
555
  kind: "transaction";
458
- action: "begin" | "commit" | "rollback";
556
+ action: "begin" | "commit" | "rollback" | "savepoint" | "rollback-to" | "release";
557
+ name?: string;
459
558
  version?: number;
460
559
  } | {
461
560
  kind: "create-view";
@@ -517,18 +616,67 @@ export interface VisibleSegment {
517
616
  rowCount: number;
518
617
  columnBlockIds: Readonly<Record<string, readonly string[]>>;
519
618
  }
619
+ export interface VisibleSegmentPageRecord extends VisibleSegment {
620
+ /** Stable logical scan order, exposed so bounded-page consumers can order a completed fold. */
621
+ readonly logicalOrder: number;
622
+ /** The commit that made the segment eligible at the captured manifest version. */
623
+ readonly committedVersion: number;
624
+ /** Stable order among segments from the same commit. */
625
+ readonly commitOrdinal: number;
626
+ }
627
+ /** One public segment-inspection page; kept small for direct and worker callers alike. */
628
+ export declare const MAX_VISIBLE_SEGMENT_PAGE_ITEMS = 64;
629
+ /**
630
+ * Opaque continuation state for a visible-segment scan. The manifest version and table identity
631
+ * are captured on the first page, so later commits cannot move an in-progress scan onto different
632
+ * data. Dropping or replacing the table makes this cursor stale and fails the next page.
633
+ */
634
+ export interface VisibleSegmentPageCursor {
635
+ readonly tableName: string;
636
+ readonly tableId: string;
637
+ readonly version: number | null;
638
+ readonly afterId: string;
639
+ }
640
+ export interface VisibleSegmentPageOptions {
641
+ /** First page only. Omit for the current committed version; null names the empty version. */
642
+ readonly version?: number | null;
643
+ /** Use the exact cursor returned by the previous page; do not combine with `version`. */
644
+ readonly cursor?: VisibleSegmentPageCursor;
645
+ /** Defaults to and may not exceed MAX_VISIBLE_SEGMENT_PAGE_ITEMS. */
646
+ readonly limit?: number;
647
+ }
648
+ export interface VisibleSegmentPage {
649
+ /** Visible records from this bounded physical segment-ID window, in lexical ID order. */
650
+ readonly records: VisibleSegmentPageRecord[];
651
+ /** The exact manifest version captured for every page in this scan. */
652
+ readonly version: number | null;
653
+ /** May be non-null when `records` is empty because historical records were filtered out. */
654
+ readonly nextCursor: VisibleSegmentPageCursor | null;
655
+ }
520
656
  export interface SnapshotExportOptions {
521
657
  /** Called as the export moves through its phases; see SnapshotExportProgress. */
522
658
  onProgress?: (progress: SnapshotExportProgress) => void;
659
+ /** Cancels transfer and releases the durable export pin. */
660
+ signal?: AbortSignal;
523
661
  }
524
662
  export interface SnapshotImportOptions {
525
663
  /** Called as blocks land, for a progress bar over a multi-megabyte file. */
526
664
  onProgress?: (progress: SnapshotLoadProgress) => void;
665
+ /** Cancels transfer and atomically removes this caller's staged import. */
666
+ signal?: AbortSignal;
527
667
  }
528
668
  export declare class MinnowDatabase {
529
669
  #private;
530
670
  private readonly store;
531
671
  constructor(store: BlockStore, options?: MinnowDatabaseOptions);
672
+ /**
673
+ * Stops timers and background scheduling, rolls back an abandoned statement transaction,
674
+ * closes live-query resources, releases the engine's reader lease, and drops resident caches.
675
+ * The injected block store remains caller-owned and must be closed separately.
676
+ */
677
+ close(): Promise<void>;
678
+ /** Current background-collection health, returned as a defensive snapshot. */
679
+ maintenanceStatus(): MaintenanceStatus;
532
680
  createTable(input: CreateTableInput): Promise<void>;
533
681
  /**
534
682
  * The published catalog: stable column IDs, key identity, constraints, triggers, and view
@@ -551,6 +699,14 @@ export declare class MinnowDatabase {
551
699
  dropView(name: string, options?: {
552
700
  ifExists?: boolean;
553
701
  }): Promise<boolean>;
702
+ /**
703
+ * Drops one non-key column in one storage transaction: catalog metadata and segment references
704
+ * change with the successor manifest that retires the column's exclusively owned live blocks.
705
+ * Payload bytes remain readable to historical leases until ordinary collection reclaims them.
706
+ */
707
+ dropColumn(tableName: string, columnName: string, options?: {
708
+ ifExists?: boolean;
709
+ }): Promise<boolean>;
554
710
  /**
555
711
  * Drops a table: its rows, its catalog record, its full-text index, and its triggers. The
556
712
  * blocks are retired through an ordinary commit rather than deleted, so a reader pinned to an
@@ -586,6 +742,12 @@ export declare class MinnowDatabase {
586
742
  snapshot<T>(action: (session: SnapshotSession) => Promise<T>): Promise<T>;
587
743
  /** Executes a read-only SELECT statement through the public query API. */
588
744
  query(sql: string, options?: QueryOptions): Promise<QueryResult>;
745
+ /**
746
+ * Pull-driven query batches. Cursor-safe scans emit directly from vector batches; blocking
747
+ * plans (sorts, groups, joins, derived sources) use the ordinary correct execution and page
748
+ * its result. In both cases the iterator applies backpressure and owns one snapshot at a time.
749
+ */
750
+ queryCursor(sql: string, options?: QueryCursorOptions): AsyncIterableIterator<QueryResult, undefined>;
589
751
  /**
590
752
  * Reclaims temp spill pages whose owner lease is expired or missing at a cutoff fixed when the
591
753
  * pass starts. Owners with an unexpired lease are retained; each owner is removed atomically
@@ -596,7 +758,8 @@ export declare class MinnowDatabase {
596
758
  * Creates a live-query set over this database. Local commits hint it directly, an optional
597
759
  * channel carries cross-tab hints, and an optional poll interval bounds staleness without any
598
760
  * hint; every hint path converges on the durable manifest version, so missed messages delay a
599
- * refresh but never produce a stale result. Subscriptions retain a result digest, not rows.
761
+ * refresh but never produce a stale result. Equal subscriptions retain one private exact
762
+ * result snapshot plus a digest that rejects most inequality before exact comparison.
600
763
  */
601
764
  liveQueries(options?: LiveQuerySetOptions): LiveQuerySet;
602
765
  /**
@@ -625,14 +788,7 @@ export declare class MinnowDatabase {
625
788
  * steps — and every catalog alteration is one atomic compare-and-swap, so a concurrent
626
789
  * migrator fails explicitly with a conflict instead of interleaving.
627
790
  */
628
- migrate(definition: SchemaDefinition<readonly AnyTable[]>, options?: MigrateOptions): Promise<{
629
- createdTables: string[];
630
- alteredTables: string[];
631
- droppedTables: string[];
632
- replacedViews: string[];
633
- droppedViews: string[];
634
- steps: MigrationStep[];
635
- }>;
791
+ migrate(definition: SchemaDefinition<readonly AnyTable[]>, options?: MigrateOptions): Promise<MigrateResult>;
636
792
  /**
637
793
  * Renders the optimized logical plan for a SELECT statement plus the physical strategy notes
638
794
  * the prepared execution would choose, without executing it.
@@ -654,27 +810,41 @@ export declare class MinnowDatabase {
654
810
  * (the snapshot row with assignments applied — the exact values the mutation wrote).
655
811
  */
656
812
  runStatement(statement: CompiledStatement, options?: RunStatementOptions): Promise<ExecuteResult>;
657
- listVisibleSegments(tableName: string, version?: number): Promise<VisibleSegment[]>;
658
813
  /**
659
- * Copies the current committed version out as a portable snapshot file — the byte array
660
- * `../storage/snapshot.ts` describes, which `importSnapshot()` loads back into any store.
661
- *
662
- * The bytes are the unit here rather than the structured `DatabaseSnapshot` the store returns,
663
- * because that is what a caller does with a snapshot: write it to disk, hand it to a colleague,
664
- * ship it as an asset. Reach for `store.exportSnapshot()` directly when you want the records
665
- * instead. Either way the whole snapshot is materialized in memory, so a database of hundreds
666
- * of megabytes needs the headroom for a copy of itself.
667
- *
668
- * Stores differ in how they hold still while this runs: see the note on exporting safely in the
669
- * snapshots guide.
814
+ * Inspects exactly one bounded physical segment-ID window at a stable manifest version.
815
+ * Historical records that are not visible are filtered rather than replaced from later
816
+ * windows, so callers must follow `nextCursor` even when a page returns no records.
817
+ */
818
+ listVisibleSegmentPage(tableName: string, options?: VisibleSegmentPageOptions): Promise<VisibleSegmentPage>;
819
+ /**
820
+ * Collects the pull-driven framed snapshot stream into one portable byte array. This helper is
821
+ * convenient for small and medium databases, but it necessarily retains the complete file and
822
+ * has the Uint8Array 4-GiB ceiling. Use `exportSnapshotStream()` for larger databases or direct
823
+ * file/network transfer. See the snapshots guide for framing and durability guarantees.
670
824
  */
671
825
  exportSnapshot(options?: SnapshotExportOptions): Promise<Uint8Array>;
826
+ /**
827
+ * Streams one pinned committed snapshot with at most one payload block resident. Stopping the
828
+ * iterator releases its durable backup lease in `finally`.
829
+ */
830
+ exportSnapshotStream(options?: SnapshotExportOptions): AsyncGenerator<Uint8Array, void, void>;
672
831
  /**
673
832
  * Loads a snapshot file into this database's store, which must be empty. Every block is
674
- * authenticated while decoding, so a corrupt file fails here rather than mid-query, and a store
675
- * that already holds a database throws rather than merging two histories.
833
+ * integrity-checked while decoding, so a corrupt file fails here rather than mid-query, and a
834
+ * store that already holds a database throws rather than merging two histories.
676
835
  */
677
836
  importSnapshot(bytes: Uint8Array, options?: SnapshotImportOptions): Promise<void>;
837
+ /** Incrementally validates and stages a snapshot; only the final adapter CAS makes it visible. */
838
+ importSnapshotStream(source: AsyncIterable<Uint8Array>, options?: SnapshotImportOptions): Promise<void>;
839
+ /** Verifies adapter metadata, or metadata plus every live payload, without changing storage. */
840
+ checkIntegrity(options?: {
841
+ mode?: StorageIntegrityMode;
842
+ maxIssues?: number;
843
+ }): Promise<StorageIntegrityReport>;
844
+ /** Explicit, potentially storage-scanning accounting for live, obsolete, temp, and WAL bytes. */
845
+ storageStats(): Promise<StorageStats>;
846
+ inspectInterruptedImport(): Promise<InterruptedSnapshotImport | null>;
847
+ abortInterruptedImport(identity: string): Promise<InterruptedSnapshotImportAbortResult>;
678
848
  compactTable(tableName: string, options?: CompactTableOptions): Promise<CompactTableResult>;
679
849
  /** Plans or advances one restart-safe physical compaction job. */
680
850
  compactTableStep(tableName: string, options?: CompactTableStepOptions): Promise<CompactionJobProgress>;
@@ -698,6 +868,22 @@ export declare class MinnowDatabase {
698
868
  * derived results, memoized results). Use it to size bufferPoolBytes from real workloads.
699
869
  */
700
870
  bufferPoolStats(): BufferPoolStats;
871
+ /**
872
+ * Creates and fully builds a durable secondary index. The catalog's global
873
+ * index-name namespace matches the SQL DDL: a duplicate name is rejected even on another
874
+ * table. The building state makes the operation crash-safe; readers scan until the base and
875
+ * every concurrent commit delta are known to be covered.
876
+ */
877
+ createIndex(indexName: string, tableName: string, requestedColumns: string | ReadonlyArray<{
878
+ name: string;
879
+ direction: "asc" | "desc";
880
+ }>, options?: {
881
+ unique?: boolean;
882
+ }): Promise<void>;
883
+ /** Drops one globally named secondary index. */
884
+ dropIndex(indexName: string, options?: {
885
+ ifExists?: boolean;
886
+ }): Promise<boolean>;
701
887
  /**
702
888
  * Builds (or rebuilds) the persisted full-text pruning index for one column from the current
703
889
  * snapshot. Append-only tables only. The planner consults the index when the column is
@@ -707,4 +893,3 @@ export declare class MinnowDatabase {
707
893
  */
708
894
  buildFtsIndex(tableName: string, columnName: string): Promise<void>;
709
895
  }
710
- //# sourceMappingURL=database.d.ts.map