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.
Files changed (103) hide show
  1. package/dist/{canonical-BbnqavJm.mjs → canonical-BXUguqfo.mjs} +23 -23
  2. package/dist/codegen.d.mts +25 -33
  3. package/dist/codegen.mjs +38 -45
  4. package/dist/column-hqKr7-1I.mjs +620 -0
  5. package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
  6. package/dist/{complete-types-BavBtv8J.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
  7. package/dist/core.d.mts +2 -2
  8. package/dist/core.mjs +4 -4
  9. package/dist/ddl.d.mts +12 -12
  10. package/dist/ddl.mjs +13 -14
  11. package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
  12. package/dist/diff.d.mts +1 -1
  13. package/dist/diff.mjs +6 -7
  14. package/dist/{index-DH0qV6aS.d.mts → index-1DpA3mUh.d.mts} +20 -20
  15. package/dist/{index-D3ZOwPT-.d.mts → index-CPvfEheG.d.mts} +13 -15
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +94 -95
  18. package/dist/introspection.d.mts +8 -8
  19. package/dist/introspection.mjs +29 -30
  20. package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
  21. package/dist/migration.d.mts +20 -21
  22. package/dist/migration.mjs +5 -6
  23. package/dist/{mysql-CKEKGnj4.mjs → mysql-B_cYzzX2.mjs} +237 -7
  24. package/dist/mysql.d.mts +2 -2
  25. package/dist/mysql.mjs +3 -3
  26. package/dist/{on-conflict-4MOBl51J.mjs → on-conflict-hfPW0KmQ.mjs} +3 -4
  27. package/dist/postgres.d.mts +5 -5
  28. package/dist/postgres.mjs +6 -6
  29. package/dist/{registry-CXV8u7Pt.mjs → registry-BRMLYwDp.mjs} +26 -29
  30. package/dist/{relational-DuQ9IHSb.mjs → relational-BZ3WDPzC.mjs} +2 -2
  31. package/dist/schema.d.mts +1 -1
  32. package/dist/schema.mjs +5 -6
  33. package/dist/{snapshot-DJpfmxhQ.mjs → snapshot-C-W65HEd.mjs} +5 -5
  34. package/dist/snapshot.d.mts +3 -3
  35. package/dist/snapshot.mjs +5 -7
  36. package/dist/{source-DGO3DRgg.mjs → source-BcS2AsIg.mjs} +6 -8
  37. package/dist/{serialize-CFtYYAdk.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
  38. package/dist/sqlite.d.mts +1 -1
  39. package/dist/sqlite.mjs +2 -2
  40. package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
  41. package/dist/{table-D6rcs8SB.mjs → table-Bp5irMSj.mjs} +2 -3
  42. package/dist/{types-Deo_q43Y.d.mts → types-BK1COGZe.d.mts} +1113 -1128
  43. package/dist/{types-g-vVvj1B.mjs → types-JM3FcAnX.mjs} +7 -8
  44. package/dist/{types-CSNJTYaM.d.mts → types-JSZHpUEj.d.mts} +83 -84
  45. package/dist/{value-b6OFZXVS.mjs → value-Bi71Agyf.mjs} +1 -1
  46. package/dist/vite/ambient.d.ts +309 -340
  47. package/dist/vite.d.mts +5 -6
  48. package/dist/vite.mjs +3 -4
  49. package/docs/dialects-and-execution.md +45 -55
  50. package/docs/getting-started.md +4 -4
  51. package/docs/guides/better-auth.md +57 -0
  52. package/docs/guides/compose-queries.md +24 -67
  53. package/docs/guides/drizzle.md +23 -23
  54. package/docs/guides/extensions/dialects.md +4 -4
  55. package/docs/guides/extensions/sources-and-clauses.md +15 -15
  56. package/docs/guides/extensions/typed-expressions.md +13 -17
  57. package/docs/guides/extensions/unsafe-syntax.md +3 -3
  58. package/docs/guides/json.md +7 -7
  59. package/docs/guides/mutations.md +14 -21
  60. package/docs/guides/select/conditions.md +6 -8
  61. package/docs/guides/select/grouping-and-windows.md +4 -15
  62. package/docs/guides/select/ordering-and-pagination.md +6 -19
  63. package/docs/guides/select/overview.md +12 -26
  64. package/docs/guides/sql-templates.md +20 -24
  65. package/docs/guides/vite-plugin.md +9 -13
  66. package/docs/index.md +5 -7
  67. package/docs/query-model/fragments.md +4 -15
  68. package/docs/query-model/result-shapes.md +11 -14
  69. package/docs/query-model/source-scope.md +31 -49
  70. package/docs/reference/mysql-snapshot.md +2 -5
  71. package/docs/reference/postgres-snapshot.md +3 -3
  72. package/docs/reference/sqlite-snapshot.md +2 -5
  73. package/docs/reference/supported-surface.md +26 -26
  74. package/docs/schema/catalog-model.md +2 -5
  75. package/docs/schema/code-generation.md +18 -18
  76. package/docs/schema/columns-and-writes.md +17 -25
  77. package/docs/schema/constraints-and-indexes.md +36 -52
  78. package/docs/schema/ddl-emission.md +6 -6
  79. package/docs/schema/diff.md +5 -5
  80. package/docs/schema/introspection.md +7 -7
  81. package/docs/schema/migration-plans.md +9 -9
  82. package/docs/schema/snapshots.md +3 -3
  83. package/docs/schema/storage-and-schema-sql.md +11 -11
  84. package/docs/schema/tables-and-names.md +11 -14
  85. package/docs/sql-semantic-types.md +10 -10
  86. package/docs/troubleshooting.md +10 -10
  87. package/package.json +21 -33
  88. package/skills/qubu/agents/openai.yaml +3 -3
  89. package/dist/column-D-8OqGuV.mjs +0 -328
  90. package/dist/column-LV7oGQde.mjs +0 -296
  91. package/dist/drizzle-mysql.d.mts +0 -24
  92. package/dist/drizzle-mysql.mjs +0 -72
  93. package/dist/drizzle-postgres.d.mts +0 -24
  94. package/dist/drizzle-postgres.mjs +0 -73
  95. package/dist/drizzle-sqlite.d.mts +0 -57
  96. package/dist/drizzle-sqlite.mjs +0 -108
  97. package/dist/drizzle.d.mts +0 -13
  98. package/dist/drizzle.mjs +0 -2
  99. package/dist/errors-BGCoLe_r.mjs +0 -14
  100. package/dist/postgres-BK2APkKP.mjs +0 -236
  101. package/dist/runtime-Cn_Xgzta.mjs +0 -193
  102. package/dist/sqlite-CrsK0Fza.mjs +0 -320
  103. package/dist/types-DZsueVoI.d.mts +0 -45
@@ -1,193 +0,0 @@
1
- import { t as DrizzleSchemaConversionError } from "./errors-BGCoLe_r.mjs";
2
- import { getTableColumns, sql } from "drizzle-orm";
3
- //#region src/drizzle/runtime.ts
4
- /** Build Drizzle tables using one dialect adapter supplied by a leaf entrypoint. */
5
- function convertDrizzleSchema(schema, adapter) {
6
- const snapshot = adapter.createSnapshot(schema);
7
- assertRepresentableMetadata(snapshot, adapter.dialect);
8
- const tables = {};
9
- const tableFactory = adapter.createTableFactory(schema.namespace);
10
- const snapshotTables = new Map(snapshot.tables.map((table) => [table.id, table]));
11
- for (const [tableId, entry] of Object.entries(schema.registry)) {
12
- const snapshotTable = snapshotTables.get(tableId);
13
- if (snapshotTable === void 0) continue;
14
- const columns = createColumns(entry.table, snapshotTable, adapter);
15
- tables[snapshotTable.id] = tableFactory(snapshotTable.physicalName, columns, (drizzleColumns) => createExtraConfig(snapshotTable, drizzleColumns, tables, adapter));
16
- }
17
- return Object.freeze({ ...tables });
18
- }
19
- function createColumns(table, snapshotTable, adapter) {
20
- const definitions = table.definitions;
21
- const snapshotColumns = new Map(snapshotTable.columns.map((column) => [column.id, column]));
22
- return Object.fromEntries(Object.entries(definitions).map(([columnId, definition]) => {
23
- const snapshotColumn = snapshotColumns.get(columnId);
24
- if (snapshotColumn === void 0) throw new DrizzleSchemaConversionError("missing-storage", `Qubu column "${snapshotTable.id}.${columnId}" has no snapshot definition`, [
25
- "tables",
26
- snapshotTable.id,
27
- "columns",
28
- columnId
29
- ]);
30
- return [snapshotColumn.id, createColumnBuilder(definition, snapshotColumn, snapshotTable, adapter)];
31
- }));
32
- }
33
- function createColumnBuilder(definition, column, table, adapter) {
34
- const declaration = column.storage?.type;
35
- if (declaration === void 0) throw new DrizzleSchemaConversionError("missing-storage", `Qubu column "${table.id}.${column.id}" needs physical storage before it can become a Drizzle column`, [
36
- "tables",
37
- table.id,
38
- "columns",
39
- column.id,
40
- "storage"
41
- ]);
42
- const portableType = definition.storage?.kind === "portable" ? definition.storage.type : void 0;
43
- let builder = adapter.createStorageBuilder(portableType, column.physicalName, declaration, definition);
44
- if (!column.nullable) builder = builder.notNull();
45
- if (column.default?.kind === "literal") builder = builder.default(decodeSnapshotLiteral(column.default.value));
46
- else if (column.default?.kind === "expression") builder = builder.default(sql.raw(column.default.expression.sql));
47
- if (column.generatedColumn?.kind === "expression") builder = builder.generatedAlwaysAs(sql.raw(column.generatedColumn.expression.sql), { mode: column.generatedColumn.mode });
48
- if (column.onUpdate !== void 0) builder = builder.$onUpdateFn(() => sql.raw(column.onUpdate?.sql ?? ""));
49
- if (column.identity !== void 0) builder = adapter.applyIdentity(builder, definition, column, table);
50
- return builder;
51
- }
52
- function decodeSnapshotLiteral(value) {
53
- switch (value.kind) {
54
- case "null": return null;
55
- case "boolean":
56
- case "string": return value.value;
57
- case "number": return Number(value.value);
58
- case "bigint": return BigInt(value.value);
59
- }
60
- }
61
- function createExtraConfig(table, columns, tables, adapter) {
62
- return [...table.constraints.flatMap((constraint) => createConstraint(constraint, columns, tables, adapter)), ...table.indexes.map((index) => createIndex(index, columns, adapter))];
63
- }
64
- function createConstraint(constraint, columns, tables, adapter) {
65
- const localColumns = constraint.kind === "check" ? [] : constraint.columns.map((column) => columns[column]);
66
- if (constraint.kind !== "check" && localColumns.some((value) => !value)) throw unsupportedMetadata(`Drizzle could not resolve every column in constraint "${constraint.id}"`, [
67
- "constraints",
68
- constraint.id,
69
- "columns"
70
- ]);
71
- if (constraint.kind === "primary-key") {
72
- if (adapter.dialect === "sqlite" && localColumns.length === 1 && localColumns[0]?.primary === true) return [];
73
- return [adapter.createPrimaryKey(constraint.physicalName, localColumns)];
74
- }
75
- if (constraint.kind === "unique" || constraint.kind === "unique-constraint") return [adapter.createUniqueConstraint(constraint.physicalName, localColumns, constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct")];
76
- if (constraint.kind === "check") return [adapter.createCheck(constraint.physicalName, sql.raw(constraint.expression.sql))];
77
- if (constraint.kind !== "foreign-key") throw unsupportedMetadata(`Drizzle cannot represent constraint kind "${constraint.kind}"`, [
78
- "constraints",
79
- constraint.id,
80
- "kind"
81
- ]);
82
- const foreignTable = tables[constraint.target.table];
83
- const foreignColumns = foreignTable ? constraint.target.columns.map((column) => getTableColumns(foreignTable)[column]) : [];
84
- if (foreignColumns.length !== constraint.target.columns.length || foreignColumns.some((value) => !value)) throw unsupportedMetadata(`Drizzle could not resolve the target of foreign key "${constraint.id}"`, [
85
- "constraints",
86
- constraint.id,
87
- "target"
88
- ]);
89
- let builder = adapter.createForeignKey(constraint.physicalName, localColumns, foreignColumns);
90
- if (constraint.onUpdate) builder = builder.onUpdate(toDrizzleAction(constraint.onUpdate));
91
- if (constraint.onDelete) builder = builder.onDelete(toDrizzleAction(constraint.onDelete));
92
- return [builder];
93
- }
94
- function createIndex(index, columns, adapter) {
95
- const terms = index.terms.map((term) => createIndexTerm(term, columns));
96
- const predicate = index.predicate ? sql.raw(index.predicate.sql) : void 0;
97
- return adapter.createIndex(index, terms, predicate);
98
- }
99
- function createIndexTerm(term, columns) {
100
- if (term.kind !== "order") return createIndexTermExpression(term, columns);
101
- const expression = createIndexTermExpression(term.expression, columns);
102
- const suffix = [term.direction, term.nulls && `NULLS ${term.nulls}`].filter((value) => value !== void 0).join(" ");
103
- return suffix.length === 0 ? expression : sql`${expression} ${sql.raw(suffix)}`;
104
- }
105
- function createIndexTermExpression(term, columns) {
106
- if (term.kind === "expression") return sql.raw(term.expression.sql);
107
- const column = columns[term.column];
108
- if (column === void 0) throw unsupportedMetadata(`Drizzle could not resolve index column "${term.column}"`, [
109
- "indexes",
110
- "terms",
111
- term.column
112
- ]);
113
- return column;
114
- }
115
- function toDrizzleAction(action) {
116
- return action.replace("-", " ");
117
- }
118
- function assertRepresentableMetadata(snapshot, dialect) {
119
- for (const table of snapshot.tables) {
120
- for (const constraint of table.constraints) {
121
- const path = [
122
- "tables",
123
- table.id,
124
- "constraints",
125
- constraint.id
126
- ];
127
- if (constraint.deferrable === true || constraint.initially !== void 0) throw unsupportedMetadata(`Drizzle cannot represent deferred constraint "${constraint.id}"`, path);
128
- if (constraint.kind === "foreign-key" && constraint.match !== void 0 && constraint.match !== "simple") throw unsupportedMetadata(`Drizzle cannot represent MATCH ${constraint.match.toUpperCase()} on foreign key "${constraint.id}"`, [...path, "match"]);
129
- assertConstraintExtension(constraint.dialect, dialect, path);
130
- }
131
- for (const index of table.indexes) {
132
- const path = [
133
- "tables",
134
- table.id,
135
- "indexes",
136
- index.id
137
- ];
138
- if (index.includedColumns && index.includedColumns.length > 0) throw unsupportedMetadata(`Drizzle ${dialect} indexes cannot represent included columns`, [...path, "includedColumns"]);
139
- assertIndexExtension(index.dialect, dialect, path);
140
- }
141
- }
142
- }
143
- function assertConstraintExtension(extension, dialect, path) {
144
- const data = extensionData(extension);
145
- const unsupported = Object.entries(data).find(([key, value]) => {
146
- if (value === void 0) return false;
147
- if (dialect === "postgresql" && key === "notValid") return value === true;
148
- if (dialect === "mysql" && key === "enforced") return value === false;
149
- if (dialect === "sqlite" && key === "onConflict") return true;
150
- if (value === false) return false;
151
- return true;
152
- });
153
- if (unsupported) throw unsupportedMetadata(`Drizzle cannot represent constraint option "${unsupported[0]}"`, [
154
- ...path,
155
- "dialect",
156
- unsupported[0]
157
- ]);
158
- }
159
- function assertIndexExtension(extension, dialect, path) {
160
- const data = extensionData(extension);
161
- const supported = dialect === "postgresql" ? /* @__PURE__ */ new Set([
162
- "method",
163
- "concurrently",
164
- "storageParameters"
165
- ]) : dialect === "mysql" ? /* @__PURE__ */ new Set([
166
- "using",
167
- "algorithm",
168
- "lock"
169
- ]) : /* @__PURE__ */ new Set();
170
- const unsupported = Object.entries(data).find(([key, value]) => value !== void 0 && value !== false && !supported.has(key));
171
- if (unsupported) throw unsupportedMetadata(`Drizzle cannot represent index option "${unsupported[0]}"`, [
172
- ...path,
173
- "dialect",
174
- unsupported[0]
175
- ]);
176
- }
177
- function extensionData(extension) {
178
- const data = extension?.data;
179
- return data !== null && typeof data === "object" && !Array.isArray(data) ? data : {};
180
- }
181
- function stringExtension(data, key) {
182
- const value = data[key];
183
- return typeof value === "string" ? value : void 0;
184
- }
185
- function recordExtension(data, key) {
186
- const value = data[key];
187
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
188
- }
189
- function unsupportedMetadata(message, path) {
190
- return new DrizzleSchemaConversionError("unsupported-metadata", message, path);
191
- }
192
- //#endregion
193
- export { stringExtension as i, extensionData as n, recordExtension as r, convertDrizzleSchema as t };
@@ -1,320 +0,0 @@
1
- import { d as isValidSchemaObjectName, r as isColumnReference } from "./column-D-8OqGuV.mjs";
2
- import { _ as isUnsafeSchemaSql, m as validateConstraintDialect, w as validateIndexDialect, y as renderSchemaExpression } from "./registry-CXV8u7Pt.mjs";
3
- import { t as createSchemaDialect } from "./dialect-b2-Z6uBF.mjs";
4
- import { a as toSnapshotJsonValue } from "./canonical-BbnqavJm.mjs";
5
- import { sqliteDialect } from "./sqlite.mjs";
6
- import { n as createSchemaSnapshot, s as tryCreateSchemaSnapshot } from "./serialize-CFtYYAdk.mjs";
7
- //#region src/snapshot/sqlite.ts
8
- /** SQLite's v1 snapshot extension identity. */
9
- const sqliteSnapshotDialect = Object.freeze({
10
- name: "sqlite",
11
- version: 1
12
- });
13
- var SqliteSnapshotDialectError = class extends TypeError {
14
- code = "dialect-mismatch";
15
- };
16
- const sqliteStorageTypes = Object.freeze({
17
- integer: "INTEGER",
18
- numeric: "NUMERIC",
19
- text: "TEXT",
20
- boolean: "INTEGER",
21
- date: "TEXT",
22
- timestamp: "TEXT",
23
- uuid: "TEXT",
24
- json: "TEXT",
25
- bigint: "INTEGER",
26
- binary: "BLOB"
27
- });
28
- /**
29
- * Resolve SQLite's declared-type affinity without changing the declaration.
30
- * SQLite applies these ordered substring rules at table creation time; the
31
- * returned affinity is useful metadata, not a replacement for the exact type.
32
- */
33
- function sqliteStorageAffinity(declaration) {
34
- const upper = declaration.toUpperCase();
35
- if (upper.includes("INT")) return "integer";
36
- if (upper.includes("CHAR") || upper.includes("CLOB") || upper.includes("TEXT")) return "text";
37
- if (upper.includes("BLOB") || upper.trim().length === 0) return "blob";
38
- if (upper.includes("REAL") || upper.includes("FLOA") || upper.includes("DOUB")) return "real";
39
- return "numeric";
40
- }
41
- /** SQLite's query dialect plus its schema metadata behavior. */
42
- const sqliteSchemaDialect = createSchemaDialect(sqliteDialect(), {
43
- version: 1,
44
- validate: validateSqliteSchema,
45
- encodeStorage(storage, context) {
46
- return encodeSqliteStorage(storage, context.dialect);
47
- },
48
- encodeExpression(expression, context) {
49
- return encodeSqliteExpression(expression, context.mode, context.dialect);
50
- },
51
- encodeDialectExtension(extension, context) {
52
- return encodeSqliteExtension(extension, context.dialect);
53
- }
54
- });
55
- /** Snapshot adapter retaining the historical adapter-shaped entry point. */
56
- const sqliteSnapshotAdapter = Object.freeze({ dialect: sqliteSchemaDialect });
57
- /** Create a canonical SQLite schema snapshot. */
58
- function createSqliteSchemaSnapshot(schema, options = {}) {
59
- return createSchemaSnapshot(schema, {
60
- ...options,
61
- adapter: sqliteSnapshotAdapter
62
- });
63
- }
64
- /** Return SQLite capability diagnostics without throwing. */
65
- function tryCreateSqliteSchemaSnapshot(schema, options = {}) {
66
- return tryCreateSchemaSnapshot(schema, {
67
- ...options,
68
- adapter: sqliteSnapshotAdapter
69
- });
70
- }
71
- function encodeSqliteStorage(storage, dialect) {
72
- if (storage.kind === "native") {
73
- if (storage.dialect !== dialect.name) throw new SqliteSnapshotDialectError(`SQLite storage cannot encode a native declaration owned by "${storage.dialect}"`);
74
- if (storage.type.trim().length === 0) throw new TypeError("SQLite native storage declarations cannot be empty");
75
- return {
76
- kind: "native",
77
- dialect: dialect.name,
78
- type: storage.type,
79
- affinity: sqliteStorageAffinity(storage.type)
80
- };
81
- }
82
- const type = sqliteStorageTypes[storage.type];
83
- if (type === void 0) throw new TypeError(`Unsupported portable storage type for SQLite: ${String(storage.type)}`);
84
- return {
85
- kind: "native",
86
- dialect: dialect.name,
87
- type,
88
- affinity: sqliteStorageAffinity(type)
89
- };
90
- }
91
- function encodeSqliteExpression(expression, mode, dialect) {
92
- 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}"`);
93
- const rendered = renderSchemaExpression(expression, {
94
- mode,
95
- dialect
96
- });
97
- if (rendered.parameters.length !== 0) throw new TypeError("SQLite schema expressions must be parameter-free");
98
- return {
99
- kind: "expression",
100
- expressionKind: expression.expressionKind,
101
- sql: rendered.text,
102
- ...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
103
- };
104
- }
105
- function encodeSqliteExtension(extension, dialect) {
106
- if (extension.dialect !== dialect.name) throw new TypeError(`SQLite schema extensions require dialect "${dialect.name}"`);
107
- const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
108
- return {
109
- dialect: dialect.name,
110
- version: dialect.schema.version,
111
- data: sortSnapshotJson(toSnapshotJsonValue(data))
112
- };
113
- }
114
- function sortSnapshotJson(value) {
115
- if (Array.isArray(value)) return value.map(sortSnapshotJson);
116
- if (typeof value !== "object" || value === null) return value;
117
- return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
118
- }
119
- function validateSqliteSchema(schema, context) {
120
- const diagnostics = [];
121
- const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
122
- const relationNames = /* @__PURE__ */ new Map();
123
- if (schema.namespace !== void 0) validateSqliteName(schema.namespace, ["namespace"], "SQLite namespace", diagnostics);
124
- for (const [id, entry] of tableEntries) {
125
- const tablePath = ["tables", id];
126
- validateSqliteName(entry.physicalName, [...tablePath, "physicalName"], "SQLite table", diagnostics);
127
- addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
128
- }
129
- for (const [id, entry] of tableEntries) validateSqliteTable(id, entry, context, relationNames, diagnostics);
130
- return Object.freeze(diagnostics);
131
- }
132
- function validateSqliteTable(tableId, entry, context, relationNames, diagnostics) {
133
- const table = entry.table;
134
- const tablePath = ["tables", tableId];
135
- const definitions = table.definitions;
136
- const metadata = table;
137
- for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
138
- validateSqliteName(table.sqlNames[columnId] ?? columnId, [
139
- ...tablePath,
140
- "columns",
141
- columnId,
142
- "physicalName"
143
- ], "SQLite column", diagnostics);
144
- if (definition.onUpdate !== void 0) diagnostics.push({
145
- code: "unsupported-dialect-option",
146
- message: "MySQL ON UPDATE expressions are not supported by SQLite",
147
- path: [
148
- ...tablePath,
149
- "columns",
150
- columnId,
151
- "onUpdate"
152
- ]
153
- });
154
- const storage = definition.storage;
155
- const identity = definition.identity;
156
- if (identity !== void 0) {
157
- const identityPath = [
158
- ...tablePath,
159
- "columns",
160
- columnId,
161
- "identity"
162
- ];
163
- const extension = identity.dialect;
164
- if (extension !== void 0 && extension.dialect === "sqlite" && extension.autoIncrement !== void 0 && typeof extension.autoIncrement !== "boolean") diagnostics.push({
165
- code: "unsupported-dialect-option",
166
- message: "SQLite identity autoIncrement must be boolean",
167
- path: [
168
- ...identityPath,
169
- "dialect",
170
- "autoIncrement"
171
- ]
172
- });
173
- const primary = primaryKeyForColumn(metadata.constraints, columnId);
174
- const declaration = sqliteDeclaration(storage);
175
- if ((declaration === void 0 ? void 0 : sqliteStorageAffinity(declaration)) !== "integer") diagnostics.push({
176
- code: "unsupported-dialect-option",
177
- message: "SQLite identity columns must use INTEGER affinity so they can be rowid aliases",
178
- path: [...identityPath, "generation"]
179
- });
180
- if (primary === void 0 || primary.length !== 1) diagnostics.push({
181
- code: "unsupported-dialect-option",
182
- message: "SQLite identity columns must be the sole column of a PRIMARY KEY constraint",
183
- path: [...identityPath, "generation"]
184
- });
185
- if (extension?.dialect === "sqlite" && extension.autoIncrement === true && declaration?.trim().toUpperCase() !== "INTEGER") diagnostics.push({
186
- code: "unsupported-dialect-option",
187
- message: "SQLite AUTOINCREMENT requires an exact INTEGER PRIMARY KEY declaration",
188
- path: [
189
- ...identityPath,
190
- "dialect",
191
- "autoIncrement"
192
- ]
193
- });
194
- }
195
- if (definition.generatedColumn?.kind === "expression" && primaryKeyForColumn(metadata.constraints, columnId) !== void 0) diagnostics.push({
196
- code: "unsupported-dialect-option",
197
- message: "SQLite generated columns cannot be part of a PRIMARY KEY",
198
- path: [
199
- ...tablePath,
200
- "columns",
201
- columnId,
202
- "generatedColumn"
203
- ]
204
- });
205
- }
206
- const constraintNames = /* @__PURE__ */ new Map();
207
- const constraints = Object.entries(metadata.constraints);
208
- for (const [constraintId, constraint] of constraints.sort(([left], [right]) => compareIds(left, right))) {
209
- const constraintPath = [
210
- ...tablePath,
211
- "constraints",
212
- constraintId
213
- ];
214
- const physicalName = constraint.physicalName ?? constraintId;
215
- validateSqliteName(physicalName, [...constraintPath, "physicalName"], "SQLite constraint", diagnostics);
216
- addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
217
- appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
218
- if ((constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint" || constraint.kind === "check") && (constraint.deferrable === true || constraint.initially !== void 0)) diagnostics.push({
219
- code: "unsupported-dialect-option",
220
- message: "SQLite only supports DEFERRABLE timing on foreign-key constraints",
221
- path: [...constraintPath, constraint.deferrable ? "deferrable" : "initially"]
222
- });
223
- if (constraint.kind === "foreign-key" && constraint.match !== void 0 && constraint.match !== "simple") diagnostics.push({
224
- code: "unsupported-dialect-option",
225
- message: "SQLite supports MATCH SIMPLE foreign keys only",
226
- path: [...constraintPath, "match"]
227
- });
228
- if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
229
- code: "unsupported-dialect-option",
230
- message: "SQLite UNIQUE constraints always use distinct NULL semantics in v1",
231
- path: [...constraintPath, "nulls"]
232
- });
233
- if (constraint.dialect?.dialect === "sqlite" && "onConflict" in constraint.dialect && constraint.dialect.onConflict !== void 0 && ![
234
- "rollback",
235
- "abort",
236
- "fail",
237
- "ignore",
238
- "replace"
239
- ].includes(String(constraint.dialect.onConflict))) diagnostics.push({
240
- code: "unsupported-dialect-option",
241
- message: "SQLite constraint onConflict has an unsupported value",
242
- path: [
243
- ...constraintPath,
244
- "dialect",
245
- "onConflict"
246
- ]
247
- });
248
- }
249
- const indexes = Object.entries(metadata.indexes);
250
- for (const [indexId, index] of indexes.sort(([left], [right]) => compareIds(left, right))) {
251
- const indexPath = [
252
- ...tablePath,
253
- "indexes",
254
- indexId
255
- ];
256
- const physicalName = index.physicalName ?? indexId;
257
- validateSqliteName(physicalName, [...indexPath, "physicalName"], "SQLite index", diagnostics);
258
- addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
259
- appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
260
- if (index.dialect?.dialect === "sqlite" && "auto" in index.dialect && index.dialect.auto !== void 0 && typeof index.dialect.auto !== "boolean") diagnostics.push({
261
- code: "unsupported-dialect-option",
262
- message: "SQLite index auto must be boolean",
263
- path: [
264
- ...indexPath,
265
- "dialect",
266
- "auto"
267
- ]
268
- });
269
- }
270
- }
271
- function sqliteDeclaration(storage) {
272
- if (storage === void 0) return void 0;
273
- if (storage.kind === "native") return storage.type;
274
- return sqliteStorageTypes[storage.type];
275
- }
276
- function primaryKeyForColumn(constraints, columnId) {
277
- for (const constraint of Object.values(constraints)) {
278
- if (constraint.kind !== "primary-key") continue;
279
- if (constraint.columns.some((column) => isColumnReference(column) && column.fieldName === columnId)) return constraint.columns;
280
- }
281
- }
282
- function validateSqliteName(name, path, kind, diagnostics) {
283
- if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
284
- code: "invalid-schema",
285
- message: `${kind} name "${name}" is not a valid unqualified identifier`,
286
- path
287
- });
288
- }
289
- function addRelationName(names, name, path, kind, diagnostics) {
290
- addScopedName(names, name, path, kind, diagnostics);
291
- }
292
- function addScopedName(names, name, path, kind, diagnostics) {
293
- const previousPath = names.get(name);
294
- if (previousPath !== void 0) {
295
- diagnostics.push({
296
- code: "invalid-schema",
297
- message: `SQLite ${kind} name "${name}" collides with another table or index`,
298
- path,
299
- relatedPaths: [previousPath]
300
- });
301
- return;
302
- }
303
- names.set(name, path);
304
- }
305
- function appendMetadataDiagnostics(diagnostics, issues) {
306
- for (const issue of issues) {
307
- if (issue.code === "dialect-mismatch") continue;
308
- diagnostics.push({
309
- code: issue.code === "unsupported-dialect-option" ? "unsupported-dialect-option" : "invalid-schema",
310
- message: issue.message,
311
- path: issue.path,
312
- ...issue.relatedPaths === void 0 ? {} : { relatedPaths: issue.relatedPaths }
313
- });
314
- }
315
- }
316
- function compareIds(left, right) {
317
- return left < right ? -1 : left > right ? 1 : 0;
318
- }
319
- //#endregion
320
- export { sqliteStorageAffinity as a, sqliteSnapshotDialect as i, sqliteSchemaDialect as n, tryCreateSqliteSchemaSnapshot as o, sqliteSnapshotAdapter as r, createSqliteSchemaSnapshot as t };
@@ -1,45 +0,0 @@
1
- import { As as ColumnInsertInput, Fs as ColumnOutput, Gs as ColumnUpdateInput, Hs as ColumnStorageOf, Os as ColumnHasDefault, Xs as PortableColumnStorage, js as ColumnIsGenerated, ks as ColumnIdentityOf, oi as SchemaTableRecord, qs as NativeColumnStorage } from "./types-Deo_q43Y.mjs";
2
- //#region src/drizzle/types.d.ts
3
- /** SQL engines supported by the Qubu-to-Drizzle runtime adapter. */
4
- type DrizzleDialect = 'postgresql' | 'mysql' | 'sqlite';
5
- type IsAny<T> = 0 extends 1 & T ? true : false;
6
- type SameType<TLeft, TRight> = IsAny<TLeft> extends true ? true : IsAny<TRight> extends true ? true : (<T>() => T extends TLeft ? 1 : 2) extends (<T>() => T extends TRight ? 1 : 2) ? (<T>() => T extends TRight ? 1 : 2) extends (<T>() => T extends TLeft ? 1 : 2) ? true : false : false;
7
- type HasCompatibleValueTypes<TDefinition> = SameType<ColumnOutput<TDefinition>, ColumnInsertInput<TDefinition>> extends true ? SameType<ColumnOutput<TDefinition>, ColumnUpdateInput<TDefinition>> : false;
8
- type HasCompatibleStorage<TDefinition, TDialect extends DrizzleDialect> = ColumnStorageOf<TDefinition> extends (infer TStorage) ? TStorage extends PortableColumnStorage ? true : TStorage extends NativeColumnStorage<infer TStorageDialect, string> ? TDialect extends TStorageDialect ? true : false : false : false;
9
- type InvalidValueTypeColumns<TTables extends SchemaTableRecord> = { [TTableKey in keyof TTables & string]: { [TColumnKey in keyof TTables[TTableKey]['definitions'] & string]: HasCompatibleValueTypes<TTables[TTableKey]['definitions'][TColumnKey]> extends true ? never : `${TTableKey}.${TColumnKey}`; }[keyof TTables[TTableKey]['definitions'] & string]; }[keyof TTables & string];
10
- type InvalidStorageColumns<TTables extends SchemaTableRecord, TDialect extends DrizzleDialect> = { [TTableKey in keyof TTables & string]: { [TColumnKey in keyof TTables[TTableKey]['definitions'] & string]: HasCompatibleStorage<TTables[TTableKey]['definitions'][TColumnKey], TDialect> extends true ? never : `${TTableKey}.${TColumnKey}`; }[keyof TTables[TTableKey]['definitions'] & string]; }[keyof TTables & string];
11
- type DrizzleSchemaValidation<TTables extends SchemaTableRecord, TDialect extends DrizzleDialect> = ([InvalidValueTypeColumns<TTables>] extends [never] ? unknown : {
12
- readonly __drizzle_requires_one_value_type__: InvalidValueTypeColumns<TTables>;
13
- }) & ([InvalidStorageColumns<TTables, TDialect>] extends [never] ? unknown : {
14
- readonly __drizzle_requires_compatible_storage__: InvalidStorageColumns<TTables, TDialect>;
15
- });
16
- type DrizzleColumnIdentity<TDefinition> = ColumnIdentityOf<TDefinition> extends {
17
- readonly generation: infer TGeneration;
18
- } ? TGeneration extends 'always' ? 'always' : TGeneration extends 'by-default' ? 'byDefault' : undefined : undefined;
19
- type DrizzleColumnGenerated<TDefinition> = ColumnIsGenerated<TDefinition> extends true ? {
20
- readonly as: ColumnOutput<TDefinition>;
21
- readonly type: 'always';
22
- } : undefined;
23
- type DrizzleColumnHasDefault<TDefinition> = ColumnIsGenerated<TDefinition> extends true ? true : ColumnHasDefault<TDefinition>;
24
- type DrizzleColumnConfig<TTableName extends string, TDefinition> = {
25
- readonly name: string;
26
- readonly tableName: TTableName;
27
- readonly dataType: 'custom';
28
- readonly data: ColumnOutput<TDefinition>;
29
- readonly driverParam: ColumnInsertInput<TDefinition>;
30
- readonly enumValues: undefined;
31
- /**
32
- * Qubu makes nullable columns required on insert unless they have a default.
33
- * Keeping this flag true and carrying null in `data` preserves that rule in
34
- * Drizzle's single-axis column model.
35
- */
36
- readonly notNull: true;
37
- readonly hasDefault: DrizzleColumnHasDefault<TDefinition>;
38
- readonly isPrimaryKey: false;
39
- readonly isAutoincrement: false;
40
- readonly hasRuntimeDefault: false;
41
- readonly identity: DrizzleColumnIdentity<TDefinition>;
42
- readonly generated: DrizzleColumnGenerated<TDefinition>;
43
- };
44
- //#endregion
45
- export { DrizzleDialect as n, DrizzleSchemaValidation as r, DrizzleColumnConfig as t };