qubu 0.6.0 → 0.6.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/README.md +112 -0
- package/dist/{complete-DP7pliuY.mjs → canonical-B5_ouh-c.mjs} +466 -241
- package/dist/codegen.d.mts +2 -2
- package/dist/codegen.mjs +180 -90
- package/dist/column-Cyc2CMnG.mjs +116 -0
- package/dist/column-DDRvD7SF.mjs +721 -0
- package/dist/{constraints-YGyNPQ_z.mjs → constraints-CAmi18Uk.mjs} +8 -3
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +4 -5
- package/dist/diagnostics-I9vVtXkc.mjs +40 -0
- package/dist/diff.d.mts +9 -9
- package/dist/diff.mjs +152 -102
- package/dist/{explain-CkIK13L_.mjs → explain-BIqEmZha.mjs} +1 -1
- package/dist/expressions-_6JF_J77.mjs +130 -0
- package/dist/index-CaxrMD1A.d.mts +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +414 -77
- package/dist/introspection/mysql.d.mts +26 -0
- package/dist/introspection/mysql.mjs +1278 -0
- package/dist/introspection/postgres.d.mts +43 -0
- package/dist/introspection/postgres.mjs +1889 -0
- package/dist/introspection/sqlite.d.mts +15 -0
- package/dist/introspection/sqlite.mjs +1172 -0
- package/dist/introspection.d.mts +26 -87
- package/dist/introspection.mjs +3 -4351
- package/dist/mysql.d.mts +3 -3
- package/dist/mysql.mjs +8 -7
- package/dist/{errors-Dxv73YJu.mjs → omit-VEr9Ydux.mjs} +5 -1
- package/dist/{on-conflict-DZQ85f1t.mjs → on-conflict-B2rFyHGF.mjs} +78 -8
- package/dist/on-duplicate-key-update-Czsw1Yq-.mjs +95 -0
- package/dist/postgres-hFhd0I9n.mjs +68 -0
- package/dist/postgres.d.mts +3 -3
- package/dist/postgres.mjs +3 -52
- package/dist/registry-BXE_4M9P.mjs +127 -0
- package/dist/{relational-CxnLCqZQ.mjs → relational-CoPBETjI.mjs} +3 -3
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +8 -7
- package/dist/{serialize-BN07IK0v.mjs → serialize-CyobNEx-.mjs} +174 -30
- package/dist/serialize-Du2UPZMt.d.mts +92 -0
- package/dist/snapshot/mysql.d.mts +5 -5
- package/dist/snapshot/mysql.mjs +32 -32
- package/dist/snapshot/postgres.d.mts +5 -5
- package/dist/snapshot/postgres.mjs +25 -25
- package/dist/snapshot/sqlite.d.mts +5 -5
- package/dist/snapshot/sqlite.mjs +30 -30
- package/dist/snapshot-mIb-Zzb5.mjs +1489 -0
- package/dist/snapshot.d.mts +4 -5
- package/dist/snapshot.mjs +3 -4
- package/dist/{source-SqrKWjFJ.mjs → source-DYSUqzvb.mjs} +2 -2
- package/dist/sqlite.d.mts +2 -2
- package/dist/sqlite.mjs +10 -10
- package/dist/{table-BwflqeAj.mjs → table-B8zEq0az.mjs} +4 -4
- package/dist/{types-BIJsj2fJ.mjs → types-CYHpSPwj.mjs} +10 -7
- package/dist/{types-CTCqtFlS.d.mts → types-CiMvKi5V.d.mts} +14 -4
- package/dist/{types-C0VkiwpR.d.mts → types-Dqr4o2I1.d.mts} +640 -189
- package/dist/value-CpaUFtjw.mjs +45 -0
- package/dist/vite/ambient.d.ts +2 -0
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +2 -0
- package/docs/dialects-and-execution.md +61 -11
- package/docs/getting-started.md +1 -1
- package/docs/guides/compose-queries.md +22 -0
- package/docs/guides/drizzle.md +11 -11
- package/docs/guides/extensions/typed-expressions.md +5 -3
- package/docs/guides/json.md +95 -2
- package/docs/guides/mutations.md +125 -0
- package/docs/guides/valtio-sync.md +113 -0
- package/docs/index.md +1 -1
- package/docs/migrations/adapters.md +58 -21
- package/docs/migrations/index.md +50 -12
- package/docs/migrations/operations.md +20 -6
- package/docs/migrations/recovery.md +7 -1
- package/docs/query-model/fragments.md +21 -1
- package/docs/reference/introspection-support.md +16 -18
- package/docs/reference/supported-surface.md +23 -11
- package/docs/schema/catalog-model.md +20 -7
- package/docs/schema/code-generation.md +4 -3
- package/docs/schema/diff.md +2 -2
- package/docs/schema/introspection.md +24 -16
- package/docs/schema/snapshots.md +18 -8
- package/docs/schema/storage-and-schema-sql.md +7 -2
- package/docs/sql-semantic-types.md +8 -0
- package/package.json +14 -1
- package/dist/canonical-DMvR9yBe.mjs +0 -972
- package/dist/column-Da37jYSD.mjs +0 -309
- package/dist/column-r1Y4ivwt.mjs +0 -327
- package/dist/complete-types-CY0KbzNw.d.mts +0 -371
- package/dist/index-B2rZf3-2.d.mts +0 -32
- package/dist/json-Db7XRD91.mjs +0 -169
- package/dist/omit-OxV58AwX.mjs +0 -5
- package/dist/registry-BRcUuazJ.mjs +0 -256
- package/dist/serialize-CEIIlWhC.d.mts +0 -66
- package/dist/snapshot-Xam8-q0j.mjs +0 -392
- package/dist/standard-DfcZEVOj.mjs +0 -12
- package/dist/value-D14I_XgL.mjs +0 -29
package/dist/snapshot/mysql.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-
|
|
3
|
-
import {
|
|
1
|
+
import { r as isColumnReference, v as isValidSchemaObjectName } from "../column-DDRvD7SF.mjs";
|
|
2
|
+
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-CAmi18Uk.mjs";
|
|
3
|
+
import { a as renderSchemaExpression, r as isUnsafeSchemaSql } from "../expressions-_6JF_J77.mjs";
|
|
4
4
|
import { t as createSchemaDialect } from "../dialect-wUKrnPMB.mjs";
|
|
5
|
-
import { a as toSnapshotJsonValue } from "../canonical-
|
|
6
|
-
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-
|
|
5
|
+
import { a as toSnapshotJsonValue } from "../canonical-B5_ouh-c.mjs";
|
|
6
|
+
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-CyobNEx-.mjs";
|
|
7
7
|
import { mysqlDialect } from "../mysql.mjs";
|
|
8
8
|
//#region src/snapshot/mysql.ts
|
|
9
|
-
/** MySQL's
|
|
9
|
+
/** MySQL's snapshot dialect-extension identity. */
|
|
10
10
|
const mysqlSnapshotDialect = Object.freeze({
|
|
11
11
|
name: "mysql",
|
|
12
12
|
version: 1
|
|
@@ -29,15 +29,15 @@ const mysqlStorageTypes = Object.freeze({
|
|
|
29
29
|
/** MySQL's query dialect plus its schema metadata behavior. */
|
|
30
30
|
const mysqlSchemaDialect = createSchemaDialect(mysqlDialect(), {
|
|
31
31
|
version: 1,
|
|
32
|
-
validate:
|
|
32
|
+
validate: validateSchema,
|
|
33
33
|
encodeStorage(storage, context) {
|
|
34
|
-
return
|
|
34
|
+
return encodeStorage(storage, context.dialect);
|
|
35
35
|
},
|
|
36
36
|
encodeExpression(expression, context) {
|
|
37
|
-
return
|
|
37
|
+
return encodeExpression(expression, context.mode, context.dialect);
|
|
38
38
|
},
|
|
39
39
|
encodeDialectExtension(extension, context) {
|
|
40
|
-
return
|
|
40
|
+
return encodeExtension(extension, context.dialect);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
@@ -56,7 +56,7 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
56
56
|
adapter: mysqlSnapshotAdapter
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function encodeStorage(storage, dialect) {
|
|
60
60
|
if (storage.kind === "native") {
|
|
61
61
|
if (storage.dialect !== dialect.name) throw new MysqlSnapshotDialectError(`MySQL storage cannot encode a native declaration owned by "${storage.dialect}"`);
|
|
62
62
|
if (storage.type.trim().length === 0) throw new TypeError("MySQL native storage declarations cannot be empty");
|
|
@@ -74,7 +74,7 @@ function encodeMysqlStorage(storage, dialect) {
|
|
|
74
74
|
type
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function encodeExpression(expression, mode, dialect) {
|
|
78
78
|
if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new MysqlSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the MySQL schema dialect is "${dialect.name}"`);
|
|
79
79
|
const rendered = renderSchemaExpression(expression, {
|
|
80
80
|
mode,
|
|
@@ -88,7 +88,7 @@ function encodeMysqlExpression(expression, mode, dialect) {
|
|
|
88
88
|
...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function encodeExtension(extension, dialect) {
|
|
92
92
|
if (extension.dialect !== dialect.name) throw new MysqlSnapshotDialectError(`MySQL schema extensions require dialect "${dialect.name}"`);
|
|
93
93
|
const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
|
|
94
94
|
return {
|
|
@@ -102,20 +102,20 @@ function sortSnapshotJson(value) {
|
|
|
102
102
|
if (typeof value !== "object" || value === null) return value;
|
|
103
103
|
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function validateSchema(schema, context) {
|
|
106
106
|
const diagnostics = [];
|
|
107
107
|
const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
|
|
108
108
|
const relationNames = /* @__PURE__ */ new Map();
|
|
109
|
-
if (schema.namespace !== void 0)
|
|
109
|
+
if (schema.namespace !== void 0) validateName(schema.namespace, ["namespace"], "MySQL database/schema", diagnostics);
|
|
110
110
|
for (const [id, entry] of tableEntries) {
|
|
111
111
|
const tablePath = ["tables", id];
|
|
112
|
-
|
|
112
|
+
validateName(entry.physicalName, [...tablePath, "physicalName"], "MySQL table", diagnostics);
|
|
113
113
|
addScopedName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
|
|
114
114
|
}
|
|
115
|
-
for (const [id, entry] of tableEntries)
|
|
115
|
+
for (const [id, entry] of tableEntries) validateTable(id, entry, context, diagnostics);
|
|
116
116
|
return Object.freeze(diagnostics);
|
|
117
117
|
}
|
|
118
|
-
function
|
|
118
|
+
function validateTable(tableId, entry, context, diagnostics) {
|
|
119
119
|
const table = entry.table;
|
|
120
120
|
const tablePath = ["tables", tableId];
|
|
121
121
|
const definitions = table.definitions;
|
|
@@ -126,7 +126,7 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
126
126
|
"columns",
|
|
127
127
|
columnId
|
|
128
128
|
];
|
|
129
|
-
|
|
129
|
+
validateName(table.sqlNames[columnId] ?? columnId, [...columnPath, "physicalName"], "MySQL column", diagnostics);
|
|
130
130
|
if (definition.onUpdate !== void 0 && definition.generatedColumn) diagnostics.push({
|
|
131
131
|
code: "unsupported-dialect-option",
|
|
132
132
|
message: "MySQL generated columns cannot also declare ON UPDATE",
|
|
@@ -144,7 +144,7 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
144
144
|
"autoIncrement"
|
|
145
145
|
]
|
|
146
146
|
});
|
|
147
|
-
if (autoIncrement === true)
|
|
147
|
+
if (autoIncrement === true) validateAutoIncrement(columnId, definition, metadata, columnPath, diagnostics);
|
|
148
148
|
}
|
|
149
149
|
const constraintNames = /* @__PURE__ */ new Map();
|
|
150
150
|
const constraints = Object.entries(metadata.constraints);
|
|
@@ -155,12 +155,12 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
155
155
|
constraintId
|
|
156
156
|
];
|
|
157
157
|
const physicalName = constraint.physicalName ?? constraintId;
|
|
158
|
-
|
|
158
|
+
validateName(physicalName, [...constraintPath, "physicalName"], "MySQL constraint", diagnostics);
|
|
159
159
|
addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
|
|
160
160
|
appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
|
|
161
161
|
if (constraint.kind === "foreign-key" && (constraint.match === "full" || constraint.match === "partial")) diagnostics.push({
|
|
162
162
|
code: "unsupported-dialect-option",
|
|
163
|
-
message: "MySQL
|
|
163
|
+
message: "MySQL snapshots support MATCH SIMPLE foreign keys only",
|
|
164
164
|
path: [...constraintPath, "match"]
|
|
165
165
|
});
|
|
166
166
|
if (constraint.kind === "foreign-key" && (constraint.onUpdate === "set-default" || constraint.onDelete === "set-default")) diagnostics.push({
|
|
@@ -170,7 +170,7 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
170
170
|
});
|
|
171
171
|
if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
|
|
172
172
|
code: "unsupported-dialect-option",
|
|
173
|
-
message: "MySQL ordinary UNIQUE constraints use distinct NULL semantics
|
|
173
|
+
message: "MySQL ordinary UNIQUE constraints use distinct NULL semantics",
|
|
174
174
|
path: [...constraintPath, "nulls"]
|
|
175
175
|
});
|
|
176
176
|
if (constraint.dialect?.dialect === mysqlSnapshotDialect.name && "enforced" in constraint.dialect && constraint.dialect.enforced !== void 0 && typeof constraint.dialect.enforced !== "boolean") diagnostics.push({
|
|
@@ -192,7 +192,7 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
192
192
|
indexId
|
|
193
193
|
];
|
|
194
194
|
const physicalName = index.physicalName ?? indexId;
|
|
195
|
-
|
|
195
|
+
validateName(physicalName, [...indexPath, "physicalName"], "MySQL index", diagnostics);
|
|
196
196
|
addScopedName(tableIndexNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
|
|
197
197
|
appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
|
|
198
198
|
if (index.predicate !== void 0) diagnostics.push({
|
|
@@ -265,7 +265,7 @@ function validateMysqlTable(tableId, entry, context, diagnostics) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
function
|
|
268
|
+
function validateAutoIncrement(columnId, definition, metadata, columnPath, diagnostics) {
|
|
269
269
|
if (definition.nullable) diagnostics.push({
|
|
270
270
|
code: "unsupported-dialect-option",
|
|
271
271
|
message: "MySQL AUTO_INCREMENT columns must be non-nullable",
|
|
@@ -276,13 +276,13 @@ function validateMysqlAutoIncrement(columnId, definition, metadata, columnPath,
|
|
|
276
276
|
message: "MySQL AUTO_INCREMENT columns cannot be generated columns",
|
|
277
277
|
path: [...columnPath, "generatedColumn"]
|
|
278
278
|
});
|
|
279
|
-
const declaration =
|
|
280
|
-
if (declaration === void 0 || !
|
|
279
|
+
const declaration = declarationFor(definition.storage);
|
|
280
|
+
if (declaration === void 0 || !isIntegerDeclaration(declaration)) diagnostics.push({
|
|
281
281
|
code: "unsupported-dialect-option",
|
|
282
282
|
message: "MySQL AUTO_INCREMENT requires an integer-family physical storage declaration",
|
|
283
283
|
path: [...columnPath, "storage"]
|
|
284
284
|
});
|
|
285
|
-
if (!
|
|
285
|
+
if (!hasAutoIncrementKey(columnId, metadata)) diagnostics.push({
|
|
286
286
|
code: "unsupported-dialect-option",
|
|
287
287
|
message: "MySQL AUTO_INCREMENT columns must be the first column of a primary, unique, or ordinary index key",
|
|
288
288
|
path: [
|
|
@@ -293,15 +293,15 @@ function validateMysqlAutoIncrement(columnId, definition, metadata, columnPath,
|
|
|
293
293
|
]
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
|
-
function
|
|
296
|
+
function declarationFor(storage) {
|
|
297
297
|
if (storage === void 0) return;
|
|
298
298
|
return storage.kind === "native" ? storage.type : mysqlStorageTypes[storage.type];
|
|
299
299
|
}
|
|
300
|
-
function
|
|
300
|
+
function isIntegerDeclaration(declaration) {
|
|
301
301
|
const base = declaration.trim().toUpperCase().split(/\s+/u)[0] ?? "";
|
|
302
302
|
return /^(?:TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)(?:\(\d+\))?$/u.test(base);
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function hasAutoIncrementKey(columnId, metadata) {
|
|
305
305
|
for (const constraint of Object.values(metadata.constraints)) if ((constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint") && isColumnReference(constraint.columns[0]) && constraint.columns[0].fieldName === columnId) return true;
|
|
306
306
|
for (const index of Object.values(metadata.indexes)) {
|
|
307
307
|
const first = index.terms[0];
|
|
@@ -310,7 +310,7 @@ function hasMysqlAutoIncrementKey(columnId, metadata) {
|
|
|
310
310
|
}
|
|
311
311
|
return false;
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function validateName(name, path, kind, diagnostics) {
|
|
314
314
|
if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
|
|
315
315
|
code: "invalid-schema",
|
|
316
316
|
message: `${kind} name "${name}" is not a valid unqualified identifier`,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as SchemaSnapshotOptions } from "../serialize-
|
|
1
|
+
import { Yi as Schema, ji as SchemaDialect, l as SnapshotCreateResult, m as SnapshotDialect, n as SchemaSnapshot, r as SchemaSnapshotAdapter } from "../types-Dqr4o2I1.mjs";
|
|
2
|
+
import { t as SchemaSnapshotOptions } from "../serialize-Du2UPZMt.mjs";
|
|
3
3
|
//#region src/snapshot/postgres.d.ts
|
|
4
|
-
/** PostgreSQL's
|
|
4
|
+
/** PostgreSQL's snapshot dialect-extension identity. */
|
|
5
5
|
declare const postgresSnapshotDialect: SnapshotDialect;
|
|
6
6
|
/** PostgreSQL's query dialect plus its schema metadata behavior. */
|
|
7
|
-
declare const postgresSchemaDialect: SchemaDialect<"ilike" | "json" | "on-conflict" | "row-locking">;
|
|
7
|
+
declare const postgresSchemaDialect: SchemaDialect<"ilike" | "json" | "on-conflict" | "row-locking" | "update-from">;
|
|
8
8
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
9
|
-
declare const postgresSnapshotAdapter: SchemaSnapshotAdapter<"ilike" | "json" | "on-conflict" | "row-locking">;
|
|
9
|
+
declare const postgresSnapshotAdapter: SchemaSnapshotAdapter<"ilike" | "json" | "on-conflict" | "row-locking" | "update-from">;
|
|
10
10
|
/** Create a canonical PostgreSQL schema snapshot. */
|
|
11
11
|
declare function createSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: PostgresSnapshotOptions): SchemaSnapshot;
|
|
12
12
|
/** Return PostgreSQL capability diagnostics without throwing. */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-
|
|
3
|
-
import {
|
|
1
|
+
import { v as isValidSchemaObjectName } from "../column-DDRvD7SF.mjs";
|
|
2
|
+
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-CAmi18Uk.mjs";
|
|
3
|
+
import { a as renderSchemaExpression, r as isUnsafeSchemaSql } from "../expressions-_6JF_J77.mjs";
|
|
4
4
|
import { t as createSchemaDialect } from "../dialect-wUKrnPMB.mjs";
|
|
5
|
-
import { a as toSnapshotJsonValue } from "../canonical-
|
|
6
|
-
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-
|
|
7
|
-
import { postgresDialect } from "../postgres.mjs";
|
|
5
|
+
import { a as toSnapshotJsonValue } from "../canonical-B5_ouh-c.mjs";
|
|
6
|
+
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-CyobNEx-.mjs";
|
|
7
|
+
import { n as postgresDialect } from "../postgres-hFhd0I9n.mjs";
|
|
8
8
|
//#region src/snapshot/postgres.ts
|
|
9
|
-
/** PostgreSQL's
|
|
9
|
+
/** PostgreSQL's snapshot dialect-extension identity. */
|
|
10
10
|
const postgresSnapshotDialect = Object.freeze({
|
|
11
11
|
name: "postgresql",
|
|
12
12
|
version: 1
|
|
@@ -29,15 +29,15 @@ const postgresStorageTypes = Object.freeze({
|
|
|
29
29
|
/** PostgreSQL's query dialect plus its schema metadata behavior. */
|
|
30
30
|
const postgresSchemaDialect = createSchemaDialect(postgresDialect(), {
|
|
31
31
|
version: 1,
|
|
32
|
-
validate:
|
|
32
|
+
validate: validateSchema,
|
|
33
33
|
encodeStorage(storage, context) {
|
|
34
|
-
return
|
|
34
|
+
return encodeStorage(storage, context.dialect);
|
|
35
35
|
},
|
|
36
36
|
encodeExpression(expression, context) {
|
|
37
|
-
return
|
|
37
|
+
return encodeExpression(expression, context.mode, context.dialect);
|
|
38
38
|
},
|
|
39
39
|
encodeDialectExtension(extension, context) {
|
|
40
|
-
return
|
|
40
|
+
return encodeExtension(extension, context.dialect);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
@@ -56,7 +56,7 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
56
56
|
adapter: postgresSnapshotAdapter
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function encodeStorage(storage, dialect) {
|
|
60
60
|
if (storage.kind === "native") {
|
|
61
61
|
if (storage.dialect !== dialect.name) throw new TypeError(`PostgreSQL storage cannot encode a native declaration owned by "${storage.dialect}"`);
|
|
62
62
|
if (storage.type.trim().length === 0) throw new TypeError("PostgreSQL native storage declarations cannot be empty");
|
|
@@ -74,7 +74,7 @@ function encodePostgresStorage(storage, dialect) {
|
|
|
74
74
|
type
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function encodeExpression(expression, mode, dialect) {
|
|
78
78
|
if (isUnsafeSchemaSql(expression) && expression.schemaSqlDialect !== dialect.name) throw new PostgresSnapshotDialectError(`Schema SQL is tagged for "${expression.schemaSqlDialect}" but the PostgreSQL schema dialect is "${dialect.name}"`);
|
|
79
79
|
const rendered = renderSchemaExpression(expression, {
|
|
80
80
|
mode,
|
|
@@ -88,7 +88,7 @@ function encodePostgresExpression(expression, mode, dialect) {
|
|
|
88
88
|
...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function encodeExtension(extension, dialect) {
|
|
92
92
|
if (extension.dialect !== dialect.name) throw new TypeError(`PostgreSQL schema extensions require dialect "${dialect.name}"`);
|
|
93
93
|
const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
|
|
94
94
|
return {
|
|
@@ -102,25 +102,25 @@ function sortSnapshotJson(value) {
|
|
|
102
102
|
if (typeof value !== "object" || value === null) return value;
|
|
103
103
|
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function validateSchema(schema, context) {
|
|
106
106
|
const diagnostics = [];
|
|
107
107
|
const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
|
|
108
108
|
const relationNames = /* @__PURE__ */ new Map();
|
|
109
|
-
if (schema.namespace !== void 0)
|
|
109
|
+
if (schema.namespace !== void 0) validateName(schema.namespace, ["namespace"], "PostgreSQL namespace", diagnostics);
|
|
110
110
|
for (const [id, entry] of tableEntries) {
|
|
111
111
|
const tablePath = ["tables", id];
|
|
112
|
-
|
|
112
|
+
validateName(entry.physicalName, [...tablePath, "physicalName"], "PostgreSQL table", diagnostics);
|
|
113
113
|
addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
|
|
114
114
|
}
|
|
115
|
-
for (const [id, entry] of tableEntries)
|
|
115
|
+
for (const [id, entry] of tableEntries) validateTable(id, entry, context, relationNames, diagnostics);
|
|
116
116
|
return Object.freeze(diagnostics);
|
|
117
117
|
}
|
|
118
|
-
function
|
|
118
|
+
function validateTable(tableId, entry, context, relationNames, diagnostics) {
|
|
119
119
|
const table = entry.table;
|
|
120
120
|
const tablePath = ["tables", tableId];
|
|
121
121
|
const definitions = table.definitions;
|
|
122
122
|
for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
|
|
123
|
-
|
|
123
|
+
validateName(table.sqlNames[columnId] ?? columnId, [
|
|
124
124
|
...tablePath,
|
|
125
125
|
"columns",
|
|
126
126
|
columnId,
|
|
@@ -139,7 +139,7 @@ function validatePostgresTable(tableId, entry, context, relationNames, diagnosti
|
|
|
139
139
|
const generated = definition.generatedColumn;
|
|
140
140
|
if (generated !== void 0 && generated.kind === "expression" && generated.mode === "virtual") diagnostics.push({
|
|
141
141
|
code: "unsupported-dialect-option",
|
|
142
|
-
message: "PostgreSQL
|
|
142
|
+
message: "PostgreSQL snapshots support stored generated columns only; virtual generated columns are not supported",
|
|
143
143
|
path: [
|
|
144
144
|
...tablePath,
|
|
145
145
|
"columns",
|
|
@@ -159,7 +159,7 @@ function validatePostgresTable(tableId, entry, context, relationNames, diagnosti
|
|
|
159
159
|
constraintId
|
|
160
160
|
];
|
|
161
161
|
const physicalName = constraint.physicalName ?? constraintId;
|
|
162
|
-
|
|
162
|
+
validateName(physicalName, [...constraintPath, "physicalName"], "PostgreSQL constraint", diagnostics);
|
|
163
163
|
addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
|
|
164
164
|
appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
|
|
165
165
|
if (constraint.kind === "check" && constraint.deferrable === true) diagnostics.push({
|
|
@@ -174,7 +174,7 @@ function validatePostgresTable(tableId, entry, context, relationNames, diagnosti
|
|
|
174
174
|
});
|
|
175
175
|
if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
|
|
176
176
|
code: "unsupported-dialect-option",
|
|
177
|
-
message: "PostgreSQL NULLS NOT DISTINCT requires a server-version policy; the
|
|
177
|
+
message: "PostgreSQL NULLS NOT DISTINCT requires a server-version policy; the adapter does not assume PostgreSQL 15 or newer",
|
|
178
178
|
path: [...constraintPath, "nulls"]
|
|
179
179
|
});
|
|
180
180
|
}
|
|
@@ -186,12 +186,12 @@ function validatePostgresTable(tableId, entry, context, relationNames, diagnosti
|
|
|
186
186
|
indexId
|
|
187
187
|
];
|
|
188
188
|
const physicalName = index.physicalName ?? indexId;
|
|
189
|
-
|
|
189
|
+
validateName(physicalName, [...indexPath, "physicalName"], "PostgreSQL index", diagnostics);
|
|
190
190
|
addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
|
|
191
191
|
appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function validateName(name, path, kind, diagnostics) {
|
|
195
195
|
if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
|
|
196
196
|
code: "invalid-schema",
|
|
197
197
|
message: `${kind} name "${name}" is not a valid unqualified identifier`,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as SchemaSnapshotOptions } from "../serialize-
|
|
1
|
+
import { Yi as Schema, ji as SchemaDialect, l as SnapshotCreateResult, m as SnapshotDialect, n as SchemaSnapshot, r as SchemaSnapshotAdapter } from "../types-Dqr4o2I1.mjs";
|
|
2
|
+
import { t as SchemaSnapshotOptions } from "../serialize-Du2UPZMt.mjs";
|
|
3
3
|
//#region src/snapshot/sqlite.d.ts
|
|
4
|
-
/** SQLite's
|
|
4
|
+
/** SQLite's snapshot dialect-extension identity. */
|
|
5
5
|
declare const sqliteSnapshotDialect: SnapshotDialect;
|
|
6
6
|
/** SQLite's five declared-type affinity categories. */
|
|
7
7
|
type SqliteStorageAffinity = "blob" | "integer" | "numeric" | "real" | "text";
|
|
@@ -10,7 +10,7 @@ type SqliteStorageAffinity = "blob" | "integer" | "numeric" | "real" | "text";
|
|
|
10
10
|
* ordered substring rules at table creation time; the returned affinity is useful metadata, not a
|
|
11
11
|
* replacement for the exact type.
|
|
12
12
|
*/
|
|
13
|
-
declare function
|
|
13
|
+
declare function storageAffinity(declaration: string): SqliteStorageAffinity;
|
|
14
14
|
/** SQLite's query dialect plus its schema metadata behavior. */
|
|
15
15
|
declare const sqliteSchemaDialect: SchemaDialect<"json" | "on-conflict">;
|
|
16
16
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
@@ -22,4 +22,4 @@ declare function tryCreateSchemaSnapshot<TSchema extends Schema<any>>(schema: TS
|
|
|
22
22
|
/** Options accepted by the SQLite snapshot convenience functions. */
|
|
23
23
|
type SqliteSnapshotOptions = Omit<SchemaSnapshotOptions, "adapter" | "dialect">;
|
|
24
24
|
//#endregion
|
|
25
|
-
export { SqliteSnapshotOptions, SqliteStorageAffinity, createSchemaSnapshot, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect,
|
|
25
|
+
export { SqliteSnapshotOptions, SqliteStorageAffinity, createSchemaSnapshot, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect, storageAffinity, tryCreateSchemaSnapshot };
|
package/dist/snapshot/sqlite.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-
|
|
3
|
-
import {
|
|
1
|
+
import { r as isColumnReference, v as isValidSchemaObjectName } from "../column-DDRvD7SF.mjs";
|
|
2
|
+
import { d as validateIndexDialect, l as validateConstraintDialect } from "../constraints-CAmi18Uk.mjs";
|
|
3
|
+
import { a as renderSchemaExpression, r as isUnsafeSchemaSql } from "../expressions-_6JF_J77.mjs";
|
|
4
4
|
import { t as createSchemaDialect } from "../dialect-wUKrnPMB.mjs";
|
|
5
|
-
import { a as toSnapshotJsonValue } from "../canonical-
|
|
5
|
+
import { a as toSnapshotJsonValue } from "../canonical-B5_ouh-c.mjs";
|
|
6
|
+
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-CyobNEx-.mjs";
|
|
6
7
|
import { sqliteDialect } from "../sqlite.mjs";
|
|
7
|
-
import { n as createSchemaSnapshot$1, s as tryCreateSchemaSnapshot$1 } from "../serialize-BN07IK0v.mjs";
|
|
8
8
|
//#region src/snapshot/sqlite.ts
|
|
9
|
-
/** SQLite's
|
|
9
|
+
/** SQLite's snapshot dialect-extension identity. */
|
|
10
10
|
const sqliteSnapshotDialect = Object.freeze({
|
|
11
11
|
name: "sqlite",
|
|
12
12
|
version: 1
|
|
@@ -31,7 +31,7 @@ const sqliteStorageTypes = Object.freeze({
|
|
|
31
31
|
* ordered substring rules at table creation time; the returned affinity is useful metadata, not a
|
|
32
32
|
* replacement for the exact type.
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
34
|
+
function storageAffinity(declaration) {
|
|
35
35
|
const upper = declaration.toUpperCase();
|
|
36
36
|
if (upper.includes("INT")) return "integer";
|
|
37
37
|
if (upper.includes("CHAR") || upper.includes("CLOB") || upper.includes("TEXT")) return "text";
|
|
@@ -42,15 +42,15 @@ function sqliteStorageAffinity(declaration) {
|
|
|
42
42
|
/** SQLite's query dialect plus its schema metadata behavior. */
|
|
43
43
|
const sqliteSchemaDialect = createSchemaDialect(sqliteDialect(), {
|
|
44
44
|
version: 1,
|
|
45
|
-
validate:
|
|
45
|
+
validate: validateSchema,
|
|
46
46
|
encodeStorage(storage, context) {
|
|
47
|
-
return
|
|
47
|
+
return encodeStorage(storage, context.dialect);
|
|
48
48
|
},
|
|
49
49
|
encodeExpression(expression, context) {
|
|
50
|
-
return
|
|
50
|
+
return encodeExpression(expression, context.mode, context.dialect);
|
|
51
51
|
},
|
|
52
52
|
encodeDialectExtension(extension, context) {
|
|
53
|
-
return
|
|
53
|
+
return encodeExtension(extension, context.dialect);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
@@ -69,7 +69,7 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
69
69
|
adapter: sqliteSnapshotAdapter
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function encodeStorage(storage, dialect) {
|
|
73
73
|
if (storage.kind === "native") {
|
|
74
74
|
if (storage.dialect !== dialect.name) throw new SqliteSnapshotDialectError(`SQLite storage cannot encode a native declaration owned by "${storage.dialect}"`);
|
|
75
75
|
if (storage.type.trim().length === 0) throw new TypeError("SQLite native storage declarations cannot be empty");
|
|
@@ -77,7 +77,7 @@ function encodeSqliteStorage(storage, dialect) {
|
|
|
77
77
|
kind: "native",
|
|
78
78
|
dialect: dialect.name,
|
|
79
79
|
type: storage.type,
|
|
80
|
-
affinity:
|
|
80
|
+
affinity: storageAffinity(storage.type)
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
const type = sqliteStorageTypes[storage.type];
|
|
@@ -86,10 +86,10 @@ function encodeSqliteStorage(storage, dialect) {
|
|
|
86
86
|
kind: "native",
|
|
87
87
|
dialect: dialect.name,
|
|
88
88
|
type,
|
|
89
|
-
affinity:
|
|
89
|
+
affinity: storageAffinity(type)
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function encodeExpression(expression, mode, dialect) {
|
|
93
93
|
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}"`);
|
|
94
94
|
const rendered = renderSchemaExpression(expression, {
|
|
95
95
|
mode,
|
|
@@ -103,7 +103,7 @@ function encodeSqliteExpression(expression, mode, dialect) {
|
|
|
103
103
|
...isUnsafeSchemaSql(expression) ? { dialect: dialect.name } : {}
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
function
|
|
106
|
+
function encodeExtension(extension, dialect) {
|
|
107
107
|
if (extension.dialect !== dialect.name) throw new TypeError(`SQLite schema extensions require dialect "${dialect.name}"`);
|
|
108
108
|
const data = Object.fromEntries(Object.entries(extension).filter(([key]) => key !== "dialect").sort(([left], [right]) => left.localeCompare(right)));
|
|
109
109
|
return {
|
|
@@ -117,26 +117,26 @@ function sortSnapshotJson(value) {
|
|
|
117
117
|
if (typeof value !== "object" || value === null) return value;
|
|
118
118
|
return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, child]) => [key, sortSnapshotJson(child)]));
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function validateSchema(schema, context) {
|
|
121
121
|
const diagnostics = [];
|
|
122
122
|
const tableEntries = Object.entries(schema.registry).sort(([left], [right]) => compareIds(left, right));
|
|
123
123
|
const relationNames = /* @__PURE__ */ new Map();
|
|
124
|
-
if (schema.namespace !== void 0)
|
|
124
|
+
if (schema.namespace !== void 0) validateName(schema.namespace, ["namespace"], "SQLite namespace", diagnostics);
|
|
125
125
|
for (const [id, entry] of tableEntries) {
|
|
126
126
|
const tablePath = ["tables", id];
|
|
127
|
-
|
|
127
|
+
validateName(entry.physicalName, [...tablePath, "physicalName"], "SQLite table", diagnostics);
|
|
128
128
|
addRelationName(relationNames, entry.physicalName, [...tablePath, "physicalName"], "table", diagnostics);
|
|
129
129
|
}
|
|
130
|
-
for (const [id, entry] of tableEntries)
|
|
130
|
+
for (const [id, entry] of tableEntries) validateTable(id, entry, context, relationNames, diagnostics);
|
|
131
131
|
return Object.freeze(diagnostics);
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function validateTable(tableId, entry, context, relationNames, diagnostics) {
|
|
134
134
|
const table = entry.table;
|
|
135
135
|
const tablePath = ["tables", tableId];
|
|
136
136
|
const definitions = table.definitions;
|
|
137
137
|
const metadata = table;
|
|
138
138
|
for (const [columnId, definition] of Object.entries(definitions).sort(([left], [right]) => compareIds(left, right))) {
|
|
139
|
-
|
|
139
|
+
validateName(table.sqlNames[columnId] ?? columnId, [
|
|
140
140
|
...tablePath,
|
|
141
141
|
"columns",
|
|
142
142
|
columnId,
|
|
@@ -172,8 +172,8 @@ function validateSqliteTable(tableId, entry, context, relationNames, diagnostics
|
|
|
172
172
|
]
|
|
173
173
|
});
|
|
174
174
|
const primary = primaryKeyForColumn(metadata.constraints, columnId);
|
|
175
|
-
const declaration =
|
|
176
|
-
if ((declaration === void 0 ? void 0 :
|
|
175
|
+
const declaration = declarationFor(storage);
|
|
176
|
+
if ((declaration === void 0 ? void 0 : storageAffinity(declaration)) !== "integer") diagnostics.push({
|
|
177
177
|
code: "unsupported-dialect-option",
|
|
178
178
|
message: "SQLite identity columns must use INTEGER affinity so they can be rowid aliases",
|
|
179
179
|
path: [...identityPath, "generation"]
|
|
@@ -213,7 +213,7 @@ function validateSqliteTable(tableId, entry, context, relationNames, diagnostics
|
|
|
213
213
|
constraintId
|
|
214
214
|
];
|
|
215
215
|
const physicalName = constraint.physicalName ?? constraintId;
|
|
216
|
-
|
|
216
|
+
validateName(physicalName, [...constraintPath, "physicalName"], "SQLite constraint", diagnostics);
|
|
217
217
|
addScopedName(constraintNames, physicalName, [...constraintPath, "physicalName"], "constraint", diagnostics);
|
|
218
218
|
appendMetadataDiagnostics(diagnostics, validateConstraintDialect(constraint, context.dialect.name, constraintPath));
|
|
219
219
|
if ((constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint" || constraint.kind === "check") && (constraint.deferrable === true || constraint.initially !== void 0)) diagnostics.push({
|
|
@@ -228,7 +228,7 @@ function validateSqliteTable(tableId, entry, context, relationNames, diagnostics
|
|
|
228
228
|
});
|
|
229
229
|
if (constraint.kind === "unique-constraint" && constraint.nulls === "not-distinct") diagnostics.push({
|
|
230
230
|
code: "unsupported-dialect-option",
|
|
231
|
-
message: "SQLite UNIQUE constraints always use distinct NULL semantics
|
|
231
|
+
message: "SQLite UNIQUE constraints always use distinct NULL semantics",
|
|
232
232
|
path: [...constraintPath, "nulls"]
|
|
233
233
|
});
|
|
234
234
|
if (constraint.dialect?.dialect === "sqlite" && "onConflict" in constraint.dialect && constraint.dialect.onConflict !== void 0 && ![
|
|
@@ -255,7 +255,7 @@ function validateSqliteTable(tableId, entry, context, relationNames, diagnostics
|
|
|
255
255
|
indexId
|
|
256
256
|
];
|
|
257
257
|
const physicalName = index.physicalName ?? indexId;
|
|
258
|
-
|
|
258
|
+
validateName(physicalName, [...indexPath, "physicalName"], "SQLite index", diagnostics);
|
|
259
259
|
addRelationName(relationNames, physicalName, [...indexPath, "physicalName"], "index", diagnostics);
|
|
260
260
|
appendMetadataDiagnostics(diagnostics, validateIndexDialect(index, context.dialect.name, indexPath));
|
|
261
261
|
if (index.dialect?.dialect === "sqlite" && "auto" in index.dialect && index.dialect.auto !== void 0 && typeof index.dialect.auto !== "boolean") diagnostics.push({
|
|
@@ -269,7 +269,7 @@ function validateSqliteTable(tableId, entry, context, relationNames, diagnostics
|
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
|
-
function
|
|
272
|
+
function declarationFor(storage) {
|
|
273
273
|
if (storage === void 0) return;
|
|
274
274
|
if (storage.kind === "native") return storage.type;
|
|
275
275
|
return sqliteStorageTypes[storage.type];
|
|
@@ -280,7 +280,7 @@ function primaryKeyForColumn(constraints, columnId) {
|
|
|
280
280
|
if (constraint.columns.some((column) => isColumnReference(column) && column.fieldName === columnId)) return constraint.columns;
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
function
|
|
283
|
+
function validateName(name, path, kind, diagnostics) {
|
|
284
284
|
if (!isValidSchemaObjectName(name) || name.length === 0) diagnostics.push({
|
|
285
285
|
code: "invalid-schema",
|
|
286
286
|
message: `${kind} name "${name}" is not a valid unqualified identifier`,
|
|
@@ -318,4 +318,4 @@ function compareIds(left, right) {
|
|
|
318
318
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
319
319
|
}
|
|
320
320
|
//#endregion
|
|
321
|
-
export { createSchemaSnapshot, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect,
|
|
321
|
+
export { createSchemaSnapshot, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect, storageAffinity, tryCreateSchemaSnapshot };
|