qubu 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{canonical-BbnqavJm.mjs → canonical-BXUguqfo.mjs} +23 -23
- package/dist/codegen.d.mts +25 -33
- package/dist/codegen.mjs +38 -45
- package/dist/column-hqKr7-1I.mjs +620 -0
- package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
- package/dist/{complete-types-BavBtv8J.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +4 -4
- package/dist/ddl.d.mts +12 -12
- package/dist/ddl.mjs +13 -14
- package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
- package/dist/diff.d.mts +1 -1
- package/dist/diff.mjs +6 -7
- package/dist/{index-DH0qV6aS.d.mts → index-1DpA3mUh.d.mts} +20 -20
- package/dist/{index-D3ZOwPT-.d.mts → index-CPvfEheG.d.mts} +13 -15
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +94 -95
- package/dist/introspection.d.mts +8 -8
- package/dist/introspection.mjs +29 -30
- package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
- package/dist/migration.d.mts +20 -21
- package/dist/migration.mjs +5 -6
- package/dist/{mysql-CKEKGnj4.mjs → mysql-B_cYzzX2.mjs} +237 -7
- package/dist/mysql.d.mts +2 -2
- package/dist/mysql.mjs +3 -3
- package/dist/{on-conflict-4MOBl51J.mjs → on-conflict-hfPW0KmQ.mjs} +3 -4
- package/dist/postgres.d.mts +5 -5
- package/dist/postgres.mjs +6 -6
- package/dist/{registry-CXV8u7Pt.mjs → registry-BRMLYwDp.mjs} +26 -29
- package/dist/{relational-DuQ9IHSb.mjs → relational-BZ3WDPzC.mjs} +2 -2
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +5 -6
- package/dist/{snapshot-DJpfmxhQ.mjs → snapshot-C-W65HEd.mjs} +5 -5
- package/dist/snapshot.d.mts +3 -3
- package/dist/snapshot.mjs +5 -7
- package/dist/{source-DGO3DRgg.mjs → source-BcS2AsIg.mjs} +6 -8
- package/dist/{serialize-CFtYYAdk.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +2 -2
- package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
- package/dist/{table-D6rcs8SB.mjs → table-Bp5irMSj.mjs} +2 -3
- package/dist/{types-Deo_q43Y.d.mts → types-BK1COGZe.d.mts} +1113 -1128
- package/dist/{types-g-vVvj1B.mjs → types-JM3FcAnX.mjs} +7 -8
- package/dist/{types-CSNJTYaM.d.mts → types-JSZHpUEj.d.mts} +83 -84
- package/dist/{value-b6OFZXVS.mjs → value-Bi71Agyf.mjs} +1 -1
- package/dist/vite/ambient.d.ts +309 -340
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/docs/dialects-and-execution.md +45 -55
- package/docs/getting-started.md +4 -4
- package/docs/guides/better-auth.md +57 -0
- package/docs/guides/compose-queries.md +24 -67
- package/docs/guides/drizzle.md +23 -23
- package/docs/guides/extensions/dialects.md +4 -4
- package/docs/guides/extensions/sources-and-clauses.md +15 -15
- package/docs/guides/extensions/typed-expressions.md +13 -17
- package/docs/guides/extensions/unsafe-syntax.md +3 -3
- package/docs/guides/json.md +7 -7
- package/docs/guides/mutations.md +14 -21
- package/docs/guides/select/conditions.md +6 -8
- package/docs/guides/select/grouping-and-windows.md +4 -15
- package/docs/guides/select/ordering-and-pagination.md +6 -19
- package/docs/guides/select/overview.md +12 -26
- package/docs/guides/sql-templates.md +20 -24
- package/docs/guides/vite-plugin.md +9 -13
- package/docs/index.md +5 -7
- package/docs/query-model/fragments.md +4 -15
- package/docs/query-model/result-shapes.md +11 -14
- package/docs/query-model/source-scope.md +31 -49
- package/docs/reference/mysql-snapshot.md +2 -5
- package/docs/reference/postgres-snapshot.md +3 -3
- package/docs/reference/sqlite-snapshot.md +2 -5
- package/docs/reference/supported-surface.md +26 -26
- package/docs/schema/catalog-model.md +2 -5
- package/docs/schema/code-generation.md +18 -18
- package/docs/schema/columns-and-writes.md +17 -25
- package/docs/schema/constraints-and-indexes.md +36 -52
- package/docs/schema/ddl-emission.md +6 -6
- package/docs/schema/diff.md +5 -5
- package/docs/schema/introspection.md +7 -7
- package/docs/schema/migration-plans.md +9 -9
- package/docs/schema/snapshots.md +3 -3
- package/docs/schema/storage-and-schema-sql.md +11 -11
- package/docs/schema/tables-and-names.md +11 -14
- package/docs/sql-semantic-types.md +10 -10
- package/docs/troubleshooting.md +10 -10
- package/package.json +21 -33
- package/skills/qubu/agents/openai.yaml +3 -3
- package/dist/column-D-8OqGuV.mjs +0 -328
- package/dist/column-LV7oGQde.mjs +0 -296
- package/dist/drizzle-mysql.d.mts +0 -24
- package/dist/drizzle-mysql.mjs +0 -72
- package/dist/drizzle-postgres.d.mts +0 -24
- package/dist/drizzle-postgres.mjs +0 -73
- package/dist/drizzle-sqlite.d.mts +0 -57
- package/dist/drizzle-sqlite.mjs +0 -108
- package/dist/drizzle.d.mts +0 -13
- package/dist/drizzle.mjs +0 -2
- package/dist/errors-BGCoLe_r.mjs +0 -14
- package/dist/postgres-BK2APkKP.mjs +0 -236
- package/dist/runtime-Cn_Xgzta.mjs +0 -193
- package/dist/sqlite-CrsK0Fza.mjs +0 -320
- package/dist/types-DZsueVoI.d.mts +0 -45
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as standardDialect } from "./standard-
|
|
2
|
-
import {
|
|
3
|
-
import { _ as isUnsafeSchemaSql, n as defaultSchemaNamingPolicy, y as renderSchemaExpression } from "./registry-
|
|
4
|
-
import { t as createSchemaDialect } from "./dialect-
|
|
5
|
-
import { a as toSnapshotJsonValue, f as schemaSnapshotFormat, i as schemaSnapshotDigest, o as SnapshotValidationError, r as encodeCanonicalSnapshot, s as assertSchemaSnapshot, u as neutralSnapshotDialect } from "./canonical-
|
|
1
|
+
import { t as standardDialect } from "./standard-DfcZEVOj.mjs";
|
|
2
|
+
import { N as generatedSchemaObjectName, P as isValidSchemaObjectName, r as isColumnReference } from "./column-hqKr7-1I.mjs";
|
|
3
|
+
import { _ as isUnsafeSchemaSql, m as validateConstraintDialect, n as defaultSchemaNamingPolicy, w as validateIndexDialect, y as renderSchemaExpression } from "./registry-BRMLYwDp.mjs";
|
|
4
|
+
import { t as createSchemaDialect } from "./dialect-wUKrnPMB.mjs";
|
|
5
|
+
import { a as toSnapshotJsonValue, f as schemaSnapshotFormat, i as schemaSnapshotDigest, o as SnapshotValidationError, r as encodeCanonicalSnapshot, s as assertSchemaSnapshot, u as neutralSnapshotDialect } from "./canonical-BXUguqfo.mjs";
|
|
6
|
+
import { sqliteDialect } from "./sqlite.mjs";
|
|
6
7
|
//#region src/snapshot/serialize.ts
|
|
7
8
|
const neutralSchemaDialect = createSchemaDialect(Object.freeze({
|
|
8
9
|
...standardDialect(),
|
|
@@ -248,7 +249,7 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
248
249
|
id,
|
|
249
250
|
"dialect"
|
|
250
251
|
], options, diagnostics);
|
|
251
|
-
if (columns === void 0) return
|
|
252
|
+
if (columns === void 0) return;
|
|
252
253
|
const timing = serializeTiming(constraint);
|
|
253
254
|
if (constraint.kind === "unique-constraint") return {
|
|
254
255
|
...common,
|
|
@@ -282,7 +283,7 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
282
283
|
id,
|
|
283
284
|
"dialect"
|
|
284
285
|
], options, diagnostics);
|
|
285
|
-
if (columns === void 0 || target === void 0) return
|
|
286
|
+
if (columns === void 0 || target === void 0) return;
|
|
286
287
|
return {
|
|
287
288
|
...common,
|
|
288
289
|
kind: "foreign-key",
|
|
@@ -306,7 +307,7 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
306
307
|
id,
|
|
307
308
|
"dialect"
|
|
308
309
|
], options, diagnostics);
|
|
309
|
-
if (expression === void 0) return
|
|
310
|
+
if (expression === void 0) return;
|
|
310
311
|
return {
|
|
311
312
|
...common,
|
|
312
313
|
kind: "check",
|
|
@@ -372,7 +373,7 @@ function resolveForeignKeyTarget(constraint, tableIds, tablesById, path, diagnos
|
|
|
372
373
|
return;
|
|
373
374
|
}
|
|
374
375
|
const targetColumns = serializeColumns(target.columns, target.table, [...path, "columns"], diagnostics);
|
|
375
|
-
if (targetColumns === void 0) return
|
|
376
|
+
if (targetColumns === void 0) return;
|
|
376
377
|
return {
|
|
377
378
|
table: targetId,
|
|
378
379
|
columns: targetColumns
|
|
@@ -404,7 +405,7 @@ function serializeIndex(id, indexMetadata, table, dialect, options, diagnostics)
|
|
|
404
405
|
id,
|
|
405
406
|
"dialect"
|
|
406
407
|
], options, diagnostics);
|
|
407
|
-
if (terms.length !== indexMetadata.terms.length || indexMetadata.includedColumns !== void 0 && includedColumns === void 0) return
|
|
408
|
+
if (terms.length !== indexMetadata.terms.length || indexMetadata.includedColumns !== void 0 && includedColumns === void 0) return;
|
|
408
409
|
return {
|
|
409
410
|
id,
|
|
410
411
|
kind: "index",
|
|
@@ -503,7 +504,7 @@ function encodeExpression(expression, mode, dialect, path, options, diagnostics)
|
|
|
503
504
|
}
|
|
504
505
|
}
|
|
505
506
|
function encodeExtension(extension, dialect, path, options, diagnostics) {
|
|
506
|
-
if (extension === void 0) return
|
|
507
|
+
if (extension === void 0) return;
|
|
507
508
|
if (extension.dialect !== dialect.name) {
|
|
508
509
|
diagnostics.push({
|
|
509
510
|
code: "dialect-mismatch",
|
|
@@ -553,4 +554,317 @@ function compareId(left, right) {
|
|
|
553
554
|
return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
|
|
554
555
|
}
|
|
555
556
|
//#endregion
|
|
556
|
-
|
|
557
|
+
//#region src/snapshot/sqlite.ts
|
|
558
|
+
/** SQLite's v1 snapshot extension identity. */
|
|
559
|
+
const sqliteSnapshotDialect = Object.freeze({
|
|
560
|
+
name: "sqlite",
|
|
561
|
+
version: 1
|
|
562
|
+
});
|
|
563
|
+
var SqliteSnapshotDialectError = class extends TypeError {
|
|
564
|
+
code = "dialect-mismatch";
|
|
565
|
+
};
|
|
566
|
+
const sqliteStorageTypes = Object.freeze({
|
|
567
|
+
integer: "INTEGER",
|
|
568
|
+
numeric: "NUMERIC",
|
|
569
|
+
text: "TEXT",
|
|
570
|
+
boolean: "INTEGER",
|
|
571
|
+
date: "TEXT",
|
|
572
|
+
timestamp: "TEXT",
|
|
573
|
+
uuid: "TEXT",
|
|
574
|
+
json: "TEXT",
|
|
575
|
+
bigint: "INTEGER",
|
|
576
|
+
binary: "BLOB"
|
|
577
|
+
});
|
|
578
|
+
/**
|
|
579
|
+
* Resolve SQLite's declared-type affinity without changing the declaration. SQLite applies these
|
|
580
|
+
* ordered substring rules at table creation time; the returned affinity is useful metadata, not a
|
|
581
|
+
* replacement for the exact type.
|
|
582
|
+
*/
|
|
583
|
+
function sqliteStorageAffinity(declaration) {
|
|
584
|
+
const upper = declaration.toUpperCase();
|
|
585
|
+
if (upper.includes("INT")) return "integer";
|
|
586
|
+
if (upper.includes("CHAR") || upper.includes("CLOB") || upper.includes("TEXT")) return "text";
|
|
587
|
+
if (upper.includes("BLOB") || upper.trim().length === 0) return "blob";
|
|
588
|
+
if (upper.includes("REAL") || upper.includes("FLOA") || upper.includes("DOUB")) return "real";
|
|
589
|
+
return "numeric";
|
|
590
|
+
}
|
|
591
|
+
/** SQLite's query dialect plus its schema metadata behavior. */
|
|
592
|
+
const sqliteSchemaDialect = createSchemaDialect(sqliteDialect(), {
|
|
593
|
+
version: 1,
|
|
594
|
+
validate: validateSqliteSchema,
|
|
595
|
+
encodeStorage(storage, context) {
|
|
596
|
+
return encodeSqliteStorage(storage, context.dialect);
|
|
597
|
+
},
|
|
598
|
+
encodeExpression(expression, context) {
|
|
599
|
+
return encodeSqliteExpression(expression, context.mode, context.dialect);
|
|
600
|
+
},
|
|
601
|
+
encodeDialectExtension(extension, context) {
|
|
602
|
+
return encodeSqliteExtension(extension, context.dialect);
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
606
|
+
const sqliteSnapshotAdapter = Object.freeze({ dialect: sqliteSchemaDialect });
|
|
607
|
+
/** Create a canonical SQLite schema snapshot. */
|
|
608
|
+
function createSqliteSchemaSnapshot(schema, options = {}) {
|
|
609
|
+
return createSchemaSnapshot(schema, {
|
|
610
|
+
...options,
|
|
611
|
+
adapter: sqliteSnapshotAdapter
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
/** Return SQLite capability diagnostics without throwing. */
|
|
615
|
+
function tryCreateSqliteSchemaSnapshot(schema, options = {}) {
|
|
616
|
+
return tryCreateSchemaSnapshot(schema, {
|
|
617
|
+
...options,
|
|
618
|
+
adapter: sqliteSnapshotAdapter
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
function encodeSqliteStorage(storage, dialect) {
|
|
622
|
+
if (storage.kind === "native") {
|
|
623
|
+
if (storage.dialect !== dialect.name) throw new SqliteSnapshotDialectError(`SQLite storage cannot encode a native declaration owned by "${storage.dialect}"`);
|
|
624
|
+
if (storage.type.trim().length === 0) throw new TypeError("SQLite native storage declarations cannot be empty");
|
|
625
|
+
return {
|
|
626
|
+
kind: "native",
|
|
627
|
+
dialect: dialect.name,
|
|
628
|
+
type: storage.type,
|
|
629
|
+
affinity: sqliteStorageAffinity(storage.type)
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
const type = sqliteStorageTypes[storage.type];
|
|
633
|
+
if (type === void 0) throw new TypeError(`Unsupported portable storage type for SQLite: ${String(storage.type)}`);
|
|
634
|
+
return {
|
|
635
|
+
kind: "native",
|
|
636
|
+
dialect: dialect.name,
|
|
637
|
+
type,
|
|
638
|
+
affinity: sqliteStorageAffinity(type)
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
function encodeSqliteExpression(expression, mode, dialect) {
|
|
642
|
+
if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new SqliteSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the SQLite schema dialect is "${dialect.name}"`);
|
|
643
|
+
const rendered = renderSchemaExpression(expression, {
|
|
644
|
+
mode,
|
|
645
|
+
dialect
|
|
646
|
+
});
|
|
647
|
+
if (rendered.parameters.length !== 0) throw new TypeError("SQLite schema expressions must be parameter-free");
|
|
648
|
+
return {
|
|
649
|
+
kind: "expression",
|
|
650
|
+
expressionKind: expression.expressionKind,
|
|
651
|
+
sql: rendered.text,
|
|
652
|
+
...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
function encodeSqliteExtension(extension, dialect) {
|
|
656
|
+
if (extension.dialect !== dialect.name) throw new TypeError(`SQLite schema extensions require dialect "${dialect.name}"`);
|
|
657
|
+
const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
|
|
658
|
+
return {
|
|
659
|
+
dialect: dialect.name,
|
|
660
|
+
version: dialect.schema.version,
|
|
661
|
+
data: sortSnapshotJson(toSnapshotJsonValue(data))
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
function sortSnapshotJson(value) {
|
|
665
|
+
if (Array.isArray(value)) return value.map(sortSnapshotJson);
|
|
666
|
+
if (typeof value !== "object" || value === null) return value;
|
|
667
|
+
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
|
|
668
|
+
}
|
|
669
|
+
function validateSqliteSchema(schema, context) {
|
|
670
|
+
const diagnostics = [];
|
|
671
|
+
const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
|
|
672
|
+
const relationNames = /* @__PURE__ */ new Map();
|
|
673
|
+
if (schema.namespace !== void 0) validateSqliteName(schema.namespace, ["namespace"], "SQLite namespace", diagnostics);
|
|
674
|
+
for (const [id, entry] of tableEntries) {
|
|
675
|
+
const tablePath = ["tables", id];
|
|
676
|
+
validateSqliteName(entry.physicalName, [...tablePath, "physicalName"], "SQLite table", diagnostics);
|
|
677
|
+
addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
|
|
678
|
+
}
|
|
679
|
+
for (const [id, entry] of tableEntries) validateSqliteTable(id, entry, context, relationNames, diagnostics);
|
|
680
|
+
return Object.freeze(diagnostics);
|
|
681
|
+
}
|
|
682
|
+
function validateSqliteTable(tableId, entry, context, relationNames, diagnostics) {
|
|
683
|
+
const table = entry.table;
|
|
684
|
+
const tablePath = ["tables", tableId];
|
|
685
|
+
const definitions = table.definitions;
|
|
686
|
+
const metadata = table;
|
|
687
|
+
for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
|
|
688
|
+
validateSqliteName(table.sqlNames[columnId] ?? columnId, [
|
|
689
|
+
...tablePath,
|
|
690
|
+
"columns",
|
|
691
|
+
columnId,
|
|
692
|
+
"physicalName"
|
|
693
|
+
], "SQLite column", diagnostics);
|
|
694
|
+
if (definition.onUpdate !== void 0) diagnostics.push({
|
|
695
|
+
code: "unsupported-dialect-option",
|
|
696
|
+
message: "MySQL ON UPDATE expressions are not supported by SQLite",
|
|
697
|
+
path: [
|
|
698
|
+
...tablePath,
|
|
699
|
+
"columns",
|
|
700
|
+
columnId,
|
|
701
|
+
"onUpdate"
|
|
702
|
+
]
|
|
703
|
+
});
|
|
704
|
+
const storage = definition.storage;
|
|
705
|
+
const identity = definition.identity;
|
|
706
|
+
if (identity !== void 0) {
|
|
707
|
+
const identityPath = [
|
|
708
|
+
...tablePath,
|
|
709
|
+
"columns",
|
|
710
|
+
columnId,
|
|
711
|
+
"identity"
|
|
712
|
+
];
|
|
713
|
+
const extension = identity.dialect;
|
|
714
|
+
if (extension !== void 0 && extension.dialect === "sqlite" && extension.autoIncrement !== void 0 && typeof extension.autoIncrement !== "boolean") diagnostics.push({
|
|
715
|
+
code: "unsupported-dialect-option",
|
|
716
|
+
message: "SQLite identity autoIncrement must be boolean",
|
|
717
|
+
path: [
|
|
718
|
+
...identityPath,
|
|
719
|
+
"dialect",
|
|
720
|
+
"autoIncrement"
|
|
721
|
+
]
|
|
722
|
+
});
|
|
723
|
+
const primary = primaryKeyForColumn(metadata.constraints, columnId);
|
|
724
|
+
const declaration = sqliteDeclaration(storage);
|
|
725
|
+
if ((declaration === void 0 ? void 0 : sqliteStorageAffinity(declaration)) !== "integer") diagnostics.push({
|
|
726
|
+
code: "unsupported-dialect-option",
|
|
727
|
+
message: "SQLite identity columns must use INTEGER affinity so they can be rowid aliases",
|
|
728
|
+
path: [...identityPath, "generation"]
|
|
729
|
+
});
|
|
730
|
+
if (primary === void 0 || primary.length !== 1) diagnostics.push({
|
|
731
|
+
code: "unsupported-dialect-option",
|
|
732
|
+
message: "SQLite identity columns must be the sole column of a PRIMARY KEY constraint",
|
|
733
|
+
path: [...identityPath, "generation"]
|
|
734
|
+
});
|
|
735
|
+
if (extension?.dialect === "sqlite" && extension.autoIncrement === true && declaration?.trim().toUpperCase() !== "INTEGER") diagnostics.push({
|
|
736
|
+
code: "unsupported-dialect-option",
|
|
737
|
+
message: "SQLite AUTOINCREMENT requires an exact INTEGER PRIMARY KEY declaration",
|
|
738
|
+
path: [
|
|
739
|
+
...identityPath,
|
|
740
|
+
"dialect",
|
|
741
|
+
"autoIncrement"
|
|
742
|
+
]
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
if (definition.generatedColumn?.kind === "expression" && primaryKeyForColumn(metadata.constraints, columnId) !== void 0) diagnostics.push({
|
|
746
|
+
code: "unsupported-dialect-option",
|
|
747
|
+
message: "SQLite generated columns cannot be part of a PRIMARY KEY",
|
|
748
|
+
path: [
|
|
749
|
+
...tablePath,
|
|
750
|
+
"columns",
|
|
751
|
+
columnId,
|
|
752
|
+
"generatedColumn"
|
|
753
|
+
]
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
const constraintNames = /* @__PURE__ */ new Map();
|
|
757
|
+
const constraints = Object.entries(metadata.constraints);
|
|
758
|
+
for (const [constraintId, constraint] of constraints.sort(([left], [right]) => compareIds(left, right))) {
|
|
759
|
+
const constraintPath = [
|
|
760
|
+
...tablePath,
|
|
761
|
+
"constraints",
|
|
762
|
+
constraintId
|
|
763
|
+
];
|
|
764
|
+
const physicalName = constraint.physicalName ?? constraintId;
|
|
765
|
+
validateSqliteName(physicalName, [...constraintPath, "physicalName"], "SQLite constraint", diagnostics);
|
|
766
|
+
addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
|
|
767
|
+
appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
|
|
768
|
+
if ((constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint" || constraint.kind === "check") && (constraint.deferrable === true || constraint.initially !== void 0)) diagnostics.push({
|
|
769
|
+
code: "unsupported-dialect-option",
|
|
770
|
+
message: "SQLite only supports DEFERRABLE timing on foreign-key constraints",
|
|
771
|
+
path: [...constraintPath, constraint.deferrable ? "deferrable" : "initially"]
|
|
772
|
+
});
|
|
773
|
+
if (constraint.kind === "foreign-key" && constraint.match !== void 0 && constraint.match !== "simple") diagnostics.push({
|
|
774
|
+
code: "unsupported-dialect-option",
|
|
775
|
+
message: "SQLite supports MATCH SIMPLE foreign keys only",
|
|
776
|
+
path: [...constraintPath, "match"]
|
|
777
|
+
});
|
|
778
|
+
if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
|
|
779
|
+
code: "unsupported-dialect-option",
|
|
780
|
+
message: "SQLite UNIQUE constraints always use distinct NULL semantics in v1",
|
|
781
|
+
path: [...constraintPath, "nulls"]
|
|
782
|
+
});
|
|
783
|
+
if (constraint.dialect?.dialect === "sqlite" && "onConflict" in constraint.dialect && constraint.dialect.onConflict !== void 0 && ![
|
|
784
|
+
"rollback",
|
|
785
|
+
"abort",
|
|
786
|
+
"fail",
|
|
787
|
+
"ignore",
|
|
788
|
+
"replace"
|
|
789
|
+
].includes(String(constraint.dialect.onConflict))) diagnostics.push({
|
|
790
|
+
code: "unsupported-dialect-option",
|
|
791
|
+
message: "SQLite constraint onConflict has an unsupported value",
|
|
792
|
+
path: [
|
|
793
|
+
...constraintPath,
|
|
794
|
+
"dialect",
|
|
795
|
+
"onConflict"
|
|
796
|
+
]
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
const indexes = Object.entries(metadata.indexes);
|
|
800
|
+
for (const [indexId, index] of indexes.sort(([left], [right]) => compareIds(left, right))) {
|
|
801
|
+
const indexPath = [
|
|
802
|
+
...tablePath,
|
|
803
|
+
"indexes",
|
|
804
|
+
indexId
|
|
805
|
+
];
|
|
806
|
+
const physicalName = index.physicalName ?? indexId;
|
|
807
|
+
validateSqliteName(physicalName, [...indexPath, "physicalName"], "SQLite index", diagnostics);
|
|
808
|
+
addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
|
|
809
|
+
appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
|
|
810
|
+
if (index.dialect?.dialect === "sqlite" && "auto" in index.dialect && index.dialect.auto !== void 0 && typeof index.dialect.auto !== "boolean") diagnostics.push({
|
|
811
|
+
code: "unsupported-dialect-option",
|
|
812
|
+
message: "SQLite index auto must be boolean",
|
|
813
|
+
path: [
|
|
814
|
+
...indexPath,
|
|
815
|
+
"dialect",
|
|
816
|
+
"auto"
|
|
817
|
+
]
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function sqliteDeclaration(storage) {
|
|
822
|
+
if (storage === void 0) return;
|
|
823
|
+
if (storage.kind === "native") return storage.type;
|
|
824
|
+
return sqliteStorageTypes[storage.type];
|
|
825
|
+
}
|
|
826
|
+
function primaryKeyForColumn(constraints, columnId) {
|
|
827
|
+
for (const constraint of Object.values(constraints)) {
|
|
828
|
+
if (constraint.kind !== "primary-key") continue;
|
|
829
|
+
if (constraint.columns.some((column) => isColumnReference(column) && column.fieldName === columnId)) return constraint.columns;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function validateSqliteName(name, path, kind, diagnostics) {
|
|
833
|
+
if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
|
|
834
|
+
code: "invalid-schema",
|
|
835
|
+
message: `${kind} name "${name}" is not a valid unqualified identifier`,
|
|
836
|
+
path
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
function addRelationName(names, name, path, kind, diagnostics) {
|
|
840
|
+
addScopedName(names, name, path, kind, diagnostics);
|
|
841
|
+
}
|
|
842
|
+
function addScopedName(names, name, path, kind, diagnostics) {
|
|
843
|
+
const previousPath = names.get(name);
|
|
844
|
+
if (previousPath !== void 0) {
|
|
845
|
+
diagnostics.push({
|
|
846
|
+
code: "invalid-schema",
|
|
847
|
+
message: `SQLite ${kind} name "${name}" collides with another table or index`,
|
|
848
|
+
path,
|
|
849
|
+
relatedPaths: [previousPath]
|
|
850
|
+
});
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
names.set(name, path);
|
|
854
|
+
}
|
|
855
|
+
function appendMetadataDiagnostics(diagnostics, issues) {
|
|
856
|
+
for (const issue of issues) {
|
|
857
|
+
if (issue.code === "dialect-mismatch") continue;
|
|
858
|
+
diagnostics.push({
|
|
859
|
+
code: issue.code === "unsupported-dialect-option" ? "unsupported-dialect-option" : "invalid-schema",
|
|
860
|
+
message: issue.message,
|
|
861
|
+
path: issue.path,
|
|
862
|
+
...issue.relatedPaths === void 0 ? {} : { relatedPaths: issue.relatedPaths }
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
function compareIds(left, right) {
|
|
867
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
868
|
+
}
|
|
869
|
+
//#endregion
|
|
870
|
+
export { sqliteStorageAffinity as a, createSchemaSnapshot as c, encodeSnapshot as d, serializeSchema as f, sqliteSnapshotDialect as i, digestSchemaSnapshot as l, sqliteSchemaDialect as n, tryCreateSqliteSchemaSnapshot as o, tryCreateSchemaSnapshot as p, sqliteSnapshotAdapter as r, SnapshotSerializationError as s, createSqliteSchemaSnapshot as t, encodeSchemaSnapshot as u };
|
package/dist/sqlite.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as Dialect, _n as doNothing, bn as onConflict, dn as ConflictAction, fn as ConflictTarget, gn as OnConflictClause, hn as ExcludedSource, mn as DoUpdateAction, pn as DoNothingAction, vn as doUpdate, yn as excluded } from "./types-BK1COGZe.mjs";
|
|
2
2
|
//#region src/dialects/sqlite.d.ts
|
|
3
3
|
declare function sqliteDialect(): Dialect<"json" | "on-conflict">;
|
|
4
4
|
//#endregion
|
package/dist/sqlite.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { o as createDialect, r as sqliteJson } from "./json-
|
|
1
|
+
import { o as createDialect, r as sqliteJson } from "./json-Db7XRD91.mjs";
|
|
2
2
|
import { r as sqliteExplain } from "./explain-CkIK13L_.mjs";
|
|
3
|
-
import { i as onConflict, n as doUpdate, r as excluded, t as doNothing } from "./on-conflict-
|
|
3
|
+
import { i as onConflict, n as doUpdate, r as excluded, t as doNothing } from "./on-conflict-hfPW0KmQ.mjs";
|
|
4
4
|
//#region src/dialects/sqlite.ts
|
|
5
5
|
function renderSqliteSchemaLiteral(value) {
|
|
6
6
|
if (value === null) return "NULL";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as standardJson, o as createDialect } from "./json-
|
|
1
|
+
import { i as standardJson, o as createDialect } from "./json-Db7XRD91.mjs";
|
|
2
2
|
//#region src/dialects/standard.ts
|
|
3
3
|
/** SQL:2008-style rendering defaults used by the core builder. */
|
|
4
4
|
function standardDialect() {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { r as exposeColumns, t as createSource } from "./source-DGO3DRgg.mjs";
|
|
1
|
+
import { I as materializeSchemaObjectRecord, J as parenthesize, L as resolveSqlNames, i as identifier, it as resultValueOf, nt as resultShapeValue, t as createColumnReference, u as columnResultValue } from "./column-hqKr7-1I.mjs";
|
|
2
|
+
import { r as exposeColumns, t as createSource } from "./source-BcS2AsIg.mjs";
|
|
4
3
|
//#region src/schema/alias.ts
|
|
5
4
|
function alias(sourceOrQuery, name) {
|
|
6
5
|
const input = sourceOrQuery;
|