mutano 3.0.6 → 3.0.8
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 +4 -4
- package/dist/main.d.ts +1 -0
- package/dist/main.js +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,16 +90,16 @@ export interface InsertableUser {
|
|
|
90
90
|
|
|
91
91
|
**Kysely Types:**
|
|
92
92
|
```typescript
|
|
93
|
-
export interface
|
|
93
|
+
export interface User {
|
|
94
94
|
id: Generated<number>;
|
|
95
95
|
name: string;
|
|
96
96
|
email: string;
|
|
97
97
|
role: 'admin' | 'user';
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export type
|
|
101
|
-
export type
|
|
102
|
-
export type
|
|
100
|
+
export type SelectableUser = Selectable<User>;
|
|
101
|
+
export type InsertableUser = Insertable<User>;
|
|
102
|
+
export type UpdateableUser = Updateable<User>;
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
## Configuration
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -263,7 +263,8 @@ function getType(op, desc, config, destination) {
|
|
|
263
263
|
}
|
|
264
264
|
const enumTypesForSchema = typeMappings.enumTypes[schemaType] || [];
|
|
265
265
|
const isEnum = enumTypesForSchema.includes(type);
|
|
266
|
-
|
|
266
|
+
const isPrismaEnum = schemaType === "prisma" && config.enumDeclarations && config.enumDeclarations[type];
|
|
267
|
+
if (isEnum || isPrismaEnum) {
|
|
267
268
|
let enumValues = [];
|
|
268
269
|
if (schemaType === "mysql" && type === "enum") {
|
|
269
270
|
const match = Type.match(enumRegex);
|
|
@@ -272,6 +273,8 @@ function getType(op, desc, config, destination) {
|
|
|
272
273
|
}
|
|
273
274
|
} else if (schemaType === "postgres" && EnumOptions) {
|
|
274
275
|
enumValues = EnumOptions;
|
|
276
|
+
} else if (isPrismaEnum && config.enumDeclarations) {
|
|
277
|
+
enumValues = config.enumDeclarations[type];
|
|
275
278
|
}
|
|
276
279
|
if (enumValues.length > 0) {
|
|
277
280
|
const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
|
|
@@ -541,7 +544,7 @@ function generateKyselyContent({
|
|
|
541
544
|
`;
|
|
542
545
|
content += `// This interface defines the structure of the '${table}' table
|
|
543
546
|
`;
|
|
544
|
-
content += `export interface ${pascalTable}
|
|
547
|
+
content += `export interface ${pascalTable} {
|
|
545
548
|
`;
|
|
546
549
|
for (const desc of describes) {
|
|
547
550
|
const fieldName = isCamelCase ? camelCase(desc.Field) : desc.Field;
|
|
@@ -557,11 +560,11 @@ function generateKyselyContent({
|
|
|
557
560
|
content += "}\n\n";
|
|
558
561
|
content += `// Use these types for inserting, selecting and updating the table
|
|
559
562
|
`;
|
|
560
|
-
content += `export type Selectable${pascalTable} = Selectable<${pascalTable}
|
|
563
|
+
content += `export type Selectable${pascalTable} = Selectable<${pascalTable}>;
|
|
561
564
|
`;
|
|
562
|
-
content += `export type Insertable${pascalTable} = Insertable<${pascalTable}
|
|
565
|
+
content += `export type Insertable${pascalTable} = Insertable<${pascalTable}>;
|
|
563
566
|
`;
|
|
564
|
-
content += `export type Updateable${pascalTable} = Updateable<${pascalTable}
|
|
567
|
+
content += `export type Updateable${pascalTable} = Updateable<${pascalTable}>;
|
|
565
568
|
`;
|
|
566
569
|
return content;
|
|
567
570
|
}
|
|
@@ -896,6 +899,7 @@ async function generate(config) {
|
|
|
896
899
|
tables = prismaEntities.tables;
|
|
897
900
|
views = prismaEntities.views;
|
|
898
901
|
enumDeclarations = prismaEntities.enumDeclarations;
|
|
902
|
+
config.enumDeclarations = enumDeclarations;
|
|
899
903
|
} else {
|
|
900
904
|
db = createDatabaseConnection(config);
|
|
901
905
|
tables = await extractTables(db, config);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mutano",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.8",
|
|
5
5
|
"description": "Converts Prisma/MySQL/PostgreSQL/SQLite schemas to Zod/TS/Kysely interfaces",
|
|
6
6
|
"author": "Alisson Cavalcante Agiani <thelinuxlich@gmail.com>",
|
|
7
7
|
"license": "MIT",
|