@drzl/analyzer 1.5.2 → 1.6.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 +103 -16
- package/dist/index.d.cts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +103 -16
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,15 @@ __export(index_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
var import_meta = {};
|
|
38
|
-
|
|
38
|
+
function renderSqlLiteral(v) {
|
|
39
|
+
if (v === null || v === void 0) return "NULL";
|
|
40
|
+
if (typeof v === "number" || typeof v === "bigint") return String(v);
|
|
41
|
+
if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
|
|
42
|
+
if (v instanceof Date) return `'${v.toISOString()}'`;
|
|
43
|
+
if (Array.isArray(v)) return `(${v.map(renderSqlLiteral).join(", ")})`;
|
|
44
|
+
return `'${String(v).replace(/'/g, "''")}'`;
|
|
45
|
+
}
|
|
46
|
+
var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
39
47
|
constructor(schemaPath) {
|
|
40
48
|
this.schemaPath = schemaPath;
|
|
41
49
|
}
|
|
@@ -172,6 +180,12 @@ var SchemaAnalyzer = class {
|
|
|
172
180
|
if (Array.isArray(c?.value)) return c.value.join("");
|
|
173
181
|
if (typeof c?.name === "string") return toTs(c.name);
|
|
174
182
|
if (c?.queryChunks) return this.renderSql(c, toTs);
|
|
183
|
+
if (c === null || ["number", "string", "boolean", "bigint"].includes(typeof c)) {
|
|
184
|
+
return renderSqlLiteral(c);
|
|
185
|
+
}
|
|
186
|
+
if (typeof c === "object" && "value" in c) {
|
|
187
|
+
return renderSqlLiteral(c.value);
|
|
188
|
+
}
|
|
175
189
|
return "?";
|
|
176
190
|
}).join("").trim();
|
|
177
191
|
}
|
|
@@ -243,6 +257,26 @@ var SchemaAnalyzer = class {
|
|
|
243
257
|
}
|
|
244
258
|
return out;
|
|
245
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Constraints the column definition already carries, which the analysis used to throw away.
|
|
262
|
+
*
|
|
263
|
+
* Everything here is read off Drizzle's own column instance, so it states what the schema
|
|
264
|
+
* states. Nothing is inferred from a name or guessed from a type.
|
|
265
|
+
*/
|
|
266
|
+
columnConstraints(column) {
|
|
267
|
+
const ctor = column?.constructor?.name ?? "";
|
|
268
|
+
const out = {};
|
|
269
|
+
const length = column?.length ?? column?.config?.length;
|
|
270
|
+
if (typeof length === "number" && Number.isFinite(length) && length > 0) {
|
|
271
|
+
out.maxLength = length;
|
|
272
|
+
}
|
|
273
|
+
const range = _SchemaAnalyzer.INT_RANGES[ctor];
|
|
274
|
+
if (range) {
|
|
275
|
+
[out.min, out.max] = range;
|
|
276
|
+
}
|
|
277
|
+
if (/^(Pg)?UUID$/i.test(ctor) || /Uuid$/i.test(ctor)) out.format = "uuid";
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
246
280
|
mapColumnType(column) {
|
|
247
281
|
const ctor = column?.constructor?.name ?? "";
|
|
248
282
|
switch (ctor) {
|
|
@@ -264,6 +298,14 @@ var SchemaAnalyzer = class {
|
|
|
264
298
|
case "PgInteger":
|
|
265
299
|
case "PgSmallInt":
|
|
266
300
|
return { tsType: "number", dbType: "INTEGER" };
|
|
301
|
+
// Drizzle names these by their mode: `PgBigInt53` for `{ mode: 'number' }` and
|
|
302
|
+
// `PgBigInt64` for `{ mode: 'bigint' }`. `PgBigInt` matched neither, so both fell through
|
|
303
|
+
// to the regex arm and came back as `bigint`, which is wrong for the number mode: the
|
|
304
|
+
// value really is a JS number there, and a schema demanding a bigint rejects every row.
|
|
305
|
+
case "PgBigInt53":
|
|
306
|
+
return { tsType: "number", dbType: "BIGINT" };
|
|
307
|
+
case "PgBigInt64":
|
|
308
|
+
return { tsType: "bigint", dbType: "BIGINT" };
|
|
267
309
|
case "PgBigInt":
|
|
268
310
|
return {
|
|
269
311
|
tsType: column?.config?.mode === "number" ? "number" : "bigint",
|
|
@@ -277,6 +319,9 @@ var SchemaAnalyzer = class {
|
|
|
277
319
|
case "PgVarchar":
|
|
278
320
|
case "PgChar":
|
|
279
321
|
return { tsType: "string", dbType: "TEXT" };
|
|
322
|
+
// Drizzle spells it `PgUUID`. `PgUuid` matched nothing, so every uuid column fell through
|
|
323
|
+
// to the regex arm below and came back as plain TEXT, losing the format.
|
|
324
|
+
case "PgUUID":
|
|
280
325
|
case "PgUuid":
|
|
281
326
|
return { tsType: "string", dbType: "UUID" };
|
|
282
327
|
case "PgBoolean":
|
|
@@ -407,7 +452,8 @@ var SchemaAnalyzer = class {
|
|
|
407
452
|
isGenerated,
|
|
408
453
|
defaultExpression: void 0,
|
|
409
454
|
references,
|
|
410
|
-
enumValues: Array.isArray(ev) ? ev : void 0
|
|
455
|
+
enumValues: Array.isArray(ev) ? ev : void 0,
|
|
456
|
+
...this.columnConstraints(col)
|
|
411
457
|
});
|
|
412
458
|
}
|
|
413
459
|
const name = this.getSymbol(tbl, "drizzle:Name") || tsName;
|
|
@@ -568,27 +614,32 @@ var SchemaAnalyzer = class {
|
|
|
568
614
|
enums.push(candidate);
|
|
569
615
|
}
|
|
570
616
|
let dialect = "unknown";
|
|
571
|
-
const
|
|
617
|
+
const marks = /* @__PURE__ */ new Set();
|
|
572
618
|
for (const [_, val] of Object.entries(exportsObj)) {
|
|
573
619
|
const cols = val?.[/* @__PURE__ */ Symbol.for("drizzle:Columns")];
|
|
574
|
-
if (cols)
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
620
|
+
if (!cols) continue;
|
|
621
|
+
for (const c of Object.values(cols)) {
|
|
622
|
+
const kind = c?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")];
|
|
623
|
+
if (typeof kind === "string") marks.add(kind);
|
|
624
|
+
const n = c?.constructor?.name;
|
|
625
|
+
if (n) marks.add(n);
|
|
579
626
|
}
|
|
580
627
|
}
|
|
581
|
-
const names = Array.from(
|
|
628
|
+
const names = Array.from(marks).join(",");
|
|
582
629
|
if (/SQLite/i.test(names)) dialect = "sqlite";
|
|
583
|
-
else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
|
|
584
|
-
else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
|
|
585
630
|
else if (/SingleStore/i.test(names)) dialect = "singlestore";
|
|
631
|
+
else if (/Cockroach/i.test(names)) dialect = "cockroach";
|
|
632
|
+
else if (/MsSql/i.test(names)) dialect = "mssql";
|
|
633
|
+
else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
|
|
634
|
+
else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
|
|
586
635
|
else if (/Gel/i.test(names)) dialect = "gel";
|
|
587
|
-
if (dialect === "unknown") {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
636
|
+
if (dialect === "unknown" && tables.length) {
|
|
637
|
+
issues.push({
|
|
638
|
+
code: "DRZL_ANL_DIALECT",
|
|
639
|
+
level: "warn",
|
|
640
|
+
message: `Could not identify the Drizzle dialect for this schema${names ? `; saw column kinds: ${Array.from(marks).slice(0, 6).join(", ")}` : ""}.`,
|
|
641
|
+
hint: "Column types will fall back to their coarse defaults. If this is a dialect DRZL does not know yet, please open an issue."
|
|
642
|
+
});
|
|
592
643
|
}
|
|
593
644
|
if (opts.includeRelations) {
|
|
594
645
|
relations.push(...this.inferManyToMany(tables));
|
|
@@ -628,6 +679,42 @@ var SchemaAnalyzer = class {
|
|
|
628
679
|
};
|
|
629
680
|
}
|
|
630
681
|
};
|
|
682
|
+
/**
|
|
683
|
+
* The range an integer column can actually hold, keyed off the Drizzle column class.
|
|
684
|
+
*
|
|
685
|
+
* Matches what `drizzle-orm/zod` emits, measured at 1.0.0-rc.4. The two bigint modes differ on
|
|
686
|
+
* purpose: in `{ mode: 'number' }` the value arrives as a JS number, so the real ceiling is
|
|
687
|
+
* `Number.MAX_SAFE_INTEGER` rather than the column's, and bounding at the column's would
|
|
688
|
+
* promise a precision that cannot survive the round trip.
|
|
689
|
+
*/
|
|
690
|
+
_SchemaAnalyzer.INT_RANGES = {
|
|
691
|
+
// 8 bit
|
|
692
|
+
MySqlTinyInt: ["-128", "127"],
|
|
693
|
+
SQLiteInteger: ["-9223372036854775808", "9223372036854775807"],
|
|
694
|
+
// 16 bit
|
|
695
|
+
PgSmallInt: ["-32768", "32767"],
|
|
696
|
+
PgSmallSerial: ["1", "32767"],
|
|
697
|
+
MySqlSmallInt: ["-32768", "32767"],
|
|
698
|
+
SingleStoreSmallInt: ["-32768", "32767"],
|
|
699
|
+
// 24 bit
|
|
700
|
+
MySqlMediumInt: ["-8388608", "8388607"],
|
|
701
|
+
// 32 bit
|
|
702
|
+
PgInteger: ["-2147483648", "2147483647"],
|
|
703
|
+
PgSerial: ["1", "2147483647"],
|
|
704
|
+
MySqlInt: ["-2147483648", "2147483647"],
|
|
705
|
+
SingleStoreInt: ["-2147483648", "2147483647"],
|
|
706
|
+
// 53 bit, the JS safe-integer ceiling rather than the column's
|
|
707
|
+
PgBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
708
|
+
PgBigSerial53: ["1", "9007199254740991"],
|
|
709
|
+
MySqlBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
710
|
+
SingleStoreBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
711
|
+
// 64 bit, representable because the value is a bigint
|
|
712
|
+
PgBigInt64: ["-9223372036854775808", "9223372036854775807"],
|
|
713
|
+
PgBigSerial64: ["1", "9223372036854775807"],
|
|
714
|
+
MySqlBigInt64: ["-9223372036854775808", "9223372036854775807"],
|
|
715
|
+
SingleStoreBigInt64: ["-9223372036854775808", "9223372036854775807"]
|
|
716
|
+
};
|
|
717
|
+
var SchemaAnalyzer = _SchemaAnalyzer;
|
|
631
718
|
var index_default = SchemaAnalyzer;
|
|
632
719
|
// Annotate the CommonJS export names for ESM import in node:
|
|
633
720
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `mssql` and `cockroach` arrived with Drizzle v1. `gel` was removed in the same release, but
|
|
3
|
+
* stays here so an analysis of a 0.4x schema still names what it found.
|
|
4
|
+
*/
|
|
5
|
+
type Dialect = 'sqlite' | 'postgres' | 'mysql' | 'singlestore' | 'mssql' | 'cockroach' | 'gel' | 'unknown';
|
|
2
6
|
interface Issue {
|
|
3
7
|
code: string;
|
|
4
8
|
level: 'info' | 'warn' | 'error';
|
|
@@ -31,6 +35,26 @@ interface Column {
|
|
|
31
35
|
onUpdate?: string;
|
|
32
36
|
};
|
|
33
37
|
enumValues?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Declared character limit, from `varchar('x', { length: 255 })` and friends.
|
|
40
|
+
*
|
|
41
|
+
* The column has always known this and the analysis discarded it, so generated schemas
|
|
42
|
+
* accepted a 300 character value that the database then rejected. Absent where the type has
|
|
43
|
+
* no limit, since claiming one would invent a constraint the schema never stated.
|
|
44
|
+
*/
|
|
45
|
+
maxLength?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Inclusive bounds for an integer column, as decimal strings.
|
|
48
|
+
*
|
|
49
|
+
* Strings rather than numbers because a 64 bit bound is not representable as a JS number:
|
|
50
|
+
* `9223372036854775807` rounds to `9223372036854775808` the moment it becomes one, so a
|
|
51
|
+
* numeric field here would silently emit a wrong bound. Absent for floats and for `numeric`,
|
|
52
|
+
* which have no integer range.
|
|
53
|
+
*/
|
|
54
|
+
min?: string;
|
|
55
|
+
max?: string;
|
|
56
|
+
/** A string column with a known shape, currently only `uuid`. */
|
|
57
|
+
format?: 'uuid';
|
|
34
58
|
}
|
|
35
59
|
interface Key {
|
|
36
60
|
name?: string;
|
|
@@ -171,6 +195,22 @@ declare class SchemaAnalyzer {
|
|
|
171
195
|
* it a join table would invent a relation the author never declared.
|
|
172
196
|
*/
|
|
173
197
|
private inferManyToMany;
|
|
198
|
+
/**
|
|
199
|
+
* The range an integer column can actually hold, keyed off the Drizzle column class.
|
|
200
|
+
*
|
|
201
|
+
* Matches what `drizzle-orm/zod` emits, measured at 1.0.0-rc.4. The two bigint modes differ on
|
|
202
|
+
* purpose: in `{ mode: 'number' }` the value arrives as a JS number, so the real ceiling is
|
|
203
|
+
* `Number.MAX_SAFE_INTEGER` rather than the column's, and bounding at the column's would
|
|
204
|
+
* promise a precision that cannot survive the round trip.
|
|
205
|
+
*/
|
|
206
|
+
private static readonly INT_RANGES;
|
|
207
|
+
/**
|
|
208
|
+
* Constraints the column definition already carries, which the analysis used to throw away.
|
|
209
|
+
*
|
|
210
|
+
* Everything here is read off Drizzle's own column instance, so it states what the schema
|
|
211
|
+
* states. Nothing is inferred from a name or guessed from a type.
|
|
212
|
+
*/
|
|
213
|
+
private columnConstraints;
|
|
174
214
|
private mapColumnType;
|
|
175
215
|
private analyzeTable;
|
|
176
216
|
analyze(opts?: AnalyzeOptions): Promise<Analysis>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `mssql` and `cockroach` arrived with Drizzle v1. `gel` was removed in the same release, but
|
|
3
|
+
* stays here so an analysis of a 0.4x schema still names what it found.
|
|
4
|
+
*/
|
|
5
|
+
type Dialect = 'sqlite' | 'postgres' | 'mysql' | 'singlestore' | 'mssql' | 'cockroach' | 'gel' | 'unknown';
|
|
2
6
|
interface Issue {
|
|
3
7
|
code: string;
|
|
4
8
|
level: 'info' | 'warn' | 'error';
|
|
@@ -31,6 +35,26 @@ interface Column {
|
|
|
31
35
|
onUpdate?: string;
|
|
32
36
|
};
|
|
33
37
|
enumValues?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Declared character limit, from `varchar('x', { length: 255 })` and friends.
|
|
40
|
+
*
|
|
41
|
+
* The column has always known this and the analysis discarded it, so generated schemas
|
|
42
|
+
* accepted a 300 character value that the database then rejected. Absent where the type has
|
|
43
|
+
* no limit, since claiming one would invent a constraint the schema never stated.
|
|
44
|
+
*/
|
|
45
|
+
maxLength?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Inclusive bounds for an integer column, as decimal strings.
|
|
48
|
+
*
|
|
49
|
+
* Strings rather than numbers because a 64 bit bound is not representable as a JS number:
|
|
50
|
+
* `9223372036854775807` rounds to `9223372036854775808` the moment it becomes one, so a
|
|
51
|
+
* numeric field here would silently emit a wrong bound. Absent for floats and for `numeric`,
|
|
52
|
+
* which have no integer range.
|
|
53
|
+
*/
|
|
54
|
+
min?: string;
|
|
55
|
+
max?: string;
|
|
56
|
+
/** A string column with a known shape, currently only `uuid`. */
|
|
57
|
+
format?: 'uuid';
|
|
34
58
|
}
|
|
35
59
|
interface Key {
|
|
36
60
|
name?: string;
|
|
@@ -171,6 +195,22 @@ declare class SchemaAnalyzer {
|
|
|
171
195
|
* it a join table would invent a relation the author never declared.
|
|
172
196
|
*/
|
|
173
197
|
private inferManyToMany;
|
|
198
|
+
/**
|
|
199
|
+
* The range an integer column can actually hold, keyed off the Drizzle column class.
|
|
200
|
+
*
|
|
201
|
+
* Matches what `drizzle-orm/zod` emits, measured at 1.0.0-rc.4. The two bigint modes differ on
|
|
202
|
+
* purpose: in `{ mode: 'number' }` the value arrives as a JS number, so the real ceiling is
|
|
203
|
+
* `Number.MAX_SAFE_INTEGER` rather than the column's, and bounding at the column's would
|
|
204
|
+
* promise a precision that cannot survive the round trip.
|
|
205
|
+
*/
|
|
206
|
+
private static readonly INT_RANGES;
|
|
207
|
+
/**
|
|
208
|
+
* Constraints the column definition already carries, which the analysis used to throw away.
|
|
209
|
+
*
|
|
210
|
+
* Everything here is read off Drizzle's own column instance, so it states what the schema
|
|
211
|
+
* states. Nothing is inferred from a name or guessed from a type.
|
|
212
|
+
*/
|
|
213
|
+
private columnConstraints;
|
|
174
214
|
private mapColumnType;
|
|
175
215
|
private analyzeTable;
|
|
176
216
|
analyze(opts?: AnalyzeOptions): Promise<Analysis>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
2
|
+
function renderSqlLiteral(v) {
|
|
3
|
+
if (v === null || v === void 0) return "NULL";
|
|
4
|
+
if (typeof v === "number" || typeof v === "bigint") return String(v);
|
|
5
|
+
if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
|
|
6
|
+
if (v instanceof Date) return `'${v.toISOString()}'`;
|
|
7
|
+
if (Array.isArray(v)) return `(${v.map(renderSqlLiteral).join(", ")})`;
|
|
8
|
+
return `'${String(v).replace(/'/g, "''")}'`;
|
|
9
|
+
}
|
|
10
|
+
var _SchemaAnalyzer = class _SchemaAnalyzer {
|
|
3
11
|
constructor(schemaPath) {
|
|
4
12
|
this.schemaPath = schemaPath;
|
|
5
13
|
}
|
|
@@ -136,6 +144,12 @@ var SchemaAnalyzer = class {
|
|
|
136
144
|
if (Array.isArray(c?.value)) return c.value.join("");
|
|
137
145
|
if (typeof c?.name === "string") return toTs(c.name);
|
|
138
146
|
if (c?.queryChunks) return this.renderSql(c, toTs);
|
|
147
|
+
if (c === null || ["number", "string", "boolean", "bigint"].includes(typeof c)) {
|
|
148
|
+
return renderSqlLiteral(c);
|
|
149
|
+
}
|
|
150
|
+
if (typeof c === "object" && "value" in c) {
|
|
151
|
+
return renderSqlLiteral(c.value);
|
|
152
|
+
}
|
|
139
153
|
return "?";
|
|
140
154
|
}).join("").trim();
|
|
141
155
|
}
|
|
@@ -207,6 +221,26 @@ var SchemaAnalyzer = class {
|
|
|
207
221
|
}
|
|
208
222
|
return out;
|
|
209
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Constraints the column definition already carries, which the analysis used to throw away.
|
|
226
|
+
*
|
|
227
|
+
* Everything here is read off Drizzle's own column instance, so it states what the schema
|
|
228
|
+
* states. Nothing is inferred from a name or guessed from a type.
|
|
229
|
+
*/
|
|
230
|
+
columnConstraints(column) {
|
|
231
|
+
const ctor = column?.constructor?.name ?? "";
|
|
232
|
+
const out = {};
|
|
233
|
+
const length = column?.length ?? column?.config?.length;
|
|
234
|
+
if (typeof length === "number" && Number.isFinite(length) && length > 0) {
|
|
235
|
+
out.maxLength = length;
|
|
236
|
+
}
|
|
237
|
+
const range = _SchemaAnalyzer.INT_RANGES[ctor];
|
|
238
|
+
if (range) {
|
|
239
|
+
[out.min, out.max] = range;
|
|
240
|
+
}
|
|
241
|
+
if (/^(Pg)?UUID$/i.test(ctor) || /Uuid$/i.test(ctor)) out.format = "uuid";
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
210
244
|
mapColumnType(column) {
|
|
211
245
|
const ctor = column?.constructor?.name ?? "";
|
|
212
246
|
switch (ctor) {
|
|
@@ -228,6 +262,14 @@ var SchemaAnalyzer = class {
|
|
|
228
262
|
case "PgInteger":
|
|
229
263
|
case "PgSmallInt":
|
|
230
264
|
return { tsType: "number", dbType: "INTEGER" };
|
|
265
|
+
// Drizzle names these by their mode: `PgBigInt53` for `{ mode: 'number' }` and
|
|
266
|
+
// `PgBigInt64` for `{ mode: 'bigint' }`. `PgBigInt` matched neither, so both fell through
|
|
267
|
+
// to the regex arm and came back as `bigint`, which is wrong for the number mode: the
|
|
268
|
+
// value really is a JS number there, and a schema demanding a bigint rejects every row.
|
|
269
|
+
case "PgBigInt53":
|
|
270
|
+
return { tsType: "number", dbType: "BIGINT" };
|
|
271
|
+
case "PgBigInt64":
|
|
272
|
+
return { tsType: "bigint", dbType: "BIGINT" };
|
|
231
273
|
case "PgBigInt":
|
|
232
274
|
return {
|
|
233
275
|
tsType: column?.config?.mode === "number" ? "number" : "bigint",
|
|
@@ -241,6 +283,9 @@ var SchemaAnalyzer = class {
|
|
|
241
283
|
case "PgVarchar":
|
|
242
284
|
case "PgChar":
|
|
243
285
|
return { tsType: "string", dbType: "TEXT" };
|
|
286
|
+
// Drizzle spells it `PgUUID`. `PgUuid` matched nothing, so every uuid column fell through
|
|
287
|
+
// to the regex arm below and came back as plain TEXT, losing the format.
|
|
288
|
+
case "PgUUID":
|
|
244
289
|
case "PgUuid":
|
|
245
290
|
return { tsType: "string", dbType: "UUID" };
|
|
246
291
|
case "PgBoolean":
|
|
@@ -371,7 +416,8 @@ var SchemaAnalyzer = class {
|
|
|
371
416
|
isGenerated,
|
|
372
417
|
defaultExpression: void 0,
|
|
373
418
|
references,
|
|
374
|
-
enumValues: Array.isArray(ev) ? ev : void 0
|
|
419
|
+
enumValues: Array.isArray(ev) ? ev : void 0,
|
|
420
|
+
...this.columnConstraints(col)
|
|
375
421
|
});
|
|
376
422
|
}
|
|
377
423
|
const name = this.getSymbol(tbl, "drizzle:Name") || tsName;
|
|
@@ -532,27 +578,32 @@ var SchemaAnalyzer = class {
|
|
|
532
578
|
enums.push(candidate);
|
|
533
579
|
}
|
|
534
580
|
let dialect = "unknown";
|
|
535
|
-
const
|
|
581
|
+
const marks = /* @__PURE__ */ new Set();
|
|
536
582
|
for (const [_, val] of Object.entries(exportsObj)) {
|
|
537
583
|
const cols = val?.[/* @__PURE__ */ Symbol.for("drizzle:Columns")];
|
|
538
|
-
if (cols)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
584
|
+
if (!cols) continue;
|
|
585
|
+
for (const c of Object.values(cols)) {
|
|
586
|
+
const kind = c?.constructor?.[/* @__PURE__ */ Symbol.for("drizzle:entityKind")];
|
|
587
|
+
if (typeof kind === "string") marks.add(kind);
|
|
588
|
+
const n = c?.constructor?.name;
|
|
589
|
+
if (n) marks.add(n);
|
|
543
590
|
}
|
|
544
591
|
}
|
|
545
|
-
const names = Array.from(
|
|
592
|
+
const names = Array.from(marks).join(",");
|
|
546
593
|
if (/SQLite/i.test(names)) dialect = "sqlite";
|
|
547
|
-
else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
|
|
548
|
-
else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
|
|
549
594
|
else if (/SingleStore/i.test(names)) dialect = "singlestore";
|
|
595
|
+
else if (/Cockroach/i.test(names)) dialect = "cockroach";
|
|
596
|
+
else if (/MsSql/i.test(names)) dialect = "mssql";
|
|
597
|
+
else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
|
|
598
|
+
else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
|
|
550
599
|
else if (/Gel/i.test(names)) dialect = "gel";
|
|
551
|
-
if (dialect === "unknown") {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
600
|
+
if (dialect === "unknown" && tables.length) {
|
|
601
|
+
issues.push({
|
|
602
|
+
code: "DRZL_ANL_DIALECT",
|
|
603
|
+
level: "warn",
|
|
604
|
+
message: `Could not identify the Drizzle dialect for this schema${names ? `; saw column kinds: ${Array.from(marks).slice(0, 6).join(", ")}` : ""}.`,
|
|
605
|
+
hint: "Column types will fall back to their coarse defaults. If this is a dialect DRZL does not know yet, please open an issue."
|
|
606
|
+
});
|
|
556
607
|
}
|
|
557
608
|
if (opts.includeRelations) {
|
|
558
609
|
relations.push(...this.inferManyToMany(tables));
|
|
@@ -592,6 +643,42 @@ var SchemaAnalyzer = class {
|
|
|
592
643
|
};
|
|
593
644
|
}
|
|
594
645
|
};
|
|
646
|
+
/**
|
|
647
|
+
* The range an integer column can actually hold, keyed off the Drizzle column class.
|
|
648
|
+
*
|
|
649
|
+
* Matches what `drizzle-orm/zod` emits, measured at 1.0.0-rc.4. The two bigint modes differ on
|
|
650
|
+
* purpose: in `{ mode: 'number' }` the value arrives as a JS number, so the real ceiling is
|
|
651
|
+
* `Number.MAX_SAFE_INTEGER` rather than the column's, and bounding at the column's would
|
|
652
|
+
* promise a precision that cannot survive the round trip.
|
|
653
|
+
*/
|
|
654
|
+
_SchemaAnalyzer.INT_RANGES = {
|
|
655
|
+
// 8 bit
|
|
656
|
+
MySqlTinyInt: ["-128", "127"],
|
|
657
|
+
SQLiteInteger: ["-9223372036854775808", "9223372036854775807"],
|
|
658
|
+
// 16 bit
|
|
659
|
+
PgSmallInt: ["-32768", "32767"],
|
|
660
|
+
PgSmallSerial: ["1", "32767"],
|
|
661
|
+
MySqlSmallInt: ["-32768", "32767"],
|
|
662
|
+
SingleStoreSmallInt: ["-32768", "32767"],
|
|
663
|
+
// 24 bit
|
|
664
|
+
MySqlMediumInt: ["-8388608", "8388607"],
|
|
665
|
+
// 32 bit
|
|
666
|
+
PgInteger: ["-2147483648", "2147483647"],
|
|
667
|
+
PgSerial: ["1", "2147483647"],
|
|
668
|
+
MySqlInt: ["-2147483648", "2147483647"],
|
|
669
|
+
SingleStoreInt: ["-2147483648", "2147483647"],
|
|
670
|
+
// 53 bit, the JS safe-integer ceiling rather than the column's
|
|
671
|
+
PgBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
672
|
+
PgBigSerial53: ["1", "9007199254740991"],
|
|
673
|
+
MySqlBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
674
|
+
SingleStoreBigInt53: ["-9007199254740991", "9007199254740991"],
|
|
675
|
+
// 64 bit, representable because the value is a bigint
|
|
676
|
+
PgBigInt64: ["-9223372036854775808", "9223372036854775807"],
|
|
677
|
+
PgBigSerial64: ["1", "9223372036854775807"],
|
|
678
|
+
MySqlBigInt64: ["-9223372036854775808", "9223372036854775807"],
|
|
679
|
+
SingleStoreBigInt64: ["-9223372036854775808", "9223372036854775807"]
|
|
680
|
+
};
|
|
681
|
+
var SchemaAnalyzer = _SchemaAnalyzer;
|
|
595
682
|
var index_default = SchemaAnalyzer;
|
|
596
683
|
export {
|
|
597
684
|
SchemaAnalyzer,
|