mutano 3.0.8 → 3.0.9
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/main.js +38 -14
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -277,24 +277,36 @@ function getType(op, desc, config, destination) {
|
|
|
277
277
|
enumValues = config.enumDeclarations[type];
|
|
278
278
|
}
|
|
279
279
|
if (enumValues.length > 0) {
|
|
280
|
-
const shouldBeNullable = isNull
|
|
280
|
+
const shouldBeNullable = isNull;
|
|
281
|
+
const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
|
|
281
282
|
if (isZodDestination) {
|
|
282
283
|
const enumString = `z.enum([${enumValues.map((v) => `'${v}'`).join(",")}])`;
|
|
283
284
|
const nullishOption = destination.nullish;
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
if (shouldBeNullable && shouldBeOptional) {
|
|
286
|
+
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
287
|
+
return `${enumString}.${nullableMethod}()`;
|
|
288
|
+
} else if (shouldBeNullable) {
|
|
289
|
+
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
290
|
+
return `${enumString}.${nullableMethod}()`;
|
|
291
|
+
} else if (shouldBeOptional) {
|
|
292
|
+
return `${enumString}.optional()`;
|
|
293
|
+
} else {
|
|
294
|
+
return enumString;
|
|
295
|
+
}
|
|
286
296
|
} else if (isTsDestination) {
|
|
287
|
-
const
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
return shouldBeNullable ? `${enumString} | null` : enumString;
|
|
297
|
+
const enumString = enumValues.map((v) => `'${v}'`).join(" | ");
|
|
298
|
+
if (shouldBeNullable) {
|
|
299
|
+
return `${enumString} | null`;
|
|
291
300
|
} else {
|
|
292
|
-
|
|
293
|
-
return shouldBeNullable ? `${enumString} | null` : enumString;
|
|
301
|
+
return enumString;
|
|
294
302
|
}
|
|
295
303
|
} else if (isKyselyDestination) {
|
|
296
304
|
const enumString = enumValues.map((v) => `'${v}'`).join(" | ");
|
|
297
|
-
|
|
305
|
+
if (shouldBeNullable) {
|
|
306
|
+
return `${enumString} | null`;
|
|
307
|
+
} else {
|
|
308
|
+
return enumString;
|
|
309
|
+
}
|
|
298
310
|
}
|
|
299
311
|
}
|
|
300
312
|
}
|
|
@@ -309,7 +321,8 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
309
321
|
const isGenerated = Extra.toLowerCase().includes("auto_increment") || Extra.toLowerCase().includes("default_generated");
|
|
310
322
|
const isZodDestination = destination.type === "zod";
|
|
311
323
|
const isKyselyDestination = destination.type === "kysely";
|
|
312
|
-
const shouldBeNullable = isNull
|
|
324
|
+
const shouldBeNullable = isNull;
|
|
325
|
+
const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
|
|
313
326
|
let baseType;
|
|
314
327
|
if (typeMappings.dateTypes.includes(type)) {
|
|
315
328
|
if (isZodDestination) {
|
|
@@ -362,16 +375,27 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
|
|
|
362
375
|
} else {
|
|
363
376
|
baseType = isZodDestination ? "z.string()" : "string";
|
|
364
377
|
}
|
|
365
|
-
if (
|
|
366
|
-
if (
|
|
378
|
+
if (isZodDestination) {
|
|
379
|
+
if (shouldBeNullable && shouldBeOptional) {
|
|
367
380
|
const nullishOption = destination.nullish;
|
|
368
381
|
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
369
382
|
return `${baseType}.${nullableMethod}()`;
|
|
383
|
+
} else if (shouldBeNullable) {
|
|
384
|
+
const nullishOption = destination.nullish;
|
|
385
|
+
const nullableMethod = nullishOption ? "nullish" : "nullable";
|
|
386
|
+
return `${baseType}.${nullableMethod}()`;
|
|
387
|
+
} else if (shouldBeOptional) {
|
|
388
|
+
return `${baseType}.optional()`;
|
|
370
389
|
} else {
|
|
390
|
+
return baseType;
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
if (shouldBeNullable) {
|
|
371
394
|
return `${baseType} | null`;
|
|
395
|
+
} else {
|
|
396
|
+
return baseType;
|
|
372
397
|
}
|
|
373
398
|
}
|
|
374
|
-
return baseType;
|
|
375
399
|
}
|
|
376
400
|
|
|
377
401
|
function generateViewContent({
|
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.9",
|
|
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",
|