qubu 0.0.0 → 0.3.4
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/dist/canonical-BbnqavJm.mjs +972 -0
- package/dist/codegen.d.mts +107 -0
- package/dist/codegen.mjs +1199 -0
- package/dist/column-CXMxx8Hq.mjs +118 -0
- package/dist/complete-D5Djh-zo.mjs +1788 -0
- package/dist/complete-types-BdFqUfbb.d.mts +371 -0
- package/dist/core.d.mts +33 -0
- package/dist/core.mjs +36 -0
- package/dist/ddl.d.mts +118 -0
- package/dist/ddl.mjs +1120 -0
- package/dist/dialect-b2-Z6uBF.mjs +13 -0
- package/dist/diff.d.mts +2 -0
- package/dist/diff.mjs +883 -0
- package/dist/drizzle-mysql.d.mts +24 -0
- package/dist/drizzle-mysql.mjs +72 -0
- package/dist/drizzle-postgres.d.mts +24 -0
- package/dist/drizzle-postgres.mjs +73 -0
- package/dist/drizzle-sqlite.d.mts +24 -0
- package/dist/drizzle-sqlite.mjs +82 -0
- package/dist/drizzle.d.mts +13 -0
- package/dist/drizzle.mjs +2 -0
- package/dist/errors-BGCoLe_r.mjs +14 -0
- package/dist/errors-Dxv73YJu.mjs +26 -0
- package/dist/explain-CkIK13L_.mjs +98 -0
- package/dist/index-Ds7-mhJi.d.mts +146 -0
- package/dist/index-Dug5HnLB.d.mts +204 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1276 -0
- package/dist/introspection.d.mts +117 -0
- package/dist/introspection.mjs +4341 -0
- package/dist/json-CUZlv4HT.mjs +169 -0
- package/dist/migration.d.mts +215 -0
- package/dist/migration.mjs +1161 -0
- package/dist/mysql-DqkqXB6A.mjs +355 -0
- package/dist/mysql.d.mts +5 -0
- package/dist/mysql.mjs +50 -0
- package/dist/naming-QVCOnSj2.mjs +20 -0
- package/dist/omit-OxV58AwX.mjs +5 -0
- package/dist/on-conflict-BxnxubMb.mjs +143 -0
- package/dist/postgres-DEBBeh52.mjs +235 -0
- package/dist/postgres.d.mts +123 -0
- package/dist/postgres.mjs +52 -0
- package/dist/registry-BufIskVN.mjs +569 -0
- package/dist/relational-DCZrrNia.mjs +77 -0
- package/dist/runtime-BTr-MTlo.mjs +193 -0
- package/dist/schema.d.mts +2 -0
- package/dist/schema.mjs +5 -0
- package/dist/serialize-PF1cfH2P.mjs +556 -0
- package/dist/snapshot-CWPgzxNx.mjs +392 -0
- package/dist/snapshot.d.mts +4 -0
- package/dist/snapshot.mjs +8 -0
- package/dist/source-DUoJVXmL.mjs +68 -0
- package/dist/sqlite-BU6DBxef.mjs +320 -0
- package/dist/sqlite.d.mts +5 -0
- package/dist/sqlite.mjs +48 -0
- package/dist/standard-BTVYKh_F.mjs +12 -0
- package/dist/table-llv9tsZ8.mjs +384 -0
- package/dist/types-4Q076HKo.d.mts +3636 -0
- package/dist/types-BX0mckiU.d.mts +644 -0
- package/dist/types-Cec0xzo4.mjs +116 -0
- package/dist/types-H4vyCw8_.d.mts +45 -0
- package/dist/value-BvilP0oz.mjs +29 -0
- package/dist/vite/ambient.d.ts +449 -0
- package/dist/vite.d.mts +35 -0
- package/dist/vite.mjs +498 -0
- package/docs/config.json +21 -0
- package/docs/dialects-and-execution.md +427 -0
- package/docs/getting-started.md +96 -0
- package/docs/guides/compose-queries.md +225 -0
- package/docs/guides/drizzle.md +130 -0
- package/docs/guides/extensions/dialects.md +40 -0
- package/docs/guides/extensions/overview.md +36 -0
- package/docs/guides/extensions/sources-and-clauses.md +82 -0
- package/docs/guides/extensions/typed-expressions.md +94 -0
- package/docs/guides/extensions/unsafe-syntax.md +27 -0
- package/docs/guides/json.md +65 -0
- package/docs/guides/mutations.md +138 -0
- package/docs/guides/select/conditions.md +110 -0
- package/docs/guides/select/grouping-and-windows.md +82 -0
- package/docs/guides/select/ordering-and-pagination.md +78 -0
- package/docs/guides/select/overview.md +139 -0
- package/docs/guides/sql-templates.md +157 -0
- package/docs/guides/vite-plugin.md +92 -0
- package/docs/index.md +111 -0
- package/docs/query-model/fragments.md +109 -0
- package/docs/query-model/result-shapes.md +125 -0
- package/docs/query-model/source-scope.md +182 -0
- package/docs/reference/introspection-support.md +196 -0
- package/docs/reference/mysql-snapshot.md +55 -0
- package/docs/reference/postgres-snapshot.md +61 -0
- package/docs/reference/sqlite-snapshot.md +53 -0
- package/docs/reference/supported-surface.md +104 -0
- package/docs/schema/catalog-model.md +58 -0
- package/docs/schema/code-generation.md +139 -0
- package/docs/schema/columns-and-writes.md +130 -0
- package/docs/schema/constraints-and-indexes.md +180 -0
- package/docs/schema/ddl-emission.md +75 -0
- package/docs/schema/diff.md +75 -0
- package/docs/schema/introspection.md +214 -0
- package/docs/schema/migration-plans.md +76 -0
- package/docs/schema/snapshots.md +93 -0
- package/docs/schema/storage-and-schema-sql.md +104 -0
- package/docs/schema/tables-and-names.md +106 -0
- package/docs/sql-semantic-types.md +141 -0
- package/docs/troubleshooting.md +151 -0
- package/package.json +132 -10
- package/skills/qubu/SKILL.md +42 -0
- package/skills/qubu/agents/openai.yaml +6 -0
- package/readme.md +0 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { s as assertSchemaSnapshot } from "./canonical-BbnqavJm.mjs";
|
|
2
|
+
import { a as sqliteStorageAffinity } from "./sqlite-BU6DBxef.mjs";
|
|
3
|
+
//#region src/introspection/diagnostics.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create one immutable diagnostic without interpreting catalog text or
|
|
6
|
+
* copying driver error details into the structured fields.
|
|
7
|
+
*/
|
|
8
|
+
function createIntrospectionDiagnostic(diagnostic) {
|
|
9
|
+
return freezeDiagnostic(diagnostic);
|
|
10
|
+
}
|
|
11
|
+
/** Return whether a diagnostic list prevents strict introspection output. */
|
|
12
|
+
function hasIntrospectionErrors(diagnostics) {
|
|
13
|
+
return diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
14
|
+
}
|
|
15
|
+
/** Error raised by a throwing introspection operation after collecting findings. */
|
|
16
|
+
var IntrospectionError = class extends Error {
|
|
17
|
+
name = "IntrospectionError";
|
|
18
|
+
diagnostics;
|
|
19
|
+
issues;
|
|
20
|
+
constructor(diagnostics) {
|
|
21
|
+
const frozenDiagnostics = Object.freeze(diagnostics.map((diagnostic) => freezeDiagnostic(diagnostic)));
|
|
22
|
+
super(frozenDiagnostics.map((diagnostic) => diagnostic.message).join("\n"));
|
|
23
|
+
this.diagnostics = frozenDiagnostics;
|
|
24
|
+
this.issues = frozenDiagnostics;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function freezeDiagnostic(diagnostic) {
|
|
28
|
+
return Object.freeze({
|
|
29
|
+
...diagnostic,
|
|
30
|
+
path: Object.freeze([...diagnostic.path]),
|
|
31
|
+
physicalReference: diagnostic.physicalReference ? freezeReference(diagnostic.physicalReference) : void 0,
|
|
32
|
+
relatedReferences: diagnostic.relatedReferences ? Object.freeze(diagnostic.relatedReferences.map((reference) => freezeReference(reference))) : void 0
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function freezeReference(reference) {
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
...reference,
|
|
38
|
+
catalog: reference.catalog ? Object.freeze({ ...reference.catalog }) : void 0
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/introspection/identity.ts
|
|
43
|
+
/** The naming policy used by the first introspection snapshot mapper. */
|
|
44
|
+
const introspectedPhysicalIdentityPolicy = Object.freeze({
|
|
45
|
+
name: "introspected-physical",
|
|
46
|
+
version: 1,
|
|
47
|
+
fallback: "escaped",
|
|
48
|
+
precedence: Object.freeze([
|
|
49
|
+
"explicit-hint",
|
|
50
|
+
"previous-snapshot",
|
|
51
|
+
"physical-name",
|
|
52
|
+
"deterministic-fallback"
|
|
53
|
+
])
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/introspection/snapshot.ts
|
|
57
|
+
/** Construct and validate a canonical Snapshot v1 from a normalized catalog. */
|
|
58
|
+
function mapCatalogToSnapshot(catalog, options) {
|
|
59
|
+
const mode = options.mode ?? "strict";
|
|
60
|
+
const diagnostics = [...catalog.diagnostics];
|
|
61
|
+
const tables = catalog.tables.map((table) => mapTable(catalog, table, options, mode, diagnostics)).sort(compareById);
|
|
62
|
+
const snapshot = {
|
|
63
|
+
format: "qubu-schema",
|
|
64
|
+
version: 1,
|
|
65
|
+
dialect: {
|
|
66
|
+
name: catalog.dialect,
|
|
67
|
+
version: 1
|
|
68
|
+
},
|
|
69
|
+
namingPolicy: {
|
|
70
|
+
name: introspectedPhysicalIdentityPolicy.name,
|
|
71
|
+
version: introspectedPhysicalIdentityPolicy.version
|
|
72
|
+
},
|
|
73
|
+
namespace: catalog.namespace.name,
|
|
74
|
+
tables
|
|
75
|
+
};
|
|
76
|
+
if (mode === "strict" && diagnostics.some(isError)) return failure(catalog, diagnostics);
|
|
77
|
+
try {
|
|
78
|
+
const value = assertSchemaSnapshot(snapshot);
|
|
79
|
+
const lossy = mode === "lossy" && diagnostics.some((diagnostic) => diagnostic.severity === "warning");
|
|
80
|
+
const result = {
|
|
81
|
+
ok: true,
|
|
82
|
+
catalog,
|
|
83
|
+
snapshot: value,
|
|
84
|
+
diagnostics: Object.freeze(diagnostics),
|
|
85
|
+
lossy
|
|
86
|
+
};
|
|
87
|
+
return Object.freeze(result);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const severity = mode === "strict" ? "error" : "warning";
|
|
90
|
+
diagnostics.push(createIntrospectionDiagnostic({
|
|
91
|
+
severity,
|
|
92
|
+
code: "invalid-catalog-row",
|
|
93
|
+
message: error instanceof Error ? `Catalog facts could not form Snapshot v1: ${error.message}` : "Catalog facts could not form Snapshot v1",
|
|
94
|
+
path: [],
|
|
95
|
+
remediation: "Inspect the catalog diagnostics and unsupported features."
|
|
96
|
+
}));
|
|
97
|
+
return failure(catalog, diagnostics);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function mapTable(catalog, table, options, mode, diagnostics) {
|
|
101
|
+
const tableId = resolveId("table", table.id, table.physicalName, void 0, options);
|
|
102
|
+
const columnIds = new Map(table.columns.map((column) => [column.physicalName, resolveId("column", column.id, column.physicalName, table.physicalName, options)]));
|
|
103
|
+
const columns = [...table.columns].sort((left, right) => left.ordinalPosition - right.ordinalPosition).map((column) => mapColumn(catalog.dialect, table, column, options, diagnostics)).sort(compareById);
|
|
104
|
+
const constraints = [...table.constraints].map((constraint) => mapConstraint(catalog, table, constraint, columnIds, options, mode, diagnostics)).filter((value) => value !== void 0).sort(compareById);
|
|
105
|
+
const indexes = [...table.indexes].map((index) => mapIndex(table, index, columnIds, options, mode, diagnostics)).filter((value) => value !== void 0).sort(compareById);
|
|
106
|
+
return {
|
|
107
|
+
id: tableId,
|
|
108
|
+
physicalName: table.physicalName,
|
|
109
|
+
columns,
|
|
110
|
+
constraints,
|
|
111
|
+
indexes
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function mapColumn(dialect, table, column, options, diagnostics) {
|
|
115
|
+
const defaultValue = column.default ? mapDefault(column.default, column, diagnostics) : void 0;
|
|
116
|
+
const generated = column.generated ? mapGenerated(column.generated, column, options.mode ?? "strict", diagnostics) : void 0;
|
|
117
|
+
const identity = column.identity ? mapIdentity(column.identity, column, diagnostics) : void 0;
|
|
118
|
+
const storage = {
|
|
119
|
+
kind: "native",
|
|
120
|
+
dialect,
|
|
121
|
+
type: column.storage.nativeType,
|
|
122
|
+
...dialect === "sqlite" ? { affinity: sqliteStorageAffinity(column.storage.nativeType) } : {}
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
id: resolveId("column", column.id, column.physicalName, table.physicalName, options),
|
|
126
|
+
physicalName: column.physicalName,
|
|
127
|
+
nullable: column.nullable,
|
|
128
|
+
hasDefault: defaultValue !== void 0,
|
|
129
|
+
generated: generated !== void 0 || identity !== void 0,
|
|
130
|
+
storage,
|
|
131
|
+
default: defaultValue,
|
|
132
|
+
generatedColumn: generated,
|
|
133
|
+
identity,
|
|
134
|
+
onUpdate: column.onUpdate ? mapExpression(column.onUpdate) : void 0
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function mapConstraint(catalog, table, constraint, columnIds, options, mode, diagnostics) {
|
|
138
|
+
const physicalName = constraint.physicalName ?? constraint.id;
|
|
139
|
+
const id = resolveId("constraint", constraint.id, physicalName, table.physicalName, options);
|
|
140
|
+
if (constraint.kind === "check") return {
|
|
141
|
+
id,
|
|
142
|
+
kind: "check",
|
|
143
|
+
physicalName,
|
|
144
|
+
expression: mapExpression(constraint.expression),
|
|
145
|
+
deferrable: constraint.deferrable,
|
|
146
|
+
initially: constraint.initially,
|
|
147
|
+
dialect: mapExtension(constraint.dialect)
|
|
148
|
+
};
|
|
149
|
+
const columns = constraint.columns.map((column) => {
|
|
150
|
+
const value = columnIds.get(column);
|
|
151
|
+
if (value) return value;
|
|
152
|
+
addIssue(mode, diagnostics, "unresolved-reference", `Constraint column ${column} was not found`, constraint);
|
|
153
|
+
return column;
|
|
154
|
+
});
|
|
155
|
+
if (constraint.kind === "primary-key") return {
|
|
156
|
+
id,
|
|
157
|
+
kind: "primary-key",
|
|
158
|
+
physicalName,
|
|
159
|
+
columns,
|
|
160
|
+
deferrable: constraint.deferrable,
|
|
161
|
+
initially: constraint.initially,
|
|
162
|
+
dialect: mapExtension(constraint.dialect)
|
|
163
|
+
};
|
|
164
|
+
if (constraint.kind === "unique") {
|
|
165
|
+
if (constraint.columns.some((column) => table.columns.find((candidate) => candidate.physicalName === column)?.nullable) || constraint.nulls === "not-distinct") return {
|
|
166
|
+
id,
|
|
167
|
+
kind: "unique-constraint",
|
|
168
|
+
physicalName,
|
|
169
|
+
columns,
|
|
170
|
+
nulls: constraint.nulls,
|
|
171
|
+
deferrable: constraint.deferrable,
|
|
172
|
+
initially: constraint.initially,
|
|
173
|
+
dialect: mapExtension(constraint.dialect)
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
id,
|
|
177
|
+
kind: "unique",
|
|
178
|
+
physicalName,
|
|
179
|
+
columns,
|
|
180
|
+
deferrable: constraint.deferrable,
|
|
181
|
+
initially: constraint.initially,
|
|
182
|
+
dialect: mapExtension(constraint.dialect)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const targetTable = catalog.tables.find((candidate) => candidate.physicalName === constraint.target.table);
|
|
186
|
+
if (!targetTable) {
|
|
187
|
+
addIssue(mode, diagnostics, "unresolved-reference", `Foreign key target table ${constraint.target.table} was not found`, constraint);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
id,
|
|
192
|
+
kind: "foreign-key",
|
|
193
|
+
physicalName,
|
|
194
|
+
columns,
|
|
195
|
+
target: {
|
|
196
|
+
table: resolveId("table", targetTable.id, targetTable.physicalName, void 0, options),
|
|
197
|
+
columns: constraint.target.columns.map((column) => {
|
|
198
|
+
const target = targetTable.columns.find((candidate) => candidate.physicalName === column);
|
|
199
|
+
if (target) return resolveId("column", target.id, target.physicalName, targetTable.physicalName, options);
|
|
200
|
+
addIssue(mode, diagnostics, "unresolved-reference", `Foreign key target column ${column} was not found`, constraint);
|
|
201
|
+
return column;
|
|
202
|
+
})
|
|
203
|
+
},
|
|
204
|
+
onUpdate: constraint.onUpdate,
|
|
205
|
+
onDelete: constraint.onDelete,
|
|
206
|
+
match: constraint.match,
|
|
207
|
+
deferrable: constraint.deferrable,
|
|
208
|
+
initially: constraint.initially,
|
|
209
|
+
dialect: mapExtension(constraint.dialect)
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function mapIndex(table, index, columnIds, options, mode, diagnostics) {
|
|
213
|
+
const physicalName = index.physicalName ?? index.id;
|
|
214
|
+
const id = resolveId("index", index.id, physicalName, table.physicalName, options);
|
|
215
|
+
const terms = [...index.terms].sort((left, right) => left.position - right.position).map((term) => mapIndexTerm(term, columnIds, index, mode, diagnostics)).filter((value) => value !== void 0);
|
|
216
|
+
const includedColumns = index.includedColumns?.map((column) => {
|
|
217
|
+
const value = columnIds.get(column);
|
|
218
|
+
if (value) return value;
|
|
219
|
+
addIssue(mode, diagnostics, "unresolved-reference", `Index column ${column} was not found`, index);
|
|
220
|
+
return column;
|
|
221
|
+
});
|
|
222
|
+
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);
|
|
223
|
+
return {
|
|
224
|
+
id,
|
|
225
|
+
kind: "index",
|
|
226
|
+
physicalName,
|
|
227
|
+
terms,
|
|
228
|
+
unique: index.unique,
|
|
229
|
+
candidateKey,
|
|
230
|
+
predicate: index.predicate ? mapExpression(index.predicate) : void 0,
|
|
231
|
+
includedColumns,
|
|
232
|
+
dialect: mapExtension(index.dialect)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function mapIndexTerm(term, columnIds, index, mode, diagnostics) {
|
|
236
|
+
let expression;
|
|
237
|
+
if (term.kind === "column") {
|
|
238
|
+
const column = columnIds.get(term.column);
|
|
239
|
+
if (!column) {
|
|
240
|
+
addIssue(mode, diagnostics, "unresolved-reference", `Index column ${term.column} was not found`, index);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
expression = {
|
|
244
|
+
kind: "column",
|
|
245
|
+
column
|
|
246
|
+
};
|
|
247
|
+
if (term.prefixLength !== void 0 || term.operatorClass !== void 0) addIssue(mode, diagnostics, "unsupported-feature", "Index term metadata is not represented by Snapshot v1", index);
|
|
248
|
+
} else {
|
|
249
|
+
expression = {
|
|
250
|
+
kind: "expression",
|
|
251
|
+
expression: mapExpression(term.expression)
|
|
252
|
+
};
|
|
253
|
+
if (term.operatorClass !== void 0) addIssue(mode, diagnostics, "unsupported-feature", "Index operator classes are not represented by Snapshot v1", index);
|
|
254
|
+
}
|
|
255
|
+
if (term.direction === void 0 && term.nulls === void 0) return expression;
|
|
256
|
+
return {
|
|
257
|
+
kind: "order",
|
|
258
|
+
expression,
|
|
259
|
+
direction: term.direction,
|
|
260
|
+
nulls: term.nulls
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function mapDefault(value, owner, diagnostics) {
|
|
264
|
+
if (value.kind === "literal") return {
|
|
265
|
+
kind: "literal",
|
|
266
|
+
value: mapLiteral(value)
|
|
267
|
+
};
|
|
268
|
+
if (value.expression.text.trim().length === 0) diagnostics.push(createIntrospectionDiagnostic({
|
|
269
|
+
severity: "error",
|
|
270
|
+
code: "invalid-catalog-row",
|
|
271
|
+
message: "A default expression was empty",
|
|
272
|
+
path: [owner.id, "default"],
|
|
273
|
+
remediation: "Return the database expression or omit the default fact."
|
|
274
|
+
}));
|
|
275
|
+
return {
|
|
276
|
+
kind: "expression",
|
|
277
|
+
expression: mapExpression(value.expression)
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function mapGenerated(value, owner, mode, diagnostics) {
|
|
281
|
+
if (value.mode === "unknown") {
|
|
282
|
+
addIssue(mode, diagnostics, "unsupported-feature", "Generated-column storage mode was not recovered", owner);
|
|
283
|
+
return { kind: "external" };
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
kind: "expression",
|
|
287
|
+
expression: mapExpression(value.expression),
|
|
288
|
+
mode: value.mode
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function mapIdentity(value, owner, diagnostics) {
|
|
292
|
+
if (Object.keys(value.options).length > 0) diagnostics.push(createIntrospectionDiagnostic({
|
|
293
|
+
severity: "warning",
|
|
294
|
+
code: "lossy-mapping",
|
|
295
|
+
message: "Identity sequence options are not represented by Snapshot v1",
|
|
296
|
+
path: [owner.id, "identity"],
|
|
297
|
+
remediation: "Use the normalized catalog for options or add a typed dialect extension."
|
|
298
|
+
}));
|
|
299
|
+
return {
|
|
300
|
+
kind: "identity",
|
|
301
|
+
generation: value.generation,
|
|
302
|
+
dialect: mapExtension(value.dialect)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function mapExpression(value) {
|
|
306
|
+
return {
|
|
307
|
+
kind: "expression",
|
|
308
|
+
expressionKind: "unsafe",
|
|
309
|
+
sql: value.text.replace(/\r\n?/g, "\n").trim(),
|
|
310
|
+
dialect: value.dialect
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function mapLiteral(value) {
|
|
314
|
+
if (value.value === null) return { kind: "null" };
|
|
315
|
+
if (typeof value.value === "boolean") return {
|
|
316
|
+
kind: "boolean",
|
|
317
|
+
value: value.value
|
|
318
|
+
};
|
|
319
|
+
if (typeof value.value === "bigint") return {
|
|
320
|
+
kind: "bigint",
|
|
321
|
+
value: value.value.toString()
|
|
322
|
+
};
|
|
323
|
+
if (typeof value.value === "number") return {
|
|
324
|
+
kind: "number",
|
|
325
|
+
value: String(value.value)
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
kind: "string",
|
|
329
|
+
value: value.value
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function mapExtension(value) {
|
|
333
|
+
if (!value) return void 0;
|
|
334
|
+
return {
|
|
335
|
+
dialect: value.dialect,
|
|
336
|
+
version: value.version,
|
|
337
|
+
data: toSnapshotData(value.data)
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function toSnapshotData(value) {
|
|
341
|
+
if (typeof value === "bigint") return { $bigint: value.toString() };
|
|
342
|
+
if (Array.isArray(value)) return value.map(toSnapshotData);
|
|
343
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toSnapshotData(child)]));
|
|
344
|
+
return value;
|
|
345
|
+
}
|
|
346
|
+
function resolveId(kind, currentId, physicalName, tablePhysicalName, options) {
|
|
347
|
+
const hint = options.identityHints?.find((candidate) => candidate.kind === kind && candidate.physicalName === physicalName && candidate.tablePhysicalName === tablePhysicalName);
|
|
348
|
+
if (hint) return hint.logicalId;
|
|
349
|
+
const previous = options.previousSnapshot;
|
|
350
|
+
if (previous) {
|
|
351
|
+
const table = tablePhysicalName ? previous.tables.find((candidate) => candidate.physicalName === tablePhysicalName) : previous.tables.find((candidate) => candidate.physicalName === physicalName);
|
|
352
|
+
if (kind === "table" && table) return table.id;
|
|
353
|
+
if (table && kind === "column") {
|
|
354
|
+
const column = table.columns.find((candidate) => candidate.physicalName === physicalName);
|
|
355
|
+
if (column) return column.id;
|
|
356
|
+
}
|
|
357
|
+
if (table && kind === "constraint") {
|
|
358
|
+
const constraint = table.constraints.find((candidate) => candidate.physicalName === physicalName);
|
|
359
|
+
if (constraint) return constraint.id;
|
|
360
|
+
}
|
|
361
|
+
if (table && kind === "index") {
|
|
362
|
+
const index = table.indexes.find((candidate) => candidate.physicalName === physicalName);
|
|
363
|
+
if (index) return index.id;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return currentId || physicalName;
|
|
367
|
+
}
|
|
368
|
+
function addIssue(mode, diagnostics, code, message, owner) {
|
|
369
|
+
diagnostics.push(createIntrospectionDiagnostic({
|
|
370
|
+
severity: mode === "strict" ? "error" : "warning",
|
|
371
|
+
code,
|
|
372
|
+
message,
|
|
373
|
+
path: owner.id ? [owner.id] : [],
|
|
374
|
+
remediation: "Use lossy mode or add a typed dialect mapping for this feature."
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
function failure(catalog, diagnostics) {
|
|
378
|
+
return Object.freeze({
|
|
379
|
+
ok: false,
|
|
380
|
+
catalog,
|
|
381
|
+
diagnostics: Object.freeze([...diagnostics]),
|
|
382
|
+
lossy: false
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function compareById(left, right) {
|
|
386
|
+
return left.id.localeCompare(right.id);
|
|
387
|
+
}
|
|
388
|
+
function isError(value) {
|
|
389
|
+
return value.severity === "error";
|
|
390
|
+
}
|
|
391
|
+
//#endregion
|
|
392
|
+
export { hasIntrospectionErrors as a, createIntrospectionDiagnostic as i, introspectedPhysicalIdentityPolicy as n, IntrospectionError as r, mapCatalogToSnapshot as t };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { A as SnapshotStorage, C as SnapshotIndexTerm, D as SnapshotLiteral, E as SnapshotKeyConstraint, F as neutralSnapshotDialect, Hs as PortableColumnStorage, I as schemaSnapshotDialectVersion, L as schemaSnapshotFormat, M as SnapshotTable, Mr as SchemaDialect, N as SnapshotUniqueConstraint, Nr as SchemaDialectHooks, O as SnapshotNamingPolicy, P as SnapshotValidationContext, Pr as createSchemaDialect, R as schemaSnapshotNamingPolicyVersion, S as SnapshotIndex, T as SnapshotJsonValue, _ as SnapshotExpressionContext, a as SnapshotBigInt, b as SnapshotGeneratedColumn, c as SnapshotConstraint, d as SnapshotDefault, f as SnapshotDiagnostic, g as SnapshotExpression, h as SnapshotDialectExtension, i as SchemaSnapshotInput, j as SnapshotStorageContext, k as SnapshotSpecialNumber, l as SnapshotCreateResult, m as SnapshotDialect, n as SchemaSnapshot, o as SnapshotCheckConstraint, p as SnapshotDiagnosticCode, r as SchemaSnapshotAdapter, s as SnapshotColumn, t as AnySchema, u as SnapshotDecodeResult, v as SnapshotExtensionContext, w as SnapshotIndexTermExpression, x as SnapshotIdentity, y as SnapshotForeignKey, z as schemaSnapshotVersion, zs as NativeColumnStorage } from "./types-4Q076HKo.mjs";
|
|
2
|
+
import { A as CompleteSnapshotProvenance, B as SchemaSnapshotV2Input, C as CompleteSnapshotObjectMetadata, D as CompleteSnapshotPartition, E as CompleteSnapshotOwnership, F as CompleteSnapshotTrigger, G as schemaSnapshotVersion2, H as completeSchemaSnapshotVersion, I as CompleteSnapshotValueFact, L as CompleteSnapshotView, M as CompleteSnapshotRoutineParameter, N as CompleteSnapshotSequence, O as CompleteSnapshotPhysicalReference, P as CompleteSnapshotTable, R as SchemaSnapshotV2, S as CompleteSnapshotObjectKind, T as CompleteSnapshotOpaqueObject, U as schemaSnapshotCompleteVersion, V as completeSchemaSnapshotFormat, W as schemaSnapshotV2Version, _ as CompleteSnapshotIndex, a as CompleteSnapshotCollation, b as CompleteSnapshotNamespace, c as CompleteSnapshotConstraint, d as CompleteSnapshotDeferredObject, f as CompleteSnapshotDomain, g as CompleteSnapshotIdentity, h as CompleteSnapshotForeignKey, i as CompleteSnapshotCheckConstraint, j as CompleteSnapshotRoutine, k as CompleteSnapshotPolicy, l as CompleteSnapshotCreateResult, m as CompleteSnapshotExtension, n as CompleteSchemaSnapshotInput, o as CompleteSnapshotColumn, p as CompleteSnapshotEnum, r as CompleteSnapshotCapabilities, s as CompleteSnapshotComment, t as CompleteSchemaSnapshot, u as CompleteSnapshotDecodeResult, v as CompleteSnapshotIndexTerm, w as CompleteSnapshotObjectReference, x as CompleteSnapshotObject, y as CompleteSnapshotKeyConstraint, z as SchemaSnapshotV2DecodeResult } from "./complete-types-BdFqUfbb.mjs";
|
|
3
|
+
import { A as assertSchemaSnapshot, B as decodeCompleteSchemaSnapshot, C as createSchemaSnapshot, D as serializeSchema, E as encodeSnapshot, F as assertCompleteSnapshot, G as encodeCompleteSnapshot, H as decodeSchemaSnapshotV2, I as assertSchemaSnapshotV2, J as SnapshotCanonicalError, K as encodeSchemaSnapshotV2, L as canonicalizeCompleteSchemaSnapshot, M as decodeSchemaSnapshot, N as CompleteSnapshotValidationError, O as tryCreateSchemaSnapshot, P as assertCompleteSchemaSnapshot, Q as toSnapshotJsonValue, R as canonicalizeSchemaSnapshotV2, S as SnapshotSerializationError, T as encodeSchemaSnapshot, U as digestCompleteSchemaSnapshot, V as decodeCompleteSnapshot, W as encodeCompleteSchemaSnapshot, X as encodeCanonicalSnapshot, Y as canonicalJson, Z as schemaSnapshotDigest, _ as postgresSchemaDialect, a as mysqlSnapshotDialect, b as tryCreatePostgresSchemaSnapshot, c as SqliteStorageAffinity, d as sqliteSnapshotAdapter, f as sqliteSnapshotDialect, g as createPostgresSchemaSnapshot, h as PostgresSnapshotOptions, i as mysqlSnapshotAdapter, j as canonicalizeSchemaSnapshot, k as SnapshotValidationError, l as createSqliteSchemaSnapshot, m as tryCreateSqliteSchemaSnapshot, n as createMysqlSchemaSnapshot, o as tryCreateMysqlSchemaSnapshot, p as sqliteStorageAffinity, q as schemaSnapshotV2Digest, r as mysqlSchemaDialect, s as SqliteSnapshotOptions, t as MysqlSnapshotOptions, u as sqliteSchemaDialect, v as postgresSnapshotAdapter, w as digestSchemaSnapshot, x as SchemaSnapshotOptions, y as postgresSnapshotDialect, z as completeSchemaSnapshotDigest } from "./index-Ds7-mhJi.mjs";
|
|
4
|
+
export { AnySchema, CompleteSchemaSnapshot, CompleteSchemaSnapshotInput, CompleteSnapshotCapabilities, CompleteSnapshotCheckConstraint, CompleteSnapshotCollation, CompleteSnapshotColumn, CompleteSnapshotComment, CompleteSnapshotConstraint, CompleteSnapshotCreateResult, CompleteSnapshotDecodeResult, CompleteSnapshotDeferredObject, CompleteSnapshotDomain, CompleteSnapshotEnum, CompleteSnapshotExtension, CompleteSnapshotForeignKey, CompleteSnapshotIdentity, CompleteSnapshotIndex, CompleteSnapshotIndexTerm, CompleteSnapshotKeyConstraint, CompleteSnapshotNamespace, CompleteSnapshotObject, CompleteSnapshotObjectKind, CompleteSnapshotObjectMetadata, CompleteSnapshotObjectReference, CompleteSnapshotOpaqueObject, CompleteSnapshotOwnership, CompleteSnapshotPartition, CompleteSnapshotPhysicalReference, CompleteSnapshotPolicy, CompleteSnapshotProvenance, CompleteSnapshotRoutine, CompleteSnapshotRoutineParameter, CompleteSnapshotSequence, CompleteSnapshotTable, CompleteSnapshotTrigger, CompleteSnapshotValidationError, CompleteSnapshotValueFact, CompleteSnapshotView, MysqlSnapshotOptions, type NativeColumnStorage, type PortableColumnStorage, PostgresSnapshotOptions, type SchemaDialect, type SchemaDialectHooks, SchemaSnapshot, SchemaSnapshotAdapter, SchemaSnapshotInput, SchemaSnapshotOptions, SchemaSnapshotV2, SchemaSnapshotV2DecodeResult, SchemaSnapshotV2Input, SnapshotBigInt, SnapshotCanonicalError, SnapshotCheckConstraint, SnapshotColumn, SnapshotConstraint, SnapshotCreateResult, SnapshotDecodeResult, SnapshotDefault, SnapshotDiagnostic, SnapshotDiagnosticCode, SnapshotDialect, SnapshotDialectExtension, SnapshotExpression, SnapshotExpressionContext, SnapshotExtensionContext, SnapshotForeignKey, SnapshotGeneratedColumn, SnapshotIdentity, SnapshotIndex, SnapshotIndexTerm, SnapshotIndexTermExpression, SnapshotJsonValue, SnapshotKeyConstraint, SnapshotLiteral, SnapshotNamingPolicy, SnapshotSerializationError, SnapshotSpecialNumber, SnapshotStorage, SnapshotStorageContext, SnapshotTable, SnapshotUniqueConstraint, SnapshotValidationContext, SnapshotValidationError, SqliteSnapshotOptions, SqliteStorageAffinity, assertCompleteSchemaSnapshot, assertCompleteSnapshot, assertSchemaSnapshot, assertSchemaSnapshotV2, canonicalJson, canonicalizeCompleteSchemaSnapshot, canonicalizeSchemaSnapshot, canonicalizeSchemaSnapshotV2, completeSchemaSnapshotDigest, completeSchemaSnapshotFormat, completeSchemaSnapshotVersion, createMysqlSchemaSnapshot, createPostgresSchemaSnapshot, createSchemaDialect, createSchemaSnapshot, createSqliteSchemaSnapshot, decodeCompleteSchemaSnapshot, decodeCompleteSnapshot, decodeSchemaSnapshot, decodeSchemaSnapshotV2, digestCompleteSchemaSnapshot, digestSchemaSnapshot, encodeCanonicalSnapshot, encodeCompleteSchemaSnapshot, encodeCompleteSnapshot, encodeSchemaSnapshot, encodeSchemaSnapshotV2, encodeSnapshot, mysqlSchemaDialect, mysqlSnapshotAdapter, mysqlSnapshotDialect, neutralSnapshotDialect, postgresSchemaDialect, postgresSnapshotAdapter, postgresSnapshotDialect, schemaSnapshotCompleteVersion, schemaSnapshotDialectVersion, schemaSnapshotDigest, schemaSnapshotFormat, schemaSnapshotNamingPolicyVersion, schemaSnapshotV2Digest, schemaSnapshotV2Version, schemaSnapshotVersion, schemaSnapshotVersion2, serializeSchema, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect, sqliteStorageAffinity, toSnapshotJsonValue, tryCreateMysqlSchemaSnapshot, tryCreatePostgresSchemaSnapshot, tryCreateSchemaSnapshot, tryCreateSqliteSchemaSnapshot };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { t as createSchemaDialect } from "./dialect-b2-Z6uBF.mjs";
|
|
2
|
+
import { a as toSnapshotJsonValue, c as canonicalizeSchemaSnapshot, d as schemaSnapshotDialectVersion, f as schemaSnapshotFormat, i as schemaSnapshotDigest, l as decodeSchemaSnapshot, m as schemaSnapshotVersion, n as canonicalJson, o as SnapshotValidationError, p as schemaSnapshotNamingPolicyVersion, r as encodeCanonicalSnapshot, s as assertSchemaSnapshot, t as SnapshotCanonicalError, u as neutralSnapshotDialect } from "./canonical-BbnqavJm.mjs";
|
|
3
|
+
import { a as encodeSnapshot, i as encodeSchemaSnapshot, n as createSchemaSnapshot, o as serializeSchema, r as digestSchemaSnapshot, s as tryCreateSchemaSnapshot, t as SnapshotSerializationError } from "./serialize-PF1cfH2P.mjs";
|
|
4
|
+
import { a as sqliteStorageAffinity, i as sqliteSnapshotDialect, n as sqliteSchemaDialect, o as tryCreateSqliteSchemaSnapshot, r as sqliteSnapshotAdapter, t as createSqliteSchemaSnapshot } from "./sqlite-BU6DBxef.mjs";
|
|
5
|
+
import { _ as completeSchemaSnapshotVersion, a as canonicalizeCompleteSchemaSnapshot, b as schemaSnapshotVersion2, c as decodeCompleteSchemaSnapshot, d as digestCompleteSchemaSnapshot, f as encodeCompleteSchemaSnapshot, g as completeSchemaSnapshotFormat, h as schemaSnapshotV2Digest, i as assertSchemaSnapshotV2, l as decodeCompleteSnapshot, m as encodeSchemaSnapshotV2, n as assertCompleteSchemaSnapshot, o as canonicalizeSchemaSnapshotV2, p as encodeCompleteSnapshot, r as assertCompleteSnapshot, s as completeSchemaSnapshotDigest, t as CompleteSnapshotValidationError, u as decodeSchemaSnapshotV2, v as schemaSnapshotCompleteVersion, y as schemaSnapshotV2Version } from "./complete-D5Djh-zo.mjs";
|
|
6
|
+
import { a as tryCreatePostgresSchemaSnapshot, i as postgresSnapshotDialect, n as postgresSchemaDialect, r as postgresSnapshotAdapter, t as createPostgresSchemaSnapshot } from "./postgres-DEBBeh52.mjs";
|
|
7
|
+
import { a as tryCreateMysqlSchemaSnapshot, i as mysqlSnapshotDialect, n as mysqlSchemaDialect, r as mysqlSnapshotAdapter, t as createMysqlSchemaSnapshot } from "./mysql-DqkqXB6A.mjs";
|
|
8
|
+
export { CompleteSnapshotValidationError, SnapshotCanonicalError, SnapshotSerializationError, SnapshotValidationError, assertCompleteSchemaSnapshot, assertCompleteSnapshot, assertSchemaSnapshot, assertSchemaSnapshotV2, canonicalJson, canonicalizeCompleteSchemaSnapshot, canonicalizeSchemaSnapshot, canonicalizeSchemaSnapshotV2, completeSchemaSnapshotDigest, completeSchemaSnapshotFormat, completeSchemaSnapshotVersion, createMysqlSchemaSnapshot, createPostgresSchemaSnapshot, createSchemaDialect, createSchemaSnapshot, createSqliteSchemaSnapshot, decodeCompleteSchemaSnapshot, decodeCompleteSnapshot, decodeSchemaSnapshot, decodeSchemaSnapshotV2, digestCompleteSchemaSnapshot, digestSchemaSnapshot, encodeCanonicalSnapshot, encodeCompleteSchemaSnapshot, encodeCompleteSnapshot, encodeSchemaSnapshot, encodeSchemaSnapshotV2, encodeSnapshot, mysqlSchemaDialect, mysqlSnapshotAdapter, mysqlSnapshotDialect, neutralSnapshotDialect, postgresSchemaDialect, postgresSnapshotAdapter, postgresSnapshotDialect, schemaSnapshotCompleteVersion, schemaSnapshotDialectVersion, schemaSnapshotDigest, schemaSnapshotFormat, schemaSnapshotNamingPolicyVersion, schemaSnapshotV2Digest, schemaSnapshotV2Version, schemaSnapshotVersion, schemaSnapshotVersion2, serializeSchema, sqliteSchemaDialect, sqliteSnapshotAdapter, sqliteSnapshotDialect, sqliteStorageAffinity, toSnapshotJsonValue, tryCreateMysqlSchemaSnapshot, tryCreatePostgresSchemaSnapshot, tryCreateSchemaSnapshot, tryCreateSqliteSchemaSnapshot };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as createColumnReference } from "./column-CXMxx8Hq.mjs";
|
|
2
|
+
import { t as resolveSqlNames } from "./naming-QVCOnSj2.mjs";
|
|
3
|
+
//#region src/schema/source.ts
|
|
4
|
+
const sourceIdentity = Symbol("qubu.source.identity");
|
|
5
|
+
function createSource(sourceKind, render, reference, constraints = {}) {
|
|
6
|
+
return {
|
|
7
|
+
sourceKind,
|
|
8
|
+
render,
|
|
9
|
+
reference,
|
|
10
|
+
columns: {},
|
|
11
|
+
constraints
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a typed source-producing fragment for a custom FROM relation such as
|
|
16
|
+
* a table-valued function. The renderer owns the relation syntax and may bind
|
|
17
|
+
* values through context.parameter(); the source identity and output columns
|
|
18
|
+
* remain available to the normal FROM/JOIN scope checks.
|
|
19
|
+
*/
|
|
20
|
+
function customSource(options) {
|
|
21
|
+
const source = createSource(options.sourceKind ?? "custom", options.render, options.reference);
|
|
22
|
+
const sqlNames = resolveSqlNames(Object.entries(options.columns).map(([fieldName, definition]) => ({
|
|
23
|
+
fieldName,
|
|
24
|
+
sqlName: definition.sqlName
|
|
25
|
+
})));
|
|
26
|
+
const columns = Object.fromEntries(Object.keys(options.columns).map((fieldName) => {
|
|
27
|
+
return [fieldName, createColumnReference(sqlNames[fieldName], source.reference, fieldName)];
|
|
28
|
+
}));
|
|
29
|
+
Object.assign(source, {
|
|
30
|
+
identity: options.identity,
|
|
31
|
+
definitions: options.columns,
|
|
32
|
+
columns
|
|
33
|
+
});
|
|
34
|
+
exposeColumns(source, columns);
|
|
35
|
+
return source;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Add convenient direct column properties without allowing a column name to
|
|
39
|
+
* overwrite the source's rendering or metadata primitives.
|
|
40
|
+
*/
|
|
41
|
+
function exposeColumns(target, columns) {
|
|
42
|
+
const reserved = /* @__PURE__ */ new Set([
|
|
43
|
+
"render",
|
|
44
|
+
"reference",
|
|
45
|
+
"sourceKind",
|
|
46
|
+
"columns",
|
|
47
|
+
"tableName",
|
|
48
|
+
"definitions",
|
|
49
|
+
"sqlNames",
|
|
50
|
+
"alias",
|
|
51
|
+
"base",
|
|
52
|
+
"query",
|
|
53
|
+
"cteName",
|
|
54
|
+
"identity",
|
|
55
|
+
"constraints"
|
|
56
|
+
]);
|
|
57
|
+
for (const [name, column] of Object.entries(columns)) {
|
|
58
|
+
if (reserved.has(name)) continue;
|
|
59
|
+
Object.defineProperty(target, name, {
|
|
60
|
+
configurable: true,
|
|
61
|
+
enumerable: true,
|
|
62
|
+
value: column,
|
|
63
|
+
writable: false
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { sourceIdentity as i, customSource as n, exposeColumns as r, createSource as t };
|