@drzl/analyzer 1.17.4 → 1.17.5
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 +26 -1
- package/dist/index.js +26 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -87,6 +87,7 @@ var BYTE_STRING_CLASSES = /* @__PURE__ */ new Set([
|
|
|
87
87
|
"SingleStoreBinary",
|
|
88
88
|
"SingleStoreVarBinary"
|
|
89
89
|
]);
|
|
90
|
+
var BUFFER_CLASSES = /* @__PURE__ */ new Set(["SQLiteBlobBuffer"]);
|
|
90
91
|
function describeV1Column(column) {
|
|
91
92
|
const codec = column?.codec;
|
|
92
93
|
const dataType = column?.dataType;
|
|
@@ -593,12 +594,36 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
593
594
|
tsType: column?.config?.mode === "timestamp" ? "Date" : "number",
|
|
594
595
|
dbType: "INTEGER"
|
|
595
596
|
};
|
|
597
|
+
// Both timestamp modes of `integer()`, which are one class and one type. `timestamp` and
|
|
598
|
+
// `timestamp_ms` differ in the scale of the number on the wire, seconds against
|
|
599
|
+
// milliseconds, and `mapFromDriverValue` consumes that difference and hands back a `Date`
|
|
600
|
+
// either way; nothing downstream of the analyzer ever sees the integer. So an arm keyed on
|
|
601
|
+
// the class covers both, where the mode check that used to answer this fell through the
|
|
602
|
+
// switch to a default arm testing `config.mode === 'timestamp'` and named only the first.
|
|
603
|
+
// The second came back `unknown`, and every generator emitted a schema accepting anything.
|
|
604
|
+
//
|
|
605
|
+
// `DATE` rather than the `INTEGER` that mode check returned, so the two majors describe the
|
|
606
|
+
// column identically. `dbType` is read in exactly one place outside this file,
|
|
607
|
+
// `isIntegerColumn`, which the generators consult only for a `tsType` of `number`, so the
|
|
608
|
+
// relabel reaches no output. Measured rather than argued: emitting a `Date` column under
|
|
609
|
+
// both labels, nullable and not, through all five generators gives ten byte-identical pairs.
|
|
610
|
+
case "SQLiteTimestamp":
|
|
611
|
+
return { tsType: "Date", dbType: "DATE" };
|
|
596
612
|
case "SQLiteText":
|
|
597
613
|
return { tsType: "string", dbType: "TEXT" };
|
|
598
614
|
case "SQLiteReal":
|
|
599
615
|
return { tsType: "number", dbType: "REAL" };
|
|
616
|
+
// No 0.4x column is a `SQLiteBlob`: `sqlite-core` builds a `SQLiteBlobBuffer`, a
|
|
617
|
+
// `SQLiteBlobJson` or a `SQLiteBigInt`, one per mode, and exports no class of this name at
|
|
618
|
+
// all. The arm answers the hand-built column in sqlite-types.spec.ts and nothing drizzle
|
|
619
|
+
// produces, which is why a real `blob()` reached neither it nor anything else.
|
|
600
620
|
case "SQLiteBlob":
|
|
601
621
|
return { tsType: "Uint8Array", dbType: "BLOB" };
|
|
622
|
+
// The class a real `blob()` and `blob({ mode: 'buffer' })` both build. See `BUFFER_CLASSES`
|
|
623
|
+
// for the measurement; the answers here are v1's own for the same column, so this is the
|
|
624
|
+
// two majors agreeing rather than a new opinion.
|
|
625
|
+
case "SQLiteBlobBuffer":
|
|
626
|
+
return { tsType: "Buffer", dbType: "BYTEA" };
|
|
602
627
|
// SQLite spells a mode as a distinct class rather than as config, so `text({mode:'json'})`
|
|
603
628
|
// is a `SQLiteTextJson` and matched no arm at all: the column came back UNKNOWN, which is
|
|
604
629
|
// wider than the `any` a json column at least used to get.
|
|
@@ -880,7 +905,7 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
880
905
|
const sqlType = sqlKind.startsWith("MySql") && typeof col?.getSQLType === "function" ? String(col.getSQLType()).toLowerCase() : void 0;
|
|
881
906
|
const byteCap = sqlType ? MYSQL_TEXT_CAPS[sqlType] : void 0;
|
|
882
907
|
const ctorName = String(col?.constructor?.name ?? "");
|
|
883
|
-
const fallbackShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : BYTE_STRING_CLASSES.has(ctorName) ? { kind: "byteString", length: declaredLength(col) } : NUMBER_VECTOR_CLASSES.has(ctorName) ? { kind: "numberVector", length: declaredLength(col) } : BIT_STRING_CLASSES.has(ctorName) ? { kind: "bitstring", length: declaredLength(col), exact: true } : GEOMETRIC_CLASS_SHAPES[ctorName];
|
|
908
|
+
const fallbackShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : BYTE_STRING_CLASSES.has(ctorName) ? { kind: "byteString", length: declaredLength(col) } : BUFFER_CLASSES.has(ctorName) ? { kind: "buffer" } : NUMBER_VECTOR_CLASSES.has(ctorName) ? { kind: "numberVector", length: declaredLength(col) } : BIT_STRING_CLASSES.has(ctorName) ? { kind: "bitstring", length: declaredLength(col), exact: true } : GEOMETRIC_CLASS_SHAPES[ctorName];
|
|
884
909
|
if (fallbackShape?.kind === "byteString") delete constraints.maxLength;
|
|
885
910
|
const shape = (v1?.shape ?? fallbackShape)?.kind;
|
|
886
911
|
const finalTs = v1?.tsType ?? tsType;
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ var BYTE_STRING_CLASSES = /* @__PURE__ */ new Set([
|
|
|
46
46
|
"SingleStoreBinary",
|
|
47
47
|
"SingleStoreVarBinary"
|
|
48
48
|
]);
|
|
49
|
+
var BUFFER_CLASSES = /* @__PURE__ */ new Set(["SQLiteBlobBuffer"]);
|
|
49
50
|
function describeV1Column(column) {
|
|
50
51
|
const codec = column?.codec;
|
|
51
52
|
const dataType = column?.dataType;
|
|
@@ -552,12 +553,36 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
552
553
|
tsType: column?.config?.mode === "timestamp" ? "Date" : "number",
|
|
553
554
|
dbType: "INTEGER"
|
|
554
555
|
};
|
|
556
|
+
// Both timestamp modes of `integer()`, which are one class and one type. `timestamp` and
|
|
557
|
+
// `timestamp_ms` differ in the scale of the number on the wire, seconds against
|
|
558
|
+
// milliseconds, and `mapFromDriverValue` consumes that difference and hands back a `Date`
|
|
559
|
+
// either way; nothing downstream of the analyzer ever sees the integer. So an arm keyed on
|
|
560
|
+
// the class covers both, where the mode check that used to answer this fell through the
|
|
561
|
+
// switch to a default arm testing `config.mode === 'timestamp'` and named only the first.
|
|
562
|
+
// The second came back `unknown`, and every generator emitted a schema accepting anything.
|
|
563
|
+
//
|
|
564
|
+
// `DATE` rather than the `INTEGER` that mode check returned, so the two majors describe the
|
|
565
|
+
// column identically. `dbType` is read in exactly one place outside this file,
|
|
566
|
+
// `isIntegerColumn`, which the generators consult only for a `tsType` of `number`, so the
|
|
567
|
+
// relabel reaches no output. Measured rather than argued: emitting a `Date` column under
|
|
568
|
+
// both labels, nullable and not, through all five generators gives ten byte-identical pairs.
|
|
569
|
+
case "SQLiteTimestamp":
|
|
570
|
+
return { tsType: "Date", dbType: "DATE" };
|
|
555
571
|
case "SQLiteText":
|
|
556
572
|
return { tsType: "string", dbType: "TEXT" };
|
|
557
573
|
case "SQLiteReal":
|
|
558
574
|
return { tsType: "number", dbType: "REAL" };
|
|
575
|
+
// No 0.4x column is a `SQLiteBlob`: `sqlite-core` builds a `SQLiteBlobBuffer`, a
|
|
576
|
+
// `SQLiteBlobJson` or a `SQLiteBigInt`, one per mode, and exports no class of this name at
|
|
577
|
+
// all. The arm answers the hand-built column in sqlite-types.spec.ts and nothing drizzle
|
|
578
|
+
// produces, which is why a real `blob()` reached neither it nor anything else.
|
|
559
579
|
case "SQLiteBlob":
|
|
560
580
|
return { tsType: "Uint8Array", dbType: "BLOB" };
|
|
581
|
+
// The class a real `blob()` and `blob({ mode: 'buffer' })` both build. See `BUFFER_CLASSES`
|
|
582
|
+
// for the measurement; the answers here are v1's own for the same column, so this is the
|
|
583
|
+
// two majors agreeing rather than a new opinion.
|
|
584
|
+
case "SQLiteBlobBuffer":
|
|
585
|
+
return { tsType: "Buffer", dbType: "BYTEA" };
|
|
561
586
|
// SQLite spells a mode as a distinct class rather than as config, so `text({mode:'json'})`
|
|
562
587
|
// is a `SQLiteTextJson` and matched no arm at all: the column came back UNKNOWN, which is
|
|
563
588
|
// wider than the `any` a json column at least used to get.
|
|
@@ -839,7 +864,7 @@ var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
|
839
864
|
const sqlType = sqlKind.startsWith("MySql") && typeof col?.getSQLType === "function" ? String(col.getSQLType()).toLowerCase() : void 0;
|
|
840
865
|
const byteCap = sqlType ? MYSQL_TEXT_CAPS[sqlType] : void 0;
|
|
841
866
|
const ctorName = String(col?.constructor?.name ?? "");
|
|
842
|
-
const fallbackShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : BYTE_STRING_CLASSES.has(ctorName) ? { kind: "byteString", length: declaredLength(col) } : NUMBER_VECTOR_CLASSES.has(ctorName) ? { kind: "numberVector", length: declaredLength(col) } : BIT_STRING_CLASSES.has(ctorName) ? { kind: "bitstring", length: declaredLength(col), exact: true } : GEOMETRIC_CLASS_SHAPES[ctorName];
|
|
867
|
+
const fallbackShape = dbType === "JSON" || dbType === "JSONB" || col?.config?.mode === "json" ? { kind: "json" } : BYTE_STRING_CLASSES.has(ctorName) ? { kind: "byteString", length: declaredLength(col) } : BUFFER_CLASSES.has(ctorName) ? { kind: "buffer" } : NUMBER_VECTOR_CLASSES.has(ctorName) ? { kind: "numberVector", length: declaredLength(col) } : BIT_STRING_CLASSES.has(ctorName) ? { kind: "bitstring", length: declaredLength(col), exact: true } : GEOMETRIC_CLASS_SHAPES[ctorName];
|
|
843
868
|
if (fallbackShape?.kind === "byteString") delete constraints.maxLength;
|
|
844
869
|
const shape = (v1?.shape ?? fallbackShape)?.kind;
|
|
845
870
|
const finalTs = v1?.tsType ?? tsType;
|