mutano 3.0.15 → 3.0.17

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 +11 -2
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -243,14 +243,23 @@ function getType(op, desc, config, destination) {
243
243
  if (isZodDestination && config.magicComments) {
244
244
  const zodOverrideType = extractZodExpression(Comment);
245
245
  if (zodOverrideType) {
246
- const shouldBeNullable = isNull || ["insertable", "updateable"].includes(op) && (hasDefaultValue || isGenerated) || op === "updateable" && !isNull && !hasDefaultValue;
246
+ const shouldBeNullable = isNull;
247
+ const shouldBeOptional = op === "insertable" && (hasDefaultValue || isGenerated) || op === "updateable";
247
248
  const nullishOption = destination.nullish;
248
249
  const nullableMethod = nullishOption ? "nullish" : "nullable";
249
250
  let finalType = zodOverrideType;
250
- if (shouldBeNullable) {
251
+ if (shouldBeNullable && shouldBeOptional) {
251
252
  if (!zodOverrideType.includes(`.${nullableMethod}()`) && !zodOverrideType.includes(".optional()")) {
252
253
  finalType = `${zodOverrideType}.${nullableMethod}()`;
253
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
+ }
254
263
  }
255
264
  if ((op === "table" || op === "insertable") && hasDefaultValue && Default !== null && !isGenerated) {
256
265
  let defaultValueFormatted = Default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mutano",
3
3
  "type": "module",
4
- "version": "3.0.15",
4
+ "version": "3.0.17",
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",