@stryke/prisma-trpc-generator 0.10.6 → 0.11.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/dist/index.js CHANGED
@@ -2485,20 +2485,20 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
2485
2485
 
2486
2486
  // ../fs/src/helpers.ts
2487
2487
  import { mkdir, readFile, rm } from "node:fs/promises";
2488
- async function createDirectory(path5) {
2489
- if (await exists(path5)) {
2488
+ async function createDirectory(path6) {
2489
+ if (await exists(path6)) {
2490
2490
  return;
2491
2491
  }
2492
- return mkdir(path5, {
2492
+ return mkdir(path6, {
2493
2493
  recursive: true
2494
2494
  });
2495
2495
  }
2496
2496
  __name(createDirectory, "createDirectory");
2497
- async function removeDirectory(path5) {
2498
- if (!existsSync(path5)) {
2497
+ async function removeDirectory(path6) {
2498
+ if (!existsSync(path6)) {
2499
2499
  return;
2500
2500
  }
2501
- return rm(path5, {
2501
+ return rm(path6, {
2502
2502
  recursive: true
2503
2503
  });
2504
2504
  }
@@ -2520,65 +2520,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
2520
2520
  var isAbsolute = /* @__PURE__ */ __name(function(p) {
2521
2521
  return _IS_ABSOLUTE_RE.test(p);
2522
2522
  }, "isAbsolute");
2523
- var correctPaths = /* @__PURE__ */ __name(function(path5) {
2524
- if (!path5 || path5.length === 0) {
2523
+ var correctPaths = /* @__PURE__ */ __name(function(path6) {
2524
+ if (!path6 || path6.length === 0) {
2525
2525
  return ".";
2526
2526
  }
2527
- path5 = normalizeWindowsPath(path5);
2528
- const isUNCPath = path5.match(_UNC_REGEX);
2529
- const isPathAbsolute = isAbsolute(path5);
2530
- const trailingSeparator = path5[path5.length - 1] === "/";
2531
- path5 = normalizeString(path5, !isPathAbsolute);
2532
- if (path5.length === 0) {
2527
+ path6 = normalizeWindowsPath(path6);
2528
+ const isUNCPath = path6.match(_UNC_REGEX);
2529
+ const isPathAbsolute = isAbsolute(path6);
2530
+ const trailingSeparator = path6[path6.length - 1] === "/";
2531
+ path6 = normalizeString(path6, !isPathAbsolute);
2532
+ if (path6.length === 0) {
2533
2533
  if (isPathAbsolute) {
2534
2534
  return "/";
2535
2535
  }
2536
2536
  return trailingSeparator ? "./" : ".";
2537
2537
  }
2538
2538
  if (trailingSeparator) {
2539
- path5 += "/";
2539
+ path6 += "/";
2540
2540
  }
2541
- if (_DRIVE_LETTER_RE.test(path5)) {
2542
- path5 += "/";
2541
+ if (_DRIVE_LETTER_RE.test(path6)) {
2542
+ path6 += "/";
2543
2543
  }
2544
2544
  if (isUNCPath) {
2545
2545
  if (!isPathAbsolute) {
2546
- return `//./${path5}`;
2546
+ return `//./${path6}`;
2547
2547
  }
2548
- return `//${path5}`;
2548
+ return `//${path6}`;
2549
2549
  }
2550
- return isPathAbsolute && !isAbsolute(path5) ? `/${path5}` : path5;
2550
+ return isPathAbsolute && !isAbsolute(path6) ? `/${path6}` : path6;
2551
2551
  }, "correctPaths");
2552
2552
  var joinPaths = /* @__PURE__ */ __name(function(...segments) {
2553
- let path5 = "";
2553
+ let path6 = "";
2554
2554
  for (const seg of segments) {
2555
2555
  if (!seg) {
2556
2556
  continue;
2557
2557
  }
2558
- if (path5.length > 0) {
2559
- const pathTrailing = path5[path5.length - 1] === "/";
2558
+ if (path6.length > 0) {
2559
+ const pathTrailing = path6[path6.length - 1] === "/";
2560
2560
  const segLeading = seg[0] === "/";
2561
2561
  const both = pathTrailing && segLeading;
2562
2562
  if (both) {
2563
- path5 += seg.slice(1);
2563
+ path6 += seg.slice(1);
2564
2564
  } else {
2565
- path5 += pathTrailing || segLeading ? seg : `/${seg}`;
2565
+ path6 += pathTrailing || segLeading ? seg : `/${seg}`;
2566
2566
  }
2567
2567
  } else {
2568
- path5 += seg;
2568
+ path6 += seg;
2569
2569
  }
2570
2570
  }
2571
- return correctPaths(path5);
2571
+ return correctPaths(path6);
2572
2572
  }, "joinPaths");
2573
- function normalizeString(path5, allowAboveRoot) {
2573
+ function normalizeString(path6, allowAboveRoot) {
2574
2574
  let res = "";
2575
2575
  let lastSegmentLength = 0;
2576
2576
  let lastSlash = -1;
2577
2577
  let dots = 0;
2578
2578
  let char = null;
2579
- for (let index = 0; index <= path5.length; ++index) {
2580
- if (index < path5.length) {
2581
- char = path5[index];
2579
+ for (let index = 0; index <= path6.length; ++index) {
2580
+ if (index < path6.length) {
2581
+ char = path6[index];
2582
2582
  } else if (char === "/") {
2583
2583
  break;
2584
2584
  } else {
@@ -2614,9 +2614,9 @@ function normalizeString(path5, allowAboveRoot) {
2614
2614
  }
2615
2615
  } else {
2616
2616
  if (res.length > 0) {
2617
- res += `/${path5.slice(lastSlash + 1, index)}`;
2617
+ res += `/${path6.slice(lastSlash + 1, index)}`;
2618
2618
  } else {
2619
- res = path5.slice(lastSlash + 1, index);
2619
+ res = path6.slice(lastSlash + 1, index);
2620
2620
  }
2621
2621
  lastSegmentLength = index - lastSlash - 1;
2622
2622
  }
@@ -2640,7 +2640,7 @@ var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
2640
2640
 
2641
2641
  // src/prisma-generator.ts
2642
2642
  var import_pluralize = __toESM(require_pluralize(), 1);
2643
- import path4 from "node:path";
2643
+ import path5 from "node:path";
2644
2644
 
2645
2645
  // src/config.ts
2646
2646
  init_esm_shims();
@@ -3007,8 +3007,8 @@ function getErrorMap() {
3007
3007
  }
3008
3008
  __name(getErrorMap, "getErrorMap");
3009
3009
  var makeIssue = /* @__PURE__ */ __name((params) => {
3010
- const { data, path: path5, errorMaps, issueData } = params;
3011
- const fullPath = [...path5, ...issueData.path || []];
3010
+ const { data, path: path6, errorMaps, issueData } = params;
3011
+ const fullPath = [...path6, ...issueData.path || []];
3012
3012
  const fullIssue = {
3013
3013
  ...issueData,
3014
3014
  path: fullPath
@@ -3142,11 +3142,11 @@ var ParseInputLazyPath = class {
3142
3142
  static {
3143
3143
  __name(this, "ParseInputLazyPath");
3144
3144
  }
3145
- constructor(parent, value, path5, key) {
3145
+ constructor(parent, value, path6, key) {
3146
3146
  this._cachedPath = [];
3147
3147
  this.parent = parent;
3148
3148
  this.data = value;
3149
- this._path = path5;
3149
+ this._path = path6;
3150
3150
  this._key = key;
3151
3151
  }
3152
3152
  get path() {
@@ -6878,7 +6878,6 @@ var modelActionEnum = z.nativeEnum(ModelAction);
6878
6878
  var configBoolean = z.string().trim().transform((value) => !value || value.toLowerCase() === "false" || value.toLowerCase() === "n" || value.toLowerCase() === "no" || value === "0" ? false : value.toLowerCase() === "true" || value.toLowerCase() === "y" || value.toLowerCase() === "yes" || value === "1" ? true : value);
6879
6879
  var configSchema = z.object({
6880
6880
  debug: configBoolean.default("false"),
6881
- withZod: configBoolean.default("true"),
6882
6881
  withNext: configBoolean.default("true"),
6883
6882
  withMiddleware: configBoolean.default("false"),
6884
6883
  withShield: configBoolean.default("false"),
@@ -6887,7 +6886,18 @@ var configSchema = z.object({
6887
6886
  showModelNameInProcedure: configBoolean.default("false"),
6888
6887
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
6889
6888
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
6890
- })
6889
+ }),
6890
+ // Zod configuration
6891
+ withZod: configBoolean.default("true"),
6892
+ relationModel: configBoolean.default("true").or(z.literal("default")),
6893
+ modelSuffix: z.string().default("Model"),
6894
+ modelCase: z.enum([
6895
+ "PascalCase",
6896
+ "camelCase"
6897
+ ]).default("PascalCase"),
6898
+ useDecimalJs: configBoolean.default("false"),
6899
+ imports: z.string().optional(),
6900
+ prismaJsonNullability: configBoolean.default("true")
6891
6901
  });
6892
6902
 
6893
6903
  // src/helpers.ts
@@ -6907,20 +6917,20 @@ init_esm_shims();
6907
6917
  // ../path/src/is-file.ts
6908
6918
  init_esm_shims();
6909
6919
  import { lstatSync, statSync } from "node:fs";
6910
- function isFile(path5, additionalPath) {
6911
- return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
6920
+ function isFile(path6, additionalPath) {
6921
+ return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path6) : path6, {
6912
6922
  throwIfNoEntry: false
6913
6923
  })?.isFile());
6914
6924
  }
6915
6925
  __name(isFile, "isFile");
6916
- function isDirectory(path5, additionalPath) {
6917
- return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
6926
+ function isDirectory(path6, additionalPath) {
6927
+ return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path6) : path6, {
6918
6928
  throwIfNoEntry: false
6919
6929
  })?.isDirectory());
6920
6930
  }
6921
6931
  __name(isDirectory, "isDirectory");
6922
- function isAbsolutePath(path5) {
6923
- return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path5);
6932
+ function isAbsolutePath(path6) {
6933
+ return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path6);
6924
6934
  }
6925
6935
  __name(isAbsolutePath, "isAbsolutePath");
6926
6936
 
@@ -6935,45 +6945,45 @@ function normalizeWindowsPath2(input = "") {
6935
6945
  __name(normalizeWindowsPath2, "normalizeWindowsPath");
6936
6946
  var _UNC_REGEX2 = /^[/\\]{2}/;
6937
6947
  var _DRIVE_LETTER_RE2 = /^[A-Z]:$/i;
6938
- function correctPath(path5) {
6939
- if (!path5 || path5.length === 0) {
6948
+ function correctPath(path6) {
6949
+ if (!path6 || path6.length === 0) {
6940
6950
  return ".";
6941
6951
  }
6942
- path5 = normalizeWindowsPath2(path5);
6943
- const isUNCPath = path5.match(_UNC_REGEX2);
6944
- const isPathAbsolute = isAbsolutePath(path5);
6945
- const trailingSeparator = path5[path5.length - 1] === "/";
6946
- path5 = normalizeString2(path5, !isPathAbsolute);
6947
- if (path5.length === 0) {
6952
+ path6 = normalizeWindowsPath2(path6);
6953
+ const isUNCPath = path6.match(_UNC_REGEX2);
6954
+ const isPathAbsolute = isAbsolutePath(path6);
6955
+ const trailingSeparator = path6[path6.length - 1] === "/";
6956
+ path6 = normalizeString2(path6, !isPathAbsolute);
6957
+ if (path6.length === 0) {
6948
6958
  if (isPathAbsolute) {
6949
6959
  return "/";
6950
6960
  }
6951
6961
  return trailingSeparator ? "./" : ".";
6952
6962
  }
6953
6963
  if (trailingSeparator) {
6954
- path5 += "/";
6964
+ path6 += "/";
6955
6965
  }
6956
- if (_DRIVE_LETTER_RE2.test(path5)) {
6957
- path5 += "/";
6966
+ if (_DRIVE_LETTER_RE2.test(path6)) {
6967
+ path6 += "/";
6958
6968
  }
6959
6969
  if (isUNCPath) {
6960
6970
  if (!isPathAbsolute) {
6961
- return `//./${path5}`;
6971
+ return `//./${path6}`;
6962
6972
  }
6963
- return `//${path5}`;
6973
+ return `//${path6}`;
6964
6974
  }
6965
- return isPathAbsolute && !isAbsolutePath(path5) ? `/${path5}` : path5;
6975
+ return isPathAbsolute && !isAbsolutePath(path6) ? `/${path6}` : path6;
6966
6976
  }
6967
6977
  __name(correctPath, "correctPath");
6968
- function normalizeString2(path5, allowAboveRoot) {
6978
+ function normalizeString2(path6, allowAboveRoot) {
6969
6979
  let res = "";
6970
6980
  let lastSegmentLength = 0;
6971
6981
  let lastSlash = -1;
6972
6982
  let dots = 0;
6973
6983
  let char = null;
6974
- for (let index = 0; index <= path5.length; ++index) {
6975
- if (index < path5.length) {
6976
- char = path5[index];
6984
+ for (let index = 0; index <= path6.length; ++index) {
6985
+ if (index < path6.length) {
6986
+ char = path6[index];
6977
6987
  } else if (char === "/") {
6978
6988
  break;
6979
6989
  } else {
@@ -7009,9 +7019,9 @@ function normalizeString2(path5, allowAboveRoot) {
7009
7019
  }
7010
7020
  } else {
7011
7021
  if (res.length > 0) {
7012
- res += `/${path5.slice(lastSlash + 1, index)}`;
7022
+ res += `/${path6.slice(lastSlash + 1, index)}`;
7013
7023
  } else {
7014
- res = path5.slice(lastSlash + 1, index);
7024
+ res = path6.slice(lastSlash + 1, index);
7015
7025
  }
7016
7026
  lastSegmentLength = index - lastSlash - 1;
7017
7027
  }
@@ -7083,34 +7093,34 @@ __name2(normalizeWindowsPath3, "normalizeWindowsPath");
7083
7093
  var _UNC_REGEX3 = /^[/\\]{2}/;
7084
7094
  var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
7085
7095
  var _DRIVE_LETTER_RE3 = /^[A-Za-z]:$/;
7086
- var correctPaths2 = /* @__PURE__ */ __name2(function(path5) {
7087
- if (!path5 || path5.length === 0) {
7096
+ var correctPaths2 = /* @__PURE__ */ __name2(function(path6) {
7097
+ if (!path6 || path6.length === 0) {
7088
7098
  return ".";
7089
7099
  }
7090
- path5 = normalizeWindowsPath3(path5);
7091
- const isUNCPath = path5.match(_UNC_REGEX3);
7092
- const isPathAbsolute = isAbsolute2(path5);
7093
- const trailingSeparator = path5[path5.length - 1] === "/";
7094
- path5 = normalizeString3(path5, !isPathAbsolute);
7095
- if (path5.length === 0) {
7100
+ path6 = normalizeWindowsPath3(path6);
7101
+ const isUNCPath = path6.match(_UNC_REGEX3);
7102
+ const isPathAbsolute = isAbsolute2(path6);
7103
+ const trailingSeparator = path6[path6.length - 1] === "/";
7104
+ path6 = normalizeString3(path6, !isPathAbsolute);
7105
+ if (path6.length === 0) {
7096
7106
  if (isPathAbsolute) {
7097
7107
  return "/";
7098
7108
  }
7099
7109
  return trailingSeparator ? "./" : ".";
7100
7110
  }
7101
7111
  if (trailingSeparator) {
7102
- path5 += "/";
7112
+ path6 += "/";
7103
7113
  }
7104
- if (_DRIVE_LETTER_RE3.test(path5)) {
7105
- path5 += "/";
7114
+ if (_DRIVE_LETTER_RE3.test(path6)) {
7115
+ path6 += "/";
7106
7116
  }
7107
7117
  if (isUNCPath) {
7108
7118
  if (!isPathAbsolute) {
7109
- return `//./${path5}`;
7119
+ return `//./${path6}`;
7110
7120
  }
7111
- return `//${path5}`;
7121
+ return `//${path6}`;
7112
7122
  }
7113
- return isPathAbsolute && !isAbsolute2(path5) ? `/${path5}` : path5;
7123
+ return isPathAbsolute && !isAbsolute2(path6) ? `/${path6}` : path6;
7114
7124
  }, "correctPaths");
7115
7125
  function cwd() {
7116
7126
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -7120,15 +7130,15 @@ function cwd() {
7120
7130
  }
7121
7131
  __name(cwd, "cwd");
7122
7132
  __name2(cwd, "cwd");
7123
- function normalizeString3(path5, allowAboveRoot) {
7133
+ function normalizeString3(path6, allowAboveRoot) {
7124
7134
  let res = "";
7125
7135
  let lastSegmentLength = 0;
7126
7136
  let lastSlash = -1;
7127
7137
  let dots = 0;
7128
7138
  let char = null;
7129
- for (let index = 0; index <= path5.length; ++index) {
7130
- if (index < path5.length) {
7131
- char = path5[index];
7139
+ for (let index = 0; index <= path6.length; ++index) {
7140
+ if (index < path6.length) {
7141
+ char = path6[index];
7132
7142
  } else if (char === "/") {
7133
7143
  break;
7134
7144
  } else {
@@ -7164,9 +7174,9 @@ function normalizeString3(path5, allowAboveRoot) {
7164
7174
  }
7165
7175
  } else {
7166
7176
  if (res.length > 0) {
7167
- res += `/${path5.slice(lastSlash + 1, index)}`;
7177
+ res += `/${path6.slice(lastSlash + 1, index)}`;
7168
7178
  } else {
7169
- res = path5.slice(lastSlash + 1, index);
7179
+ res = path6.slice(lastSlash + 1, index);
7170
7180
  }
7171
7181
  lastSegmentLength = index - lastSlash - 1;
7172
7182
  }
@@ -7251,8 +7261,8 @@ __name2(findWorkspaceRoot, "findWorkspaceRoot");
7251
7261
 
7252
7262
  // ../path/src/get-parent-path.ts
7253
7263
  init_esm_shims();
7254
- var resolveParentPath = /* @__PURE__ */ __name((path5) => {
7255
- return resolvePaths(path5, "..");
7264
+ var resolveParentPath = /* @__PURE__ */ __name((path6) => {
7265
+ return resolvePaths(path6, "..");
7256
7266
  }, "resolveParentPath");
7257
7267
  var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
7258
7268
  const ignoreCase = options?.ignoreCase ?? true;
@@ -7357,17 +7367,17 @@ function findFilePath(filePath) {
7357
7367
  }), "");
7358
7368
  }
7359
7369
  __name(findFilePath, "findFilePath");
7360
- function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
7361
- const paths = normalizeWindowsPath2(path5).split("/");
7370
+ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
7371
+ const paths = normalizeWindowsPath2(path6).split("/");
7362
7372
  let resolvedPath = "";
7363
7373
  let resolvedAbsolute = false;
7364
7374
  for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
7365
- const path6 = index >= 0 ? paths[index] : cwd2;
7366
- if (!path6 || path6.length === 0) {
7375
+ const path7 = index >= 0 ? paths[index] : cwd2;
7376
+ if (!path7 || path7.length === 0) {
7367
7377
  continue;
7368
7378
  }
7369
- resolvedPath = joinPaths(path6, resolvedPath);
7370
- resolvedAbsolute = isAbsolutePath(path6);
7379
+ resolvedPath = joinPaths(path7, resolvedPath);
7380
+ resolvedAbsolute = isAbsolutePath(path7);
7371
7381
  }
7372
7382
  resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute);
7373
7383
  if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
@@ -7377,7 +7387,7 @@ function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
7377
7387
  }
7378
7388
  __name(resolvePath, "resolvePath");
7379
7389
  function resolvePaths(...paths) {
7380
- return resolvePath(joinPaths(...paths.map((path5) => normalizeWindowsPath2(path5))));
7390
+ return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7381
7391
  }
7382
7392
  __name(resolvePaths, "resolvePaths");
7383
7393
  function relativePath(from, to) {
@@ -7403,6 +7413,22 @@ function relativePath(from, to) {
7403
7413
  }
7404
7414
  __name(relativePath, "relativePath");
7405
7415
 
7416
+ // src/project.ts
7417
+ init_esm_shims();
7418
+ import { ModuleKind, Project, ScriptTarget } from "ts-morph";
7419
+ var compilerOptions = {
7420
+ target: ScriptTarget.ESNext,
7421
+ module: ModuleKind.ESNext,
7422
+ emitDecoratorMetadata: true,
7423
+ experimentalDecorators: true,
7424
+ esModuleInterop: true
7425
+ };
7426
+ var project = new Project({
7427
+ compilerOptions: {
7428
+ ...compilerOptions
7429
+ }
7430
+ });
7431
+
7406
7432
  // src/utils/get-prisma-internals.ts
7407
7433
  init_esm_shims();
7408
7434
 
@@ -7594,6 +7620,322 @@ async function getPrismaGeneratorHelper() {
7594
7620
  }
7595
7621
  __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7596
7622
 
7623
+ // src/zod/model-helpers.ts
7624
+ init_esm_shims();
7625
+ import path2 from "node:path";
7626
+ import { StructureKind, VariableDeclarationKind } from "ts-morph";
7627
+
7628
+ // src/zod/docs-helpers.ts
7629
+ init_esm_shims();
7630
+ import { parse, stringify } from "parenthesis";
7631
+ var getJSDocs = /* @__PURE__ */ __name((docString) => {
7632
+ const lines = [];
7633
+ if (docString) {
7634
+ const docLines = docString.split("\n").filter((dL) => !dL.trimStart().startsWith("@zod"));
7635
+ if (docLines.length) {
7636
+ lines.push("/**");
7637
+ docLines.forEach((dL) => lines.push(` * ${dL}`));
7638
+ lines.push(" */");
7639
+ }
7640
+ }
7641
+ return lines;
7642
+ }, "getJSDocs");
7643
+ var getZodDocElements = /* @__PURE__ */ __name((docString) => docString.split("\n").filter((line) => line.trimStart().startsWith("@zod")).map((line) => line.trimStart().slice(4)).flatMap((line) => (
7644
+ // Array.from(line.matchAll(/\.([^().]+\(.*?\))/g), (m) => m.slice(1)).flat()
7645
+ chunk(parse(line), 2).slice(0, -1).map(([each, contents]) => `${each.replace(/\)?\./, "")}${stringify(contents)})`)
7646
+ )), "getZodDocElements");
7647
+
7648
+ // src/zod/model-helpers.ts
7649
+ function checkModelHasModelRelation(model) {
7650
+ const { fields: modelFields } = model;
7651
+ for (const modelField of modelFields) {
7652
+ const isRelationField = checkIsModelRelationField(modelField);
7653
+ if (isRelationField) {
7654
+ return true;
7655
+ }
7656
+ }
7657
+ return false;
7658
+ }
7659
+ __name(checkModelHasModelRelation, "checkModelHasModelRelation");
7660
+ function checkModelHasManyModelRelation(model) {
7661
+ const { fields: modelFields } = model;
7662
+ for (const modelField of modelFields) {
7663
+ const isManyRelationField = checkIsManyModelRelationField(modelField);
7664
+ if (isManyRelationField) {
7665
+ return true;
7666
+ }
7667
+ }
7668
+ return false;
7669
+ }
7670
+ __name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
7671
+ function checkIsModelRelationField(modelField) {
7672
+ const { kind, relationName } = modelField;
7673
+ return kind === "object" && !!relationName;
7674
+ }
7675
+ __name(checkIsModelRelationField, "checkIsModelRelationField");
7676
+ function checkIsManyModelRelationField(modelField) {
7677
+ return checkIsModelRelationField(modelField) && modelField.isList;
7678
+ }
7679
+ __name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
7680
+ function findModelByName(models, modelName) {
7681
+ return models.find(({ name }) => name === modelName);
7682
+ }
7683
+ __name(findModelByName, "findModelByName");
7684
+ var writeArray = /* @__PURE__ */ __name((writer, array, newLine = true) => array.forEach((line) => writer.write(line).conditionalNewLine(newLine)), "writeArray");
7685
+ var useModelNames = /* @__PURE__ */ __name(({ modelCase, modelSuffix, relationModel }) => {
7686
+ const formatModelName = /* @__PURE__ */ __name((name, prefix = "") => {
7687
+ if (modelCase === "camelCase") {
7688
+ name = name.slice(0, 1).toLowerCase() + name.slice(1);
7689
+ }
7690
+ return `${prefix}${name}${modelSuffix}`;
7691
+ }, "formatModelName");
7692
+ return {
7693
+ modelName: /* @__PURE__ */ __name((name) => formatModelName(name, relationModel === "default" ? "_" : ""), "modelName"),
7694
+ relatedModelName: /* @__PURE__ */ __name((name) => formatModelName(relationModel === "default" ? name.toString() : `Related${name.toString()}`), "relatedModelName")
7695
+ };
7696
+ }, "useModelNames");
7697
+ var dotSlash = /* @__PURE__ */ __name((input) => {
7698
+ const converted = input.replace(/^\\\\\?\\/, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/");
7699
+ if (converted.includes(`/node_modules/`)) return converted.split(`/node_modules/`).slice(-1)[0];
7700
+ if (converted.startsWith(`../`)) return converted;
7701
+ return `./${converted}`;
7702
+ }, "dotSlash");
7703
+ var chunk = /* @__PURE__ */ __name((input, size) => {
7704
+ return input.reduce((arr, item, idx) => {
7705
+ return idx % size === 0 ? [
7706
+ ...arr,
7707
+ [
7708
+ item
7709
+ ]
7710
+ ] : [
7711
+ ...arr.slice(0, -1),
7712
+ [
7713
+ ...arr.slice(-1)[0],
7714
+ item
7715
+ ]
7716
+ ];
7717
+ }, []);
7718
+ }, "chunk");
7719
+ var needsRelatedModel = /* @__PURE__ */ __name((model, config) => model.fields.some((field) => field.kind === "object") && config.relationModel !== false, "needsRelatedModel");
7720
+ var writeImportsForModel = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
7721
+ const internals = await getPrismaInternals();
7722
+ const outputPath = internals.parseEnvValue(options.generator.output);
7723
+ const { relatedModelName } = useModelNames(config);
7724
+ const importList = [
7725
+ {
7726
+ kind: StructureKind.ImportDeclaration,
7727
+ namespaceImport: "z",
7728
+ moduleSpecifier: "zod"
7729
+ }
7730
+ ];
7731
+ if (config.imports) {
7732
+ importList.push({
7733
+ kind: StructureKind.ImportDeclaration,
7734
+ namespaceImport: "imports",
7735
+ moduleSpecifier: dotSlash(path2.relative(outputPath, path2.resolve(path2.dirname(options.schemaPath), config.imports)))
7736
+ });
7737
+ }
7738
+ if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
7739
+ importList.push({
7740
+ kind: StructureKind.ImportDeclaration,
7741
+ namedImports: [
7742
+ "Decimal"
7743
+ ],
7744
+ moduleSpecifier: "decimal.js"
7745
+ });
7746
+ }
7747
+ const enumFields = model.fields.filter((f) => f.kind === "enum");
7748
+ const relationFields = model.fields.filter((f) => f.kind === "object");
7749
+ const clientPath = options.otherGenerators.find((each) => each.provider.value === "prisma-client-js").output.value;
7750
+ const relativePath2 = path2.relative(outputPath, clientPath);
7751
+ if (enumFields.length > 0) {
7752
+ importList.push({
7753
+ kind: StructureKind.ImportDeclaration,
7754
+ isTypeOnly: enumFields.length === 0,
7755
+ moduleSpecifier: dotSlash(relativePath2),
7756
+ namedImports: enumFields.map((f) => f.type)
7757
+ });
7758
+ }
7759
+ if (config.relationModel !== false && relationFields.length > 0) {
7760
+ const filteredFields = relationFields.filter((f) => f.type !== model.name);
7761
+ if (filteredFields.length > 0) {
7762
+ importList.push({
7763
+ kind: StructureKind.ImportDeclaration,
7764
+ moduleSpecifier: "./index",
7765
+ namedImports: Array.from(new Set(filteredFields.flatMap((f) => [
7766
+ `${f.type}`,
7767
+ relatedModelName(f.type)
7768
+ ])))
7769
+ });
7770
+ }
7771
+ }
7772
+ sourceFile.addImportDeclarations(importList);
7773
+ }, "writeImportsForModel");
7774
+ var computeCustomSchema = /* @__PURE__ */ __name((docString) => {
7775
+ return getZodDocElements(docString).find((modifier) => modifier.startsWith("custom("))?.slice(7).slice(0, -1);
7776
+ }, "computeCustomSchema");
7777
+ var computeModifiers = /* @__PURE__ */ __name((docString) => {
7778
+ return getZodDocElements(docString).filter((each) => !each.startsWith("custom("));
7779
+ }, "computeModifiers");
7780
+ var getZodConstructor = /* @__PURE__ */ __name((field, getRelatedModelName = (name) => name.toString()) => {
7781
+ let zodType = "z.unknown()";
7782
+ const extraModifiers = [
7783
+ ""
7784
+ ];
7785
+ if (field.kind === "scalar") {
7786
+ switch (field.type) {
7787
+ case "String":
7788
+ zodType = "z.string()";
7789
+ break;
7790
+ case "Int":
7791
+ zodType = "z.number()";
7792
+ extraModifiers.push("int()");
7793
+ break;
7794
+ case "BigInt":
7795
+ zodType = "z.bigint()";
7796
+ break;
7797
+ case "DateTime":
7798
+ zodType = "z.date()";
7799
+ break;
7800
+ case "Float":
7801
+ zodType = "z.number()";
7802
+ break;
7803
+ case "Decimal":
7804
+ zodType = "z.number()";
7805
+ break;
7806
+ case "Json":
7807
+ zodType = "jsonSchema";
7808
+ break;
7809
+ case "Boolean":
7810
+ zodType = "z.boolean()";
7811
+ break;
7812
+ // TODO: Proper type for bytes fields
7813
+ case "Bytes":
7814
+ zodType = "z.unknown()";
7815
+ break;
7816
+ }
7817
+ } else if (field.kind === "enum") {
7818
+ zodType = `z.nativeEnum(${field.type})`;
7819
+ } else if (field.kind === "object") {
7820
+ zodType = getRelatedModelName(field.type);
7821
+ }
7822
+ if (field.isList) extraModifiers.push("array()");
7823
+ if (field.documentation) {
7824
+ zodType = computeCustomSchema(field.documentation) ?? zodType;
7825
+ extraModifiers.push(...computeModifiers(field.documentation));
7826
+ }
7827
+ if (!field.isRequired && field.type !== "Json") extraModifiers.push("nullish()");
7828
+ return `${zodType}${extraModifiers.join(".")}`;
7829
+ }, "getZodConstructor");
7830
+ var writeTypeSpecificSchemas = /* @__PURE__ */ __name((model, sourceFile, config) => {
7831
+ if (model.fields.some((f) => f.type === "Json")) {
7832
+ sourceFile.addStatements((writer) => {
7833
+ writer.newLine();
7834
+ writeArray(writer, [
7835
+ "// Helper schema for JSON fields",
7836
+ `type Literal = boolean | number | string${config.prismaJsonNullability ? "" : "| null"}`,
7837
+ "type Json = Literal | { [key: string]: Json } | Json[]",
7838
+ `const literalSchema = z.union([z.string(), z.number(), z.boolean()${config.prismaJsonNullability ? "" : ", z.null()"}])`,
7839
+ "const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))"
7840
+ ]);
7841
+ });
7842
+ }
7843
+ if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
7844
+ sourceFile.addStatements((writer) => {
7845
+ writer.newLine();
7846
+ writeArray(writer, [
7847
+ "// Helper schema for Decimal fields",
7848
+ "z",
7849
+ ".instanceof(Decimal)",
7850
+ ".or(z.string())",
7851
+ ".or(z.number())",
7852
+ ".refine((value) => {",
7853
+ " try {",
7854
+ " return new Decimal(value);",
7855
+ " } catch (error) {",
7856
+ " return false;",
7857
+ " }",
7858
+ "})",
7859
+ ".transform((value) => new Decimal(value));"
7860
+ ]);
7861
+ });
7862
+ }
7863
+ }, "writeTypeSpecificSchemas");
7864
+ var generateSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
7865
+ const { modelName } = useModelNames(config);
7866
+ sourceFile.addVariableStatement({
7867
+ declarationKind: VariableDeclarationKind.Const,
7868
+ isExported: true,
7869
+ leadingTrivia: /* @__PURE__ */ __name((writer) => writer.blankLineIfLastNot(), "leadingTrivia"),
7870
+ declarations: [
7871
+ {
7872
+ name: modelName(model.name),
7873
+ initializer(writer) {
7874
+ writer.write("z.object(").inlineBlock(() => {
7875
+ model.fields.filter((f) => f.kind !== "object").forEach((field) => {
7876
+ writeArray(writer, getJSDocs(field.documentation));
7877
+ writer.write(`${field.name}: ${getZodConstructor(field)}`).write(",").newLine();
7878
+ });
7879
+ }).write(")");
7880
+ }
7881
+ }
7882
+ ]
7883
+ });
7884
+ }, "generateSchemaForModel");
7885
+ var generateRelatedSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
7886
+ const { modelName, relatedModelName } = useModelNames(config);
7887
+ const relationFields = model.fields.filter((f) => f.kind === "object");
7888
+ sourceFile.addInterface({
7889
+ name: `${model.name}`,
7890
+ isExported: true,
7891
+ extends: [
7892
+ `z.infer<typeof ${modelName(model.name)}>`
7893
+ ],
7894
+ properties: relationFields.map((f) => ({
7895
+ hasQuestionToken: !f.isRequired,
7896
+ name: f.name,
7897
+ type: `${f.type}${f.isList ? "[]" : ""}${!f.isRequired ? " | null" : ""}`
7898
+ }))
7899
+ });
7900
+ sourceFile.addStatements((writer) => writeArray(writer, [
7901
+ "",
7902
+ "/**",
7903
+ ` * ${relatedModelName(model.name)} contains all relations on your model in addition to the scalars`,
7904
+ " *",
7905
+ " * NOTE: Lazy required in case of potential circular dependencies within schema",
7906
+ " */"
7907
+ ]));
7908
+ sourceFile.addVariableStatement({
7909
+ declarationKind: VariableDeclarationKind.Const,
7910
+ isExported: true,
7911
+ declarations: [
7912
+ {
7913
+ name: relatedModelName(model.name),
7914
+ type: `z.ZodSchema<${model.name}>`,
7915
+ initializer(writer) {
7916
+ writer.write(`z.lazy(() => ${modelName(model.name)}.extend(`).inlineBlock(() => {
7917
+ relationFields.forEach((field) => {
7918
+ writeArray(writer, getJSDocs(field.documentation));
7919
+ writer.write(`${field.name}: ${getZodConstructor(field, relatedModelName)}`).write(",").newLine();
7920
+ });
7921
+ }).write("))");
7922
+ }
7923
+ }
7924
+ ]
7925
+ });
7926
+ }, "generateRelatedSchemaForModel");
7927
+ var populateModelFile = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
7928
+ await writeImportsForModel(model, sourceFile, config, options);
7929
+ writeTypeSpecificSchemas(model, sourceFile, config);
7930
+ generateSchemaForModel(model, sourceFile, config);
7931
+ if (needsRelatedModel(model, config)) generateRelatedSchemaForModel(model, sourceFile, config);
7932
+ }, "populateModelFile");
7933
+ var generateBarrelFile = /* @__PURE__ */ __name((models, indexFile) => {
7934
+ models.forEach((model) => indexFile.addExportDeclaration({
7935
+ moduleSpecifier: `./${lowerCaseFirst(model.name)}`
7936
+ }));
7937
+ }, "generateBarrelFile");
7938
+
7597
7939
  // src/helpers.ts
7598
7940
  var getProcedureName = /* @__PURE__ */ __name((config) => {
7599
7941
  return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
@@ -8011,22 +8353,24 @@ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transfor
8011
8353
  export default options;
8012
8354
  `;
8013
8355
  }, "constructDefaultOptions");
8014
-
8015
- // src/project.ts
8016
- init_esm_shims();
8017
- import { ModuleKind, Project, ScriptTarget } from "ts-morph";
8018
- var compilerOptions = {
8019
- target: ScriptTarget.ESNext,
8020
- module: ModuleKind.ESNext,
8021
- emitDecoratorMetadata: true,
8022
- experimentalDecorators: true,
8023
- esModuleInterop: true
8024
- };
8025
- var project = new Project({
8026
- compilerOptions: {
8027
- ...compilerOptions
8028
- }
8029
- });
8356
+ var constructZodModels = /* @__PURE__ */ __name(async (models, outputPath, config, options) => {
8357
+ const indexFile = project.createSourceFile(`${outputPath}/index.ts`, {}, {
8358
+ overwrite: true
8359
+ });
8360
+ generateBarrelFile(models, indexFile);
8361
+ indexFile.formatText({
8362
+ indentSize: 2
8363
+ });
8364
+ await Promise.all(models.map(async (model) => {
8365
+ const sourceFile = project.createSourceFile(`${outputPath}/${lowerCaseFirst(model.name)}.schema.ts`, {}, {
8366
+ overwrite: true
8367
+ });
8368
+ await populateModelFile(model, sourceFile, config, options);
8369
+ sourceFile.formatText({
8370
+ indentSize: 2
8371
+ });
8372
+ }));
8373
+ }, "constructZodModels");
8030
8374
 
8031
8375
  // src/utils/write-file-safely.ts
8032
8376
  init_esm_shims();
@@ -8563,7 +8907,7 @@ var ParseOptions;
8563
8907
  allowTrailingComma: false
8564
8908
  };
8565
8909
  })(ParseOptions || (ParseOptions = {}));
8566
- function parse(text, errors = [], options = ParseOptions.DEFAULT) {
8910
+ function parse2(text, errors = [], options = ParseOptions.DEFAULT) {
8567
8911
  let currentProperty = null;
8568
8912
  let currentParent = [];
8569
8913
  const previousParents = [];
@@ -8611,7 +8955,7 @@ function parse(text, errors = [], options = ParseOptions.DEFAULT) {
8611
8955
  visit(text, visitor, options);
8612
8956
  return currentParent[0];
8613
8957
  }
8614
- __name(parse, "parse");
8958
+ __name(parse2, "parse");
8615
8959
  function visit(text, visitor, options = ParseOptions.DEFAULT) {
8616
8960
  const _scanner = createScanner(text, false);
8617
8961
  const _jsonPath = [];
@@ -8963,7 +9307,7 @@ var SyntaxKind;
8963
9307
  SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
8964
9308
  SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
8965
9309
  })(SyntaxKind || (SyntaxKind = {}));
8966
- var parse2 = parse;
9310
+ var parse3 = parse2;
8967
9311
  var ParseErrorCode;
8968
9312
  (function(ParseErrorCode2) {
8969
9313
  ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
@@ -9216,7 +9560,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
9216
9560
  // ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
9217
9561
  init_esm_shims();
9218
9562
  var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
9219
- var stringifyPath = /* @__PURE__ */ __name((path5) => path5.map(String).map(escapeKey).join("."), "stringifyPath");
9563
+ var stringifyPath = /* @__PURE__ */ __name((path6) => path6.map(String).map(escapeKey).join("."), "stringifyPath");
9220
9564
  var parsePath = /* @__PURE__ */ __name((string) => {
9221
9565
  const result = [];
9222
9566
  let segment = "";
@@ -9479,27 +9823,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
9479
9823
  }
9480
9824
  return keys.next().value;
9481
9825
  }, "getNthKey");
9482
- function validatePath(path5) {
9483
- if (includes(path5, "__proto__")) {
9826
+ function validatePath(path6) {
9827
+ if (includes(path6, "__proto__")) {
9484
9828
  throw new Error("__proto__ is not allowed as a property");
9485
9829
  }
9486
- if (includes(path5, "prototype")) {
9830
+ if (includes(path6, "prototype")) {
9487
9831
  throw new Error("prototype is not allowed as a property");
9488
9832
  }
9489
- if (includes(path5, "constructor")) {
9833
+ if (includes(path6, "constructor")) {
9490
9834
  throw new Error("constructor is not allowed as a property");
9491
9835
  }
9492
9836
  }
9493
9837
  __name(validatePath, "validatePath");
9494
- var getDeep = /* @__PURE__ */ __name((object, path5) => {
9495
- validatePath(path5);
9496
- for (let i = 0; i < path5.length; i++) {
9497
- const key = path5[i];
9838
+ var getDeep = /* @__PURE__ */ __name((object, path6) => {
9839
+ validatePath(path6);
9840
+ for (let i = 0; i < path6.length; i++) {
9841
+ const key = path6[i];
9498
9842
  if (isSet(object)) {
9499
9843
  object = getNthKey(object, +key);
9500
9844
  } else if (isMap(object)) {
9501
9845
  const row = +key;
9502
- const type = +path5[++i] === 0 ? "key" : "value";
9846
+ const type = +path6[++i] === 0 ? "key" : "value";
9503
9847
  const keyOfRow = getNthKey(object, row);
9504
9848
  switch (type) {
9505
9849
  case "key":
@@ -9515,14 +9859,14 @@ var getDeep = /* @__PURE__ */ __name((object, path5) => {
9515
9859
  }
9516
9860
  return object;
9517
9861
  }, "getDeep");
9518
- var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9519
- validatePath(path5);
9520
- if (path5.length === 0) {
9862
+ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
9863
+ validatePath(path6);
9864
+ if (path6.length === 0) {
9521
9865
  return mapper(object);
9522
9866
  }
9523
9867
  let parent = object;
9524
- for (let i = 0; i < path5.length - 1; i++) {
9525
- const key = path5[i];
9868
+ for (let i = 0; i < path6.length - 1; i++) {
9869
+ const key = path6[i];
9526
9870
  if (isArray(parent)) {
9527
9871
  const index = +key;
9528
9872
  parent = parent[index];
@@ -9532,12 +9876,12 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9532
9876
  const row = +key;
9533
9877
  parent = getNthKey(parent, row);
9534
9878
  } else if (isMap(parent)) {
9535
- const isEnd = i === path5.length - 2;
9879
+ const isEnd = i === path6.length - 2;
9536
9880
  if (isEnd) {
9537
9881
  break;
9538
9882
  }
9539
9883
  const row = +key;
9540
- const type = +path5[++i] === 0 ? "key" : "value";
9884
+ const type = +path6[++i] === 0 ? "key" : "value";
9541
9885
  const keyOfRow = getNthKey(parent, row);
9542
9886
  switch (type) {
9543
9887
  case "key":
@@ -9549,7 +9893,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9549
9893
  }
9550
9894
  }
9551
9895
  }
9552
- const lastKey = path5[path5.length - 1];
9896
+ const lastKey = path6[path6.length - 1];
9553
9897
  if (isArray(parent)) {
9554
9898
  parent[+lastKey] = mapper(parent[+lastKey]);
9555
9899
  } else if (isPlainObject2(parent)) {
@@ -9564,7 +9908,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9564
9908
  }
9565
9909
  }
9566
9910
  if (isMap(parent)) {
9567
- const row = +path5[path5.length - 2];
9911
+ const row = +path6[path6.length - 2];
9568
9912
  const keyToRow = getNthKey(parent, row);
9569
9913
  const type = +lastKey === 0 ? "key" : "value";
9570
9914
  switch (type) {
@@ -9610,15 +9954,15 @@ function traverse(tree, walker2, origin = []) {
9610
9954
  }
9611
9955
  __name(traverse, "traverse");
9612
9956
  function applyValueAnnotations(plain, annotations, superJson) {
9613
- traverse(annotations, (type, path5) => {
9614
- plain = setDeep(plain, path5, (v) => untransformValue(v, type, superJson));
9957
+ traverse(annotations, (type, path6) => {
9958
+ plain = setDeep(plain, path6, (v) => untransformValue(v, type, superJson));
9615
9959
  });
9616
9960
  return plain;
9617
9961
  }
9618
9962
  __name(applyValueAnnotations, "applyValueAnnotations");
9619
9963
  function applyReferentialEqualityAnnotations(plain, annotations) {
9620
- function apply(identicalPaths, path5) {
9621
- const object = getDeep(plain, parsePath(path5));
9964
+ function apply(identicalPaths, path6) {
9965
+ const object = getDeep(plain, parsePath(path6));
9622
9966
  identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
9623
9967
  plain = setDeep(plain, identicalObjectPath, () => object);
9624
9968
  });
@@ -9639,13 +9983,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
9639
9983
  }
9640
9984
  __name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
9641
9985
  var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
9642
- function addIdentity(object, path5, identities) {
9986
+ function addIdentity(object, path6, identities) {
9643
9987
  const existingSet = identities.get(object);
9644
9988
  if (existingSet) {
9645
- existingSet.push(path5);
9989
+ existingSet.push(path6);
9646
9990
  } else {
9647
9991
  identities.set(object, [
9648
- path5
9992
+ path6
9649
9993
  ]);
9650
9994
  }
9651
9995
  }
@@ -9658,7 +10002,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
9658
10002
  return;
9659
10003
  }
9660
10004
  if (!dedupe) {
9661
- paths = paths.map((path5) => path5.map(String)).sort((a, b) => a.length - b.length);
10005
+ paths = paths.map((path6) => path6.map(String)).sort((a, b) => a.length - b.length);
9662
10006
  }
9663
10007
  const [representativePath, ...identicalPaths] = paths;
9664
10008
  if (representativePath.length === 0) {
@@ -9683,10 +10027,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
9683
10027
  }
9684
10028
  }
9685
10029
  __name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
9686
- var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path5 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
10030
+ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path6 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
9687
10031
  const primitive = isPrimitive(object);
9688
10032
  if (!primitive) {
9689
- addIdentity(object, path5, identities);
10033
+ addIdentity(object, path6, identities);
9690
10034
  const seen = seenObjects.get(object);
9691
10035
  if (seen) {
9692
10036
  return dedupe ? {
@@ -9723,7 +10067,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
9723
10067
  throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
9724
10068
  }
9725
10069
  const recursiveResult = walker(value, identities, superJson, dedupe, [
9726
- ...path5,
10070
+ ...path6,
9727
10071
  index
9728
10072
  ], [
9729
10073
  ...objectsInThisPath,
@@ -9907,8 +10251,8 @@ SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJS
9907
10251
  SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
9908
10252
  var serialize = SuperJSON.serialize;
9909
10253
  var deserialize = SuperJSON.deserialize;
9910
- var stringify = SuperJSON.stringify;
9911
- var parse3 = SuperJSON.parse;
10254
+ var stringify2 = SuperJSON.stringify;
10255
+ var parse4 = SuperJSON.parse;
9912
10256
  var registerClass = SuperJSON.registerClass;
9913
10257
  var registerCustom = SuperJSON.registerCustom;
9914
10258
  var registerSymbol = SuperJSON.registerSymbol;
@@ -10121,7 +10465,7 @@ var isNumber2 = /* @__PURE__ */ __name((value) => {
10121
10465
  }, "isNumber");
10122
10466
 
10123
10467
  // ../json/src/utils/stringify.ts
10124
- var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10468
+ var stringify3 = /* @__PURE__ */ __name((value, spacing = 2) => {
10125
10469
  const space = isNumber2(spacing) ? " ".repeat(spacing) : spacing;
10126
10470
  switch (value) {
10127
10471
  case null: {
@@ -10138,7 +10482,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10138
10482
  }
10139
10483
  }
10140
10484
  if (Array.isArray(value)) {
10141
- return `[${space}${value.map((v) => stringify2(v, space)).join(`,${space}`)}${space}]`;
10485
+ return `[${space}${value.map((v) => stringify3(v, space)).join(`,${space}`)}${space}]`;
10142
10486
  }
10143
10487
  if (value instanceof Uint8Array) {
10144
10488
  return value.toString();
@@ -10152,7 +10496,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10152
10496
  }
10153
10497
  case "object": {
10154
10498
  const keys = Object.keys(value);
10155
- return `{${space}${keys.map((k) => `${k}: ${space}${stringify2(value[k], space)}`).join(`,${space}`)}${space}}`;
10499
+ return `{${space}${keys.map((k) => `${k}: ${space}${stringify3(value[k], space)}`).join(`,${space}`)}${space}}`;
10156
10500
  }
10157
10501
  default:
10158
10502
  return "null";
@@ -10208,7 +10552,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
10208
10552
  if (customTransformer) {
10209
10553
  result = customTransformer.serialize(result);
10210
10554
  }
10211
- return stringify2(result?.json ? result?.json : result, options?.spaces);
10555
+ return stringify3(result?.json ? result?.json : result, options?.spaces);
10212
10556
  }
10213
10557
  /**
10214
10558
  * Stringify the given value with superjson
@@ -10239,7 +10583,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
10239
10583
  allowTrailingComma: true,
10240
10584
  ...options
10241
10585
  };
10242
- const result = parse2(strData, errors, opts);
10586
+ const result = parse3(strData, errors, opts);
10243
10587
  if (errors.length > 0 && errors[0]) {
10244
10588
  throw new Error(formatParseError(strData, errors[0]));
10245
10589
  }
@@ -10303,7 +10647,7 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
10303
10647
  }, "writeFile");
10304
10648
 
10305
10649
  // src/utils/write-file-safely.ts
10306
- import path2 from "node:path";
10650
+ import path3 from "node:path";
10307
10651
 
10308
10652
  // src/utils/format-file.ts
10309
10653
  init_esm_shims();
@@ -10347,13 +10691,14 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10347
10691
  }, "writeFileSafely");
10348
10692
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10349
10693
  const rows = Array.from(indexExports).map((filePath) => {
10350
- let relativePath2 = path2.relative(path2.dirname(indexPath), filePath);
10694
+ let relativePath2 = path3.relative(path3.dirname(indexPath), filePath);
10351
10695
  if (relativePath2.endsWith(".ts")) {
10352
10696
  relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10353
10697
  }
10354
10698
  const normalized = correctPath(relativePath2);
10355
- return `export * from './${normalized}'`;
10699
+ return `export * from './${normalized}';`;
10356
10700
  });
10701
+ rows.push("export * from './models';");
10357
10702
  await writeFileSafely(indexPath, rows.join("\n"), false);
10358
10703
  }, "writeIndexFile");
10359
10704
 
@@ -10524,45 +10869,7 @@ init_esm_shims();
10524
10869
 
10525
10870
  // src/zod/transformer.ts
10526
10871
  init_esm_shims();
10527
- import path3 from "node:path";
10528
-
10529
- // src/zod/model-helpers.ts
10530
- init_esm_shims();
10531
- function checkModelHasModelRelation(model) {
10532
- const { fields: modelFields } = model;
10533
- for (const modelField of modelFields) {
10534
- const isRelationField = checkIsModelRelationField(modelField);
10535
- if (isRelationField) {
10536
- return true;
10537
- }
10538
- }
10539
- return false;
10540
- }
10541
- __name(checkModelHasModelRelation, "checkModelHasModelRelation");
10542
- function checkModelHasManyModelRelation(model) {
10543
- const { fields: modelFields } = model;
10544
- for (const modelField of modelFields) {
10545
- const isManyRelationField = checkIsManyModelRelationField(modelField);
10546
- if (isManyRelationField) {
10547
- return true;
10548
- }
10549
- }
10550
- return false;
10551
- }
10552
- __name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
10553
- function checkIsModelRelationField(modelField) {
10554
- const { kind, relationName } = modelField;
10555
- return kind === "object" && !!relationName;
10556
- }
10557
- __name(checkIsModelRelationField, "checkIsModelRelationField");
10558
- function checkIsManyModelRelationField(modelField) {
10559
- return checkIsModelRelationField(modelField) && modelField.isList;
10560
- }
10561
- __name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
10562
- function findModelByName(models, modelName) {
10563
- return models.find(({ name }) => name === modelName);
10564
- }
10565
- __name(findModelByName, "findModelByName");
10872
+ import path4 from "node:path";
10566
10873
 
10567
10874
  // src/zod/mongodb-helpers.ts
10568
10875
  init_esm_shims();
@@ -10672,13 +10979,13 @@ var Transformer = class _Transformer {
10672
10979
  this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
10673
10980
  }
10674
10981
  static async generateIndex() {
10675
- const indexPath = path3.join(_Transformer.outputPath, "schemas/index.ts");
10982
+ const indexPath = path4.join(_Transformer.outputPath, "schemas/index.ts");
10676
10983
  await writeIndexFile(indexPath);
10677
10984
  }
10678
10985
  async generateEnumSchemas() {
10679
10986
  for (const enumType2 of this.enumTypes) {
10680
10987
  const { name, values } = enumType2;
10681
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
10988
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
10682
10989
  ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
10683
10990
  }
10684
10991
  }
@@ -10692,7 +10999,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10692
10999
  const zodObjectSchemaFields = this.generateObjectSchemaFields();
10693
11000
  const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
10694
11001
  const objectSchemaName = this.resolveObjectSchemaName();
10695
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
11002
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
10696
11003
  }
10697
11004
  generateObjectSchemaFields() {
10698
11005
  const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
@@ -10827,9 +11134,9 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10827
11134
  generateImportPrismaStatement() {
10828
11135
  let prismaClientImportPath;
10829
11136
  if (_Transformer.isCustomPrismaClientOutputPath) {
10830
- const fromPath = path3.join(_Transformer.outputPath, "schemas", "objects");
11137
+ const fromPath = path4.join(_Transformer.outputPath, "schemas", "objects");
10831
11138
  const toPath = _Transformer.prismaClientOutputPath;
10832
- const relativePathFromOutputToPrismaClient = path3.relative(fromPath, toPath).split(path3.sep).join(path3.posix.sep);
11139
+ const relativePathFromOutputToPrismaClient = path4.relative(fromPath, toPath).split(path4.sep).join(path4.posix.sep);
10833
11140
  prismaClientImportPath = relativePathFromOutputToPrismaClient;
10834
11141
  } else {
10835
11142
  prismaClientImportPath = _Transformer.prismaClientOutputPath;
@@ -10959,7 +11266,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10959
11266
  includeImport,
10960
11267
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
10961
11268
  ];
10962
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11269
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
10963
11270
  }
10964
11271
  if (findFirst) {
10965
11272
  const imports = [
@@ -10970,7 +11277,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10970
11277
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
10971
11278
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
10972
11279
  ];
10973
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findFirst}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindFirst`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
11280
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${findFirst}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindFirst`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
10974
11281
  }
10975
11282
  if (findMany) {
10976
11283
  const imports = [
@@ -10981,7 +11288,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10981
11288
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
10982
11289
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
10983
11290
  ];
10984
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindMany`, `z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
11291
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${findMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindMany`, `z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
10985
11292
  }
10986
11293
  if (createOne) {
10987
11294
  const imports = [
@@ -10990,19 +11297,19 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10990
11297
  `import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
10991
11298
  `import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
10992
11299
  ];
10993
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema]) })`)}`);
11300
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${createOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema]) })`)}`);
10994
11301
  }
10995
11302
  if (createMany) {
10996
11303
  const imports = [
10997
11304
  `import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
10998
11305
  ];
10999
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateMany`, `z.object({ data: z.union([ ${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11306
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${createMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateMany`, `z.object({ data: z.union([ ${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11000
11307
  }
11001
11308
  if (createManyAndReturn) {
11002
11309
  const imports = [
11003
11310
  `import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`
11004
11311
  ];
11005
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateManyAndReturn`, `z.object({ data: z.union([ ${modelName}CreateManyAndReturnInputObjectSchema, z.array(${modelName}CreateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11312
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${createManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateManyAndReturn`, `z.object({ data: z.union([ ${modelName}CreateManyAndReturnInputObjectSchema, z.array(${modelName}CreateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11006
11313
  }
11007
11314
  if (deleteOne) {
11008
11315
  const imports = [
@@ -11010,13 +11317,13 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11010
11317
  includeImport,
11011
11318
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
11012
11319
  ];
11013
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11320
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11014
11321
  }
11015
11322
  if (deleteMany) {
11016
11323
  const imports = [
11017
11324
  `import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
11018
11325
  ];
11019
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11326
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11020
11327
  }
11021
11328
  if (updateOne) {
11022
11329
  const imports = [
@@ -11026,20 +11333,20 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11026
11333
  `import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
11027
11334
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
11028
11335
  ];
11029
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema]), where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11336
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${updateOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema]), where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11030
11337
  }
11031
11338
  if (updateMany) {
11032
11339
  const imports = [
11033
11340
  `import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
11034
11341
  `import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
11035
11342
  ];
11036
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11343
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11037
11344
  }
11038
11345
  if (updateManyAndReturn) {
11039
11346
  const imports = [
11040
11347
  `import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`
11041
11348
  ];
11042
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateManyAndReturn`, `z.object({ data: z.union([ ${modelName}UpdateManyAndReturnInputObjectSchema, z.array(${modelName}UpdateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11349
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${updateManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateManyAndReturn`, `z.object({ data: z.union([ ${modelName}UpdateManyAndReturnInputObjectSchema, z.array(${modelName}UpdateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
11043
11350
  }
11044
11351
  if (upsertOne) {
11045
11352
  const imports = [
@@ -11051,7 +11358,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11051
11358
  `import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
11052
11359
  `import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
11053
11360
  ];
11054
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${upsertOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Upsert`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema, create: z.union([ ${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema ]), update: z.union([ ${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema ]) })`)}`);
11361
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${upsertOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Upsert`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema, create: z.union([ ${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema ]), update: z.union([ ${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema ]) })`)}`);
11055
11362
  }
11056
11363
  if (aggregate) {
11057
11364
  const imports = [
@@ -11082,7 +11389,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11082
11389
  aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
11083
11390
  }
11084
11391
  }
11085
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${aggregate}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Aggregate`, `z.object({ ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${aggregateOperations.join(", ")} })`)}`);
11392
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${aggregate}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Aggregate`, `z.object({ ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${aggregateOperations.join(", ")} })`)}`);
11086
11393
  }
11087
11394
  if (groupBy) {
11088
11395
  const imports = [
@@ -11091,7 +11398,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11091
11398
  `import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
11092
11399
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
11093
11400
  ];
11094
- await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${groupBy}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}GroupBy`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${modelName}OrderByWithAggregationInputObjectSchema, ${modelName}OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${modelName}ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${modelName}ScalarFieldEnumSchema) })`)}`);
11401
+ await writeFileSafely(path4.join(_Transformer.outputPath, `schemas/${groupBy}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}GroupBy`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${modelName}OrderByWithAggregationInputObjectSchema, ${modelName}OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${modelName}ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${modelName}ScalarFieldEnumSchema) })`)}`);
11095
11402
  }
11096
11403
  }
11097
11404
  }
@@ -11572,6 +11879,7 @@ ${JSON.stringify(config)}`);
11572
11879
  if (prismaClientProvider?.isCustomOutput) {
11573
11880
  Transformer.setPrismaClientOutputPath(prismaClientProvider.output?.value);
11574
11881
  }
11882
+ await constructZodModels(models, joinPaths(zodOutputPath, "models"), config, options);
11575
11883
  resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
11576
11884
  await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
11577
11885
  const dataSource = options.datasources?.[0];
@@ -11648,12 +11956,12 @@ ${JSON.stringify(config)}`);
11648
11956
  }
11649
11957
  resolveModelsComments(models, hiddenModels);
11650
11958
  consoleLog("Generating tRPC export file");
11651
- const trpcExports = project.createSourceFile(path4.resolve(outputDir, "trpc.ts"), void 0, {
11959
+ const trpcExports = project.createSourceFile(path5.resolve(outputDir, "trpc.ts"), void 0, {
11652
11960
  overwrite: true
11653
11961
  });
11654
11962
  await generateTRPCExports(trpcExports, config, options, outputDir);
11655
11963
  consoleLog("Generating tRPC app router");
11656
- const appRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `index.ts`), void 0, {
11964
+ const appRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `index.ts`), void 0, {
11657
11965
  overwrite: true
11658
11966
  });
11659
11967
  consoleLog("Generating tRPC router imports");
@@ -11682,7 +11990,7 @@ ${JSON.stringify(config)}`);
11682
11990
  const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
11683
11991
  consoleLog(`Generating tRPC router for model ${model}`);
11684
11992
  generateRouterImport(appRouter, plural, model);
11685
- const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
11993
+ const modelRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
11686
11994
  overwrite: true
11687
11995
  });
11688
11996
  generateCreateRouterImport({