@minnowdb/core 0.3.0 → 0.4.1

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 (276) hide show
  1. package/README.md +4 -2
  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 +0 -1
  21. package/dist/engine/artifact-cache.js +0 -1
  22. package/dist/engine/batch.d.ts +5 -2
  23. package/dist/engine/batch.js +0 -1
  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 +5 -6
  29. package/dist/engine/catalog.js +5 -5
  30. package/dist/engine/client.d.ts +27 -7
  31. package/dist/engine/client.js +197 -31
  32. package/dist/engine/database.d.ts +161 -38
  33. package/dist/engine/database.js +4326 -1523
  34. package/dist/engine/defaults.d.ts +0 -1
  35. package/dist/engine/defaults.js +2 -4
  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 +39 -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 -11
  43. package/dist/engine/index.js +12 -10
  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 +499 -129
  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 +4 -4
  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 +0 -1
  59. package/dist/engine/query-cache.js +4 -4
  60. package/dist/engine/query.d.ts +4 -7
  61. package/dist/engine/query.js +348 -155
  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 +1 -2
  65. package/dist/engine/schema-wire.js +0 -1
  66. package/dist/engine/schema.d.ts +3 -8
  67. package/dist/engine/schema.js +41 -24
  68. package/dist/engine/sort-keys.d.ts +0 -1
  69. package/dist/engine/sort-keys.js +2 -2
  70. package/dist/engine/sql-domains.d.ts +6 -1
  71. package/dist/engine/sql-domains.js +209 -45
  72. package/dist/engine/sql-driver.d.ts +2 -2
  73. package/dist/engine/sql-driver.js +0 -1
  74. package/dist/engine/sql-json.d.ts +0 -1
  75. package/dist/engine/sql-json.js +53 -7
  76. package/dist/engine/sql-semantics.d.ts +8 -5
  77. package/dist/engine/sql-semantics.js +427 -65
  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 +7 -1
  81. package/dist/engine/vector.js +202 -58
  82. package/dist/engine/worker-host.d.ts +8 -2
  83. package/dist/engine/worker-host.js +616 -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 +0 -1
  91. package/dist/plan/index.js +0 -1
  92. package/dist/storage/index.d.ts +1 -1
  93. package/dist/storage/index.js +1 -1
  94. package/dist/storage/indexeddb.d.ts +74 -65
  95. package/dist/storage/indexeddb.js +12301 -2076
  96. package/dist/storage/memory.d.ts +56 -66
  97. package/dist/storage/memory.js +1004 -139
  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 +403 -91
  103. package/dist/storage/opfs/leader.js +4318 -602
  104. package/dist/storage/opfs/rpc.d.ts +15 -3
  105. package/dist/storage/opfs/rpc.js +223 -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 +26 -121
  109. package/dist/storage/opfs/store.js +436 -388
  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 -99
  115. package/dist/storage/snapshot.js +33 -309
  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 +3 -4
  119. package/dist/storage/toolkit/index.js +27 -3
  120. package/dist/storage/toolkit/record-core.d.ts +174 -61
  121. package/dist/storage/toolkit/record-core.js +5401 -849
  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 +4 -6
  127. package/dist/storage/toolkit/wire.js +80 -25
  128. package/dist/storage/types.d.ts +1271 -218
  129. package/dist/storage/types.js +1471 -138
  130. package/dist/testing/block-store-conformance.d.ts +0 -1
  131. package/dist/testing/block-store-conformance.js +877 -138
  132. package/dist/testing/index.d.ts +42 -31
  133. package/dist/testing/index.js +100 -68
  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 +0 -1
  137. package/dist/testing/simulator.js +43 -12
  138. package/dist/testing/sqllogictest.d.ts +0 -1
  139. package/dist/testing/sqllogictest.js +0 -1
  140. package/dist/transactions/index.d.ts +81 -20
  141. package/dist/transactions/index.js +1050 -268
  142. package/dist/worker-protocol/index.d.ts +3 -2
  143. package/dist/worker-protocol/index.js +2 -5
  144. package/package.json +49 -1
  145. package/dist/block-format/block.d.ts.map +0 -1
  146. package/dist/block-format/block.js.map +0 -1
  147. package/dist/block-format/checksum.d.ts.map +0 -1
  148. package/dist/block-format/checksum.js.map +0 -1
  149. package/dist/block-format/codecs.d.ts.map +0 -1
  150. package/dist/block-format/codecs.js.map +0 -1
  151. package/dist/block-format/column.d.ts.map +0 -1
  152. package/dist/block-format/column.js.map +0 -1
  153. package/dist/block-format/index.d.ts.map +0 -1
  154. package/dist/block-format/index.js.map +0 -1
  155. package/dist/block-format/physical.d.ts.map +0 -1
  156. package/dist/block-format/physical.js.map +0 -1
  157. package/dist/block-format/types.d.ts.map +0 -1
  158. package/dist/block-format/types.js.map +0 -1
  159. package/dist/engine/artifact-cache.d.ts.map +0 -1
  160. package/dist/engine/artifact-cache.js.map +0 -1
  161. package/dist/engine/batch.d.ts.map +0 -1
  162. package/dist/engine/batch.js.map +0 -1
  163. package/dist/engine/buffered-writer.d.ts.map +0 -1
  164. package/dist/engine/buffered-writer.js.map +0 -1
  165. package/dist/engine/catalog.d.ts.map +0 -1
  166. package/dist/engine/catalog.js.map +0 -1
  167. package/dist/engine/client.d.ts.map +0 -1
  168. package/dist/engine/client.js.map +0 -1
  169. package/dist/engine/coordinator.d.ts +0 -17
  170. package/dist/engine/coordinator.d.ts.map +0 -1
  171. package/dist/engine/coordinator.js +0 -60
  172. package/dist/engine/coordinator.js.map +0 -1
  173. package/dist/engine/database.d.ts.map +0 -1
  174. package/dist/engine/database.js.map +0 -1
  175. package/dist/engine/defaults.d.ts.map +0 -1
  176. package/dist/engine/defaults.js.map +0 -1
  177. package/dist/engine/errors.d.ts.map +0 -1
  178. package/dist/engine/errors.js.map +0 -1
  179. package/dist/engine/fts.d.ts.map +0 -1
  180. package/dist/engine/fts.js.map +0 -1
  181. package/dist/engine/group-index.d.ts.map +0 -1
  182. package/dist/engine/group-index.js.map +0 -1
  183. package/dist/engine/index.d.ts.map +0 -1
  184. package/dist/engine/index.js.map +0 -1
  185. package/dist/engine/join-index.d.ts.map +0 -1
  186. package/dist/engine/join-index.js.map +0 -1
  187. package/dist/engine/live.d.ts.map +0 -1
  188. package/dist/engine/live.js.map +0 -1
  189. package/dist/engine/memory.d.ts.map +0 -1
  190. package/dist/engine/memory.js.map +0 -1
  191. package/dist/engine/optimizer.d.ts.map +0 -1
  192. package/dist/engine/optimizer.js.map +0 -1
  193. package/dist/engine/query-cache.d.ts.map +0 -1
  194. package/dist/engine/query-cache.js.map +0 -1
  195. package/dist/engine/query.d.ts.map +0 -1
  196. package/dist/engine/query.js.map +0 -1
  197. package/dist/engine/result-wire.d.ts.map +0 -1
  198. package/dist/engine/result-wire.js.map +0 -1
  199. package/dist/engine/schema-wire.d.ts.map +0 -1
  200. package/dist/engine/schema-wire.js.map +0 -1
  201. package/dist/engine/schema.d.ts.map +0 -1
  202. package/dist/engine/schema.js.map +0 -1
  203. package/dist/engine/sort-keys.d.ts.map +0 -1
  204. package/dist/engine/sort-keys.js.map +0 -1
  205. package/dist/engine/sql-domains.d.ts.map +0 -1
  206. package/dist/engine/sql-domains.js.map +0 -1
  207. package/dist/engine/sql-driver.d.ts.map +0 -1
  208. package/dist/engine/sql-driver.js.map +0 -1
  209. package/dist/engine/sql-json.d.ts.map +0 -1
  210. package/dist/engine/sql-json.js.map +0 -1
  211. package/dist/engine/sql-semantics.d.ts.map +0 -1
  212. package/dist/engine/sql-semantics.js.map +0 -1
  213. package/dist/engine/vector.d.ts.map +0 -1
  214. package/dist/engine/vector.js.map +0 -1
  215. package/dist/engine/worker-host.d.ts.map +0 -1
  216. package/dist/engine/worker-host.js.map +0 -1
  217. package/dist/engine/worker.d.ts.map +0 -1
  218. package/dist/engine/worker.js.map +0 -1
  219. package/dist/index.d.ts.map +0 -1
  220. package/dist/index.js.map +0 -1
  221. package/dist/plan/index.d.ts.map +0 -1
  222. package/dist/plan/index.js.map +0 -1
  223. package/dist/storage/fixture-shape.d.ts +0 -42
  224. package/dist/storage/fixture-shape.d.ts.map +0 -1
  225. package/dist/storage/fixture-shape.js +0 -146
  226. package/dist/storage/fixture-shape.js.map +0 -1
  227. package/dist/storage/index.d.ts.map +0 -1
  228. package/dist/storage/index.js.map +0 -1
  229. package/dist/storage/indexeddb.d.ts.map +0 -1
  230. package/dist/storage/indexeddb.js.map +0 -1
  231. package/dist/storage/memory.d.ts.map +0 -1
  232. package/dist/storage/memory.js.map +0 -1
  233. package/dist/storage/opfs/files.d.ts.map +0 -1
  234. package/dist/storage/opfs/files.js.map +0 -1
  235. package/dist/storage/opfs/index.d.ts.map +0 -1
  236. package/dist/storage/opfs/index.js.map +0 -1
  237. package/dist/storage/opfs/leader.d.ts.map +0 -1
  238. package/dist/storage/opfs/leader.js.map +0 -1
  239. package/dist/storage/opfs/rpc.d.ts.map +0 -1
  240. package/dist/storage/opfs/rpc.js.map +0 -1
  241. package/dist/storage/opfs/store.d.ts.map +0 -1
  242. package/dist/storage/opfs/store.js.map +0 -1
  243. package/dist/storage/snapshot.d.ts.map +0 -1
  244. package/dist/storage/snapshot.js.map +0 -1
  245. package/dist/storage/toolkit/extents.d.ts.map +0 -1
  246. package/dist/storage/toolkit/extents.js.map +0 -1
  247. package/dist/storage/toolkit/index.d.ts.map +0 -1
  248. package/dist/storage/toolkit/index.js.map +0 -1
  249. package/dist/storage/toolkit/record-core.d.ts.map +0 -1
  250. package/dist/storage/toolkit/record-core.js.map +0 -1
  251. package/dist/storage/toolkit/sync-file.d.ts.map +0 -1
  252. package/dist/storage/toolkit/sync-file.js.map +0 -1
  253. package/dist/storage/toolkit/wal.d.ts.map +0 -1
  254. package/dist/storage/toolkit/wal.js.map +0 -1
  255. package/dist/storage/toolkit/wire.d.ts.map +0 -1
  256. package/dist/storage/toolkit/wire.js.map +0 -1
  257. package/dist/storage/types.d.ts.map +0 -1
  258. package/dist/storage/types.js.map +0 -1
  259. package/dist/testing/block-store-conformance.d.ts.map +0 -1
  260. package/dist/testing/block-store-conformance.js.map +0 -1
  261. package/dist/testing/index.d.ts.map +0 -1
  262. package/dist/testing/index.js.map +0 -1
  263. package/dist/testing/opfs-shim.d.ts.map +0 -1
  264. package/dist/testing/opfs-shim.js.map +0 -1
  265. package/dist/testing/seeds.d.ts +0 -11
  266. package/dist/testing/seeds.d.ts.map +0 -1
  267. package/dist/testing/seeds.js +0 -50
  268. package/dist/testing/seeds.js.map +0 -1
  269. package/dist/testing/simulator.d.ts.map +0 -1
  270. package/dist/testing/simulator.js.map +0 -1
  271. package/dist/testing/sqllogictest.d.ts.map +0 -1
  272. package/dist/testing/sqllogictest.js.map +0 -1
  273. package/dist/transactions/index.d.ts.map +0 -1
  274. package/dist/transactions/index.js.map +0 -1
  275. package/dist/worker-protocol/index.d.ts.map +0 -1
  276. package/dist/worker-protocol/index.js.map +0 -1
@@ -27,4 +27,3 @@ export declare function fillColumnDefaults(table: TableRecord, input: ColumnarBa
27
27
  * `fillColumnDefaults` created for this fill, never a caller-owned one.
28
28
  */
29
29
  export declare function patchAutoIncrementValues(input: ColumnarBatch, fill: AutoIncrementFill, range: RowIdRange): void;
30
- //# sourceMappingURL=defaults.d.ts.map
@@ -3,6 +3,7 @@
3
3
  * explicit NULL passes through untouched. Literal and SQL-expression defaults are filled before
4
4
  * validation. Auto-increment slots stay null until the write path atomically reserves a range.
5
5
  */
6
+ import { copyDate } from "../date-value.js";
6
7
  export async function fillColumnDefaults(table, input, evaluateExpression, knownRowCount) {
7
8
  const rowCount = knownRowCount ?? Object.values(input.columns).find((values) => values.length > 0)?.length ?? 0;
8
9
  if (!Number.isSafeInteger(rowCount) || rowCount < 0) {
@@ -76,9 +77,7 @@ export async function fillColumnDefaults(table, input, evaluateExpression, known
76
77
  switch (defaultValue.kind) {
77
78
  case "literal":
78
79
  values[index] =
79
- defaultValue.value instanceof Date
80
- ? new Date(defaultValue.value.getTime())
81
- : defaultValue.value;
80
+ defaultValue.value instanceof Date ? copyDate(defaultValue.value) : defaultValue.value;
82
81
  break;
83
82
  case "expression":
84
83
  values[index] = await evaluateExpression(defaultValue.sql, index);
@@ -110,4 +109,3 @@ export function patchAutoIncrementValues(input, fill, range) {
110
109
  vector[rowIndex] = Number(value);
111
110
  });
112
111
  }
113
- //# sourceMappingURL=defaults.js.map
@@ -34,6 +34,25 @@ export declare class CompactionJobCancelledError extends Error {
34
34
  readonly name = "CompactionJobCancelledError";
35
35
  constructor(jobId: string);
36
36
  }
37
+ /** Refuses more growth after automatic collection repeatedly fails at a generous debt limit. */
38
+ export declare class MaintenanceBacklogError extends Error {
39
+ readonly pendingCommits: number;
40
+ readonly causeMessage: string | null;
41
+ readonly name = "MaintenanceBacklogError";
42
+ constructor(pendingCommits: number, causeMessage: string | null);
43
+ }
44
+ /**
45
+ * A paged visible-segment scan cannot continue after its table is dropped or replaced. Segment
46
+ * metadata for a dropped table is removed immediately, so returning an empty or partial page
47
+ * would silently misrepresent the captured scan.
48
+ */
49
+ export declare class VisibleSegmentCursorStaleError extends Error {
50
+ readonly tableName: string;
51
+ readonly capturedTableId: string;
52
+ readonly currentTableId: string | null;
53
+ readonly name = "VisibleSegmentCursorStaleError";
54
+ constructor(tableName: string, capturedTableId: string, currentTableId: string | null);
55
+ }
37
56
  /**
38
57
  * SQL that failed to compile, located in the text the caller passed. `offset` and `length` are
39
58
  * character positions into that exact string — leading whitespace included — so an editor can
@@ -52,4 +71,3 @@ export declare class SqlCompileError extends TypeError {
52
71
  constructor(message: string, offset: number, length: number);
53
72
  }
54
73
  export {};
55
- //# sourceMappingURL=errors.d.ts.map
@@ -3,7 +3,7 @@
3
3
  * them (name, fields, instanceof) without bundling the executor.
4
4
  */
5
5
  function formatValue(value) {
6
- return value instanceof Date ? value.toISOString() : String(value);
6
+ return value instanceof Date ? dateIsoString(value) : String(value);
7
7
  }
8
8
  export class UniqueConstraintError extends Error {
9
9
  tableName;
@@ -57,6 +57,36 @@ export class CompactionJobCancelledError extends Error {
57
57
  this.jobId = jobId;
58
58
  }
59
59
  }
60
+ /** Refuses more growth after automatic collection repeatedly fails at a generous debt limit. */
61
+ export class MaintenanceBacklogError extends Error {
62
+ pendingCommits;
63
+ causeMessage;
64
+ name = "MaintenanceBacklogError";
65
+ constructor(pendingCommits, causeMessage) {
66
+ super(`Automatic storage collection could not keep up after ${String(pendingCommits)} commits${causeMessage === null ? "" : `: ${causeMessage}`}`);
67
+ this.pendingCommits = pendingCommits;
68
+ this.causeMessage = causeMessage;
69
+ }
70
+ }
71
+ /**
72
+ * A paged visible-segment scan cannot continue after its table is dropped or replaced. Segment
73
+ * metadata for a dropped table is removed immediately, so returning an empty or partial page
74
+ * would silently misrepresent the captured scan.
75
+ */
76
+ export class VisibleSegmentCursorStaleError extends Error {
77
+ tableName;
78
+ capturedTableId;
79
+ currentTableId;
80
+ name = "VisibleSegmentCursorStaleError";
81
+ constructor(tableName, capturedTableId, currentTableId) {
82
+ super(`Visible segment cursor for ${tableName} is stale: captured table ${capturedTableId}; ${currentTableId === null
83
+ ? "the table no longer exists"
84
+ : `current table is ${currentTableId}`}`);
85
+ this.tableName = tableName;
86
+ this.capturedTableId = capturedTableId;
87
+ this.currentTableId = currentTableId;
88
+ }
89
+ }
60
90
  /**
61
91
  * SQL that failed to compile, located in the text the caller passed. `offset` and `length` are
62
92
  * character positions into that exact string — leading whitespace included — so an editor can
@@ -78,4 +108,4 @@ export class SqlCompileError extends TypeError {
78
108
  this.length = length;
79
109
  }
80
110
  }
81
- //# sourceMappingURL=errors.js.map
111
+ import { dateIsoString } from "../date-value.js";
@@ -41,11 +41,6 @@ export declare function tokenize(text: string): string[];
41
41
  */
42
42
  export declare function tokenizeQuery(query: string): FtsQueryTerm[];
43
43
  export declare function termMatches(token: string, term: FtsQueryTerm): boolean;
44
- /**
45
- * Compile-time cap on query terms: the columnar fast path packs per-term presence into one
46
- * 32-bit mask per dictionary entry.
47
- */
48
- export declare const FTS_MAX_QUERY_TERMS = 32;
49
44
  /** Tokenized query terms with the same bounded caching scheme as the LIKE pattern cache. */
50
45
  export declare function cachedQueryTerms(query: string): FtsQueryTerm[];
51
46
  /** Compile-time validation shared by the SQL parser and the DSL expression builder. */
@@ -90,4 +85,3 @@ export declare class FtsStatsAccumulator {
90
85
  export declare function ftsBm25Row(terms: readonly FtsQueryTerm[], values: Iterable<unknown>, stats: FtsStats): number | null;
91
86
  /** Renders one cell for the document, per column type. Booleans are excluded from documents. */
92
87
  export declare function renderDocumentValue(value: unknown): string | undefined;
93
- //# sourceMappingURL=fts.d.ts.map
@@ -11,19 +11,22 @@
11
11
  * count, total token count), so the row and columnar executors produce bit-identical scores no
12
12
  * matter what order they accumulate in. Keep it that way: never feed it a running float.
13
13
  */
14
+ import { assertWellFormedString } from "../block-format/unicode.js";
15
+ import { MAX_CACHEABLE_TEXT_CHARACTERS, MAX_SQL_PATTERN_CHARACTERS } from "./cache-limits.js";
14
16
  import { externalSqlDomainValue } from "./sql-domains.js";
17
+ import { MAX_FTS_QUERY_TERMS, MAX_FTS_TOKENS_PER_DOCUMENT, MAX_INDEXED_STRING_CHARACTERS, } from "../storage/types.js";
15
18
  export const FTS_TOKENIZER_VERSION = 1;
16
19
  /** BM25 constants — the standard defaults. */
17
20
  const BM25_K1 = 1.2;
18
21
  const BM25_B = 0.75;
19
22
  const MAX_TOKEN_LENGTH = 32;
20
- const MAX_TOKENS_PER_DOCUMENT = 4096;
21
23
  const TOKEN_RUN = /[\p{L}\p{N}]+/gu;
24
+ const QUERY_WHITESPACE = /\s/u;
22
25
  // Script_Extensions rather than Script: shared marks like the katakana prolonged sound mark
23
26
  // (U+30FC, script Common) must stay inside the kana run they extend.
24
27
  const CJK = /[\p{Script_Extensions=Han}\p{Script_Extensions=Hiragana}\p{Script_Extensions=Katakana}]/u;
25
28
  function pushToken(tokens, token) {
26
- if (tokens.length >= MAX_TOKENS_PER_DOCUMENT)
29
+ if (tokens.length >= MAX_FTS_TOKENS_PER_DOCUMENT)
27
30
  return;
28
31
  tokens.push(token.length > MAX_TOKEN_LENGTH ? token.slice(0, MAX_TOKEN_LENGTH) : token);
29
32
  }
@@ -59,11 +62,15 @@ function emitRun(tokens, run) {
59
62
  }
60
63
  /** Tokenizes one cell's text: NFKC, locale-independent lowercase, letter/number runs. */
61
64
  export function tokenize(text) {
65
+ if (text.length > MAX_INDEXED_STRING_CHARACTERS) {
66
+ throw new RangeError(`Full-text values cannot exceed ${String(MAX_INDEXED_STRING_CHARACTERS)} characters`);
67
+ }
68
+ assertWellFormedString(text, "Full-text value");
62
69
  const tokens = [];
63
70
  const normalized = text.normalize("NFKC").toLowerCase();
64
71
  for (const match of normalized.matchAll(TOKEN_RUN)) {
65
72
  emitRun(tokens, match[0]);
66
- if (tokens.length >= MAX_TOKENS_PER_DOCUMENT)
73
+ if (tokens.length >= MAX_FTS_TOKENS_PER_DOCUMENT)
67
74
  break;
68
75
  }
69
76
  return tokens;
@@ -74,15 +81,32 @@ export function tokenize(text) {
74
81
  * query matches nothing.
75
82
  */
76
83
  export function tokenizeQuery(query) {
84
+ if (query.length > MAX_SQL_PATTERN_CHARACTERS) {
85
+ throw new RangeError(`Full-text queries cannot exceed ${String(MAX_SQL_PATTERN_CHARACTERS)} characters`);
86
+ }
87
+ assertWellFormedString(query, "Full-text query");
77
88
  const terms = [];
78
- for (const chunk of query.split(/\s+/)) {
79
- if (chunk.length === 0)
89
+ let cursor = 0;
90
+ while (cursor < query.length) {
91
+ while (cursor < query.length && QUERY_WHITESPACE.test(query[cursor] ?? ""))
92
+ cursor += 1;
93
+ const start = cursor;
94
+ while (cursor < query.length && !QUERY_WHITESPACE.test(query[cursor] ?? ""))
95
+ cursor += 1;
96
+ if (cursor === start)
80
97
  continue;
81
- const prefix = chunk.endsWith("*");
82
- const tokens = tokenize(prefix ? chunk.slice(0, -1) : chunk);
83
- tokens.forEach((term, index) => {
98
+ const prefix = query[cursor - 1] === "*";
99
+ const tokens = tokenize(query.slice(start, prefix ? cursor - 1 : cursor));
100
+ for (let index = 0; index < tokens.length; index += 1) {
101
+ const term = tokens[index];
102
+ if (term === undefined)
103
+ continue;
84
104
  terms.push({ term, prefix: prefix && index === tokens.length - 1 });
85
- });
105
+ // Every caller rejects above 32. Stop before adversarial whitespace can allocate a terms
106
+ // array proportional to the input; the 33rd item is all validation needs to see.
107
+ if (terms.length > MAX_FTS_QUERY_TERMS)
108
+ return terms;
109
+ }
86
110
  }
87
111
  return terms;
88
112
  }
@@ -93,7 +117,6 @@ export function termMatches(token, term) {
93
117
  * Compile-time cap on query terms: the columnar fast path packs per-term presence into one
94
118
  * 32-bit mask per dictionary entry.
95
119
  */
96
- export const FTS_MAX_QUERY_TERMS = 32;
97
120
  const queryTermsCache = new Map();
98
121
  /** Tokenized query terms with the same bounded caching scheme as the LIKE pattern cache. */
99
122
  export function cachedQueryTerms(query) {
@@ -101,6 +124,8 @@ export function cachedQueryTerms(query) {
101
124
  if (cached !== undefined)
102
125
  return cached;
103
126
  const terms = tokenizeQuery(query);
127
+ if (query.length > MAX_CACHEABLE_TEXT_CHARACTERS)
128
+ return terms;
104
129
  if (queryTermsCache.size >= 128)
105
130
  queryTermsCache.clear();
106
131
  queryTermsCache.set(query, terms);
@@ -108,8 +133,8 @@ export function cachedQueryTerms(query) {
108
133
  }
109
134
  /** Compile-time validation shared by the SQL parser and the DSL expression builder. */
110
135
  export function validateFtsQuery(query) {
111
- if (cachedQueryTerms(query).length > FTS_MAX_QUERY_TERMS) {
112
- throw new TypeError(`Full-text queries support at most ${String(FTS_MAX_QUERY_TERMS)} terms`);
136
+ if (cachedQueryTerms(query).length > MAX_FTS_QUERY_TERMS) {
137
+ throw new TypeError(`Full-text queries support at most ${String(MAX_FTS_QUERY_TERMS)} terms`);
113
138
  }
114
139
  }
115
140
  /** Bitmask of query terms present in a token list: bit i set means terms[i] matched. */
@@ -267,9 +292,9 @@ export function renderDocumentValue(value) {
267
292
  if (value === null || value === undefined || typeof value === "boolean")
268
293
  return undefined;
269
294
  if (value instanceof Date)
270
- return value.toISOString();
295
+ return dateIsoString(value);
271
296
  if (typeof value === "number")
272
297
  return String(value);
273
298
  return typeof value === "string" ? value : undefined;
274
299
  }
275
- //# sourceMappingURL=fts.js.map
300
+ import { dateIsoString } from "../date-value.js";
@@ -29,4 +29,3 @@ export declare function hashScratch(length: number): number;
29
29
  export declare function equalsScratch(arena: Uint8Array, offset: number, length: number): boolean;
30
30
  /** Copies the scratch arena's first `length` bytes into owned storage. Exported for the join index. */
31
31
  export declare function copyScratchKey(length: number): Uint8Array;
32
- //# sourceMappingURL=group-index.d.ts.map
@@ -4,7 +4,6 @@ const INITIAL_KEY_CAPACITY = 32;
4
4
  const INDEX_FIELDS = 4;
5
5
  const UINT32_BYTES = Uint32Array.BYTES_PER_ELEMENT;
6
6
  const INITIAL_SCRATCH_CAPACITY = 64;
7
- const REPLACEMENT_CHARACTER_BYTES = [0xef, 0xbf, 0xbd];
8
7
  // Every probe encodes its key into this shared scratch arena instead of allocating a fresh buffer
9
8
  // per row. Encoding is synchronous and the bytes are consumed before the next probe begins, so a
10
9
  // single arena serves every index; the miss path copies out of it before any caller code runs.
@@ -255,8 +254,9 @@ function writeGroupKey(key, offset) {
255
254
  scratchView.setFloat64(offset + 1, key === 0 ? 0 : key, true);
256
255
  return offset + 1 + Float64Array.BYTES_PER_ELEMENT;
257
256
  }
258
- // A UTF-16 code unit never expands past three UTF-8 bytes, and a surrogate pair yields four
259
- // across two units, so reserving three bytes per unit lets the encode loop skip bounds checks.
257
+ // A code unit never expands past three UTF-8 bytes. Reserving the one conservative bound keeps
258
+ // this query hot path single-pass and branch-light; oversized scratch is reclaimed before the
259
+ // next key operation.
260
260
  const bound = safeSum(offset + 5, safeProduct(key.length, 3, "Encoded group key"), "Encoded group key");
261
261
  if (bound > 0xffff_ffff)
262
262
  throw new RangeError("Encoded group key is too large");
@@ -268,8 +268,8 @@ function writeGroupKey(key, offset) {
268
268
  return payloadEnd;
269
269
  }
270
270
  /**
271
- * Encodes `value` as UTF-8 at `offset`, which the caller has already sized. Unpaired surrogates
272
- * become U+FFFD, matching `TextEncoder` so two distinct strings never collapse to one key.
271
+ * Encodes `value` as UTF-8 in one pass. Isolated surrogates fail before the encoded bytes can
272
+ * participate in a lookup or insertion.
273
273
  */
274
274
  function writeUtf8(value, offset) {
275
275
  let write = offset;
@@ -300,11 +300,7 @@ function writeUtf8(value, offset) {
300
300
  }
301
301
  }
302
302
  if (code >= 0xd800 && code <= 0xdfff) {
303
- scratch[write] = REPLACEMENT_CHARACTER_BYTES[0];
304
- scratch[write + 1] = REPLACEMENT_CHARACTER_BYTES[1];
305
- scratch[write + 2] = REPLACEMENT_CHARACTER_BYTES[2];
306
- write += 3;
307
- continue;
303
+ throw new TypeError(`String value contains an unpaired surrogate at UTF-16 index ${String(index)}`);
308
304
  }
309
305
  scratch[write] = 0xe0 | (code >>> 12);
310
306
  scratch[write + 1] = 0x80 | ((code >>> 6) & 0x3f);
@@ -363,4 +359,3 @@ function safeSum(left, right, label) {
363
359
  throw new RangeError(`${label} exceeds the safe integer range`);
364
360
  return sum;
365
361
  }
366
- //# sourceMappingURL=group-index.js.map
@@ -1,14 +1,19 @@
1
+ /**
2
+ * The everyday in-thread API. Larger optional surfaces have their own entry points so exporting
3
+ * one helper cannot make an application download the worker client or typed live-query layer.
4
+ */
1
5
  export * from "./catalog.js";
2
- export * from "./client.js";
3
- export * from "./coordinator.js";
4
6
  export * from "./database.js";
5
- export * from "./schema-wire.js";
6
- export * from "./worker-host.js";
7
- export { bindPlanParameters, bindStatementParameters, compileQuery, compileStatement, executeQuery, referencedColumns, type InsertValue, type CompiledQuery, type CompiledStatement, type QueryResult, type QueryRow, type QueryExecutionOptions, type QueryValue, type SqlColumnSchema, type SqlColumnType, } from "./query.js";
7
+ export * from "./errors.js";
8
8
  export { QueryMemoryBudgetError, type QueryMemoryUsage } from "./memory.js";
9
- export { optimizePlan, renderPlan } from "./optimizer.js";
10
- export * from "./schema.js";
11
- export * from "./live.js";
12
- export * from "./sql-driver.js";
13
- export type { AsyncQueryExecutionOptions, QuerySpillStore } from "./vector.js";
14
- //# sourceMappingURL=index.d.ts.map
9
+ export { MAX_SQL_NESTING_DEPTH, MAX_SQL_NUMERIC_DIGITS, MAX_SQL_PARAMETERS, MAX_SQL_PATTERN_CHARACTERS, MAX_SQL_PATTERN_MATCH_STEPS, MAX_SQL_SCALAR_RESULT_CHARACTERS, MAX_SQL_STRUCTURED_VALUE_DEPTH, MAX_SQL_STRUCTURED_VALUE_ITEMS, MAX_SQL_TEXT_CHARACTERS, MAX_SQL_TOKENS, } from "./cache-limits.js";
10
+ /**
11
+ * The core schema declarations stay on the everyday entry. The optional typed-table renderer is
12
+ * available from `@minnowdb/core/schema`, so applications that execute SQL directly do not ship
13
+ * its statement builder. Advanced schema internals remain available from that same subpath.
14
+ */
15
+ export { column, foreignKeyName, isDestructiveStep, planMigration, schema, table, view, } from "./schema.js";
16
+ export type * from "./schema.js";
17
+ export type { InsertValue, CompiledQuery, CompiledStatement, QueryResult, QueryRow, QueryExecutionOptions, QueryValue, SqlColumnSchema, SqlColumnType, } from "./query.js";
18
+ export type { AsyncQueryExecutionOptions, QueryBatchExecutionOptions, QuerySpillStore, } from "./vector.js";
19
+ export type { MinnowSqlDriver, MinnowSqlExecutor } from "./sql-driver.js";
@@ -1,13 +1,15 @@
1
+ /**
2
+ * The everyday in-thread API. Larger optional surfaces have their own entry points so exporting
3
+ * one helper cannot make an application download the worker client or typed live-query layer.
4
+ */
1
5
  export * from "./catalog.js";
2
- export * from "./client.js";
3
- export * from "./coordinator.js";
4
6
  export * from "./database.js";
5
- export * from "./schema-wire.js";
6
- export * from "./worker-host.js";
7
- export { bindPlanParameters, bindStatementParameters, compileQuery, compileStatement, executeQuery, referencedColumns, } from "./query.js";
7
+ export * from "./errors.js";
8
8
  export { QueryMemoryBudgetError } from "./memory.js";
9
- export { optimizePlan, renderPlan } from "./optimizer.js";
10
- export * from "./schema.js";
11
- export * from "./live.js";
12
- export * from "./sql-driver.js";
13
- //# sourceMappingURL=index.js.map
9
+ export { MAX_SQL_NESTING_DEPTH, MAX_SQL_NUMERIC_DIGITS, MAX_SQL_PARAMETERS, MAX_SQL_PATTERN_CHARACTERS, MAX_SQL_PATTERN_MATCH_STEPS, MAX_SQL_SCALAR_RESULT_CHARACTERS, MAX_SQL_STRUCTURED_VALUE_DEPTH, MAX_SQL_STRUCTURED_VALUE_ITEMS, MAX_SQL_TEXT_CHARACTERS, MAX_SQL_TOKENS, } from "./cache-limits.js";
10
+ /**
11
+ * The core schema declarations stay on the everyday entry. The optional typed-table renderer is
12
+ * available from `@minnowdb/core/schema`, so applications that execute SQL directly do not ship
13
+ * its statement builder. Advanced schema internals remain available from that same subpath.
14
+ */
15
+ export { column, foreignKeyName, isDestructiveStep, planMigration, schema, table, view, } from "./schema.js";
@@ -9,4 +9,3 @@ export declare class ByteJoinIndex {
9
9
  firstRow(value: unknown): number;
10
10
  nextRow(row: number): number;
11
11
  }
12
- //# sourceMappingURL=join-index.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { dateMilliseconds } from "../date-value.js";
1
2
  import { copyScratchKey, encodeSingleScalarKey, equalsScratch, hashScratch, } from "./group-index.js";
2
3
  const INITIAL_ENTRY_CAPACITY = 4;
3
4
  const INITIAL_BUCKET_CAPACITY = 8;
@@ -190,7 +191,7 @@ export class ByteJoinIndex {
190
191
  * so a Date and its number representation join as the same key.
191
192
  */
192
193
  function encodeJoinKey(value) {
193
- const key = value instanceof Date ? value.getTime() : value;
194
+ const key = value instanceof Date ? dateMilliseconds(value) : value;
194
195
  if (key === null || key === undefined)
195
196
  return -1;
196
197
  if (typeof key === "number" && Number.isNaN(key))
@@ -214,4 +215,3 @@ function safeProduct(left, right, label) {
214
215
  }
215
216
  return product;
216
217
  }
217
- //# sourceMappingURL=join-index.js.map
@@ -0,0 +1,57 @@
1
+ import type { LiveQuery } from "./typed-live.js";
2
+ export type LiveResultKey = string | number | boolean | Date;
3
+ export type LiveKeyOf<TRow extends object> = {
4
+ [TKey in keyof TRow]-?: TRow[TKey] extends LiveResultKey ? TKey : never;
5
+ }[keyof TRow];
6
+ export type LiveResultChange<TRow extends object, TKey extends keyof TRow> = {
7
+ readonly type: "insert";
8
+ readonly row: TRow;
9
+ readonly index: number;
10
+ } | {
11
+ readonly type: "update";
12
+ readonly row: TRow;
13
+ readonly previous: TRow;
14
+ readonly index: number;
15
+ } | {
16
+ readonly type: "delete";
17
+ readonly key: TRow[TKey];
18
+ readonly previous: TRow;
19
+ readonly index: number;
20
+ } | {
21
+ readonly type: "move";
22
+ readonly key: TRow[TKey];
23
+ readonly row: TRow;
24
+ readonly from: number;
25
+ readonly to: number;
26
+ };
27
+ export type LiveChangesSnapshot<TRow extends object, TKey extends keyof TRow> = {
28
+ readonly status: "loading";
29
+ readonly rows: readonly TRow[];
30
+ } | {
31
+ readonly status: "ready";
32
+ readonly rows: readonly TRow[];
33
+ readonly changes: ReadonlyArray<LiveResultChange<TRow, TKey>>;
34
+ readonly initial: boolean;
35
+ readonly version: number | null;
36
+ } | {
37
+ readonly status: "error";
38
+ readonly rows: readonly TRow[];
39
+ readonly error: unknown;
40
+ readonly version: number | null;
41
+ };
42
+ export interface KeyedLiveQueryOptions<TRow extends object, TKey extends LiveKeyOf<TRow>> {
43
+ readonly key: TKey;
44
+ /** A window refuses a result larger than this instead of retaining an accidentally unbounded query. */
45
+ readonly maxRows?: number;
46
+ }
47
+ /** Keyed exact diffs over a typed live query, with optional bounded-window enforcement. */
48
+ export declare class KeyedLiveQuery<TRow extends object, TKey extends LiveKeyOf<TRow>> {
49
+ #private;
50
+ readonly $inferRow: TRow;
51
+ readonly $inferKey: TRow[TKey];
52
+ constructor(source: LiveQuery<TRow>, options: KeyedLiveQueryOptions<TRow, TKey>);
53
+ getSnapshot: () => LiveChangesSnapshot<TRow, TKey>;
54
+ subscribe: (listener: () => void) => (() => void);
55
+ refresh(): Promise<void>;
56
+ close(): void;
57
+ }