qubu 0.6.1 → 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.
Files changed (84) hide show
  1. package/dist/{complete-DP7pliuY.mjs → canonical-B5_ouh-c.mjs} +466 -241
  2. package/dist/codegen.d.mts +2 -2
  3. package/dist/codegen.mjs +180 -90
  4. package/dist/column-Cyc2CMnG.mjs +116 -0
  5. package/dist/column-DDRvD7SF.mjs +721 -0
  6. package/dist/{constraints-DM_tarXc.mjs → constraints-CAmi18Uk.mjs} +8 -3
  7. package/dist/core.d.mts +3 -3
  8. package/dist/core.mjs +4 -4
  9. package/dist/diff.d.mts +9 -9
  10. package/dist/diff.mjs +152 -102
  11. package/dist/{explain-CkIK13L_.mjs → explain-BIqEmZha.mjs} +1 -1
  12. package/dist/{expressions-BCjc08zw.mjs → expressions-_6JF_J77.mjs} +2 -1
  13. package/dist/index-CaxrMD1A.d.mts +1 -0
  14. package/dist/index.d.mts +2 -2
  15. package/dist/index.mjs +368 -74
  16. package/dist/introspection/mysql.d.mts +1 -1
  17. package/dist/introspection/mysql.mjs +156 -23
  18. package/dist/introspection/postgres.d.mts +6 -3
  19. package/dist/introspection/postgres.mjs +388 -53
  20. package/dist/introspection/sqlite.d.mts +1 -1
  21. package/dist/introspection/sqlite.mjs +198 -12
  22. package/dist/introspection.d.mts +26 -12
  23. package/dist/introspection.mjs +2 -672
  24. package/dist/mysql.d.mts +3 -3
  25. package/dist/mysql.mjs +6 -5
  26. package/dist/{errors-Dxv73YJu.mjs → omit-VEr9Ydux.mjs} +5 -1
  27. package/dist/{on-conflict-CnaY5qso.mjs → on-conflict-B2rFyHGF.mjs} +6 -8
  28. package/dist/on-duplicate-key-update-Czsw1Yq-.mjs +95 -0
  29. package/dist/{postgres-Dey7QXPL.mjs → postgres-hFhd0I9n.mjs} +4 -5
  30. package/dist/postgres.d.mts +2 -2
  31. package/dist/postgres.mjs +2 -2
  32. package/dist/{registry-oWDiqD7i.mjs → registry-BXE_4M9P.mjs} +1 -1
  33. package/dist/{relational-DSAJ-l58.mjs → relational-CoPBETjI.mjs} +3 -2
  34. package/dist/schema.d.mts +2 -2
  35. package/dist/schema.mjs +8 -8
  36. package/dist/{serialize-CE-gw5_s.mjs → serialize-CyobNEx-.mjs} +174 -30
  37. package/dist/serialize-Du2UPZMt.d.mts +92 -0
  38. package/dist/snapshot/mysql.d.mts +5 -5
  39. package/dist/snapshot/mysql.mjs +8 -8
  40. package/dist/snapshot/postgres.d.mts +3 -3
  41. package/dist/snapshot/postgres.mjs +9 -9
  42. package/dist/snapshot/sqlite.d.mts +3 -3
  43. package/dist/snapshot/sqlite.mjs +7 -7
  44. package/dist/snapshot-mIb-Zzb5.mjs +1489 -0
  45. package/dist/snapshot.d.mts +4 -5
  46. package/dist/snapshot.mjs +3 -4
  47. package/dist/{source-BDuUXmAk.mjs → source-DYSUqzvb.mjs} +2 -2
  48. package/dist/sqlite.d.mts +2 -2
  49. package/dist/sqlite.mjs +6 -6
  50. package/dist/{table-C1QGNe4P.mjs → table-B8zEq0az.mjs} +4 -4
  51. package/dist/{types-BLNRatG_.mjs → types-CYHpSPwj.mjs} +10 -5
  52. package/dist/{types-BEn0N_al.d.mts → types-CiMvKi5V.d.mts} +14 -4
  53. package/dist/{types-DUe6eeI0.d.mts → types-Dqr4o2I1.d.mts} +590 -168
  54. package/dist/value-CpaUFtjw.mjs +45 -0
  55. package/dist/vite/ambient.d.ts +2 -0
  56. package/dist/vite.d.mts +1 -1
  57. package/dist/vite.mjs +2 -0
  58. package/docs/dialects-and-execution.md +61 -11
  59. package/docs/getting-started.md +1 -1
  60. package/docs/guides/extensions/typed-expressions.md +5 -3
  61. package/docs/guides/json.md +95 -2
  62. package/docs/guides/mutations.md +36 -0
  63. package/docs/index.md +1 -1
  64. package/docs/migrations/adapters.md +58 -21
  65. package/docs/migrations/recovery.md +7 -1
  66. package/docs/query-model/fragments.md +21 -1
  67. package/docs/reference/introspection-support.md +16 -18
  68. package/docs/reference/supported-surface.md +8 -7
  69. package/docs/schema/catalog-model.md +20 -7
  70. package/docs/schema/code-generation.md +1 -1
  71. package/docs/schema/diff.md +2 -2
  72. package/docs/schema/introspection.md +21 -14
  73. package/docs/schema/snapshots.md +18 -8
  74. package/docs/schema/storage-and-schema-sql.md +7 -2
  75. package/package.json +2 -1
  76. package/dist/canonical-DMvR9yBe.mjs +0 -972
  77. package/dist/column-BzN8KFJa.mjs +0 -364
  78. package/dist/column-CFvSbil0.mjs +0 -309
  79. package/dist/complete-types-CNMWBWap.d.mts +0 -371
  80. package/dist/index-CGui70hi.d.mts +0 -32
  81. package/dist/json-Db7XRD91.mjs +0 -169
  82. package/dist/omit-OxV58AwX.mjs +0 -5
  83. package/dist/serialize-OvXCLzjm.d.mts +0 -66
  84. package/dist/snapshot-DgsOhf_8.mjs +0 -354
@@ -1,673 +1,3 @@
1
- import { a as toSnapshotJsonValue } from "./canonical-DMvR9yBe.mjs";
1
+ import { a as createCompleteIntrospectionCatalog, i as introspectedPhysicalIdentityPolicy, n as mapCatalogToCompleteSnapshot, o as freezeIntrospectionCatalog, r as mapCatalogToSnapshotV1, s as toIntrospectionCatalog, t as mapCatalogToSnapshot } from "./snapshot-mIb-Zzb5.mjs";
2
2
  import { n as createIntrospectionDiagnostic, r as hasIntrospectionErrors, t as IntrospectionError } from "./diagnostics-I9vVtXkc.mjs";
3
- import { n as introspectedPhysicalIdentityPolicy, t as mapCatalogToSnapshot } from "./snapshot-DgsOhf_8.mjs";
4
- import { n as assertCompleteSchemaSnapshot } from "./complete-DP7pliuY.mjs";
5
- import "./snapshot.mjs";
6
- //#region src/introspection/catalog.ts
7
- /**
8
- * Materialize every optional object-family collection and deeply freeze the normalized catalog.
9
- * Catalog text and extension data remain values; this helper never evaluates SQL or assigns
10
- * persisted logical identities.
11
- */
12
- function createCompleteIntrospectionCatalog(catalog) {
13
- return deepFreeze({
14
- dialect: catalog.dialect,
15
- server: catalog.server,
16
- capabilities: catalog.capabilities ?? catalog.server.capabilities,
17
- namespace: catalog.namespace,
18
- tables: sortTables(catalog.tables),
19
- views: sortObjects(catalog.views ?? []),
20
- sequences: sortObjects(catalog.sequences ?? []),
21
- enums: sortObjects(catalog.enums ?? []),
22
- domains: sortObjects(catalog.domains ?? []),
23
- collations: sortObjects(catalog.collations ?? []),
24
- triggers: sortObjects(catalog.triggers ?? []),
25
- routines: sortObjects(catalog.routines ?? []),
26
- partitions: sortObjects(catalog.partitions ?? []),
27
- policies: sortObjects(catalog.policies ?? []),
28
- extensionObjects: sortObjects(catalog.extensionObjects ?? []),
29
- deferredObjects: [...catalog.deferredObjects].sort(compareDeferred),
30
- opaqueObjects: sortObjects(catalog.opaqueObjects ?? []),
31
- comments: [...catalog.comments ?? []].sort(compareId$1),
32
- ownership: [...catalog.ownership ?? []].sort(compareId$1),
33
- diagnostics: [...catalog.diagnostics]
34
- });
35
- }
36
- /** Alias for callers that already use the normalized-catalog terminology. */
37
- const freezeIntrospectionCatalog = createCompleteIntrospectionCatalog;
38
- /** Convert a complete catalog back to the optional reader-facing contract. */
39
- function toIntrospectionCatalog(catalog) {
40
- return deepFreeze({
41
- ...catalog,
42
- capabilities: catalog.capabilities
43
- });
44
- }
45
- function sortTables(tables) {
46
- return [...tables].map((table) => deepFreeze({
47
- ...table,
48
- columns: [...table.columns].sort(compareColumn),
49
- constraints: [...table.constraints].sort(compareId$1),
50
- indexes: [...table.indexes].sort(compareId$1)
51
- })).sort(compareId$1);
52
- }
53
- function sortObjects(objects) {
54
- return [...objects].sort(compareId$1);
55
- }
56
- function compareId$1(left, right) {
57
- return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
58
- }
59
- function compareDeferred(left, right) {
60
- const leftId = left.id ?? left.physicalName;
61
- const rightId = right.id ?? right.physicalName;
62
- return leftId < rightId ? -1 : leftId > rightId ? 1 : 0;
63
- }
64
- function compareColumn(left, right) {
65
- return left.ordinalPosition - right.ordinalPosition || compareId$1(left, right);
66
- }
67
- /**
68
- * Freeze nested catalog values without imposing JSON semantics on bigint or opaque driver values.
69
- * The normalized contract is expected to contain plain records, arrays, and scalar values;
70
- * unsupported prototypes are retained but still frozen so the operation remains non-destructive.
71
- */
72
- function deepFreeze(value, seen = /* @__PURE__ */ new WeakSet()) {
73
- if (value === null || typeof value !== "object") return value;
74
- if (seen.has(value)) return value;
75
- seen.add(value);
76
- if (Array.isArray(value)) for (const item of value) deepFreeze(item, seen);
77
- else for (const child of Object.values(value)) deepFreeze(child, seen);
78
- return Object.freeze(value);
79
- }
80
- //#endregion
81
- //#region src/introspection/complete-snapshot.ts
82
- /**
83
- * Map a normalized catalog to strict Snapshot v2 data. This is intentionally separate from the
84
- * Snapshot v1 mapper: complete objects are never fabricated as tables, and catalog references
85
- * remain evidence rather than logical IDs.
86
- */
87
- function mapCatalogToCompleteSnapshot(input) {
88
- const catalog = createCompleteIntrospectionCatalog(input);
89
- const diagnostics = [...catalog.diagnostics];
90
- const tableByPhysicalName = new Map(catalog.tables.map((table) => [table.physicalName, table]));
91
- const tables = catalog.tables.map((table) => mapTable(table, catalog.dialect, tableByPhysicalName, diagnostics));
92
- const views = catalog.views.map((view) => mapView(view, catalog.dialect));
93
- const sequences = catalog.sequences.map((sequence) => mapSequence(sequence, catalog.dialect));
94
- const enums = catalog.enums.map((item) => mapEnum(item, catalog.dialect));
95
- const domains = catalog.domains.map((domain) => mapDomain(domain, catalog.dialect));
96
- const collations = catalog.collations.map((collation) => ({
97
- kind: "collation",
98
- id: collation.id,
99
- physicalName: collation.physicalName,
100
- ...collation.provider === void 0 ? {} : { provider: collation.provider },
101
- ...collation.locale === void 0 ? {} : { locale: collation.locale },
102
- ...collation.deterministic === void 0 ? {} : { deterministic: collation.deterministic },
103
- ...collation.version === void 0 ? {} : { version: collation.version },
104
- ...mapMetadata(collation.provenance, collation.dialect, catalog.dialect, collation.reference)
105
- }));
106
- const triggers = catalog.triggers.map((trigger) => mapTrigger(trigger, catalog.dialect, diagnostics));
107
- const routines = catalog.routines.map((routine) => mapRoutine(routine, catalog.dialect));
108
- const partitions = catalog.partitions.map((partition) => mapPartition(partition, catalog.dialect));
109
- const policies = catalog.policies.map((policy) => mapPolicy(policy, catalog.dialect));
110
- const extensions = catalog.extensionObjects.map((extension) => mapExtensionObject(extension, catalog.dialect));
111
- const deferredObjects = catalog.deferredObjects.map((object) => mapDeferredObject(object, catalog.dialect));
112
- const opaqueObjects = catalog.opaqueObjects.map((object) => mapOpaqueObject(object, catalog.dialect));
113
- for (const object of catalogObjectsWithUnknownFields(catalog)) for (const field of object.unknownFields ?? []) opaqueObjects.push(mapUnknownField(object, field, catalog.dialect));
114
- const comments = (catalog.comments ?? []).map((comment) => mapComment(comment, catalog.dialect));
115
- const ownership = (catalog.ownership ?? []).map((item) => mapOwnership(item, catalog.dialect));
116
- for (const object of catalogObjectList(catalog)) {
117
- if (object.comment && !comments.some((item) => item.id === object.comment?.id)) comments.push(mapComment(object.comment, catalog.dialect));
118
- if (object.ownership && !ownership.some((item) => item.id === object.ownership?.id)) ownership.push(mapOwnership(object.ownership, catalog.dialect));
119
- }
120
- const snapshot = {
121
- format: "qubu-schema",
122
- version: 2,
123
- dialect: {
124
- name: catalog.dialect,
125
- version: 1
126
- },
127
- namingPolicy: {
128
- name: introspectedPhysicalIdentityPolicy.name,
129
- version: introspectedPhysicalIdentityPolicy.version
130
- },
131
- namespace: {
132
- kind: catalog.namespace.kind,
133
- name: catalog.namespace.name,
134
- ...mapMetadata(catalog.namespace.provenance, catalog.namespace.dialect, catalog.dialect, catalog.namespace.reference)
135
- },
136
- capabilities: catalog.capabilities,
137
- tables: tables.sort(compareId),
138
- views: views.sort(compareId),
139
- sequences: sequences.sort(compareId),
140
- enums: enums.sort(compareId),
141
- domains: domains.sort(compareId),
142
- collations: collations.sort(compareId),
143
- triggers: triggers.sort(compareId),
144
- routines: routines.sort(compareId),
145
- partitions: partitions.sort(compareId),
146
- policies: policies.sort(compareId),
147
- extensions: extensions.sort(compareId),
148
- deferredObjects: deferredObjects.sort(compareId),
149
- opaqueObjects: opaqueObjects.sort(compareId),
150
- comments: comments.sort(compareId),
151
- ownership: ownership.sort(compareId)
152
- };
153
- if (diagnostics.some((diagnostic) => diagnostic.severity === "error")) return Object.freeze({
154
- ok: false,
155
- catalog,
156
- diagnostics: Object.freeze(diagnostics),
157
- lossy: false
158
- });
159
- try {
160
- const value = assertCompleteSchemaSnapshot(snapshot);
161
- return Object.freeze({
162
- ok: true,
163
- catalog,
164
- snapshot: value,
165
- diagnostics: Object.freeze(diagnostics),
166
- lossy: false
167
- });
168
- } catch (error) {
169
- diagnostics.push(createIntrospectionDiagnostic({
170
- severity: "error",
171
- code: "invalid-catalog-row",
172
- message: error instanceof Error ? `Catalog facts could not form Snapshot v2: ${error.message}` : "Catalog facts could not form Snapshot v2",
173
- path: [],
174
- remediation: "Inspect the catalog diagnostics and complete object mappings."
175
- }));
176
- return Object.freeze({
177
- ok: false,
178
- catalog,
179
- diagnostics: Object.freeze(diagnostics),
180
- lossy: false
181
- });
182
- }
183
- }
184
- /** Numbered alias for callers that keep both snapshot mappers available. */
185
- const mapCatalogToSnapshotV2 = mapCatalogToCompleteSnapshot;
186
- function mapTable(table, dialect, tables, diagnostics) {
187
- const columns = table.columns.map((column) => mapColumn(column, dialect)).sort(compareId);
188
- const columnIds = new Map(table.columns.map((column) => [column.physicalName, column.id]));
189
- const constraints = table.constraints.map((constraint) => mapConstraint(constraint, dialect, columnIds, tables, diagnostics)).filter((value) => value !== void 0).sort(compareId);
190
- const indexes = table.indexes.map((index) => mapIndex(index, dialect, columnIds)).sort(compareId);
191
- return {
192
- kind: "table",
193
- id: table.id,
194
- physicalName: table.physicalName,
195
- columns,
196
- constraints,
197
- indexes,
198
- ...mapMetadata(table.provenance, table.dialect, dialect, table.reference)
199
- };
200
- }
201
- function mapColumn(column, dialect) {
202
- const defaultValue = column.default ? mapValueFact(column.default) : void 0;
203
- const generatedColumn = column.generated ? column.generated.mode === "unknown" ? { kind: "external" } : {
204
- kind: "expression",
205
- expression: mapExpression(column.generated.expression),
206
- mode: column.generated.mode
207
- } : void 0;
208
- const identity = column.identity ? mapIdentity(column.identity, dialect) : void 0;
209
- return {
210
- kind: "column",
211
- id: column.id,
212
- physicalName: column.physicalName,
213
- ordinalPosition: column.ordinalPosition,
214
- nullable: column.nullable,
215
- hasDefault: defaultValue !== void 0 || generatedColumn !== void 0 || identity !== void 0,
216
- generated: generatedColumn !== void 0,
217
- storage: mapStorage(column.storage, dialect),
218
- ...defaultValue === void 0 ? {} : { default: defaultValue },
219
- ...generatedColumn === void 0 ? {} : { generatedColumn },
220
- ...identity === void 0 ? {} : { identity },
221
- ...column.onUpdate === void 0 ? {} : { onUpdate: mapExpression(column.onUpdate) },
222
- ...mapMetadata(column.provenance, column.dialect, dialect, column.reference)
223
- };
224
- }
225
- function mapConstraint(constraint, dialect, columns, tables, diagnostics) {
226
- const physicalName = constraint.physicalName ?? constraint.id;
227
- const common = {
228
- id: constraint.id,
229
- physicalName,
230
- ...mapMetadata(constraint.provenance, constraint.dialect, dialect, constraint.reference)
231
- };
232
- const mappedColumns = constraint.kind === "check" ? void 0 : constraint.columns.map((column) => {
233
- const id = columns.get(column);
234
- if (id !== void 0) return id;
235
- diagnostics.push(createIntrospectionDiagnostic({
236
- severity: "error",
237
- code: "unresolved-reference",
238
- message: `Constraint column ${column} was not found`,
239
- path: [constraint.id, "columns"]
240
- }));
241
- return column;
242
- });
243
- if (constraint.kind === "check") return {
244
- kind: "check",
245
- ...common,
246
- expression: mapExpression(constraint.expression),
247
- ...constraint.deferrable === void 0 ? {} : { deferrable: constraint.deferrable },
248
- ...constraint.initially === void 0 ? {} : { initially: constraint.initially },
249
- ...constraint.validated === void 0 ? {} : { validated: constraint.validated }
250
- };
251
- if (constraint.kind === "primary-key") return {
252
- kind: "primary-key",
253
- ...common,
254
- columns: mappedColumns ?? [],
255
- ...constraint.backingIndex === void 0 ? {} : { backingIndex: mapReference(constraint.backingIndex) },
256
- ...constraint.deferrable === void 0 ? {} : { deferrable: constraint.deferrable },
257
- ...constraint.initially === void 0 ? {} : { initially: constraint.initially },
258
- ...constraint.validated === void 0 ? {} : { validated: constraint.validated }
259
- };
260
- if (constraint.kind === "unique") return {
261
- kind: "unique-constraint",
262
- ...common,
263
- columns: mappedColumns ?? [],
264
- nulls: constraint.nulls,
265
- ...constraint.backingIndex === void 0 ? {} : { backingIndex: mapReference(constraint.backingIndex) },
266
- ...constraint.deferrable === void 0 ? {} : { deferrable: constraint.deferrable },
267
- ...constraint.initially === void 0 ? {} : { initially: constraint.initially },
268
- ...constraint.validated === void 0 ? {} : { validated: constraint.validated }
269
- };
270
- const targetTable = tables.get(constraint.target.table);
271
- const targetId = targetTable?.id;
272
- if (targetId === void 0) diagnostics.push(createIntrospectionDiagnostic({
273
- severity: "error",
274
- code: "unresolved-reference",
275
- message: `Foreign-key target table ${constraint.target.table} was not found`,
276
- path: [
277
- constraint.id,
278
- "target",
279
- "table"
280
- ]
281
- }));
282
- const targetColumns = targetTable ? constraint.target.columns.map((column) => targetTable.columns.find((item) => item.physicalName === column)?.id ?? column) : constraint.target.columns;
283
- return {
284
- kind: "foreign-key",
285
- ...common,
286
- columns: mappedColumns ?? [],
287
- target: {
288
- table: {
289
- kind: "table",
290
- id: targetId ?? constraint.target.table
291
- },
292
- columns: targetColumns
293
- },
294
- ...constraint.onUpdate === void 0 ? {} : { onUpdate: constraint.onUpdate },
295
- ...constraint.onDelete === void 0 ? {} : { onDelete: constraint.onDelete },
296
- ...constraint.match === void 0 ? {} : { match: constraint.match },
297
- ...constraint.deferrable === void 0 ? {} : { deferrable: constraint.deferrable },
298
- ...constraint.initially === void 0 ? {} : { initially: constraint.initially },
299
- ...constraint.validated === void 0 ? {} : { validated: constraint.validated }
300
- };
301
- }
302
- function mapIndex(index, dialect, columns) {
303
- return {
304
- kind: "index",
305
- id: index.id,
306
- physicalName: index.physicalName ?? index.id,
307
- terms: index.terms.map((term) => mapIndexTerm(term, columns)).filter((term) => term !== void 0).sort((left, right) => left.position - right.position),
308
- unique: index.unique,
309
- candidateKey: index.unique,
310
- ...index.predicate === void 0 ? {} : { predicate: mapExpression(index.predicate) },
311
- ...index.includedColumns === void 0 ? {} : { includedColumns: index.includedColumns.map((column) => columns.get(column) ?? column) },
312
- ...index.backingConstraint === void 0 ? {} : { backingConstraint: mapReference(index.backingConstraint) },
313
- ...index.method === void 0 ? {} : { method: index.method },
314
- ...mapMetadata(void 0, index.dialect, dialect, index.reference)
315
- };
316
- }
317
- function mapIndexTerm(term, columns) {
318
- if (term.kind === "column") return {
319
- kind: "column",
320
- column: columns.get(term.column) ?? term.column,
321
- position: term.position,
322
- ...term.direction === void 0 ? {} : { direction: term.direction },
323
- ...term.nulls === void 0 ? {} : { nulls: term.nulls },
324
- ...term.prefixLength === void 0 ? {} : { prefixLength: mapValueFact(term.prefixLength) },
325
- ...term.operatorClass === void 0 ? {} : { operatorClass: term.operatorClass }
326
- };
327
- return {
328
- kind: "expression",
329
- expression: mapExpression(term.expression),
330
- position: term.position,
331
- ...term.direction === void 0 ? {} : { direction: term.direction },
332
- ...term.nulls === void 0 ? {} : { nulls: term.nulls },
333
- ...term.operatorClass === void 0 ? {} : { operatorClass: term.operatorClass }
334
- };
335
- }
336
- function mapView(view, dialect) {
337
- return {
338
- kind: view.kind,
339
- id: view.id,
340
- physicalName: view.physicalName,
341
- columns: view.columns.map((column) => mapColumn(column, dialect)).sort(compareId),
342
- definition: mapExpression(view.definition),
343
- ...view.dependencies === void 0 ? {} : { dependencies: view.dependencies.map(mapReference) },
344
- ...view.checkOption === void 0 ? {} : { checkOption: view.checkOption },
345
- ...view.securityBarrier === void 0 ? {} : { securityBarrier: view.securityBarrier },
346
- ...view.securityInvoker === void 0 ? {} : { securityInvoker: view.securityInvoker },
347
- ...mapMetadata(view.provenance, view.dialect, dialect, view.reference)
348
- };
349
- }
350
- function mapSequence(sequence, dialect) {
351
- return {
352
- kind: "sequence",
353
- id: sequence.id,
354
- physicalName: sequence.physicalName,
355
- ...sequence.storage === void 0 ? {} : { storage: mapStorage(sequence.storage, dialect) },
356
- ...sequence.start === void 0 ? {} : { start: mapValueFact(sequence.start) },
357
- ...sequence.increment === void 0 ? {} : { increment: mapValueFact(sequence.increment) },
358
- ...sequence.minimum === void 0 ? {} : { minimum: mapValueFact(sequence.minimum) },
359
- ...sequence.maximum === void 0 ? {} : { maximum: mapValueFact(sequence.maximum) },
360
- ...sequence.cache === void 0 ? {} : { cache: mapValueFact(sequence.cache) },
361
- ...sequence.cycle === void 0 ? {} : { cycle: sequence.cycle },
362
- ...sequence.ownedBy === void 0 ? {} : { ownedBy: mapReference(sequence.ownedBy) },
363
- ...sequence.identity === void 0 ? {} : { identity: mapIdentity(sequence.identity, dialect) },
364
- ...mapMetadata(sequence.provenance, sequence.dialect, dialect, sequence.reference)
365
- };
366
- }
367
- function mapEnum(item, dialect) {
368
- return {
369
- kind: "enum",
370
- id: item.id,
371
- physicalName: item.physicalName,
372
- values: [...item.values].sort((left, right) => left.ordinalPosition - right.ordinalPosition).map((value) => ({
373
- value: value.value,
374
- ordinalPosition: value.ordinalPosition,
375
- ...value.provenance === void 0 ? {} : { provenance: mapProvenance(value.provenance) }
376
- })),
377
- ...mapMetadata(item.provenance, item.dialect, dialect, item.reference)
378
- };
379
- }
380
- function mapDomain(domain, dialect) {
381
- return {
382
- kind: "domain",
383
- id: domain.id,
384
- physicalName: domain.physicalName,
385
- storage: mapStorage(domain.storage, dialect),
386
- ...domain.nullable === void 0 ? {} : { nullable: domain.nullable },
387
- ...domain.default === void 0 ? {} : { default: mapValueFact(domain.default) },
388
- ...domain.constraints === void 0 ? {} : { constraints: domain.constraints.map((constraint) => mapCheckConstraint(constraint, dialect)).sort(compareId) },
389
- ...mapMetadata(domain.provenance, domain.dialect, dialect, domain.reference)
390
- };
391
- }
392
- function mapCheckConstraint(constraint, dialect) {
393
- return {
394
- kind: "check",
395
- id: constraint.id,
396
- physicalName: constraint.physicalName ?? constraint.id,
397
- expression: mapExpression(constraint.expression),
398
- ...constraint.deferrable === void 0 ? {} : { deferrable: constraint.deferrable },
399
- ...constraint.initially === void 0 ? {} : { initially: constraint.initially },
400
- ...constraint.validated === void 0 ? {} : { validated: constraint.validated },
401
- ...mapMetadata(constraint.provenance, constraint.dialect, dialect, constraint.reference)
402
- };
403
- }
404
- function mapTrigger(trigger, dialect, _diagnostics) {
405
- return {
406
- kind: "trigger",
407
- id: trigger.id,
408
- physicalName: trigger.physicalName,
409
- table: mapReference(trigger.table),
410
- timing: trigger.timing,
411
- events: [...trigger.events].sort(),
412
- ...trigger.orientation === void 0 ? {} : { orientation: trigger.orientation },
413
- ...trigger.condition === void 0 ? {} : { condition: mapExpression(trigger.condition) },
414
- body: mapExpression(trigger.body),
415
- ...trigger.enabled === void 0 ? {} : { enabled: trigger.enabled },
416
- ...mapMetadata(trigger.provenance, trigger.dialect, dialect, trigger.reference)
417
- };
418
- }
419
- function mapRoutine(routine, dialect) {
420
- return {
421
- kind: "routine",
422
- id: routine.id,
423
- physicalName: routine.physicalName,
424
- routineKind: routine.routineKind,
425
- parameters: [...routine.parameters].sort((left, right) => left.ordinalPosition - right.ordinalPosition).map((parameter) => mapRoutineParameter(parameter, dialect)),
426
- ...routine.returnType === void 0 ? {} : { returnType: mapStorage(routine.returnType, dialect) },
427
- ...routine.language === void 0 ? {} : { language: routine.language },
428
- ...routine.body === void 0 ? {} : { body: mapExpression(routine.body) },
429
- ...routine.volatility === void 0 ? {} : { volatility: routine.volatility },
430
- ...routine.parallel === void 0 ? {} : { parallel: routine.parallel },
431
- ...routine.security === void 0 ? {} : { security: routine.security },
432
- ...routine.dependencies === void 0 ? {} : { dependencies: routine.dependencies.map(mapReference) },
433
- ...mapMetadata(routine.provenance, routine.dialect, dialect, routine.reference)
434
- };
435
- }
436
- function mapRoutineParameter(parameter, dialect) {
437
- return {
438
- ...parameter.name === void 0 ? {} : { name: parameter.name },
439
- ...parameter.mode === void 0 ? {} : { mode: parameter.mode },
440
- storage: mapStorage(parameter.storage, dialect),
441
- ...parameter.default === void 0 ? {} : { default: mapValueFact(parameter.default) },
442
- ordinalPosition: parameter.ordinalPosition
443
- };
444
- }
445
- function mapPartition(partition, dialect) {
446
- return {
447
- kind: "partition",
448
- id: partition.id,
449
- physicalName: partition.physicalName,
450
- parent: mapReference(partition.parent),
451
- strategy: partition.strategy,
452
- ...partition.keyColumns === void 0 ? {} : { keyColumns: [...partition.keyColumns] },
453
- ...partition.bound === void 0 ? {} : { bound: mapExpression(partition.bound) },
454
- ...partition.default === void 0 ? {} : { default: partition.default },
455
- ...mapMetadata(partition.provenance, partition.dialect, dialect, partition.reference)
456
- };
457
- }
458
- function mapPolicy(policy, dialect) {
459
- return {
460
- kind: "policy",
461
- id: policy.id,
462
- physicalName: policy.physicalName,
463
- table: mapReference(policy.table),
464
- command: policy.command,
465
- ...policy.roles === void 0 ? {} : { roles: [...policy.roles].sort() },
466
- ...policy.permissive === void 0 ? {} : { permissive: policy.permissive },
467
- ...policy.using === void 0 ? {} : { using: mapExpression(policy.using) },
468
- ...policy.check === void 0 ? {} : { check: mapExpression(policy.check) },
469
- ...mapMetadata(policy.provenance, policy.dialect, dialect, policy.reference)
470
- };
471
- }
472
- function mapExtensionObject(extension, dialect) {
473
- return {
474
- kind: "extension",
475
- id: extension.id,
476
- physicalName: extension.physicalName,
477
- extensionName: extension.extensionName,
478
- ...extension.extensionVersion === void 0 ? {} : { extensionVersion: extension.extensionVersion },
479
- ...extension.schema === void 0 ? {} : { schema: extension.schema },
480
- data: toSnapshotJsonValue(extension.data),
481
- ...extension.configuration === void 0 ? {} : { configuration: toSnapshotJsonValue(extension.configuration) },
482
- ...mapMetadata(extension.provenance, extension.dialect, dialect, extension.reference)
483
- };
484
- }
485
- function mapDeferredObject(object, dialect) {
486
- const data = object.unknownFields ? Object.fromEntries(object.unknownFields.map((field) => [field.name, toSnapshotJsonValue(isCatalogSqlExpression(field.value) ? field.value.text : field.value)])) : void 0;
487
- return {
488
- kind: "deferred-object",
489
- id: object.id ?? `deferred:${object.objectKind}:${object.physicalName}`,
490
- objectKind: object.objectKind,
491
- physicalName: object.physicalName,
492
- ...data === void 0 ? {} : { data: toSnapshotJsonValue(data) },
493
- ...mapMetadata(object.provenance, object.dialect, dialect, object.reference)
494
- };
495
- }
496
- function mapOpaqueObject(object, dialect) {
497
- return {
498
- kind: "opaque-object",
499
- id: object.id,
500
- objectKind: object.objectKind,
501
- physicalName: object.physicalName,
502
- data: toSnapshotJsonValue(object.data),
503
- ...object.sql === void 0 ? {} : { sql: mapExpression(object.sql) },
504
- ...mapMetadata(object.provenance, object.dialect, dialect, object.reference)
505
- };
506
- }
507
- function mapComment(comment, dialect) {
508
- return {
509
- kind: "comment",
510
- id: comment.id,
511
- physicalName: comment.reference?.name ?? comment.id,
512
- object: mapReference(comment.object),
513
- text: comment.text,
514
- ...mapMetadata(comment.provenance, comment.dialect, dialect, comment.reference)
515
- };
516
- }
517
- function mapOwnership(ownership, dialect) {
518
- return {
519
- kind: "ownership",
520
- id: ownership.id,
521
- physicalName: ownership.reference?.name ?? ownership.id,
522
- object: mapReference(ownership.object),
523
- owner: ownership.owner,
524
- ...mapMetadata(ownership.provenance, ownership.dialect, dialect, ownership.reference)
525
- };
526
- }
527
- function mapStorage(storage, dialect) {
528
- if (storage.portable !== void 0) return {
529
- kind: "portable",
530
- type: storage.portable.type
531
- };
532
- return {
533
- kind: "native",
534
- dialect,
535
- type: storage.nativeType
536
- };
537
- }
538
- function mapValueFact(value) {
539
- if (value.kind === "literal") return {
540
- kind: "literal",
541
- value: mapLiteral(value)
542
- };
543
- return {
544
- kind: "expression",
545
- expression: mapExpression(value.expression)
546
- };
547
- }
548
- function mapLiteral(value) {
549
- if (value.value === null) return { kind: "null" };
550
- if (typeof value.value === "boolean") return {
551
- kind: "boolean",
552
- value: value.value
553
- };
554
- if (typeof value.value === "bigint") return {
555
- kind: "bigint",
556
- value: value.value.toString()
557
- };
558
- if (typeof value.value === "number") return {
559
- kind: "number",
560
- value: String(value.value)
561
- };
562
- return {
563
- kind: "string",
564
- value: value.value
565
- };
566
- }
567
- function mapIdentity(identity, dialect) {
568
- return {
569
- kind: "identity",
570
- generation: identity.generation,
571
- options: Object.fromEntries(Object.entries(identity.options).map(([key, value]) => [key, mapValueFact(value)])),
572
- ...mapMetadata(void 0, identity.dialect, dialect)
573
- };
574
- }
575
- function mapExpression(value) {
576
- return {
577
- kind: "expression",
578
- expressionKind: "unsafe",
579
- sql: value.text.replace(/\r\n?/g, "\n").trim(),
580
- dialect: value.dialect
581
- };
582
- }
583
- function mapMetadata(provenance, extension, dialect, reference) {
584
- const mappedProvenance = provenance ? mapProvenance(provenance) : void 0;
585
- const mappedExtension = extension ? {
586
- dialect: extension.dialect,
587
- version: extension.version,
588
- data: toSnapshotJsonValue(extension.data)
589
- } : void 0;
590
- const physicalReference = reference ? {
591
- kind: reference.kind,
592
- ...reference.namespace === void 0 ? {} : { namespace: reference.namespace },
593
- ...reference.table === void 0 ? {} : { table: reference.table },
594
- name: reference.name
595
- } : void 0;
596
- return {
597
- ...mappedProvenance === void 0 ? {} : { provenance: mappedProvenance },
598
- ...physicalReference === void 0 ? {} : { physicalReference },
599
- ...mappedExtension === void 0 ? {} : { dialect: mappedExtension }
600
- };
601
- }
602
- function mapProvenance(value) {
603
- return {
604
- kind: value.kind,
605
- dialect: value.dialect,
606
- ...value.path === void 0 ? {} : { path: [...value.path] }
607
- };
608
- }
609
- function mapReference(reference) {
610
- return {
611
- kind: reference.kind,
612
- id: reference.id
613
- };
614
- }
615
- function catalogObjectList(catalog) {
616
- const topLevel = [
617
- catalog.namespace,
618
- ...catalog.tables,
619
- ...catalog.views,
620
- ...catalog.sequences,
621
- ...catalog.enums,
622
- ...catalog.domains,
623
- ...catalog.collations,
624
- ...catalog.triggers,
625
- ...catalog.routines,
626
- ...catalog.partitions,
627
- ...catalog.policies,
628
- ...catalog.extensionObjects,
629
- ...catalog.deferredObjects,
630
- ...catalog.opaqueObjects,
631
- ...catalog.comments,
632
- ...catalog.ownership
633
- ];
634
- const nested = [
635
- ...catalog.tables.flatMap((table) => [
636
- ...table.columns,
637
- ...table.constraints,
638
- ...table.indexes
639
- ]),
640
- ...catalog.views.flatMap((view) => view.columns),
641
- ...catalog.domains.flatMap((domain) => domain.constraints ?? [])
642
- ];
643
- return [...topLevel, ...nested];
644
- }
645
- function catalogObjectsWithUnknownFields(catalog) {
646
- return catalogObjectList(catalog);
647
- }
648
- function mapUnknownField(object, field, dialect) {
649
- const sql = isCatalogSqlExpression(field.value) ? mapExpression(field.value) : void 0;
650
- const value = isCatalogSqlExpression(field.value) ? field.value.text : field.value;
651
- return {
652
- kind: "opaque-object",
653
- id: `unknown:${object.kind}:${object.id ?? object.physicalName ?? "object"}:${field.name}`,
654
- objectKind: "unknown-field",
655
- physicalName: object.physicalName ?? object.id ?? field.name,
656
- data: toSnapshotJsonValue({
657
- ownerKind: object.kind,
658
- ownerId: object.id ?? object.physicalName ?? field.name,
659
- field: field.name,
660
- value
661
- }),
662
- ...sql === void 0 ? {} : { sql },
663
- ...mapMetadata(field.provenance, void 0, dialect)
664
- };
665
- }
666
- function compareId(left, right) {
667
- return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
668
- }
669
- function isCatalogSqlExpression(value) {
670
- return typeof value === "object" && value !== null && !Array.isArray(value) && value.kind === "sql" && typeof value.text === "string";
671
- }
672
- //#endregion
673
- export { IntrospectionError, createCompleteIntrospectionCatalog, createIntrospectionDiagnostic, freezeIntrospectionCatalog, hasIntrospectionErrors, introspectedPhysicalIdentityPolicy, mapCatalogToCompleteSnapshot, mapCatalogToSnapshot, mapCatalogToSnapshotV2, toIntrospectionCatalog };
3
+ export { IntrospectionError, createCompleteIntrospectionCatalog, createIntrospectionDiagnostic, freezeIntrospectionCatalog, hasIntrospectionErrors, introspectedPhysicalIdentityPolicy, mapCatalogToCompleteSnapshot, mapCatalogToSnapshot, mapCatalogToSnapshotV1, toIntrospectionCatalog };
package/dist/mysql.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { V as Dialect } from "./types-DUe6eeI0.mjs";
1
+ import { Cr as onDuplicateKeyUpdate, Pt as Dialect, Sr as incoming, br as IncomingIdentity, xr as OnDuplicateKeyUpdateClause, yr as IncomingColumns } from "./types-Dqr4o2I1.mjs";
2
2
  //#region src/dialects/mysql.d.ts
3
- declare function mysqlDialect(): Dialect<"json" | "row-locking">;
3
+ declare function mysqlDialect(): Dialect<"row-locking" | "on-duplicate-key-update" | "json">;
4
4
  //#endregion
5
- export { mysqlDialect };
5
+ export { type IncomingColumns, type IncomingIdentity, type OnDuplicateKeyUpdateClause, incoming, mysqlDialect, onDuplicateKeyUpdate };