@stryke/prisma-trpc-generator 0.7.6 → 0.8.1
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.cjs +206 -188
- package/dist/generator.js +206 -188
- package/dist/index.cjs +206 -188
- package/dist/index.js +206 -188
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -2489,20 +2489,20 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
|
|
|
2489
2489
|
|
|
2490
2490
|
// ../fs/src/helpers.ts
|
|
2491
2491
|
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
2492
|
-
async function createDirectory(
|
|
2493
|
-
if (await exists(
|
|
2492
|
+
async function createDirectory(path5) {
|
|
2493
|
+
if (await exists(path5)) {
|
|
2494
2494
|
return;
|
|
2495
2495
|
}
|
|
2496
|
-
return mkdir(
|
|
2496
|
+
return mkdir(path5, {
|
|
2497
2497
|
recursive: true
|
|
2498
2498
|
});
|
|
2499
2499
|
}
|
|
2500
2500
|
__name(createDirectory, "createDirectory");
|
|
2501
|
-
async function removeDirectory(
|
|
2502
|
-
if (!existsSync(
|
|
2501
|
+
async function removeDirectory(path5) {
|
|
2502
|
+
if (!existsSync(path5)) {
|
|
2503
2503
|
return;
|
|
2504
2504
|
}
|
|
2505
|
-
return rm(
|
|
2505
|
+
return rm(path5, {
|
|
2506
2506
|
recursive: true
|
|
2507
2507
|
});
|
|
2508
2508
|
}
|
|
@@ -2539,65 +2539,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
|
2539
2539
|
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
2540
2540
|
return _IS_ABSOLUTE_RE.test(p);
|
|
2541
2541
|
}, "isAbsolute");
|
|
2542
|
-
var correctPaths = /* @__PURE__ */ __name(function(
|
|
2543
|
-
if (!
|
|
2542
|
+
var correctPaths = /* @__PURE__ */ __name(function(path5) {
|
|
2543
|
+
if (!path5 || path5.length === 0) {
|
|
2544
2544
|
return ".";
|
|
2545
2545
|
}
|
|
2546
|
-
|
|
2547
|
-
const isUNCPath =
|
|
2548
|
-
const isPathAbsolute = isAbsolute(
|
|
2549
|
-
const trailingSeparator =
|
|
2550
|
-
|
|
2551
|
-
if (
|
|
2546
|
+
path5 = normalizeWindowsPath(path5);
|
|
2547
|
+
const isUNCPath = path5.match(_UNC_REGEX);
|
|
2548
|
+
const isPathAbsolute = isAbsolute(path5);
|
|
2549
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2550
|
+
path5 = normalizeString(path5, !isPathAbsolute);
|
|
2551
|
+
if (path5.length === 0) {
|
|
2552
2552
|
if (isPathAbsolute) {
|
|
2553
2553
|
return "/";
|
|
2554
2554
|
}
|
|
2555
2555
|
return trailingSeparator ? "./" : ".";
|
|
2556
2556
|
}
|
|
2557
2557
|
if (trailingSeparator) {
|
|
2558
|
-
|
|
2558
|
+
path5 += "/";
|
|
2559
2559
|
}
|
|
2560
|
-
if (_DRIVE_LETTER_RE.test(
|
|
2561
|
-
|
|
2560
|
+
if (_DRIVE_LETTER_RE.test(path5)) {
|
|
2561
|
+
path5 += "/";
|
|
2562
2562
|
}
|
|
2563
2563
|
if (isUNCPath) {
|
|
2564
2564
|
if (!isPathAbsolute) {
|
|
2565
|
-
return `//./${
|
|
2565
|
+
return `//./${path5}`;
|
|
2566
2566
|
}
|
|
2567
|
-
return `//${
|
|
2567
|
+
return `//${path5}`;
|
|
2568
2568
|
}
|
|
2569
|
-
return isPathAbsolute && !isAbsolute(
|
|
2569
|
+
return isPathAbsolute && !isAbsolute(path5) ? `/${path5}` : path5;
|
|
2570
2570
|
}, "correctPaths");
|
|
2571
2571
|
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
2572
|
-
let
|
|
2572
|
+
let path5 = "";
|
|
2573
2573
|
for (const seg of segments) {
|
|
2574
2574
|
if (!seg) {
|
|
2575
2575
|
continue;
|
|
2576
2576
|
}
|
|
2577
|
-
if (
|
|
2578
|
-
const pathTrailing =
|
|
2577
|
+
if (path5.length > 0) {
|
|
2578
|
+
const pathTrailing = path5[path5.length - 1] === "/";
|
|
2579
2579
|
const segLeading = seg[0] === "/";
|
|
2580
2580
|
const both = pathTrailing && segLeading;
|
|
2581
2581
|
if (both) {
|
|
2582
|
-
|
|
2582
|
+
path5 += seg.slice(1);
|
|
2583
2583
|
} else {
|
|
2584
|
-
|
|
2584
|
+
path5 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
2585
2585
|
}
|
|
2586
2586
|
} else {
|
|
2587
|
-
|
|
2587
|
+
path5 += seg;
|
|
2588
2588
|
}
|
|
2589
2589
|
}
|
|
2590
|
-
return correctPaths(
|
|
2590
|
+
return correctPaths(path5);
|
|
2591
2591
|
}, "joinPaths");
|
|
2592
|
-
function normalizeString(
|
|
2592
|
+
function normalizeString(path5, allowAboveRoot) {
|
|
2593
2593
|
let res = "";
|
|
2594
2594
|
let lastSegmentLength = 0;
|
|
2595
2595
|
let lastSlash = -1;
|
|
2596
2596
|
let dots = 0;
|
|
2597
2597
|
let char = null;
|
|
2598
|
-
for (let index = 0; index <=
|
|
2599
|
-
if (index <
|
|
2600
|
-
char =
|
|
2598
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2599
|
+
if (index < path5.length) {
|
|
2600
|
+
char = path5[index];
|
|
2601
2601
|
} else if (char === "/") {
|
|
2602
2602
|
break;
|
|
2603
2603
|
} else {
|
|
@@ -2633,9 +2633,9 @@ function normalizeString(path6, allowAboveRoot) {
|
|
|
2633
2633
|
}
|
|
2634
2634
|
} else {
|
|
2635
2635
|
if (res.length > 0) {
|
|
2636
|
-
res += `/${
|
|
2636
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2637
2637
|
} else {
|
|
2638
|
-
res =
|
|
2638
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2639
2639
|
}
|
|
2640
2640
|
lastSegmentLength = index - lastSlash - 1;
|
|
2641
2641
|
}
|
|
@@ -2652,20 +2652,20 @@ function normalizeString(path6, allowAboveRoot) {
|
|
|
2652
2652
|
__name(normalizeString, "normalizeString");
|
|
2653
2653
|
|
|
2654
2654
|
// ../path/src/is-file.ts
|
|
2655
|
-
function isFile(
|
|
2656
|
-
return Boolean(statSync(additionalPath ? joinPaths(additionalPath,
|
|
2655
|
+
function isFile(path5, additionalPath) {
|
|
2656
|
+
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
|
|
2657
2657
|
throwIfNoEntry: false
|
|
2658
2658
|
})?.isFile());
|
|
2659
2659
|
}
|
|
2660
2660
|
__name(isFile, "isFile");
|
|
2661
|
-
function isDirectory(
|
|
2662
|
-
return Boolean(statSync(additionalPath ? joinPaths(additionalPath,
|
|
2661
|
+
function isDirectory(path5, additionalPath) {
|
|
2662
|
+
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
|
|
2663
2663
|
throwIfNoEntry: false
|
|
2664
2664
|
})?.isDirectory());
|
|
2665
2665
|
}
|
|
2666
2666
|
__name(isDirectory, "isDirectory");
|
|
2667
|
-
function isAbsolutePath(
|
|
2668
|
-
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(
|
|
2667
|
+
function isAbsolutePath(path5) {
|
|
2668
|
+
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path5);
|
|
2669
2669
|
}
|
|
2670
2670
|
__name(isAbsolutePath, "isAbsolutePath");
|
|
2671
2671
|
|
|
@@ -2680,45 +2680,45 @@ function normalizeWindowsPath2(input = "") {
|
|
|
2680
2680
|
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
2681
2681
|
var _UNC_REGEX2 = /^[/\\]{2}/;
|
|
2682
2682
|
var _DRIVE_LETTER_RE2 = /^[A-Z]:$/i;
|
|
2683
|
-
function correctPath(
|
|
2684
|
-
if (!
|
|
2683
|
+
function correctPath(path5) {
|
|
2684
|
+
if (!path5 || path5.length === 0) {
|
|
2685
2685
|
return ".";
|
|
2686
2686
|
}
|
|
2687
|
-
|
|
2688
|
-
const isUNCPath =
|
|
2689
|
-
const isPathAbsolute = isAbsolutePath(
|
|
2690
|
-
const trailingSeparator =
|
|
2691
|
-
|
|
2692
|
-
if (
|
|
2687
|
+
path5 = normalizeWindowsPath2(path5);
|
|
2688
|
+
const isUNCPath = path5.match(_UNC_REGEX2);
|
|
2689
|
+
const isPathAbsolute = isAbsolutePath(path5);
|
|
2690
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2691
|
+
path5 = normalizeString2(path5, !isPathAbsolute);
|
|
2692
|
+
if (path5.length === 0) {
|
|
2693
2693
|
if (isPathAbsolute) {
|
|
2694
2694
|
return "/";
|
|
2695
2695
|
}
|
|
2696
2696
|
return trailingSeparator ? "./" : ".";
|
|
2697
2697
|
}
|
|
2698
2698
|
if (trailingSeparator) {
|
|
2699
|
-
|
|
2699
|
+
path5 += "/";
|
|
2700
2700
|
}
|
|
2701
|
-
if (_DRIVE_LETTER_RE2.test(
|
|
2702
|
-
|
|
2701
|
+
if (_DRIVE_LETTER_RE2.test(path5)) {
|
|
2702
|
+
path5 += "/";
|
|
2703
2703
|
}
|
|
2704
2704
|
if (isUNCPath) {
|
|
2705
2705
|
if (!isPathAbsolute) {
|
|
2706
|
-
return `//./${
|
|
2706
|
+
return `//./${path5}`;
|
|
2707
2707
|
}
|
|
2708
|
-
return `//${
|
|
2708
|
+
return `//${path5}`;
|
|
2709
2709
|
}
|
|
2710
|
-
return isPathAbsolute && !isAbsolutePath(
|
|
2710
|
+
return isPathAbsolute && !isAbsolutePath(path5) ? `/${path5}` : path5;
|
|
2711
2711
|
}
|
|
2712
2712
|
__name(correctPath, "correctPath");
|
|
2713
|
-
function normalizeString2(
|
|
2713
|
+
function normalizeString2(path5, allowAboveRoot) {
|
|
2714
2714
|
let res = "";
|
|
2715
2715
|
let lastSegmentLength = 0;
|
|
2716
2716
|
let lastSlash = -1;
|
|
2717
2717
|
let dots = 0;
|
|
2718
2718
|
let char = null;
|
|
2719
|
-
for (let index = 0; index <=
|
|
2720
|
-
if (index <
|
|
2721
|
-
char =
|
|
2719
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2720
|
+
if (index < path5.length) {
|
|
2721
|
+
char = path5[index];
|
|
2722
2722
|
} else if (char === "/") {
|
|
2723
2723
|
break;
|
|
2724
2724
|
} else {
|
|
@@ -2754,9 +2754,9 @@ function normalizeString2(path6, allowAboveRoot) {
|
|
|
2754
2754
|
}
|
|
2755
2755
|
} else {
|
|
2756
2756
|
if (res.length > 0) {
|
|
2757
|
-
res += `/${
|
|
2757
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2758
2758
|
} else {
|
|
2759
|
-
res =
|
|
2759
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2760
2760
|
}
|
|
2761
2761
|
lastSegmentLength = index - lastSlash - 1;
|
|
2762
2762
|
}
|
|
@@ -2828,34 +2828,34 @@ __name2(normalizeWindowsPath3, "normalizeWindowsPath");
|
|
|
2828
2828
|
var _UNC_REGEX3 = /^[/\\]{2}/;
|
|
2829
2829
|
var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
2830
2830
|
var _DRIVE_LETTER_RE3 = /^[A-Za-z]:$/;
|
|
2831
|
-
var correctPaths2 = /* @__PURE__ */ __name2(function(
|
|
2832
|
-
if (!
|
|
2831
|
+
var correctPaths2 = /* @__PURE__ */ __name2(function(path5) {
|
|
2832
|
+
if (!path5 || path5.length === 0) {
|
|
2833
2833
|
return ".";
|
|
2834
2834
|
}
|
|
2835
|
-
|
|
2836
|
-
const isUNCPath =
|
|
2837
|
-
const isPathAbsolute = isAbsolute2(
|
|
2838
|
-
const trailingSeparator =
|
|
2839
|
-
|
|
2840
|
-
if (
|
|
2835
|
+
path5 = normalizeWindowsPath3(path5);
|
|
2836
|
+
const isUNCPath = path5.match(_UNC_REGEX3);
|
|
2837
|
+
const isPathAbsolute = isAbsolute2(path5);
|
|
2838
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2839
|
+
path5 = normalizeString3(path5, !isPathAbsolute);
|
|
2840
|
+
if (path5.length === 0) {
|
|
2841
2841
|
if (isPathAbsolute) {
|
|
2842
2842
|
return "/";
|
|
2843
2843
|
}
|
|
2844
2844
|
return trailingSeparator ? "./" : ".";
|
|
2845
2845
|
}
|
|
2846
2846
|
if (trailingSeparator) {
|
|
2847
|
-
|
|
2847
|
+
path5 += "/";
|
|
2848
2848
|
}
|
|
2849
|
-
if (_DRIVE_LETTER_RE3.test(
|
|
2850
|
-
|
|
2849
|
+
if (_DRIVE_LETTER_RE3.test(path5)) {
|
|
2850
|
+
path5 += "/";
|
|
2851
2851
|
}
|
|
2852
2852
|
if (isUNCPath) {
|
|
2853
2853
|
if (!isPathAbsolute) {
|
|
2854
|
-
return `//./${
|
|
2854
|
+
return `//./${path5}`;
|
|
2855
2855
|
}
|
|
2856
|
-
return `//${
|
|
2856
|
+
return `//${path5}`;
|
|
2857
2857
|
}
|
|
2858
|
-
return isPathAbsolute && !isAbsolute2(
|
|
2858
|
+
return isPathAbsolute && !isAbsolute2(path5) ? `/${path5}` : path5;
|
|
2859
2859
|
}, "correctPaths");
|
|
2860
2860
|
function cwd() {
|
|
2861
2861
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
@@ -2865,15 +2865,15 @@ function cwd() {
|
|
|
2865
2865
|
}
|
|
2866
2866
|
__name(cwd, "cwd");
|
|
2867
2867
|
__name2(cwd, "cwd");
|
|
2868
|
-
function normalizeString3(
|
|
2868
|
+
function normalizeString3(path5, allowAboveRoot) {
|
|
2869
2869
|
let res = "";
|
|
2870
2870
|
let lastSegmentLength = 0;
|
|
2871
2871
|
let lastSlash = -1;
|
|
2872
2872
|
let dots = 0;
|
|
2873
2873
|
let char = null;
|
|
2874
|
-
for (let index = 0; index <=
|
|
2875
|
-
if (index <
|
|
2876
|
-
char =
|
|
2874
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2875
|
+
if (index < path5.length) {
|
|
2876
|
+
char = path5[index];
|
|
2877
2877
|
} else if (char === "/") {
|
|
2878
2878
|
break;
|
|
2879
2879
|
} else {
|
|
@@ -2909,9 +2909,9 @@ function normalizeString3(path6, allowAboveRoot) {
|
|
|
2909
2909
|
}
|
|
2910
2910
|
} else {
|
|
2911
2911
|
if (res.length > 0) {
|
|
2912
|
-
res += `/${
|
|
2912
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2913
2913
|
} else {
|
|
2914
|
-
res =
|
|
2914
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2915
2915
|
}
|
|
2916
2916
|
lastSegmentLength = index - lastSlash - 1;
|
|
2917
2917
|
}
|
|
@@ -3356,8 +3356,8 @@ function getErrorMap() {
|
|
|
3356
3356
|
}
|
|
3357
3357
|
__name(getErrorMap, "getErrorMap");
|
|
3358
3358
|
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
3359
|
-
const { data, path:
|
|
3360
|
-
const fullPath = [...
|
|
3359
|
+
const { data, path: path5, errorMaps, issueData } = params;
|
|
3360
|
+
const fullPath = [...path5, ...issueData.path || []];
|
|
3361
3361
|
const fullIssue = {
|
|
3362
3362
|
...issueData,
|
|
3363
3363
|
path: fullPath
|
|
@@ -3491,11 +3491,11 @@ var ParseInputLazyPath = class {
|
|
|
3491
3491
|
static {
|
|
3492
3492
|
__name(this, "ParseInputLazyPath");
|
|
3493
3493
|
}
|
|
3494
|
-
constructor(parent, value,
|
|
3494
|
+
constructor(parent, value, path5, key) {
|
|
3495
3495
|
this._cachedPath = [];
|
|
3496
3496
|
this.parent = parent;
|
|
3497
3497
|
this.data = value;
|
|
3498
|
-
this._path =
|
|
3498
|
+
this._path = path5;
|
|
3499
3499
|
this._key = key;
|
|
3500
3500
|
}
|
|
3501
3501
|
get path() {
|
|
@@ -7202,8 +7202,8 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
7202
7202
|
|
|
7203
7203
|
// ../path/src/get-parent-path.ts
|
|
7204
7204
|
init_esm_shims();
|
|
7205
|
-
var resolveParentPath = /* @__PURE__ */ __name((
|
|
7206
|
-
return resolvePaths(
|
|
7205
|
+
var resolveParentPath = /* @__PURE__ */ __name((path5) => {
|
|
7206
|
+
return resolvePaths(path5, "..");
|
|
7207
7207
|
}, "resolveParentPath");
|
|
7208
7208
|
var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
|
|
7209
7209
|
const ignoreCase = options?.ignoreCase ?? true;
|
|
@@ -7308,25 +7308,17 @@ function findFilePath(filePath) {
|
|
|
7308
7308
|
}), "");
|
|
7309
7309
|
}
|
|
7310
7310
|
__name(findFilePath, "findFilePath");
|
|
7311
|
-
function
|
|
7312
|
-
|
|
7313
|
-
return "";
|
|
7314
|
-
}
|
|
7315
|
-
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7316
|
-
return match && match[1] || EMPTY_STRING;
|
|
7317
|
-
}
|
|
7318
|
-
__name(findFileExtension, "findFileExtension");
|
|
7319
|
-
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7320
|
-
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7311
|
+
function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
|
|
7312
|
+
const paths = normalizeWindowsPath2(path5).split("/");
|
|
7321
7313
|
let resolvedPath = "";
|
|
7322
7314
|
let resolvedAbsolute = false;
|
|
7323
7315
|
for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
7324
|
-
const
|
|
7325
|
-
if (!
|
|
7316
|
+
const path6 = index >= 0 ? paths[index] : cwd2;
|
|
7317
|
+
if (!path6 || path6.length === 0) {
|
|
7326
7318
|
continue;
|
|
7327
7319
|
}
|
|
7328
|
-
resolvedPath = joinPaths(
|
|
7329
|
-
resolvedAbsolute = isAbsolutePath(
|
|
7320
|
+
resolvedPath = joinPaths(path6, resolvedPath);
|
|
7321
|
+
resolvedAbsolute = isAbsolutePath(path6);
|
|
7330
7322
|
}
|
|
7331
7323
|
resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute);
|
|
7332
7324
|
if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
|
|
@@ -7336,7 +7328,7 @@ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
|
7336
7328
|
}
|
|
7337
7329
|
__name(resolvePath, "resolvePath");
|
|
7338
7330
|
function resolvePaths(...paths) {
|
|
7339
|
-
return resolvePath(joinPaths(...paths.map((
|
|
7331
|
+
return resolvePath(joinPaths(...paths.map((path5) => normalizeWindowsPath2(path5))));
|
|
7340
7332
|
}
|
|
7341
7333
|
__name(resolvePaths, "resolvePaths");
|
|
7342
7334
|
function relativePath(from, to) {
|
|
@@ -7370,7 +7362,7 @@ var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
|
7370
7362
|
|
|
7371
7363
|
// src/prisma-generator.ts
|
|
7372
7364
|
var import_pluralize = __toESM(require_pluralize(), 1);
|
|
7373
|
-
import
|
|
7365
|
+
import path4 from "node:path";
|
|
7374
7366
|
|
|
7375
7367
|
// src/config.ts
|
|
7376
7368
|
init_esm_shims();
|
|
@@ -7403,7 +7395,7 @@ var configSchema = z.object({
|
|
|
7403
7395
|
withShield: z.coerce.boolean().or(z.string()).default(true),
|
|
7404
7396
|
withZod: z.coerce.boolean().or(z.string()).default(true),
|
|
7405
7397
|
withNext: z.coerce.boolean().or(z.string()).default(true),
|
|
7406
|
-
contextPath: z.string().default("../src/trpc/context"),
|
|
7398
|
+
contextPath: z.string().default("../src/trpc/context.ts"),
|
|
7407
7399
|
trpcOptions: z.coerce.boolean().or(z.string()).default(true),
|
|
7408
7400
|
showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
|
|
7409
7401
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
@@ -7607,17 +7599,12 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
|
|
|
7607
7599
|
|
|
7608
7600
|
// src/utils/get-relative-path.ts
|
|
7609
7601
|
init_esm_shims();
|
|
7610
|
-
import path2 from "node:path";
|
|
7611
7602
|
function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
|
|
7618
|
-
}
|
|
7619
|
-
const newPath = relativePath(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
|
|
7620
|
-
return newPath;
|
|
7603
|
+
let toPath = joinPaths(outputPath, filePath.endsWith(".ts") ? findFilePath(filePath) : filePath);
|
|
7604
|
+
if (isOutsideOutputPath && schemaPath) {
|
|
7605
|
+
toPath = joinPaths(schemaPath.endsWith(".prisma") ? findFilePath(schemaPath) : schemaPath, filePath);
|
|
7606
|
+
}
|
|
7607
|
+
return relativePath(fromPath || outputPath, toPath);
|
|
7621
7608
|
}
|
|
7622
7609
|
__name(getRelativePath, "getRelativePath");
|
|
7623
7610
|
|
|
@@ -7931,7 +7918,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7931
7918
|
if (type === "trpc") {
|
|
7932
7919
|
statement = "import * as trpc from '@trpc/server';\n";
|
|
7933
7920
|
} else if (type === "trpc-shield") {
|
|
7934
|
-
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7921
|
+
statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
|
|
7935
7922
|
} else if (type === "context") {
|
|
7936
7923
|
statement = `import type { Context } from '${newPath}';
|
|
7937
7924
|
`;
|
|
@@ -7995,6 +7982,53 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7995
7982
|
});
|
|
7996
7983
|
return shieldText;
|
|
7997
7984
|
}, "constructShield");
|
|
7985
|
+
var constructDefaultOptions = /* @__PURE__ */ __name((config, options, outputDir) => {
|
|
7986
|
+
return `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
7987
|
+
import type {
|
|
7988
|
+
DataTransformerOptions,
|
|
7989
|
+
RootConfig
|
|
7990
|
+
} from "@trpc/server/unstable-core-do-not-import";
|
|
7991
|
+
import type { Context } from "${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}";
|
|
7992
|
+
|
|
7993
|
+
interface RuntimeConfigOptions<
|
|
7994
|
+
TContext extends object,
|
|
7995
|
+
TMeta extends object = object
|
|
7996
|
+
> extends Partial<
|
|
7997
|
+
Omit<
|
|
7998
|
+
RootConfig<{
|
|
7999
|
+
ctx: TContext;
|
|
8000
|
+
meta: TMeta;
|
|
8001
|
+
errorShape: any;
|
|
8002
|
+
transformer: any;
|
|
8003
|
+
}>,
|
|
8004
|
+
"$types" | "transformer"
|
|
8005
|
+
>
|
|
8006
|
+
> {
|
|
8007
|
+
/**
|
|
8008
|
+
* Use a data transformer
|
|
8009
|
+
* @see https://trpc.io/docs/v11/data-transformers
|
|
8010
|
+
*/
|
|
8011
|
+
transformer?: DataTransformerOptions;
|
|
8012
|
+
}
|
|
8013
|
+
|
|
8014
|
+
const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
|
|
8015
|
+
errorFormatter({ shape, error }) {
|
|
8016
|
+
return {
|
|
8017
|
+
...shape,
|
|
8018
|
+
data: {
|
|
8019
|
+
...shape.data,
|
|
8020
|
+
zodError:
|
|
8021
|
+
error.code === "BAD_REQUEST" && error.cause instanceof ZodError
|
|
8022
|
+
? error.cause.flatten()
|
|
8023
|
+
: null
|
|
8024
|
+
}
|
|
8025
|
+
};
|
|
8026
|
+
}
|
|
8027
|
+
};
|
|
8028
|
+
|
|
8029
|
+
export default options;
|
|
8030
|
+
`;
|
|
8031
|
+
}, "constructDefaultOptions");
|
|
7998
8032
|
|
|
7999
8033
|
// src/project.ts
|
|
8000
8034
|
init_esm_shims();
|
|
@@ -9200,7 +9234,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
|
|
|
9200
9234
|
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
|
9201
9235
|
init_esm_shims();
|
|
9202
9236
|
var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
|
|
9203
|
-
var stringifyPath = /* @__PURE__ */ __name((
|
|
9237
|
+
var stringifyPath = /* @__PURE__ */ __name((path5) => path5.map(String).map(escapeKey).join("."), "stringifyPath");
|
|
9204
9238
|
var parsePath = /* @__PURE__ */ __name((string) => {
|
|
9205
9239
|
const result = [];
|
|
9206
9240
|
let segment = "";
|
|
@@ -9463,27 +9497,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
|
|
|
9463
9497
|
}
|
|
9464
9498
|
return keys.next().value;
|
|
9465
9499
|
}, "getNthKey");
|
|
9466
|
-
function validatePath(
|
|
9467
|
-
if (includes(
|
|
9500
|
+
function validatePath(path5) {
|
|
9501
|
+
if (includes(path5, "__proto__")) {
|
|
9468
9502
|
throw new Error("__proto__ is not allowed as a property");
|
|
9469
9503
|
}
|
|
9470
|
-
if (includes(
|
|
9504
|
+
if (includes(path5, "prototype")) {
|
|
9471
9505
|
throw new Error("prototype is not allowed as a property");
|
|
9472
9506
|
}
|
|
9473
|
-
if (includes(
|
|
9507
|
+
if (includes(path5, "constructor")) {
|
|
9474
9508
|
throw new Error("constructor is not allowed as a property");
|
|
9475
9509
|
}
|
|
9476
9510
|
}
|
|
9477
9511
|
__name(validatePath, "validatePath");
|
|
9478
|
-
var getDeep = /* @__PURE__ */ __name((object,
|
|
9479
|
-
validatePath(
|
|
9480
|
-
for (let i = 0; i <
|
|
9481
|
-
const key =
|
|
9512
|
+
var getDeep = /* @__PURE__ */ __name((object, path5) => {
|
|
9513
|
+
validatePath(path5);
|
|
9514
|
+
for (let i = 0; i < path5.length; i++) {
|
|
9515
|
+
const key = path5[i];
|
|
9482
9516
|
if (isSet(object)) {
|
|
9483
9517
|
object = getNthKey(object, +key);
|
|
9484
9518
|
} else if (isMap(object)) {
|
|
9485
9519
|
const row = +key;
|
|
9486
|
-
const type = +
|
|
9520
|
+
const type = +path5[++i] === 0 ? "key" : "value";
|
|
9487
9521
|
const keyOfRow = getNthKey(object, row);
|
|
9488
9522
|
switch (type) {
|
|
9489
9523
|
case "key":
|
|
@@ -9499,14 +9533,14 @@ var getDeep = /* @__PURE__ */ __name((object, path6) => {
|
|
|
9499
9533
|
}
|
|
9500
9534
|
return object;
|
|
9501
9535
|
}, "getDeep");
|
|
9502
|
-
var setDeep = /* @__PURE__ */ __name((object,
|
|
9503
|
-
validatePath(
|
|
9504
|
-
if (
|
|
9536
|
+
var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
9537
|
+
validatePath(path5);
|
|
9538
|
+
if (path5.length === 0) {
|
|
9505
9539
|
return mapper(object);
|
|
9506
9540
|
}
|
|
9507
9541
|
let parent = object;
|
|
9508
|
-
for (let i = 0; i <
|
|
9509
|
-
const key =
|
|
9542
|
+
for (let i = 0; i < path5.length - 1; i++) {
|
|
9543
|
+
const key = path5[i];
|
|
9510
9544
|
if (isArray(parent)) {
|
|
9511
9545
|
const index = +key;
|
|
9512
9546
|
parent = parent[index];
|
|
@@ -9516,12 +9550,12 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9516
9550
|
const row = +key;
|
|
9517
9551
|
parent = getNthKey(parent, row);
|
|
9518
9552
|
} else if (isMap(parent)) {
|
|
9519
|
-
const isEnd = i ===
|
|
9553
|
+
const isEnd = i === path5.length - 2;
|
|
9520
9554
|
if (isEnd) {
|
|
9521
9555
|
break;
|
|
9522
9556
|
}
|
|
9523
9557
|
const row = +key;
|
|
9524
|
-
const type = +
|
|
9558
|
+
const type = +path5[++i] === 0 ? "key" : "value";
|
|
9525
9559
|
const keyOfRow = getNthKey(parent, row);
|
|
9526
9560
|
switch (type) {
|
|
9527
9561
|
case "key":
|
|
@@ -9533,7 +9567,7 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9533
9567
|
}
|
|
9534
9568
|
}
|
|
9535
9569
|
}
|
|
9536
|
-
const lastKey =
|
|
9570
|
+
const lastKey = path5[path5.length - 1];
|
|
9537
9571
|
if (isArray(parent)) {
|
|
9538
9572
|
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
9539
9573
|
} else if (isPlainObject2(parent)) {
|
|
@@ -9548,7 +9582,7 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9548
9582
|
}
|
|
9549
9583
|
}
|
|
9550
9584
|
if (isMap(parent)) {
|
|
9551
|
-
const row = +
|
|
9585
|
+
const row = +path5[path5.length - 2];
|
|
9552
9586
|
const keyToRow = getNthKey(parent, row);
|
|
9553
9587
|
const type = +lastKey === 0 ? "key" : "value";
|
|
9554
9588
|
switch (type) {
|
|
@@ -9594,15 +9628,15 @@ function traverse(tree, walker2, origin = []) {
|
|
|
9594
9628
|
}
|
|
9595
9629
|
__name(traverse, "traverse");
|
|
9596
9630
|
function applyValueAnnotations(plain, annotations, superJson) {
|
|
9597
|
-
traverse(annotations, (type,
|
|
9598
|
-
plain = setDeep(plain,
|
|
9631
|
+
traverse(annotations, (type, path5) => {
|
|
9632
|
+
plain = setDeep(plain, path5, (v) => untransformValue(v, type, superJson));
|
|
9599
9633
|
});
|
|
9600
9634
|
return plain;
|
|
9601
9635
|
}
|
|
9602
9636
|
__name(applyValueAnnotations, "applyValueAnnotations");
|
|
9603
9637
|
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
9604
|
-
function apply(identicalPaths,
|
|
9605
|
-
const object = getDeep(plain, parsePath(
|
|
9638
|
+
function apply(identicalPaths, path5) {
|
|
9639
|
+
const object = getDeep(plain, parsePath(path5));
|
|
9606
9640
|
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
9607
9641
|
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
9608
9642
|
});
|
|
@@ -9623,13 +9657,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
|
9623
9657
|
}
|
|
9624
9658
|
__name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
|
|
9625
9659
|
var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
|
|
9626
|
-
function addIdentity(object,
|
|
9660
|
+
function addIdentity(object, path5, identities) {
|
|
9627
9661
|
const existingSet = identities.get(object);
|
|
9628
9662
|
if (existingSet) {
|
|
9629
|
-
existingSet.push(
|
|
9663
|
+
existingSet.push(path5);
|
|
9630
9664
|
} else {
|
|
9631
9665
|
identities.set(object, [
|
|
9632
|
-
|
|
9666
|
+
path5
|
|
9633
9667
|
]);
|
|
9634
9668
|
}
|
|
9635
9669
|
}
|
|
@@ -9642,7 +9676,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9642
9676
|
return;
|
|
9643
9677
|
}
|
|
9644
9678
|
if (!dedupe) {
|
|
9645
|
-
paths = paths.map((
|
|
9679
|
+
paths = paths.map((path5) => path5.map(String)).sort((a, b) => a.length - b.length);
|
|
9646
9680
|
}
|
|
9647
9681
|
const [representativePath, ...identicalPaths] = paths;
|
|
9648
9682
|
if (representativePath.length === 0) {
|
|
@@ -9667,10 +9701,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9667
9701
|
}
|
|
9668
9702
|
}
|
|
9669
9703
|
__name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
|
|
9670
|
-
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe,
|
|
9704
|
+
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path5 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
9671
9705
|
const primitive = isPrimitive(object);
|
|
9672
9706
|
if (!primitive) {
|
|
9673
|
-
addIdentity(object,
|
|
9707
|
+
addIdentity(object, path5, identities);
|
|
9674
9708
|
const seen = seenObjects.get(object);
|
|
9675
9709
|
if (seen) {
|
|
9676
9710
|
return dedupe ? {
|
|
@@ -9707,7 +9741,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
|
|
|
9707
9741
|
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
9708
9742
|
}
|
|
9709
9743
|
const recursiveResult = walker(value, identities, superJson, dedupe, [
|
|
9710
|
-
...
|
|
9744
|
+
...path5,
|
|
9711
9745
|
index
|
|
9712
9746
|
], [
|
|
9713
9747
|
...objectsInThisPath,
|
|
@@ -10287,7 +10321,7 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
|
|
|
10287
10321
|
}, "writeFile");
|
|
10288
10322
|
|
|
10289
10323
|
// src/utils/write-file-safely.ts
|
|
10290
|
-
import
|
|
10324
|
+
import path2 from "node:path";
|
|
10291
10325
|
|
|
10292
10326
|
// src/utils/format-file.ts
|
|
10293
10327
|
init_esm_shims();
|
|
@@ -10331,7 +10365,7 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10331
10365
|
}, "writeFileSafely");
|
|
10332
10366
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10333
10367
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10334
|
-
let relativePath2 =
|
|
10368
|
+
let relativePath2 = path2.relative(path2.dirname(indexPath), filePath);
|
|
10335
10369
|
if (relativePath2.endsWith(".ts")) {
|
|
10336
10370
|
relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
|
|
10337
10371
|
}
|
|
@@ -10508,7 +10542,7 @@ init_esm_shims();
|
|
|
10508
10542
|
|
|
10509
10543
|
// src/zod-helpers/transformer.ts
|
|
10510
10544
|
init_esm_shims();
|
|
10511
|
-
import
|
|
10545
|
+
import path3 from "node:path";
|
|
10512
10546
|
|
|
10513
10547
|
// src/zod-helpers/model-helpers.ts
|
|
10514
10548
|
init_esm_shims();
|
|
@@ -10656,13 +10690,13 @@ var Transformer = class _Transformer {
|
|
|
10656
10690
|
this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
|
|
10657
10691
|
}
|
|
10658
10692
|
static async generateIndex() {
|
|
10659
|
-
const indexPath =
|
|
10693
|
+
const indexPath = path3.join(_Transformer.outputPath, "schemas/index.ts");
|
|
10660
10694
|
await writeIndexFile(indexPath);
|
|
10661
10695
|
}
|
|
10662
10696
|
async generateEnumSchemas() {
|
|
10663
10697
|
for (const enumType2 of this.enumTypes) {
|
|
10664
10698
|
const { name, values } = enumType2;
|
|
10665
|
-
await writeFileSafely(
|
|
10699
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10666
10700
|
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10667
10701
|
}
|
|
10668
10702
|
}
|
|
@@ -10676,7 +10710,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10676
10710
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10677
10711
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10678
10712
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10679
|
-
await writeFileSafely(
|
|
10713
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10680
10714
|
}
|
|
10681
10715
|
generateObjectSchemaFields() {
|
|
10682
10716
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10815,9 +10849,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10815
10849
|
generateImportPrismaStatement() {
|
|
10816
10850
|
let prismaClientImportPath;
|
|
10817
10851
|
if (_Transformer.isCustomPrismaClientOutputPath) {
|
|
10818
|
-
const fromPath =
|
|
10852
|
+
const fromPath = path3.join(_Transformer.outputPath, "schemas", "objects");
|
|
10819
10853
|
const toPath = _Transformer.prismaClientOutputPath;
|
|
10820
|
-
const relativePathFromOutputToPrismaClient =
|
|
10854
|
+
const relativePathFromOutputToPrismaClient = path3.relative(fromPath, toPath).split(path3.sep).join(path3.posix.sep);
|
|
10821
10855
|
prismaClientImportPath = relativePathFromOutputToPrismaClient;
|
|
10822
10856
|
} else {
|
|
10823
10857
|
prismaClientImportPath = _Transformer.prismaClientOutputPath;
|
|
@@ -10947,7 +10981,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10947
10981
|
includeImport,
|
|
10948
10982
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10949
10983
|
];
|
|
10950
|
-
await writeFileSafely(
|
|
10984
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10951
10985
|
}
|
|
10952
10986
|
if (findFirst) {
|
|
10953
10987
|
const imports = [
|
|
@@ -10958,7 +10992,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10958
10992
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10959
10993
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10960
10994
|
];
|
|
10961
|
-
await writeFileSafely(
|
|
10995
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findFirst}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindFirst`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
|
|
10962
10996
|
}
|
|
10963
10997
|
if (findMany) {
|
|
10964
10998
|
const imports = [
|
|
@@ -10969,7 +11003,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10969
11003
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10970
11004
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10971
11005
|
];
|
|
10972
|
-
await writeFileSafely(
|
|
11006
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindMany`, `z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
|
|
10973
11007
|
}
|
|
10974
11008
|
if (createOne) {
|
|
10975
11009
|
const imports = [
|
|
@@ -10978,19 +11012,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10978
11012
|
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
10979
11013
|
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
|
|
10980
11014
|
];
|
|
10981
|
-
await writeFileSafely(
|
|
11015
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema]) })`)}`);
|
|
10982
11016
|
}
|
|
10983
11017
|
if (createMany) {
|
|
10984
11018
|
const imports = [
|
|
10985
11019
|
`import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
|
|
10986
11020
|
];
|
|
10987
|
-
await writeFileSafely(
|
|
11021
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateMany`, `z.object({ data: z.union([ ${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
10988
11022
|
}
|
|
10989
11023
|
if (createManyAndReturn) {
|
|
10990
11024
|
const imports = [
|
|
10991
11025
|
`import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`
|
|
10992
11026
|
];
|
|
10993
|
-
await writeFileSafely(
|
|
11027
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${createManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateManyAndReturn`, `z.object({ data: z.union([ ${modelName}CreateManyAndReturnInputObjectSchema, z.array(${modelName}CreateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
10994
11028
|
}
|
|
10995
11029
|
if (deleteOne) {
|
|
10996
11030
|
const imports = [
|
|
@@ -10998,13 +11032,13 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10998
11032
|
includeImport,
|
|
10999
11033
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
11000
11034
|
];
|
|
11001
|
-
await writeFileSafely(
|
|
11035
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
11002
11036
|
}
|
|
11003
11037
|
if (deleteMany) {
|
|
11004
11038
|
const imports = [
|
|
11005
11039
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11006
11040
|
];
|
|
11007
|
-
await writeFileSafely(
|
|
11041
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
11008
11042
|
}
|
|
11009
11043
|
if (updateOne) {
|
|
11010
11044
|
const imports = [
|
|
@@ -11014,20 +11048,20 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11014
11048
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
|
|
11015
11049
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
11016
11050
|
];
|
|
11017
|
-
await writeFileSafely(
|
|
11051
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema]), where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
11018
11052
|
}
|
|
11019
11053
|
if (updateMany) {
|
|
11020
11054
|
const imports = [
|
|
11021
11055
|
`import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
|
|
11022
11056
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11023
11057
|
];
|
|
11024
|
-
await writeFileSafely(
|
|
11058
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
11025
11059
|
}
|
|
11026
11060
|
if (updateManyAndReturn) {
|
|
11027
11061
|
const imports = [
|
|
11028
11062
|
`import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`
|
|
11029
11063
|
];
|
|
11030
|
-
await writeFileSafely(
|
|
11064
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${updateManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateManyAndReturn`, `z.object({ data: z.union([ ${modelName}UpdateManyAndReturnInputObjectSchema, z.array(${modelName}UpdateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
11031
11065
|
}
|
|
11032
11066
|
if (upsertOne) {
|
|
11033
11067
|
const imports = [
|
|
@@ -11039,7 +11073,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11039
11073
|
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
11040
11074
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
|
|
11041
11075
|
];
|
|
11042
|
-
await writeFileSafely(
|
|
11076
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${upsertOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Upsert`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema, create: z.union([ ${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema ]), update: z.union([ ${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema ]) })`)}`);
|
|
11043
11077
|
}
|
|
11044
11078
|
if (aggregate) {
|
|
11045
11079
|
const imports = [
|
|
@@ -11070,7 +11104,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11070
11104
|
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
11071
11105
|
}
|
|
11072
11106
|
}
|
|
11073
|
-
await writeFileSafely(
|
|
11107
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${aggregate}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Aggregate`, `z.object({ ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${aggregateOperations.join(", ")} })`)}`);
|
|
11074
11108
|
}
|
|
11075
11109
|
if (groupBy) {
|
|
11076
11110
|
const imports = [
|
|
@@ -11079,7 +11113,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11079
11113
|
`import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
|
|
11080
11114
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
11081
11115
|
];
|
|
11082
|
-
await writeFileSafely(
|
|
11116
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${groupBy}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}GroupBy`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${modelName}OrderByWithAggregationInputObjectSchema, ${modelName}OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${modelName}ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${modelName}ScalarFieldEnumSchema) })`)}`);
|
|
11083
11117
|
}
|
|
11084
11118
|
}
|
|
11085
11119
|
}
|
|
@@ -11618,18 +11652,18 @@ async function generate(options) {
|
|
|
11618
11652
|
subscriptions.sort();
|
|
11619
11653
|
if (config.withShield !== false) {
|
|
11620
11654
|
consoleLog("Generating tRPC Shield");
|
|
11621
|
-
if (typeof config.withShield === "string" && (existsSync(config.withShield) || existsSync(joinPaths(config.withShield, "shield.ts")))) {
|
|
11655
|
+
if (typeof config.withShield === "string" && (existsSync(joinPaths(findFilePath(options.schemaPath), config.withShield)) || existsSync(joinPaths(findFilePath(options.schemaPath), config.withShield, "shield.ts")))) {
|
|
11622
11656
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11623
11657
|
} else {
|
|
11624
11658
|
consoleLog("Constructing tRPC Shield source file");
|
|
11625
|
-
const shieldOutputDir = typeof config.withShield === "string" ?
|
|
11659
|
+
const shieldOutputDir = typeof config.withShield === "string" ? config.withShield : outputDir;
|
|
11626
11660
|
const shieldText = await constructShield({
|
|
11627
11661
|
queries,
|
|
11628
11662
|
mutations,
|
|
11629
11663
|
subscriptions
|
|
11630
11664
|
}, config, options, shieldOutputDir);
|
|
11631
11665
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11632
|
-
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11666
|
+
await writeFileSafely(shieldOutputDir.endsWith(".ts") ? shieldOutputDir : joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11633
11667
|
}
|
|
11634
11668
|
} else {
|
|
11635
11669
|
consoleLog("Skipping tRPC Shield generation");
|
|
@@ -11638,26 +11672,10 @@ async function generate(options) {
|
|
|
11638
11672
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11639
11673
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11640
11674
|
consoleLog("Generating tRPC options source file");
|
|
11641
|
-
await writeFileSafely(trpcOptionsOutputPath,
|
|
11642
|
-
|
|
11643
|
-
export default {${config.withNext ? "\n transformer," : ""}
|
|
11644
|
-
errorFormatter({ shape, error }) {
|
|
11645
|
-
return {
|
|
11646
|
-
...shape,
|
|
11647
|
-
data: {
|
|
11648
|
-
...shape.data,
|
|
11649
|
-
zodError:
|
|
11650
|
-
error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
|
|
11651
|
-
? error.cause.flatten()
|
|
11652
|
-
: null,
|
|
11653
|
-
},
|
|
11654
|
-
};
|
|
11655
|
-
},
|
|
11656
|
-
};
|
|
11657
|
-
`);
|
|
11675
|
+
await writeFileSafely(trpcOptionsOutputPath, constructDefaultOptions(config, options, trpcOptionsOutputPath));
|
|
11658
11676
|
}
|
|
11659
11677
|
resolveModelsComments(models, hiddenModels);
|
|
11660
|
-
const trpcExports = project.createSourceFile(
|
|
11678
|
+
const trpcExports = project.createSourceFile(path4.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11661
11679
|
overwrite: true
|
|
11662
11680
|
});
|
|
11663
11681
|
consoleLog("Generating tRPC imports");
|
|
@@ -11669,7 +11687,7 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11669
11687
|
trpcExports.formatText({
|
|
11670
11688
|
indentSize: 2
|
|
11671
11689
|
});
|
|
11672
|
-
const appRouter = project.createSourceFile(
|
|
11690
|
+
const appRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
11673
11691
|
overwrite: true
|
|
11674
11692
|
});
|
|
11675
11693
|
consoleLog("Generating tRPC router imports");
|
|
@@ -11698,7 +11716,7 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11698
11716
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11699
11717
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11700
11718
|
generateRouterImport(appRouter, plural, model);
|
|
11701
|
-
const modelRouter = project.createSourceFile(
|
|
11719
|
+
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11702
11720
|
overwrite: true
|
|
11703
11721
|
});
|
|
11704
11722
|
generateCreateRouterImport({
|