@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/index.js
CHANGED
|
@@ -2485,20 +2485,20 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
|
|
|
2485
2485
|
|
|
2486
2486
|
// ../fs/src/helpers.ts
|
|
2487
2487
|
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
2488
|
-
async function createDirectory(
|
|
2489
|
-
if (await exists(
|
|
2488
|
+
async function createDirectory(path5) {
|
|
2489
|
+
if (await exists(path5)) {
|
|
2490
2490
|
return;
|
|
2491
2491
|
}
|
|
2492
|
-
return mkdir(
|
|
2492
|
+
return mkdir(path5, {
|
|
2493
2493
|
recursive: true
|
|
2494
2494
|
});
|
|
2495
2495
|
}
|
|
2496
2496
|
__name(createDirectory, "createDirectory");
|
|
2497
|
-
async function removeDirectory(
|
|
2498
|
-
if (!existsSync(
|
|
2497
|
+
async function removeDirectory(path5) {
|
|
2498
|
+
if (!existsSync(path5)) {
|
|
2499
2499
|
return;
|
|
2500
2500
|
}
|
|
2501
|
-
return rm(
|
|
2501
|
+
return rm(path5, {
|
|
2502
2502
|
recursive: true
|
|
2503
2503
|
});
|
|
2504
2504
|
}
|
|
@@ -2535,65 +2535,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
|
2535
2535
|
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
2536
2536
|
return _IS_ABSOLUTE_RE.test(p);
|
|
2537
2537
|
}, "isAbsolute");
|
|
2538
|
-
var correctPaths = /* @__PURE__ */ __name(function(
|
|
2539
|
-
if (!
|
|
2538
|
+
var correctPaths = /* @__PURE__ */ __name(function(path5) {
|
|
2539
|
+
if (!path5 || path5.length === 0) {
|
|
2540
2540
|
return ".";
|
|
2541
2541
|
}
|
|
2542
|
-
|
|
2543
|
-
const isUNCPath =
|
|
2544
|
-
const isPathAbsolute = isAbsolute(
|
|
2545
|
-
const trailingSeparator =
|
|
2546
|
-
|
|
2547
|
-
if (
|
|
2542
|
+
path5 = normalizeWindowsPath(path5);
|
|
2543
|
+
const isUNCPath = path5.match(_UNC_REGEX);
|
|
2544
|
+
const isPathAbsolute = isAbsolute(path5);
|
|
2545
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2546
|
+
path5 = normalizeString(path5, !isPathAbsolute);
|
|
2547
|
+
if (path5.length === 0) {
|
|
2548
2548
|
if (isPathAbsolute) {
|
|
2549
2549
|
return "/";
|
|
2550
2550
|
}
|
|
2551
2551
|
return trailingSeparator ? "./" : ".";
|
|
2552
2552
|
}
|
|
2553
2553
|
if (trailingSeparator) {
|
|
2554
|
-
|
|
2554
|
+
path5 += "/";
|
|
2555
2555
|
}
|
|
2556
|
-
if (_DRIVE_LETTER_RE.test(
|
|
2557
|
-
|
|
2556
|
+
if (_DRIVE_LETTER_RE.test(path5)) {
|
|
2557
|
+
path5 += "/";
|
|
2558
2558
|
}
|
|
2559
2559
|
if (isUNCPath) {
|
|
2560
2560
|
if (!isPathAbsolute) {
|
|
2561
|
-
return `//./${
|
|
2561
|
+
return `//./${path5}`;
|
|
2562
2562
|
}
|
|
2563
|
-
return `//${
|
|
2563
|
+
return `//${path5}`;
|
|
2564
2564
|
}
|
|
2565
|
-
return isPathAbsolute && !isAbsolute(
|
|
2565
|
+
return isPathAbsolute && !isAbsolute(path5) ? `/${path5}` : path5;
|
|
2566
2566
|
}, "correctPaths");
|
|
2567
2567
|
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
2568
|
-
let
|
|
2568
|
+
let path5 = "";
|
|
2569
2569
|
for (const seg of segments) {
|
|
2570
2570
|
if (!seg) {
|
|
2571
2571
|
continue;
|
|
2572
2572
|
}
|
|
2573
|
-
if (
|
|
2574
|
-
const pathTrailing =
|
|
2573
|
+
if (path5.length > 0) {
|
|
2574
|
+
const pathTrailing = path5[path5.length - 1] === "/";
|
|
2575
2575
|
const segLeading = seg[0] === "/";
|
|
2576
2576
|
const both = pathTrailing && segLeading;
|
|
2577
2577
|
if (both) {
|
|
2578
|
-
|
|
2578
|
+
path5 += seg.slice(1);
|
|
2579
2579
|
} else {
|
|
2580
|
-
|
|
2580
|
+
path5 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
2581
2581
|
}
|
|
2582
2582
|
} else {
|
|
2583
|
-
|
|
2583
|
+
path5 += seg;
|
|
2584
2584
|
}
|
|
2585
2585
|
}
|
|
2586
|
-
return correctPaths(
|
|
2586
|
+
return correctPaths(path5);
|
|
2587
2587
|
}, "joinPaths");
|
|
2588
|
-
function normalizeString(
|
|
2588
|
+
function normalizeString(path5, allowAboveRoot) {
|
|
2589
2589
|
let res = "";
|
|
2590
2590
|
let lastSegmentLength = 0;
|
|
2591
2591
|
let lastSlash = -1;
|
|
2592
2592
|
let dots = 0;
|
|
2593
2593
|
let char = null;
|
|
2594
|
-
for (let index = 0; index <=
|
|
2595
|
-
if (index <
|
|
2596
|
-
char =
|
|
2594
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2595
|
+
if (index < path5.length) {
|
|
2596
|
+
char = path5[index];
|
|
2597
2597
|
} else if (char === "/") {
|
|
2598
2598
|
break;
|
|
2599
2599
|
} else {
|
|
@@ -2629,9 +2629,9 @@ function normalizeString(path6, allowAboveRoot) {
|
|
|
2629
2629
|
}
|
|
2630
2630
|
} else {
|
|
2631
2631
|
if (res.length > 0) {
|
|
2632
|
-
res += `/${
|
|
2632
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2633
2633
|
} else {
|
|
2634
|
-
res =
|
|
2634
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2635
2635
|
}
|
|
2636
2636
|
lastSegmentLength = index - lastSlash - 1;
|
|
2637
2637
|
}
|
|
@@ -2648,20 +2648,20 @@ function normalizeString(path6, allowAboveRoot) {
|
|
|
2648
2648
|
__name(normalizeString, "normalizeString");
|
|
2649
2649
|
|
|
2650
2650
|
// ../path/src/is-file.ts
|
|
2651
|
-
function isFile(
|
|
2652
|
-
return Boolean(statSync(additionalPath ? joinPaths(additionalPath,
|
|
2651
|
+
function isFile(path5, additionalPath) {
|
|
2652
|
+
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
|
|
2653
2653
|
throwIfNoEntry: false
|
|
2654
2654
|
})?.isFile());
|
|
2655
2655
|
}
|
|
2656
2656
|
__name(isFile, "isFile");
|
|
2657
|
-
function isDirectory(
|
|
2658
|
-
return Boolean(statSync(additionalPath ? joinPaths(additionalPath,
|
|
2657
|
+
function isDirectory(path5, additionalPath) {
|
|
2658
|
+
return Boolean(statSync(additionalPath ? joinPaths(additionalPath, path5) : path5, {
|
|
2659
2659
|
throwIfNoEntry: false
|
|
2660
2660
|
})?.isDirectory());
|
|
2661
2661
|
}
|
|
2662
2662
|
__name(isDirectory, "isDirectory");
|
|
2663
|
-
function isAbsolutePath(
|
|
2664
|
-
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(
|
|
2663
|
+
function isAbsolutePath(path5) {
|
|
2664
|
+
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path5);
|
|
2665
2665
|
}
|
|
2666
2666
|
__name(isAbsolutePath, "isAbsolutePath");
|
|
2667
2667
|
|
|
@@ -2676,45 +2676,45 @@ function normalizeWindowsPath2(input = "") {
|
|
|
2676
2676
|
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
2677
2677
|
var _UNC_REGEX2 = /^[/\\]{2}/;
|
|
2678
2678
|
var _DRIVE_LETTER_RE2 = /^[A-Z]:$/i;
|
|
2679
|
-
function correctPath(
|
|
2680
|
-
if (!
|
|
2679
|
+
function correctPath(path5) {
|
|
2680
|
+
if (!path5 || path5.length === 0) {
|
|
2681
2681
|
return ".";
|
|
2682
2682
|
}
|
|
2683
|
-
|
|
2684
|
-
const isUNCPath =
|
|
2685
|
-
const isPathAbsolute = isAbsolutePath(
|
|
2686
|
-
const trailingSeparator =
|
|
2687
|
-
|
|
2688
|
-
if (
|
|
2683
|
+
path5 = normalizeWindowsPath2(path5);
|
|
2684
|
+
const isUNCPath = path5.match(_UNC_REGEX2);
|
|
2685
|
+
const isPathAbsolute = isAbsolutePath(path5);
|
|
2686
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2687
|
+
path5 = normalizeString2(path5, !isPathAbsolute);
|
|
2688
|
+
if (path5.length === 0) {
|
|
2689
2689
|
if (isPathAbsolute) {
|
|
2690
2690
|
return "/";
|
|
2691
2691
|
}
|
|
2692
2692
|
return trailingSeparator ? "./" : ".";
|
|
2693
2693
|
}
|
|
2694
2694
|
if (trailingSeparator) {
|
|
2695
|
-
|
|
2695
|
+
path5 += "/";
|
|
2696
2696
|
}
|
|
2697
|
-
if (_DRIVE_LETTER_RE2.test(
|
|
2698
|
-
|
|
2697
|
+
if (_DRIVE_LETTER_RE2.test(path5)) {
|
|
2698
|
+
path5 += "/";
|
|
2699
2699
|
}
|
|
2700
2700
|
if (isUNCPath) {
|
|
2701
2701
|
if (!isPathAbsolute) {
|
|
2702
|
-
return `//./${
|
|
2702
|
+
return `//./${path5}`;
|
|
2703
2703
|
}
|
|
2704
|
-
return `//${
|
|
2704
|
+
return `//${path5}`;
|
|
2705
2705
|
}
|
|
2706
|
-
return isPathAbsolute && !isAbsolutePath(
|
|
2706
|
+
return isPathAbsolute && !isAbsolutePath(path5) ? `/${path5}` : path5;
|
|
2707
2707
|
}
|
|
2708
2708
|
__name(correctPath, "correctPath");
|
|
2709
|
-
function normalizeString2(
|
|
2709
|
+
function normalizeString2(path5, allowAboveRoot) {
|
|
2710
2710
|
let res = "";
|
|
2711
2711
|
let lastSegmentLength = 0;
|
|
2712
2712
|
let lastSlash = -1;
|
|
2713
2713
|
let dots = 0;
|
|
2714
2714
|
let char = null;
|
|
2715
|
-
for (let index = 0; index <=
|
|
2716
|
-
if (index <
|
|
2717
|
-
char =
|
|
2715
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2716
|
+
if (index < path5.length) {
|
|
2717
|
+
char = path5[index];
|
|
2718
2718
|
} else if (char === "/") {
|
|
2719
2719
|
break;
|
|
2720
2720
|
} else {
|
|
@@ -2750,9 +2750,9 @@ function normalizeString2(path6, allowAboveRoot) {
|
|
|
2750
2750
|
}
|
|
2751
2751
|
} else {
|
|
2752
2752
|
if (res.length > 0) {
|
|
2753
|
-
res += `/${
|
|
2753
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2754
2754
|
} else {
|
|
2755
|
-
res =
|
|
2755
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2756
2756
|
}
|
|
2757
2757
|
lastSegmentLength = index - lastSlash - 1;
|
|
2758
2758
|
}
|
|
@@ -2824,34 +2824,34 @@ __name2(normalizeWindowsPath3, "normalizeWindowsPath");
|
|
|
2824
2824
|
var _UNC_REGEX3 = /^[/\\]{2}/;
|
|
2825
2825
|
var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
2826
2826
|
var _DRIVE_LETTER_RE3 = /^[A-Za-z]:$/;
|
|
2827
|
-
var correctPaths2 = /* @__PURE__ */ __name2(function(
|
|
2828
|
-
if (!
|
|
2827
|
+
var correctPaths2 = /* @__PURE__ */ __name2(function(path5) {
|
|
2828
|
+
if (!path5 || path5.length === 0) {
|
|
2829
2829
|
return ".";
|
|
2830
2830
|
}
|
|
2831
|
-
|
|
2832
|
-
const isUNCPath =
|
|
2833
|
-
const isPathAbsolute = isAbsolute2(
|
|
2834
|
-
const trailingSeparator =
|
|
2835
|
-
|
|
2836
|
-
if (
|
|
2831
|
+
path5 = normalizeWindowsPath3(path5);
|
|
2832
|
+
const isUNCPath = path5.match(_UNC_REGEX3);
|
|
2833
|
+
const isPathAbsolute = isAbsolute2(path5);
|
|
2834
|
+
const trailingSeparator = path5[path5.length - 1] === "/";
|
|
2835
|
+
path5 = normalizeString3(path5, !isPathAbsolute);
|
|
2836
|
+
if (path5.length === 0) {
|
|
2837
2837
|
if (isPathAbsolute) {
|
|
2838
2838
|
return "/";
|
|
2839
2839
|
}
|
|
2840
2840
|
return trailingSeparator ? "./" : ".";
|
|
2841
2841
|
}
|
|
2842
2842
|
if (trailingSeparator) {
|
|
2843
|
-
|
|
2843
|
+
path5 += "/";
|
|
2844
2844
|
}
|
|
2845
|
-
if (_DRIVE_LETTER_RE3.test(
|
|
2846
|
-
|
|
2845
|
+
if (_DRIVE_LETTER_RE3.test(path5)) {
|
|
2846
|
+
path5 += "/";
|
|
2847
2847
|
}
|
|
2848
2848
|
if (isUNCPath) {
|
|
2849
2849
|
if (!isPathAbsolute) {
|
|
2850
|
-
return `//./${
|
|
2850
|
+
return `//./${path5}`;
|
|
2851
2851
|
}
|
|
2852
|
-
return `//${
|
|
2852
|
+
return `//${path5}`;
|
|
2853
2853
|
}
|
|
2854
|
-
return isPathAbsolute && !isAbsolute2(
|
|
2854
|
+
return isPathAbsolute && !isAbsolute2(path5) ? `/${path5}` : path5;
|
|
2855
2855
|
}, "correctPaths");
|
|
2856
2856
|
function cwd() {
|
|
2857
2857
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
@@ -2861,15 +2861,15 @@ function cwd() {
|
|
|
2861
2861
|
}
|
|
2862
2862
|
__name(cwd, "cwd");
|
|
2863
2863
|
__name2(cwd, "cwd");
|
|
2864
|
-
function normalizeString3(
|
|
2864
|
+
function normalizeString3(path5, allowAboveRoot) {
|
|
2865
2865
|
let res = "";
|
|
2866
2866
|
let lastSegmentLength = 0;
|
|
2867
2867
|
let lastSlash = -1;
|
|
2868
2868
|
let dots = 0;
|
|
2869
2869
|
let char = null;
|
|
2870
|
-
for (let index = 0; index <=
|
|
2871
|
-
if (index <
|
|
2872
|
-
char =
|
|
2870
|
+
for (let index = 0; index <= path5.length; ++index) {
|
|
2871
|
+
if (index < path5.length) {
|
|
2872
|
+
char = path5[index];
|
|
2873
2873
|
} else if (char === "/") {
|
|
2874
2874
|
break;
|
|
2875
2875
|
} else {
|
|
@@ -2905,9 +2905,9 @@ function normalizeString3(path6, allowAboveRoot) {
|
|
|
2905
2905
|
}
|
|
2906
2906
|
} else {
|
|
2907
2907
|
if (res.length > 0) {
|
|
2908
|
-
res += `/${
|
|
2908
|
+
res += `/${path5.slice(lastSlash + 1, index)}`;
|
|
2909
2909
|
} else {
|
|
2910
|
-
res =
|
|
2910
|
+
res = path5.slice(lastSlash + 1, index);
|
|
2911
2911
|
}
|
|
2912
2912
|
lastSegmentLength = index - lastSlash - 1;
|
|
2913
2913
|
}
|
|
@@ -3352,8 +3352,8 @@ function getErrorMap() {
|
|
|
3352
3352
|
}
|
|
3353
3353
|
__name(getErrorMap, "getErrorMap");
|
|
3354
3354
|
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
3355
|
-
const { data, path:
|
|
3356
|
-
const fullPath = [...
|
|
3355
|
+
const { data, path: path5, errorMaps, issueData } = params;
|
|
3356
|
+
const fullPath = [...path5, ...issueData.path || []];
|
|
3357
3357
|
const fullIssue = {
|
|
3358
3358
|
...issueData,
|
|
3359
3359
|
path: fullPath
|
|
@@ -3487,11 +3487,11 @@ var ParseInputLazyPath = class {
|
|
|
3487
3487
|
static {
|
|
3488
3488
|
__name(this, "ParseInputLazyPath");
|
|
3489
3489
|
}
|
|
3490
|
-
constructor(parent, value,
|
|
3490
|
+
constructor(parent, value, path5, key) {
|
|
3491
3491
|
this._cachedPath = [];
|
|
3492
3492
|
this.parent = parent;
|
|
3493
3493
|
this.data = value;
|
|
3494
|
-
this._path =
|
|
3494
|
+
this._path = path5;
|
|
3495
3495
|
this._key = key;
|
|
3496
3496
|
}
|
|
3497
3497
|
get path() {
|
|
@@ -7198,8 +7198,8 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
7198
7198
|
|
|
7199
7199
|
// ../path/src/get-parent-path.ts
|
|
7200
7200
|
init_esm_shims();
|
|
7201
|
-
var resolveParentPath = /* @__PURE__ */ __name((
|
|
7202
|
-
return resolvePaths(
|
|
7201
|
+
var resolveParentPath = /* @__PURE__ */ __name((path5) => {
|
|
7202
|
+
return resolvePaths(path5, "..");
|
|
7203
7203
|
}, "resolveParentPath");
|
|
7204
7204
|
var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
|
|
7205
7205
|
const ignoreCase = options?.ignoreCase ?? true;
|
|
@@ -7304,25 +7304,17 @@ function findFilePath(filePath) {
|
|
|
7304
7304
|
}), "");
|
|
7305
7305
|
}
|
|
7306
7306
|
__name(findFilePath, "findFilePath");
|
|
7307
|
-
function
|
|
7308
|
-
|
|
7309
|
-
return "";
|
|
7310
|
-
}
|
|
7311
|
-
const match = /.(\.[^./]+|\.)$/.exec(normalizeWindowsPath2(filePath));
|
|
7312
|
-
return match && match[1] || EMPTY_STRING;
|
|
7313
|
-
}
|
|
7314
|
-
__name(findFileExtension, "findFileExtension");
|
|
7315
|
-
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7316
|
-
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7307
|
+
function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
|
|
7308
|
+
const paths = normalizeWindowsPath2(path5).split("/");
|
|
7317
7309
|
let resolvedPath = "";
|
|
7318
7310
|
let resolvedAbsolute = false;
|
|
7319
7311
|
for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
7320
|
-
const
|
|
7321
|
-
if (!
|
|
7312
|
+
const path6 = index >= 0 ? paths[index] : cwd2;
|
|
7313
|
+
if (!path6 || path6.length === 0) {
|
|
7322
7314
|
continue;
|
|
7323
7315
|
}
|
|
7324
|
-
resolvedPath = joinPaths(
|
|
7325
|
-
resolvedAbsolute = isAbsolutePath(
|
|
7316
|
+
resolvedPath = joinPaths(path6, resolvedPath);
|
|
7317
|
+
resolvedAbsolute = isAbsolutePath(path6);
|
|
7326
7318
|
}
|
|
7327
7319
|
resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute);
|
|
7328
7320
|
if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
|
|
@@ -7332,7 +7324,7 @@ function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
|
7332
7324
|
}
|
|
7333
7325
|
__name(resolvePath, "resolvePath");
|
|
7334
7326
|
function resolvePaths(...paths) {
|
|
7335
|
-
return resolvePath(joinPaths(...paths.map((
|
|
7327
|
+
return resolvePath(joinPaths(...paths.map((path5) => normalizeWindowsPath2(path5))));
|
|
7336
7328
|
}
|
|
7337
7329
|
__name(resolvePaths, "resolvePaths");
|
|
7338
7330
|
function relativePath(from, to) {
|
|
@@ -7366,7 +7358,7 @@ var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
|
7366
7358
|
|
|
7367
7359
|
// src/prisma-generator.ts
|
|
7368
7360
|
var import_pluralize = __toESM(require_pluralize(), 1);
|
|
7369
|
-
import
|
|
7361
|
+
import path4 from "node:path";
|
|
7370
7362
|
|
|
7371
7363
|
// src/config.ts
|
|
7372
7364
|
init_esm_shims();
|
|
@@ -7399,7 +7391,7 @@ var configSchema = z.object({
|
|
|
7399
7391
|
withShield: z.coerce.boolean().or(z.string()).default(true),
|
|
7400
7392
|
withZod: z.coerce.boolean().or(z.string()).default(true),
|
|
7401
7393
|
withNext: z.coerce.boolean().or(z.string()).default(true),
|
|
7402
|
-
contextPath: z.string().default("../src/trpc/context"),
|
|
7394
|
+
contextPath: z.string().default("../src/trpc/context.ts"),
|
|
7403
7395
|
trpcOptions: z.coerce.boolean().or(z.string()).default(true),
|
|
7404
7396
|
showModelNameInProcedure: z.coerce.boolean().or(z.string()).default(true),
|
|
7405
7397
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
@@ -7603,17 +7595,12 @@ __name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
|
|
|
7603
7595
|
|
|
7604
7596
|
// src/utils/get-relative-path.ts
|
|
7605
7597
|
init_esm_shims();
|
|
7606
|
-
import path2 from "node:path";
|
|
7607
7598
|
function getRelativePath(outputPath, filePath, isOutsideOutputPath, schemaPath, fromPath) {
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
toPath = path2.join(schemaPathWithoutFileAndExtension, filePath);
|
|
7614
|
-
}
|
|
7615
|
-
const newPath = relativePath(_fromPath, toPath).split(path2.sep).join(path2.posix.sep);
|
|
7616
|
-
return newPath;
|
|
7599
|
+
let toPath = joinPaths(outputPath, filePath.endsWith(".ts") ? findFilePath(filePath) : filePath);
|
|
7600
|
+
if (isOutsideOutputPath && schemaPath) {
|
|
7601
|
+
toPath = joinPaths(schemaPath.endsWith(".prisma") ? findFilePath(schemaPath) : schemaPath, filePath);
|
|
7602
|
+
}
|
|
7603
|
+
return relativePath(fromPath || outputPath, toPath);
|
|
7617
7604
|
}
|
|
7618
7605
|
__name(getRelativePath, "getRelativePath");
|
|
7619
7606
|
|
|
@@ -7927,7 +7914,7 @@ var getImports = /* @__PURE__ */ __name((type, newPath) => {
|
|
|
7927
7914
|
if (type === "trpc") {
|
|
7928
7915
|
statement = "import * as trpc from '@trpc/server';\n";
|
|
7929
7916
|
} else if (type === "trpc-shield") {
|
|
7930
|
-
statement = "import { shield, allow } from 'trpc-shield';\n";
|
|
7917
|
+
statement = "import { shield, allow } from '@stryke/trpc-next/shield';\n";
|
|
7931
7918
|
} else if (type === "context") {
|
|
7932
7919
|
statement = `import type { Context } from '${newPath}';
|
|
7933
7920
|
`;
|
|
@@ -7991,6 +7978,53 @@ var constructShield = /* @__PURE__ */ __name(async ({ queries, mutations, subscr
|
|
|
7991
7978
|
});
|
|
7992
7979
|
return shieldText;
|
|
7993
7980
|
}, "constructShield");
|
|
7981
|
+
var constructDefaultOptions = /* @__PURE__ */ __name((config, options, outputDir) => {
|
|
7982
|
+
return `import { ZodError } from 'zod';${config.withNext ? '\nimport { transformer } from "@stryke/trpc-next/shared";' : ""}
|
|
7983
|
+
import type {
|
|
7984
|
+
DataTransformerOptions,
|
|
7985
|
+
RootConfig
|
|
7986
|
+
} from "@trpc/server/unstable-core-do-not-import";
|
|
7987
|
+
import type { Context } from "${getRelativePath(outputDir, config.contextPath, true, options.schemaPath)}";
|
|
7988
|
+
|
|
7989
|
+
interface RuntimeConfigOptions<
|
|
7990
|
+
TContext extends object,
|
|
7991
|
+
TMeta extends object = object
|
|
7992
|
+
> extends Partial<
|
|
7993
|
+
Omit<
|
|
7994
|
+
RootConfig<{
|
|
7995
|
+
ctx: TContext;
|
|
7996
|
+
meta: TMeta;
|
|
7997
|
+
errorShape: any;
|
|
7998
|
+
transformer: any;
|
|
7999
|
+
}>,
|
|
8000
|
+
"$types" | "transformer"
|
|
8001
|
+
>
|
|
8002
|
+
> {
|
|
8003
|
+
/**
|
|
8004
|
+
* Use a data transformer
|
|
8005
|
+
* @see https://trpc.io/docs/v11/data-transformers
|
|
8006
|
+
*/
|
|
8007
|
+
transformer?: DataTransformerOptions;
|
|
8008
|
+
}
|
|
8009
|
+
|
|
8010
|
+
const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transformer," : ""}
|
|
8011
|
+
errorFormatter({ shape, error }) {
|
|
8012
|
+
return {
|
|
8013
|
+
...shape,
|
|
8014
|
+
data: {
|
|
8015
|
+
...shape.data,
|
|
8016
|
+
zodError:
|
|
8017
|
+
error.code === "BAD_REQUEST" && error.cause instanceof ZodError
|
|
8018
|
+
? error.cause.flatten()
|
|
8019
|
+
: null
|
|
8020
|
+
}
|
|
8021
|
+
};
|
|
8022
|
+
}
|
|
8023
|
+
};
|
|
8024
|
+
|
|
8025
|
+
export default options;
|
|
8026
|
+
`;
|
|
8027
|
+
}, "constructDefaultOptions");
|
|
7994
8028
|
|
|
7995
8029
|
// src/project.ts
|
|
7996
8030
|
init_esm_shims();
|
|
@@ -9196,7 +9230,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
|
|
|
9196
9230
|
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
|
9197
9231
|
init_esm_shims();
|
|
9198
9232
|
var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
|
|
9199
|
-
var stringifyPath = /* @__PURE__ */ __name((
|
|
9233
|
+
var stringifyPath = /* @__PURE__ */ __name((path5) => path5.map(String).map(escapeKey).join("."), "stringifyPath");
|
|
9200
9234
|
var parsePath = /* @__PURE__ */ __name((string) => {
|
|
9201
9235
|
const result = [];
|
|
9202
9236
|
let segment = "";
|
|
@@ -9459,27 +9493,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
|
|
|
9459
9493
|
}
|
|
9460
9494
|
return keys.next().value;
|
|
9461
9495
|
}, "getNthKey");
|
|
9462
|
-
function validatePath(
|
|
9463
|
-
if (includes(
|
|
9496
|
+
function validatePath(path5) {
|
|
9497
|
+
if (includes(path5, "__proto__")) {
|
|
9464
9498
|
throw new Error("__proto__ is not allowed as a property");
|
|
9465
9499
|
}
|
|
9466
|
-
if (includes(
|
|
9500
|
+
if (includes(path5, "prototype")) {
|
|
9467
9501
|
throw new Error("prototype is not allowed as a property");
|
|
9468
9502
|
}
|
|
9469
|
-
if (includes(
|
|
9503
|
+
if (includes(path5, "constructor")) {
|
|
9470
9504
|
throw new Error("constructor is not allowed as a property");
|
|
9471
9505
|
}
|
|
9472
9506
|
}
|
|
9473
9507
|
__name(validatePath, "validatePath");
|
|
9474
|
-
var getDeep = /* @__PURE__ */ __name((object,
|
|
9475
|
-
validatePath(
|
|
9476
|
-
for (let i = 0; i <
|
|
9477
|
-
const key =
|
|
9508
|
+
var getDeep = /* @__PURE__ */ __name((object, path5) => {
|
|
9509
|
+
validatePath(path5);
|
|
9510
|
+
for (let i = 0; i < path5.length; i++) {
|
|
9511
|
+
const key = path5[i];
|
|
9478
9512
|
if (isSet(object)) {
|
|
9479
9513
|
object = getNthKey(object, +key);
|
|
9480
9514
|
} else if (isMap(object)) {
|
|
9481
9515
|
const row = +key;
|
|
9482
|
-
const type = +
|
|
9516
|
+
const type = +path5[++i] === 0 ? "key" : "value";
|
|
9483
9517
|
const keyOfRow = getNthKey(object, row);
|
|
9484
9518
|
switch (type) {
|
|
9485
9519
|
case "key":
|
|
@@ -9495,14 +9529,14 @@ var getDeep = /* @__PURE__ */ __name((object, path6) => {
|
|
|
9495
9529
|
}
|
|
9496
9530
|
return object;
|
|
9497
9531
|
}, "getDeep");
|
|
9498
|
-
var setDeep = /* @__PURE__ */ __name((object,
|
|
9499
|
-
validatePath(
|
|
9500
|
-
if (
|
|
9532
|
+
var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
9533
|
+
validatePath(path5);
|
|
9534
|
+
if (path5.length === 0) {
|
|
9501
9535
|
return mapper(object);
|
|
9502
9536
|
}
|
|
9503
9537
|
let parent = object;
|
|
9504
|
-
for (let i = 0; i <
|
|
9505
|
-
const key =
|
|
9538
|
+
for (let i = 0; i < path5.length - 1; i++) {
|
|
9539
|
+
const key = path5[i];
|
|
9506
9540
|
if (isArray(parent)) {
|
|
9507
9541
|
const index = +key;
|
|
9508
9542
|
parent = parent[index];
|
|
@@ -9512,12 +9546,12 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9512
9546
|
const row = +key;
|
|
9513
9547
|
parent = getNthKey(parent, row);
|
|
9514
9548
|
} else if (isMap(parent)) {
|
|
9515
|
-
const isEnd = i ===
|
|
9549
|
+
const isEnd = i === path5.length - 2;
|
|
9516
9550
|
if (isEnd) {
|
|
9517
9551
|
break;
|
|
9518
9552
|
}
|
|
9519
9553
|
const row = +key;
|
|
9520
|
-
const type = +
|
|
9554
|
+
const type = +path5[++i] === 0 ? "key" : "value";
|
|
9521
9555
|
const keyOfRow = getNthKey(parent, row);
|
|
9522
9556
|
switch (type) {
|
|
9523
9557
|
case "key":
|
|
@@ -9529,7 +9563,7 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9529
9563
|
}
|
|
9530
9564
|
}
|
|
9531
9565
|
}
|
|
9532
|
-
const lastKey =
|
|
9566
|
+
const lastKey = path5[path5.length - 1];
|
|
9533
9567
|
if (isArray(parent)) {
|
|
9534
9568
|
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
9535
9569
|
} else if (isPlainObject2(parent)) {
|
|
@@ -9544,7 +9578,7 @@ var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
|
9544
9578
|
}
|
|
9545
9579
|
}
|
|
9546
9580
|
if (isMap(parent)) {
|
|
9547
|
-
const row = +
|
|
9581
|
+
const row = +path5[path5.length - 2];
|
|
9548
9582
|
const keyToRow = getNthKey(parent, row);
|
|
9549
9583
|
const type = +lastKey === 0 ? "key" : "value";
|
|
9550
9584
|
switch (type) {
|
|
@@ -9590,15 +9624,15 @@ function traverse(tree, walker2, origin = []) {
|
|
|
9590
9624
|
}
|
|
9591
9625
|
__name(traverse, "traverse");
|
|
9592
9626
|
function applyValueAnnotations(plain, annotations, superJson) {
|
|
9593
|
-
traverse(annotations, (type,
|
|
9594
|
-
plain = setDeep(plain,
|
|
9627
|
+
traverse(annotations, (type, path5) => {
|
|
9628
|
+
plain = setDeep(plain, path5, (v) => untransformValue(v, type, superJson));
|
|
9595
9629
|
});
|
|
9596
9630
|
return plain;
|
|
9597
9631
|
}
|
|
9598
9632
|
__name(applyValueAnnotations, "applyValueAnnotations");
|
|
9599
9633
|
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
9600
|
-
function apply(identicalPaths,
|
|
9601
|
-
const object = getDeep(plain, parsePath(
|
|
9634
|
+
function apply(identicalPaths, path5) {
|
|
9635
|
+
const object = getDeep(plain, parsePath(path5));
|
|
9602
9636
|
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
9603
9637
|
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
9604
9638
|
});
|
|
@@ -9619,13 +9653,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
|
9619
9653
|
}
|
|
9620
9654
|
__name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
|
|
9621
9655
|
var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
|
|
9622
|
-
function addIdentity(object,
|
|
9656
|
+
function addIdentity(object, path5, identities) {
|
|
9623
9657
|
const existingSet = identities.get(object);
|
|
9624
9658
|
if (existingSet) {
|
|
9625
|
-
existingSet.push(
|
|
9659
|
+
existingSet.push(path5);
|
|
9626
9660
|
} else {
|
|
9627
9661
|
identities.set(object, [
|
|
9628
|
-
|
|
9662
|
+
path5
|
|
9629
9663
|
]);
|
|
9630
9664
|
}
|
|
9631
9665
|
}
|
|
@@ -9638,7 +9672,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9638
9672
|
return;
|
|
9639
9673
|
}
|
|
9640
9674
|
if (!dedupe) {
|
|
9641
|
-
paths = paths.map((
|
|
9675
|
+
paths = paths.map((path5) => path5.map(String)).sort((a, b) => a.length - b.length);
|
|
9642
9676
|
}
|
|
9643
9677
|
const [representativePath, ...identicalPaths] = paths;
|
|
9644
9678
|
if (representativePath.length === 0) {
|
|
@@ -9663,10 +9697,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9663
9697
|
}
|
|
9664
9698
|
}
|
|
9665
9699
|
__name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
|
|
9666
|
-
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe,
|
|
9700
|
+
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path5 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
9667
9701
|
const primitive = isPrimitive(object);
|
|
9668
9702
|
if (!primitive) {
|
|
9669
|
-
addIdentity(object,
|
|
9703
|
+
addIdentity(object, path5, identities);
|
|
9670
9704
|
const seen = seenObjects.get(object);
|
|
9671
9705
|
if (seen) {
|
|
9672
9706
|
return dedupe ? {
|
|
@@ -9703,7 +9737,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
|
|
|
9703
9737
|
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
9704
9738
|
}
|
|
9705
9739
|
const recursiveResult = walker(value, identities, superJson, dedupe, [
|
|
9706
|
-
...
|
|
9740
|
+
...path5,
|
|
9707
9741
|
index
|
|
9708
9742
|
], [
|
|
9709
9743
|
...objectsInThisPath,
|
|
@@ -10283,7 +10317,7 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
|
|
|
10283
10317
|
}, "writeFile");
|
|
10284
10318
|
|
|
10285
10319
|
// src/utils/write-file-safely.ts
|
|
10286
|
-
import
|
|
10320
|
+
import path2 from "node:path";
|
|
10287
10321
|
|
|
10288
10322
|
// src/utils/format-file.ts
|
|
10289
10323
|
init_esm_shims();
|
|
@@ -10327,7 +10361,7 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10327
10361
|
}, "writeFileSafely");
|
|
10328
10362
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10329
10363
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10330
|
-
let relativePath2 =
|
|
10364
|
+
let relativePath2 = path2.relative(path2.dirname(indexPath), filePath);
|
|
10331
10365
|
if (relativePath2.endsWith(".ts")) {
|
|
10332
10366
|
relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
|
|
10333
10367
|
}
|
|
@@ -10504,7 +10538,7 @@ init_esm_shims();
|
|
|
10504
10538
|
|
|
10505
10539
|
// src/zod-helpers/transformer.ts
|
|
10506
10540
|
init_esm_shims();
|
|
10507
|
-
import
|
|
10541
|
+
import path3 from "node:path";
|
|
10508
10542
|
|
|
10509
10543
|
// src/zod-helpers/model-helpers.ts
|
|
10510
10544
|
init_esm_shims();
|
|
@@ -10652,13 +10686,13 @@ var Transformer = class _Transformer {
|
|
|
10652
10686
|
this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
|
|
10653
10687
|
}
|
|
10654
10688
|
static async generateIndex() {
|
|
10655
|
-
const indexPath =
|
|
10689
|
+
const indexPath = path3.join(_Transformer.outputPath, "schemas/index.ts");
|
|
10656
10690
|
await writeIndexFile(indexPath);
|
|
10657
10691
|
}
|
|
10658
10692
|
async generateEnumSchemas() {
|
|
10659
10693
|
for (const enumType2 of this.enumTypes) {
|
|
10660
10694
|
const { name, values } = enumType2;
|
|
10661
|
-
await writeFileSafely(
|
|
10695
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/enums/${name}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10662
10696
|
${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10663
10697
|
}
|
|
10664
10698
|
}
|
|
@@ -10672,7 +10706,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10672
10706
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10673
10707
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10674
10708
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10675
|
-
await writeFileSafely(
|
|
10709
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/objects/${objectSchemaName}.schema.ts`), objectSchema);
|
|
10676
10710
|
}
|
|
10677
10711
|
generateObjectSchemaFields() {
|
|
10678
10712
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10811,9 +10845,9 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10811
10845
|
generateImportPrismaStatement() {
|
|
10812
10846
|
let prismaClientImportPath;
|
|
10813
10847
|
if (_Transformer.isCustomPrismaClientOutputPath) {
|
|
10814
|
-
const fromPath =
|
|
10848
|
+
const fromPath = path3.join(_Transformer.outputPath, "schemas", "objects");
|
|
10815
10849
|
const toPath = _Transformer.prismaClientOutputPath;
|
|
10816
|
-
const relativePathFromOutputToPrismaClient =
|
|
10850
|
+
const relativePathFromOutputToPrismaClient = path3.relative(fromPath, toPath).split(path3.sep).join(path3.posix.sep);
|
|
10817
10851
|
prismaClientImportPath = relativePathFromOutputToPrismaClient;
|
|
10818
10852
|
} else {
|
|
10819
10853
|
prismaClientImportPath = _Transformer.prismaClientOutputPath;
|
|
@@ -10943,7 +10977,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10943
10977
|
includeImport,
|
|
10944
10978
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10945
10979
|
];
|
|
10946
|
-
await writeFileSafely(
|
|
10980
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10947
10981
|
}
|
|
10948
10982
|
if (findFirst) {
|
|
10949
10983
|
const imports = [
|
|
@@ -10954,7 +10988,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10954
10988
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10955
10989
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10956
10990
|
];
|
|
10957
|
-
await writeFileSafely(
|
|
10991
|
+
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() })`)}`);
|
|
10958
10992
|
}
|
|
10959
10993
|
if (findMany) {
|
|
10960
10994
|
const imports = [
|
|
@@ -10965,7 +10999,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10965
10999
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10966
11000
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10967
11001
|
];
|
|
10968
|
-
await writeFileSafely(
|
|
11002
|
+
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() })`)}`);
|
|
10969
11003
|
}
|
|
10970
11004
|
if (createOne) {
|
|
10971
11005
|
const imports = [
|
|
@@ -10974,19 +11008,19 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10974
11008
|
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
10975
11009
|
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
|
|
10976
11010
|
];
|
|
10977
|
-
await writeFileSafely(
|
|
11011
|
+
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]) })`)}`);
|
|
10978
11012
|
}
|
|
10979
11013
|
if (createMany) {
|
|
10980
11014
|
const imports = [
|
|
10981
11015
|
`import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
|
|
10982
11016
|
];
|
|
10983
|
-
await writeFileSafely(
|
|
11017
|
+
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()"} })`)}`);
|
|
10984
11018
|
}
|
|
10985
11019
|
if (createManyAndReturn) {
|
|
10986
11020
|
const imports = [
|
|
10987
11021
|
`import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`
|
|
10988
11022
|
];
|
|
10989
|
-
await writeFileSafely(
|
|
11023
|
+
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()"} })`)}`);
|
|
10990
11024
|
}
|
|
10991
11025
|
if (deleteOne) {
|
|
10992
11026
|
const imports = [
|
|
@@ -10994,13 +11028,13 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
10994
11028
|
includeImport,
|
|
10995
11029
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10996
11030
|
];
|
|
10997
|
-
await writeFileSafely(
|
|
11031
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10998
11032
|
}
|
|
10999
11033
|
if (deleteMany) {
|
|
11000
11034
|
const imports = [
|
|
11001
11035
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11002
11036
|
];
|
|
11003
|
-
await writeFileSafely(
|
|
11037
|
+
await writeFileSafely(path3.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
11004
11038
|
}
|
|
11005
11039
|
if (updateOne) {
|
|
11006
11040
|
const imports = [
|
|
@@ -11010,20 +11044,20 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11010
11044
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
|
|
11011
11045
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
11012
11046
|
];
|
|
11013
|
-
await writeFileSafely(
|
|
11047
|
+
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 })`)}`);
|
|
11014
11048
|
}
|
|
11015
11049
|
if (updateMany) {
|
|
11016
11050
|
const imports = [
|
|
11017
11051
|
`import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
|
|
11018
11052
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11019
11053
|
];
|
|
11020
|
-
await writeFileSafely(
|
|
11054
|
+
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() })`)}`);
|
|
11021
11055
|
}
|
|
11022
11056
|
if (updateManyAndReturn) {
|
|
11023
11057
|
const imports = [
|
|
11024
11058
|
`import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`
|
|
11025
11059
|
];
|
|
11026
|
-
await writeFileSafely(
|
|
11060
|
+
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()"} })`)}`);
|
|
11027
11061
|
}
|
|
11028
11062
|
if (upsertOne) {
|
|
11029
11063
|
const imports = [
|
|
@@ -11035,7 +11069,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11035
11069
|
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
11036
11070
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
|
|
11037
11071
|
];
|
|
11038
|
-
await writeFileSafely(
|
|
11072
|
+
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 ]) })`)}`);
|
|
11039
11073
|
}
|
|
11040
11074
|
if (aggregate) {
|
|
11041
11075
|
const imports = [
|
|
@@ -11066,7 +11100,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11066
11100
|
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
11067
11101
|
}
|
|
11068
11102
|
}
|
|
11069
|
-
await writeFileSafely(
|
|
11103
|
+
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(", ")} })`)}`);
|
|
11070
11104
|
}
|
|
11071
11105
|
if (groupBy) {
|
|
11072
11106
|
const imports = [
|
|
@@ -11075,7 +11109,7 @@ ${this.generateExportSchemaStatement(`${name}`, `z.enum(${JSON.stringify(values)
|
|
|
11075
11109
|
`import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
|
|
11076
11110
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
11077
11111
|
];
|
|
11078
|
-
await writeFileSafely(
|
|
11112
|
+
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) })`)}`);
|
|
11079
11113
|
}
|
|
11080
11114
|
}
|
|
11081
11115
|
}
|
|
@@ -11614,18 +11648,18 @@ async function generate(options) {
|
|
|
11614
11648
|
subscriptions.sort();
|
|
11615
11649
|
if (config.withShield !== false) {
|
|
11616
11650
|
consoleLog("Generating tRPC Shield");
|
|
11617
|
-
if (typeof config.withShield === "string" && (existsSync(config.withShield) || existsSync(joinPaths(config.withShield, "shield.ts")))) {
|
|
11651
|
+
if (typeof config.withShield === "string" && (existsSync(joinPaths(findFilePath(options.schemaPath), config.withShield)) || existsSync(joinPaths(findFilePath(options.schemaPath), config.withShield, "shield.ts")))) {
|
|
11618
11652
|
consoleLog("Skipping tRPC Shield generation as path provided already exists");
|
|
11619
11653
|
} else {
|
|
11620
11654
|
consoleLog("Constructing tRPC Shield source file");
|
|
11621
|
-
const shieldOutputDir = typeof config.withShield === "string" ?
|
|
11655
|
+
const shieldOutputDir = typeof config.withShield === "string" ? config.withShield : outputDir;
|
|
11622
11656
|
const shieldText = await constructShield({
|
|
11623
11657
|
queries,
|
|
11624
11658
|
mutations,
|
|
11625
11659
|
subscriptions
|
|
11626
11660
|
}, config, options, shieldOutputDir);
|
|
11627
11661
|
consoleLog("Saving tRPC Shield source file to disk");
|
|
11628
|
-
await writeFileSafely(joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11662
|
+
await writeFileSafely(shieldOutputDir.endsWith(".ts") ? shieldOutputDir : joinPaths(shieldOutputDir, "shield.ts"), shieldText);
|
|
11629
11663
|
}
|
|
11630
11664
|
} else {
|
|
11631
11665
|
consoleLog("Skipping tRPC Shield generation");
|
|
@@ -11634,26 +11668,10 @@ async function generate(options) {
|
|
|
11634
11668
|
if (config.trpcOptions && typeof config.trpcOptions === "boolean") {
|
|
11635
11669
|
const trpcOptionsOutputPath = joinPaths(outputDir, "options.ts");
|
|
11636
11670
|
consoleLog("Generating tRPC options source file");
|
|
11637
|
-
await writeFileSafely(trpcOptionsOutputPath,
|
|
11638
|
-
|
|
11639
|
-
export default {${config.withNext ? "\n transformer," : ""}
|
|
11640
|
-
errorFormatter({ shape, error }) {
|
|
11641
|
-
return {
|
|
11642
|
-
...shape,
|
|
11643
|
-
data: {
|
|
11644
|
-
...shape.data,
|
|
11645
|
-
zodError:
|
|
11646
|
-
error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
|
|
11647
|
-
? error.cause.flatten()
|
|
11648
|
-
: null,
|
|
11649
|
-
},
|
|
11650
|
-
};
|
|
11651
|
-
},
|
|
11652
|
-
};
|
|
11653
|
-
`);
|
|
11671
|
+
await writeFileSafely(trpcOptionsOutputPath, constructDefaultOptions(config, options, trpcOptionsOutputPath));
|
|
11654
11672
|
}
|
|
11655
11673
|
resolveModelsComments(models, hiddenModels);
|
|
11656
|
-
const trpcExports = project.createSourceFile(
|
|
11674
|
+
const trpcExports = project.createSourceFile(path4.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11657
11675
|
overwrite: true
|
|
11658
11676
|
});
|
|
11659
11677
|
consoleLog("Generating tRPC imports");
|
|
@@ -11665,7 +11683,7 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11665
11683
|
trpcExports.formatText({
|
|
11666
11684
|
indentSize: 2
|
|
11667
11685
|
});
|
|
11668
|
-
const appRouter = project.createSourceFile(
|
|
11686
|
+
const appRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
11669
11687
|
overwrite: true
|
|
11670
11688
|
});
|
|
11671
11689
|
consoleLog("Generating tRPC router imports");
|
|
@@ -11694,7 +11712,7 @@ export default {${config.withNext ? "\n transformer," : ""}
|
|
|
11694
11712
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11695
11713
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11696
11714
|
generateRouterImport(appRouter, plural, model);
|
|
11697
|
-
const modelRouter = project.createSourceFile(
|
|
11715
|
+
const modelRouter = project.createSourceFile(path4.resolve(outputDir, "routers", `${model}.router.ts`), void 0, {
|
|
11698
11716
|
overwrite: true
|
|
11699
11717
|
});
|
|
11700
11718
|
generateCreateRouterImport({
|