@drzl/analyzer 0.3.0 → 1.1.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/README.md CHANGED
@@ -16,13 +16,13 @@ Drizzle schema → normalized analysis for fast, reliable codegen.
16
16
  ## Use
17
17
 
18
18
  ```ts
19
- import { SchemaAnalyzer } from '@drzl/analyzer'
19
+ import { SchemaAnalyzer } from '@drzl/analyzer';
20
20
 
21
- const analyzer = new SchemaAnalyzer('src/db/schemas/index.ts')
21
+ const analyzer = new SchemaAnalyzer('src/db/schemas/index.ts');
22
22
  const analysis = await analyzer.analyze({
23
23
  includeRelations: true,
24
24
  validateConstraints: true,
25
- })
25
+ });
26
26
  ```
27
27
 
28
28
  The CLI consumes this analysis to generate validation, services, and routers.
package/dist/index.cjs CHANGED
@@ -104,11 +104,71 @@ var SchemaAnalyzer = class {
104
104
  }
105
105
  if (/^Pg/.test(ctor)) {
106
106
  if (/Text|Varchar|Char|Uuid/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
107
- if (/Int|Serial/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
107
+ if (/Inet|Cidr|Macaddr8?|Uuid/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
108
+ if (/Point|Line/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
109
+ if (/TimestampString|DateString/i.test(ctor)) return { tsType: "string", dbType: "TIMESTAMP" };
110
+ if (/Timestamptz/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMPTZ" };
111
+ if (/Timestamp/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
112
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
113
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
114
+ if (/Interval/i.test(ctor)) return { tsType: "string", dbType: "INTERVAL" };
115
+ if (/\bInt(eger)?\b|Serial/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
116
+ if (/BigInt/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
108
117
  if (/Bool/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
109
- if (/Time|Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
118
+ if (/Jsonb?/i.test(ctor)) return { tsType: "any", dbType: /Jsonb/i.test(ctor) ? "JSONB" : "JSON" };
119
+ if (/Numeric|Float|Double|Real/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
120
+ }
121
+ if (/^MySql/i.test(ctor)) {
122
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
123
+ if (/BigInt53/i.test(ctor)) return { tsType: "number", dbType: "BIGINT" };
124
+ if (/\bBigInt\b/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
125
+ if (/Decimal|Numeric|Float|Double|Real/i.test(ctor))
126
+ return { tsType: "number", dbType: "NUMERIC" };
127
+ if (/Int|Serial|TinyInt|SmallInt|MediumInt/i.test(ctor))
128
+ return { tsType: "number", dbType: "INTEGER" };
129
+ if (/Bool|Boolean/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
130
+ if (/TimestampString|DateTimeString|DateString/i.test(ctor))
131
+ return { tsType: "string", dbType: "TIMESTAMP" };
132
+ if (/Timestamp|DateTime/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
133
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
134
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
135
+ if (/Year/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
136
+ if (/Text|Varchar|VarChar|Char/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
137
+ if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
138
+ if (/Blob|Binary|VarBinary/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
139
+ }
140
+ if (/^SingleStore/i.test(ctor)) {
141
+ if (/Vector/i.test(ctor)) return { tsType: "any", dbType: "VECTOR" };
142
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
143
+ if (/BigInt53/i.test(ctor)) return { tsType: "number", dbType: "BIGINT" };
144
+ if (/Decimal|Numeric|Float|Double|Real/i.test(ctor))
145
+ return { tsType: "number", dbType: "NUMERIC" };
146
+ if (/Int|Serial|TinyInt|SmallInt|MediumInt/i.test(ctor))
147
+ return { tsType: "number", dbType: "INTEGER" };
148
+ if (/Bool|Boolean/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
149
+ if (/TimestampString|DateTimeString|DateString/i.test(ctor))
150
+ return { tsType: "string", dbType: "TIMESTAMP" };
151
+ if (/Timestamp|DateTime/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
152
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
153
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
154
+ if (/Year/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
155
+ if (/Text|Varchar|VarChar|Char/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
156
+ if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
157
+ if (/Blob|Binary|VarBinary/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
158
+ }
159
+ if (/^Gel/i.test(ctor)) {
160
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
161
+ if (/Int53|Integer|SmallInt/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
162
+ if (/Real|DoublePrecision/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
163
+ if (/Decimal/i.test(ctor)) return { tsType: "string", dbType: "NUMERIC" };
164
+ if (/UUID/i.test(ctor)) return { tsType: "string", dbType: "UUID" };
110
165
  if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
111
- if (/Numeric|Float|Double/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
166
+ if (/Text/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
167
+ if (/Bytes/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
168
+ if (/TimestampTz/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMPTZ" };
169
+ if (/Timestamp/i.test(ctor)) return { tsType: "string", dbType: "TIMESTAMP" };
170
+ if (/LocalDateString|LocalTime/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
171
+ if (/DateDuration|RelDuration|Duration/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
112
172
  }
113
173
  return { tsType: "unknown", dbType: "UNKNOWN" };
114
174
  }
@@ -319,7 +379,9 @@ var SchemaAnalyzer = class {
319
379
  const names = Array.from(ctorNames).join(",");
320
380
  if (/SQLite/i.test(names)) dialect = "sqlite";
321
381
  else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
322
- else if (/MySql|Mysql/i.test(names)) dialect = "unknown";
382
+ else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
383
+ else if (/SingleStore/i.test(names)) dialect = "singlestore";
384
+ else if (/Gel/i.test(names)) dialect = "gel";
323
385
  if (dialect === "unknown") {
324
386
  const looksSqlite = tables.some(
325
387
  (t) => t.columns.some((c) => ["INTEGER", "TEXT", "REAL", "BLOB", "NUMERIC"].includes(c.dbType))
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- type Dialect = 'sqlite' | 'postgres' | 'unknown';
1
+ type Dialect = 'sqlite' | 'postgres' | 'mysql' | 'singlestore' | 'gel' | 'unknown';
2
2
  interface Issue {
3
3
  code: string;
4
4
  level: 'info' | 'warn' | 'error';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type Dialect = 'sqlite' | 'postgres' | 'unknown';
1
+ type Dialect = 'sqlite' | 'postgres' | 'mysql' | 'singlestore' | 'gel' | 'unknown';
2
2
  interface Issue {
3
3
  code: string;
4
4
  level: 'info' | 'warn' | 'error';
package/dist/index.js CHANGED
@@ -68,11 +68,71 @@ var SchemaAnalyzer = class {
68
68
  }
69
69
  if (/^Pg/.test(ctor)) {
70
70
  if (/Text|Varchar|Char|Uuid/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
71
- if (/Int|Serial/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
71
+ if (/Inet|Cidr|Macaddr8?|Uuid/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
72
+ if (/Point|Line/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
73
+ if (/TimestampString|DateString/i.test(ctor)) return { tsType: "string", dbType: "TIMESTAMP" };
74
+ if (/Timestamptz/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMPTZ" };
75
+ if (/Timestamp/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
76
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
77
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
78
+ if (/Interval/i.test(ctor)) return { tsType: "string", dbType: "INTERVAL" };
79
+ if (/\bInt(eger)?\b|Serial/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
80
+ if (/BigInt/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
72
81
  if (/Bool/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
73
- if (/Time|Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
82
+ if (/Jsonb?/i.test(ctor)) return { tsType: "any", dbType: /Jsonb/i.test(ctor) ? "JSONB" : "JSON" };
83
+ if (/Numeric|Float|Double|Real/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
84
+ }
85
+ if (/^MySql/i.test(ctor)) {
86
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
87
+ if (/BigInt53/i.test(ctor)) return { tsType: "number", dbType: "BIGINT" };
88
+ if (/\bBigInt\b/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
89
+ if (/Decimal|Numeric|Float|Double|Real/i.test(ctor))
90
+ return { tsType: "number", dbType: "NUMERIC" };
91
+ if (/Int|Serial|TinyInt|SmallInt|MediumInt/i.test(ctor))
92
+ return { tsType: "number", dbType: "INTEGER" };
93
+ if (/Bool|Boolean/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
94
+ if (/TimestampString|DateTimeString|DateString/i.test(ctor))
95
+ return { tsType: "string", dbType: "TIMESTAMP" };
96
+ if (/Timestamp|DateTime/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
97
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
98
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
99
+ if (/Year/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
100
+ if (/Text|Varchar|VarChar|Char/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
101
+ if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
102
+ if (/Blob|Binary|VarBinary/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
103
+ }
104
+ if (/^SingleStore/i.test(ctor)) {
105
+ if (/Vector/i.test(ctor)) return { tsType: "any", dbType: "VECTOR" };
106
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
107
+ if (/BigInt53/i.test(ctor)) return { tsType: "number", dbType: "BIGINT" };
108
+ if (/Decimal|Numeric|Float|Double|Real/i.test(ctor))
109
+ return { tsType: "number", dbType: "NUMERIC" };
110
+ if (/Int|Serial|TinyInt|SmallInt|MediumInt/i.test(ctor))
111
+ return { tsType: "number", dbType: "INTEGER" };
112
+ if (/Bool|Boolean/i.test(ctor)) return { tsType: "boolean", dbType: "BOOLEAN" };
113
+ if (/TimestampString|DateTimeString|DateString/i.test(ctor))
114
+ return { tsType: "string", dbType: "TIMESTAMP" };
115
+ if (/Timestamp|DateTime/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
116
+ if (/Date/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMP" };
117
+ if (/Time/i.test(ctor)) return { tsType: "string", dbType: "TIME" };
118
+ if (/Year/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
119
+ if (/Text|Varchar|VarChar|Char/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
120
+ if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
121
+ if (/Blob|Binary|VarBinary/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
122
+ }
123
+ if (/^Gel/i.test(ctor)) {
124
+ if (/BigInt64/i.test(ctor)) return { tsType: "bigint", dbType: "BIGINT" };
125
+ if (/Int53|Integer|SmallInt/i.test(ctor)) return { tsType: "number", dbType: "INTEGER" };
126
+ if (/Real|DoublePrecision/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
127
+ if (/Decimal/i.test(ctor)) return { tsType: "string", dbType: "NUMERIC" };
128
+ if (/UUID/i.test(ctor)) return { tsType: "string", dbType: "UUID" };
74
129
  if (/Json/i.test(ctor)) return { tsType: "any", dbType: "JSON" };
75
- if (/Numeric|Float|Double/i.test(ctor)) return { tsType: "number", dbType: "NUMERIC" };
130
+ if (/Text/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
131
+ if (/Bytes/i.test(ctor)) return { tsType: "Uint8Array", dbType: "BLOB" };
132
+ if (/TimestampTz/i.test(ctor)) return { tsType: "Date", dbType: "TIMESTAMPTZ" };
133
+ if (/Timestamp/i.test(ctor)) return { tsType: "string", dbType: "TIMESTAMP" };
134
+ if (/LocalDateString|LocalTime/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
135
+ if (/DateDuration|RelDuration|Duration/i.test(ctor)) return { tsType: "string", dbType: "TEXT" };
76
136
  }
77
137
  return { tsType: "unknown", dbType: "UNKNOWN" };
78
138
  }
@@ -283,7 +343,9 @@ var SchemaAnalyzer = class {
283
343
  const names = Array.from(ctorNames).join(",");
284
344
  if (/SQLite/i.test(names)) dialect = "sqlite";
285
345
  else if (/Pg|Postgres/i.test(names)) dialect = "postgres";
286
- else if (/MySql|Mysql/i.test(names)) dialect = "unknown";
346
+ else if (/MySql|Mysql/i.test(names)) dialect = "mysql";
347
+ else if (/SingleStore/i.test(names)) dialect = "singlestore";
348
+ else if (/Gel/i.test(names)) dialect = "gel";
287
349
  if (dialect === "unknown") {
288
350
  const looksSqlite = tables.some(
289
351
  (t) => t.columns.some((c) => ["INTEGER", "TEXT", "REAL", "BLOB", "NUMERIC"].includes(c.dbType))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drzl/analyzer",
3
- "version": "0.3.0",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",