@minnowdb/core 0.3.0 → 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 (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 +4320 -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 +4306 -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
@@ -65,4 +65,3 @@ export declare function encodeQueryResult(result: QueryResult): EncodedQueryResu
65
65
  export declare function encodeQueryRows(rows: readonly QueryRow[]): EncodedQueryResult;
66
66
  export declare function decodeQueryResult(payload: unknown): QueryResult;
67
67
  export declare function isWireQueryResult(value: unknown): value is WireQueryResult;
68
- //# sourceMappingURL=result-wire.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { dateMilliseconds } from "../date-value.js";
1
2
  export function encodeQueryResult(result) {
2
3
  return encodeRows(result.columns, result.rows);
3
4
  }
@@ -115,7 +116,7 @@ function encodeColumn(name, rows) {
115
116
  nulls[index] = 1;
116
117
  }
117
118
  else if (value instanceof Date) {
118
- values[index] = value.getTime();
119
+ values[index] = dateMilliseconds(value);
119
120
  }
120
121
  else {
121
122
  return encodeMixed(name, rows);
@@ -261,4 +262,3 @@ function decodeColumnValues(column, rowCount) {
261
262
  }
262
263
  return values;
263
264
  }
264
- //# sourceMappingURL=result-wire.js.map
@@ -1,4 +1,4 @@
1
- import type { ColumnDefault, SqlDomain } from "../storage/index.js";
1
+ import type { ColumnDefault, SqlDomain } from "../storage/types.js";
2
2
  import { type AnyTable, type MigrationStep, type ReferentialAction, type SchemaColumnType, type SchemaDefinition, type TableCheck, type TableForeignKey } from "./schema.js";
3
3
  /**
4
4
  * Structured-clone-safe mirror of the schema DSL. Column builders and table validators carry
@@ -93,4 +93,3 @@ export type WireMigrationStep = {
93
93
  export declare function serializeSchema(definition: SchemaDefinition<readonly AnyTable[]>): WireSchema;
94
94
  export declare function serializeMigrationSteps(steps: readonly MigrationStep[]): WireMigrationStep[];
95
95
  export declare function deserializeSchema(wire: WireSchema): SchemaDefinition<readonly AnyTable[]>;
96
- //# sourceMappingURL=schema-wire.d.ts.map
@@ -119,4 +119,3 @@ export function deserializeSchema(wire) {
119
119
  views: (wire.views ?? []).map(deserializeView),
120
120
  });
121
121
  }
122
- //# sourceMappingURL=schema-wire.js.map
@@ -1,4 +1,4 @@
1
- import { type ColumnDefault, type SqlDomain, type TableColumnRecord, type TableRecord } from "../storage/index.js";
1
+ import { type ColumnDefault, type SqlDomain, type TableColumnRecord, type TableRecord } from "../storage/types.js";
2
2
  import { type Catalog, type CatalogColumn, type CatalogTable } from "./catalog.js";
3
3
  import { type QueryValue } from "./query.js";
4
4
  /**
@@ -44,8 +44,6 @@ export declare function foreignKeyName(tableName: string, columnName: string): s
44
44
  export type HasDefault<TValue> = TValue & {
45
45
  readonly __minnowHasDefault?: true;
46
46
  };
47
- /** Legacy compatibility marker. Schema-derived core and Kysely types read defaults directly. */
48
- export type Generated<TValue> = HasDefault<TValue>;
49
47
  export interface ColumnBuilder<TValue extends SchemaValue, TNullable extends boolean, TUnique extends boolean = false, THasDefault extends boolean = false, TInput extends SchemaValue = TValue> {
50
48
  readonly kind: "column";
51
49
  readonly type: SchemaColumnType;
@@ -232,11 +230,9 @@ export declare function table<const TName extends string, TColumns extends Recor
232
230
  */
233
231
  export declare function declaredForeignKeys(definition: AnyTable): Array<{
234
232
  name: string;
235
- column: string;
236
- columns?: string[];
233
+ columns: string[];
237
234
  parentTable: string;
238
- parentColumn: string;
239
- parentColumns?: string[];
235
+ parentColumns: string[];
240
236
  onDelete: ReferentialAction;
241
237
  }>;
242
238
  /**
@@ -472,4 +468,3 @@ export declare function typedTable<TTable extends AnyTable>(database: TypedTable
472
468
  /** Applies one table's alteration steps onto its current column records. */
473
469
  export declare function applyColumnSteps(record: TableRecord, steps: readonly MigrationStep[], createId: () => string): TableColumnRecord[];
474
470
  export {};
475
- //# sourceMappingURL=schema.d.ts.map
@@ -1,4 +1,5 @@
1
- import { validateColumnDefault, validateEnumValues, validateSqlDomain, } from "../storage/index.js";
1
+ import { copyDate, dateMilliseconds } from "../date-value.js";
2
+ import { validateColumnDefault, validateEnumValues, validateSqlDomain, } from "../storage/types.js";
2
3
  import { compileCheckExpression, expressionColumns, validateDefaultExpression, } from "./query.js";
3
4
  import { externalSqlDomainValue, normalizeSqlDomainValue } from "./sql-domains.js";
4
5
  /**
@@ -18,10 +19,10 @@ function defaultSpecFromArg(type, value, sqlDomain) {
18
19
  }
19
20
  switch (type) {
20
21
  case "datetime":
21
- if (!(value instanceof Date) || !Number.isFinite(value.getTime())) {
22
+ if (!(value instanceof Date) || !Number.isFinite(dateMilliseconds(value))) {
22
23
  throw new TypeError("Default literal must be a valid Date");
23
24
  }
24
- return { kind: "literal", value: new Date(value.getTime()) };
25
+ return { kind: "literal", value: copyDate(value) };
25
26
  case "string":
26
27
  if (typeof value !== "string")
27
28
  throw new TypeError("Default literal must be a string");
@@ -197,7 +198,7 @@ function validateDeclaredColumnValue(definition, value, context, label) {
197
198
  return;
198
199
  }
199
200
  const matches = definition.type === "datetime"
200
- ? value instanceof Date && Number.isFinite(value.getTime())
201
+ ? value instanceof Date && Number.isFinite(dateMilliseconds(value))
201
202
  : definition.type === "number"
202
203
  ? typeof value === "number" &&
203
204
  Number.isFinite(value) &&
@@ -296,6 +297,7 @@ export function table(name, columns, options = {}) {
296
297
  }
297
298
  }
298
299
  const foreignKeys = options.foreignKeys ?? [];
300
+ const constraintNames = new Set();
299
301
  const foreignKeyNames = new Set();
300
302
  for (const key of foreignKeys) {
301
303
  validateSchemaName(key.name, "FOREIGN KEY");
@@ -303,6 +305,10 @@ export function table(name, columns, options = {}) {
303
305
  throw new TypeError(`Duplicate FOREIGN KEY in table ${name}: ${key.name}`);
304
306
  }
305
307
  foreignKeyNames.add(key.name);
308
+ if (constraintNames.has(key.name)) {
309
+ throw new TypeError(`Duplicate constraint in table ${name}: ${key.name}`);
310
+ }
311
+ constraintNames.add(key.name);
306
312
  if (key.columns.length === 0 || new Set(key.columns).size !== key.columns.length) {
307
313
  throw new TypeError(`FOREIGN KEY ${key.name} needs distinct child columns`);
308
314
  }
@@ -333,9 +339,24 @@ export function table(name, columns, options = {}) {
333
339
  throw new TypeError(`Duplicate CHECK in table ${name}: ${check.name}`);
334
340
  }
335
341
  checkNames.add(check.name);
342
+ if (constraintNames.has(check.name)) {
343
+ throw new TypeError(`Duplicate constraint in table ${name}: ${check.name}`);
344
+ }
345
+ constraintNames.add(check.name);
336
346
  if (check.sql.trim().length === 0) {
337
347
  throw new TypeError(`CHECK ${check.name} in table ${name} has no expression`);
338
348
  }
349
+ for (const reference of expressionColumns(compileCheckExpression(check.sql, check.name))) {
350
+ const pieces = reference.split(".");
351
+ const columnName = pieces.at(-1) ?? reference;
352
+ const qualifier = pieces.length > 1 ? pieces.slice(0, -1).join(".") : undefined;
353
+ if (qualifier !== undefined && qualifier !== name) {
354
+ throw new TypeError(`CHECK ${check.name} references another table: ${reference}`);
355
+ }
356
+ if (columns[columnName] === undefined) {
357
+ throw new TypeError(`CHECK ${check.name} names an unknown column: ${columnName}`);
358
+ }
359
+ }
339
360
  }
340
361
  return {
341
362
  kind: "table",
@@ -406,9 +427,9 @@ export function declaredForeignKeys(definition) {
406
427
  continue;
407
428
  keys.push({
408
429
  name: foreignKeyName(definition.name, columnName),
409
- column: columnName,
430
+ columns: [columnName],
410
431
  parentTable: reference.table,
411
- parentColumn: reference.column,
432
+ parentColumns: [reference.column],
412
433
  onDelete: reference.onDelete,
413
434
  });
414
435
  }
@@ -417,11 +438,9 @@ export function declaredForeignKeys(definition) {
417
438
  const parentColumns = [...key.references.columns];
418
439
  keys.push({
419
440
  name: key.name,
420
- column: childColumns[0] ?? "",
421
- ...(childColumns.length === 1 ? {} : { columns: childColumns }),
441
+ columns: childColumns,
422
442
  parentTable: key.references.table,
423
- parentColumn: parentColumns[0] ?? "",
424
- ...(parentColumns.length === 1 ? {} : { parentColumns }),
443
+ parentColumns,
425
444
  onDelete: key.onDelete ?? "restrict",
426
445
  });
427
446
  }
@@ -478,8 +497,8 @@ export function schema(tables, options = {}) {
478
497
  throw new TypeError(`Duplicate FOREIGN KEY in table ${definition.name}: ${key.name}`);
479
498
  }
480
499
  declaredNames.add(key.name);
481
- const childNames = key.columns ?? [key.column];
482
- const parentNames = key.parentColumns ?? [key.parentColumn];
500
+ const childNames = key.columns;
501
+ const parentNames = key.parentColumns;
483
502
  const target = tables.find(({ name }) => name === key.parentTable);
484
503
  if (target === undefined ||
485
504
  childNames.some((columnName) => !(columnName in definition.columns)) ||
@@ -584,7 +603,7 @@ export function assertColumnDroppable(record, column) {
584
603
  throw new TypeError(`The unique key cannot be dropped: ${where}. Unique-key changes need the table recreated.`);
585
604
  }
586
605
  for (const key of record.foreignKeys) {
587
- if ((key.columns ?? [key.column]).includes(column.name)) {
606
+ if (key.columns.includes(column.name)) {
588
607
  throw new TypeError(`FOREIGN KEY ${key.name} still uses this column: ${where}`);
589
608
  }
590
609
  }
@@ -611,9 +630,8 @@ function assertColumnRenamable(catalog, record, column) {
611
630
  const where = `${record.name}.${column.name}`;
612
631
  for (const owner of catalog.tables) {
613
632
  for (const key of owner.foreignKeys) {
614
- const usesChild = owner.name === record.name && (key.columns ?? [key.column]).includes(column.name);
615
- const usesParent = key.parentTable === record.name &&
616
- (key.parentColumns ?? [key.parentColumn]).includes(column.name);
633
+ const usesChild = owner.name === record.name && key.columns.includes(column.name);
634
+ const usesParent = key.parentTable === record.name && key.parentColumns.includes(column.name);
617
635
  if (usesChild || usesParent) {
618
636
  throw new TypeError(`FOREIGN KEY ${key.name} prevents renaming ${where}`);
619
637
  }
@@ -652,7 +670,7 @@ function backfillsEqual(left, right) {
652
670
  if (externalLeft instanceof Date || externalRight instanceof Date) {
653
671
  return (externalLeft instanceof Date &&
654
672
  externalRight instanceof Date &&
655
- externalLeft.getTime() === externalRight.getTime());
673
+ dateMilliseconds(externalLeft) === dateMilliseconds(externalRight));
656
674
  }
657
675
  return externalLeft === externalRight;
658
676
  }
@@ -664,18 +682,18 @@ function backfillsEqual(left, right) {
664
682
  * discipline every other unprovable change gets: an explicit error naming the fix.
665
683
  */
666
684
  function assertConstraintsUnchanged(record, definition) {
667
- const describeKey = (key) => `${(key.columns ?? [key.column]).join(",")} -> ${key.parentTable}.` +
668
- `${(key.parentColumns ?? [key.parentColumn]).join(",")} ON DELETE ${key.onDelete}`;
685
+ const describeKey = (key) => `${key.columns.join(",")} -> ${key.parentTable}.` +
686
+ `${key.parentColumns.join(",")} ON DELETE ${key.onDelete}`;
669
687
  const existingKeys = new Map(record.foreignKeys.map((key) => [key.name, key]));
670
688
  const declaredKeys = new Map(declaredForeignKeys(definition).map((key) => [key.name, key]));
671
689
  for (const [name, declared] of declaredKeys) {
672
690
  const existing = existingKeys.get(name);
673
691
  if (existing === undefined) {
674
- throw new TypeError(`FOREIGN KEY cannot be added after creation: ${definition.name}.${declared.column}. ` +
692
+ throw new TypeError(`FOREIGN KEY cannot be added after creation: ${definition.name}.${declared.columns.join(",")}. ` +
675
693
  `Existing rows are not known to satisfy it; recreate the table to add a relation.`);
676
694
  }
677
695
  if (describeKey(existing) !== describeKey(declared)) {
678
- throw new TypeError(`FOREIGN KEY cannot change: ${definition.name}.${declared.column} is ` +
696
+ throw new TypeError(`FOREIGN KEY cannot change: ${definition.name}.${declared.columns.join(",")} is ` +
679
697
  `${describeKey(existing)}, schema says ${describeKey(declared)}`);
680
698
  }
681
699
  }
@@ -965,7 +983,7 @@ export function typedTable(database, definition) {
965
983
  };
966
984
  const keyToken = (value) => {
967
985
  const parts = keyParts(value);
968
- return JSON.stringify(parts.map((part) => part instanceof Date ? ["date", part.getTime()] : [typeof part, String(part)]));
986
+ return JSON.stringify(parts.map((part) => part instanceof Date ? ["date", dateMilliseconds(part)] : [typeof part, String(part)]));
969
987
  };
970
988
  const assertKeys = (keys, operation) => {
971
989
  if (keys.length === 0)
@@ -1147,8 +1165,7 @@ function columnDefaultsEqual(left, right) {
1147
1165
  if (left.value instanceof Date || right.value instanceof Date) {
1148
1166
  return (left.value instanceof Date &&
1149
1167
  right.value instanceof Date &&
1150
- left.value.getTime() === right.value.getTime());
1168
+ dateMilliseconds(left.value) === dateMilliseconds(right.value));
1151
1169
  }
1152
1170
  return left.value === right.value;
1153
1171
  }
1154
- //# sourceMappingURL=schema.js.map
@@ -72,4 +72,3 @@ export declare function buildSortKeyColumn(count: number, valueAt: (index: numbe
72
72
  * is already in order before doing anything else, since a scan often arrives sorted.
73
73
  */
74
74
  export declare function sortKeyIndexes(count: number, terms: readonly SortKeyTerm[]): Uint32Array;
75
- //# sourceMappingURL=sort-keys.d.ts.map
@@ -1,7 +1,8 @@
1
+ import { dateMilliseconds } from "../date-value.js";
1
2
  import { compareSqlStrings, compareSqlValues } from "./sql-semantics.js";
2
3
  /** Unwraps a datetime to the number the comparisons use; every other value passes through. */
3
4
  export function comparableSortValue(value) {
4
- return value instanceof Date ? value.getTime() : value;
5
+ return value instanceof Date ? dateMilliseconds(value) : value;
5
6
  }
6
7
  /**
7
8
  * Extracts one term's values into a comparison-ready column. `valueAt` is called once per row,
@@ -418,4 +419,3 @@ class KeySorter {
418
419
  return compare;
419
420
  }
420
421
  }
421
- //# sourceMappingURL=sort-keys.js.map
@@ -11,6 +11,12 @@ export declare function isExactNumeric(value: unknown): value is string;
11
11
  export declare function exactNumericValue(value: unknown, precision?: number, scale?: number): string | null;
12
12
  export declare function exactNumericBinary(operator: "+" | "-" | "*" | "/" | "%", left: unknown, right: unknown): string | null | undefined;
13
13
  export declare function exactNumericCompare(left: unknown, right: unknown): number | undefined;
14
+ /**
15
+ * Serializes a JSON value while bounding traversal, nesting, and output before concatenation.
16
+ * Canonical mode sorts object names directly in the wire text (including integer-looking names,
17
+ * which JavaScript object enumeration would otherwise silently reorder).
18
+ */
19
+ export declare function boundedJsonText(value: unknown, canonical: boolean, label?: string): string;
14
20
  export declare function jsonDomainValue(value: unknown, binary: boolean): string | null;
15
21
  export declare function uuidDomainValue(value: unknown): string | null;
16
22
  export declare function timeDomainValue(value: unknown): string | null;
@@ -23,4 +29,3 @@ export declare function collatedDomainValue(value: unknown, collation: unknown):
23
29
  export declare function collatedDomainCompare(left: unknown, right: unknown): number | undefined;
24
30
  export declare function externalSqlDomainValue(value: unknown): unknown;
25
31
  export declare function isSqlDomainValue(value: unknown): value is string;
26
- //# sourceMappingURL=sql-domains.d.ts.map