qubu 0.3.5 → 0.4.1
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 → canonical-BXUguqfo.mjs} +23 -23
- package/dist/codegen.d.mts +25 -33
- package/dist/codegen.mjs +38 -45
- package/dist/column-hqKr7-1I.mjs +620 -0
- package/dist/{complete-D5Djh-zo.mjs → complete-WYyVozgK.mjs} +50 -50
- package/dist/{complete-types-B2PO6wQD.d.mts → complete-types-IjEn5VPN.d.mts} +56 -56
- package/dist/core.d.mts +2 -2
- package/dist/core.mjs +4 -4
- package/dist/ddl.d.mts +12 -12
- package/dist/ddl.mjs +13 -14
- package/dist/{dialect-b2-Z6uBF.mjs → dialect-wUKrnPMB.mjs} +2 -2
- package/dist/diff.d.mts +1 -1
- package/dist/diff.mjs +6 -7
- package/dist/{index-7qc6OcIC.d.mts → index-1DpA3mUh.d.mts} +20 -20
- package/dist/{index-CqWnouTK.d.mts → index-CPvfEheG.d.mts} +13 -15
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +148 -120
- package/dist/introspection.d.mts +8 -8
- package/dist/introspection.mjs +29 -30
- package/dist/{json-CUZlv4HT.mjs → json-Db7XRD91.mjs} +2 -2
- package/dist/migration.d.mts +20 -21
- package/dist/migration.mjs +5 -6
- package/dist/{mysql-DqkqXB6A.mjs → mysql-B_cYzzX2.mjs} +237 -7
- package/dist/mysql.d.mts +1 -1
- package/dist/mysql.mjs +3 -3
- package/dist/{on-conflict-BxnxubMb.mjs → on-conflict-hfPW0KmQ.mjs} +4 -4
- package/dist/postgres.d.mts +5 -5
- package/dist/postgres.mjs +6 -6
- package/dist/{registry-BufIskVN.mjs → registry-BRMLYwDp.mjs} +27 -135
- package/dist/{relational-DCZrrNia.mjs → relational-BZ3WDPzC.mjs} +4 -4
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +6 -6
- package/dist/{snapshot-CWPgzxNx.mjs → snapshot-C-W65HEd.mjs} +5 -5
- package/dist/snapshot.d.mts +3 -3
- package/dist/snapshot.mjs +5 -7
- package/dist/{source-DUoJVXmL.mjs → source-BcS2AsIg.mjs} +7 -9
- package/dist/{serialize-PF1cfH2P.mjs → sqlite-Cg0nwYEH.mjs} +326 -12
- package/dist/sqlite.d.mts +2 -2
- package/dist/sqlite.mjs +2 -2
- package/dist/{standard-BTVYKh_F.mjs → standard-DfcZEVOj.mjs} +1 -1
- package/dist/{table-CCUJ60rB.mjs → table-Bp5irMSj.mjs} +5 -7
- package/dist/{types-D8M1yZF4.d.mts → types-BK1COGZe.d.mts} +2661 -2150
- package/dist/{types-Cec0xzo4.mjs → types-JM3FcAnX.mjs} +8 -8
- package/dist/{types-LBt5rclR.d.mts → types-JSZHpUEj.d.mts} +83 -84
- package/dist/{value-BvilP0oz.mjs → value-Bi71Agyf.mjs} +1 -1
- package/dist/vite/ambient.d.ts +311 -390
- package/dist/vite.d.mts +5 -6
- package/dist/vite.mjs +3 -4
- package/docs/dialects-and-execution.md +121 -81
- package/docs/getting-started.md +4 -4
- package/docs/guides/better-auth.md +57 -0
- package/docs/guides/compose-queries.md +24 -67
- package/docs/guides/drizzle.md +23 -23
- package/docs/guides/extensions/dialects.md +4 -4
- package/docs/guides/extensions/sources-and-clauses.md +15 -15
- package/docs/guides/extensions/typed-expressions.md +13 -17
- package/docs/guides/extensions/unsafe-syntax.md +3 -3
- package/docs/guides/json.md +7 -7
- package/docs/guides/mutations.md +14 -21
- package/docs/guides/select/conditions.md +6 -8
- package/docs/guides/select/grouping-and-windows.md +4 -15
- package/docs/guides/select/ordering-and-pagination.md +6 -19
- package/docs/guides/select/overview.md +12 -26
- package/docs/guides/sql-templates.md +20 -24
- package/docs/guides/vite-plugin.md +9 -13
- package/docs/index.md +5 -7
- package/docs/query-model/fragments.md +4 -15
- package/docs/query-model/result-shapes.md +11 -14
- package/docs/query-model/source-scope.md +31 -49
- package/docs/reference/mysql-snapshot.md +2 -5
- package/docs/reference/postgres-snapshot.md +3 -3
- package/docs/reference/sqlite-snapshot.md +2 -5
- package/docs/reference/supported-surface.md +33 -33
- package/docs/schema/catalog-model.md +2 -5
- package/docs/schema/code-generation.md +18 -18
- package/docs/schema/columns-and-writes.md +17 -25
- package/docs/schema/constraints-and-indexes.md +36 -52
- package/docs/schema/ddl-emission.md +6 -6
- package/docs/schema/diff.md +5 -5
- package/docs/schema/introspection.md +7 -7
- package/docs/schema/migration-plans.md +9 -9
- package/docs/schema/snapshots.md +3 -3
- package/docs/schema/storage-and-schema-sql.md +11 -11
- package/docs/schema/tables-and-names.md +11 -14
- package/docs/sql-semantic-types.md +10 -10
- package/docs/troubleshooting.md +10 -10
- package/package.json +21 -33
- package/skills/qubu/agents/openai.yaml +3 -3
- package/dist/column-CXMxx8Hq.mjs +0 -118
- package/dist/column-CYMbKbOy.mjs +0 -290
- package/dist/drizzle-mysql.d.mts +0 -24
- package/dist/drizzle-mysql.mjs +0 -72
- package/dist/drizzle-postgres.d.mts +0 -24
- package/dist/drizzle-postgres.mjs +0 -73
- package/dist/drizzle-sqlite.d.mts +0 -50
- package/dist/drizzle-sqlite.mjs +0 -108
- package/dist/drizzle.d.mts +0 -13
- package/dist/drizzle.mjs +0 -2
- package/dist/errors-BGCoLe_r.mjs +0 -14
- package/dist/naming-QVCOnSj2.mjs +0 -20
- package/dist/postgres-DEBBeh52.mjs +0 -235
- package/dist/runtime-Cn_Xgzta.mjs +0 -193
- package/dist/sqlite-BU6DBxef.mjs +0 -320
- package/dist/types-Ctlxz1ip.d.mts +0 -45
|
@@ -93,7 +93,7 @@ function validateSnapshot(value, diagnostics) {
|
|
|
93
93
|
if (validated !== void 0) tables.push(validated);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
if (dialect === void 0 || namingPolicy === void 0) return
|
|
96
|
+
if (dialect === void 0 || namingPolicy === void 0) return;
|
|
97
97
|
validateCrossReferences(tables, diagnostics);
|
|
98
98
|
return {
|
|
99
99
|
format: schemaSnapshotFormat,
|
|
@@ -113,7 +113,7 @@ function validateDialect(value, path, diagnostics) {
|
|
|
113
113
|
if (typeof value.name !== "string" || value.name.length === 0) diagnostics.push(diagnostic("invalid-snapshot", "Dialect name must be non-empty", [...path, "name"]));
|
|
114
114
|
if (typeof value.version !== "number" || !Number.isSafeInteger(value.version) || value.version < 1) diagnostics.push(diagnostic("invalid-snapshot", "Dialect version must be a positive integer", [...path, "version"]));
|
|
115
115
|
else if (value.version > 1) diagnostics.push(diagnostic("future-version", `Unsupported dialect extension version: ${value.version}`, [...path, "version"]));
|
|
116
|
-
if (typeof value.name !== "string" || typeof value.version !== "number") return
|
|
116
|
+
if (typeof value.name !== "string" || typeof value.version !== "number") return;
|
|
117
117
|
return {
|
|
118
118
|
name: value.name,
|
|
119
119
|
version: value.version
|
|
@@ -127,7 +127,7 @@ function validateNamingPolicy(value, path, diagnostics) {
|
|
|
127
127
|
requireKeys(value, ["name", "version"], path, diagnostics);
|
|
128
128
|
if (typeof value.name !== "string" || value.name.length === 0) diagnostics.push(diagnostic("invalid-snapshot", "Naming-policy name must be non-empty", [...path, "name"]));
|
|
129
129
|
if (value.version !== 1) diagnostics.push(diagnostic(typeof value.version === "number" && value.version > 1 ? "future-version" : "invalid-snapshot", `Unsupported naming-policy version: ${String(value.version)}`, [...path, "version"]));
|
|
130
|
-
if (typeof value.name !== "string" || typeof value.version !== "number") return
|
|
130
|
+
if (typeof value.name !== "string" || typeof value.version !== "number") return;
|
|
131
131
|
return {
|
|
132
132
|
name: value.name,
|
|
133
133
|
version: value.version
|
|
@@ -153,7 +153,7 @@ function validateTable(value, path, dialect, diagnostics) {
|
|
|
153
153
|
validateSortedIds(value.columns, [...path, "columns"], diagnostics);
|
|
154
154
|
validateSortedIds(value.constraints, [...path, "constraints"], diagnostics);
|
|
155
155
|
validateSortedIds(value.indexes, [...path, "indexes"], diagnostics);
|
|
156
|
-
if (id === void 0 || physicalName === void 0 || columns === void 0 || constraints === void 0 || indexes === void 0) return
|
|
156
|
+
if (id === void 0 || physicalName === void 0 || columns === void 0 || constraints === void 0 || indexes === void 0) return;
|
|
157
157
|
return {
|
|
158
158
|
id,
|
|
159
159
|
physicalName,
|
|
@@ -196,7 +196,7 @@ function validateColumn(value, path, dialect, diagnostics) {
|
|
|
196
196
|
const identity = value.identity === void 0 ? void 0 : validateIdentity(value.identity, [...path, "identity"], dialect, diagnostics);
|
|
197
197
|
const onUpdate = value.onUpdate === void 0 ? void 0 : validateExpression(value.onUpdate, [...path, "onUpdate"], "default", dialect, diagnostics);
|
|
198
198
|
if (onUpdate !== void 0 && dialect !== "mysql") diagnostics.push(diagnostic("dialect-mismatch", "Column onUpdate metadata is only valid for MySQL snapshots", [...path, "onUpdate"]));
|
|
199
|
-
if (id === void 0 || physicalName === void 0 || nullable === void 0 || hasDefault === void 0 || generated === void 0) return
|
|
199
|
+
if (id === void 0 || physicalName === void 0 || nullable === void 0 || hasDefault === void 0 || generated === void 0) return;
|
|
200
200
|
return {
|
|
201
201
|
id,
|
|
202
202
|
physicalName,
|
|
@@ -311,7 +311,7 @@ function validateIdentity(value, path, dialect, diagnostics) {
|
|
|
311
311
|
], path, diagnostics, ["dialect"]);
|
|
312
312
|
if (value.kind !== "identity") diagnostics.push(diagnostic("invalid-snapshot", "Identity kind must be identity", [...path, "kind"]));
|
|
313
313
|
if (value.generation !== "always" && value.generation !== "by-default") diagnostics.push(diagnostic("invalid-snapshot", "Identity generation is invalid", [...path, "generation"]));
|
|
314
|
-
if (value.kind !== "identity" || value.generation !== "always" && value.generation !== "by-default") return
|
|
314
|
+
if (value.kind !== "identity" || value.generation !== "always" && value.generation !== "by-default") return;
|
|
315
315
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
316
316
|
return {
|
|
317
317
|
kind: "identity",
|
|
@@ -325,7 +325,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const common = validateConstraintCommon(value, path, diagnostics);
|
|
328
|
-
if (common === void 0) return
|
|
328
|
+
if (common === void 0) return;
|
|
329
329
|
if (value.kind === "primary-key" || value.kind === "unique") {
|
|
330
330
|
requireKeys(value, [
|
|
331
331
|
"id",
|
|
@@ -343,7 +343,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
343
343
|
const columns = validateColumnIds(value.columns, [...path, "columns"], diagnostics);
|
|
344
344
|
const extra = validateConstraintTiming(value, path, diagnostics);
|
|
345
345
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
346
|
-
if (columns === void 0 || extra === void 0) return
|
|
346
|
+
if (columns === void 0 || extra === void 0) return;
|
|
347
347
|
return {
|
|
348
348
|
...common,
|
|
349
349
|
kind: value.kind,
|
|
@@ -371,7 +371,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
371
371
|
const extra = validateConstraintTiming(value, path, diagnostics);
|
|
372
372
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
373
373
|
if (value.nulls !== "distinct" && value.nulls !== "not-distinct") diagnostics.push(diagnostic("invalid-snapshot", "Unique-constraint null semantics are invalid", [...path, "nulls"]));
|
|
374
|
-
if (columns === void 0 || extra === void 0 || value.nulls !== "distinct" && value.nulls !== "not-distinct") return
|
|
374
|
+
if (columns === void 0 || extra === void 0 || value.nulls !== "distinct" && value.nulls !== "not-distinct") return;
|
|
375
375
|
return {
|
|
376
376
|
...common,
|
|
377
377
|
kind: "unique-constraint",
|
|
@@ -406,7 +406,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
406
406
|
const target = validateForeignKeyTarget(value.target, [...path, "target"], diagnostics);
|
|
407
407
|
const extra = validateForeignKeyOptions(value, path, diagnostics);
|
|
408
408
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
409
|
-
if (columns === void 0 || target === void 0 || extra === void 0) return
|
|
409
|
+
if (columns === void 0 || target === void 0 || extra === void 0) return;
|
|
410
410
|
return {
|
|
411
411
|
...common,
|
|
412
412
|
kind: "foreign-key",
|
|
@@ -433,7 +433,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
433
433
|
const expression = validateExpression(value.expression, [...path, "expression"], "check", dialect, diagnostics);
|
|
434
434
|
const extra = validateConstraintTiming(value, path, diagnostics);
|
|
435
435
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
436
|
-
if (expression === void 0 || extra === void 0) return
|
|
436
|
+
if (expression === void 0 || extra === void 0) return;
|
|
437
437
|
return {
|
|
438
438
|
...common,
|
|
439
439
|
kind: "check",
|
|
@@ -447,7 +447,7 @@ function validateConstraint(value, path, dialect, diagnostics) {
|
|
|
447
447
|
function validateConstraintCommon(value, path, diagnostics) {
|
|
448
448
|
const id = validateId(value.id, [...path, "id"], diagnostics);
|
|
449
449
|
const physicalName = validateName(value.physicalName, [...path, "physicalName"], diagnostics);
|
|
450
|
-
if (id === void 0 || physicalName === void 0) return
|
|
450
|
+
if (id === void 0 || physicalName === void 0) return;
|
|
451
451
|
return {
|
|
452
452
|
id,
|
|
453
453
|
kind: value.kind,
|
|
@@ -458,8 +458,8 @@ function validateConstraintTiming(value, path, diagnostics) {
|
|
|
458
458
|
const deferrable = validateOptionalBoolean(value.deferrable, [...path, "deferrable"], diagnostics);
|
|
459
459
|
const initially = value.initially === void 0 ? void 0 : value.initially === "immediate" || value.initially === "deferred" ? value.initially : void 0;
|
|
460
460
|
if (value.initially !== void 0 && initially === void 0) diagnostics.push(diagnostic("invalid-snapshot", "Constraint timing is invalid", [...path, "initially"]));
|
|
461
|
-
if (deferrable === void 0 && value.deferrable !== void 0) return
|
|
462
|
-
if (value.initially !== void 0 && initially === void 0) return
|
|
461
|
+
if (deferrable === void 0 && value.deferrable !== void 0) return;
|
|
462
|
+
if (value.initially !== void 0 && initially === void 0) return;
|
|
463
463
|
return {
|
|
464
464
|
...deferrable === void 0 ? {} : { deferrable },
|
|
465
465
|
...initially === void 0 ? {} : { initially }
|
|
@@ -468,7 +468,7 @@ function validateConstraintTiming(value, path, diagnostics) {
|
|
|
468
468
|
function validateForeignKeyOptions(value, path, diagnostics) {
|
|
469
469
|
const action = (key) => {
|
|
470
470
|
const candidate = value[key];
|
|
471
|
-
if (candidate === void 0) return
|
|
471
|
+
if (candidate === void 0) return;
|
|
472
472
|
if (candidate === "no-action" || candidate === "restrict" || candidate === "cascade" || candidate === "set-null" || candidate === "set-default") return candidate;
|
|
473
473
|
diagnostics.push(diagnostic("invalid-snapshot", `Foreign-key ${key} action is invalid`, [...path, key]));
|
|
474
474
|
};
|
|
@@ -477,7 +477,7 @@ function validateForeignKeyOptions(value, path, diagnostics) {
|
|
|
477
477
|
const match = value.match === void 0 ? void 0 : value.match === "simple" || value.match === "full" || value.match === "partial" ? value.match : void 0;
|
|
478
478
|
if (value.match !== void 0 && match === void 0) diagnostics.push(diagnostic("invalid-snapshot", "Foreign-key match mode is invalid", [...path, "match"]));
|
|
479
479
|
const timing = validateConstraintTiming(value, path, diagnostics);
|
|
480
|
-
if (timing === void 0 || value.onUpdate !== void 0 && onUpdate === void 0 || value.onDelete !== void 0 && onDelete === void 0 || value.match !== void 0 && match === void 0) return
|
|
480
|
+
if (timing === void 0 || value.onUpdate !== void 0 && onUpdate === void 0 || value.onDelete !== void 0 && onDelete === void 0 || value.match !== void 0 && match === void 0) return;
|
|
481
481
|
return {
|
|
482
482
|
...onUpdate === void 0 ? {} : { onUpdate },
|
|
483
483
|
...onDelete === void 0 ? {} : { onDelete },
|
|
@@ -527,7 +527,7 @@ function validateIndex(value, path, dialect, diagnostics) {
|
|
|
527
527
|
const predicate = value.predicate === void 0 ? void 0 : validateExpression(value.predicate, [...path, "predicate"], "index", dialect, diagnostics);
|
|
528
528
|
const includedColumns = value.includedColumns === void 0 ? void 0 : validateColumnIds(value.includedColumns, [...path, "includedColumns"], diagnostics);
|
|
529
529
|
const extension = validateExtension(value.dialect, [...path, "dialect"], dialect, diagnostics);
|
|
530
|
-
if (id === void 0 || physicalName === void 0 || unique === void 0 || candidateKey === void 0 || terms === void 0 || value.kind !== "index" || terms.length === 0) return
|
|
530
|
+
if (id === void 0 || physicalName === void 0 || unique === void 0 || candidateKey === void 0 || terms === void 0 || value.kind !== "index" || terms.length === 0) return;
|
|
531
531
|
return {
|
|
532
532
|
id,
|
|
533
533
|
kind: "index",
|
|
@@ -573,7 +573,7 @@ function validateIndexTerm(value, path, dialect, diagnostics) {
|
|
|
573
573
|
const nulls = value.nulls === void 0 ? void 0 : value.nulls === "FIRST" || value.nulls === "LAST" ? value.nulls : void 0;
|
|
574
574
|
if (value.direction !== void 0 && direction === void 0) diagnostics.push(diagnostic("invalid-snapshot", "Index order direction is invalid", [...path, "direction"]));
|
|
575
575
|
if (value.nulls !== void 0 && nulls === void 0) diagnostics.push(diagnostic("invalid-snapshot", "Index NULL ordering is invalid", [...path, "nulls"]));
|
|
576
|
-
if (expression === void 0 || value.direction !== void 0 && direction === void 0 || value.nulls !== void 0 && nulls === void 0) return
|
|
576
|
+
if (expression === void 0 || value.direction !== void 0 && direction === void 0 || value.nulls !== void 0 && nulls === void 0) return;
|
|
577
577
|
return {
|
|
578
578
|
kind: "order",
|
|
579
579
|
expression,
|
|
@@ -626,7 +626,7 @@ function validateExpression(value, path, _mode, dialect, diagnostics) {
|
|
|
626
626
|
if (expressionDialect !== void 0 && value.expressionKind !== "unsafe") diagnostics.push(diagnostic("invalid-snapshot", "Only unsafe expressions may carry a dialect tag", [...path, "dialect"]));
|
|
627
627
|
if (expressionDialect === void 0 && value.expressionKind === "unsafe") diagnostics.push(diagnostic("invalid-snapshot", "Unsafe expressions must carry a dialect tag", [...path, "dialect"]));
|
|
628
628
|
if (sql !== void 0 && sql !== sql.replace(/\r\n?/g, "\n")) diagnostics.push(diagnostic("non-canonical", "Expression SQL must use LF line endings", [...path, "sql"]));
|
|
629
|
-
if (expressionKind === void 0 || sql === void 0 || value.kind !== "expression") return
|
|
629
|
+
if (expressionKind === void 0 || sql === void 0 || value.kind !== "expression") return;
|
|
630
630
|
return {
|
|
631
631
|
kind: "expression",
|
|
632
632
|
expressionKind,
|
|
@@ -670,7 +670,7 @@ function validateLiteral(value, path, diagnostics) {
|
|
|
670
670
|
diagnostics.push(diagnostic("invalid-snapshot", "Literal kind is invalid", [...path, "kind"]));
|
|
671
671
|
}
|
|
672
672
|
function validateExtension(value, path, dialect, diagnostics) {
|
|
673
|
-
if (value === void 0) return
|
|
673
|
+
if (value === void 0) return;
|
|
674
674
|
if (!isRecord(value)) {
|
|
675
675
|
diagnostics.push(diagnostic("invalid-snapshot", "Dialect extension must be an object", path));
|
|
676
676
|
return;
|
|
@@ -686,7 +686,7 @@ function validateExtension(value, path, dialect, diagnostics) {
|
|
|
686
686
|
else if (version > 1) diagnostics.push(diagnostic("future-version", `Unsupported dialect extension version: ${version}`, [...path, "version"]));
|
|
687
687
|
if (extensionDialect !== void 0 && dialect !== void 0 && extensionDialect !== dialect) diagnostics.push(diagnostic("dialect-mismatch", `Dialect extension belongs to "${extensionDialect}" but snapshot dialect is "${dialect}"`, [...path, "dialect"]));
|
|
688
688
|
const data = validateJsonValue(value.data, [...path, "data"], diagnostics);
|
|
689
|
-
if (extensionDialect === void 0 || typeof version !== "number" || data === void 0) return
|
|
689
|
+
if (extensionDialect === void 0 || typeof version !== "number" || data === void 0) return;
|
|
690
690
|
return {
|
|
691
691
|
dialect: extensionDialect,
|
|
692
692
|
version,
|
|
@@ -943,8 +943,8 @@ function encodeCanonicalSnapshot(snapshot) {
|
|
|
943
943
|
return canonicalJson(snapshot);
|
|
944
944
|
}
|
|
945
945
|
/**
|
|
946
|
-
* Compute a small deterministic content digest for cache keys and diagnostics.
|
|
947
|
-
*
|
|
946
|
+
* Compute a small deterministic content digest for cache keys and diagnostics. It is deliberately
|
|
947
|
+
* not an entity identity, signature, or migration lineage.
|
|
948
948
|
*/
|
|
949
949
|
function schemaSnapshotDigest(snapshot) {
|
|
950
950
|
const source = encodeCanonicalSnapshot(assertSchemaSnapshot(snapshot));
|
package/dist/codegen.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { St as IntrospectionDiagnostic, dt as IntrospectionResult, i as CatalogClassificationConfidence, p as CatalogDialect, z as CatalogPortableStorageType } from "./types-
|
|
1
|
+
import { St as IntrospectionDiagnostic, dt as IntrospectionResult, i as CatalogClassificationConfidence, p as CatalogDialect, z as CatalogPortableStorageType } from "./types-JSZHpUEj.mjs";
|
|
2
2
|
//#region src/codegen/types.d.ts
|
|
3
3
|
/** TypeScript value types that the controlled source printer can emit. */
|
|
4
|
-
type CodegenApplicationType =
|
|
4
|
+
type CodegenApplicationType = "unknown" | "string" | "number" | "boolean" | "bigint" | "Date" | "Uint8Array";
|
|
5
5
|
/** Qubu SQL semantic domains that generated columns can carry. */
|
|
6
|
-
type CodegenSqlDomain =
|
|
6
|
+
type CodegenSqlDomain = "unknown" | "integer" | "decimal" | "text" | "boolean" | "date" | "timestamp" | "uuid" | "json" | "bigint" | "binary";
|
|
7
7
|
/** One logical-name decision exposed to a generator naming callback. */
|
|
8
8
|
interface CodegenNameContext {
|
|
9
|
-
readonly kind:
|
|
9
|
+
readonly kind: "schema" | "table" | "column" | "constraint" | "index";
|
|
10
10
|
readonly physicalName: string;
|
|
11
11
|
readonly suggestedName: string;
|
|
12
12
|
readonly tablePhysicalName?: string;
|
|
@@ -39,21 +39,20 @@ interface CodegenColumnMapping {
|
|
|
39
39
|
/** Controlled customization points for generated logical names and types. */
|
|
40
40
|
interface SchemaCodegenOptions {
|
|
41
41
|
/**
|
|
42
|
-
* Override one suggested camelCase name. The returned value must still be a
|
|
43
|
-
*
|
|
44
|
-
* bindings.
|
|
42
|
+
* Override one suggested camelCase name. The returned value must still be a safe camelCase
|
|
43
|
+
* logical ID, and table and schema names must be valid export bindings.
|
|
45
44
|
*/
|
|
46
45
|
readonly naming?: (context: CodegenNameContext) => string | undefined;
|
|
47
46
|
/**
|
|
48
|
-
* Override trusted application types or a Qubu SQL domain for one column.
|
|
49
|
-
*
|
|
47
|
+
* Override trusted application types or a Qubu SQL domain for one column. The callback selects
|
|
48
|
+
* from fixed tokens and cannot inject source text.
|
|
50
49
|
*/
|
|
51
50
|
readonly mapColumn?: (context: CodegenColumnContext) => CodegenColumnMapping | undefined;
|
|
52
51
|
}
|
|
53
52
|
/** Stable generator findings added beside retained introspection diagnostics. */
|
|
54
|
-
type CodegenDiagnosticCode = IntrospectionDiagnostic[
|
|
53
|
+
type CodegenDiagnosticCode = IntrospectionDiagnostic["code"] | "invalid-input" | "lossy-input" | "unsupported-snapshot" | "omitted-fact" | "unsafe-name" | "name-collision" | "invalid-option" | "unrepresentable-fact" | "excluded-object-family" | "unsafe-source";
|
|
55
54
|
/** A path-addressed finding returned by schema source generation. */
|
|
56
|
-
interface CodegenDiagnostic extends Omit<IntrospectionDiagnostic,
|
|
55
|
+
interface CodegenDiagnostic extends Omit<IntrospectionDiagnostic, "code"> {
|
|
57
56
|
readonly code: CodegenDiagnosticCode;
|
|
58
57
|
readonly relatedPaths?: readonly (readonly (string | number)[])[];
|
|
59
58
|
}
|
|
@@ -77,28 +76,21 @@ type SchemaCodegenResult = SchemaCodegenSuccess | SchemaCodegenFailure;
|
|
|
77
76
|
* Generate a deterministic TypeScript module from one introspection result.
|
|
78
77
|
*
|
|
79
78
|
* @remarks
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* `unknown`. The generator may attach a conservative SQL semantic domain, and
|
|
96
|
-
* {@link SchemaCodegenOptions.mapColumn} can override either type axis with a
|
|
97
|
-
* fixed token. Naming callbacks can replace suggested camelCase IDs, but they
|
|
98
|
-
* cannot supply source syntax.
|
|
99
|
-
*
|
|
100
|
-
* @param input A completed introspection operation. Failed and lossy results
|
|
101
|
-
* are reported as diagnostics rather than thrown errors.
|
|
79
|
+
* Generation accepts only a successful, non-lossy Snapshot v1 result for one PostgreSQL, SQLite,
|
|
80
|
+
* or MySQL namespace. It is pure: it opens no connection, performs no filesystem writes, and
|
|
81
|
+
* never evaluates catalog SQL. Existing introspection diagnostics are copied into the result. Any
|
|
82
|
+
* error returns no source. The generated module exports every ordinary table plus one schema
|
|
83
|
+
* registry. Physical names and native declarations remain escaped string literals. Catalog
|
|
84
|
+
* expressions use dialect-tagged schema data, checks use `catalogCheck()`, and foreign keys use
|
|
85
|
+
* lazy `catalogForeignKey()` targets. Foreign keys must have equal local and target arity and
|
|
86
|
+
* target an exact primary key, strict unique key, or candidate index. Nullable database UNIQUE
|
|
87
|
+
* constraints do not provide that candidate-key proof and fail generation. Application output,
|
|
88
|
+
* insert, and update types default independently to `unknown`. The generator may attach a
|
|
89
|
+
* conservative SQL semantic domain, and {@link SchemaCodegenOptions.mapColumn} can override either
|
|
90
|
+
* type axis with a fixed token. Naming callbacks can replace suggested camelCase IDs, but they
|
|
91
|
+
* cannot supply source syntax.
|
|
92
|
+
* @param input A completed introspection operation. Failed and lossy results are reported as
|
|
93
|
+
* diagnostics rather than thrown errors.
|
|
102
94
|
* @param options Controlled logical-name and column-type mappings.
|
|
103
95
|
* @returns Generated source and diagnostics, or diagnostics without source.
|
|
104
96
|
*/
|
package/dist/codegen.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as decodeSchemaSnapshot } from "./canonical-
|
|
2
|
-
import { t as mapCatalogToSnapshot } from "./snapshot-
|
|
1
|
+
import { l as decodeSchemaSnapshot } from "./canonical-BXUguqfo.mjs";
|
|
2
|
+
import { t as mapCatalogToSnapshot } from "./snapshot-C-W65HEd.mjs";
|
|
3
3
|
//#region src/codegen/source.ts
|
|
4
4
|
const header = `/* Generated by Qubu. Do not edit this machine-owned file. */
|
|
5
5
|
import * as _qubu from 'qubu'
|
|
@@ -40,7 +40,7 @@ const catalogPredicateHelper = `const _catalogPredicate = <
|
|
|
40
40
|
`;
|
|
41
41
|
function printSchemaSource(schema, diagnostics) {
|
|
42
42
|
const tables = schema.tables.map((table) => printTable(schema, table, diagnostics));
|
|
43
|
-
if (tables.some((table) => table === void 0)) return
|
|
43
|
+
if (tables.some((table) => table === void 0)) return;
|
|
44
44
|
const registry = schema.tables.map((table) => ` ${literal(table.name)}: ${table.name},`).join("\n");
|
|
45
45
|
const predicateHelper = schema.tables.some((table) => table.indexes.some((index) => index.snapshot.predicate !== void 0)) ? `\n${catalogPredicateHelper}` : "";
|
|
46
46
|
const columnHelper = schema.tables.some((table) => table.columns.length > 0) ? `\n${catalogColumnHelper}` : "";
|
|
@@ -110,7 +110,7 @@ function printConstraintType(table, constraint, columnsName, diagnostics) {
|
|
|
110
110
|
];
|
|
111
111
|
if (snapshot.kind === "check") return `readonly ${literal(constraint.name)}: _qubu.CheckConstraint`;
|
|
112
112
|
const columns = printColumnTypeTuple(table, snapshot.columns, columnsName, path, diagnostics);
|
|
113
|
-
if (columns === void 0) return
|
|
113
|
+
if (columns === void 0) return;
|
|
114
114
|
if (snapshot.kind === "foreign-key") return `readonly ${literal(constraint.name)}: _qubu.ForeignKeyConstraint<${columns}>`;
|
|
115
115
|
if (snapshot.kind === "unique-constraint") return `readonly ${literal(constraint.name)}: _qubu.UniqueConstraint<
|
|
116
116
|
${columns},
|
|
@@ -134,7 +134,7 @@ function printIndexType(table, index, columnsName, diagnostics) {
|
|
|
134
134
|
"terms",
|
|
135
135
|
position
|
|
136
136
|
], diagnostics));
|
|
137
|
-
if (terms.some((term) => term === void 0)) return
|
|
137
|
+
if (terms.some((term) => term === void 0)) return;
|
|
138
138
|
const properties = [
|
|
139
139
|
`readonly terms: readonly [${terms.join(", ")}]`,
|
|
140
140
|
`readonly unique: ${index.snapshot.unique ? "true" : "false"}`,
|
|
@@ -143,7 +143,7 @@ function printIndexType(table, index, columnsName, diagnostics) {
|
|
|
143
143
|
];
|
|
144
144
|
if (index.snapshot.includedColumns !== void 0) {
|
|
145
145
|
const included = printColumnTypeTuple(table, index.snapshot.includedColumns, columnsName, [...path, "includedColumns"], diagnostics);
|
|
146
|
-
if (included === void 0) return
|
|
146
|
+
if (included === void 0) return;
|
|
147
147
|
properties.push(`readonly includedColumns?: ${included}`);
|
|
148
148
|
} else properties.push("readonly includedColumns?: undefined");
|
|
149
149
|
return `readonly ${literal(index.name)}: {
|
|
@@ -199,7 +199,7 @@ function printColumn(schema, table, column, diagnostics) {
|
|
|
199
199
|
if (snapshot.default.kind === "external") options.push("default: _qubu.externalDefault()");
|
|
200
200
|
else if (snapshot.default.kind === "literal") {
|
|
201
201
|
const value = printSnapshotLiteral(snapshot.default.value, path, diagnostics);
|
|
202
|
-
if (value === void 0) return
|
|
202
|
+
if (value === void 0) return;
|
|
203
203
|
options.push(`default: ${value}`);
|
|
204
204
|
} else {
|
|
205
205
|
const value = printExpression(snapshot.default.expression, schema, [
|
|
@@ -207,7 +207,7 @@ function printColumn(schema, table, column, diagnostics) {
|
|
|
207
207
|
"default",
|
|
208
208
|
"expression"
|
|
209
209
|
], diagnostics);
|
|
210
|
-
if (value === void 0) return
|
|
210
|
+
if (value === void 0) return;
|
|
211
211
|
options.push(`default: ${value}`);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -219,7 +219,7 @@ function printColumn(schema, table, column, diagnostics) {
|
|
|
219
219
|
"generatedColumn",
|
|
220
220
|
"expression"
|
|
221
221
|
], diagnostics);
|
|
222
|
-
if (expression === void 0) return
|
|
222
|
+
if (expression === void 0) return;
|
|
223
223
|
options.push(`generatedColumn: _qubu.generatedColumn(${expression}, ${literal(snapshot.generatedColumn.mode)})`);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
@@ -234,7 +234,7 @@ function printColumn(schema, table, column, diagnostics) {
|
|
|
234
234
|
}
|
|
235
235
|
if (snapshot.onUpdate !== void 0) {
|
|
236
236
|
const expression = printExpression(snapshot.onUpdate, schema, [...path, "onUpdate"], diagnostics);
|
|
237
|
-
if (expression === void 0) return
|
|
237
|
+
if (expression === void 0) return;
|
|
238
238
|
options.push(`onUpdate: ${expression}`);
|
|
239
239
|
}
|
|
240
240
|
const types = [
|
|
@@ -262,11 +262,11 @@ function printConstraint(schema, table, constraint, diagnostics) {
|
|
|
262
262
|
snapshot.id
|
|
263
263
|
];
|
|
264
264
|
const options = printConstraintOptions(snapshot, schema, path, diagnostics);
|
|
265
|
-
if (options === void 0) return
|
|
265
|
+
if (options === void 0) return;
|
|
266
266
|
let expression;
|
|
267
267
|
if (snapshot.kind === "check") {
|
|
268
268
|
const sql = catalogExpressionData(snapshot.expression, schema, [...path, "expression"], diagnostics);
|
|
269
|
-
if (sql === void 0) return
|
|
269
|
+
if (sql === void 0) return;
|
|
270
270
|
expression = `_qubu.catalogCheck(${sql}, ${options})`;
|
|
271
271
|
} else if (snapshot.kind === "foreign-key") {
|
|
272
272
|
const local = printColumns(table, snapshot.columns, path, diagnostics);
|
|
@@ -280,7 +280,7 @@ function printConstraint(schema, table, constraint, diagnostics) {
|
|
|
280
280
|
return;
|
|
281
281
|
}
|
|
282
282
|
const target = printColumns(targetTable, snapshot.target.columns, [...path, "target"], diagnostics, targetTable.name);
|
|
283
|
-
if (local === void 0 || target === void 0) return
|
|
283
|
+
if (local === void 0 || target === void 0) return;
|
|
284
284
|
expression = `_qubu.catalogForeignKey(
|
|
285
285
|
[${local.join(", ")}],
|
|
286
286
|
() => _qubu.references(${targetTable.name}, ${target.join(", ")}),
|
|
@@ -288,7 +288,7 @@ function printConstraint(schema, table, constraint, diagnostics) {
|
|
|
288
288
|
)`;
|
|
289
289
|
} else {
|
|
290
290
|
const columns = printColumns(table, snapshot.columns, path, diagnostics);
|
|
291
|
-
if (columns === void 0) return
|
|
291
|
+
if (columns === void 0) return;
|
|
292
292
|
expression = `_qubu.${snapshot.kind === "primary-key" ? "primaryKey" : snapshot.kind === "unique" ? "unique" : "uniqueConstraint"}(${columns.join(", ")}, ${options})`;
|
|
293
293
|
}
|
|
294
294
|
return `${literal(constraint.name)}: ${expression},`;
|
|
@@ -305,7 +305,7 @@ function printConstraintOptions(constraint, schema, path, diagnostics) {
|
|
|
305
305
|
if (constraint.initially !== void 0) properties.push(`initially: ${literal(constraint.initially)}`);
|
|
306
306
|
if (constraint.dialect !== void 0) {
|
|
307
307
|
const extension = printExtension(constraint.dialect, schema, [...path, "dialect"], diagnostics);
|
|
308
|
-
if (extension === void 0) return
|
|
308
|
+
if (extension === void 0) return;
|
|
309
309
|
properties.push(`dialect: ${extension}`);
|
|
310
310
|
}
|
|
311
311
|
return `{ ${properties.join(", ")} }`;
|
|
@@ -323,21 +323,21 @@ function printIndex(schema, table, index, diagnostics) {
|
|
|
323
323
|
"terms",
|
|
324
324
|
termIndex
|
|
325
325
|
], diagnostics));
|
|
326
|
-
if (terms.some((term) => term === void 0)) return
|
|
326
|
+
if (terms.some((term) => term === void 0)) return;
|
|
327
327
|
const options = [`physicalName: ${literal(index.snapshot.physicalName)}`, `unique: ${index.snapshot.unique ? "true" : "false"}`];
|
|
328
328
|
if (index.snapshot.predicate !== void 0) {
|
|
329
329
|
const predicate = catalogExpressionData(index.snapshot.predicate, schema, [...path, "predicate"], diagnostics);
|
|
330
|
-
if (predicate === void 0) return
|
|
330
|
+
if (predicate === void 0) return;
|
|
331
331
|
options.push(`where: _catalogPredicate(${predicate})`);
|
|
332
332
|
}
|
|
333
333
|
if (index.snapshot.includedColumns !== void 0) {
|
|
334
334
|
const included = printColumns(table, index.snapshot.includedColumns, [...path, "includedColumns"], diagnostics);
|
|
335
|
-
if (included === void 0) return
|
|
335
|
+
if (included === void 0) return;
|
|
336
336
|
options.push(`include: [${included.join(", ")}]`);
|
|
337
337
|
}
|
|
338
338
|
if (index.snapshot.dialect !== void 0) {
|
|
339
339
|
const extension = printExtension(index.snapshot.dialect, schema, [...path, "dialect"], diagnostics);
|
|
340
|
-
if (extension === void 0) return
|
|
340
|
+
if (extension === void 0) return;
|
|
341
341
|
options.push(`dialect: ${extension}`);
|
|
342
342
|
}
|
|
343
343
|
return `${literal(index.name)}: _qubu.index(
|
|
@@ -348,7 +348,7 @@ function printIndex(schema, table, index, diagnostics) {
|
|
|
348
348
|
function printIndexTerm(schema, table, term, path, diagnostics) {
|
|
349
349
|
if (term.kind !== "order") return printIndexTermExpression(schema, table, term, path, diagnostics);
|
|
350
350
|
const expression = printIndexTermExpression(schema, table, term.expression, [...path, "expression"], diagnostics);
|
|
351
|
-
if (expression === void 0) return
|
|
351
|
+
if (expression === void 0) return;
|
|
352
352
|
return `_qubu.order(${expression}, ${term.direction === void 0 ? "undefined" : literal(term.direction)}, ${term.nulls === void 0 ? "undefined" : literal(term.nulls)})`;
|
|
353
353
|
}
|
|
354
354
|
function printIndexTermExpression(schema, table, expression, path, diagnostics) {
|
|
@@ -567,28 +567,21 @@ const excludedFamilies = [
|
|
|
567
567
|
* Generate a deterministic TypeScript module from one introspection result.
|
|
568
568
|
*
|
|
569
569
|
* @remarks
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
* `unknown`. The generator may attach a conservative SQL semantic domain, and
|
|
586
|
-
* {@link SchemaCodegenOptions.mapColumn} can override either type axis with a
|
|
587
|
-
* fixed token. Naming callbacks can replace suggested camelCase IDs, but they
|
|
588
|
-
* cannot supply source syntax.
|
|
589
|
-
*
|
|
590
|
-
* @param input A completed introspection operation. Failed and lossy results
|
|
591
|
-
* are reported as diagnostics rather than thrown errors.
|
|
570
|
+
* Generation accepts only a successful, non-lossy Snapshot v1 result for one PostgreSQL, SQLite,
|
|
571
|
+
* or MySQL namespace. It is pure: it opens no connection, performs no filesystem writes, and
|
|
572
|
+
* never evaluates catalog SQL. Existing introspection diagnostics are copied into the result. Any
|
|
573
|
+
* error returns no source. The generated module exports every ordinary table plus one schema
|
|
574
|
+
* registry. Physical names and native declarations remain escaped string literals. Catalog
|
|
575
|
+
* expressions use dialect-tagged schema data, checks use `catalogCheck()`, and foreign keys use
|
|
576
|
+
* lazy `catalogForeignKey()` targets. Foreign keys must have equal local and target arity and
|
|
577
|
+
* target an exact primary key, strict unique key, or candidate index. Nullable database UNIQUE
|
|
578
|
+
* constraints do not provide that candidate-key proof and fail generation. Application output,
|
|
579
|
+
* insert, and update types default independently to `unknown`. The generator may attach a
|
|
580
|
+
* conservative SQL semantic domain, and {@link SchemaCodegenOptions.mapColumn} can override either
|
|
581
|
+
* type axis with a fixed token. Naming callbacks can replace suggested camelCase IDs, but they
|
|
582
|
+
* cannot supply source syntax.
|
|
583
|
+
* @param input A completed introspection operation. Failed and lossy results are reported as
|
|
584
|
+
* diagnostics rather than thrown errors.
|
|
592
585
|
* @param options Controlled logical-name and column-type mappings.
|
|
593
586
|
* @returns Generated source and diagnostics, or diagnostics without source.
|
|
594
587
|
*/
|
|
@@ -730,7 +723,7 @@ function candidateIndexColumns(index) {
|
|
|
730
723
|
const columns = [];
|
|
731
724
|
for (const term of index.terms) {
|
|
732
725
|
const expression = term.kind === "order" ? term.expression : term;
|
|
733
|
-
if (expression.kind !== "column") return
|
|
726
|
+
if (expression.kind !== "column") return;
|
|
734
727
|
columns.push(expression.column);
|
|
735
728
|
}
|
|
736
729
|
return columns.length > 0 ? columns : void 0;
|
|
@@ -777,7 +770,7 @@ function resolveSchema(catalog, snapshot, options, diagnostics) {
|
|
|
777
770
|
const tableCollision = tableNames.get(schemaName);
|
|
778
771
|
if (tableCollision !== void 0) diagnostics.push(errorDiagnostic("name-collision", `Schema export and table export both resolve to "${schemaName}"`, ["schema"], void 0, [tableCollision]));
|
|
779
772
|
}
|
|
780
|
-
if (schemaName === void 0 || hasErrors(diagnostics)) return
|
|
773
|
+
if (schemaName === void 0 || hasErrors(diagnostics)) return;
|
|
781
774
|
const orderedTables = tables.sort(compareName);
|
|
782
775
|
return {
|
|
783
776
|
name: schemaName,
|
|
@@ -858,7 +851,7 @@ function resolveTable(snapshot, catalogTable, tableName, catalog, options, diagn
|
|
|
858
851
|
}
|
|
859
852
|
const constraints = resolveObjects(snapshot.constraints, "constraint", snapshot, tableName, options, diagnostics);
|
|
860
853
|
const indexes = resolveObjects(snapshot.indexes, "index", snapshot, tableName, options, diagnostics);
|
|
861
|
-
if (hasErrors(diagnostics)) return
|
|
854
|
+
if (hasErrors(diagnostics)) return;
|
|
862
855
|
const orderedColumns = columns.sort(compareName);
|
|
863
856
|
return {
|
|
864
857
|
name: tableName,
|