@drzl/analyzer 1.13.0 → 1.14.0
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/index.cjs +13 -4
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +13 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -206,7 +206,7 @@ function describeV1Column(column) {
|
|
|
206
206
|
out.dbType = codec === "varchar" ? "VARCHAR" : codec === "char" ? "CHAR" : "TEXT";
|
|
207
207
|
const kind = String(column?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
208
208
|
const cap = codec && kind.startsWith("MySql") ? MYSQL_TEXT_CAPS[codec] : void 0;
|
|
209
|
-
if (cap) out.
|
|
209
|
+
if (cap) out.maxBytes = cap;
|
|
210
210
|
} else {
|
|
211
211
|
return null;
|
|
212
212
|
}
|
|
@@ -700,16 +700,19 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
700
700
|
const v1 = describeV1Column(col);
|
|
701
701
|
const constraints = this.columnConstraints(col);
|
|
702
702
|
if (v1?.shape) delete constraints.maxLength;
|
|
703
|
+
const sqlKind = String(outerCol?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
704
|
+
const sqlType = sqlKind.startsWith("MySql") && typeof col?.getSQLType === "function" ? String(col.getSQLType()).toLowerCase() : void 0;
|
|
705
|
+
const byteCap = sqlType ? MYSQL_TEXT_CAPS[sqlType] : void 0;
|
|
703
706
|
const jsonShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : void 0;
|
|
704
707
|
const shape = (v1?.shape ?? jsonShape)?.kind;
|
|
705
708
|
const finalTs = v1?.tsType ?? tsType;
|
|
706
709
|
const wide = (finalTs === "unknown" || finalTs === "any") && (!shape || shape === "custom");
|
|
707
710
|
if (wide) {
|
|
708
|
-
const
|
|
711
|
+
const sqlType2 = typeof col?.getSQLType === "function" ? col.getSQLType() : void 0;
|
|
709
712
|
issues.push({
|
|
710
713
|
code: "DRZL_ANL_UNKNOWN_COLUMN",
|
|
711
714
|
level: "warn",
|
|
712
|
-
message: `Column "${colName}" on table "${tsName}" has no known type${
|
|
715
|
+
message: `Column "${colName}" on table "${tsName}" has no known type${sqlType2 ? ` (SQL type ${sqlType2})` : ""}, so its validator will accept any value.`,
|
|
713
716
|
hint: shape === "custom" ? "A customType has no runtime shape to read. Declare it with .$type<T>() and turn on typedColumns to give the validator the type." : "Open an issue naming the column type so it can be modelled, or declare it with .$type<T>() and turn on typedColumns."
|
|
714
717
|
});
|
|
715
718
|
}
|
|
@@ -730,7 +733,8 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
730
733
|
// that spread has nothing to say and this is the only source.
|
|
731
734
|
...arrayDims ? { arrayDimensions: arrayDims } : {},
|
|
732
735
|
// Only where v1 did not already describe the value, so a shaped column keeps its shape.
|
|
733
|
-
...jsonShape && !v1?.shape ? { shape: jsonShape } : {}
|
|
736
|
+
...jsonShape && !v1?.shape ? { shape: jsonShape } : {},
|
|
737
|
+
...byteCap && v1?.maxBytes === void 0 ? { maxBytes: byteCap } : {}
|
|
734
738
|
});
|
|
735
739
|
}
|
|
736
740
|
const name = this.getSymbol(tbl, "drizzle:Name") || tsName;
|
|
@@ -770,6 +774,11 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
770
774
|
const cfg = entry?.config ?? entry ?? {};
|
|
771
775
|
const cols = (cfg.columns ?? []).map((c) => toTs(c?.name)).filter(Boolean);
|
|
772
776
|
if (!cols.length) continue;
|
|
777
|
+
const entityKind = String(entry?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
778
|
+
if (entityKind.endsWith("UniqueConstraintBuilder")) {
|
|
779
|
+
unique.push({ columns: cols, name: entry?.name });
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
773
782
|
if (cfg.unique === void 0) {
|
|
774
783
|
pkCols.splice(0, pkCols.length, ...cols);
|
|
775
784
|
continue;
|
package/dist/index.d.cts
CHANGED
|
@@ -81,6 +81,16 @@ interface Column {
|
|
|
81
81
|
* value than the one actually stored, so only the literal case is carried.
|
|
82
82
|
*/
|
|
83
83
|
defaultValue?: unknown;
|
|
84
|
+
/**
|
|
85
|
+
* A cap measured in bytes rather than characters.
|
|
86
|
+
*
|
|
87
|
+
* MySQL's TEXT and BLOB families carry their limit in the type itself, and that limit is a byte
|
|
88
|
+
* budget: `tinytext` is 255 bytes, which on utf8mb4 is 255 ascii characters or 63 emoji.
|
|
89
|
+
* `maxLength` cannot express that, and using it applied the number as a character count.
|
|
90
|
+
*
|
|
91
|
+
* Only MySQL sets this. Postgres `text` has no limit and its `varchar(n)` counts characters.
|
|
92
|
+
*/
|
|
93
|
+
maxBytes?: number;
|
|
84
94
|
/**
|
|
85
95
|
* Array depth for a column declared with `.array()`, absent when the column is a scalar.
|
|
86
96
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -81,6 +81,16 @@ interface Column {
|
|
|
81
81
|
* value than the one actually stored, so only the literal case is carried.
|
|
82
82
|
*/
|
|
83
83
|
defaultValue?: unknown;
|
|
84
|
+
/**
|
|
85
|
+
* A cap measured in bytes rather than characters.
|
|
86
|
+
*
|
|
87
|
+
* MySQL's TEXT and BLOB families carry their limit in the type itself, and that limit is a byte
|
|
88
|
+
* budget: `tinytext` is 255 bytes, which on utf8mb4 is 255 ascii characters or 63 emoji.
|
|
89
|
+
* `maxLength` cannot express that, and using it applied the number as a character count.
|
|
90
|
+
*
|
|
91
|
+
* Only MySQL sets this. Postgres `text` has no limit and its `varchar(n)` counts characters.
|
|
92
|
+
*/
|
|
93
|
+
maxBytes?: number;
|
|
84
94
|
/**
|
|
85
95
|
* Array depth for a column declared with `.array()`, absent when the column is a scalar.
|
|
86
96
|
*
|
package/dist/index.js
CHANGED
|
@@ -166,7 +166,7 @@ function describeV1Column(column) {
|
|
|
166
166
|
out.dbType = codec === "varchar" ? "VARCHAR" : codec === "char" ? "CHAR" : "TEXT";
|
|
167
167
|
const kind = String(column?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
168
168
|
const cap = codec && kind.startsWith("MySql") ? MYSQL_TEXT_CAPS[codec] : void 0;
|
|
169
|
-
if (cap) out.
|
|
169
|
+
if (cap) out.maxBytes = cap;
|
|
170
170
|
} else {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
@@ -660,16 +660,19 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
660
660
|
const v1 = describeV1Column(col);
|
|
661
661
|
const constraints = this.columnConstraints(col);
|
|
662
662
|
if (v1?.shape) delete constraints.maxLength;
|
|
663
|
+
const sqlKind = String(outerCol?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
664
|
+
const sqlType = sqlKind.startsWith("MySql") && typeof col?.getSQLType === "function" ? String(col.getSQLType()).toLowerCase() : void 0;
|
|
665
|
+
const byteCap = sqlType ? MYSQL_TEXT_CAPS[sqlType] : void 0;
|
|
663
666
|
const jsonShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : void 0;
|
|
664
667
|
const shape = (v1?.shape ?? jsonShape)?.kind;
|
|
665
668
|
const finalTs = v1?.tsType ?? tsType;
|
|
666
669
|
const wide = (finalTs === "unknown" || finalTs === "any") && (!shape || shape === "custom");
|
|
667
670
|
if (wide) {
|
|
668
|
-
const
|
|
671
|
+
const sqlType2 = typeof col?.getSQLType === "function" ? col.getSQLType() : void 0;
|
|
669
672
|
issues.push({
|
|
670
673
|
code: "DRZL_ANL_UNKNOWN_COLUMN",
|
|
671
674
|
level: "warn",
|
|
672
|
-
message: `Column "${colName}" on table "${tsName}" has no known type${
|
|
675
|
+
message: `Column "${colName}" on table "${tsName}" has no known type${sqlType2 ? ` (SQL type ${sqlType2})` : ""}, so its validator will accept any value.`,
|
|
673
676
|
hint: shape === "custom" ? "A customType has no runtime shape to read. Declare it with .$type<T>() and turn on typedColumns to give the validator the type." : "Open an issue naming the column type so it can be modelled, or declare it with .$type<T>() and turn on typedColumns."
|
|
674
677
|
});
|
|
675
678
|
}
|
|
@@ -690,7 +693,8 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
690
693
|
// that spread has nothing to say and this is the only source.
|
|
691
694
|
...arrayDims ? { arrayDimensions: arrayDims } : {},
|
|
692
695
|
// Only where v1 did not already describe the value, so a shaped column keeps its shape.
|
|
693
|
-
...jsonShape && !v1?.shape ? { shape: jsonShape } : {}
|
|
696
|
+
...jsonShape && !v1?.shape ? { shape: jsonShape } : {},
|
|
697
|
+
...byteCap && v1?.maxBytes === void 0 ? { maxBytes: byteCap } : {}
|
|
694
698
|
});
|
|
695
699
|
}
|
|
696
700
|
const name = this.getSymbol(tbl, "drizzle:Name") || tsName;
|
|
@@ -730,6 +734,11 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
730
734
|
const cfg = entry?.config ?? entry ?? {};
|
|
731
735
|
const cols = (cfg.columns ?? []).map((c) => toTs(c?.name)).filter(Boolean);
|
|
732
736
|
if (!cols.length) continue;
|
|
737
|
+
const entityKind = String(entry?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")] ?? "");
|
|
738
|
+
if (entityKind.endsWith("UniqueConstraintBuilder")) {
|
|
739
|
+
unique.push({ columns: cols, name: entry?.name });
|
|
740
|
+
continue;
|
|
741
|
+
}
|
|
733
742
|
if (cfg.unique === void 0) {
|
|
734
743
|
pkCols.splice(0, pkCols.length, ...cols);
|
|
735
744
|
continue;
|