mutano 3.1.4 → 3.1.6

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.
Files changed (2) hide show
  1. package/dist/main.js +5 -39
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -218,8 +218,7 @@ function getType(op, desc, config, destination) {
218
218
  if (config.magicComments) {
219
219
  const kyselyOverrideType = extractKyselyExpression(Comment);
220
220
  if (kyselyOverrideType) {
221
- const shouldBeNullable2 = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
222
- return shouldBeNullable2 ? kyselyOverrideType.includes("| null") ? kyselyOverrideType : `${kyselyOverrideType} | null` : kyselyOverrideType;
221
+ return kyselyOverrideType;
223
222
  }
224
223
  }
225
224
  const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
@@ -228,53 +227,20 @@ function getType(op, desc, config, destination) {
228
227
  if (isKyselyDestination && config.magicComments) {
229
228
  const kyselyOverrideType = extractKyselyExpression(Comment);
230
229
  if (kyselyOverrideType) {
231
- const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
232
- return shouldBeNullable ? kyselyOverrideType.includes("| null") ? kyselyOverrideType : `${kyselyOverrideType} | null` : kyselyOverrideType;
230
+ return kyselyOverrideType;
233
231
  }
234
232
  }
235
233
  if ((isTsDestination || isKyselyDestination) && config.magicComments) {
236
234
  const tsOverrideType = extractTSExpression(Comment);
237
235
  if (tsOverrideType) {
238
- const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
239
- return shouldBeNullable ? tsOverrideType.includes("| null") ? tsOverrideType : `${tsOverrideType} | null` : tsOverrideType;
236
+ return tsOverrideType;
240
237
  }
241
238
  }
242
239
  }
243
240
  if (isZodDestination && config.magicComments) {
244
241
  const zodOverrideType = extractZodExpression(Comment);
245
242
  if (zodOverrideType) {
246
- const shouldBeNullable = isNull;
247
- const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
248
- const nullishOption = destination.nullish;
249
- const nullableMethod = nullishOption && op !== "selectable" ? "nullish" : "nullable";
250
- let finalType = zodOverrideType;
251
- if (shouldBeNullable && shouldBeOptional) {
252
- if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
253
- finalType = `${zodOverrideType}.${nullableMethod}()`;
254
- }
255
- } else if (shouldBeNullable) {
256
- if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
257
- finalType = `${zodOverrideType}.${nullableMethod}()`;
258
- }
259
- } else if (shouldBeOptional) {
260
- if (!zodOverrideType.includes(".optional()") && !zodOverrideType.includes(`.${nullableMethod}()`)) {
261
- finalType = `${zodOverrideType}.optional()`;
262
- }
263
- }
264
- if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
265
- let defaultValueFormatted = Default;
266
- if (typeMappings.stringTypes.includes(type) || typeMappings.dateTypes.includes(type)) {
267
- defaultValueFormatted = `'${Default}'`;
268
- } else if (typeMappings.booleanTypes.includes(type)) {
269
- defaultValueFormatted = Default.toLowerCase() === "true" ? "true" : "false";
270
- } else if (typeMappings.numberTypes.includes(type)) {
271
- defaultValueFormatted = Default;
272
- } else {
273
- defaultValueFormatted = `'${Default}'`;
274
- }
275
- finalType = `${finalType}.default(${defaultValueFormatted})`;
276
- }
277
- return finalType;
243
+ return zodOverrideType;
278
244
  }
279
245
  }
280
246
  const overrideTypes = config.origin.overrideTypes;
@@ -386,7 +352,7 @@ function generateStandardType(op, desc, config, destination, typeMappings) {
386
352
  baseType = "z.string()";
387
353
  if (op !== "selectable") {
388
354
  baseType += ".trim()";
389
- if (!hasDefaultValue) {
355
+ if (!hasDefaultValue && !shouldBeNullable) {
390
356
  baseType += ".min(1)";
391
357
  }
392
358
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.1.4",
4
+ "version": "3.1.6",
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",