@stryke/prisma-trpc-generator 0.3.0 → 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/generator.js CHANGED
@@ -681,9 +681,160 @@ init_esm_shims();
681
681
 
682
682
  // src/prisma-generator.ts
683
683
  init_esm_shims();
684
+
685
+ // ../fs/src/helpers.ts
686
+ init_esm_shims();
687
+
688
+ // ../path/src/exists.ts
689
+ init_esm_shims();
690
+ import { access, constants } from "node:fs/promises";
691
+ var exists = /* @__PURE__ */ __name(async (filePath) => {
692
+ return access(filePath, constants.F_OK).then(() => true).catch(() => false);
693
+ }, "exists");
694
+
695
+ // ../fs/src/helpers.ts
696
+ import { mkdir, readFile, rm } from "node:fs/promises";
697
+ async function createDirectory(path6) {
698
+ if (await exists(path6)) {
699
+ return;
700
+ }
701
+ return mkdir(path6, {
702
+ recursive: true
703
+ });
704
+ }
705
+ __name(createDirectory, "createDirectory");
706
+
707
+ // ../path/src/join-paths.ts
708
+ init_esm_shims();
709
+ var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
710
+ function normalizeWindowsPath(input = "") {
711
+ if (!input) {
712
+ return input;
713
+ }
714
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
715
+ }
716
+ __name(normalizeWindowsPath, "normalizeWindowsPath");
717
+ var _UNC_REGEX = /^[/\\]{2}/;
718
+ var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
719
+ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
720
+ var isAbsolute = /* @__PURE__ */ __name(function(p) {
721
+ return _IS_ABSOLUTE_RE.test(p);
722
+ }, "isAbsolute");
723
+ var correctPaths = /* @__PURE__ */ __name(function(path6) {
724
+ if (!path6 || path6.length === 0) {
725
+ return ".";
726
+ }
727
+ path6 = normalizeWindowsPath(path6);
728
+ const isUNCPath = path6.match(_UNC_REGEX);
729
+ const isPathAbsolute = isAbsolute(path6);
730
+ const trailingSeparator = path6[path6.length - 1] === "/";
731
+ path6 = normalizeString(path6, !isPathAbsolute);
732
+ if (path6.length === 0) {
733
+ if (isPathAbsolute) {
734
+ return "/";
735
+ }
736
+ return trailingSeparator ? "./" : ".";
737
+ }
738
+ if (trailingSeparator) {
739
+ path6 += "/";
740
+ }
741
+ if (_DRIVE_LETTER_RE.test(path6)) {
742
+ path6 += "/";
743
+ }
744
+ if (isUNCPath) {
745
+ if (!isPathAbsolute) {
746
+ return `//./${path6}`;
747
+ }
748
+ return `//${path6}`;
749
+ }
750
+ return isPathAbsolute && !isAbsolute(path6) ? `/${path6}` : path6;
751
+ }, "correctPaths");
752
+ var joinPaths = /* @__PURE__ */ __name(function(...segments) {
753
+ let path6 = "";
754
+ for (const seg of segments) {
755
+ if (!seg) {
756
+ continue;
757
+ }
758
+ if (path6.length > 0) {
759
+ const pathTrailing = path6[path6.length - 1] === "/";
760
+ const segLeading = seg[0] === "/";
761
+ const both = pathTrailing && segLeading;
762
+ if (both) {
763
+ path6 += seg.slice(1);
764
+ } else {
765
+ path6 += pathTrailing || segLeading ? seg : `/${seg}`;
766
+ }
767
+ } else {
768
+ path6 += seg;
769
+ }
770
+ }
771
+ return correctPaths(path6);
772
+ }, "joinPaths");
773
+ function normalizeString(path6, allowAboveRoot) {
774
+ let res = "";
775
+ let lastSegmentLength = 0;
776
+ let lastSlash = -1;
777
+ let dots = 0;
778
+ let char = null;
779
+ for (let index = 0; index <= path6.length; ++index) {
780
+ if (index < path6.length) {
781
+ char = path6[index];
782
+ } else if (char === "/") {
783
+ break;
784
+ } else {
785
+ char = "/";
786
+ }
787
+ if (char === "/") {
788
+ if (lastSlash === index - 1 || dots === 1) {
789
+ } else if (dots === 2) {
790
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
791
+ if (res.length > 2) {
792
+ const lastSlashIndex = res.lastIndexOf("/");
793
+ if (lastSlashIndex === -1) {
794
+ res = "";
795
+ lastSegmentLength = 0;
796
+ } else {
797
+ res = res.slice(0, lastSlashIndex);
798
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
799
+ }
800
+ lastSlash = index;
801
+ dots = 0;
802
+ continue;
803
+ } else if (res.length > 0) {
804
+ res = "";
805
+ lastSegmentLength = 0;
806
+ lastSlash = index;
807
+ dots = 0;
808
+ continue;
809
+ }
810
+ }
811
+ if (allowAboveRoot) {
812
+ res += res.length > 0 ? "/.." : "..";
813
+ lastSegmentLength = 2;
814
+ }
815
+ } else {
816
+ if (res.length > 0) {
817
+ res += `/${path6.slice(lastSlash + 1, index)}`;
818
+ } else {
819
+ res = path6.slice(lastSlash + 1, index);
820
+ }
821
+ lastSegmentLength = index - lastSlash - 1;
822
+ }
823
+ lastSlash = index;
824
+ dots = 0;
825
+ } else if (char === "." && dots !== -1) {
826
+ ++dots;
827
+ } else {
828
+ dots = -1;
829
+ }
830
+ }
831
+ return res;
832
+ }
833
+ __name(normalizeString, "normalizeString");
834
+
835
+ // src/prisma-generator.ts
684
836
  var import_pluralize = __toESM(require_pluralize(), 1);
685
- import { promises as fs4 } from "node:fs";
686
- import path6 from "node:path";
837
+ import path5 from "node:path";
687
838
 
688
839
  // src/config.ts
689
840
  init_esm_shims();
@@ -1050,8 +1201,8 @@ function getErrorMap() {
1050
1201
  }
1051
1202
  __name(getErrorMap, "getErrorMap");
1052
1203
  var makeIssue = /* @__PURE__ */ __name((params) => {
1053
- const { data, path: path7, errorMaps, issueData } = params;
1054
- const fullPath = [...path7, ...issueData.path || []];
1204
+ const { data, path: path6, errorMaps, issueData } = params;
1205
+ const fullPath = [...path6, ...issueData.path || []];
1055
1206
  const fullIssue = {
1056
1207
  ...issueData,
1057
1208
  path: fullPath
@@ -1185,11 +1336,11 @@ var ParseInputLazyPath = class {
1185
1336
  static {
1186
1337
  __name(this, "ParseInputLazyPath");
1187
1338
  }
1188
- constructor(parent, value, path7, key) {
1339
+ constructor(parent, value, path6, key) {
1189
1340
  this._cachedPath = [];
1190
1341
  this.parent = parent;
1191
1342
  this.data = value;
1192
- this._path = path7;
1343
+ this._path = path6;
1193
1344
  this._key = key;
1194
1345
  }
1195
1346
  get path() {
@@ -4961,134 +5112,6 @@ init_esm_shims();
4961
5112
  // ../env/src/get-env-paths.ts
4962
5113
  init_esm_shims();
4963
5114
 
4964
- // ../path/src/join-paths.ts
4965
- init_esm_shims();
4966
- var _DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
4967
- function normalizeWindowsPath(input = "") {
4968
- if (!input) {
4969
- return input;
4970
- }
4971
- return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
4972
- }
4973
- __name(normalizeWindowsPath, "normalizeWindowsPath");
4974
- var _UNC_REGEX = /^[/\\]{2}/;
4975
- var _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
4976
- var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
4977
- var isAbsolute = /* @__PURE__ */ __name(function(p) {
4978
- return _IS_ABSOLUTE_RE.test(p);
4979
- }, "isAbsolute");
4980
- var correctPaths = /* @__PURE__ */ __name(function(path7) {
4981
- if (!path7 || path7.length === 0) {
4982
- return ".";
4983
- }
4984
- path7 = normalizeWindowsPath(path7);
4985
- const isUNCPath = path7.match(_UNC_REGEX);
4986
- const isPathAbsolute = isAbsolute(path7);
4987
- const trailingSeparator = path7[path7.length - 1] === "/";
4988
- path7 = normalizeString(path7, !isPathAbsolute);
4989
- if (path7.length === 0) {
4990
- if (isPathAbsolute) {
4991
- return "/";
4992
- }
4993
- return trailingSeparator ? "./" : ".";
4994
- }
4995
- if (trailingSeparator) {
4996
- path7 += "/";
4997
- }
4998
- if (_DRIVE_LETTER_RE.test(path7)) {
4999
- path7 += "/";
5000
- }
5001
- if (isUNCPath) {
5002
- if (!isPathAbsolute) {
5003
- return `//./${path7}`;
5004
- }
5005
- return `//${path7}`;
5006
- }
5007
- return isPathAbsolute && !isAbsolute(path7) ? `/${path7}` : path7;
5008
- }, "correctPaths");
5009
- var joinPaths = /* @__PURE__ */ __name(function(...segments) {
5010
- let path7 = "";
5011
- for (const seg of segments) {
5012
- if (!seg) {
5013
- continue;
5014
- }
5015
- if (path7.length > 0) {
5016
- const pathTrailing = path7[path7.length - 1] === "/";
5017
- const segLeading = seg[0] === "/";
5018
- const both = pathTrailing && segLeading;
5019
- if (both) {
5020
- path7 += seg.slice(1);
5021
- } else {
5022
- path7 += pathTrailing || segLeading ? seg : `/${seg}`;
5023
- }
5024
- } else {
5025
- path7 += seg;
5026
- }
5027
- }
5028
- return correctPaths(path7);
5029
- }, "joinPaths");
5030
- function normalizeString(path7, allowAboveRoot) {
5031
- let res = "";
5032
- let lastSegmentLength = 0;
5033
- let lastSlash = -1;
5034
- let dots = 0;
5035
- let char = null;
5036
- for (let index = 0; index <= path7.length; ++index) {
5037
- if (index < path7.length) {
5038
- char = path7[index];
5039
- } else if (char === "/") {
5040
- break;
5041
- } else {
5042
- char = "/";
5043
- }
5044
- if (char === "/") {
5045
- if (lastSlash === index - 1 || dots === 1) {
5046
- } else if (dots === 2) {
5047
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
5048
- if (res.length > 2) {
5049
- const lastSlashIndex = res.lastIndexOf("/");
5050
- if (lastSlashIndex === -1) {
5051
- res = "";
5052
- lastSegmentLength = 0;
5053
- } else {
5054
- res = res.slice(0, lastSlashIndex);
5055
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
5056
- }
5057
- lastSlash = index;
5058
- dots = 0;
5059
- continue;
5060
- } else if (res.length > 0) {
5061
- res = "";
5062
- lastSegmentLength = 0;
5063
- lastSlash = index;
5064
- dots = 0;
5065
- continue;
5066
- }
5067
- }
5068
- if (allowAboveRoot) {
5069
- res += res.length > 0 ? "/.." : "..";
5070
- lastSegmentLength = 2;
5071
- }
5072
- } else {
5073
- if (res.length > 0) {
5074
- res += `/${path7.slice(lastSlash + 1, index)}`;
5075
- } else {
5076
- res = path7.slice(lastSlash + 1, index);
5077
- }
5078
- lastSegmentLength = index - lastSlash - 1;
5079
- }
5080
- lastSlash = index;
5081
- dots = 0;
5082
- } else if (char === "." && dots !== -1) {
5083
- ++dots;
5084
- } else {
5085
- dots = -1;
5086
- }
5087
- }
5088
- return res;
5089
- }
5090
- __name(normalizeString, "normalizeString");
5091
-
5092
5115
  // ../string-format/src/title-case.ts
5093
5116
  init_esm_shims();
5094
5117
 
@@ -5267,16 +5290,16 @@ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp2(target, "name
5267
5290
  }), "__name");
5268
5291
 
5269
5292
  // ../../node_modules/.pnpm/@storm-software+config-tools@1.160.6_@storm-software+config@1.110.6/node_modules/@storm-software/config-tools/dist/chunk-NQFXB5CV.js
5270
- import { existsSync } from "node:fs";
5293
+ import { existsSync as existsSync2 } from "node:fs";
5271
5294
  import { join } from "node:path";
5272
5295
  var MAX_PATH_SEARCH_DEPTH = 30;
5273
5296
  var depth = 0;
5274
5297
  function findFolderUp(startPath, endFileNames = [], endDirectoryNames = []) {
5275
5298
  const _startPath = startPath ?? process.cwd();
5276
- if (endDirectoryNames.some((endDirName) => existsSync(join(_startPath, endDirName)))) {
5299
+ if (endDirectoryNames.some((endDirName) => existsSync2(join(_startPath, endDirName)))) {
5277
5300
  return _startPath;
5278
5301
  }
5279
- if (endFileNames.some((endFileName) => existsSync(join(_startPath, endFileName)))) {
5302
+ if (endFileNames.some((endFileName) => existsSync2(join(_startPath, endFileName)))) {
5280
5303
  return _startPath;
5281
5304
  }
5282
5305
  if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
@@ -5302,34 +5325,34 @@ __name2(normalizeWindowsPath2, "normalizeWindowsPath");
5302
5325
  var _UNC_REGEX2 = /^[/\\]{2}/;
5303
5326
  var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
5304
5327
  var _DRIVE_LETTER_RE2 = /^[A-Za-z]:$/;
5305
- var correctPaths2 = /* @__PURE__ */ __name2(function(path7) {
5306
- if (!path7 || path7.length === 0) {
5328
+ var correctPaths2 = /* @__PURE__ */ __name2(function(path6) {
5329
+ if (!path6 || path6.length === 0) {
5307
5330
  return ".";
5308
5331
  }
5309
- path7 = normalizeWindowsPath2(path7);
5310
- const isUNCPath = path7.match(_UNC_REGEX2);
5311
- const isPathAbsolute = isAbsolute2(path7);
5312
- const trailingSeparator = path7[path7.length - 1] === "/";
5313
- path7 = normalizeString2(path7, !isPathAbsolute);
5314
- if (path7.length === 0) {
5332
+ path6 = normalizeWindowsPath2(path6);
5333
+ const isUNCPath = path6.match(_UNC_REGEX2);
5334
+ const isPathAbsolute = isAbsolute2(path6);
5335
+ const trailingSeparator = path6[path6.length - 1] === "/";
5336
+ path6 = normalizeString2(path6, !isPathAbsolute);
5337
+ if (path6.length === 0) {
5315
5338
  if (isPathAbsolute) {
5316
5339
  return "/";
5317
5340
  }
5318
5341
  return trailingSeparator ? "./" : ".";
5319
5342
  }
5320
5343
  if (trailingSeparator) {
5321
- path7 += "/";
5344
+ path6 += "/";
5322
5345
  }
5323
- if (_DRIVE_LETTER_RE2.test(path7)) {
5324
- path7 += "/";
5346
+ if (_DRIVE_LETTER_RE2.test(path6)) {
5347
+ path6 += "/";
5325
5348
  }
5326
5349
  if (isUNCPath) {
5327
5350
  if (!isPathAbsolute) {
5328
- return `//./${path7}`;
5351
+ return `//./${path6}`;
5329
5352
  }
5330
- return `//${path7}`;
5353
+ return `//${path6}`;
5331
5354
  }
5332
- return isPathAbsolute && !isAbsolute2(path7) ? `/${path7}` : path7;
5355
+ return isPathAbsolute && !isAbsolute2(path6) ? `/${path6}` : path6;
5333
5356
  }, "correctPaths");
5334
5357
  function cwd() {
5335
5358
  if (typeof process !== "undefined" && typeof process.cwd === "function") {
@@ -5339,15 +5362,15 @@ function cwd() {
5339
5362
  }
5340
5363
  __name(cwd, "cwd");
5341
5364
  __name2(cwd, "cwd");
5342
- function normalizeString2(path7, allowAboveRoot) {
5365
+ function normalizeString2(path6, allowAboveRoot) {
5343
5366
  let res = "";
5344
5367
  let lastSegmentLength = 0;
5345
5368
  let lastSlash = -1;
5346
5369
  let dots = 0;
5347
5370
  let char = null;
5348
- for (let index = 0; index <= path7.length; ++index) {
5349
- if (index < path7.length) {
5350
- char = path7[index];
5371
+ for (let index = 0; index <= path6.length; ++index) {
5372
+ if (index < path6.length) {
5373
+ char = path6[index];
5351
5374
  } else if (char === "/") {
5352
5375
  break;
5353
5376
  } else {
@@ -5383,9 +5406,9 @@ function normalizeString2(path7, allowAboveRoot) {
5383
5406
  }
5384
5407
  } else {
5385
5408
  if (res.length > 0) {
5386
- res += `/${path7.slice(lastSlash + 1, index)}`;
5409
+ res += `/${path6.slice(lastSlash + 1, index)}`;
5387
5410
  } else {
5388
- res = path7.slice(lastSlash + 1, index);
5411
+ res = path6.slice(lastSlash + 1, index);
5389
5412
  }
5390
5413
  lastSegmentLength = index - lastSlash - 1;
5391
5414
  }
@@ -5484,20 +5507,20 @@ init_esm_shims();
5484
5507
  // ../path/src/is-file.ts
5485
5508
  init_esm_shims();
5486
5509
  import { lstatSync, statSync } from "node:fs";
5487
- function isFile(path7, additionalPath) {
5488
- return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path7) : path7, {
5510
+ function isFile(path6, additionalPath) {
5511
+ return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path6) : path6, {
5489
5512
  throwIfNoEntry: false
5490
5513
  })?.isFile());
5491
5514
  }
5492
5515
  __name(isFile, "isFile");
5493
- function isDirectory(path7, additionalPath) {
5494
- return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path7) : path7, {
5516
+ function isDirectory(path6, additionalPath) {
5517
+ return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path6) : path6, {
5495
5518
  throwIfNoEntry: false
5496
5519
  })?.isDirectory());
5497
5520
  }
5498
5521
  __name(isDirectory, "isDirectory");
5499
- function isAbsolutePath(path7) {
5500
- return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path7);
5522
+ function isAbsolutePath(path6) {
5523
+ return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path6);
5501
5524
  }
5502
5525
  __name(isAbsolutePath, "isAbsolutePath");
5503
5526
 
@@ -5510,15 +5533,15 @@ function normalizeWindowsPath3(input = "") {
5510
5533
  return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE3, (r) => r.toUpperCase());
5511
5534
  }
5512
5535
  __name(normalizeWindowsPath3, "normalizeWindowsPath");
5513
- function normalizeString3(path7, allowAboveRoot) {
5536
+ function normalizeString3(path6, allowAboveRoot) {
5514
5537
  let res = "";
5515
5538
  let lastSegmentLength = 0;
5516
5539
  let lastSlash = -1;
5517
5540
  let dots = 0;
5518
5541
  let char = null;
5519
- for (let index = 0; index <= path7.length; ++index) {
5520
- if (index < path7.length) {
5521
- char = path7[index];
5542
+ for (let index = 0; index <= path6.length; ++index) {
5543
+ if (index < path6.length) {
5544
+ char = path6[index];
5522
5545
  } else if (char === "/") {
5523
5546
  break;
5524
5547
  } else {
@@ -5554,9 +5577,9 @@ function normalizeString3(path7, allowAboveRoot) {
5554
5577
  }
5555
5578
  } else {
5556
5579
  if (res.length > 0) {
5557
- res += `/${path7.slice(lastSlash + 1, index)}`;
5580
+ res += `/${path6.slice(lastSlash + 1, index)}`;
5558
5581
  } else {
5559
- res = path7.slice(lastSlash + 1, index);
5582
+ res = path6.slice(lastSlash + 1, index);
5560
5583
  }
5561
5584
  lastSegmentLength = index - lastSlash - 1;
5562
5585
  }
@@ -5573,17 +5596,17 @@ function normalizeString3(path7, allowAboveRoot) {
5573
5596
  __name(normalizeString3, "normalizeString");
5574
5597
 
5575
5598
  // ../path/src/file-path-fns.ts
5576
- function resolvePath(path7, cwd2 = getWorkspaceRoot()) {
5577
- const paths = normalizeWindowsPath3(path7).split("/");
5599
+ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
5600
+ const paths = normalizeWindowsPath3(path6).split("/");
5578
5601
  let resolvedPath = "";
5579
5602
  let resolvedAbsolute = false;
5580
5603
  for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
5581
- const path8 = index >= 0 ? paths[index] : cwd2;
5582
- if (!path8 || path8.length === 0) {
5604
+ const path7 = index >= 0 ? paths[index] : cwd2;
5605
+ if (!path7 || path7.length === 0) {
5583
5606
  continue;
5584
5607
  }
5585
- resolvedPath = joinPaths(path8, resolvedPath);
5586
- resolvedAbsolute = isAbsolutePath(path8);
5608
+ resolvedPath = joinPaths(path7, resolvedPath);
5609
+ resolvedAbsolute = isAbsolutePath(path7);
5587
5610
  }
5588
5611
  resolvedPath = normalizeString3(resolvedPath, !resolvedAbsolute);
5589
5612
  if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
@@ -5593,13 +5616,13 @@ function resolvePath(path7, cwd2 = getWorkspaceRoot()) {
5593
5616
  }
5594
5617
  __name(resolvePath, "resolvePath");
5595
5618
  function resolvePaths(...paths) {
5596
- return resolvePath(joinPaths(...paths.map((path7) => normalizeWindowsPath3(path7))));
5619
+ return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath3(path6))));
5597
5620
  }
5598
5621
  __name(resolvePaths, "resolvePaths");
5599
5622
 
5600
5623
  // ../path/src/get-parent-path.ts
5601
- var resolveParentPath = /* @__PURE__ */ __name((path7) => {
5602
- return resolvePaths(path7, "..");
5624
+ var resolveParentPath = /* @__PURE__ */ __name((path6) => {
5625
+ return resolvePaths(path6, "..");
5603
5626
  }, "resolveParentPath");
5604
5627
  var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
5605
5628
  const ignoreCase = options?.ignoreCase ?? true;
@@ -6080,10 +6103,21 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
6080
6103
  return shieldText;
6081
6104
  }, "constructShield");
6082
6105
 
6083
- // src/prisma-shield-generator.ts
6106
+ // src/project.ts
6084
6107
  init_esm_shims();
6085
- import { promises as fs3 } from "node:fs";
6086
- import path5 from "node:path";
6108
+ import { ModuleKind, Project, ScriptTarget } from "ts-morph";
6109
+ var compilerOptions = {
6110
+ target: ScriptTarget.ESNext,
6111
+ module: ModuleKind.ESNext,
6112
+ emitDecoratorMetadata: true,
6113
+ experimentalDecorators: true,
6114
+ esModuleInterop: true
6115
+ };
6116
+ var project = new Project({
6117
+ compilerOptions: {
6118
+ ...compilerOptions
6119
+ }
6120
+ });
6087
6121
 
6088
6122
  // src/utils/remove-dir.ts
6089
6123
  init_esm_shims();
@@ -6141,80 +6175,9 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content) => {
6141
6175
  fs2.writeFileSync(writeLocation, await formatFile(content));
6142
6176
  }, "writeFileSafely");
6143
6177
 
6144
- // src/prisma-shield-generator.ts
6145
- async function generateShield(options) {
6146
- const internals = await getPrismaInternals();
6147
- const outputDir = internals.parseEnvValue(options.generator.output);
6148
- const results = configSchema.safeParse(options.generator.config);
6149
- if (!results.success) throw new Error("Invalid options passed");
6150
- const config = results.data;
6151
- await fs3.mkdir(outputDir, {
6152
- recursive: true
6153
- });
6154
- await removeDir(outputDir, true);
6155
- const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6156
- const prismaClientDmmf = await internals.getDMMF({
6157
- datamodel: options.datamodel,
6158
- previewFeatures: prismaClientProvider?.previewFeatures
6159
- });
6160
- const queries = [];
6161
- const mutations = [];
6162
- const subscriptions = [];
6163
- prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
6164
- const { model: _model, plural: _plural, ...operations } = modelOperation;
6165
- for (const [opType, opNameWithModel] of Object.entries(operations)) {
6166
- if ([
6167
- "findUnique",
6168
- "findFirst",
6169
- "findMany",
6170
- "aggregate",
6171
- "groupBy"
6172
- ].includes(opType)) {
6173
- queries.push(opNameWithModel);
6174
- }
6175
- if ([
6176
- "createOne",
6177
- "deleteOne",
6178
- "updateOne",
6179
- "deleteMany",
6180
- "updateMany",
6181
- "upsertOne"
6182
- ].includes(opType)) {
6183
- mutations.push(opNameWithModel);
6184
- }
6185
- }
6186
- });
6187
- queries.sort();
6188
- mutations.sort();
6189
- subscriptions.sort();
6190
- const shieldText = constructShield({
6191
- queries,
6192
- mutations,
6193
- subscriptions
6194
- }, config, options);
6195
- await writeFileSafely(path5.join(outputDir, "shield.ts"), shieldText);
6196
- }
6197
- __name(generateShield, "generateShield");
6198
-
6199
- // src/project.ts
6200
- init_esm_shims();
6201
- import { ModuleKind, Project, ScriptTarget } from "ts-morph";
6202
- var compilerOptions = {
6203
- target: ScriptTarget.ESNext,
6204
- module: ModuleKind.ESNext,
6205
- emitDecoratorMetadata: true,
6206
- experimentalDecorators: true,
6207
- esModuleInterop: true
6208
- };
6209
- var project = new Project({
6210
- compilerOptions: {
6211
- ...compilerOptions
6212
- }
6213
- });
6214
-
6215
6178
  // src/prisma-generator.ts
6216
6179
  async function generate(options) {
6217
- console.log("[STORM]: Running the Storm Software - Prisma tRPC generator with options: \n", JSON.stringify(options, null, 2));
6180
+ console.log("[STORM]: Running the Storm Software - Prisma tRPC generator");
6218
6181
  const internals = await getPrismaInternals();
6219
6182
  console.log(`[STORM]: Validating configuration options`);
6220
6183
  const outputDir = internals.parseEnvValue(options.generator.output);
@@ -6225,13 +6188,12 @@ async function generate(options) {
6225
6188
  const config = results.data;
6226
6189
  const consoleLog = /* @__PURE__ */ __name((message) => {
6227
6190
  if (config.debug) {
6228
- console.log(`[STORM]: ${message}`);
6191
+ console.log(`[STORM]: ${message}
6192
+ `);
6229
6193
  }
6230
6194
  }, "consoleLog");
6231
6195
  consoleLog(`Preparing output directory: ${outputDir}`);
6232
- await fs4.mkdir(outputDir, {
6233
- recursive: true
6234
- });
6196
+ await createDirectory(outputDir);
6235
6197
  await removeDir(outputDir, true);
6236
6198
  if (config.withZod !== false) {
6237
6199
  consoleLog("Generating Zod schemas");
@@ -6240,17 +6202,68 @@ async function generate(options) {
6240
6202
  } else {
6241
6203
  consoleLog("Skipping Zod schemas generation");
6242
6204
  }
6205
+ consoleLog("Finding Prisma Client generator");
6206
+ const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6207
+ if (!prismaClientProvider) {
6208
+ throw new Error("No Prisma Client generator found. Please add `prisma-client-js` to your generator list.");
6209
+ }
6210
+ consoleLog("Generating Prisma Client DMMF");
6211
+ const prismaClientDmmf = await internals.getDMMF({
6212
+ datamodel: options.datamodel,
6213
+ previewFeatures: prismaClientProvider?.previewFeatures
6214
+ });
6215
+ const modelOperations = prismaClientDmmf.mappings.modelOperations;
6216
+ const models = prismaClientDmmf.datamodel.models;
6217
+ const hiddenModels = [];
6243
6218
  if (config.withShield !== false) {
6244
6219
  consoleLog("Generating tRPC Shield");
6245
- const shieldOutputPath = path6.join(outputDir, "./shield");
6246
- await generateShield({
6220
+ const shieldOutputDir = joinPaths(outputDir, "shield");
6221
+ consoleLog("Preparing tRPC Shield output directory");
6222
+ await createDirectory(shieldOutputDir);
6223
+ await removeDir(shieldOutputDir, true);
6224
+ const queries = [];
6225
+ const mutations = [];
6226
+ const subscriptions = [];
6227
+ prismaClientDmmf.mappings.modelOperations.forEach((modelOperation) => {
6228
+ const { model: _model, plural: _plural, ...operations } = modelOperation;
6229
+ for (const [opType, opNameWithModel] of Object.entries(operations)) {
6230
+ if ([
6231
+ "findUnique",
6232
+ "findFirst",
6233
+ "findMany",
6234
+ "aggregate",
6235
+ "groupBy"
6236
+ ].includes(opType)) {
6237
+ queries.push(opNameWithModel);
6238
+ }
6239
+ if ([
6240
+ "createOne",
6241
+ "deleteOne",
6242
+ "updateOne",
6243
+ "deleteMany",
6244
+ "updateMany",
6245
+ "upsertOne"
6246
+ ].includes(opType)) {
6247
+ mutations.push(opNameWithModel);
6248
+ }
6249
+ }
6250
+ });
6251
+ queries.sort();
6252
+ mutations.sort();
6253
+ subscriptions.sort();
6254
+ consoleLog("Constructing tRPC Shield source file");
6255
+ const shieldText = constructShield({
6256
+ queries,
6257
+ mutations,
6258
+ subscriptions
6259
+ }, config, {
6247
6260
  ...options,
6248
6261
  generator: {
6249
6262
  ...options.generator,
6250
6263
  output: {
6251
6264
  fromEnvVar: null,
6252
6265
  ...options.generator.output,
6253
- value: shieldOutputPath
6266
+ value: shieldOutputDir
6254
6267
  },
6255
6268
  config: {
6256
6269
  ...options.generator.config,
@@ -6258,44 +6271,49 @@ async function generate(options) {
6258
6271
  }
6259
6272
  }
6260
6273
  });
6274
+ consoleLog("Saving tRPC Shield source file to disk");
6275
+ await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
6261
6276
  } else {
6262
6277
  consoleLog("Skipping tRPC Shield generation");
6263
6278
  }
6264
- const prismaClientProvider = options.otherGenerators.find((it) => internals.parseEnvValue(it.provider) === "prisma-client-js");
6265
- const prismaClientDmmf = await internals.getDMMF({
6266
- datamodel: options.datamodel,
6267
- previewFeatures: prismaClientProvider?.previewFeatures
6268
- });
6269
- const modelOperations = prismaClientDmmf.mappings.modelOperations;
6270
- const models = prismaClientDmmf.datamodel.models;
6271
- const hiddenModels = [];
6279
+ consoleLog(`Generating tRPC source code for ${models.length} models`);
6272
6280
  resolveModelsComments(models, hiddenModels);
6273
- const createRouter = project.createSourceFile(path6.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
6281
+ const createRouter = project.createSourceFile(path5.resolve(outputDir, "routers", "helpers", "createRouter.ts"), void 0, {
6274
6282
  overwrite: true
6275
6283
  });
6284
+ consoleLog("Generating tRPC imports");
6276
6285
  generateRPCImport(createRouter);
6277
6286
  if (config.withShield) {
6278
6287
  await generateShieldImport(createRouter, options, config.withShield);
6279
6288
  }
6289
+ consoleLog("Generating tRPC base router");
6280
6290
  await generateBaseRouter(createRouter, config, options);
6281
6291
  createRouter.formatText({
6282
6292
  indentSize: 2
6283
6293
  });
6284
- const appRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `index.ts`), void 0, {
6294
+ const appRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `index.ts`), void 0, {
6285
6295
  overwrite: true
6286
6296
  });
6297
+ consoleLog("Generating tRPC router imports");
6287
6298
  generateCreateRouterImport({
6288
6299
  sourceFile: appRouter
6289
6300
  });
6290
6301
  const routerStatements = [];
6291
6302
  for (const modelOperation of modelOperations) {
6292
6303
  const { model, ...operations } = modelOperation;
6293
- if (hiddenModels.includes(model)) continue;
6304
+ if (hiddenModels.includes(model)) {
6305
+ consoleLog(`Skipping model ${model} as it is hidden`);
6306
+ continue;
6307
+ }
6294
6308
  const modelActions = Object.keys(operations).filter((opType) => config.generateModelActions.includes(opType.replace("One", "")));
6295
- if (!modelActions.length) continue;
6309
+ if (!modelActions.length) {
6310
+ consoleLog(`Skipping model ${model} as it has no actions to generate`);
6311
+ continue;
6312
+ }
6296
6313
  const plural = (0, import_pluralize.default)(model.toLowerCase());
6314
+ consoleLog(`Generating tRPC router for model ${model}`);
6297
6315
  generateRouterImport(appRouter, plural, model);
6298
- const modelRouter = project.createSourceFile(path6.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
6316
+ const modelRouter = project.createSourceFile(path5.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
6299
6317
  overwrite: true
6300
6318
  });
6301
6319
  generateCreateRouterImport({
@@ -6303,6 +6321,7 @@ async function generate(options) {
6303
6321
  config
6304
6322
  });
6305
6323
  if (config.withZod) {
6324
+ consoleLog("Generating Zod schemas imports");
6306
6325
  generateRouterSchemaImports(modelRouter, model, modelActions);
6307
6326
  }
6308
6327
  modelRouter.addStatements(
@@ -6328,7 +6347,9 @@ async function generate(options) {
6328
6347
  `
6329
6348
  ${model.toLowerCase()}: ${plural}Router`
6330
6349
  );
6350
+ consoleLog(`Generated tRPC router for model ${model} with ${modelActions.length} actions`);
6331
6351
  }
6352
+ consoleLog("Generating tRPC app router");
6332
6353
  appRouter.addStatements(
6333
6354
  /* ts */
6334
6355
  `
@@ -6338,7 +6359,9 @@ async function generate(options) {
6338
6359
  appRouter.formatText({
6339
6360
  indentSize: 2
6340
6361
  });
6362
+ consoleLog("Saving tRPC router source files to disk");
6341
6363
  await project.save();
6364
+ consoleLog("Storm Software - Prisma tRPC generator completed successfully");
6342
6365
  }
6343
6366
  __name(generate, "generate");
6344
6367