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/schema.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import {
|
|
3
|
-
import { i as sourceIdentity, n as customSource, r as exposeColumns, t as createSource } from "./source-
|
|
4
|
-
import { n as alias, r as lateral, t as table } from "./table-
|
|
5
|
-
import { a as primaryKey, c as uniqueConstraint, d as validateIndexDialect, i as foreignKey, l as validateConstraintDialect, n as catalogForeignKey, o as references, r as check, s as unique, t as catalogCheck, u as index } from "./constraints-
|
|
6
|
-
import { a as
|
|
1
|
+
import { _ as generatedSchemaObjectName, b as materializeSchemaObjectRecord, c as externalDefault, d as identityColumn, f as resolveColumnBehavior, g as freezeSchemaMetadata, h as dialectMismatchDiagnostic, l as externalGeneratedColumn, m as assertSchemaDialectSupport, o as ColumnBehaviorError, p as SchemaMetadataValidationError, s as canonicalLiteral, u as generatedColumn, v as isValidSchemaObjectName, y as materializeSchemaObjectIdentity } from "./column-DDRvD7SF.mjs";
|
|
2
|
+
import { _ as timestamp, a as columnResultValue, c as encodeColumnParameter, d as nativeColumn, f as nativeStorage, g as text, h as portableStorage, i as column, l as integer, m as numeric, n as binary, o as columnSqlType, p as nullable, r as boolean, s as date, t as bigint, u as json, v as uuid } from "./column-Cyc2CMnG.mjs";
|
|
3
|
+
import { i as sourceIdentity, n as customSource, r as exposeColumns, t as createSource } from "./source-DYSUqzvb.mjs";
|
|
4
|
+
import { n as alias, r as lateral, t as table } from "./table-B8zEq0az.mjs";
|
|
5
|
+
import { a as primaryKey, c as uniqueConstraint, d as validateIndexDialect, i as foreignKey, l as validateConstraintDialect, n as catalogForeignKey, o as references, r as check, s as unique, t as catalogCheck, u as index } from "./constraints-CAmi18Uk.mjs";
|
|
6
|
+
import { a as renderSchemaExpression, c as unsafeSchemaSql, i as normalizeSchemaSql, n as defineSchemaExpression, o as renderSchemaSql, r as isUnsafeSchemaSql, s as schemaExpression, t as SchemaExpressionError } from "./expressions-_6JF_J77.mjs";
|
|
7
|
+
import { a as schemaNamingPolicyVersion, i as schema, n as defaultSchemaNamingPolicy, r as generatedTableName, t as SchemaValidationError } from "./registry-BXE_4M9P.mjs";
|
|
7
8
|
import { t as createSchemaDialect } from "./dialect-wUKrnPMB.mjs";
|
|
8
|
-
export { ColumnBehaviorError, SchemaExpressionError, SchemaMetadataValidationError, SchemaValidationError, alias, assertSchemaDialectSupport, bigint, binary, boolean, canonicalLiteral, catalogCheck, catalogForeignKey, check, column, columnResultValue, createSchemaDialect, createSource, customSource, date, defaultSchemaNamingPolicy, defineSchemaExpression, dialectMismatchDiagnostic, encodeColumnParameter, exposeColumns, externalDefault, externalGeneratedColumn, foreignKey, freezeSchemaMetadata, generatedColumn, generatedSchemaObjectName, generatedTableName, identityColumn, index, integer, isUnsafeSchemaSql, isValidSchemaObjectName, json, lateral, materializeSchemaObjectIdentity, materializeSchemaObjectRecord, nativeColumn, nativeStorage, normalizeSchemaSql, nullable, numeric, portableStorage, primaryKey, references, renderSchemaExpression, renderSchemaSql, resolveColumnBehavior, schema, schemaExpression, schemaNamingPolicyVersion, sourceIdentity, table, text, timestamp, unique, uniqueConstraint, unsafeSchemaSql, uuid, validateConstraintDialect, validateIndexDialect };
|
|
9
|
+
export { ColumnBehaviorError, SchemaExpressionError, SchemaMetadataValidationError, SchemaValidationError, alias, assertSchemaDialectSupport, bigint, binary, boolean, canonicalLiteral, catalogCheck, catalogForeignKey, check, column, columnResultValue, columnSqlType, createSchemaDialect, createSource, customSource, date, defaultSchemaNamingPolicy, defineSchemaExpression, dialectMismatchDiagnostic, encodeColumnParameter, exposeColumns, externalDefault, externalGeneratedColumn, foreignKey, freezeSchemaMetadata, generatedColumn, generatedSchemaObjectName, generatedTableName, identityColumn, index, integer, isUnsafeSchemaSql, isValidSchemaObjectName, json, lateral, materializeSchemaObjectIdentity, materializeSchemaObjectRecord, nativeColumn, nativeStorage, normalizeSchemaSql, nullable, numeric, portableStorage, primaryKey, references, renderSchemaExpression, renderSchemaSql, resolveColumnBehavior, schema, schemaExpression, schemaNamingPolicyVersion, sourceIdentity, table, text, timestamp, unique, uniqueConstraint, unsafeSchemaSql, uuid, validateConstraintDialect, validateIndexDialect };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { _ as generatedSchemaObjectName, r as isColumnReference, s as canonicalLiteral, w as isSchemaExpression } from "./column-DDRvD7SF.mjs";
|
|
2
|
+
import { o as standardDialect } from "./value-CpaUFtjw.mjs";
|
|
3
|
+
import { a as renderSchemaExpression, r as isUnsafeSchemaSql } from "./expressions-_6JF_J77.mjs";
|
|
4
|
+
import { n as defaultSchemaNamingPolicy } from "./registry-BXE_4M9P.mjs";
|
|
4
5
|
import { t as createSchemaDialect } from "./dialect-wUKrnPMB.mjs";
|
|
5
|
-
import {
|
|
6
|
+
import { A as neutralSnapshotDialect, M as schemaSnapshotFormat, a as toSnapshotJsonValue, i as schemaSnapshotFingerprint, o as SnapshotValidationError, r as encodeCanonicalSnapshot, s as assertSchemaSnapshot } from "./canonical-B5_ouh-c.mjs";
|
|
6
7
|
//#region src/snapshot/serialize.ts
|
|
7
8
|
const neutralSchemaDialect = createSchemaDialect(Object.freeze({
|
|
8
9
|
...standardDialect(),
|
|
@@ -12,7 +13,7 @@ const neutralSchemaDialect = createSchemaDialect(Object.freeze({
|
|
|
12
13
|
var SnapshotSerializationError = class extends SnapshotValidationError {
|
|
13
14
|
name = "SnapshotSerializationError";
|
|
14
15
|
};
|
|
15
|
-
/** Create
|
|
16
|
+
/** Create an immutable Snapshot v1 value from a live schema. */
|
|
16
17
|
function createSchemaSnapshot(schema, options = {}) {
|
|
17
18
|
const result = tryCreateSchemaSnapshot(schema, options);
|
|
18
19
|
if (!result.ok) throw new SnapshotSerializationError(result.diagnostics);
|
|
@@ -69,6 +70,7 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
69
70
|
ok: false,
|
|
70
71
|
diagnostics: Object.freeze(diagnostics)
|
|
71
72
|
};
|
|
73
|
+
const namespace = schema.namespace ?? "default";
|
|
72
74
|
const rawSnapshot = {
|
|
73
75
|
format: schemaSnapshotFormat,
|
|
74
76
|
version: 1,
|
|
@@ -80,8 +82,23 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
80
82
|
name: namingPolicy.name,
|
|
81
83
|
version: namingPolicy.version ?? 1
|
|
82
84
|
}),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
namespace: namespaceFor(dialect.name, namespace),
|
|
86
|
+
capabilities: capabilitiesFor(dialect.name),
|
|
87
|
+
tables,
|
|
88
|
+
views: [],
|
|
89
|
+
sequences: [],
|
|
90
|
+
enums: [],
|
|
91
|
+
domains: [],
|
|
92
|
+
collations: [],
|
|
93
|
+
triggers: [],
|
|
94
|
+
routines: [],
|
|
95
|
+
partitions: [],
|
|
96
|
+
policies: [],
|
|
97
|
+
extensions: [],
|
|
98
|
+
deferredObjects: [],
|
|
99
|
+
opaqueObjects: [],
|
|
100
|
+
comments: [],
|
|
101
|
+
ownership: []
|
|
85
102
|
};
|
|
86
103
|
try {
|
|
87
104
|
return {
|
|
@@ -103,7 +120,7 @@ function tryCreateSchemaSnapshot(schema, options = {}) {
|
|
|
103
120
|
};
|
|
104
121
|
}
|
|
105
122
|
}
|
|
106
|
-
/** Encode a valid
|
|
123
|
+
/** Encode a valid Snapshot v1 value using canonical JSON. */
|
|
107
124
|
function encodeSchemaSnapshot(snapshot) {
|
|
108
125
|
const canonical = assertSchemaSnapshot(snapshot);
|
|
109
126
|
return encodeCanonicalSnapshot(canonical);
|
|
@@ -116,16 +133,27 @@ const encodeSnapshot = encodeSchemaSnapshot;
|
|
|
116
133
|
const fingerprintSchemaSnapshot = schemaSnapshotFingerprint;
|
|
117
134
|
function serializeTable(id, table, physicalName, tableIds, tablesById, dialect, options, diagnostics) {
|
|
118
135
|
const definitions = table.definitions;
|
|
136
|
+
const owner = {
|
|
137
|
+
kind: "table",
|
|
138
|
+
id
|
|
139
|
+
};
|
|
119
140
|
const tableMetadata = table;
|
|
141
|
+
const tableDialect = tableMetadata.dialect ? encodeExtension(tableMetadata.dialect, dialect, [
|
|
142
|
+
"tables",
|
|
143
|
+
id,
|
|
144
|
+
"dialect"
|
|
145
|
+
], options, diagnostics) : void 0;
|
|
120
146
|
return {
|
|
147
|
+
kind: "table",
|
|
121
148
|
id,
|
|
122
149
|
physicalName,
|
|
123
|
-
columns: Object.entries(definitions).map(([fieldName, definition]) => serializeColumn(fieldName, definition, table.sqlNames[fieldName] ?? fieldName, dialect, options, diagnostics)).sort(compareId),
|
|
124
|
-
constraints: Object.entries(tableMetadata.constraints).map(([constraintId, constraint]) => serializeConstraint(constraintId, constraint, table, tableIds, tablesById, dialect, options, diagnostics)).filter((constraint) => constraint !== void 0).sort(compareId),
|
|
125
|
-
indexes: Object.entries(tableMetadata.indexes).map(([indexId, indexMetadata]) => serializeIndex(indexId, indexMetadata, table, dialect, options, diagnostics)).filter((index) => index !== void 0).sort(compareId)
|
|
150
|
+
columns: Object.entries(definitions).map(([fieldName, definition], ordinalPosition) => serializeColumn(id, fieldName, definition, table.sqlNames[fieldName] ?? fieldName, ordinalPosition + 1, dialect, options, diagnostics)).sort(compareId),
|
|
151
|
+
constraints: Object.entries(tableMetadata.constraints).map(([constraintId, constraint]) => serializeConstraint(constraintId, constraint, table, owner, tableIds, tablesById, dialect, options, diagnostics)).filter((constraint) => constraint !== void 0).sort(compareId),
|
|
152
|
+
indexes: Object.entries(tableMetadata.indexes).map(([indexId, indexMetadata]) => serializeIndex(indexId, indexMetadata, table, owner, dialect, options, diagnostics)).filter((index) => index !== void 0).sort(compareId),
|
|
153
|
+
...tableDialect === void 0 ? {} : { dialect: tableDialect }
|
|
126
154
|
};
|
|
127
155
|
}
|
|
128
|
-
function serializeColumn(id, definition, physicalName, dialect, options, diagnostics) {
|
|
156
|
+
function serializeColumn(tableId, id, definition, physicalName, ordinalPosition, dialect, options, diagnostics) {
|
|
129
157
|
const storage = definition.storage ? encodeStorage(definition.storage, dialect, [
|
|
130
158
|
"tables",
|
|
131
159
|
id,
|
|
@@ -155,9 +183,18 @@ function serializeColumn(id, definition, physicalName, dialect, options, diagnos
|
|
|
155
183
|
id,
|
|
156
184
|
"onUpdate"
|
|
157
185
|
], options, diagnostics) : void 0;
|
|
186
|
+
const columnDialect = definition.dialect ? encodeExtension(definition.dialect, dialect, [
|
|
187
|
+
"tables",
|
|
188
|
+
tableId,
|
|
189
|
+
"columns",
|
|
190
|
+
id,
|
|
191
|
+
"dialect"
|
|
192
|
+
], options, diagnostics) : void 0;
|
|
158
193
|
return {
|
|
194
|
+
kind: "column",
|
|
159
195
|
id,
|
|
160
196
|
physicalName,
|
|
197
|
+
ordinalPosition,
|
|
161
198
|
nullable: definition.nullable,
|
|
162
199
|
hasDefault: definition.hasDefault,
|
|
163
200
|
generated: definition.generated,
|
|
@@ -165,7 +202,8 @@ function serializeColumn(id, definition, physicalName, dialect, options, diagnos
|
|
|
165
202
|
...defaultValue === void 0 ? {} : { default: defaultValue },
|
|
166
203
|
...generatedColumn === void 0 ? {} : { generatedColumn },
|
|
167
204
|
...identity === void 0 ? {} : { identity },
|
|
168
|
-
...onUpdate === void 0 ? {} : { onUpdate }
|
|
205
|
+
...onUpdate === void 0 ? {} : { onUpdate },
|
|
206
|
+
...columnDialect === void 0 ? {} : { dialect: columnDialect }
|
|
169
207
|
};
|
|
170
208
|
}
|
|
171
209
|
function encodeStorage(storage, dialect, path, options, diagnostics) {
|
|
@@ -224,18 +262,48 @@ function encodeGenerated(value, dialect, path, options, diagnostics) {
|
|
|
224
262
|
}
|
|
225
263
|
function encodeIdentity(value, dialect, path, options, diagnostics) {
|
|
226
264
|
const extension = encodeExtension(value.dialect, dialect, [...path, "dialect"], options, diagnostics);
|
|
265
|
+
const identityOptions = {};
|
|
266
|
+
for (const [key, option] of Object.entries(value.options ?? {}).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
267
|
+
const encoded = encodeValueFact(option, dialect, [
|
|
268
|
+
...path,
|
|
269
|
+
"options",
|
|
270
|
+
key
|
|
271
|
+
], options, diagnostics);
|
|
272
|
+
if (encoded !== void 0) identityOptions[key] = encoded;
|
|
273
|
+
}
|
|
227
274
|
return {
|
|
228
275
|
kind: "identity",
|
|
229
276
|
generation: value.generation,
|
|
277
|
+
options: identityOptions,
|
|
230
278
|
...extension === void 0 ? {} : { dialect: extension }
|
|
231
279
|
};
|
|
232
280
|
}
|
|
233
|
-
function
|
|
234
|
-
|
|
281
|
+
function encodeValueFact(value, dialect, path, options, diagnostics) {
|
|
282
|
+
if (isSchemaExpression(value)) {
|
|
283
|
+
const expression = encodeExpression(value, "default", dialect, path, options, diagnostics);
|
|
284
|
+
return expression === void 0 ? void 0 : {
|
|
285
|
+
kind: "expression",
|
|
286
|
+
expression
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
return {
|
|
291
|
+
kind: "literal",
|
|
292
|
+
value: canonicalLiteral(value)
|
|
293
|
+
};
|
|
294
|
+
} catch (error) {
|
|
295
|
+
diagnostics.push({
|
|
296
|
+
code: "invalid-schema",
|
|
297
|
+
message: error instanceof Error ? error.message : String(error),
|
|
298
|
+
path
|
|
299
|
+
});
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function serializeConstraint(id, constraint, table, owner, tableIds, tablesById, dialect, options, diagnostics) {
|
|
235
304
|
const common = {
|
|
236
305
|
id,
|
|
237
|
-
|
|
238
|
-
physicalName
|
|
306
|
+
physicalName: constraint.physicalName ?? generatedSchemaObjectName(id)
|
|
239
307
|
};
|
|
240
308
|
if (constraint.kind === "primary-key" || constraint.kind === "unique" || constraint.kind === "unique-constraint") {
|
|
241
309
|
const columns = serializeColumns(constraint.columns, table, [
|
|
@@ -250,12 +318,15 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
250
318
|
], options, diagnostics);
|
|
251
319
|
if (columns === void 0) return;
|
|
252
320
|
const timing = serializeTiming(constraint);
|
|
321
|
+
const backingIndex = serializeBackingIndex(constraint, owner);
|
|
253
322
|
if (constraint.kind === "unique-constraint") return {
|
|
254
323
|
...common,
|
|
255
324
|
kind: "unique-constraint",
|
|
256
325
|
columns,
|
|
257
326
|
nulls: constraint.nulls,
|
|
258
327
|
...timing,
|
|
328
|
+
...constraint.validated === void 0 ? {} : { validated: constraint.validated },
|
|
329
|
+
...backingIndex === void 0 ? {} : { backingIndex },
|
|
259
330
|
...extension === void 0 ? {} : { dialect: extension }
|
|
260
331
|
};
|
|
261
332
|
return {
|
|
@@ -263,6 +334,8 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
263
334
|
kind: constraint.kind,
|
|
264
335
|
columns,
|
|
265
336
|
...timing,
|
|
337
|
+
...constraint.validated === void 0 ? {} : { validated: constraint.validated },
|
|
338
|
+
...backingIndex === void 0 ? {} : { backingIndex },
|
|
266
339
|
...extension === void 0 ? {} : { dialect: extension }
|
|
267
340
|
};
|
|
268
341
|
}
|
|
@@ -292,6 +365,7 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
292
365
|
...constraint.onDelete === void 0 ? {} : { onDelete: constraint.onDelete },
|
|
293
366
|
...constraint.match === void 0 ? {} : { match: constraint.match },
|
|
294
367
|
...serializeTiming(constraint),
|
|
368
|
+
...constraint.validated === void 0 ? {} : { validated: constraint.validated },
|
|
295
369
|
...extension === void 0 ? {} : { dialect: extension }
|
|
296
370
|
};
|
|
297
371
|
}
|
|
@@ -312,6 +386,7 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
312
386
|
kind: "check",
|
|
313
387
|
expression,
|
|
314
388
|
...serializeTiming(constraint),
|
|
389
|
+
...constraint.validated === void 0 ? {} : { validated: constraint.validated },
|
|
315
390
|
...extension === void 0 ? {} : { dialect: extension }
|
|
316
391
|
};
|
|
317
392
|
}
|
|
@@ -321,13 +396,20 @@ function serializeConstraint(id, constraint, table, tableIds, tablesById, dialec
|
|
|
321
396
|
path: ["constraints", id]
|
|
322
397
|
});
|
|
323
398
|
}
|
|
399
|
+
function serializeBackingIndex(constraint, owner) {
|
|
400
|
+
return constraint.backingIndex === void 0 ? void 0 : {
|
|
401
|
+
kind: "index",
|
|
402
|
+
id: constraint.backingIndex,
|
|
403
|
+
owner
|
|
404
|
+
};
|
|
405
|
+
}
|
|
324
406
|
function serializeTiming(value) {
|
|
325
407
|
return {
|
|
326
408
|
...value.deferrable === void 0 ? {} : { deferrable: value.deferrable },
|
|
327
409
|
...value.initially === void 0 ? {} : { initially: value.initially }
|
|
328
410
|
};
|
|
329
411
|
}
|
|
330
|
-
function serializeColumns(columns, table, path, diagnostics) {
|
|
412
|
+
function serializeColumns(columns, table, path, diagnostics, nonEmpty = true) {
|
|
331
413
|
const result = [];
|
|
332
414
|
for (const [index, column] of columns.entries()) {
|
|
333
415
|
if (!isColumnReference(column)) {
|
|
@@ -348,7 +430,7 @@ function serializeColumns(columns, table, path, diagnostics) {
|
|
|
348
430
|
}
|
|
349
431
|
result.push(column.fieldName);
|
|
350
432
|
}
|
|
351
|
-
return result.length === columns.length && result.length > 0 ? result : void 0;
|
|
433
|
+
return result.length === columns.length && (!nonEmpty || result.length > 0) ? result : void 0;
|
|
352
434
|
}
|
|
353
435
|
function resolveForeignKeyTarget(constraint, tableIds, tablesById, path, diagnostics) {
|
|
354
436
|
let target;
|
|
@@ -374,14 +456,17 @@ function resolveForeignKeyTarget(constraint, tableIds, tablesById, path, diagnos
|
|
|
374
456
|
const targetColumns = serializeColumns(target.columns, target.table, [...path, "columns"], diagnostics);
|
|
375
457
|
if (targetColumns === void 0) return;
|
|
376
458
|
return {
|
|
377
|
-
table:
|
|
459
|
+
table: {
|
|
460
|
+
kind: "table",
|
|
461
|
+
id: targetId
|
|
462
|
+
},
|
|
378
463
|
columns: targetColumns
|
|
379
464
|
};
|
|
380
465
|
}
|
|
381
|
-
function serializeIndex(id, indexMetadata, table, dialect, options, diagnostics) {
|
|
466
|
+
function serializeIndex(id, indexMetadata, table, owner, dialect, options, diagnostics) {
|
|
382
467
|
const terms = [];
|
|
383
468
|
for (const [termIndex, term] of indexMetadata.terms.entries()) {
|
|
384
|
-
const serialized = serializeIndexTerm(term, table, dialect, [
|
|
469
|
+
const serialized = serializeIndexTerm(term, indexMetadata.termOptions?.[termIndex], table, dialect, termIndex + 1, [
|
|
385
470
|
"indexes",
|
|
386
471
|
id,
|
|
387
472
|
"terms",
|
|
@@ -398,12 +483,21 @@ function serializeIndex(id, indexMetadata, table, dialect, options, diagnostics)
|
|
|
398
483
|
"indexes",
|
|
399
484
|
id,
|
|
400
485
|
"includedColumns"
|
|
401
|
-
], diagnostics);
|
|
486
|
+
], diagnostics, false);
|
|
402
487
|
const extension = encodeExtension(indexMetadata.dialect, dialect, [
|
|
403
488
|
"indexes",
|
|
404
489
|
id,
|
|
405
490
|
"dialect"
|
|
406
491
|
], options, diagnostics);
|
|
492
|
+
if (indexMetadata.termOptions !== void 0 && indexMetadata.termOptions.length > indexMetadata.terms.length) diagnostics.push({
|
|
493
|
+
code: "invalid-schema",
|
|
494
|
+
message: "Index termOptions cannot contain entries without matching terms",
|
|
495
|
+
path: [
|
|
496
|
+
"indexes",
|
|
497
|
+
id,
|
|
498
|
+
"termOptions"
|
|
499
|
+
]
|
|
500
|
+
});
|
|
407
501
|
if (terms.length !== indexMetadata.terms.length || indexMetadata.includedColumns !== void 0 && includedColumns === void 0) return;
|
|
408
502
|
return {
|
|
409
503
|
id,
|
|
@@ -414,20 +508,42 @@ function serializeIndex(id, indexMetadata, table, dialect, options, diagnostics)
|
|
|
414
508
|
candidateKey: indexMetadata.candidateKey,
|
|
415
509
|
...predicate === void 0 ? {} : { predicate },
|
|
416
510
|
...includedColumns === void 0 ? {} : { includedColumns },
|
|
511
|
+
...indexMetadata.backingConstraint === void 0 ? {} : { backingConstraint: {
|
|
512
|
+
kind: "constraint",
|
|
513
|
+
id: indexMetadata.backingConstraint,
|
|
514
|
+
owner
|
|
515
|
+
} },
|
|
516
|
+
...indexMetadata.method === void 0 ? {} : { method: indexMetadata.method },
|
|
417
517
|
...extension === void 0 ? {} : { dialect: extension }
|
|
418
518
|
};
|
|
419
519
|
}
|
|
420
|
-
function serializeIndexTerm(term, table, dialect, path, options, diagnostics) {
|
|
520
|
+
function serializeIndexTerm(term, termOptions, table, dialect, position, path, options, diagnostics) {
|
|
421
521
|
if (isOrderTerm(term)) {
|
|
422
522
|
const expression = serializeIndexTermExpression(term.expression, table, dialect, [...path, "expression"], options, diagnostics);
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
expression,
|
|
523
|
+
const termMetadata = expression === void 0 ? void 0 : serializeIndexTermOptions(termOptions, dialect, path, options, diagnostics);
|
|
524
|
+
return expression === void 0 || termMetadata === void 0 ? void 0 : {
|
|
525
|
+
...expression,
|
|
526
|
+
position,
|
|
426
527
|
...term.direction === void 0 ? {} : { direction: term.direction },
|
|
427
|
-
...term.nulls === void 0 ? {} : { nulls: term.nulls }
|
|
528
|
+
...term.nulls === void 0 ? {} : { nulls: term.nulls },
|
|
529
|
+
...termMetadata
|
|
428
530
|
};
|
|
429
531
|
}
|
|
430
|
-
|
|
532
|
+
const expression = serializeIndexTermExpression(term, table, dialect, path, options, diagnostics);
|
|
533
|
+
const termMetadata = expression === void 0 ? void 0 : serializeIndexTermOptions(termOptions, dialect, path, options, diagnostics);
|
|
534
|
+
return expression === void 0 || termMetadata === void 0 ? void 0 : {
|
|
535
|
+
...expression,
|
|
536
|
+
position,
|
|
537
|
+
...termMetadata
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function serializeIndexTermOptions(value, dialect, path, options, diagnostics) {
|
|
541
|
+
if (value === void 0) return {};
|
|
542
|
+
const prefixLength = value.prefixLength === void 0 ? void 0 : encodeValueFact(value.prefixLength, dialect, [...path, "prefixLength"], options, diagnostics);
|
|
543
|
+
return value.prefixLength !== void 0 && prefixLength === void 0 ? void 0 : {
|
|
544
|
+
...prefixLength === void 0 ? {} : { prefixLength },
|
|
545
|
+
...value.operatorClass === void 0 ? {} : { operatorClass: value.operatorClass }
|
|
546
|
+
};
|
|
431
547
|
}
|
|
432
548
|
function serializeIndexTermExpression(expression, table, dialect, path, options, diagnostics) {
|
|
433
549
|
if (isColumnReference(expression)) {
|
|
@@ -527,7 +643,7 @@ function encodeExtension(extension, dialect, path, options, diagnostics) {
|
|
|
527
643
|
return;
|
|
528
644
|
}
|
|
529
645
|
const data = {};
|
|
530
|
-
for (const [key, value] of Object.entries(extension)) if (key !== "dialect") data
|
|
646
|
+
for (const [key, value] of Object.entries(extension)) if (key !== "dialect") setOwn(data, key, value);
|
|
531
647
|
try {
|
|
532
648
|
return {
|
|
533
649
|
dialect: extension.dialect,
|
|
@@ -552,5 +668,33 @@ function isSchemaRoot(value) {
|
|
|
552
668
|
function compareId(left, right) {
|
|
553
669
|
return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
|
|
554
670
|
}
|
|
671
|
+
function setOwn(target, key, value) {
|
|
672
|
+
Object.defineProperty(target, key, {
|
|
673
|
+
configurable: true,
|
|
674
|
+
enumerable: true,
|
|
675
|
+
value,
|
|
676
|
+
writable: true
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function namespaceFor(dialect, name) {
|
|
680
|
+
return {
|
|
681
|
+
kind: dialect === "postgresql" ? "postgres-schema" : dialect === "sqlite" ? "sqlite-database" : dialect === "mysql" ? "mysql-database" : "generic",
|
|
682
|
+
name
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function capabilitiesFor(dialect) {
|
|
686
|
+
return {
|
|
687
|
+
generatedColumns: dialect !== "neutral",
|
|
688
|
+
identityMetadata: dialect !== "neutral",
|
|
689
|
+
checkConstraints: true,
|
|
690
|
+
checkConstraintEnforcement: "unknown",
|
|
691
|
+
expressionDecompilation: false,
|
|
692
|
+
indexExpressions: true,
|
|
693
|
+
indexPredicates: true,
|
|
694
|
+
indexIncludedColumns: dialect === "postgresql",
|
|
695
|
+
namespaces: dialect !== "neutral",
|
|
696
|
+
visibility: "complete"
|
|
697
|
+
};
|
|
698
|
+
}
|
|
555
699
|
//#endregion
|
|
556
700
|
export { fingerprintSchemaSnapshot as a, encodeSnapshot as i, createSchemaSnapshot as n, serializeSchema as o, encodeSchemaSnapshot as r, tryCreateSchemaSnapshot as s, SnapshotSerializationError as t };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { B as CompleteSchemaSnapshot, T as SnapshotJsonValue, V as CompleteSchemaSnapshotInput, Y as CompleteSnapshotDecodeResult, Yi as Schema, f as SnapshotDiagnostic, i as SchemaSnapshotInput, ji as SchemaDialect, l as SnapshotCreateResult, n as SchemaSnapshot, r as SchemaSnapshotAdapter, u as SnapshotDecodeResult } from "./types-Dqr4o2I1.mjs";
|
|
2
|
+
//#region src/snapshot/canonical.d.ts
|
|
3
|
+
/** Error raised when a value cannot cross the canonical JSON boundary. */
|
|
4
|
+
declare class SnapshotCanonicalError extends TypeError {
|
|
5
|
+
readonly path: readonly (string | number)[];
|
|
6
|
+
constructor(message: string, path?: readonly (string | number)[]);
|
|
7
|
+
}
|
|
8
|
+
/** Convert a JavaScript value to the explicit JSON-safe snapshot domain. */
|
|
9
|
+
declare function toSnapshotJsonValue(value: unknown, path?: readonly (string | number)[], seen?: WeakSet<object>): SnapshotJsonValue;
|
|
10
|
+
/** Render a JSON-safe value with deterministic scalar and object handling. */
|
|
11
|
+
declare function canonicalJson(value: SnapshotJsonValue): string;
|
|
12
|
+
/** Canonical JSON for a schema snapshot after fixed-order reconstruction. */
|
|
13
|
+
declare function encodeCanonicalSnapshot(snapshot: SchemaSnapshot): string;
|
|
14
|
+
/**
|
|
15
|
+
* Compute a small deterministic content fingerprint for cache keys and diagnostics. It is
|
|
16
|
+
* deliberately not an entity identity, signature, or migration lineage.
|
|
17
|
+
*/
|
|
18
|
+
declare function schemaSnapshotFingerprint(snapshot: SchemaSnapshotInput | string): string;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/snapshot/complete.d.ts
|
|
21
|
+
/** Error raised by throwing APIs after collecting strict v1 diagnostics. */
|
|
22
|
+
declare class CompleteSnapshotValidationError extends TypeError {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly diagnostics: readonly SnapshotDiagnostic[];
|
|
25
|
+
readonly issues: readonly SnapshotDiagnostic[];
|
|
26
|
+
constructor(diagnostics: readonly SnapshotDiagnostic[]);
|
|
27
|
+
}
|
|
28
|
+
/** Decode and strictly validate a complete Snapshot v1 JSON value. */
|
|
29
|
+
declare function decodeCompleteSchemaSnapshot(input: string | unknown): CompleteSnapshotDecodeResult;
|
|
30
|
+
/** Validate a complete snapshot and throw one structured error on failure. */
|
|
31
|
+
declare function assertCompleteSchemaSnapshot(input: CompleteSchemaSnapshotInput | string): CompleteSchemaSnapshot;
|
|
32
|
+
/** Return a fixed-order, deeply immutable complete snapshot. */
|
|
33
|
+
declare function canonicalizeCompleteSchemaSnapshot(input: CompleteSchemaSnapshotInput): CompleteSchemaSnapshot;
|
|
34
|
+
/** Encode a complete snapshot with deterministic property and array order. */
|
|
35
|
+
declare function encodeCompleteSchemaSnapshot(snapshot: CompleteSchemaSnapshot): string;
|
|
36
|
+
/** Compute the deterministic content fingerprint for a complete Snapshot v1. */
|
|
37
|
+
declare function completeSchemaSnapshotFingerprint(snapshot: CompleteSchemaSnapshotInput | string): string;
|
|
38
|
+
/** Numbered aliases for tooling that prefers explicit Snapshot v1 names. */
|
|
39
|
+
declare const decodeSchemaSnapshotV1: typeof decodeCompleteSchemaSnapshot;
|
|
40
|
+
declare const assertSchemaSnapshotV1: typeof assertCompleteSchemaSnapshot;
|
|
41
|
+
declare const encodeSchemaSnapshotV1: typeof encodeCompleteSchemaSnapshot;
|
|
42
|
+
declare const canonicalizeSchemaSnapshotV1: typeof canonicalizeCompleteSchemaSnapshot;
|
|
43
|
+
declare const schemaSnapshotV1Fingerprint: typeof completeSchemaSnapshotFingerprint;
|
|
44
|
+
declare const decodeCompleteSnapshot: typeof decodeCompleteSchemaSnapshot;
|
|
45
|
+
declare const assertCompleteSnapshot: typeof assertCompleteSchemaSnapshot;
|
|
46
|
+
declare const encodeCompleteSnapshot: typeof encodeCompleteSchemaSnapshot;
|
|
47
|
+
declare const fingerprintCompleteSchemaSnapshot: typeof completeSchemaSnapshotFingerprint;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/snapshot/decode.d.ts
|
|
50
|
+
/** Error raised by throwing snapshot APIs after collecting diagnostics. */
|
|
51
|
+
declare class SnapshotValidationError extends CompleteSnapshotValidationError {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
}
|
|
54
|
+
/** Decode and strictly validate the canonical Snapshot v1 JSON value. */
|
|
55
|
+
declare function decodeSchemaSnapshot(input: string | unknown): SnapshotDecodeResult;
|
|
56
|
+
/** Validate a Snapshot v1 value and throw one structured error if it is malformed. */
|
|
57
|
+
declare function assertSchemaSnapshot(input: SchemaSnapshotInput | string): SchemaSnapshot;
|
|
58
|
+
/** Return a fixed-order, deeply immutable copy of a valid Snapshot v1 value. */
|
|
59
|
+
declare function canonicalizeSchemaSnapshot(input: SchemaSnapshotInput): SchemaSnapshot;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/snapshot/serialize.d.ts
|
|
62
|
+
/** Error raised when a live Qubu schema cannot be represented as a snapshot. */
|
|
63
|
+
declare class SnapshotSerializationError extends SnapshotValidationError {
|
|
64
|
+
readonly name = "SnapshotSerializationError";
|
|
65
|
+
}
|
|
66
|
+
/** Options for the schema traversal and a dialect adapter. */
|
|
67
|
+
interface SchemaSnapshotOptions {
|
|
68
|
+
readonly adapter?: SchemaSnapshotAdapter;
|
|
69
|
+
readonly dialect?: SchemaDialect;
|
|
70
|
+
/** Explicit hook overrides retained for custom tooling integrations. */
|
|
71
|
+
readonly expressionEncoder?: SchemaDialect["schema"]["encodeExpression"];
|
|
72
|
+
readonly storageEncoder?: SchemaDialect["schema"]["encodeStorage"];
|
|
73
|
+
readonly extensionEncoder?: SchemaDialect["schema"]["encodeDialectExtension"];
|
|
74
|
+
readonly namingPolicy?: {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
readonly version?: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Create an immutable Snapshot v1 value from a live schema. */
|
|
80
|
+
declare function createSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: SchemaSnapshotOptions): SchemaSnapshot;
|
|
81
|
+
/** Non-throwing form of {@link createSchemaSnapshot}. */
|
|
82
|
+
declare function tryCreateSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: SchemaSnapshotOptions): SnapshotCreateResult;
|
|
83
|
+
/** Encode a valid Snapshot v1 value using canonical JSON. */
|
|
84
|
+
declare function encodeSchemaSnapshot(snapshot: SchemaSnapshot): string;
|
|
85
|
+
/** Alias used by tooling packages that call the operation serialization. */
|
|
86
|
+
declare const serializeSchema: typeof createSchemaSnapshot;
|
|
87
|
+
/** Alias for the canonical snapshot encoder. */
|
|
88
|
+
declare const encodeSnapshot: typeof encodeSchemaSnapshot;
|
|
89
|
+
/** Alias for the canonical snapshot fingerprint helper. */
|
|
90
|
+
declare const fingerprintSchemaSnapshot: typeof schemaSnapshotFingerprint;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { encodeCanonicalSnapshot as A, encodeCompleteSchemaSnapshot as C, schemaSnapshotV1Fingerprint as D, fingerprintCompleteSchemaSnapshot as E, toSnapshotJsonValue as M, SnapshotCanonicalError as O, decodeSchemaSnapshotV1 as S, encodeSchemaSnapshotV1 as T, canonicalizeCompleteSchemaSnapshot as _, encodeSnapshot as a, decodeCompleteSchemaSnapshot as b, tryCreateSchemaSnapshot as c, canonicalizeSchemaSnapshot as d, decodeSchemaSnapshot as f, assertSchemaSnapshotV1 as g, assertCompleteSnapshot as h, encodeSchemaSnapshot as i, schemaSnapshotFingerprint as j, canonicalJson as k, SnapshotValidationError as l, assertCompleteSchemaSnapshot as m, SnapshotSerializationError as n, fingerprintSchemaSnapshot as o, CompleteSnapshotValidationError as p, createSchemaSnapshot as r, serializeSchema as s, SchemaSnapshotOptions as t, assertSchemaSnapshot as u, canonicalizeSchemaSnapshotV1 as v, encodeCompleteSnapshot as w, decodeCompleteSnapshot as x, completeSchemaSnapshotFingerprint as y };
|
|
@@ -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/mysql.d.ts
|
|
4
|
-
/** MySQL's
|
|
4
|
+
/** MySQL's snapshot dialect-extension identity. */
|
|
5
5
|
declare const mysqlSnapshotDialect: SnapshotDialect;
|
|
6
6
|
/** MySQL's query dialect plus its schema metadata behavior. */
|
|
7
|
-
declare const mysqlSchemaDialect: SchemaDialect<"json" | "row-locking">;
|
|
7
|
+
declare const mysqlSchemaDialect: SchemaDialect<"json" | "on-duplicate-key-update" | "row-locking">;
|
|
8
8
|
/** Snapshot adapter retaining the historical adapter-shaped entry point. */
|
|
9
|
-
declare const mysqlSnapshotAdapter: SchemaSnapshotAdapter<"json" | "row-locking">;
|
|
9
|
+
declare const mysqlSnapshotAdapter: SchemaSnapshotAdapter<"json" | "on-duplicate-key-update" | "row-locking">;
|
|
10
10
|
/** Create a canonical MySQL schema snapshot. */
|
|
11
11
|
declare function createSchemaSnapshot<TSchema extends Schema<any>>(schema: TSchema, options?: MysqlSnapshotOptions): SchemaSnapshot;
|
|
12
12
|
/** Return MySQL capability diagnostics without throwing. */
|