@stryke/prisma-trpc-generator 0.3.1 → 0.3.2

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
@@ -672,8 +672,159 @@ init_cjs_shims();
672
672
 
673
673
  // src/prisma-generator.ts
674
674
  init_cjs_shims();
675
- var import_node_fs6 = require("node:fs");
676
- var import_node_path7 = __toESM(require("node:path"), 1);
675
+
676
+ // ../fs/src/helpers.ts
677
+ init_cjs_shims();
678
+
679
+ // ../path/src/exists.ts
680
+ init_cjs_shims();
681
+ var import_promises = require("node:fs/promises");
682
+ var exists = /* @__PURE__ */ __name(async (filePath) => {
683
+ return (0, import_promises.access)(filePath, import_promises.constants.F_OK).then(() => true).catch(() => false);
684
+ }, "exists");
685
+
686
+ // ../fs/src/helpers.ts
687
+ var import_promises2 = require("node:fs/promises");
688
+ async function createDirectory(path6) {
689
+ if (await exists(path6)) {
690
+ return;
691
+ }
692
+ return (0, import_promises2.mkdir)(path6, {
693
+ recursive: true
694
+ });
695
+ }
696
+ __name(createDirectory, "createDirectory");
697
+
698
+ // ../path/src/join-paths.ts
699
+ init_cjs_shims();
700
+ var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
701
+ function normalizeWindowsPath(input = "") {
702
+ if (!input) {
703
+ return input;
704
+ }
705
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
706
+ }
707
+ __name(normalizeWindowsPath, "normalizeWindowsPath");
708
+ var _UNC_REGEX = /^[/\\]{2}/;
709
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
710
+ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
711
+ var isAbsolute = /* @__PURE__ */ __name(function(p) {
712
+ return _IS_ABSOLUTE_RE.test(p);
713
+ }, "isAbsolute");
714
+ var correctPaths = /* @__PURE__ */ __name(function(path6) {
715
+ if (!path6 || path6.length === 0) {
716
+ return ".";
717
+ }
718
+ path6 = normalizeWindowsPath(path6);
719
+ const isUNCPath = path6.match(_UNC_REGEX);
720
+ const isPathAbsolute = isAbsolute(path6);
721
+ const trailingSeparator = path6[path6.length - 1] === "/";
722
+ path6 = normalizeString(path6, !isPathAbsolute);
723
+ if (path6.length === 0) {
724
+ if (isPathAbsolute) {
725
+ return "/";
726
+ }
727
+ return trailingSeparator ? "./" : ".";
728
+ }
729
+ if (trailingSeparator) {
730
+ path6 += "/";
731
+ }
732
+ if (_DRIVE_LETTER_RE.test(path6)) {
733
+ path6 += "/";
734
+ }
735
+ if (isUNCPath) {
736
+ if (!isPathAbsolute) {
737
+ return `//./${path6}`;
738
+ }
739
+ return `//${path6}`;
740
+ }
741
+ return isPathAbsolute && !isAbsolute(path6) ? `/${path6}` : path6;
742
+ }, "correctPaths");
743
+ var joinPaths = /* @__PURE__ */ __name(function(...segments) {
744
+ let path6 = "";
745
+ for (const seg of segments) {
746
+ if (!seg) {
747
+ continue;
748
+ }
749
+ if (path6.length > 0) {
750
+ const pathTrailing = path6[path6.length - 1] === "/";
751
+ const segLeading = seg[0] === "/";
752
+ const both = pathTrailing && segLeading;
753
+ if (both) {
754
+ path6 += seg.slice(1);
755
+ } else {
756
+ path6 += pathTrailing || segLeading ? seg : `/${seg}`;
757
+ }
758
+ } else {
759
+ path6 += seg;
760
+ }
761
+ }
762
+ return correctPaths(path6);
763
+ }, "joinPaths");
764
+ function normalizeString(path6, allowAboveRoot) {
765
+ let res = "";
766
+ let lastSegmentLength = 0;
767
+ let lastSlash = -1;
768
+ let dots = 0;
769
+ let char = null;
770
+ for (let index = 0; index <= path6.length; ++index) {
771
+ if (index < path6.length) {
772
+ char = path6[index];
773
+ } else if (char === "/") {
774
+ break;
775
+ } else {
776
+ char = "/";
777
+ }
778
+ if (char === "/") {
779
+ if (lastSlash === index - 1 || dots === 1) {
780
+ } else if (dots === 2) {
781
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
782
+ if (res.length > 2) {
783
+ const lastSlashIndex = res.lastIndexOf("/");
784
+ if (lastSlashIndex === -1) {
785
+ res = "";
786
+ lastSegmentLength = 0;
787
+ } else {
788
+ res = res.slice(0, lastSlashIndex);
789
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
790
+ }
791
+ lastSlash = index;
792
+ dots = 0;
793
+ continue;
794
+ } else if (res.length > 0) {
795
+ res = "";
796
+ lastSegmentLength = 0;
797
+ lastSlash = index;
798
+ dots = 0;
799
+ continue;
800
+ }
801
+ }
802
+ if (allowAboveRoot) {
803
+ res += res.length > 0 ? "/.." : "..";
804
+ lastSegmentLength = 2;
805
+ }
806
+ } else {
807
+ if (res.length > 0) {
808
+ res += `/${path6.slice(lastSlash + 1, index)}`;
809
+ } else {
810
+ res = path6.slice(lastSlash + 1, index);
811
+ }
812
+ lastSegmentLength = index - lastSlash - 1;
813
+ }
814
+ lastSlash = index;
815
+ dots = 0;
816
+ } else if (char === "." && dots !== -1) {
817
+ ++dots;
818
+ } else {
819
+ dots = -1;
820
+ }
821
+ }
822
+ return res;
823
+ }
824
+ __name(normalizeString, "normalizeString");
825
+
826
+ // src/prisma-generator.ts
827
+ var import_node_path6 = __toESM(require("node:path"), 1);
677
828
  var import_pluralize = __toESM(require_pluralize(), 1);
678
829
 
679
830
  // src/config.ts
@@ -1041,8 +1192,8 @@ function getErrorMap() {
1041
1192
  }
1042
1193
  __name(getErrorMap, "getErrorMap");
1043
1194
  var makeIssue = /* @__PURE__ */ __name((params) => {
1044
- const { data, path: path7, errorMaps, issueData } = params;
1045
- const fullPath = [...path7, ...issueData.path || []];
1195
+ const { data, path: path6, errorMaps, issueData } = params;
1196
+ const fullPath = [...path6, ...issueData.path || []];
1046
1197
  const fullIssue = {
1047
1198
  ...issueData,
1048
1199
  path: fullPath
@@ -1176,11 +1327,11 @@ var ParseInputLazyPath = class {
1176
1327
  static {
1177
1328
  __name(this, "ParseInputLazyPath");
1178
1329
  }
1179
- constructor(parent, value, path7, key) {
1330
+ constructor(parent, value, path6, key) {
1180
1331
  this._cachedPath = [];
1181
1332
  this.parent = parent;
1182
1333
  this.data = value;
1183
- this._path = path7;
1334
+ this._path = path6;
1184
1335
  this._key = key;
1185
1336
  }
1186
1337
  get path() {
@@ -4952,134 +5103,6 @@ init_cjs_shims();
4952
5103
  // ../env/src/get-env-paths.ts
4953
5104
  init_cjs_shims();
4954
5105
 
4955
- // ../path/src/join-paths.ts
4956
- init_cjs_shims();
4957
- var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
4958
- function normalizeWindowsPath(input = "") {
4959
- if (!input) {
4960
- return input;
4961
- }
4962
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
4963
- }
4964
- __name(normalizeWindowsPath, "normalizeWindowsPath");
4965
- var _UNC_REGEX = /^[/\\]{2}/;
4966
- var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
4967
- var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
4968
- var isAbsolute = /* @__PURE__ */ __name(function(p) {
4969
- return _IS_ABSOLUTE_RE.test(p);
4970
- }, "isAbsolute");
4971
- var correctPaths = /* @__PURE__ */ __name(function(path7) {
4972
- if (!path7 || path7.length === 0) {
4973
- return ".";
4974
- }
4975
- path7 = normalizeWindowsPath(path7);
4976
- const isUNCPath = path7.match(_UNC_REGEX);
4977
- const isPathAbsolute = isAbsolute(path7);
4978
- const trailingSeparator = path7[path7.length - 1] === "/";
4979
- path7 = normalizeString(path7, !isPathAbsolute);
4980
- if (path7.length === 0) {
4981
- if (isPathAbsolute) {
4982
- return "/";
4983
- }
4984
- return trailingSeparator ? "./" : ".";
4985
- }
4986
- if (trailingSeparator) {
4987
- path7 += "/";
4988
- }
4989
- if (_DRIVE_LETTER_RE.test(path7)) {
4990
- path7 += "/";
4991
- }
4992
- if (isUNCPath) {
4993
- if (!isPathAbsolute) {
4994
- return `//./${path7}`;
4995
- }
4996
- return `//${path7}`;
4997
- }
4998
- return isPathAbsolute && !isAbsolute(path7) ? `/${path7}` : path7;
4999
- }, "correctPaths");
5000
- var joinPaths = /* @__PURE__ */ __name(function(...segments) {
5001
- let path7 = "";
5002
- for (const seg of segments) {
5003
- if (!seg) {
5004
- continue;
5005
- }
5006
- if (path7.length > 0) {
5007
- const pathTrailing = path7[path7.length - 1] === "/";
5008
- const segLeading = seg[0] === "/";
5009
- const both = pathTrailing && segLeading;
5010
- if (both) {
5011
- path7 += seg.slice(1);
5012
- } else {
5013
- path7 += pathTrailing || segLeading ? seg : `/${seg}`;
5014
- }
5015
- } else {
5016
- path7 += seg;
5017
- }
5018
- }
5019
- return correctPaths(path7);
5020
- }, "joinPaths");
5021
- function normalizeString(path7, allowAboveRoot) {
5022
- let res = "";
5023
- let lastSegmentLength = 0;
5024
- let lastSlash = -1;
5025
- let dots = 0;
5026
- let char = null;
5027
- for (let index = 0; index <= path7.length; ++index) {
5028
- if (index < path7.length) {
5029
- char = path7[index];
5030
- } else if (char === "/") {
5031
- break;
5032
- } else {
5033
- char = "/";
5034
- }
5035
- if (char === "/") {
5036
- if (lastSlash === index - 1 || dots === 1) {
5037
- } else if (dots === 2) {
5038
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
5039
- if (res.length > 2) {
5040
- const lastSlashIndex = res.lastIndexOf("/");
5041
- if (lastSlashIndex === -1) {
5042
- res = "";
5043
- lastSegmentLength = 0;
5044
- } else {
5045
- res = res.slice(0, lastSlashIndex);
5046
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
5047
- }
5048
- lastSlash = index;
5049
- dots = 0;
5050
- continue;
5051
- } else if (res.length > 0) {
5052
- res = "";
5053
- lastSegmentLength = 0;
5054
- lastSlash = index;
5055
- dots = 0;
5056
- continue;
5057
- }
5058
- }
5059
- if (allowAboveRoot) {
5060
- res += res.length > 0 ? "/.." : "..";
5061
- lastSegmentLength = 2;
5062
- }
5063
- } else {
5064
- if (res.length > 0) {
5065
- res += `/${path7.slice(lastSlash + 1, index)}`;
5066
- } else {
5067
- res = path7.slice(lastSlash + 1, index);
5068
- }
5069
- lastSegmentLength = index - lastSlash - 1;
5070
- }
5071
- lastSlash = index;
5072
- dots = 0;
5073
- } else if (char === "." && dots !== -1) {
5074
- ++dots;
5075
- } else {
5076
- dots = -1;
5077
- }
5078
- }
5079
- return res;
5080
- }
5081
- __name(normalizeString, "normalizeString");
5082
-
5083
5106
  // ../string-format/src/title-case.ts
5084
5107
  init_cjs_shims();
5085
5108
 
@@ -5293,34 +5316,34 @@ __name2(normalizeWindowsPath2, "normalizeWindowsPath");
5293
5316
  var _UNC_REGEX2 = /^[/\\]{2}/;
5294
5317
  var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
5295
5318
  var _DRIVE_LETTER_RE2 = /^[A-Za-z]:$/;
5296
- var correctPaths2 = /* @__PURE__ */ __name2(function(path7) {
5297
- if (!path7 || path7.length === 0) {
5319
+ var correctPaths2 = /* @__PURE__ */ __name2(function(path6) {
5320
+ if (!path6 || path6.length === 0) {
5298
5321
  return ".";
5299
5322
  }
5300
- path7 = normalizeWindowsPath2(path7);
5301
- const isUNCPath = path7.match(_UNC_REGEX2);
5302
- const isPathAbsolute = isAbsolute2(path7);
5303
- const trailingSeparator = path7[path7.length - 1] === "/";
5304
- path7 = normalizeString2(path7, !isPathAbsolute);
5305
- if (path7.length === 0) {
5323
+ path6 = normalizeWindowsPath2(path6);
5324
+ const isUNCPath = path6.match(_UNC_REGEX2);
5325
+ const isPathAbsolute = isAbsolute2(path6);
5326
+ const trailingSeparator = path6[path6.length - 1] === "/";
5327
+ path6 = normalizeString2(path6, !isPathAbsolute);
5328
+ if (path6.length === 0) {
5306
5329
  if (isPathAbsolute) {
5307
5330
  return "/";
5308
5331
  }
5309
5332
  return trailingSeparator ? "./" : ".";
5310
5333
  }
5311
5334
  if (trailingSeparator) {
5312
- path7 += "/";
5335
+ path6 += "/";
5313
5336
  }
5314
- if (_DRIVE_LETTER_RE2.test(path7)) {
5315
- path7 += "/";
5337
+ if (_DRIVE_LETTER_RE2.test(path6)) {
5338
+ path6 += "/";
5316
5339
  }
5317
5340
  if (isUNCPath) {
5318
5341
  if (!isPathAbsolute) {
5319
- return `//./${path7}`;
5342
+ return `//./${path6}`;
5320
5343
  }
5321
- return `//${path7}`;
5344
+ return `//${path6}`;
5322
5345
  }
5323
- return isPathAbsolute && !isAbsolute2(path7) ? `/${path7}` : path7;
5346
+ return isPathAbsolute && !isAbsolute2(path6) ? `/${path6}` : path6;
5324
5347
  }, "correctPaths");
5325
5348
  function cwd() {
5326
5349
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -5330,15 +5353,15 @@ function cwd() {
5330
5353
  }
5331
5354
  __name(cwd, "cwd");
5332
5355
  __name2(cwd, "cwd");
5333
- function normalizeString2(path7, allowAboveRoot) {
5356
+ function normalizeString2(path6, allowAboveRoot) {
5334
5357
  let res = "";
5335
5358
  let lastSegmentLength = 0;
5336
5359
  let lastSlash = -1;
5337
5360
  let dots = 0;
5338
5361
  let char = null;
5339
- for (let index = 0; index <= path7.length; ++index) {
5340
- if (index < path7.length) {
5341
- char = path7[index];
5362
+ for (let index = 0; index <= path6.length; ++index) {
5363
+ if (index < path6.length) {
5364
+ char = path6[index];
5342
5365
  } else if (char === "/") {
5343
5366
  break;
5344
5367
  } else {
@@ -5374,9 +5397,9 @@ function normalizeString2(path7, allowAboveRoot) {
5374
5397
  }
5375
5398
  } else {
5376
5399
  if (res.length > 0) {
5377
- res += `/${path7.slice(lastSlash + 1, index)}`;
5400
+ res += `/${path6.slice(lastSlash + 1, index)}`;
5378
5401
  } else {
5379
- res = path7.slice(lastSlash + 1, index);
5402
+ res = path6.slice(lastSlash + 1, index);
5380
5403
  }
5381
5404
  lastSegmentLength = index - lastSlash - 1;
5382
5405
  }
@@ -5475,20 +5498,20 @@ init_cjs_shims();
5475
5498
  // ../path/src/is-file.ts
5476
5499
  init_cjs_shims();
5477
5500
  var import_node_fs2 = require("node:fs");
5478
- function isFile(path7, additionalPath) {
5479
- return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path7) : path7, {
5501
+ function isFile(path6, additionalPath) {
5502
+ return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
5480
5503
  throwIfNoEntry: false
5481
5504
  })?.isFile());
5482
5505
  }
5483
5506
  __name(isFile, "isFile");
5484
- function isDirectory(path7, additionalPath) {
5485
- return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path7) : path7, {
5507
+ function isDirectory(path6, additionalPath) {
5508
+ return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
5486
5509
  throwIfNoEntry: false
5487
5510
  })?.isDirectory());
5488
5511
  }
5489
5512
  __name(isDirectory, "isDirectory");
5490
- function isAbsolutePath(path7) {
5491
- return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path7);
5513
+ function isAbsolutePath(path6) {
5514
+ return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path6);
5492
5515
  }
5493
5516
  __name(isAbsolutePath, "isAbsolutePath");
5494
5517
 
@@ -5501,15 +5524,15 @@ function normalizeWindowsPath3(input = "") {
5501
5524
  return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE3, (r) => r.toUpperCase());
5502
5525
  }
5503
5526
  __name(normalizeWindowsPath3, "normalizeWindowsPath");
5504
- function normalizeString3(path7, allowAboveRoot) {
5527
+ function normalizeString3(path6, allowAboveRoot) {
5505
5528
  let res = "";
5506
5529
  let lastSegmentLength = 0;
5507
5530
  let lastSlash = -1;
5508
5531
  let dots = 0;
5509
5532
  let char = null;
5510
- for (let index = 0; index <= path7.length; ++index) {
5511
- if (index < path7.length) {
5512
- char = path7[index];
5533
+ for (let index = 0; index <= path6.length; ++index) {
5534
+ if (index < path6.length) {
5535
+ char = path6[index];
5513
5536
  } else if (char === "/") {
5514
5537
  break;
5515
5538
  } else {
@@ -5545,9 +5568,9 @@ function normalizeString3(path7, allowAboveRoot) {
5545
5568
  }
5546
5569
  } else {
5547
5570
  if (res.length > 0) {
5548
- res += `/${path7.slice(lastSlash + 1, index)}`;
5571
+ res += `/${path6.slice(lastSlash + 1, index)}`;
5549
5572
  } else {
5550
- res = path7.slice(lastSlash + 1, index);
5573
+ res = path6.slice(lastSlash + 1, index);
5551
5574
  }
5552
5575
  lastSegmentLength = index - lastSlash - 1;
5553
5576
  }
@@ -5564,17 +5587,17 @@ function normalizeString3(path7, allowAboveRoot) {
5564
5587
  __name(normalizeString3, "normalizeString");
5565
5588
 
5566
5589
  // ../path/src/file-path-fns.ts
5567
- function resolvePath(path7, cwd2 = getWorkspaceRoot()) {
5568
- const paths = normalizeWindowsPath3(path7).split("/");
5590
+ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
5591
+ const paths = normalizeWindowsPath3(path6).split("/");
5569
5592
  let resolvedPath = "";
5570
5593
  let resolvedAbsolute = false;
5571
5594
  for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
5572
- const path8 = index >= 0 ? paths[index] : cwd2;
5573
- if (!path8 || path8.length === 0) {
5595
+ const path7 = index >= 0 ? paths[index] : cwd2;
5596
+ if (!path7 || path7.length === 0) {
5574
5597
  continue;
5575
5598
  }
5576
- resolvedPath = joinPaths(path8, resolvedPath);
5577
- resolvedAbsolute = isAbsolutePath(path8);
5599
+ resolvedPath = joinPaths(path7, resolvedPath);
5600
+ resolvedAbsolute = isAbsolutePath(path7);
5578
5601
  }
5579
5602
  resolvedPath = normalizeString3(resolvedPath, !resolvedAbsolute);
5580
5603
  if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
@@ -5584,13 +5607,13 @@ function resolvePath(path7, cwd2 = getWorkspaceRoot()) {
5584
5607
  }
5585
5608
  __name(resolvePath, "resolvePath");
5586
5609
  function resolvePaths(...paths) {
5587
- return resolvePath(joinPaths(...paths.map((path7) => normalizeWindowsPath3(path7))));
5610
+ return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath3(path6))));
5588
5611
  }
5589
5612
  __name(resolvePaths, "resolvePaths");
5590
5613
 
5591
5614
  // ../path/src/get-parent-path.ts
5592
- var resolveParentPath = /* @__PURE__ */ __name((path7) => {
5593
- return resolvePaths(path7, "..");
5615
+ var resolveParentPath = /* @__PURE__ */ __name((path6) => {
5616
+ return resolvePaths(path6, "..");
5594
5617
  }, "resolveParentPath");
5595
5618
  var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
5596
5619
  const ignoreCase = options?.ignoreCase ?? true;
@@ -6071,10 +6094,21 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
6071
6094
  return shieldText;
6072
6095
  }, "constructShield");
6073
6096
 
6074
- // src/prisma-shield-generator.ts
6097
+ // src/project.ts
6075
6098
  init_cjs_shims();
6076
- var import_node_fs5 = require("node:fs");
6077
- var import_node_path6 = __toESM(require("node:path"), 1);
6099
+ var import_ts_morph = require("ts-morph");
6100
+ var compilerOptions = {
6101
+ target: import_ts_morph.ScriptTarget.ESNext,
6102
+ module: import_ts_morph.ModuleKind.ESNext,
6103
+ emitDecoratorMetadata: true,
6104
+ experimentalDecorators: true,
6105
+ esModuleInterop: true
6106
+ };
6107
+ var project = new import_ts_morph.Project({
6108
+ compilerOptions: {
6109
+ ...compilerOptions
6110
+ }
6111
+ });
6078
6112
 
6079
6113
  // src/utils/remove-dir.ts
6080
6114
  init_cjs_shims();
@@ -6132,80 +6166,9 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content) => {
6132
6166
  import_node_fs4.default.writeFileSync(writeLocation, await formatFile(content));
6133
6167
  }, "writeFileSafely");
6134
6168
 
6135
- // src/prisma-shield-generator.ts
6136
- async function generateShield(options) {
6137
- const internals = await getPrismaInternals();
6138
- const outputDir = internals.parseEnvValue(options.generator.output);
6139
- const results = configSchema.safeParse(options.generator.config);
6140
- if (!results.success) throw new Error("Invalid options passed");
6141
- const config = results.data;
6142
- await import_node_fs5.promises.mkdir(outputDir, {
6143
- recursive: true
6144
- });
6145
- await removeDir(outputDir, true);
6146
- const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6147
- const prismaClientDmmf = await internals.getDMMF({
6148
- datamodel: options.datamodel,
6149
- previewFeatures: prismaClientProvider?.previewFeatures
6150
- });
6151
- const queries = [];
6152
- const mutations = [];
6153
- const subscriptions = [];
6154
- prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
6155
- const { model: _model, plural: _plural, ...operations } = modelOperation;
6156
- for (const [opType, opNameWithModel] of Object.entries(operations)) {
6157
- if ([
6158
- "findUnique",
6159
- "findFirst",
6160
- "findMany",
6161
- "aggregate",
6162
- "groupBy"
6163
- ].includes(opType)) {
6164
- queries.push(opNameWithModel);
6165
- }
6166
- if ([
6167
- "createOne",
6168
- "deleteOne",
6169
- "updateOne",
6170
- "deleteMany",
6171
- "updateMany",
6172
- "upsertOne"
6173
- ].includes(opType)) {
6174
- mutations.push(opNameWithModel);
6175
- }
6176
- }
6177
- });
6178
- queries.sort();
6179
- mutations.sort();
6180
- subscriptions.sort();
6181
- const shieldText = constructShield({
6182
- queries,
6183
- mutations,
6184
- subscriptions
6185
- }, config, options);
6186
- await writeFileSafely(import_node_path6.default.join(outputDir, "shield.ts"), shieldText);
6187
- }
6188
- __name(generateShield, "generateShield");
6189
-
6190
- // src/project.ts
6191
- init_cjs_shims();
6192
- var import_ts_morph = require("ts-morph");
6193
- var compilerOptions = {
6194
- target: import_ts_morph.ScriptTarget.ESNext,
6195
- module: import_ts_morph.ModuleKind.ESNext,
6196
- emitDecoratorMetadata: true,
6197
- experimentalDecorators: true,
6198
- esModuleInterop: true
6199
- };
6200
- var project = new import_ts_morph.Project({
6201
- compilerOptions: {
6202
- ...compilerOptions
6203
- }
6204
- });
6205
-
6206
6169
  // src/prisma-generator.ts
6207
6170
  async function generate(options) {
6208
- console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
6171
+ console.log("[STORM]: Running the Storm Software - Prisma tRPC generator");
6209
6172
  const internals = await getPrismaInternals();
6210
6173
  console.log(`[STORM]: Validating configuration options`);
6211
6174
  const outputDir = internals.parseEnvValue(options.generator.output);
@@ -6216,13 +6179,12 @@ async function generate(options) {
6216
6179
  const config = results.data;
6217
6180
  const consoleLog = /* @__PURE__ */ __name((message) => {
6218
6181
  if (config.debug) {
6219
- console.log(`[STORM]: ${message}`);
6182
+ console.log(`[STORM]: ${message}
6183
+ `);
6220
6184
  }
6221
6185
  }, "consoleLog");
6222
6186
  consoleLog(`Preparing output directory: ${outputDir}`);
6223
- await import_node_fs6.promises.mkdir(outputDir, {
6224
- recursive: true
6225
- });
6187
+ await createDirectory(outputDir);
6226
6188
  await removeDir(outputDir, true);
6227
6189
  if (config.withZod !== false) {
6228
6190
  consoleLog("Generating Zod schemas");
@@ -6231,17 +6193,68 @@ async function generate(options) {
6231
6193
  } else {
6232
6194
  consoleLog("Skipping Zod schemas generation");
6233
6195
  }
6196
+ consoleLog("Finding Prisma Client generator");
6197
+ const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6198
+ if (!prismaClientProvider) {
6199
+ throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
6200
+ }
6201
+ consoleLog("Generating Prisma Client DMMF");
6202
+ const prismaClientDmmf = await internals.getDMMF({
6203
+ datamodel: options.datamodel,
6204
+ previewFeatures: prismaClientProvider?.previewFeatures
6205
+ });
6206
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
6207
+ const models = prismaClientDmmf.datamodel.models;
6208
+ const hiddenModels = [];
6234
6209
  if (config.withShield !== false) {
6235
6210
  consoleLog("Generating tRPC Shield");
6236
- const shieldOutputPath = import_node_path7.default.join(outputDir, "./shield");
6237
- await generateShield({
6211
+ const shieldOutputDir = joinPaths(outputDir, "shield");
6212
+ consoleLog("Preparing tRPC Shield output directory");
6213
+ await createDirectory(shieldOutputDir);
6214
+ await removeDir(shieldOutputDir, true);
6215
+ const queries = [];
6216
+ const mutations = [];
6217
+ const subscriptions = [];
6218
+ prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
6219
+ const { model: _model, plural: _plural, ...operations } = modelOperation;
6220
+ for (const [opType, opNameWithModel] of Object.entries(operations)) {
6221
+ if ([
6222
+ "findUnique",
6223
+ "findFirst",
6224
+ "findMany",
6225
+ "aggregate",
6226
+ "groupBy"
6227
+ ].includes(opType)) {
6228
+ queries.push(opNameWithModel);
6229
+ }
6230
+ if ([
6231
+ "createOne",
6232
+ "deleteOne",
6233
+ "updateOne",
6234
+ "deleteMany",
6235
+ "updateMany",
6236
+ "upsertOne"
6237
+ ].includes(opType)) {
6238
+ mutations.push(opNameWithModel);
6239
+ }
6240
+ }
6241
+ });
6242
+ queries.sort();
6243
+ mutations.sort();
6244
+ subscriptions.sort();
6245
+ consoleLog("Constructing tRPC Shield source file");
6246
+ const shieldText = constructShield({
6247
+ queries,
6248
+ mutations,
6249
+ subscriptions
6250
+ }, config, {
6238
6251
  ...options,
6239
6252
  generator: {
6240
6253
  ...options.generator,
6241
6254
  output: {
6242
6255
  fromEnvVar: null,
6243
6256
  ...options.generator.output,
6244
- value: shieldOutputPath
6257
+ value: shieldOutputDir
6245
6258
  },
6246
6259
  config: {
6247
6260
  ...options.generator.config,
@@ -6249,25 +6262,14 @@ async function generate(options) {
6249
6262
  }
6250
6263
  }
6251
6264
  });
6265
+ consoleLog("Saving tRPC Shield source file to disk");
6266
+ await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
6252
6267
  } else {
6253
6268
  consoleLog("Skipping tRPC Shield generation");
6254
6269
  }
6255
- consoleLog("Finding Prisma Client generator");
6256
- const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6257
- if (!prismaClientProvider) {
6258
- throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
6259
- }
6260
- consoleLog("Generating Prisma Client DMMF");
6261
- const prismaClientDmmf = await internals.getDMMF({
6262
- datamodel: options.datamodel,
6263
- previewFeatures: prismaClientProvider?.previewFeatures
6264
- });
6265
- const modelOperations = prismaClientDmmf.mappings.modelOperations;
6266
- const models = prismaClientDmmf.datamodel.models;
6267
- const hiddenModels = [];
6268
6270
  consoleLog(`Generating tRPC source code for ${models.length} models`);
6269
6271
  resolveModelsComments(models, hiddenModels);
6270
- const createRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
6272
+ const createRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
6271
6273
  overwrite: true
6272
6274
  });
6273
6275
  consoleLog("Generating tRPC imports");
@@ -6280,7 +6282,7 @@ async function generate(options) {
6280
6282
  createRouter.formatText({
6281
6283
  indentSize: 2
6282
6284
  });
6283
- const appRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `index.ts`), void 0, {
6285
+ const appRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `index.ts`), void 0, {
6284
6286
  overwrite: true
6285
6287
  });
6286
6288
  consoleLog("Generating tRPC router imports");
@@ -6302,7 +6304,7 @@ async function generate(options) {
6302
6304
  const plural = (0, import_pluralize.default)(model.toLowerCase());
6303
6305
  consoleLog(`Generating tRPC router for model ${model}`);
6304
6306
  generateRouterImport(appRouter, plural, model);
6305
- const modelRouter = project.createSourceFile(import_node_path7.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
6307
+ const modelRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
6306
6308
  overwrite: true
6307
6309
  });
6308
6310
  generateCreateRouterImport({