@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.cjs CHANGED
@@ -2480,20 +2480,20 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
2480
2480
 
2481
2481
  // ../fs/src/helpers.ts
2482
2482
  var import_promises2 = require("node:fs/promises");
2483
- async function createDirectory(path5) {
2484
- if (await exists(path5)) {
2483
+ async function createDirectory(path6) {
2484
+ if (await exists(path6)) {
2485
2485
  return;
2486
2486
  }
2487
- return (0, import_promises2.mkdir)(path5, {
2487
+ return (0, import_promises2.mkdir)(path6, {
2488
2488
  recursive: true
2489
2489
  });
2490
2490
  }
2491
2491
  __name(createDirectory, "createDirectory");
2492
- async function removeDirectory(path5) {
2493
- if (!existsSync(path5)) {
2492
+ async function removeDirectory(path6) {
2493
+ if (!existsSync(path6)) {
2494
2494
  return;
2495
2495
  }
2496
- return (0, import_promises2.rm)(path5, {
2496
+ return (0, import_promises2.rm)(path6, {
2497
2497
  recursive: true
2498
2498
  });
2499
2499
  }
@@ -2515,65 +2515,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
2515
2515
  var isAbsolute = /* @__PURE__ */ __name(function(p) {
2516
2516
  return _IS_ABSOLUTE_RE.test(p);
2517
2517
  }, "isAbsolute");
2518
- var correctPaths = /* @__PURE__ */ __name(function(path5) {
2519
- if (!path5 || path5.length === 0) {
2518
+ var correctPaths = /* @__PURE__ */ __name(function(path6) {
2519
+ if (!path6 || path6.length === 0) {
2520
2520
  return ".";
2521
2521
  }
2522
- path5 = normalizeWindowsPath(path5);
2523
- const isUNCPath = path5.match(_UNC_REGEX);
2524
- const isPathAbsolute = isAbsolute(path5);
2525
- const trailingSeparator = path5[path5.length - 1] === "/";
2526
- path5 = normalizeString(path5, !isPathAbsolute);
2527
- if (path5.length === 0) {
2522
+ path6 = normalizeWindowsPath(path6);
2523
+ const isUNCPath = path6.match(_UNC_REGEX);
2524
+ const isPathAbsolute = isAbsolute(path6);
2525
+ const trailingSeparator = path6[path6.length - 1] === "/";
2526
+ path6 = normalizeString(path6, !isPathAbsolute);
2527
+ if (path6.length === 0) {
2528
2528
  if (isPathAbsolute) {
2529
2529
  return "/";
2530
2530
  }
2531
2531
  return trailingSeparator ? "./" : ".";
2532
2532
  }
2533
2533
  if (trailingSeparator) {
2534
- path5 += "/";
2534
+ path6 += "/";
2535
2535
  }
2536
- if (_DRIVE_LETTER_RE.test(path5)) {
2537
- path5 += "/";
2536
+ if (_DRIVE_LETTER_RE.test(path6)) {
2537
+ path6 += "/";
2538
2538
  }
2539
2539
  if (isUNCPath) {
2540
2540
  if (!isPathAbsolute) {
2541
- return `//./${path5}`;
2541
+ return `//./${path6}`;
2542
2542
  }
2543
- return `//${path5}`;
2543
+ return `//${path6}`;
2544
2544
  }
2545
- return isPathAbsolute && !isAbsolute(path5) ? `/${path5}` : path5;
2545
+ return isPathAbsolute && !isAbsolute(path6) ? `/${path6}` : path6;
2546
2546
  }, "correctPaths");
2547
2547
  var joinPaths = /* @__PURE__ */ __name(function(...segments) {
2548
- let path5 = "";
2548
+ let path6 = "";
2549
2549
  for (const seg of segments) {
2550
2550
  if (!seg) {
2551
2551
  continue;
2552
2552
  }
2553
- if (path5.length > 0) {
2554
- const pathTrailing = path5[path5.length - 1] === "/";
2553
+ if (path6.length > 0) {
2554
+ const pathTrailing = path6[path6.length - 1] === "/";
2555
2555
  const segLeading = seg[0] === "/";
2556
2556
  const both = pathTrailing && segLeading;
2557
2557
  if (both) {
2558
- path5 += seg.slice(1);
2558
+ path6 += seg.slice(1);
2559
2559
  } else {
2560
- path5 += pathTrailing || segLeading ? seg : `/${seg}`;
2560
+ path6 += pathTrailing || segLeading ? seg : `/${seg}`;
2561
2561
  }
2562
2562
  } else {
2563
- path5 += seg;
2563
+ path6 += seg;
2564
2564
  }
2565
2565
  }
2566
- return correctPaths(path5);
2566
+ return correctPaths(path6);
2567
2567
  }, "joinPaths");
2568
- function normalizeString(path5, allowAboveRoot) {
2568
+ function normalizeString(path6, allowAboveRoot) {
2569
2569
  let res = "";
2570
2570
  let lastSegmentLength = 0;
2571
2571
  let lastSlash = -1;
2572
2572
  let dots = 0;
2573
2573
  let char = null;
2574
- for (let index = 0; index <= path5.length; ++index) {
2575
- if (index < path5.length) {
2576
- char = path5[index];
2574
+ for (let index = 0; index <= path6.length; ++index) {
2575
+ if (index < path6.length) {
2576
+ char = path6[index];
2577
2577
  } else if (char === "/") {
2578
2578
  break;
2579
2579
  } else {
@@ -2609,9 +2609,9 @@ function normalizeString(path5, allowAboveRoot) {
2609
2609
  }
2610
2610
  } else {
2611
2611
  if (res.length > 0) {
2612
- res += `/${path5.slice(lastSlash + 1, index)}`;
2612
+ res += `/${path6.slice(lastSlash + 1, index)}`;
2613
2613
  } else {
2614
- res = path5.slice(lastSlash + 1, index);
2614
+ res = path6.slice(lastSlash + 1, index);
2615
2615
  }
2616
2616
  lastSegmentLength = index - lastSlash - 1;
2617
2617
  }
@@ -2634,7 +2634,7 @@ var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
2634
2634
  }, "lowerCaseFirst");
2635
2635
 
2636
2636
  // src/prisma-generator.ts
2637
- var import_node_path5 = __toESM(require("node:path"), 1);
2637
+ var import_node_path6 = __toESM(require("node:path"), 1);
2638
2638
  var import_pluralize = __toESM(require_pluralize(), 1);
2639
2639
 
2640
2640
  // src/config.ts
@@ -3002,8 +3002,8 @@ function getErrorMap() {
3002
3002
  }
3003
3003
  __name(getErrorMap, "getErrorMap");
3004
3004
  var makeIssue = /* @__PURE__ */ __name((params) => {
3005
- const { data, path: path5, errorMaps, issueData } = params;
3006
- const fullPath = [...path5, ...issueData.path || []];
3005
+ const { data, path: path6, errorMaps, issueData } = params;
3006
+ const fullPath = [...path6, ...issueData.path || []];
3007
3007
  const fullIssue = {
3008
3008
  ...issueData,
3009
3009
  path: fullPath
@@ -3137,11 +3137,11 @@ var ParseInputLazyPath = class {
3137
3137
  static {
3138
3138
  __name(this, "ParseInputLazyPath");
3139
3139
  }
3140
- constructor(parent, value, path5, key) {
3140
+ constructor(parent, value, path6, key) {
3141
3141
  this._cachedPath = [];
3142
3142
  this.parent = parent;
3143
3143
  this.data = value;
3144
- this._path = path5;
3144
+ this._path = path6;
3145
3145
  this._key = key;
3146
3146
  }
3147
3147
  get path() {
@@ -6873,7 +6873,6 @@ var modelActionEnum = z.nativeEnum(ModelAction);
6873
6873
  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);
6874
6874
  var configSchema = z.object({
6875
6875
  debug: configBoolean.default("false"),
6876
- withZod: configBoolean.default("true"),
6877
6876
  withNext: configBoolean.default("true"),
6878
6877
  withMiddleware: configBoolean.default("false"),
6879
6878
  withShield: configBoolean.default("false"),
@@ -6882,7 +6881,18 @@ var configSchema = z.object({
6882
6881
  showModelNameInProcedure: configBoolean.default("false"),
6883
6882
  generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
6884
6883
  return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
6885
- })
6884
+ }),
6885
+ // Zod configuration
6886
+ withZod: configBoolean.default("true"),
6887
+ relationModel: configBoolean.default("true").or(z.literal("default")),
6888
+ modelSuffix: z.string().default("Model"),
6889
+ modelCase: z.enum([
6890
+ "PascalCase",
6891
+ "camelCase"
6892
+ ]).default("PascalCase"),
6893
+ useDecimalJs: configBoolean.default("false"),
6894
+ imports: z.string().optional(),
6895
+ prismaJsonNullability: configBoolean.default("true")
6886
6896
  });
6887
6897
 
6888
6898
  // src/helpers.ts
@@ -6902,20 +6912,20 @@ init_cjs_shims();
6902
6912
  // ../path/src/is-file.ts
6903
6913
  init_cjs_shims();
6904
6914
  var import_node_fs2 = require("node:fs");
6905
- function isFile(path5, additionalPath) {
6906
- return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path5) : path5, {
6915
+ function isFile(path6, additionalPath) {
6916
+ return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
6907
6917
  throwIfNoEntry: false
6908
6918
  })?.isFile());
6909
6919
  }
6910
6920
  __name(isFile, "isFile");
6911
- function isDirectory(path5, additionalPath) {
6912
- return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path5) : path5, {
6921
+ function isDirectory(path6, additionalPath) {
6922
+ return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
6913
6923
  throwIfNoEntry: false
6914
6924
  })?.isDirectory());
6915
6925
  }
6916
6926
  __name(isDirectory, "isDirectory");
6917
- function isAbsolutePath(path5) {
6918
- return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path5);
6927
+ function isAbsolutePath(path6) {
6928
+ return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path6);
6919
6929
  }
6920
6930
  __name(isAbsolutePath, "isAbsolutePath");
6921
6931
 
@@ -6930,45 +6940,45 @@ function normalizeWindowsPath2(input = "") {
6930
6940
  __name(normalizeWindowsPath2, "normalizeWindowsPath");
6931
6941
  var _UNC_REGEX2 = /^[/\\]{2}/;
6932
6942
  var _DRIVE_LETTER_RE2 = /^[A-Z]:$/i;
6933
- function correctPath(path5) {
6934
- if (!path5 || path5.length === 0) {
6943
+ function correctPath(path6) {
6944
+ if (!path6 || path6.length === 0) {
6935
6945
  return ".";
6936
6946
  }
6937
- path5 = normalizeWindowsPath2(path5);
6938
- const isUNCPath = path5.match(_UNC_REGEX2);
6939
- const isPathAbsolute = isAbsolutePath(path5);
6940
- const trailingSeparator = path5[path5.length - 1] === "/";
6941
- path5 = normalizeString2(path5, !isPathAbsolute);
6942
- if (path5.length === 0) {
6947
+ path6 = normalizeWindowsPath2(path6);
6948
+ const isUNCPath = path6.match(_UNC_REGEX2);
6949
+ const isPathAbsolute = isAbsolutePath(path6);
6950
+ const trailingSeparator = path6[path6.length - 1] === "/";
6951
+ path6 = normalizeString2(path6, !isPathAbsolute);
6952
+ if (path6.length === 0) {
6943
6953
  if (isPathAbsolute) {
6944
6954
  return "/";
6945
6955
  }
6946
6956
  return trailingSeparator ? "./" : ".";
6947
6957
  }
6948
6958
  if (trailingSeparator) {
6949
- path5 += "/";
6959
+ path6 += "/";
6950
6960
  }
6951
- if (_DRIVE_LETTER_RE2.test(path5)) {
6952
- path5 += "/";
6961
+ if (_DRIVE_LETTER_RE2.test(path6)) {
6962
+ path6 += "/";
6953
6963
  }
6954
6964
  if (isUNCPath) {
6955
6965
  if (!isPathAbsolute) {
6956
- return `//./${path5}`;
6966
+ return `//./${path6}`;
6957
6967
  }
6958
- return `//${path5}`;
6968
+ return `//${path6}`;
6959
6969
  }
6960
- return isPathAbsolute && !isAbsolutePath(path5) ? `/${path5}` : path5;
6970
+ return isPathAbsolute && !isAbsolutePath(path6) ? `/${path6}` : path6;
6961
6971
  }
6962
6972
  __name(correctPath, "correctPath");
6963
- function normalizeString2(path5, allowAboveRoot) {
6973
+ function normalizeString2(path6, allowAboveRoot) {
6964
6974
  let res = "";
6965
6975
  let lastSegmentLength = 0;
6966
6976
  let lastSlash = -1;
6967
6977
  let dots = 0;
6968
6978
  let char = null;
6969
- for (let index = 0; index <= path5.length; ++index) {
6970
- if (index < path5.length) {
6971
- char = path5[index];
6979
+ for (let index = 0; index <= path6.length; ++index) {
6980
+ if (index < path6.length) {
6981
+ char = path6[index];
6972
6982
  } else if (char === "/") {
6973
6983
  break;
6974
6984
  } else {
@@ -7004,9 +7014,9 @@ function normalizeString2(path5, allowAboveRoot) {
7004
7014
  }
7005
7015
  } else {
7006
7016
  if (res.length > 0) {
7007
- res += `/${path5.slice(lastSlash + 1, index)}`;
7017
+ res += `/${path6.slice(lastSlash + 1, index)}`;
7008
7018
  } else {
7009
- res = path5.slice(lastSlash + 1, index);
7019
+ res = path6.slice(lastSlash + 1, index);
7010
7020
  }
7011
7021
  lastSegmentLength = index - lastSlash - 1;
7012
7022
  }
@@ -7078,34 +7088,34 @@ __name2(normalizeWindowsPath3, "normalizeWindowsPath");
7078
7088
  var _UNC_REGEX3 = /^[/\\]{2}/;
7079
7089
  var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
7080
7090
  var _DRIVE_LETTER_RE3 = /^[A-Za-z]:$/;
7081
- var correctPaths2 = /* @__PURE__ */ __name2(function(path5) {
7082
- if (!path5 || path5.length === 0) {
7091
+ var correctPaths2 = /* @__PURE__ */ __name2(function(path6) {
7092
+ if (!path6 || path6.length === 0) {
7083
7093
  return ".";
7084
7094
  }
7085
- path5 = normalizeWindowsPath3(path5);
7086
- const isUNCPath = path5.match(_UNC_REGEX3);
7087
- const isPathAbsolute = isAbsolute2(path5);
7088
- const trailingSeparator = path5[path5.length - 1] === "/";
7089
- path5 = normalizeString3(path5, !isPathAbsolute);
7090
- if (path5.length === 0) {
7095
+ path6 = normalizeWindowsPath3(path6);
7096
+ const isUNCPath = path6.match(_UNC_REGEX3);
7097
+ const isPathAbsolute = isAbsolute2(path6);
7098
+ const trailingSeparator = path6[path6.length - 1] === "/";
7099
+ path6 = normalizeString3(path6, !isPathAbsolute);
7100
+ if (path6.length === 0) {
7091
7101
  if (isPathAbsolute) {
7092
7102
  return "/";
7093
7103
  }
7094
7104
  return trailingSeparator ? "./" : ".";
7095
7105
  }
7096
7106
  if (trailingSeparator) {
7097
- path5 += "/";
7107
+ path6 += "/";
7098
7108
  }
7099
- if (_DRIVE_LETTER_RE3.test(path5)) {
7100
- path5 += "/";
7109
+ if (_DRIVE_LETTER_RE3.test(path6)) {
7110
+ path6 += "/";
7101
7111
  }
7102
7112
  if (isUNCPath) {
7103
7113
  if (!isPathAbsolute) {
7104
- return `//./${path5}`;
7114
+ return `//./${path6}`;
7105
7115
  }
7106
- return `//${path5}`;
7116
+ return `//${path6}`;
7107
7117
  }
7108
- return isPathAbsolute && !isAbsolute2(path5) ? `/${path5}` : path5;
7118
+ return isPathAbsolute && !isAbsolute2(path6) ? `/${path6}` : path6;
7109
7119
  }, "correctPaths");
7110
7120
  function cwd() {
7111
7121
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -7115,15 +7125,15 @@ function cwd() {
7115
7125
  }
7116
7126
  __name(cwd, "cwd");
7117
7127
  __name2(cwd, "cwd");
7118
- function normalizeString3(path5, allowAboveRoot) {
7128
+ function normalizeString3(path6, allowAboveRoot) {
7119
7129
  let res = "";
7120
7130
  let lastSegmentLength = 0;
7121
7131
  let lastSlash = -1;
7122
7132
  let dots = 0;
7123
7133
  let char = null;
7124
- for (let index = 0; index <= path5.length; ++index) {
7125
- if (index < path5.length) {
7126
- char = path5[index];
7134
+ for (let index = 0; index <= path6.length; ++index) {
7135
+ if (index < path6.length) {
7136
+ char = path6[index];
7127
7137
  } else if (char === "/") {
7128
7138
  break;
7129
7139
  } else {
@@ -7159,9 +7169,9 @@ function normalizeString3(path5, allowAboveRoot) {
7159
7169
  }
7160
7170
  } else {
7161
7171
  if (res.length > 0) {
7162
- res += `/${path5.slice(lastSlash + 1, index)}`;
7172
+ res += `/${path6.slice(lastSlash + 1, index)}`;
7163
7173
  } else {
7164
- res = path5.slice(lastSlash + 1, index);
7174
+ res = path6.slice(lastSlash + 1, index);
7165
7175
  }
7166
7176
  lastSegmentLength = index - lastSlash - 1;
7167
7177
  }
@@ -7246,8 +7256,8 @@ __name2(findWorkspaceRoot, "findWorkspaceRoot");
7246
7256
 
7247
7257
  // ../path/src/get-parent-path.ts
7248
7258
  init_cjs_shims();
7249
- var resolveParentPath = /* @__PURE__ */ __name((path5) => {
7250
- return resolvePaths(path5, "..");
7259
+ var resolveParentPath = /* @__PURE__ */ __name((path6) => {
7260
+ return resolvePaths(path6, "..");
7251
7261
  }, "resolveParentPath");
7252
7262
  var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
7253
7263
  const ignoreCase = options?.ignoreCase ?? true;
@@ -7352,17 +7362,17 @@ function findFilePath(filePath) {
7352
7362
  }), "");
7353
7363
  }
7354
7364
  __name(findFilePath, "findFilePath");
7355
- function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
7356
- const paths = normalizeWindowsPath2(path5).split("/");
7365
+ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
7366
+ const paths = normalizeWindowsPath2(path6).split("/");
7357
7367
  let resolvedPath = "";
7358
7368
  let resolvedAbsolute = false;
7359
7369
  for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
7360
- const path6 = index >= 0 ? paths[index] : cwd2;
7361
- if (!path6 || path6.length === 0) {
7370
+ const path7 = index >= 0 ? paths[index] : cwd2;
7371
+ if (!path7 || path7.length === 0) {
7362
7372
  continue;
7363
7373
  }
7364
- resolvedPath = joinPaths(path6, resolvedPath);
7365
- resolvedAbsolute = isAbsolutePath(path6);
7374
+ resolvedPath = joinPaths(path7, resolvedPath);
7375
+ resolvedAbsolute = isAbsolutePath(path7);
7366
7376
  }
7367
7377
  resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute);
7368
7378
  if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
@@ -7372,7 +7382,7 @@ function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
7372
7382
  }
7373
7383
  __name(resolvePath, "resolvePath");
7374
7384
  function resolvePaths(...paths) {
7375
- return resolvePath(joinPaths(...paths.map((path5) => normalizeWindowsPath2(path5))));
7385
+ return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
7376
7386
  }
7377
7387
  __name(resolvePaths, "resolvePaths");
7378
7388
  function relativePath(from, to) {
@@ -7398,6 +7408,22 @@ function relativePath(from, to) {
7398
7408
  }
7399
7409
  __name(relativePath, "relativePath");
7400
7410
 
7411
+ // src/project.ts
7412
+ init_cjs_shims();
7413
+ var import_ts_morph = require("ts-morph");
7414
+ var compilerOptions = {
7415
+ target: import_ts_morph.ScriptTarget.ESNext,
7416
+ module: import_ts_morph.ModuleKind.ESNext,
7417
+ emitDecoratorMetadata: true,
7418
+ experimentalDecorators: true,
7419
+ esModuleInterop: true
7420
+ };
7421
+ var project = new import_ts_morph.Project({
7422
+ compilerOptions: {
7423
+ ...compilerOptions
7424
+ }
7425
+ });
7426
+
7401
7427
  // src/utils/get-prisma-internals.ts
7402
7428
  init_cjs_shims();
7403
7429
 
@@ -7589,6 +7615,322 @@ async function getPrismaGeneratorHelper() {
7589
7615
  }
7590
7616
  __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
7591
7617
 
7618
+ // src/zod/model-helpers.ts
7619
+ init_cjs_shims();
7620
+ var import_node_path3 = __toESM(require("node:path"), 1);
7621
+ var import_ts_morph2 = require("ts-morph");
7622
+
7623
+ // src/zod/docs-helpers.ts
7624
+ init_cjs_shims();
7625
+ var import_parenthesis = require("parenthesis");
7626
+ var getJSDocs = /* @__PURE__ */ __name((docString) => {
7627
+ const lines = [];
7628
+ if (docString) {
7629
+ const docLines = docString.split("\n").filter((dL) => !dL.trimStart().startsWith("@zod"));
7630
+ if (docLines.length) {
7631
+ lines.push("/**");
7632
+ docLines.forEach((dL) => lines.push(` * ${dL}`));
7633
+ lines.push(" */");
7634
+ }
7635
+ }
7636
+ return lines;
7637
+ }, "getJSDocs");
7638
+ var getZodDocElements = /* @__PURE__ */ __name((docString) => docString.split("\n").filter((line) => line.trimStart().startsWith("@zod")).map((line) => line.trimStart().slice(4)).flatMap((line) => (
7639
+ // Array.from(line.matchAll(/\.([^().]+\(.*?\))/g), (m) => m.slice(1)).flat()
7640
+ chunk((0, import_parenthesis.parse)(line), 2).slice(0, -1).map(([each, contents]) => `${each.replace(/\)?\./, "")}${(0, import_parenthesis.stringify)(contents)})`)
7641
+ )), "getZodDocElements");
7642
+
7643
+ // src/zod/model-helpers.ts
7644
+ function checkModelHasModelRelation(model) {
7645
+ const { fields: modelFields } = model;
7646
+ for (const modelField of modelFields) {
7647
+ const isRelationField = checkIsModelRelationField(modelField);
7648
+ if (isRelationField) {
7649
+ return true;
7650
+ }
7651
+ }
7652
+ return false;
7653
+ }
7654
+ __name(checkModelHasModelRelation, "checkModelHasModelRelation");
7655
+ function checkModelHasManyModelRelation(model) {
7656
+ const { fields: modelFields } = model;
7657
+ for (const modelField of modelFields) {
7658
+ const isManyRelationField = checkIsManyModelRelationField(modelField);
7659
+ if (isManyRelationField) {
7660
+ return true;
7661
+ }
7662
+ }
7663
+ return false;
7664
+ }
7665
+ __name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
7666
+ function checkIsModelRelationField(modelField) {
7667
+ const { kind, relationName } = modelField;
7668
+ return kind === "object" && !!relationName;
7669
+ }
7670
+ __name(checkIsModelRelationField, "checkIsModelRelationField");
7671
+ function checkIsManyModelRelationField(modelField) {
7672
+ return checkIsModelRelationField(modelField) && modelField.isList;
7673
+ }
7674
+ __name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
7675
+ function findModelByName(models, modelName) {
7676
+ return models.find(({ name }) => name === modelName);
7677
+ }
7678
+ __name(findModelByName, "findModelByName");
7679
+ var writeArray = /* @__PURE__ */ __name((writer, array, newLine = true) => array.forEach((line) => writer.write(line).conditionalNewLine(newLine)), "writeArray");
7680
+ var useModelNames = /* @__PURE__ */ __name(({ modelCase, modelSuffix, relationModel }) => {
7681
+ const formatModelName = /* @__PURE__ */ __name((name, prefix = "") => {
7682
+ if (modelCase === "camelCase") {
7683
+ name = name.slice(0, 1).toLowerCase() + name.slice(1);
7684
+ }
7685
+ return `${prefix}${name}${modelSuffix}`;
7686
+ }, "formatModelName");
7687
+ return {
7688
+ modelName: /* @__PURE__ */ __name((name) => formatModelName(name, relationModel === "default" ? "_" : ""), "modelName"),
7689
+ relatedModelName: /* @__PURE__ */ __name((name) => formatModelName(relationModel === "default" ? name.toString() : `Related${name.toString()}`), "relatedModelName")
7690
+ };
7691
+ }, "useModelNames");
7692
+ var dotSlash = /* @__PURE__ */ __name((input) => {
7693
+ const converted = input.replace(/^\\\\\?\\/, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/");
7694
+ if (converted.includes(`/node_modules/`)) return converted.split(`/node_modules/`).slice(-1)[0];
7695
+ if (converted.startsWith(`../`)) return converted;
7696
+ return `./${converted}`;
7697
+ }, "dotSlash");
7698
+ var chunk = /* @__PURE__ */ __name((input, size) => {
7699
+ return input.reduce((arr, item, idx) => {
7700
+ return idx % size === 0 ? [
7701
+ ...arr,
7702
+ [
7703
+ item
7704
+ ]
7705
+ ] : [
7706
+ ...arr.slice(0, -1),
7707
+ [
7708
+ ...arr.slice(-1)[0],
7709
+ item
7710
+ ]
7711
+ ];
7712
+ }, []);
7713
+ }, "chunk");
7714
+ var needsRelatedModel = /* @__PURE__ */ __name((model, config) => model.fields.some((field) => field.kind === "object") && config.relationModel !== false, "needsRelatedModel");
7715
+ var writeImportsForModel = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
7716
+ const internals = await getPrismaInternals();
7717
+ const outputPath = internals.parseEnvValue(options.generator.output);
7718
+ const { relatedModelName } = useModelNames(config);
7719
+ const importList = [
7720
+ {
7721
+ kind: import_ts_morph2.StructureKind.ImportDeclaration,
7722
+ namespaceImport: "z",
7723
+ moduleSpecifier: "zod"
7724
+ }
7725
+ ];
7726
+ if (config.imports) {
7727
+ importList.push({
7728
+ kind: import_ts_morph2.StructureKind.ImportDeclaration,
7729
+ namespaceImport: "imports",
7730
+ moduleSpecifier: dotSlash(import_node_path3.default.relative(outputPath, import_node_path3.default.resolve(import_node_path3.default.dirname(options.schemaPath), config.imports)))
7731
+ });
7732
+ }
7733
+ if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
7734
+ importList.push({
7735
+ kind: import_ts_morph2.StructureKind.ImportDeclaration,
7736
+ namedImports: [
7737
+ "Decimal"
7738
+ ],
7739
+ moduleSpecifier: "decimal.js"
7740
+ });
7741
+ }
7742
+ const enumFields = model.fields.filter((f) => f.kind === "enum");
7743
+ const relationFields = model.fields.filter((f) => f.kind === "object");
7744
+ const clientPath = options.otherGenerators.find((each) => each.provider.value === "prisma-client-js").output.value;
7745
+ const relativePath2 = import_node_path3.default.relative(outputPath, clientPath);
7746
+ if (enumFields.length > 0) {
7747
+ importList.push({
7748
+ kind: import_ts_morph2.StructureKind.ImportDeclaration,
7749
+ isTypeOnly: enumFields.length === 0,
7750
+ moduleSpecifier: dotSlash(relativePath2),
7751
+ namedImports: enumFields.map((f) => f.type)
7752
+ });
7753
+ }
7754
+ if (config.relationModel !== false && relationFields.length > 0) {
7755
+ const filteredFields = relationFields.filter((f) => f.type !== model.name);
7756
+ if (filteredFields.length > 0) {
7757
+ importList.push({
7758
+ kind: import_ts_morph2.StructureKind.ImportDeclaration,
7759
+ moduleSpecifier: "./index",
7760
+ namedImports: Array.from(new Set(filteredFields.flatMap((f) => [
7761
+ `${f.type}`,
7762
+ relatedModelName(f.type)
7763
+ ])))
7764
+ });
7765
+ }
7766
+ }
7767
+ sourceFile.addImportDeclarations(importList);
7768
+ }, "writeImportsForModel");
7769
+ var computeCustomSchema = /* @__PURE__ */ __name((docString) => {
7770
+ return getZodDocElements(docString).find((modifier) => modifier.startsWith("custom("))?.slice(7).slice(0, -1);
7771
+ }, "computeCustomSchema");
7772
+ var computeModifiers = /* @__PURE__ */ __name((docString) => {
7773
+ return getZodDocElements(docString).filter((each) => !each.startsWith("custom("));
7774
+ }, "computeModifiers");
7775
+ var getZodConstructor = /* @__PURE__ */ __name((field, getRelatedModelName = (name) => name.toString()) => {
7776
+ let zodType = "z.unknown()";
7777
+ const extraModifiers = [
7778
+ ""
7779
+ ];
7780
+ if (field.kind === "scalar") {
7781
+ switch (field.type) {
7782
+ case "String":
7783
+ zodType = "z.string()";
7784
+ break;
7785
+ case "Int":
7786
+ zodType = "z.number()";
7787
+ extraModifiers.push("int()");
7788
+ break;
7789
+ case "BigInt":
7790
+ zodType = "z.bigint()";
7791
+ break;
7792
+ case "DateTime":
7793
+ zodType = "z.date()";
7794
+ break;
7795
+ case "Float":
7796
+ zodType = "z.number()";
7797
+ break;
7798
+ case "Decimal":
7799
+ zodType = "z.number()";
7800
+ break;
7801
+ case "Json":
7802
+ zodType = "jsonSchema";
7803
+ break;
7804
+ case "Boolean":
7805
+ zodType = "z.boolean()";
7806
+ break;
7807
+ // TODO: Proper type for bytes fields
7808
+ case "Bytes":
7809
+ zodType = "z.unknown()";
7810
+ break;
7811
+ }
7812
+ } else if (field.kind === "enum") {
7813
+ zodType = `z.nativeEnum(${field.type})`;
7814
+ } else if (field.kind === "object") {
7815
+ zodType = getRelatedModelName(field.type);
7816
+ }
7817
+ if (field.isList) extraModifiers.push("array()");
7818
+ if (field.documentation) {
7819
+ zodType = computeCustomSchema(field.documentation) ?? zodType;
7820
+ extraModifiers.push(...computeModifiers(field.documentation));
7821
+ }
7822
+ if (!field.isRequired && field.type !== "Json") extraModifiers.push("nullish()");
7823
+ return `${zodType}${extraModifiers.join(".")}`;
7824
+ }, "getZodConstructor");
7825
+ var writeTypeSpecificSchemas = /* @__PURE__ */ __name((model, sourceFile, config) => {
7826
+ if (model.fields.some((f) => f.type === "Json")) {
7827
+ sourceFile.addStatements((writer) => {
7828
+ writer.newLine();
7829
+ writeArray(writer, [
7830
+ "// Helper schema for JSON fields",
7831
+ `type Literal = boolean | number | string${config.prismaJsonNullability ? "" : "| null"}`,
7832
+ "type Json = Literal | { [key: string]: Json } | Json[]",
7833
+ `const literalSchema = z.union([z.string(), z.number(), z.boolean()${config.prismaJsonNullability ? "" : ", z.null()"}])`,
7834
+ "const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))"
7835
+ ]);
7836
+ });
7837
+ }
7838
+ if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
7839
+ sourceFile.addStatements((writer) => {
7840
+ writer.newLine();
7841
+ writeArray(writer, [
7842
+ "// Helper schema for Decimal fields",
7843
+ "z",
7844
+ ".instanceof(Decimal)",
7845
+ ".or(z.string())",
7846
+ ".or(z.number())",
7847
+ ".refine((value) => {",
7848
+ " try {",
7849
+ " return new Decimal(value);",
7850
+ " } catch (error) {",
7851
+ " return false;",
7852
+ " }",
7853
+ "})",
7854
+ ".transform((value) => new Decimal(value));"
7855
+ ]);
7856
+ });
7857
+ }
7858
+ }, "writeTypeSpecificSchemas");
7859
+ var generateSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
7860
+ const { modelName } = useModelNames(config);
7861
+ sourceFile.addVariableStatement({
7862
+ declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
7863
+ isExported: true,
7864
+ leadingTrivia: /* @__PURE__ */ __name((writer) => writer.blankLineIfLastNot(), "leadingTrivia"),
7865
+ declarations: [
7866
+ {
7867
+ name: modelName(model.name),
7868
+ initializer(writer) {
7869
+ writer.write("z.object(").inlineBlock(() => {
7870
+ model.fields.filter((f) => f.kind !== "object").forEach((field) => {
7871
+ writeArray(writer, getJSDocs(field.documentation));
7872
+ writer.write(`${field.name}: ${getZodConstructor(field)}`).write(",").newLine();
7873
+ });
7874
+ }).write(")");
7875
+ }
7876
+ }
7877
+ ]
7878
+ });
7879
+ }, "generateSchemaForModel");
7880
+ var generateRelatedSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
7881
+ const { modelName, relatedModelName } = useModelNames(config);
7882
+ const relationFields = model.fields.filter((f) => f.kind === "object");
7883
+ sourceFile.addInterface({
7884
+ name: `${model.name}`,
7885
+ isExported: true,
7886
+ extends: [
7887
+ `z.infer<typeof ${modelName(model.name)}>`
7888
+ ],
7889
+ properties: relationFields.map((f) => ({
7890
+ hasQuestionToken: !f.isRequired,
7891
+ name: f.name,
7892
+ type: `${f.type}${f.isList ? "[]" : ""}${!f.isRequired ? " | null" : ""}`
7893
+ }))
7894
+ });
7895
+ sourceFile.addStatements((writer) => writeArray(writer, [
7896
+ "",
7897
+ "/**",
7898
+ ` * ${relatedModelName(model.name)} contains all relations on your model in addition to the scalars`,
7899
+ " *",
7900
+ " * NOTE: Lazy required in case of potential circular dependencies within schema",
7901
+ " */"
7902
+ ]));
7903
+ sourceFile.addVariableStatement({
7904
+ declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
7905
+ isExported: true,
7906
+ declarations: [
7907
+ {
7908
+ name: relatedModelName(model.name),
7909
+ type: `z.ZodSchema<${model.name}>`,
7910
+ initializer(writer) {
7911
+ writer.write(`z.lazy(() => ${modelName(model.name)}.extend(`).inlineBlock(() => {
7912
+ relationFields.forEach((field) => {
7913
+ writeArray(writer, getJSDocs(field.documentation));
7914
+ writer.write(`${field.name}: ${getZodConstructor(field, relatedModelName)}`).write(",").newLine();
7915
+ });
7916
+ }).write("))");
7917
+ }
7918
+ }
7919
+ ]
7920
+ });
7921
+ }, "generateRelatedSchemaForModel");
7922
+ var populateModelFile = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
7923
+ await writeImportsForModel(model, sourceFile, config, options);
7924
+ writeTypeSpecificSchemas(model, sourceFile, config);
7925
+ generateSchemaForModel(model, sourceFile, config);
7926
+ if (needsRelatedModel(model, config)) generateRelatedSchemaForModel(model, sourceFile, config);
7927
+ }, "populateModelFile");
7928
+ var generateBarrelFile = /* @__PURE__ */ __name((models, indexFile) => {
7929
+ models.forEach((model) => indexFile.addExportDeclaration({
7930
+ moduleSpecifier: `./${lowerCaseFirst(model.name)}`
7931
+ }));
7932
+ }, "generateBarrelFile");
7933
+
7592
7934
  // src/helpers.ts
7593
7935
  var getProcedureName = /* @__PURE__ */ __name((config) => {
7594
7936
  return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
@@ -8006,22 +8348,24 @@ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transfor
8006
8348
  export default options;
8007
8349
  `;
8008
8350
  }, "constructDefaultOptions");
8009
-
8010
- // src/project.ts
8011
- init_cjs_shims();
8012
- var import_ts_morph = require("ts-morph");
8013
- var compilerOptions = {
8014
- target: import_ts_morph.ScriptTarget.ESNext,
8015
- module: import_ts_morph.ModuleKind.ESNext,
8016
- emitDecoratorMetadata: true,
8017
- experimentalDecorators: true,
8018
- esModuleInterop: true
8019
- };
8020
- var project = new import_ts_morph.Project({
8021
- compilerOptions: {
8022
- ...compilerOptions
8023
- }
8024
- });
8351
+ var constructZodModels = /* @__PURE__ */ __name(async (models, outputPath, config, options) => {
8352
+ const indexFile = project.createSourceFile(`${outputPath}/index.ts`, {}, {
8353
+ overwrite: true
8354
+ });
8355
+ generateBarrelFile(models, indexFile);
8356
+ indexFile.formatText({
8357
+ indentSize: 2
8358
+ });
8359
+ await Promise.all(models.map(async (model) => {
8360
+ const sourceFile = project.createSourceFile(`${outputPath}/${lowerCaseFirst(model.name)}.schema.ts`, {}, {
8361
+ overwrite: true
8362
+ });
8363
+ await populateModelFile(model, sourceFile, config, options);
8364
+ sourceFile.formatText({
8365
+ indentSize: 2
8366
+ });
8367
+ }));
8368
+ }, "constructZodModels");
8025
8369
 
8026
8370
  // src/utils/write-file-safely.ts
8027
8371
  init_cjs_shims();
@@ -8558,7 +8902,7 @@ var ParseOptions;
8558
8902
  allowTrailingComma: false
8559
8903
  };
8560
8904
  })(ParseOptions || (ParseOptions = {}));
8561
- function parse(text, errors = [], options = ParseOptions.DEFAULT) {
8905
+ function parse2(text, errors = [], options = ParseOptions.DEFAULT) {
8562
8906
  let currentProperty = null;
8563
8907
  let currentParent = [];
8564
8908
  const previousParents = [];
@@ -8606,7 +8950,7 @@ function parse(text, errors = [], options = ParseOptions.DEFAULT) {
8606
8950
  visit(text, visitor, options);
8607
8951
  return currentParent[0];
8608
8952
  }
8609
- __name(parse, "parse");
8953
+ __name(parse2, "parse");
8610
8954
  function visit(text, visitor, options = ParseOptions.DEFAULT) {
8611
8955
  const _scanner = createScanner(text, false);
8612
8956
  const _jsonPath = [];
@@ -8958,7 +9302,7 @@ var SyntaxKind;
8958
9302
  SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
8959
9303
  SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
8960
9304
  })(SyntaxKind || (SyntaxKind = {}));
8961
- var parse2 = parse;
9305
+ var parse3 = parse2;
8962
9306
  var ParseErrorCode;
8963
9307
  (function(ParseErrorCode2) {
8964
9308
  ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
@@ -9211,7 +9555,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
9211
9555
  // ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
9212
9556
  init_cjs_shims();
9213
9557
  var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
9214
- var stringifyPath = /* @__PURE__ */ __name((path5) => path5.map(String).map(escapeKey).join("."), "stringifyPath");
9558
+ var stringifyPath = /* @__PURE__ */ __name((path6) => path6.map(String).map(escapeKey).join("."), "stringifyPath");
9215
9559
  var parsePath = /* @__PURE__ */ __name((string) => {
9216
9560
  const result = [];
9217
9561
  let segment = "";
@@ -9474,27 +9818,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
9474
9818
  }
9475
9819
  return keys.next().value;
9476
9820
  }, "getNthKey");
9477
- function validatePath(path5) {
9478
- if (includes(path5, "__proto__")) {
9821
+ function validatePath(path6) {
9822
+ if (includes(path6, "__proto__")) {
9479
9823
  throw new Error("__proto__ is not allowed as a property");
9480
9824
  }
9481
- if (includes(path5, "prototype")) {
9825
+ if (includes(path6, "prototype")) {
9482
9826
  throw new Error("prototype is not allowed as a property");
9483
9827
  }
9484
- if (includes(path5, "constructor")) {
9828
+ if (includes(path6, "constructor")) {
9485
9829
  throw new Error("constructor is not allowed as a property");
9486
9830
  }
9487
9831
  }
9488
9832
  __name(validatePath, "validatePath");
9489
- var getDeep = /* @__PURE__ */ __name((object, path5) => {
9490
- validatePath(path5);
9491
- for (let i = 0; i < path5.length; i++) {
9492
- const key = path5[i];
9833
+ var getDeep = /* @__PURE__ */ __name((object, path6) => {
9834
+ validatePath(path6);
9835
+ for (let i = 0; i < path6.length; i++) {
9836
+ const key = path6[i];
9493
9837
  if (isSet(object)) {
9494
9838
  object = getNthKey(object, +key);
9495
9839
  } else if (isMap(object)) {
9496
9840
  const row = +key;
9497
- const type = +path5[++i] === 0 ? "key" : "value";
9841
+ const type = +path6[++i] === 0 ? "key" : "value";
9498
9842
  const keyOfRow = getNthKey(object, row);
9499
9843
  switch (type) {
9500
9844
  case "key":
@@ -9510,14 +9854,14 @@ var getDeep = /* @__PURE__ */ __name((object, path5) => {
9510
9854
  }
9511
9855
  return object;
9512
9856
  }, "getDeep");
9513
- var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9514
- validatePath(path5);
9515
- if (path5.length === 0) {
9857
+ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
9858
+ validatePath(path6);
9859
+ if (path6.length === 0) {
9516
9860
  return mapper(object);
9517
9861
  }
9518
9862
  let parent = object;
9519
- for (let i = 0; i < path5.length - 1; i++) {
9520
- const key = path5[i];
9863
+ for (let i = 0; i < path6.length - 1; i++) {
9864
+ const key = path6[i];
9521
9865
  if (isArray(parent)) {
9522
9866
  const index = +key;
9523
9867
  parent = parent[index];
@@ -9527,12 +9871,12 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9527
9871
  const row = +key;
9528
9872
  parent = getNthKey(parent, row);
9529
9873
  } else if (isMap(parent)) {
9530
- const isEnd = i === path5.length - 2;
9874
+ const isEnd = i === path6.length - 2;
9531
9875
  if (isEnd) {
9532
9876
  break;
9533
9877
  }
9534
9878
  const row = +key;
9535
- const type = +path5[++i] === 0 ? "key" : "value";
9879
+ const type = +path6[++i] === 0 ? "key" : "value";
9536
9880
  const keyOfRow = getNthKey(parent, row);
9537
9881
  switch (type) {
9538
9882
  case "key":
@@ -9544,7 +9888,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9544
9888
  }
9545
9889
  }
9546
9890
  }
9547
- const lastKey = path5[path5.length - 1];
9891
+ const lastKey = path6[path6.length - 1];
9548
9892
  if (isArray(parent)) {
9549
9893
  parent[+lastKey] = mapper(parent[+lastKey]);
9550
9894
  } else if (isPlainObject2(parent)) {
@@ -9559,7 +9903,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
9559
9903
  }
9560
9904
  }
9561
9905
  if (isMap(parent)) {
9562
- const row = +path5[path5.length - 2];
9906
+ const row = +path6[path6.length - 2];
9563
9907
  const keyToRow = getNthKey(parent, row);
9564
9908
  const type = +lastKey === 0 ? "key" : "value";
9565
9909
  switch (type) {
@@ -9605,15 +9949,15 @@ function traverse(tree, walker2, origin = []) {
9605
9949
  }
9606
9950
  __name(traverse, "traverse");
9607
9951
  function applyValueAnnotations(plain, annotations, superJson) {
9608
- traverse(annotations, (type, path5) => {
9609
- plain = setDeep(plain, path5, (v) => untransformValue(v, type, superJson));
9952
+ traverse(annotations, (type, path6) => {
9953
+ plain = setDeep(plain, path6, (v) => untransformValue(v, type, superJson));
9610
9954
  });
9611
9955
  return plain;
9612
9956
  }
9613
9957
  __name(applyValueAnnotations, "applyValueAnnotations");
9614
9958
  function applyReferentialEqualityAnnotations(plain, annotations) {
9615
- function apply(identicalPaths, path5) {
9616
- const object = getDeep(plain, parsePath(path5));
9959
+ function apply(identicalPaths, path6) {
9960
+ const object = getDeep(plain, parsePath(path6));
9617
9961
  identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
9618
9962
  plain = setDeep(plain, identicalObjectPath, () => object);
9619
9963
  });
@@ -9634,13 +9978,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
9634
9978
  }
9635
9979
  __name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
9636
9980
  var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
9637
- function addIdentity(object, path5, identities) {
9981
+ function addIdentity(object, path6, identities) {
9638
9982
  const existingSet = identities.get(object);
9639
9983
  if (existingSet) {
9640
- existingSet.push(path5);
9984
+ existingSet.push(path6);
9641
9985
  } else {
9642
9986
  identities.set(object, [
9643
- path5
9987
+ path6
9644
9988
  ]);
9645
9989
  }
9646
9990
  }
@@ -9653,7 +9997,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
9653
9997
  return;
9654
9998
  }
9655
9999
  if (!dedupe) {
9656
- paths = paths.map((path5) => path5.map(String)).sort((a, b) => a.length - b.length);
10000
+ paths = paths.map((path6) => path6.map(String)).sort((a, b) => a.length - b.length);
9657
10001
  }
9658
10002
  const [representativePath, ...identicalPaths] = paths;
9659
10003
  if (representativePath.length === 0) {
@@ -9678,10 +10022,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
9678
10022
  }
9679
10023
  }
9680
10024
  __name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
9681
- var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path5 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
10025
+ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path6 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
9682
10026
  const primitive = isPrimitive(object);
9683
10027
  if (!primitive) {
9684
- addIdentity(object, path5, identities);
10028
+ addIdentity(object, path6, identities);
9685
10029
  const seen = seenObjects.get(object);
9686
10030
  if (seen) {
9687
10031
  return dedupe ? {
@@ -9718,7 +10062,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
9718
10062
  throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
9719
10063
  }
9720
10064
  const recursiveResult = walker(value, identities, superJson, dedupe, [
9721
- ...path5,
10065
+ ...path6,
9722
10066
  index
9723
10067
  ], [
9724
10068
  ...objectsInThisPath,
@@ -9902,8 +10246,8 @@ SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJS
9902
10246
  SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
9903
10247
  var serialize = SuperJSON.serialize;
9904
10248
  var deserialize = SuperJSON.deserialize;
9905
- var stringify = SuperJSON.stringify;
9906
- var parse3 = SuperJSON.parse;
10249
+ var stringify2 = SuperJSON.stringify;
10250
+ var parse4 = SuperJSON.parse;
9907
10251
  var registerClass = SuperJSON.registerClass;
9908
10252
  var registerCustom = SuperJSON.registerCustom;
9909
10253
  var registerSymbol = SuperJSON.registerSymbol;
@@ -10116,7 +10460,7 @@ var isNumber2 = /* @__PURE__ */ __name((value) => {
10116
10460
  }, "isNumber");
10117
10461
 
10118
10462
  // ../json/src/utils/stringify.ts
10119
- var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10463
+ var stringify3 = /* @__PURE__ */ __name((value, spacing = 2) => {
10120
10464
  const space = isNumber2(spacing) ? " ".repeat(spacing) : spacing;
10121
10465
  switch (value) {
10122
10466
  case null: {
@@ -10133,7 +10477,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10133
10477
  }
10134
10478
  }
10135
10479
  if (Array.isArray(value)) {
10136
- return `[${space}${value.map((v) => stringify2(v, space)).join(`,${space}`)}${space}]`;
10480
+ return `[${space}${value.map((v) => stringify3(v, space)).join(`,${space}`)}${space}]`;
10137
10481
  }
10138
10482
  if (value instanceof Uint8Array) {
10139
10483
  return value.toString();
@@ -10147,7 +10491,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
10147
10491
  }
10148
10492
  case "object": {
10149
10493
  const keys = Object.keys(value);
10150
- return `{${space}${keys.map((k) => `${k}: ${space}${stringify2(value[k], space)}`).join(`,${space}`)}${space}}`;
10494
+ return `{${space}${keys.map((k) => `${k}: ${space}${stringify3(value[k], space)}`).join(`,${space}`)}${space}}`;
10151
10495
  }
10152
10496
  default:
10153
10497
  return "null";
@@ -10203,7 +10547,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
10203
10547
  if (customTransformer) {
10204
10548
  result = customTransformer.serialize(result);
10205
10549
  }
10206
- return stringify2(result?.json ? result?.json : result, options?.spaces);
10550
+ return stringify3(result?.json ? result?.json : result, options?.spaces);
10207
10551
  }
10208
10552
  /**
10209
10553
  * Stringify the given value with superjson
@@ -10234,7 +10578,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
10234
10578
  allowTrailingComma: true,
10235
10579
  ...options
10236
10580
  };
10237
- const result = parse2(strData, errors, opts);
10581
+ const result = parse3(strData, errors, opts);
10238
10582
  if (errors.length > 0 && errors[0]) {
10239
10583
  throw new Error(formatParseError(strData, errors[0]));
10240
10584
  }
@@ -10298,7 +10642,7 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
10298
10642
  }, "writeFile");
10299
10643
 
10300
10644
  // src/utils/write-file-safely.ts
10301
- var import_node_path3 = __toESM(require("node:path"), 1);
10645
+ var import_node_path4 = __toESM(require("node:path"), 1);
10302
10646
 
10303
10647
  // src/utils/format-file.ts
10304
10648
  init_cjs_shims();
@@ -10342,13 +10686,14 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
10342
10686
  }, "writeFileSafely");
10343
10687
  var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
10344
10688
  const rows = Array.from(indexExports).map((filePath) => {
10345
- let relativePath2 = import_node_path3.default.relative(import_node_path3.default.dirname(indexPath), filePath);
10689
+ let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
10346
10690
  if (relativePath2.endsWith(".ts")) {
10347
10691
  relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
10348
10692
  }
10349
10693
  const normalized = correctPath(relativePath2);
10350
- return `export * from './${normalized}'`;
10694
+ return `export * from './${normalized}';`;
10351
10695
  });
10696
+ rows.push("export * from './models';");
10352
10697
  await writeFileSafely(indexPath, rows.join("\n"), false);
10353
10698
  }, "writeIndexFile");
10354
10699
 
@@ -10519,45 +10864,7 @@ init_cjs_shims();
10519
10864
 
10520
10865
  // src/zod/transformer.ts
10521
10866
  init_cjs_shims();
10522
- var import_node_path4 = __toESM(require("node:path"), 1);
10523
-
10524
- // src/zod/model-helpers.ts
10525
- init_cjs_shims();
10526
- function checkModelHasModelRelation(model) {
10527
- const { fields: modelFields } = model;
10528
- for (const modelField of modelFields) {
10529
- const isRelationField = checkIsModelRelationField(modelField);
10530
- if (isRelationField) {
10531
- return true;
10532
- }
10533
- }
10534
- return false;
10535
- }
10536
- __name(checkModelHasModelRelation, "checkModelHasModelRelation");
10537
- function checkModelHasManyModelRelation(model) {
10538
- const { fields: modelFields } = model;
10539
- for (const modelField of modelFields) {
10540
- const isManyRelationField = checkIsManyModelRelationField(modelField);
10541
- if (isManyRelationField) {
10542
- return true;
10543
- }
10544
- }
10545
- return false;
10546
- }
10547
- __name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
10548
- function checkIsModelRelationField(modelField) {
10549
- const { kind, relationName } = modelField;
10550
- return kind === "object" && !!relationName;
10551
- }
10552
- __name(checkIsModelRelationField, "checkIsModelRelationField");
10553
- function checkIsManyModelRelationField(modelField) {
10554
- return checkIsModelRelationField(modelField) && modelField.isList;
10555
- }
10556
- __name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
10557
- function findModelByName(models, modelName) {
10558
- return models.find(({ name }) => name === modelName);
10559
- }
10560
- __name(findModelByName, "findModelByName");
10867
+ var import_node_path5 = __toESM(require("node:path"), 1);
10561
10868
 
10562
10869
  // src/zod/mongodb-helpers.ts
10563
10870
  init_cjs_shims();
@@ -10667,13 +10974,13 @@ var Transformer = class _Transformer {
10667
10974
  this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
10668
10975
  }
10669
10976
  static async generateIndex() {
10670
- const indexPath = import_node_path4.default.join(_Transformer.outputPath, "schemas/index.ts");
10977
+ const indexPath = import_node_path5.default.join(_Transformer.outputPath, "schemas/index.ts");
10671
10978
  await writeIndexFile(indexPath);
10672
10979
  }
10673
10980
  async generateEnumSchemas() {
10674
10981
  for (const enumType2 of this.enumTypes) {
10675
10982
  const { name, values } = enumType2;
10676
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
10983
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
10677
10984
  ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
10678
10985
  }
10679
10986
  }
@@ -10687,7 +10994,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10687
10994
  const zodObjectSchemaFields = this.generateObjectSchemaFields();
10688
10995
  const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
10689
10996
  const objectSchemaName = this.resolveObjectSchemaName();
10690
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
10997
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
10691
10998
  }
10692
10999
  generateObjectSchemaFields() {
10693
11000
  const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
@@ -10822,9 +11129,9 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10822
11129
  generateImportPrismaStatement() {
10823
11130
  let prismaClientImportPath;
10824
11131
  if (_Transformer.isCustomPrismaClientOutputPath) {
10825
- const fromPath = import_node_path4.default.join(_Transformer.outputPath, "schemas", "objects");
11132
+ const fromPath = import_node_path5.default.join(_Transformer.outputPath, "schemas", "objects");
10826
11133
  const toPath = _Transformer.prismaClientOutputPath;
10827
- const relativePathFromOutputToPrismaClient = import_node_path4.default.relative(fromPath, toPath).split(import_node_path4.default.sep).join(import_node_path4.default.posix.sep);
11134
+ const relativePathFromOutputToPrismaClient = import_node_path5.default.relative(fromPath, toPath).split(import_node_path5.default.sep).join(import_node_path5.default.posix.sep);
10828
11135
  prismaClientImportPath = relativePathFromOutputToPrismaClient;
10829
11136
  } else {
10830
11137
  prismaClientImportPath = _Transformer.prismaClientOutputPath;
@@ -10954,7 +11261,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10954
11261
  includeImport,
10955
11262
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
10956
11263
  ];
10957
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11264
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
10958
11265
  }
10959
11266
  if (findFirst) {
10960
11267
  const imports = [
@@ -10965,7 +11272,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10965
11272
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
10966
11273
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
10967
11274
  ];
10968
- await writeFileSafely(import_node_path4.default.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() })`)}`);
11275
+ await writeFileSafely(import_node_path5.default.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() })`)}`);
10969
11276
  }
10970
11277
  if (findMany) {
10971
11278
  const imports = [
@@ -10976,7 +11283,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10976
11283
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
10977
11284
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
10978
11285
  ];
10979
- await writeFileSafely(import_node_path4.default.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() })`)}`);
11286
+ await writeFileSafely(import_node_path5.default.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() })`)}`);
10980
11287
  }
10981
11288
  if (createOne) {
10982
11289
  const imports = [
@@ -10985,19 +11292,19 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
10985
11292
  `import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
10986
11293
  `import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
10987
11294
  ];
10988
- await writeFileSafely(import_node_path4.default.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]) })`)}`);
11295
+ await writeFileSafely(import_node_path5.default.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]) })`)}`);
10989
11296
  }
10990
11297
  if (createMany) {
10991
11298
  const imports = [
10992
11299
  `import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
10993
11300
  ];
10994
- await writeFileSafely(import_node_path4.default.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()"} })`)}`);
11301
+ await writeFileSafely(import_node_path5.default.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()"} })`)}`);
10995
11302
  }
10996
11303
  if (createManyAndReturn) {
10997
11304
  const imports = [
10998
11305
  `import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`
10999
11306
  ];
11000
- await writeFileSafely(import_node_path4.default.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()"} })`)}`);
11307
+ await writeFileSafely(import_node_path5.default.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()"} })`)}`);
11001
11308
  }
11002
11309
  if (deleteOne) {
11003
11310
  const imports = [
@@ -11005,13 +11312,13 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11005
11312
  includeImport,
11006
11313
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
11007
11314
  ];
11008
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11315
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
11009
11316
  }
11010
11317
  if (deleteMany) {
11011
11318
  const imports = [
11012
11319
  `import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
11013
11320
  ];
11014
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11321
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11015
11322
  }
11016
11323
  if (updateOne) {
11017
11324
  const imports = [
@@ -11021,20 +11328,20 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11021
11328
  `import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
11022
11329
  `import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
11023
11330
  ];
11024
- await writeFileSafely(import_node_path4.default.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 })`)}`);
11331
+ await writeFileSafely(import_node_path5.default.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 })`)}`);
11025
11332
  }
11026
11333
  if (updateMany) {
11027
11334
  const imports = [
11028
11335
  `import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
11029
11336
  `import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
11030
11337
  ];
11031
- await writeFileSafely(import_node_path4.default.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11338
+ await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
11032
11339
  }
11033
11340
  if (updateManyAndReturn) {
11034
11341
  const imports = [
11035
11342
  `import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`
11036
11343
  ];
11037
- await writeFileSafely(import_node_path4.default.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()"} })`)}`);
11344
+ await writeFileSafely(import_node_path5.default.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()"} })`)}`);
11038
11345
  }
11039
11346
  if (upsertOne) {
11040
11347
  const imports = [
@@ -11046,7 +11353,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11046
11353
  `import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
11047
11354
  `import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
11048
11355
  ];
11049
- await writeFileSafely(import_node_path4.default.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 ]) })`)}`);
11356
+ await writeFileSafely(import_node_path5.default.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 ]) })`)}`);
11050
11357
  }
11051
11358
  if (aggregate) {
11052
11359
  const imports = [
@@ -11077,7 +11384,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11077
11384
  aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
11078
11385
  }
11079
11386
  }
11080
- await writeFileSafely(import_node_path4.default.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(", ")} })`)}`);
11387
+ await writeFileSafely(import_node_path5.default.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(", ")} })`)}`);
11081
11388
  }
11082
11389
  if (groupBy) {
11083
11390
  const imports = [
@@ -11086,7 +11393,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
11086
11393
  `import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
11087
11394
  `import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
11088
11395
  ];
11089
- await writeFileSafely(import_node_path4.default.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) })`)}`);
11396
+ await writeFileSafely(import_node_path5.default.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) })`)}`);
11090
11397
  }
11091
11398
  }
11092
11399
  }
@@ -11567,6 +11874,7 @@ ${JSON.stringify(config)}`);
11567
11874
  if (prismaClientProvider?.isCustomOutput) {
11568
11875
  Transformer.setPrismaClientOutputPath(prismaClientProvider.output?.value);
11569
11876
  }
11877
+ await constructZodModels(models, joinPaths(zodOutputPath, "models"), config, options);
11570
11878
  resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
11571
11879
  await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
11572
11880
  const dataSource = options.datasources?.[0];
@@ -11643,12 +11951,12 @@ ${JSON.stringify(config)}`);
11643
11951
  }
11644
11952
  resolveModelsComments(models, hiddenModels);
11645
11953
  consoleLog("Generating tRPC export file");
11646
- const trpcExports = project.createSourceFile(import_node_path5.default.resolve(outputDir, "trpc.ts"), void 0, {
11954
+ const trpcExports = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
11647
11955
  overwrite: true
11648
11956
  });
11649
11957
  await generateTRPCExports(trpcExports, config, options, outputDir);
11650
11958
  consoleLog("Generating tRPC app router");
11651
- const appRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `index.ts`), void 0, {
11959
+ const appRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `index.ts`), void 0, {
11652
11960
  overwrite: true
11653
11961
  });
11654
11962
  consoleLog("Generating tRPC router imports");
@@ -11677,7 +11985,7 @@ ${JSON.stringify(config)}`);
11677
11985
  const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
11678
11986
  consoleLog(`Generating tRPC router for model ${model}`);
11679
11987
  generateRouterImport(appRouter, plural, model);
11680
- const modelRouter = project.createSourceFile(import_node_path5.default.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
11988
+ const modelRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
11681
11989
  overwrite: true
11682
11990
  });
11683
11991
  generateCreateRouterImport({