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,354 +0,0 @@
1
- import { s as assertSchemaSnapshot } from "./canonical-DMvR9yBe.mjs";
2
- import { storageAffinity } from "./snapshot/sqlite.mjs";
3
- import { n as createIntrospectionDiagnostic } from "./diagnostics-I9vVtXkc.mjs";
4
- //#region src/introspection/identity.ts
5
- /** The naming policy used by the first introspection snapshot mapper. */
6
- const introspectedPhysicalIdentityPolicy = Object.freeze({
7
- name: "introspected-physical",
8
- version: 1,
9
- fallback: "escaped",
10
- precedence: Object.freeze([
11
- "explicit-hint",
12
- "previous-snapshot",
13
- "physical-name",
14
- "deterministic-fallback"
15
- ])
16
- });
17
- //#endregion
18
- //#region src/introspection/snapshot.ts
19
- /** Construct and validate a canonical Snapshot v1 from a normalized catalog. */
20
- function mapCatalogToSnapshot(catalog, options) {
21
- const mode = options.mode ?? "strict";
22
- const diagnostics = [...catalog.diagnostics];
23
- const tables = catalog.tables.map((table) => mapTable(catalog, table, options, mode, diagnostics)).sort(compareById);
24
- const snapshot = {
25
- format: "qubu-schema",
26
- version: 1,
27
- dialect: {
28
- name: catalog.dialect,
29
- version: 1
30
- },
31
- namingPolicy: {
32
- name: introspectedPhysicalIdentityPolicy.name,
33
- version: introspectedPhysicalIdentityPolicy.version
34
- },
35
- namespace: catalog.namespace.name,
36
- tables
37
- };
38
- if (mode === "strict" && diagnostics.some(isError)) return failure(catalog, diagnostics);
39
- try {
40
- const value = assertSchemaSnapshot(snapshot);
41
- const lossy = mode === "lossy" && diagnostics.some((diagnostic) => diagnostic.severity === "warning");
42
- const result = {
43
- ok: true,
44
- catalog,
45
- snapshot: value,
46
- diagnostics: Object.freeze(diagnostics),
47
- lossy
48
- };
49
- return Object.freeze(result);
50
- } catch (error) {
51
- const severity = mode === "strict" ? "error" : "warning";
52
- diagnostics.push(createIntrospectionDiagnostic({
53
- severity,
54
- code: "invalid-catalog-row",
55
- message: error instanceof Error ? `Catalog facts could not form Snapshot v1: ${error.message}` : "Catalog facts could not form Snapshot v1",
56
- path: [],
57
- remediation: "Inspect the catalog diagnostics and unsupported features."
58
- }));
59
- return failure(catalog, diagnostics);
60
- }
61
- }
62
- function mapTable(catalog, table, options, mode, diagnostics) {
63
- const tableId = resolveId("table", table.id, table.physicalName, void 0, options);
64
- const columnIds = new Map(table.columns.map((column) => [column.physicalName, resolveId("column", column.id, column.physicalName, table.physicalName, options)]));
65
- const columns = [...table.columns].sort((left, right) => left.ordinalPosition - right.ordinalPosition).map((column) => mapColumn(catalog.dialect, table, column, options, diagnostics)).sort(compareById);
66
- const constraints = [...table.constraints].map((constraint) => mapConstraint(catalog, table, constraint, columnIds, options, mode, diagnostics)).filter((value) => value !== void 0).sort(compareById);
67
- const indexes = [...table.indexes].map((index) => mapIndex(table, index, columnIds, options, mode, diagnostics)).filter((value) => value !== void 0).sort(compareById);
68
- return {
69
- id: tableId,
70
- physicalName: table.physicalName,
71
- columns,
72
- constraints,
73
- indexes
74
- };
75
- }
76
- function mapColumn(dialect, table, column, options, diagnostics) {
77
- const defaultValue = column.default ? mapDefault(column.default, column, diagnostics) : void 0;
78
- const generated = column.generated ? mapGenerated(column.generated, column, options.mode ?? "strict", diagnostics) : void 0;
79
- const identity = column.identity ? mapIdentity(column.identity, column, diagnostics) : void 0;
80
- const storage = {
81
- kind: "native",
82
- dialect,
83
- type: column.storage.nativeType,
84
- ...dialect === "sqlite" ? { affinity: storageAffinity(column.storage.nativeType) } : {}
85
- };
86
- return {
87
- id: resolveId("column", column.id, column.physicalName, table.physicalName, options),
88
- physicalName: column.physicalName,
89
- nullable: column.nullable,
90
- hasDefault: defaultValue !== void 0,
91
- generated: generated !== void 0 || identity !== void 0,
92
- storage,
93
- default: defaultValue,
94
- generatedColumn: generated,
95
- identity,
96
- onUpdate: column.onUpdate ? mapExpression(column.onUpdate) : void 0
97
- };
98
- }
99
- function mapConstraint(catalog, table, constraint, columnIds, options, mode, diagnostics) {
100
- const physicalName = constraint.physicalName ?? constraint.id;
101
- const id = resolveId("constraint", constraint.id, physicalName, table.physicalName, options);
102
- if (constraint.kind === "check") return {
103
- id,
104
- kind: "check",
105
- physicalName,
106
- expression: mapExpression(constraint.expression),
107
- deferrable: constraint.deferrable,
108
- initially: constraint.initially,
109
- dialect: mapExtension(constraint.dialect)
110
- };
111
- const columns = constraint.columns.map((column) => {
112
- const value = columnIds.get(column);
113
- if (value) return value;
114
- addIssue(mode, diagnostics, "unresolved-reference", `Constraint column ${column} was not found`, constraint);
115
- return column;
116
- });
117
- if (constraint.kind === "primary-key") return {
118
- id,
119
- kind: "primary-key",
120
- physicalName,
121
- columns,
122
- deferrable: constraint.deferrable,
123
- initially: constraint.initially,
124
- dialect: mapExtension(constraint.dialect)
125
- };
126
- if (constraint.kind === "unique") {
127
- if (constraint.columns.some((column) => table.columns.find((candidate) => candidate.physicalName === column)?.nullable) || constraint.nulls === "not-distinct") return {
128
- id,
129
- kind: "unique-constraint",
130
- physicalName,
131
- columns,
132
- nulls: constraint.nulls,
133
- deferrable: constraint.deferrable,
134
- initially: constraint.initially,
135
- dialect: mapExtension(constraint.dialect)
136
- };
137
- return {
138
- id,
139
- kind: "unique",
140
- physicalName,
141
- columns,
142
- deferrable: constraint.deferrable,
143
- initially: constraint.initially,
144
- dialect: mapExtension(constraint.dialect)
145
- };
146
- }
147
- const targetTable = catalog.tables.find((candidate) => candidate.physicalName === constraint.target.table);
148
- if (!targetTable) {
149
- addIssue(mode, diagnostics, "unresolved-reference", `Foreign key target table ${constraint.target.table} was not found`, constraint);
150
- return;
151
- }
152
- return {
153
- id,
154
- kind: "foreign-key",
155
- physicalName,
156
- columns,
157
- target: {
158
- table: resolveId("table", targetTable.id, targetTable.physicalName, void 0, options),
159
- columns: constraint.target.columns.map((column) => {
160
- const target = targetTable.columns.find((candidate) => candidate.physicalName === column);
161
- if (target) return resolveId("column", target.id, target.physicalName, targetTable.physicalName, options);
162
- addIssue(mode, diagnostics, "unresolved-reference", `Foreign key target column ${column} was not found`, constraint);
163
- return column;
164
- })
165
- },
166
- onUpdate: constraint.onUpdate,
167
- onDelete: constraint.onDelete,
168
- match: constraint.match,
169
- deferrable: constraint.deferrable,
170
- initially: constraint.initially,
171
- dialect: mapExtension(constraint.dialect)
172
- };
173
- }
174
- function mapIndex(table, index, columnIds, options, mode, diagnostics) {
175
- const physicalName = index.physicalName ?? index.id;
176
- const id = resolveId("index", index.id, physicalName, table.physicalName, options);
177
- const terms = [...index.terms].sort((left, right) => left.position - right.position).map((term) => mapIndexTerm(term, columnIds, index, mode, diagnostics)).filter((value) => value !== void 0);
178
- const includedColumns = index.includedColumns?.map((column) => {
179
- const value = columnIds.get(column);
180
- if (value) return value;
181
- addIssue(mode, diagnostics, "unresolved-reference", `Index column ${column} was not found`, index);
182
- return column;
183
- });
184
- const candidateKey = index.unique && index.predicate === void 0 && index.terms.every((term) => term.kind === "column" && table.columns.find((column) => column.physicalName === term.column)?.nullable === false);
185
- return {
186
- id,
187
- kind: "index",
188
- physicalName,
189
- terms,
190
- unique: index.unique,
191
- candidateKey,
192
- predicate: index.predicate ? mapExpression(index.predicate) : void 0,
193
- includedColumns,
194
- dialect: mapExtension(index.dialect)
195
- };
196
- }
197
- function mapIndexTerm(term, columnIds, index, mode, diagnostics) {
198
- let expression;
199
- if (term.kind === "column") {
200
- const column = columnIds.get(term.column);
201
- if (!column) {
202
- addIssue(mode, diagnostics, "unresolved-reference", `Index column ${term.column} was not found`, index);
203
- return;
204
- }
205
- expression = {
206
- kind: "column",
207
- column
208
- };
209
- if (term.prefixLength !== void 0 || term.operatorClass !== void 0) addIssue(mode, diagnostics, "unsupported-feature", "Index term metadata is not represented by Snapshot v1", index);
210
- } else {
211
- expression = {
212
- kind: "expression",
213
- expression: mapExpression(term.expression)
214
- };
215
- if (term.operatorClass !== void 0) addIssue(mode, diagnostics, "unsupported-feature", "Index operator classes are not represented by Snapshot v1", index);
216
- }
217
- if (term.direction === void 0 && term.nulls === void 0) return expression;
218
- return {
219
- kind: "order",
220
- expression,
221
- direction: term.direction,
222
- nulls: term.nulls
223
- };
224
- }
225
- function mapDefault(value, owner, diagnostics) {
226
- if (value.kind === "literal") return {
227
- kind: "literal",
228
- value: mapLiteral(value)
229
- };
230
- if (value.expression.text.trim().length === 0) diagnostics.push(createIntrospectionDiagnostic({
231
- severity: "error",
232
- code: "invalid-catalog-row",
233
- message: "A default expression was empty",
234
- path: [owner.id, "default"],
235
- remediation: "Return the database expression or omit the default fact."
236
- }));
237
- return {
238
- kind: "expression",
239
- expression: mapExpression(value.expression)
240
- };
241
- }
242
- function mapGenerated(value, owner, mode, diagnostics) {
243
- if (value.mode === "unknown") {
244
- addIssue(mode, diagnostics, "unsupported-feature", "Generated-column storage mode was not recovered", owner);
245
- return { kind: "external" };
246
- }
247
- return {
248
- kind: "expression",
249
- expression: mapExpression(value.expression),
250
- mode: value.mode
251
- };
252
- }
253
- function mapIdentity(value, owner, diagnostics) {
254
- if (Object.keys(value.options).length > 0) diagnostics.push(createIntrospectionDiagnostic({
255
- severity: "warning",
256
- code: "lossy-mapping",
257
- message: "Identity sequence options are not represented by Snapshot v1",
258
- path: [owner.id, "identity"],
259
- remediation: "Use the normalized catalog for options or add a typed dialect extension."
260
- }));
261
- return {
262
- kind: "identity",
263
- generation: value.generation,
264
- dialect: mapExtension(value.dialect)
265
- };
266
- }
267
- function mapExpression(value) {
268
- return {
269
- kind: "expression",
270
- expressionKind: "unsafe",
271
- sql: value.text.replace(/\r\n?/g, "\n").trim(),
272
- dialect: value.dialect
273
- };
274
- }
275
- function mapLiteral(value) {
276
- if (value.value === null) return { kind: "null" };
277
- if (typeof value.value === "boolean") return {
278
- kind: "boolean",
279
- value: value.value
280
- };
281
- if (typeof value.value === "bigint") return {
282
- kind: "bigint",
283
- value: value.value.toString()
284
- };
285
- if (typeof value.value === "number") return {
286
- kind: "number",
287
- value: String(value.value)
288
- };
289
- return {
290
- kind: "string",
291
- value: value.value
292
- };
293
- }
294
- function mapExtension(value) {
295
- if (!value) return;
296
- return {
297
- dialect: value.dialect,
298
- version: value.version,
299
- data: toSnapshotData(value.data)
300
- };
301
- }
302
- function toSnapshotData(value) {
303
- if (typeof value === "bigint") return { $bigint: value.toString() };
304
- if (Array.isArray(value)) return value.map(toSnapshotData);
305
- if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toSnapshotData(child)]));
306
- return value;
307
- }
308
- function resolveId(kind, currentId, physicalName, tablePhysicalName, options) {
309
- const hint = options.identityHints?.find((candidate) => candidate.kind === kind && candidate.physicalName === physicalName && candidate.tablePhysicalName === tablePhysicalName);
310
- if (hint) return hint.logicalId;
311
- const previous = options.previousSnapshot;
312
- if (previous) {
313
- const table = tablePhysicalName ? previous.tables.find((candidate) => candidate.physicalName === tablePhysicalName) : previous.tables.find((candidate) => candidate.physicalName === physicalName);
314
- if (kind === "table" && table) return table.id;
315
- if (table && kind === "column") {
316
- const column = table.columns.find((candidate) => candidate.physicalName === physicalName);
317
- if (column) return column.id;
318
- }
319
- if (table && kind === "constraint") {
320
- const constraint = table.constraints.find((candidate) => candidate.physicalName === physicalName);
321
- if (constraint) return constraint.id;
322
- }
323
- if (table && kind === "index") {
324
- const index = table.indexes.find((candidate) => candidate.physicalName === physicalName);
325
- if (index) return index.id;
326
- }
327
- }
328
- return currentId || physicalName;
329
- }
330
- function addIssue(mode, diagnostics, code, message, owner) {
331
- diagnostics.push(createIntrospectionDiagnostic({
332
- severity: mode === "strict" ? "error" : "warning",
333
- code,
334
- message,
335
- path: owner.id ? [owner.id] : [],
336
- remediation: "Use lossy mode or add a typed dialect mapping for this feature."
337
- }));
338
- }
339
- function failure(catalog, diagnostics) {
340
- return Object.freeze({
341
- ok: false,
342
- catalog,
343
- diagnostics: Object.freeze([...diagnostics]),
344
- lossy: false
345
- });
346
- }
347
- function compareById(left, right) {
348
- return left.id.localeCompare(right.id);
349
- }
350
- function isError(value) {
351
- return value.severity === "error";
352
- }
353
- //#endregion
354
- export { introspectedPhysicalIdentityPolicy as n, mapCatalogToSnapshot as t };