@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.
- package/README.md +4 -2
- package/dist/block-format/block.d.ts +32 -13
- package/dist/block-format/block.js +179 -55
- package/dist/block-format/checksum.d.ts +2 -1
- package/dist/block-format/checksum.js +5 -2
- package/dist/block-format/codecs.d.ts +7 -2
- package/dist/block-format/codecs.js +53 -12
- package/dist/block-format/column.d.ts +3 -2
- package/dist/block-format/column.js +96 -30
- package/dist/block-format/index.d.ts +2 -2
- package/dist/block-format/index.js +2 -2
- package/dist/block-format/physical.d.ts +8 -2
- package/dist/block-format/physical.js +14 -6
- package/dist/block-format/types.d.ts +7 -3
- package/dist/block-format/types.js +0 -1
- package/dist/block-format/unicode.d.ts +11 -0
- package/dist/block-format/unicode.js +46 -0
- package/dist/date-value.d.ts +15 -0
- package/dist/date-value.js +64 -0
- package/dist/engine/artifact-cache.d.ts +0 -1
- package/dist/engine/artifact-cache.js +0 -1
- package/dist/engine/batch.d.ts +5 -2
- package/dist/engine/batch.js +0 -1
- package/dist/engine/buffered-writer.d.ts +2 -1
- package/dist/engine/buffered-writer.js +34 -9
- package/dist/engine/cache-limits.d.ts +25 -0
- package/dist/engine/cache-limits.js +25 -0
- package/dist/engine/catalog.d.ts +5 -6
- package/dist/engine/catalog.js +5 -5
- package/dist/engine/client.d.ts +27 -7
- package/dist/engine/client.js +197 -31
- package/dist/engine/database.d.ts +161 -38
- package/dist/engine/database.js +4320 -1523
- package/dist/engine/defaults.d.ts +0 -1
- package/dist/engine/defaults.js +2 -4
- package/dist/engine/errors.d.ts +19 -1
- package/dist/engine/errors.js +32 -2
- package/dist/engine/fts.d.ts +0 -6
- package/dist/engine/fts.js +39 -14
- package/dist/engine/group-index.d.ts +0 -1
- package/dist/engine/group-index.js +6 -11
- package/dist/engine/index.d.ts +16 -11
- package/dist/engine/index.js +12 -10
- package/dist/engine/join-index.d.ts +0 -1
- package/dist/engine/join-index.js +2 -2
- package/dist/engine/keyed-live.d.ts +57 -0
- package/dist/engine/keyed-live.js +226 -0
- package/dist/engine/live-api.d.ts +4 -0
- package/dist/engine/live-api.js +4 -0
- package/dist/engine/live.d.ts +43 -26
- package/dist/engine/live.js +499 -129
- package/dist/engine/memory.d.ts +2 -1
- package/dist/engine/memory.js +3 -2
- package/dist/engine/optimizer.d.ts +0 -1
- package/dist/engine/optimizer.js +4 -4
- package/dist/engine/query-api.d.ts +3 -0
- package/dist/engine/query-api.js +3 -0
- package/dist/engine/query-cache.d.ts +0 -1
- package/dist/engine/query-cache.js +4 -4
- package/dist/engine/query.d.ts +4 -7
- package/dist/engine/query.js +348 -155
- package/dist/engine/result-wire.d.ts +0 -1
- package/dist/engine/result-wire.js +2 -2
- package/dist/engine/schema-wire.d.ts +1 -2
- package/dist/engine/schema-wire.js +0 -1
- package/dist/engine/schema.d.ts +3 -8
- package/dist/engine/schema.js +41 -24
- package/dist/engine/sort-keys.d.ts +0 -1
- package/dist/engine/sort-keys.js +2 -2
- package/dist/engine/sql-domains.d.ts +6 -1
- package/dist/engine/sql-domains.js +209 -45
- package/dist/engine/sql-driver.d.ts +2 -2
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-json.d.ts +0 -1
- package/dist/engine/sql-json.js +53 -7
- package/dist/engine/sql-semantics.d.ts +8 -5
- package/dist/engine/sql-semantics.js +427 -65
- package/dist/engine/typed-live.d.ts +67 -0
- package/dist/engine/typed-live.js +349 -0
- package/dist/engine/vector.d.ts +7 -1
- package/dist/engine/vector.js +202 -58
- package/dist/engine/worker-host.d.ts +8 -2
- package/dist/engine/worker-host.js +616 -152
- package/dist/engine/worker.d.ts +0 -1
- package/dist/engine/worker.js +3 -3
- package/dist/engine/write-block-planner.d.ts +18 -0
- package/dist/engine/write-block-planner.js +112 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plan/index.d.ts +0 -1
- package/dist/plan/index.js +0 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/indexeddb.d.ts +74 -65
- package/dist/storage/indexeddb.js +12301 -2076
- package/dist/storage/memory.d.ts +56 -66
- package/dist/storage/memory.js +1004 -139
- package/dist/storage/opfs/files.d.ts +18 -7
- package/dist/storage/opfs/files.js +115 -28
- package/dist/storage/opfs/index.d.ts +1 -1
- package/dist/storage/opfs/index.js +1 -1
- package/dist/storage/opfs/leader.d.ts +403 -91
- package/dist/storage/opfs/leader.js +4306 -602
- package/dist/storage/opfs/rpc.d.ts +15 -3
- package/dist/storage/opfs/rpc.js +223 -2
- package/dist/storage/opfs/snapshot-ledger.d.ts +40 -0
- package/dist/storage/opfs/snapshot-ledger.js +281 -0
- package/dist/storage/opfs/store.d.ts +26 -121
- package/dist/storage/opfs/store.js +436 -388
- package/dist/storage/persistence.d.ts +37 -0
- package/dist/storage/persistence.js +78 -0
- package/dist/storage/snapshot-stream.d.ts +24 -0
- package/dist/storage/snapshot-stream.js +897 -0
- package/dist/storage/snapshot.d.ts +9 -99
- package/dist/storage/snapshot.js +33 -309
- package/dist/storage/toolkit/extents.d.ts +41 -7
- package/dist/storage/toolkit/extents.js +402 -39
- package/dist/storage/toolkit/index.d.ts +3 -4
- package/dist/storage/toolkit/index.js +27 -3
- package/dist/storage/toolkit/record-core.d.ts +174 -61
- package/dist/storage/toolkit/record-core.js +5401 -849
- package/dist/storage/toolkit/sync-file.d.ts +10 -1
- package/dist/storage/toolkit/sync-file.js +50 -2
- package/dist/storage/toolkit/wal.d.ts +23 -5
- package/dist/storage/toolkit/wal.js +89 -27
- package/dist/storage/toolkit/wire.d.ts +4 -6
- package/dist/storage/toolkit/wire.js +80 -25
- package/dist/storage/types.d.ts +1271 -218
- package/dist/storage/types.js +1471 -138
- package/dist/testing/block-store-conformance.d.ts +0 -1
- package/dist/testing/block-store-conformance.js +877 -138
- package/dist/testing/index.d.ts +42 -31
- package/dist/testing/index.js +100 -68
- package/dist/testing/opfs-shim.d.ts +13 -3
- package/dist/testing/opfs-shim.js +40 -6
- package/dist/testing/simulator.d.ts +0 -1
- package/dist/testing/simulator.js +43 -12
- package/dist/testing/sqllogictest.d.ts +0 -1
- package/dist/testing/sqllogictest.js +0 -1
- package/dist/transactions/index.d.ts +81 -20
- package/dist/transactions/index.js +1050 -268
- package/dist/worker-protocol/index.d.ts +3 -2
- package/dist/worker-protocol/index.js +2 -5
- package/package.json +49 -1
- package/dist/block-format/block.d.ts.map +0 -1
- package/dist/block-format/block.js.map +0 -1
- package/dist/block-format/checksum.d.ts.map +0 -1
- package/dist/block-format/checksum.js.map +0 -1
- package/dist/block-format/codecs.d.ts.map +0 -1
- package/dist/block-format/codecs.js.map +0 -1
- package/dist/block-format/column.d.ts.map +0 -1
- package/dist/block-format/column.js.map +0 -1
- package/dist/block-format/index.d.ts.map +0 -1
- package/dist/block-format/index.js.map +0 -1
- package/dist/block-format/physical.d.ts.map +0 -1
- package/dist/block-format/physical.js.map +0 -1
- package/dist/block-format/types.d.ts.map +0 -1
- package/dist/block-format/types.js.map +0 -1
- package/dist/engine/artifact-cache.d.ts.map +0 -1
- package/dist/engine/artifact-cache.js.map +0 -1
- package/dist/engine/batch.d.ts.map +0 -1
- package/dist/engine/batch.js.map +0 -1
- package/dist/engine/buffered-writer.d.ts.map +0 -1
- package/dist/engine/buffered-writer.js.map +0 -1
- package/dist/engine/catalog.d.ts.map +0 -1
- package/dist/engine/catalog.js.map +0 -1
- package/dist/engine/client.d.ts.map +0 -1
- package/dist/engine/client.js.map +0 -1
- package/dist/engine/coordinator.d.ts +0 -17
- package/dist/engine/coordinator.d.ts.map +0 -1
- package/dist/engine/coordinator.js +0 -60
- package/dist/engine/coordinator.js.map +0 -1
- package/dist/engine/database.d.ts.map +0 -1
- package/dist/engine/database.js.map +0 -1
- package/dist/engine/defaults.d.ts.map +0 -1
- package/dist/engine/defaults.js.map +0 -1
- package/dist/engine/errors.d.ts.map +0 -1
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/fts.d.ts.map +0 -1
- package/dist/engine/fts.js.map +0 -1
- package/dist/engine/group-index.d.ts.map +0 -1
- package/dist/engine/group-index.js.map +0 -1
- package/dist/engine/index.d.ts.map +0 -1
- package/dist/engine/index.js.map +0 -1
- package/dist/engine/join-index.d.ts.map +0 -1
- package/dist/engine/join-index.js.map +0 -1
- package/dist/engine/live.d.ts.map +0 -1
- package/dist/engine/live.js.map +0 -1
- package/dist/engine/memory.d.ts.map +0 -1
- package/dist/engine/memory.js.map +0 -1
- package/dist/engine/optimizer.d.ts.map +0 -1
- package/dist/engine/optimizer.js.map +0 -1
- package/dist/engine/query-cache.d.ts.map +0 -1
- package/dist/engine/query-cache.js.map +0 -1
- package/dist/engine/query.d.ts.map +0 -1
- package/dist/engine/query.js.map +0 -1
- package/dist/engine/result-wire.d.ts.map +0 -1
- package/dist/engine/result-wire.js.map +0 -1
- package/dist/engine/schema-wire.d.ts.map +0 -1
- package/dist/engine/schema-wire.js.map +0 -1
- package/dist/engine/schema.d.ts.map +0 -1
- package/dist/engine/schema.js.map +0 -1
- package/dist/engine/sort-keys.d.ts.map +0 -1
- package/dist/engine/sort-keys.js.map +0 -1
- package/dist/engine/sql-domains.d.ts.map +0 -1
- package/dist/engine/sql-domains.js.map +0 -1
- package/dist/engine/sql-driver.d.ts.map +0 -1
- package/dist/engine/sql-driver.js.map +0 -1
- package/dist/engine/sql-json.d.ts.map +0 -1
- package/dist/engine/sql-json.js.map +0 -1
- package/dist/engine/sql-semantics.d.ts.map +0 -1
- package/dist/engine/sql-semantics.js.map +0 -1
- package/dist/engine/vector.d.ts.map +0 -1
- package/dist/engine/vector.js.map +0 -1
- package/dist/engine/worker-host.d.ts.map +0 -1
- package/dist/engine/worker-host.js.map +0 -1
- package/dist/engine/worker.d.ts.map +0 -1
- package/dist/engine/worker.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/plan/index.d.ts.map +0 -1
- package/dist/plan/index.js.map +0 -1
- package/dist/storage/fixture-shape.d.ts +0 -42
- package/dist/storage/fixture-shape.d.ts.map +0 -1
- package/dist/storage/fixture-shape.js +0 -146
- package/dist/storage/fixture-shape.js.map +0 -1
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/indexeddb.d.ts.map +0 -1
- package/dist/storage/indexeddb.js.map +0 -1
- package/dist/storage/memory.d.ts.map +0 -1
- package/dist/storage/memory.js.map +0 -1
- package/dist/storage/opfs/files.d.ts.map +0 -1
- package/dist/storage/opfs/files.js.map +0 -1
- package/dist/storage/opfs/index.d.ts.map +0 -1
- package/dist/storage/opfs/index.js.map +0 -1
- package/dist/storage/opfs/leader.d.ts.map +0 -1
- package/dist/storage/opfs/leader.js.map +0 -1
- package/dist/storage/opfs/rpc.d.ts.map +0 -1
- package/dist/storage/opfs/rpc.js.map +0 -1
- package/dist/storage/opfs/store.d.ts.map +0 -1
- package/dist/storage/opfs/store.js.map +0 -1
- package/dist/storage/snapshot.d.ts.map +0 -1
- package/dist/storage/snapshot.js.map +0 -1
- package/dist/storage/toolkit/extents.d.ts.map +0 -1
- package/dist/storage/toolkit/extents.js.map +0 -1
- package/dist/storage/toolkit/index.d.ts.map +0 -1
- package/dist/storage/toolkit/index.js.map +0 -1
- package/dist/storage/toolkit/record-core.d.ts.map +0 -1
- package/dist/storage/toolkit/record-core.js.map +0 -1
- package/dist/storage/toolkit/sync-file.d.ts.map +0 -1
- package/dist/storage/toolkit/sync-file.js.map +0 -1
- package/dist/storage/toolkit/wal.d.ts.map +0 -1
- package/dist/storage/toolkit/wal.js.map +0 -1
- package/dist/storage/toolkit/wire.d.ts.map +0 -1
- package/dist/storage/toolkit/wire.js.map +0 -1
- package/dist/storage/types.d.ts.map +0 -1
- package/dist/storage/types.js.map +0 -1
- package/dist/testing/block-store-conformance.d.ts.map +0 -1
- package/dist/testing/block-store-conformance.js.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/index.js.map +0 -1
- package/dist/testing/opfs-shim.d.ts.map +0 -1
- package/dist/testing/opfs-shim.js.map +0 -1
- package/dist/testing/seeds.d.ts +0 -11
- package/dist/testing/seeds.d.ts.map +0 -1
- package/dist/testing/seeds.js +0 -50
- package/dist/testing/seeds.js.map +0 -1
- package/dist/testing/simulator.d.ts.map +0 -1
- package/dist/testing/simulator.js.map +0 -1
- package/dist/testing/sqllogictest.d.ts.map +0 -1
- package/dist/testing/sqllogictest.js.map +0 -1
- package/dist/transactions/index.d.ts.map +0 -1
- package/dist/transactions/index.js.map +0 -1
- package/dist/worker-protocol/index.d.ts.map +0 -1
- 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
|
|
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/
|
|
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
|
package/dist/engine/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ColumnDefault, type SqlDomain, type TableColumnRecord, type TableRecord } from "../storage/
|
|
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
|
-
|
|
236
|
-
columns?: string[];
|
|
233
|
+
columns: string[];
|
|
237
234
|
parentTable: string;
|
|
238
|
-
|
|
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
|
package/dist/engine/schema.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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:
|
|
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
|
|
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
|
-
|
|
430
|
+
columns: [columnName],
|
|
410
431
|
parentTable: reference.table,
|
|
411
|
-
|
|
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
|
-
|
|
421
|
-
...(childColumns.length === 1 ? {} : { columns: childColumns }),
|
|
441
|
+
columns: childColumns,
|
|
422
442
|
parentTable: key.references.table,
|
|
423
|
-
|
|
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
|
|
482
|
-
const parentNames = key.parentColumns
|
|
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 (
|
|
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 &&
|
|
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
|
|
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) => `${
|
|
668
|
-
`${
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
package/dist/engine/sort-keys.js
CHANGED
|
@@ -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
|
|
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
|