@stryke/prisma-trpc-generator 0.10.6 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator.cjs +523 -215
- package/dist/generator.js +523 -215
- package/dist/index.cjs +523 -215
- package/dist/index.js +523 -215
- package/package.json +2 -1
package/dist/generator.cjs
CHANGED
|
@@ -2484,20 +2484,20 @@ var exists = /* @__PURE__ */ __name(async (filePath) => {
|
|
|
2484
2484
|
|
|
2485
2485
|
// ../fs/src/helpers.ts
|
|
2486
2486
|
var import_promises2 = require("node:fs/promises");
|
|
2487
|
-
async function createDirectory(
|
|
2488
|
-
if (await exists(
|
|
2487
|
+
async function createDirectory(path6) {
|
|
2488
|
+
if (await exists(path6)) {
|
|
2489
2489
|
return;
|
|
2490
2490
|
}
|
|
2491
|
-
return (0, import_promises2.mkdir)(
|
|
2491
|
+
return (0, import_promises2.mkdir)(path6, {
|
|
2492
2492
|
recursive: true
|
|
2493
2493
|
});
|
|
2494
2494
|
}
|
|
2495
2495
|
__name(createDirectory, "createDirectory");
|
|
2496
|
-
async function removeDirectory(
|
|
2497
|
-
if (!existsSync(
|
|
2496
|
+
async function removeDirectory(path6) {
|
|
2497
|
+
if (!existsSync(path6)) {
|
|
2498
2498
|
return;
|
|
2499
2499
|
}
|
|
2500
|
-
return (0, import_promises2.rm)(
|
|
2500
|
+
return (0, import_promises2.rm)(path6, {
|
|
2501
2501
|
recursive: true
|
|
2502
2502
|
});
|
|
2503
2503
|
}
|
|
@@ -2519,65 +2519,65 @@ var _DRIVE_LETTER_RE = /^[A-Z]:$/i;
|
|
|
2519
2519
|
var isAbsolute = /* @__PURE__ */ __name(function(p) {
|
|
2520
2520
|
return _IS_ABSOLUTE_RE.test(p);
|
|
2521
2521
|
}, "isAbsolute");
|
|
2522
|
-
var correctPaths = /* @__PURE__ */ __name(function(
|
|
2523
|
-
if (!
|
|
2522
|
+
var correctPaths = /* @__PURE__ */ __name(function(path6) {
|
|
2523
|
+
if (!path6 || path6.length === 0) {
|
|
2524
2524
|
return ".";
|
|
2525
2525
|
}
|
|
2526
|
-
|
|
2527
|
-
const isUNCPath =
|
|
2528
|
-
const isPathAbsolute = isAbsolute(
|
|
2529
|
-
const trailingSeparator =
|
|
2530
|
-
|
|
2531
|
-
if (
|
|
2526
|
+
path6 = normalizeWindowsPath(path6);
|
|
2527
|
+
const isUNCPath = path6.match(_UNC_REGEX);
|
|
2528
|
+
const isPathAbsolute = isAbsolute(path6);
|
|
2529
|
+
const trailingSeparator = path6[path6.length - 1] === "/";
|
|
2530
|
+
path6 = normalizeString(path6, !isPathAbsolute);
|
|
2531
|
+
if (path6.length === 0) {
|
|
2532
2532
|
if (isPathAbsolute) {
|
|
2533
2533
|
return "/";
|
|
2534
2534
|
}
|
|
2535
2535
|
return trailingSeparator ? "./" : ".";
|
|
2536
2536
|
}
|
|
2537
2537
|
if (trailingSeparator) {
|
|
2538
|
-
|
|
2538
|
+
path6 += "/";
|
|
2539
2539
|
}
|
|
2540
|
-
if (_DRIVE_LETTER_RE.test(
|
|
2541
|
-
|
|
2540
|
+
if (_DRIVE_LETTER_RE.test(path6)) {
|
|
2541
|
+
path6 += "/";
|
|
2542
2542
|
}
|
|
2543
2543
|
if (isUNCPath) {
|
|
2544
2544
|
if (!isPathAbsolute) {
|
|
2545
|
-
return `//./${
|
|
2545
|
+
return `//./${path6}`;
|
|
2546
2546
|
}
|
|
2547
|
-
return `//${
|
|
2547
|
+
return `//${path6}`;
|
|
2548
2548
|
}
|
|
2549
|
-
return isPathAbsolute && !isAbsolute(
|
|
2549
|
+
return isPathAbsolute && !isAbsolute(path6) ? `/${path6}` : path6;
|
|
2550
2550
|
}, "correctPaths");
|
|
2551
2551
|
var joinPaths = /* @__PURE__ */ __name(function(...segments) {
|
|
2552
|
-
let
|
|
2552
|
+
let path6 = "";
|
|
2553
2553
|
for (const seg of segments) {
|
|
2554
2554
|
if (!seg) {
|
|
2555
2555
|
continue;
|
|
2556
2556
|
}
|
|
2557
|
-
if (
|
|
2558
|
-
const pathTrailing =
|
|
2557
|
+
if (path6.length > 0) {
|
|
2558
|
+
const pathTrailing = path6[path6.length - 1] === "/";
|
|
2559
2559
|
const segLeading = seg[0] === "/";
|
|
2560
2560
|
const both = pathTrailing && segLeading;
|
|
2561
2561
|
if (both) {
|
|
2562
|
-
|
|
2562
|
+
path6 += seg.slice(1);
|
|
2563
2563
|
} else {
|
|
2564
|
-
|
|
2564
|
+
path6 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
2565
2565
|
}
|
|
2566
2566
|
} else {
|
|
2567
|
-
|
|
2567
|
+
path6 += seg;
|
|
2568
2568
|
}
|
|
2569
2569
|
}
|
|
2570
|
-
return correctPaths(
|
|
2570
|
+
return correctPaths(path6);
|
|
2571
2571
|
}, "joinPaths");
|
|
2572
|
-
function normalizeString(
|
|
2572
|
+
function normalizeString(path6, allowAboveRoot) {
|
|
2573
2573
|
let res = "";
|
|
2574
2574
|
let lastSegmentLength = 0;
|
|
2575
2575
|
let lastSlash = -1;
|
|
2576
2576
|
let dots = 0;
|
|
2577
2577
|
let char = null;
|
|
2578
|
-
for (let index = 0; index <=
|
|
2579
|
-
if (index <
|
|
2580
|
-
char =
|
|
2578
|
+
for (let index = 0; index <= path6.length; ++index) {
|
|
2579
|
+
if (index < path6.length) {
|
|
2580
|
+
char = path6[index];
|
|
2581
2581
|
} else if (char === "/") {
|
|
2582
2582
|
break;
|
|
2583
2583
|
} else {
|
|
@@ -2613,9 +2613,9 @@ function normalizeString(path5, allowAboveRoot) {
|
|
|
2613
2613
|
}
|
|
2614
2614
|
} else {
|
|
2615
2615
|
if (res.length > 0) {
|
|
2616
|
-
res += `/${
|
|
2616
|
+
res += `/${path6.slice(lastSlash + 1, index)}`;
|
|
2617
2617
|
} else {
|
|
2618
|
-
res =
|
|
2618
|
+
res = path6.slice(lastSlash + 1, index);
|
|
2619
2619
|
}
|
|
2620
2620
|
lastSegmentLength = index - lastSlash - 1;
|
|
2621
2621
|
}
|
|
@@ -2638,7 +2638,7 @@ var lowerCaseFirst = /* @__PURE__ */ __name((input) => {
|
|
|
2638
2638
|
}, "lowerCaseFirst");
|
|
2639
2639
|
|
|
2640
2640
|
// src/prisma-generator.ts
|
|
2641
|
-
var
|
|
2641
|
+
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
2642
2642
|
var import_pluralize = __toESM(require_pluralize(), 1);
|
|
2643
2643
|
|
|
2644
2644
|
// src/config.ts
|
|
@@ -3006,8 +3006,8 @@ function getErrorMap() {
|
|
|
3006
3006
|
}
|
|
3007
3007
|
__name(getErrorMap, "getErrorMap");
|
|
3008
3008
|
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
3009
|
-
const { data, path:
|
|
3010
|
-
const fullPath = [...
|
|
3009
|
+
const { data, path: path6, errorMaps, issueData } = params;
|
|
3010
|
+
const fullPath = [...path6, ...issueData.path || []];
|
|
3011
3011
|
const fullIssue = {
|
|
3012
3012
|
...issueData,
|
|
3013
3013
|
path: fullPath
|
|
@@ -3141,11 +3141,11 @@ var ParseInputLazyPath = class {
|
|
|
3141
3141
|
static {
|
|
3142
3142
|
__name(this, "ParseInputLazyPath");
|
|
3143
3143
|
}
|
|
3144
|
-
constructor(parent, value,
|
|
3144
|
+
constructor(parent, value, path6, key) {
|
|
3145
3145
|
this._cachedPath = [];
|
|
3146
3146
|
this.parent = parent;
|
|
3147
3147
|
this.data = value;
|
|
3148
|
-
this._path =
|
|
3148
|
+
this._path = path6;
|
|
3149
3149
|
this._key = key;
|
|
3150
3150
|
}
|
|
3151
3151
|
get path() {
|
|
@@ -6877,7 +6877,6 @@ var modelActionEnum = z.nativeEnum(ModelAction);
|
|
|
6877
6877
|
var configBoolean = z.string().trim().transform((value) => !value || value.toLowerCase() === "false" || value.toLowerCase() === "n" || value.toLowerCase() === "no" || value === "0" ? false : value.toLowerCase() === "true" || value.toLowerCase() === "y" || value.toLowerCase() === "yes" || value === "1" ? true : value);
|
|
6878
6878
|
var configSchema = z.object({
|
|
6879
6879
|
debug: configBoolean.default("false"),
|
|
6880
|
-
withZod: configBoolean.default("true"),
|
|
6881
6880
|
withNext: configBoolean.default("true"),
|
|
6882
6881
|
withMiddleware: configBoolean.default("false"),
|
|
6883
6882
|
withShield: configBoolean.default("false"),
|
|
@@ -6886,7 +6885,18 @@ var configSchema = z.object({
|
|
|
6886
6885
|
showModelNameInProcedure: configBoolean.default("false"),
|
|
6887
6886
|
generateModelActions: z.string().default(Object.values(ModelAction).join(",")).transform((arg) => {
|
|
6888
6887
|
return arg.split(",").map((action) => modelActionEnum.parse(action.trim()));
|
|
6889
|
-
})
|
|
6888
|
+
}),
|
|
6889
|
+
// Zod configuration
|
|
6890
|
+
withZod: configBoolean.default("true"),
|
|
6891
|
+
relationModel: configBoolean.default("true").or(z.literal("default")),
|
|
6892
|
+
modelSuffix: z.string().default("Model"),
|
|
6893
|
+
modelCase: z.enum([
|
|
6894
|
+
"PascalCase",
|
|
6895
|
+
"camelCase"
|
|
6896
|
+
]).default("PascalCase"),
|
|
6897
|
+
useDecimalJs: configBoolean.default("false"),
|
|
6898
|
+
imports: z.string().optional(),
|
|
6899
|
+
prismaJsonNullability: configBoolean.default("true")
|
|
6890
6900
|
});
|
|
6891
6901
|
|
|
6892
6902
|
// src/helpers.ts
|
|
@@ -6906,20 +6916,20 @@ init_cjs_shims();
|
|
|
6906
6916
|
// ../path/src/is-file.ts
|
|
6907
6917
|
init_cjs_shims();
|
|
6908
6918
|
var import_node_fs2 = require("node:fs");
|
|
6909
|
-
function isFile(
|
|
6910
|
-
return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath,
|
|
6919
|
+
function isFile(path6, additionalPath) {
|
|
6920
|
+
return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
|
|
6911
6921
|
throwIfNoEntry: false
|
|
6912
6922
|
})?.isFile());
|
|
6913
6923
|
}
|
|
6914
6924
|
__name(isFile, "isFile");
|
|
6915
|
-
function isDirectory(
|
|
6916
|
-
return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath,
|
|
6925
|
+
function isDirectory(path6, additionalPath) {
|
|
6926
|
+
return Boolean((0, import_node_fs2.statSync)(additionalPath ? joinPaths(additionalPath, path6) : path6, {
|
|
6917
6927
|
throwIfNoEntry: false
|
|
6918
6928
|
})?.isDirectory());
|
|
6919
6929
|
}
|
|
6920
6930
|
__name(isDirectory, "isDirectory");
|
|
6921
|
-
function isAbsolutePath(
|
|
6922
|
-
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(
|
|
6931
|
+
function isAbsolutePath(path6) {
|
|
6932
|
+
return !/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i.test(path6);
|
|
6923
6933
|
}
|
|
6924
6934
|
__name(isAbsolutePath, "isAbsolutePath");
|
|
6925
6935
|
|
|
@@ -6934,45 +6944,45 @@ function normalizeWindowsPath2(input = "") {
|
|
|
6934
6944
|
__name(normalizeWindowsPath2, "normalizeWindowsPath");
|
|
6935
6945
|
var _UNC_REGEX2 = /^[/\\]{2}/;
|
|
6936
6946
|
var _DRIVE_LETTER_RE2 = /^[A-Z]:$/i;
|
|
6937
|
-
function correctPath(
|
|
6938
|
-
if (!
|
|
6947
|
+
function correctPath(path6) {
|
|
6948
|
+
if (!path6 || path6.length === 0) {
|
|
6939
6949
|
return ".";
|
|
6940
6950
|
}
|
|
6941
|
-
|
|
6942
|
-
const isUNCPath =
|
|
6943
|
-
const isPathAbsolute = isAbsolutePath(
|
|
6944
|
-
const trailingSeparator =
|
|
6945
|
-
|
|
6946
|
-
if (
|
|
6951
|
+
path6 = normalizeWindowsPath2(path6);
|
|
6952
|
+
const isUNCPath = path6.match(_UNC_REGEX2);
|
|
6953
|
+
const isPathAbsolute = isAbsolutePath(path6);
|
|
6954
|
+
const trailingSeparator = path6[path6.length - 1] === "/";
|
|
6955
|
+
path6 = normalizeString2(path6, !isPathAbsolute);
|
|
6956
|
+
if (path6.length === 0) {
|
|
6947
6957
|
if (isPathAbsolute) {
|
|
6948
6958
|
return "/";
|
|
6949
6959
|
}
|
|
6950
6960
|
return trailingSeparator ? "./" : ".";
|
|
6951
6961
|
}
|
|
6952
6962
|
if (trailingSeparator) {
|
|
6953
|
-
|
|
6963
|
+
path6 += "/";
|
|
6954
6964
|
}
|
|
6955
|
-
if (_DRIVE_LETTER_RE2.test(
|
|
6956
|
-
|
|
6965
|
+
if (_DRIVE_LETTER_RE2.test(path6)) {
|
|
6966
|
+
path6 += "/";
|
|
6957
6967
|
}
|
|
6958
6968
|
if (isUNCPath) {
|
|
6959
6969
|
if (!isPathAbsolute) {
|
|
6960
|
-
return `//./${
|
|
6970
|
+
return `//./${path6}`;
|
|
6961
6971
|
}
|
|
6962
|
-
return `//${
|
|
6972
|
+
return `//${path6}`;
|
|
6963
6973
|
}
|
|
6964
|
-
return isPathAbsolute && !isAbsolutePath(
|
|
6974
|
+
return isPathAbsolute && !isAbsolutePath(path6) ? `/${path6}` : path6;
|
|
6965
6975
|
}
|
|
6966
6976
|
__name(correctPath, "correctPath");
|
|
6967
|
-
function normalizeString2(
|
|
6977
|
+
function normalizeString2(path6, allowAboveRoot) {
|
|
6968
6978
|
let res = "";
|
|
6969
6979
|
let lastSegmentLength = 0;
|
|
6970
6980
|
let lastSlash = -1;
|
|
6971
6981
|
let dots = 0;
|
|
6972
6982
|
let char = null;
|
|
6973
|
-
for (let index = 0; index <=
|
|
6974
|
-
if (index <
|
|
6975
|
-
char =
|
|
6983
|
+
for (let index = 0; index <= path6.length; ++index) {
|
|
6984
|
+
if (index < path6.length) {
|
|
6985
|
+
char = path6[index];
|
|
6976
6986
|
} else if (char === "/") {
|
|
6977
6987
|
break;
|
|
6978
6988
|
} else {
|
|
@@ -7008,9 +7018,9 @@ function normalizeString2(path5, allowAboveRoot) {
|
|
|
7008
7018
|
}
|
|
7009
7019
|
} else {
|
|
7010
7020
|
if (res.length > 0) {
|
|
7011
|
-
res += `/${
|
|
7021
|
+
res += `/${path6.slice(lastSlash + 1, index)}`;
|
|
7012
7022
|
} else {
|
|
7013
|
-
res =
|
|
7023
|
+
res = path6.slice(lastSlash + 1, index);
|
|
7014
7024
|
}
|
|
7015
7025
|
lastSegmentLength = index - lastSlash - 1;
|
|
7016
7026
|
}
|
|
@@ -7082,34 +7092,34 @@ __name2(normalizeWindowsPath3, "normalizeWindowsPath");
|
|
|
7082
7092
|
var _UNC_REGEX3 = /^[/\\]{2}/;
|
|
7083
7093
|
var _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
7084
7094
|
var _DRIVE_LETTER_RE3 = /^[A-Za-z]:$/;
|
|
7085
|
-
var correctPaths2 = /* @__PURE__ */ __name2(function(
|
|
7086
|
-
if (!
|
|
7095
|
+
var correctPaths2 = /* @__PURE__ */ __name2(function(path6) {
|
|
7096
|
+
if (!path6 || path6.length === 0) {
|
|
7087
7097
|
return ".";
|
|
7088
7098
|
}
|
|
7089
|
-
|
|
7090
|
-
const isUNCPath =
|
|
7091
|
-
const isPathAbsolute = isAbsolute2(
|
|
7092
|
-
const trailingSeparator =
|
|
7093
|
-
|
|
7094
|
-
if (
|
|
7099
|
+
path6 = normalizeWindowsPath3(path6);
|
|
7100
|
+
const isUNCPath = path6.match(_UNC_REGEX3);
|
|
7101
|
+
const isPathAbsolute = isAbsolute2(path6);
|
|
7102
|
+
const trailingSeparator = path6[path6.length - 1] === "/";
|
|
7103
|
+
path6 = normalizeString3(path6, !isPathAbsolute);
|
|
7104
|
+
if (path6.length === 0) {
|
|
7095
7105
|
if (isPathAbsolute) {
|
|
7096
7106
|
return "/";
|
|
7097
7107
|
}
|
|
7098
7108
|
return trailingSeparator ? "./" : ".";
|
|
7099
7109
|
}
|
|
7100
7110
|
if (trailingSeparator) {
|
|
7101
|
-
|
|
7111
|
+
path6 += "/";
|
|
7102
7112
|
}
|
|
7103
|
-
if (_DRIVE_LETTER_RE3.test(
|
|
7104
|
-
|
|
7113
|
+
if (_DRIVE_LETTER_RE3.test(path6)) {
|
|
7114
|
+
path6 += "/";
|
|
7105
7115
|
}
|
|
7106
7116
|
if (isUNCPath) {
|
|
7107
7117
|
if (!isPathAbsolute) {
|
|
7108
|
-
return `//./${
|
|
7118
|
+
return `//./${path6}`;
|
|
7109
7119
|
}
|
|
7110
|
-
return `//${
|
|
7120
|
+
return `//${path6}`;
|
|
7111
7121
|
}
|
|
7112
|
-
return isPathAbsolute && !isAbsolute2(
|
|
7122
|
+
return isPathAbsolute && !isAbsolute2(path6) ? `/${path6}` : path6;
|
|
7113
7123
|
}, "correctPaths");
|
|
7114
7124
|
function cwd() {
|
|
7115
7125
|
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
@@ -7119,15 +7129,15 @@ function cwd() {
|
|
|
7119
7129
|
}
|
|
7120
7130
|
__name(cwd, "cwd");
|
|
7121
7131
|
__name2(cwd, "cwd");
|
|
7122
|
-
function normalizeString3(
|
|
7132
|
+
function normalizeString3(path6, allowAboveRoot) {
|
|
7123
7133
|
let res = "";
|
|
7124
7134
|
let lastSegmentLength = 0;
|
|
7125
7135
|
let lastSlash = -1;
|
|
7126
7136
|
let dots = 0;
|
|
7127
7137
|
let char = null;
|
|
7128
|
-
for (let index = 0; index <=
|
|
7129
|
-
if (index <
|
|
7130
|
-
char =
|
|
7138
|
+
for (let index = 0; index <= path6.length; ++index) {
|
|
7139
|
+
if (index < path6.length) {
|
|
7140
|
+
char = path6[index];
|
|
7131
7141
|
} else if (char === "/") {
|
|
7132
7142
|
break;
|
|
7133
7143
|
} else {
|
|
@@ -7163,9 +7173,9 @@ function normalizeString3(path5, allowAboveRoot) {
|
|
|
7163
7173
|
}
|
|
7164
7174
|
} else {
|
|
7165
7175
|
if (res.length > 0) {
|
|
7166
|
-
res += `/${
|
|
7176
|
+
res += `/${path6.slice(lastSlash + 1, index)}`;
|
|
7167
7177
|
} else {
|
|
7168
|
-
res =
|
|
7178
|
+
res = path6.slice(lastSlash + 1, index);
|
|
7169
7179
|
}
|
|
7170
7180
|
lastSegmentLength = index - lastSlash - 1;
|
|
7171
7181
|
}
|
|
@@ -7250,8 +7260,8 @@ __name2(findWorkspaceRoot, "findWorkspaceRoot");
|
|
|
7250
7260
|
|
|
7251
7261
|
// ../path/src/get-parent-path.ts
|
|
7252
7262
|
init_cjs_shims();
|
|
7253
|
-
var resolveParentPath = /* @__PURE__ */ __name((
|
|
7254
|
-
return resolvePaths(
|
|
7263
|
+
var resolveParentPath = /* @__PURE__ */ __name((path6) => {
|
|
7264
|
+
return resolvePaths(path6, "..");
|
|
7255
7265
|
}, "resolveParentPath");
|
|
7256
7266
|
var getParentPath = /* @__PURE__ */ __name((name, cwd2, options) => {
|
|
7257
7267
|
const ignoreCase = options?.ignoreCase ?? true;
|
|
@@ -7356,17 +7366,17 @@ function findFilePath(filePath) {
|
|
|
7356
7366
|
}), "");
|
|
7357
7367
|
}
|
|
7358
7368
|
__name(findFilePath, "findFilePath");
|
|
7359
|
-
function resolvePath(
|
|
7360
|
-
const paths = normalizeWindowsPath2(
|
|
7369
|
+
function resolvePath(path6, cwd2 = getWorkspaceRoot()) {
|
|
7370
|
+
const paths = normalizeWindowsPath2(path6).split("/");
|
|
7361
7371
|
let resolvedPath = "";
|
|
7362
7372
|
let resolvedAbsolute = false;
|
|
7363
7373
|
for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
7364
|
-
const
|
|
7365
|
-
if (!
|
|
7374
|
+
const path7 = index >= 0 ? paths[index] : cwd2;
|
|
7375
|
+
if (!path7 || path7.length === 0) {
|
|
7366
7376
|
continue;
|
|
7367
7377
|
}
|
|
7368
|
-
resolvedPath = joinPaths(
|
|
7369
|
-
resolvedAbsolute = isAbsolutePath(
|
|
7378
|
+
resolvedPath = joinPaths(path7, resolvedPath);
|
|
7379
|
+
resolvedAbsolute = isAbsolutePath(path7);
|
|
7370
7380
|
}
|
|
7371
7381
|
resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute);
|
|
7372
7382
|
if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {
|
|
@@ -7376,7 +7386,7 @@ function resolvePath(path5, cwd2 = getWorkspaceRoot()) {
|
|
|
7376
7386
|
}
|
|
7377
7387
|
__name(resolvePath, "resolvePath");
|
|
7378
7388
|
function resolvePaths(...paths) {
|
|
7379
|
-
return resolvePath(joinPaths(...paths.map((
|
|
7389
|
+
return resolvePath(joinPaths(...paths.map((path6) => normalizeWindowsPath2(path6))));
|
|
7380
7390
|
}
|
|
7381
7391
|
__name(resolvePaths, "resolvePaths");
|
|
7382
7392
|
function relativePath(from, to) {
|
|
@@ -7402,6 +7412,22 @@ function relativePath(from, to) {
|
|
|
7402
7412
|
}
|
|
7403
7413
|
__name(relativePath, "relativePath");
|
|
7404
7414
|
|
|
7415
|
+
// src/project.ts
|
|
7416
|
+
init_cjs_shims();
|
|
7417
|
+
var import_ts_morph = require("ts-morph");
|
|
7418
|
+
var compilerOptions = {
|
|
7419
|
+
target: import_ts_morph.ScriptTarget.ESNext,
|
|
7420
|
+
module: import_ts_morph.ModuleKind.ESNext,
|
|
7421
|
+
emitDecoratorMetadata: true,
|
|
7422
|
+
experimentalDecorators: true,
|
|
7423
|
+
esModuleInterop: true
|
|
7424
|
+
};
|
|
7425
|
+
var project = new import_ts_morph.Project({
|
|
7426
|
+
compilerOptions: {
|
|
7427
|
+
...compilerOptions
|
|
7428
|
+
}
|
|
7429
|
+
});
|
|
7430
|
+
|
|
7405
7431
|
// src/utils/get-prisma-internals.ts
|
|
7406
7432
|
init_cjs_shims();
|
|
7407
7433
|
|
|
@@ -7593,6 +7619,322 @@ async function getPrismaGeneratorHelper() {
|
|
|
7593
7619
|
}
|
|
7594
7620
|
__name(getPrismaGeneratorHelper, "getPrismaGeneratorHelper");
|
|
7595
7621
|
|
|
7622
|
+
// src/zod/model-helpers.ts
|
|
7623
|
+
init_cjs_shims();
|
|
7624
|
+
var import_node_path3 = __toESM(require("node:path"), 1);
|
|
7625
|
+
var import_ts_morph2 = require("ts-morph");
|
|
7626
|
+
|
|
7627
|
+
// src/zod/docs-helpers.ts
|
|
7628
|
+
init_cjs_shims();
|
|
7629
|
+
var import_parenthesis = require("parenthesis");
|
|
7630
|
+
var getJSDocs = /* @__PURE__ */ __name((docString) => {
|
|
7631
|
+
const lines = [];
|
|
7632
|
+
if (docString) {
|
|
7633
|
+
const docLines = docString.split("\n").filter((dL) => !dL.trimStart().startsWith("@zod"));
|
|
7634
|
+
if (docLines.length) {
|
|
7635
|
+
lines.push("/**");
|
|
7636
|
+
docLines.forEach((dL) => lines.push(` * ${dL}`));
|
|
7637
|
+
lines.push(" */");
|
|
7638
|
+
}
|
|
7639
|
+
}
|
|
7640
|
+
return lines;
|
|
7641
|
+
}, "getJSDocs");
|
|
7642
|
+
var getZodDocElements = /* @__PURE__ */ __name((docString) => docString.split("\n").filter((line) => line.trimStart().startsWith("@zod")).map((line) => line.trimStart().slice(4)).flatMap((line) => (
|
|
7643
|
+
// Array.from(line.matchAll(/\.([^().]+\(.*?\))/g), (m) => m.slice(1)).flat()
|
|
7644
|
+
chunk((0, import_parenthesis.parse)(line), 2).slice(0, -1).map(([each, contents]) => `${each.replace(/\)?\./, "")}${(0, import_parenthesis.stringify)(contents)})`)
|
|
7645
|
+
)), "getZodDocElements");
|
|
7646
|
+
|
|
7647
|
+
// src/zod/model-helpers.ts
|
|
7648
|
+
function checkModelHasModelRelation(model) {
|
|
7649
|
+
const { fields: modelFields } = model;
|
|
7650
|
+
for (const modelField of modelFields) {
|
|
7651
|
+
const isRelationField = checkIsModelRelationField(modelField);
|
|
7652
|
+
if (isRelationField) {
|
|
7653
|
+
return true;
|
|
7654
|
+
}
|
|
7655
|
+
}
|
|
7656
|
+
return false;
|
|
7657
|
+
}
|
|
7658
|
+
__name(checkModelHasModelRelation, "checkModelHasModelRelation");
|
|
7659
|
+
function checkModelHasManyModelRelation(model) {
|
|
7660
|
+
const { fields: modelFields } = model;
|
|
7661
|
+
for (const modelField of modelFields) {
|
|
7662
|
+
const isManyRelationField = checkIsManyModelRelationField(modelField);
|
|
7663
|
+
if (isManyRelationField) {
|
|
7664
|
+
return true;
|
|
7665
|
+
}
|
|
7666
|
+
}
|
|
7667
|
+
return false;
|
|
7668
|
+
}
|
|
7669
|
+
__name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
|
|
7670
|
+
function checkIsModelRelationField(modelField) {
|
|
7671
|
+
const { kind, relationName } = modelField;
|
|
7672
|
+
return kind === "object" && !!relationName;
|
|
7673
|
+
}
|
|
7674
|
+
__name(checkIsModelRelationField, "checkIsModelRelationField");
|
|
7675
|
+
function checkIsManyModelRelationField(modelField) {
|
|
7676
|
+
return checkIsModelRelationField(modelField) && modelField.isList;
|
|
7677
|
+
}
|
|
7678
|
+
__name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
|
|
7679
|
+
function findModelByName(models, modelName) {
|
|
7680
|
+
return models.find(({ name }) => name === modelName);
|
|
7681
|
+
}
|
|
7682
|
+
__name(findModelByName, "findModelByName");
|
|
7683
|
+
var writeArray = /* @__PURE__ */ __name((writer, array, newLine = true) => array.forEach((line) => writer.write(line).conditionalNewLine(newLine)), "writeArray");
|
|
7684
|
+
var useModelNames = /* @__PURE__ */ __name(({ modelCase, modelSuffix, relationModel }) => {
|
|
7685
|
+
const formatModelName = /* @__PURE__ */ __name((name, prefix = "") => {
|
|
7686
|
+
if (modelCase === "camelCase") {
|
|
7687
|
+
name = name.slice(0, 1).toLowerCase() + name.slice(1);
|
|
7688
|
+
}
|
|
7689
|
+
return `${prefix}${name}${modelSuffix}`;
|
|
7690
|
+
}, "formatModelName");
|
|
7691
|
+
return {
|
|
7692
|
+
modelName: /* @__PURE__ */ __name((name) => formatModelName(name, relationModel === "default" ? "_" : ""), "modelName"),
|
|
7693
|
+
relatedModelName: /* @__PURE__ */ __name((name) => formatModelName(relationModel === "default" ? name.toString() : `Related${name.toString()}`), "relatedModelName")
|
|
7694
|
+
};
|
|
7695
|
+
}, "useModelNames");
|
|
7696
|
+
var dotSlash = /* @__PURE__ */ __name((input) => {
|
|
7697
|
+
const converted = input.replace(/^\\\\\?\\/, "").replace(/\\/g, "/").replace(/\/{2,}/g, "/");
|
|
7698
|
+
if (converted.includes(`/node_modules/`)) return converted.split(`/node_modules/`).slice(-1)[0];
|
|
7699
|
+
if (converted.startsWith(`../`)) return converted;
|
|
7700
|
+
return `./${converted}`;
|
|
7701
|
+
}, "dotSlash");
|
|
7702
|
+
var chunk = /* @__PURE__ */ __name((input, size) => {
|
|
7703
|
+
return input.reduce((arr, item, idx) => {
|
|
7704
|
+
return idx % size === 0 ? [
|
|
7705
|
+
...arr,
|
|
7706
|
+
[
|
|
7707
|
+
item
|
|
7708
|
+
]
|
|
7709
|
+
] : [
|
|
7710
|
+
...arr.slice(0, -1),
|
|
7711
|
+
[
|
|
7712
|
+
...arr.slice(-1)[0],
|
|
7713
|
+
item
|
|
7714
|
+
]
|
|
7715
|
+
];
|
|
7716
|
+
}, []);
|
|
7717
|
+
}, "chunk");
|
|
7718
|
+
var needsRelatedModel = /* @__PURE__ */ __name((model, config) => model.fields.some((field) => field.kind === "object") && config.relationModel !== false, "needsRelatedModel");
|
|
7719
|
+
var writeImportsForModel = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
|
|
7720
|
+
const internals = await getPrismaInternals();
|
|
7721
|
+
const outputPath = internals.parseEnvValue(options.generator.output);
|
|
7722
|
+
const { relatedModelName } = useModelNames(config);
|
|
7723
|
+
const importList = [
|
|
7724
|
+
{
|
|
7725
|
+
kind: import_ts_morph2.StructureKind.ImportDeclaration,
|
|
7726
|
+
namespaceImport: "z",
|
|
7727
|
+
moduleSpecifier: "zod"
|
|
7728
|
+
}
|
|
7729
|
+
];
|
|
7730
|
+
if (config.imports) {
|
|
7731
|
+
importList.push({
|
|
7732
|
+
kind: import_ts_morph2.StructureKind.ImportDeclaration,
|
|
7733
|
+
namespaceImport: "imports",
|
|
7734
|
+
moduleSpecifier: dotSlash(import_node_path3.default.relative(outputPath, import_node_path3.default.resolve(import_node_path3.default.dirname(options.schemaPath), config.imports)))
|
|
7735
|
+
});
|
|
7736
|
+
}
|
|
7737
|
+
if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
|
|
7738
|
+
importList.push({
|
|
7739
|
+
kind: import_ts_morph2.StructureKind.ImportDeclaration,
|
|
7740
|
+
namedImports: [
|
|
7741
|
+
"Decimal"
|
|
7742
|
+
],
|
|
7743
|
+
moduleSpecifier: "decimal.js"
|
|
7744
|
+
});
|
|
7745
|
+
}
|
|
7746
|
+
const enumFields = model.fields.filter((f) => f.kind === "enum");
|
|
7747
|
+
const relationFields = model.fields.filter((f) => f.kind === "object");
|
|
7748
|
+
const clientPath = options.otherGenerators.find((each) => each.provider.value === "prisma-client-js").output.value;
|
|
7749
|
+
const relativePath2 = import_node_path3.default.relative(outputPath, clientPath);
|
|
7750
|
+
if (enumFields.length > 0) {
|
|
7751
|
+
importList.push({
|
|
7752
|
+
kind: import_ts_morph2.StructureKind.ImportDeclaration,
|
|
7753
|
+
isTypeOnly: enumFields.length === 0,
|
|
7754
|
+
moduleSpecifier: dotSlash(relativePath2),
|
|
7755
|
+
namedImports: enumFields.map((f) => f.type)
|
|
7756
|
+
});
|
|
7757
|
+
}
|
|
7758
|
+
if (config.relationModel !== false && relationFields.length > 0) {
|
|
7759
|
+
const filteredFields = relationFields.filter((f) => f.type !== model.name);
|
|
7760
|
+
if (filteredFields.length > 0) {
|
|
7761
|
+
importList.push({
|
|
7762
|
+
kind: import_ts_morph2.StructureKind.ImportDeclaration,
|
|
7763
|
+
moduleSpecifier: "./index",
|
|
7764
|
+
namedImports: Array.from(new Set(filteredFields.flatMap((f) => [
|
|
7765
|
+
`${f.type}`,
|
|
7766
|
+
relatedModelName(f.type)
|
|
7767
|
+
])))
|
|
7768
|
+
});
|
|
7769
|
+
}
|
|
7770
|
+
}
|
|
7771
|
+
sourceFile.addImportDeclarations(importList);
|
|
7772
|
+
}, "writeImportsForModel");
|
|
7773
|
+
var computeCustomSchema = /* @__PURE__ */ __name((docString) => {
|
|
7774
|
+
return getZodDocElements(docString).find((modifier) => modifier.startsWith("custom("))?.slice(7).slice(0, -1);
|
|
7775
|
+
}, "computeCustomSchema");
|
|
7776
|
+
var computeModifiers = /* @__PURE__ */ __name((docString) => {
|
|
7777
|
+
return getZodDocElements(docString).filter((each) => !each.startsWith("custom("));
|
|
7778
|
+
}, "computeModifiers");
|
|
7779
|
+
var getZodConstructor = /* @__PURE__ */ __name((field, getRelatedModelName = (name) => name.toString()) => {
|
|
7780
|
+
let zodType = "z.unknown()";
|
|
7781
|
+
const extraModifiers = [
|
|
7782
|
+
""
|
|
7783
|
+
];
|
|
7784
|
+
if (field.kind === "scalar") {
|
|
7785
|
+
switch (field.type) {
|
|
7786
|
+
case "String":
|
|
7787
|
+
zodType = "z.string()";
|
|
7788
|
+
break;
|
|
7789
|
+
case "Int":
|
|
7790
|
+
zodType = "z.number()";
|
|
7791
|
+
extraModifiers.push("int()");
|
|
7792
|
+
break;
|
|
7793
|
+
case "BigInt":
|
|
7794
|
+
zodType = "z.bigint()";
|
|
7795
|
+
break;
|
|
7796
|
+
case "DateTime":
|
|
7797
|
+
zodType = "z.date()";
|
|
7798
|
+
break;
|
|
7799
|
+
case "Float":
|
|
7800
|
+
zodType = "z.number()";
|
|
7801
|
+
break;
|
|
7802
|
+
case "Decimal":
|
|
7803
|
+
zodType = "z.number()";
|
|
7804
|
+
break;
|
|
7805
|
+
case "Json":
|
|
7806
|
+
zodType = "jsonSchema";
|
|
7807
|
+
break;
|
|
7808
|
+
case "Boolean":
|
|
7809
|
+
zodType = "z.boolean()";
|
|
7810
|
+
break;
|
|
7811
|
+
// TODO: Proper type for bytes fields
|
|
7812
|
+
case "Bytes":
|
|
7813
|
+
zodType = "z.unknown()";
|
|
7814
|
+
break;
|
|
7815
|
+
}
|
|
7816
|
+
} else if (field.kind === "enum") {
|
|
7817
|
+
zodType = `z.nativeEnum(${field.type})`;
|
|
7818
|
+
} else if (field.kind === "object") {
|
|
7819
|
+
zodType = getRelatedModelName(field.type);
|
|
7820
|
+
}
|
|
7821
|
+
if (field.isList) extraModifiers.push("array()");
|
|
7822
|
+
if (field.documentation) {
|
|
7823
|
+
zodType = computeCustomSchema(field.documentation) ?? zodType;
|
|
7824
|
+
extraModifiers.push(...computeModifiers(field.documentation));
|
|
7825
|
+
}
|
|
7826
|
+
if (!field.isRequired && field.type !== "Json") extraModifiers.push("nullish()");
|
|
7827
|
+
return `${zodType}${extraModifiers.join(".")}`;
|
|
7828
|
+
}, "getZodConstructor");
|
|
7829
|
+
var writeTypeSpecificSchemas = /* @__PURE__ */ __name((model, sourceFile, config) => {
|
|
7830
|
+
if (model.fields.some((f) => f.type === "Json")) {
|
|
7831
|
+
sourceFile.addStatements((writer) => {
|
|
7832
|
+
writer.newLine();
|
|
7833
|
+
writeArray(writer, [
|
|
7834
|
+
"// Helper schema for JSON fields",
|
|
7835
|
+
`type Literal = boolean | number | string${config.prismaJsonNullability ? "" : "| null"}`,
|
|
7836
|
+
"type Json = Literal | { [key: string]: Json } | Json[]",
|
|
7837
|
+
`const literalSchema = z.union([z.string(), z.number(), z.boolean()${config.prismaJsonNullability ? "" : ", z.null()"}])`,
|
|
7838
|
+
"const jsonSchema: z.ZodSchema<Json> = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)]))"
|
|
7839
|
+
]);
|
|
7840
|
+
});
|
|
7841
|
+
}
|
|
7842
|
+
if (config.useDecimalJs && model.fields.some((f) => f.type === "Decimal")) {
|
|
7843
|
+
sourceFile.addStatements((writer) => {
|
|
7844
|
+
writer.newLine();
|
|
7845
|
+
writeArray(writer, [
|
|
7846
|
+
"// Helper schema for Decimal fields",
|
|
7847
|
+
"z",
|
|
7848
|
+
".instanceof(Decimal)",
|
|
7849
|
+
".or(z.string())",
|
|
7850
|
+
".or(z.number())",
|
|
7851
|
+
".refine((value) => {",
|
|
7852
|
+
" try {",
|
|
7853
|
+
" return new Decimal(value);",
|
|
7854
|
+
" } catch (error) {",
|
|
7855
|
+
" return false;",
|
|
7856
|
+
" }",
|
|
7857
|
+
"})",
|
|
7858
|
+
".transform((value) => new Decimal(value));"
|
|
7859
|
+
]);
|
|
7860
|
+
});
|
|
7861
|
+
}
|
|
7862
|
+
}, "writeTypeSpecificSchemas");
|
|
7863
|
+
var generateSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
|
|
7864
|
+
const { modelName } = useModelNames(config);
|
|
7865
|
+
sourceFile.addVariableStatement({
|
|
7866
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
7867
|
+
isExported: true,
|
|
7868
|
+
leadingTrivia: /* @__PURE__ */ __name((writer) => writer.blankLineIfLastNot(), "leadingTrivia"),
|
|
7869
|
+
declarations: [
|
|
7870
|
+
{
|
|
7871
|
+
name: modelName(model.name),
|
|
7872
|
+
initializer(writer) {
|
|
7873
|
+
writer.write("z.object(").inlineBlock(() => {
|
|
7874
|
+
model.fields.filter((f) => f.kind !== "object").forEach((field) => {
|
|
7875
|
+
writeArray(writer, getJSDocs(field.documentation));
|
|
7876
|
+
writer.write(`${field.name}: ${getZodConstructor(field)}`).write(",").newLine();
|
|
7877
|
+
});
|
|
7878
|
+
}).write(")");
|
|
7879
|
+
}
|
|
7880
|
+
}
|
|
7881
|
+
]
|
|
7882
|
+
});
|
|
7883
|
+
}, "generateSchemaForModel");
|
|
7884
|
+
var generateRelatedSchemaForModel = /* @__PURE__ */ __name((model, sourceFile, config) => {
|
|
7885
|
+
const { modelName, relatedModelName } = useModelNames(config);
|
|
7886
|
+
const relationFields = model.fields.filter((f) => f.kind === "object");
|
|
7887
|
+
sourceFile.addInterface({
|
|
7888
|
+
name: `${model.name}`,
|
|
7889
|
+
isExported: true,
|
|
7890
|
+
extends: [
|
|
7891
|
+
`z.infer<typeof ${modelName(model.name)}>`
|
|
7892
|
+
],
|
|
7893
|
+
properties: relationFields.map((f) => ({
|
|
7894
|
+
hasQuestionToken: !f.isRequired,
|
|
7895
|
+
name: f.name,
|
|
7896
|
+
type: `${f.type}${f.isList ? "[]" : ""}${!f.isRequired ? " | null" : ""}`
|
|
7897
|
+
}))
|
|
7898
|
+
});
|
|
7899
|
+
sourceFile.addStatements((writer) => writeArray(writer, [
|
|
7900
|
+
"",
|
|
7901
|
+
"/**",
|
|
7902
|
+
` * ${relatedModelName(model.name)} contains all relations on your model in addition to the scalars`,
|
|
7903
|
+
" *",
|
|
7904
|
+
" * NOTE: Lazy required in case of potential circular dependencies within schema",
|
|
7905
|
+
" */"
|
|
7906
|
+
]));
|
|
7907
|
+
sourceFile.addVariableStatement({
|
|
7908
|
+
declarationKind: import_ts_morph2.VariableDeclarationKind.Const,
|
|
7909
|
+
isExported: true,
|
|
7910
|
+
declarations: [
|
|
7911
|
+
{
|
|
7912
|
+
name: relatedModelName(model.name),
|
|
7913
|
+
type: `z.ZodSchema<${model.name}>`,
|
|
7914
|
+
initializer(writer) {
|
|
7915
|
+
writer.write(`z.lazy(() => ${modelName(model.name)}.extend(`).inlineBlock(() => {
|
|
7916
|
+
relationFields.forEach((field) => {
|
|
7917
|
+
writeArray(writer, getJSDocs(field.documentation));
|
|
7918
|
+
writer.write(`${field.name}: ${getZodConstructor(field, relatedModelName)}`).write(",").newLine();
|
|
7919
|
+
});
|
|
7920
|
+
}).write("))");
|
|
7921
|
+
}
|
|
7922
|
+
}
|
|
7923
|
+
]
|
|
7924
|
+
});
|
|
7925
|
+
}, "generateRelatedSchemaForModel");
|
|
7926
|
+
var populateModelFile = /* @__PURE__ */ __name(async (model, sourceFile, config, options) => {
|
|
7927
|
+
await writeImportsForModel(model, sourceFile, config, options);
|
|
7928
|
+
writeTypeSpecificSchemas(model, sourceFile, config);
|
|
7929
|
+
generateSchemaForModel(model, sourceFile, config);
|
|
7930
|
+
if (needsRelatedModel(model, config)) generateRelatedSchemaForModel(model, sourceFile, config);
|
|
7931
|
+
}, "populateModelFile");
|
|
7932
|
+
var generateBarrelFile = /* @__PURE__ */ __name((models, indexFile) => {
|
|
7933
|
+
models.forEach((model) => indexFile.addExportDeclaration({
|
|
7934
|
+
moduleSpecifier: `./${lowerCaseFirst(model.name)}`
|
|
7935
|
+
}));
|
|
7936
|
+
}, "generateBarrelFile");
|
|
7937
|
+
|
|
7596
7938
|
// src/helpers.ts
|
|
7597
7939
|
var getProcedureName = /* @__PURE__ */ __name((config) => {
|
|
7598
7940
|
return config.withShield ? "shieldedProcedure" : config.withMiddleware ? "protectedProcedure" : "publicProcedure";
|
|
@@ -8010,22 +8352,24 @@ const options: RuntimeConfigOptions<Context> = {${config.withNext ? "\n transfor
|
|
|
8010
8352
|
export default options;
|
|
8011
8353
|
`;
|
|
8012
8354
|
}, "constructDefaultOptions");
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
});
|
|
8355
|
+
var constructZodModels = /* @__PURE__ */ __name(async (models, outputPath, config, options) => {
|
|
8356
|
+
const indexFile = project.createSourceFile(`${outputPath}/index.ts`, {}, {
|
|
8357
|
+
overwrite: true
|
|
8358
|
+
});
|
|
8359
|
+
generateBarrelFile(models, indexFile);
|
|
8360
|
+
indexFile.formatText({
|
|
8361
|
+
indentSize: 2
|
|
8362
|
+
});
|
|
8363
|
+
await Promise.all(models.map(async (model) => {
|
|
8364
|
+
const sourceFile = project.createSourceFile(`${outputPath}/${lowerCaseFirst(model.name)}.schema.ts`, {}, {
|
|
8365
|
+
overwrite: true
|
|
8366
|
+
});
|
|
8367
|
+
await populateModelFile(model, sourceFile, config, options);
|
|
8368
|
+
sourceFile.formatText({
|
|
8369
|
+
indentSize: 2
|
|
8370
|
+
});
|
|
8371
|
+
}));
|
|
8372
|
+
}, "constructZodModels");
|
|
8029
8373
|
|
|
8030
8374
|
// src/utils/write-file-safely.ts
|
|
8031
8375
|
init_cjs_shims();
|
|
@@ -8562,7 +8906,7 @@ var ParseOptions;
|
|
|
8562
8906
|
allowTrailingComma: false
|
|
8563
8907
|
};
|
|
8564
8908
|
})(ParseOptions || (ParseOptions = {}));
|
|
8565
|
-
function
|
|
8909
|
+
function parse2(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
8566
8910
|
let currentProperty = null;
|
|
8567
8911
|
let currentParent = [];
|
|
8568
8912
|
const previousParents = [];
|
|
@@ -8610,7 +8954,7 @@ function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
|
8610
8954
|
visit(text, visitor, options);
|
|
8611
8955
|
return currentParent[0];
|
|
8612
8956
|
}
|
|
8613
|
-
__name(
|
|
8957
|
+
__name(parse2, "parse");
|
|
8614
8958
|
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
8615
8959
|
const _scanner = createScanner(text, false);
|
|
8616
8960
|
const _jsonPath = [];
|
|
@@ -8962,7 +9306,7 @@ var SyntaxKind;
|
|
|
8962
9306
|
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
8963
9307
|
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
8964
9308
|
})(SyntaxKind || (SyntaxKind = {}));
|
|
8965
|
-
var
|
|
9309
|
+
var parse3 = parse2;
|
|
8966
9310
|
var ParseErrorCode;
|
|
8967
9311
|
(function(ParseErrorCode2) {
|
|
8968
9312
|
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
@@ -9215,7 +9559,7 @@ var isURL = /* @__PURE__ */ __name((payload) => payload instanceof URL, "isURL")
|
|
|
9215
9559
|
// ../../node_modules/.pnpm/superjson@2.2.2/node_modules/superjson/dist/pathstringifier.js
|
|
9216
9560
|
init_cjs_shims();
|
|
9217
9561
|
var escapeKey = /* @__PURE__ */ __name((key) => key.replace(/\./g, "\\."), "escapeKey");
|
|
9218
|
-
var stringifyPath = /* @__PURE__ */ __name((
|
|
9562
|
+
var stringifyPath = /* @__PURE__ */ __name((path6) => path6.map(String).map(escapeKey).join("."), "stringifyPath");
|
|
9219
9563
|
var parsePath = /* @__PURE__ */ __name((string) => {
|
|
9220
9564
|
const result = [];
|
|
9221
9565
|
let segment = "";
|
|
@@ -9478,27 +9822,27 @@ var getNthKey = /* @__PURE__ */ __name((value, n) => {
|
|
|
9478
9822
|
}
|
|
9479
9823
|
return keys.next().value;
|
|
9480
9824
|
}, "getNthKey");
|
|
9481
|
-
function validatePath(
|
|
9482
|
-
if (includes(
|
|
9825
|
+
function validatePath(path6) {
|
|
9826
|
+
if (includes(path6, "__proto__")) {
|
|
9483
9827
|
throw new Error("__proto__ is not allowed as a property");
|
|
9484
9828
|
}
|
|
9485
|
-
if (includes(
|
|
9829
|
+
if (includes(path6, "prototype")) {
|
|
9486
9830
|
throw new Error("prototype is not allowed as a property");
|
|
9487
9831
|
}
|
|
9488
|
-
if (includes(
|
|
9832
|
+
if (includes(path6, "constructor")) {
|
|
9489
9833
|
throw new Error("constructor is not allowed as a property");
|
|
9490
9834
|
}
|
|
9491
9835
|
}
|
|
9492
9836
|
__name(validatePath, "validatePath");
|
|
9493
|
-
var getDeep = /* @__PURE__ */ __name((object,
|
|
9494
|
-
validatePath(
|
|
9495
|
-
for (let i = 0; i <
|
|
9496
|
-
const key =
|
|
9837
|
+
var getDeep = /* @__PURE__ */ __name((object, path6) => {
|
|
9838
|
+
validatePath(path6);
|
|
9839
|
+
for (let i = 0; i < path6.length; i++) {
|
|
9840
|
+
const key = path6[i];
|
|
9497
9841
|
if (isSet(object)) {
|
|
9498
9842
|
object = getNthKey(object, +key);
|
|
9499
9843
|
} else if (isMap(object)) {
|
|
9500
9844
|
const row = +key;
|
|
9501
|
-
const type = +
|
|
9845
|
+
const type = +path6[++i] === 0 ? "key" : "value";
|
|
9502
9846
|
const keyOfRow = getNthKey(object, row);
|
|
9503
9847
|
switch (type) {
|
|
9504
9848
|
case "key":
|
|
@@ -9514,14 +9858,14 @@ var getDeep = /* @__PURE__ */ __name((object, path5) => {
|
|
|
9514
9858
|
}
|
|
9515
9859
|
return object;
|
|
9516
9860
|
}, "getDeep");
|
|
9517
|
-
var setDeep = /* @__PURE__ */ __name((object,
|
|
9518
|
-
validatePath(
|
|
9519
|
-
if (
|
|
9861
|
+
var setDeep = /* @__PURE__ */ __name((object, path6, mapper) => {
|
|
9862
|
+
validatePath(path6);
|
|
9863
|
+
if (path6.length === 0) {
|
|
9520
9864
|
return mapper(object);
|
|
9521
9865
|
}
|
|
9522
9866
|
let parent = object;
|
|
9523
|
-
for (let i = 0; i <
|
|
9524
|
-
const key =
|
|
9867
|
+
for (let i = 0; i < path6.length - 1; i++) {
|
|
9868
|
+
const key = path6[i];
|
|
9525
9869
|
if (isArray(parent)) {
|
|
9526
9870
|
const index = +key;
|
|
9527
9871
|
parent = parent[index];
|
|
@@ -9531,12 +9875,12 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9531
9875
|
const row = +key;
|
|
9532
9876
|
parent = getNthKey(parent, row);
|
|
9533
9877
|
} else if (isMap(parent)) {
|
|
9534
|
-
const isEnd = i ===
|
|
9878
|
+
const isEnd = i === path6.length - 2;
|
|
9535
9879
|
if (isEnd) {
|
|
9536
9880
|
break;
|
|
9537
9881
|
}
|
|
9538
9882
|
const row = +key;
|
|
9539
|
-
const type = +
|
|
9883
|
+
const type = +path6[++i] === 0 ? "key" : "value";
|
|
9540
9884
|
const keyOfRow = getNthKey(parent, row);
|
|
9541
9885
|
switch (type) {
|
|
9542
9886
|
case "key":
|
|
@@ -9548,7 +9892,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9548
9892
|
}
|
|
9549
9893
|
}
|
|
9550
9894
|
}
|
|
9551
|
-
const lastKey =
|
|
9895
|
+
const lastKey = path6[path6.length - 1];
|
|
9552
9896
|
if (isArray(parent)) {
|
|
9553
9897
|
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
9554
9898
|
} else if (isPlainObject2(parent)) {
|
|
@@ -9563,7 +9907,7 @@ var setDeep = /* @__PURE__ */ __name((object, path5, mapper) => {
|
|
|
9563
9907
|
}
|
|
9564
9908
|
}
|
|
9565
9909
|
if (isMap(parent)) {
|
|
9566
|
-
const row = +
|
|
9910
|
+
const row = +path6[path6.length - 2];
|
|
9567
9911
|
const keyToRow = getNthKey(parent, row);
|
|
9568
9912
|
const type = +lastKey === 0 ? "key" : "value";
|
|
9569
9913
|
switch (type) {
|
|
@@ -9609,15 +9953,15 @@ function traverse(tree, walker2, origin = []) {
|
|
|
9609
9953
|
}
|
|
9610
9954
|
__name(traverse, "traverse");
|
|
9611
9955
|
function applyValueAnnotations(plain, annotations, superJson) {
|
|
9612
|
-
traverse(annotations, (type,
|
|
9613
|
-
plain = setDeep(plain,
|
|
9956
|
+
traverse(annotations, (type, path6) => {
|
|
9957
|
+
plain = setDeep(plain, path6, (v) => untransformValue(v, type, superJson));
|
|
9614
9958
|
});
|
|
9615
9959
|
return plain;
|
|
9616
9960
|
}
|
|
9617
9961
|
__name(applyValueAnnotations, "applyValueAnnotations");
|
|
9618
9962
|
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
9619
|
-
function apply(identicalPaths,
|
|
9620
|
-
const object = getDeep(plain, parsePath(
|
|
9963
|
+
function apply(identicalPaths, path6) {
|
|
9964
|
+
const object = getDeep(plain, parsePath(path6));
|
|
9621
9965
|
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
9622
9966
|
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
9623
9967
|
});
|
|
@@ -9638,13 +9982,13 @@ function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
|
9638
9982
|
}
|
|
9639
9983
|
__name(applyReferentialEqualityAnnotations, "applyReferentialEqualityAnnotations");
|
|
9640
9984
|
var isDeep = /* @__PURE__ */ __name((object, superJson) => isPlainObject2(object) || isArray(object) || isMap(object) || isSet(object) || isInstanceOfRegisteredClass(object, superJson), "isDeep");
|
|
9641
|
-
function addIdentity(object,
|
|
9985
|
+
function addIdentity(object, path6, identities) {
|
|
9642
9986
|
const existingSet = identities.get(object);
|
|
9643
9987
|
if (existingSet) {
|
|
9644
|
-
existingSet.push(
|
|
9988
|
+
existingSet.push(path6);
|
|
9645
9989
|
} else {
|
|
9646
9990
|
identities.set(object, [
|
|
9647
|
-
|
|
9991
|
+
path6
|
|
9648
9992
|
]);
|
|
9649
9993
|
}
|
|
9650
9994
|
}
|
|
@@ -9657,7 +10001,7 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9657
10001
|
return;
|
|
9658
10002
|
}
|
|
9659
10003
|
if (!dedupe) {
|
|
9660
|
-
paths = paths.map((
|
|
10004
|
+
paths = paths.map((path6) => path6.map(String)).sort((a, b) => a.length - b.length);
|
|
9661
10005
|
}
|
|
9662
10006
|
const [representativePath, ...identicalPaths] = paths;
|
|
9663
10007
|
if (representativePath.length === 0) {
|
|
@@ -9682,10 +10026,10 @@ function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
|
9682
10026
|
}
|
|
9683
10027
|
}
|
|
9684
10028
|
__name(generateReferentialEqualityAnnotations, "generateReferentialEqualityAnnotations");
|
|
9685
|
-
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe,
|
|
10029
|
+
var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path6 = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
9686
10030
|
const primitive = isPrimitive(object);
|
|
9687
10031
|
if (!primitive) {
|
|
9688
|
-
addIdentity(object,
|
|
10032
|
+
addIdentity(object, path6, identities);
|
|
9689
10033
|
const seen = seenObjects.get(object);
|
|
9690
10034
|
if (seen) {
|
|
9691
10035
|
return dedupe ? {
|
|
@@ -9722,7 +10066,7 @@ var walker = /* @__PURE__ */ __name((object, identities, superJson, dedupe, path
|
|
|
9722
10066
|
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
9723
10067
|
}
|
|
9724
10068
|
const recursiveResult = walker(value, identities, superJson, dedupe, [
|
|
9725
|
-
...
|
|
10069
|
+
...path6,
|
|
9726
10070
|
index
|
|
9727
10071
|
], [
|
|
9728
10072
|
...objectsInThisPath,
|
|
@@ -9906,8 +10250,8 @@ SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJS
|
|
|
9906
10250
|
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
9907
10251
|
var serialize = SuperJSON.serialize;
|
|
9908
10252
|
var deserialize = SuperJSON.deserialize;
|
|
9909
|
-
var
|
|
9910
|
-
var
|
|
10253
|
+
var stringify2 = SuperJSON.stringify;
|
|
10254
|
+
var parse4 = SuperJSON.parse;
|
|
9911
10255
|
var registerClass = SuperJSON.registerClass;
|
|
9912
10256
|
var registerCustom = SuperJSON.registerCustom;
|
|
9913
10257
|
var registerSymbol = SuperJSON.registerSymbol;
|
|
@@ -10120,7 +10464,7 @@ var isNumber2 = /* @__PURE__ */ __name((value) => {
|
|
|
10120
10464
|
}, "isNumber");
|
|
10121
10465
|
|
|
10122
10466
|
// ../json/src/utils/stringify.ts
|
|
10123
|
-
var
|
|
10467
|
+
var stringify3 = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
10124
10468
|
const space = isNumber2(spacing) ? " ".repeat(spacing) : spacing;
|
|
10125
10469
|
switch (value) {
|
|
10126
10470
|
case null: {
|
|
@@ -10137,7 +10481,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
|
10137
10481
|
}
|
|
10138
10482
|
}
|
|
10139
10483
|
if (Array.isArray(value)) {
|
|
10140
|
-
return `[${space}${value.map((v) =>
|
|
10484
|
+
return `[${space}${value.map((v) => stringify3(v, space)).join(`,${space}`)}${space}]`;
|
|
10141
10485
|
}
|
|
10142
10486
|
if (value instanceof Uint8Array) {
|
|
10143
10487
|
return value.toString();
|
|
@@ -10151,7 +10495,7 @@ var stringify2 = /* @__PURE__ */ __name((value, spacing = 2) => {
|
|
|
10151
10495
|
}
|
|
10152
10496
|
case "object": {
|
|
10153
10497
|
const keys = Object.keys(value);
|
|
10154
|
-
return `{${space}${keys.map((k) => `${k}: ${space}${
|
|
10498
|
+
return `{${space}${keys.map((k) => `${k}: ${space}${stringify3(value[k], space)}`).join(`,${space}`)}${space}}`;
|
|
10155
10499
|
}
|
|
10156
10500
|
default:
|
|
10157
10501
|
return "null";
|
|
@@ -10207,7 +10551,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
|
|
|
10207
10551
|
if (customTransformer) {
|
|
10208
10552
|
result = customTransformer.serialize(result);
|
|
10209
10553
|
}
|
|
10210
|
-
return
|
|
10554
|
+
return stringify3(result?.json ? result?.json : result, options?.spaces);
|
|
10211
10555
|
}
|
|
10212
10556
|
/**
|
|
10213
10557
|
* Stringify the given value with superjson
|
|
@@ -10238,7 +10582,7 @@ var StormJSON = class _StormJSON extends SuperJSON {
|
|
|
10238
10582
|
allowTrailingComma: true,
|
|
10239
10583
|
...options
|
|
10240
10584
|
};
|
|
10241
|
-
const result =
|
|
10585
|
+
const result = parse3(strData, errors, opts);
|
|
10242
10586
|
if (errors.length > 0 && errors[0]) {
|
|
10243
10587
|
throw new Error(formatParseError(strData, errors[0]));
|
|
10244
10588
|
}
|
|
@@ -10302,7 +10646,7 @@ var writeFile = /* @__PURE__ */ __name(async (filePath, content, options) => {
|
|
|
10302
10646
|
}, "writeFile");
|
|
10303
10647
|
|
|
10304
10648
|
// src/utils/write-file-safely.ts
|
|
10305
|
-
var
|
|
10649
|
+
var import_node_path4 = __toESM(require("node:path"), 1);
|
|
10306
10650
|
|
|
10307
10651
|
// src/utils/format-file.ts
|
|
10308
10652
|
init_cjs_shims();
|
|
@@ -10346,13 +10690,14 @@ var writeFileSafely = /* @__PURE__ */ __name(async (writeLocation, content, addT
|
|
|
10346
10690
|
}, "writeFileSafely");
|
|
10347
10691
|
var writeIndexFile = /* @__PURE__ */ __name(async (indexPath) => {
|
|
10348
10692
|
const rows = Array.from(indexExports).map((filePath) => {
|
|
10349
|
-
let relativePath2 =
|
|
10693
|
+
let relativePath2 = import_node_path4.default.relative(import_node_path4.default.dirname(indexPath), filePath);
|
|
10350
10694
|
if (relativePath2.endsWith(".ts")) {
|
|
10351
10695
|
relativePath2 = relativePath2.slice(0, relativePath2.lastIndexOf(".ts"));
|
|
10352
10696
|
}
|
|
10353
10697
|
const normalized = correctPath(relativePath2);
|
|
10354
|
-
return `export * from './${normalized}'
|
|
10698
|
+
return `export * from './${normalized}';`;
|
|
10355
10699
|
});
|
|
10700
|
+
rows.push("export * from './models';");
|
|
10356
10701
|
await writeFileSafely(indexPath, rows.join("\n"), false);
|
|
10357
10702
|
}, "writeIndexFile");
|
|
10358
10703
|
|
|
@@ -10523,45 +10868,7 @@ init_cjs_shims();
|
|
|
10523
10868
|
|
|
10524
10869
|
// src/zod/transformer.ts
|
|
10525
10870
|
init_cjs_shims();
|
|
10526
|
-
var
|
|
10527
|
-
|
|
10528
|
-
// src/zod/model-helpers.ts
|
|
10529
|
-
init_cjs_shims();
|
|
10530
|
-
function checkModelHasModelRelation(model) {
|
|
10531
|
-
const { fields: modelFields } = model;
|
|
10532
|
-
for (const modelField of modelFields) {
|
|
10533
|
-
const isRelationField = checkIsModelRelationField(modelField);
|
|
10534
|
-
if (isRelationField) {
|
|
10535
|
-
return true;
|
|
10536
|
-
}
|
|
10537
|
-
}
|
|
10538
|
-
return false;
|
|
10539
|
-
}
|
|
10540
|
-
__name(checkModelHasModelRelation, "checkModelHasModelRelation");
|
|
10541
|
-
function checkModelHasManyModelRelation(model) {
|
|
10542
|
-
const { fields: modelFields } = model;
|
|
10543
|
-
for (const modelField of modelFields) {
|
|
10544
|
-
const isManyRelationField = checkIsManyModelRelationField(modelField);
|
|
10545
|
-
if (isManyRelationField) {
|
|
10546
|
-
return true;
|
|
10547
|
-
}
|
|
10548
|
-
}
|
|
10549
|
-
return false;
|
|
10550
|
-
}
|
|
10551
|
-
__name(checkModelHasManyModelRelation, "checkModelHasManyModelRelation");
|
|
10552
|
-
function checkIsModelRelationField(modelField) {
|
|
10553
|
-
const { kind, relationName } = modelField;
|
|
10554
|
-
return kind === "object" && !!relationName;
|
|
10555
|
-
}
|
|
10556
|
-
__name(checkIsModelRelationField, "checkIsModelRelationField");
|
|
10557
|
-
function checkIsManyModelRelationField(modelField) {
|
|
10558
|
-
return checkIsModelRelationField(modelField) && modelField.isList;
|
|
10559
|
-
}
|
|
10560
|
-
__name(checkIsManyModelRelationField, "checkIsManyModelRelationField");
|
|
10561
|
-
function findModelByName(models, modelName) {
|
|
10562
|
-
return models.find(({ name }) => name === modelName);
|
|
10563
|
-
}
|
|
10564
|
-
__name(findModelByName, "findModelByName");
|
|
10871
|
+
var import_node_path5 = __toESM(require("node:path"), 1);
|
|
10565
10872
|
|
|
10566
10873
|
// src/zod/mongodb-helpers.ts
|
|
10567
10874
|
init_cjs_shims();
|
|
@@ -10671,13 +10978,13 @@ var Transformer = class _Transformer {
|
|
|
10671
10978
|
this.isCustomPrismaClientOutputPath = prismaClientCustomPath !== "@prisma/client";
|
|
10672
10979
|
}
|
|
10673
10980
|
static async generateIndex() {
|
|
10674
|
-
const indexPath =
|
|
10981
|
+
const indexPath = import_node_path5.default.join(_Transformer.outputPath, "schemas/index.ts");
|
|
10675
10982
|
await writeIndexFile(indexPath);
|
|
10676
10983
|
}
|
|
10677
10984
|
async generateEnumSchemas() {
|
|
10678
10985
|
for (const enumType2 of this.enumTypes) {
|
|
10679
10986
|
const { name, values } = enumType2;
|
|
10680
|
-
await writeFileSafely(
|
|
10987
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/enums/${lowerCaseFirst(name)}.schema.ts`), `${this.generateImportZodStatement()}
|
|
10681
10988
|
${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.stringify(values)})`)}`);
|
|
10682
10989
|
}
|
|
10683
10990
|
}
|
|
@@ -10691,7 +10998,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10691
10998
|
const zodObjectSchemaFields = this.generateObjectSchemaFields();
|
|
10692
10999
|
const objectSchema = this.prepareObjectSchema(zodObjectSchemaFields);
|
|
10693
11000
|
const objectSchemaName = this.resolveObjectSchemaName();
|
|
10694
|
-
await writeFileSafely(
|
|
11001
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/objects/${lowerCaseFirst(objectSchemaName)}.schema.ts`), objectSchema);
|
|
10695
11002
|
}
|
|
10696
11003
|
generateObjectSchemaFields() {
|
|
10697
11004
|
const zodObjectSchemaFields = this.fields.map((field) => this.generateObjectSchemaField(field)).flatMap((item) => item).map((item) => {
|
|
@@ -10826,9 +11133,9 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10826
11133
|
generateImportPrismaStatement() {
|
|
10827
11134
|
let prismaClientImportPath;
|
|
10828
11135
|
if (_Transformer.isCustomPrismaClientOutputPath) {
|
|
10829
|
-
const fromPath =
|
|
11136
|
+
const fromPath = import_node_path5.default.join(_Transformer.outputPath, "schemas", "objects");
|
|
10830
11137
|
const toPath = _Transformer.prismaClientOutputPath;
|
|
10831
|
-
const relativePathFromOutputToPrismaClient =
|
|
11138
|
+
const relativePathFromOutputToPrismaClient = import_node_path5.default.relative(fromPath, toPath).split(import_node_path5.default.sep).join(import_node_path5.default.posix.sep);
|
|
10832
11139
|
prismaClientImportPath = relativePathFromOutputToPrismaClient;
|
|
10833
11140
|
} else {
|
|
10834
11141
|
prismaClientImportPath = _Transformer.prismaClientOutputPath;
|
|
@@ -10958,7 +11265,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10958
11265
|
includeImport,
|
|
10959
11266
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
10960
11267
|
];
|
|
10961
|
-
await writeFileSafely(
|
|
11268
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${findUnique}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindUnique`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
10962
11269
|
}
|
|
10963
11270
|
if (findFirst) {
|
|
10964
11271
|
const imports = [
|
|
@@ -10969,7 +11276,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10969
11276
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10970
11277
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10971
11278
|
];
|
|
10972
|
-
await writeFileSafely(
|
|
11279
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${findFirst}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindFirst`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
|
|
10973
11280
|
}
|
|
10974
11281
|
if (findMany) {
|
|
10975
11282
|
const imports = [
|
|
@@ -10980,7 +11287,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10980
11287
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`,
|
|
10981
11288
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
10982
11289
|
];
|
|
10983
|
-
await writeFileSafely(
|
|
11290
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${findMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}FindMany`, `z.object({ ${selectZodSchemaLineLazy} ${includeZodSchemaLineLazy} ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), distinct: z.array(${modelName}ScalarFieldEnumSchema).optional() })`)}`);
|
|
10984
11291
|
}
|
|
10985
11292
|
if (createOne) {
|
|
10986
11293
|
const imports = [
|
|
@@ -10989,19 +11296,19 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
10989
11296
|
`import { ${modelName}CreateInputObjectSchema } from './objects/${modelName}CreateInput.schema'`,
|
|
10990
11297
|
`import { ${modelName}UncheckedCreateInputObjectSchema } from './objects/${modelName}UncheckedCreateInput.schema'`
|
|
10991
11298
|
];
|
|
10992
|
-
await writeFileSafely(
|
|
11299
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${createOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema]) })`)}`);
|
|
10993
11300
|
}
|
|
10994
11301
|
if (createMany) {
|
|
10995
11302
|
const imports = [
|
|
10996
11303
|
`import { ${modelName}CreateManyInputObjectSchema } from './objects/${modelName}CreateManyInput.schema'`
|
|
10997
11304
|
];
|
|
10998
|
-
await writeFileSafely(
|
|
11305
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${createMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateMany`, `z.object({ data: z.union([ ${modelName}CreateManyInputObjectSchema, z.array(${modelName}CreateManyInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
10999
11306
|
}
|
|
11000
11307
|
if (createManyAndReturn) {
|
|
11001
11308
|
const imports = [
|
|
11002
11309
|
`import { ${modelName}CreateManyAndReturnInputObjectSchema } from './objects/${modelName}CreateManyAndReturnInput.schema'`
|
|
11003
11310
|
];
|
|
11004
|
-
await writeFileSafely(
|
|
11311
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${createManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}CreateManyAndReturn`, `z.object({ data: z.union([ ${modelName}CreateManyAndReturnInputObjectSchema, z.array(${modelName}CreateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
11005
11312
|
}
|
|
11006
11313
|
if (deleteOne) {
|
|
11007
11314
|
const imports = [
|
|
@@ -11009,13 +11316,13 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
11009
11316
|
includeImport,
|
|
11010
11317
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
11011
11318
|
];
|
|
11012
|
-
await writeFileSafely(
|
|
11319
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${deleteOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
11013
11320
|
}
|
|
11014
11321
|
if (deleteMany) {
|
|
11015
11322
|
const imports = [
|
|
11016
11323
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11017
11324
|
];
|
|
11018
|
-
await writeFileSafely(
|
|
11325
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${deleteMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}DeleteMany`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
11019
11326
|
}
|
|
11020
11327
|
if (updateOne) {
|
|
11021
11328
|
const imports = [
|
|
@@ -11025,20 +11332,20 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
11025
11332
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`,
|
|
11026
11333
|
`import { ${modelName}WhereUniqueInputObjectSchema } from './objects/${modelName}WhereUniqueInput.schema'`
|
|
11027
11334
|
];
|
|
11028
|
-
await writeFileSafely(
|
|
11335
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${updateOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateOne`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} data: z.union([${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema]), where: ${modelName}WhereUniqueInputObjectSchema })`)}`);
|
|
11029
11336
|
}
|
|
11030
11337
|
if (updateMany) {
|
|
11031
11338
|
const imports = [
|
|
11032
11339
|
`import { ${modelName}UpdateManyMutationInputObjectSchema } from './objects/${modelName}UpdateManyMutationInput.schema'`,
|
|
11033
11340
|
`import { ${modelName}WhereInputObjectSchema } from './objects/${modelName}WhereInput.schema'`
|
|
11034
11341
|
];
|
|
11035
|
-
await writeFileSafely(
|
|
11342
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${updateMany}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateMany`, `z.object({ data: ${modelName}UpdateManyMutationInputObjectSchema, where: ${modelName}WhereInputObjectSchema.optional() })`)}`);
|
|
11036
11343
|
}
|
|
11037
11344
|
if (updateManyAndReturn) {
|
|
11038
11345
|
const imports = [
|
|
11039
11346
|
`import { ${modelName}UpdateManyAndReturnInputObjectSchema } from './objects/${modelName}UpdateManyAndReturnInput.schema'`
|
|
11040
11347
|
];
|
|
11041
|
-
await writeFileSafely(
|
|
11348
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${updateManyAndReturn}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}UpdateManyAndReturn`, `z.object({ data: z.union([ ${modelName}UpdateManyAndReturnInputObjectSchema, z.array(${modelName}UpdateManyAndReturnInputObjectSchema) ]), ${_Transformer.provider === "mongodb" || _Transformer.provider === "sqlserver" ? "" : "skipDuplicates: z.boolean().optional()"} })`)}`);
|
|
11042
11349
|
}
|
|
11043
11350
|
if (upsertOne) {
|
|
11044
11351
|
const imports = [
|
|
@@ -11050,7 +11357,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
11050
11357
|
`import { ${modelName}UpdateInputObjectSchema } from './objects/${modelName}UpdateInput.schema'`,
|
|
11051
11358
|
`import { ${modelName}UncheckedUpdateInputObjectSchema } from './objects/${modelName}UncheckedUpdateInput.schema'`
|
|
11052
11359
|
];
|
|
11053
|
-
await writeFileSafely(
|
|
11360
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${upsertOne}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Upsert`, `z.object({ ${selectZodSchemaLine} ${includeZodSchemaLine} where: ${modelName}WhereUniqueInputObjectSchema, create: z.union([ ${modelName}CreateInputObjectSchema, ${modelName}UncheckedCreateInputObjectSchema ]), update: z.union([ ${modelName}UpdateInputObjectSchema, ${modelName}UncheckedUpdateInputObjectSchema ]) })`)}`);
|
|
11054
11361
|
}
|
|
11055
11362
|
if (aggregate) {
|
|
11056
11363
|
const imports = [
|
|
@@ -11081,7 +11388,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
11081
11388
|
aggregateOperations.push(`_sum: ${modelName}SumAggregateInputObjectSchema.optional()`);
|
|
11082
11389
|
}
|
|
11083
11390
|
}
|
|
11084
|
-
await writeFileSafely(
|
|
11391
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${aggregate}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}Aggregate`, `z.object({ ${orderByZodSchemaLine} where: ${modelName}WhereInputObjectSchema.optional(), cursor: ${modelName}WhereUniqueInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), ${aggregateOperations.join(", ")} })`)}`);
|
|
11085
11392
|
}
|
|
11086
11393
|
if (groupBy) {
|
|
11087
11394
|
const imports = [
|
|
@@ -11090,7 +11397,7 @@ ${this.generateExportSchemaStatement(`${lowerCaseFirst(name)}`, `z.enum(${JSON.s
|
|
|
11090
11397
|
`import { ${modelName}ScalarWhereWithAggregatesInputObjectSchema } from './objects/${modelName}ScalarWhereWithAggregatesInput.schema'`,
|
|
11091
11398
|
`import { ${modelName}ScalarFieldEnumSchema } from './enums/${modelName}ScalarFieldEnum.schema'`
|
|
11092
11399
|
];
|
|
11093
|
-
await writeFileSafely(
|
|
11400
|
+
await writeFileSafely(import_node_path5.default.join(_Transformer.outputPath, `schemas/${groupBy}.schema.ts`), `${this.generateImportStatements(imports)}${this.generateExportSchemaStatement(`${modelName}GroupBy`, `z.object({ where: ${modelName}WhereInputObjectSchema.optional(), orderBy: z.union([${modelName}OrderByWithAggregationInputObjectSchema, ${modelName}OrderByWithAggregationInputObjectSchema.array()]).optional(), having: ${modelName}ScalarWhereWithAggregatesInputObjectSchema.optional(), take: z.number().optional(), skip: z.number().optional(), by: z.array(${modelName}ScalarFieldEnumSchema) })`)}`);
|
|
11094
11401
|
}
|
|
11095
11402
|
}
|
|
11096
11403
|
}
|
|
@@ -11571,6 +11878,7 @@ ${JSON.stringify(config)}`);
|
|
|
11571
11878
|
if (prismaClientProvider?.isCustomOutput) {
|
|
11572
11879
|
Transformer.setPrismaClientOutputPath(prismaClientProvider.output?.value);
|
|
11573
11880
|
}
|
|
11881
|
+
await constructZodModels(models, joinPaths(zodOutputPath, "models"), config, options);
|
|
11574
11882
|
resolveZodModelsComments(models, modelOperations, enumTypes, hiddenModels, hiddenFields);
|
|
11575
11883
|
await generateZodEnumSchemas(enumTypes.prisma, enumTypes.model);
|
|
11576
11884
|
const dataSource = options.datasources?.[0];
|
|
@@ -11647,12 +11955,12 @@ ${JSON.stringify(config)}`);
|
|
|
11647
11955
|
}
|
|
11648
11956
|
resolveModelsComments(models, hiddenModels);
|
|
11649
11957
|
consoleLog("Generating tRPC export file");
|
|
11650
|
-
const trpcExports = project.createSourceFile(
|
|
11958
|
+
const trpcExports = project.createSourceFile(import_node_path6.default.resolve(outputDir, "trpc.ts"), void 0, {
|
|
11651
11959
|
overwrite: true
|
|
11652
11960
|
});
|
|
11653
11961
|
await generateTRPCExports(trpcExports, config, options, outputDir);
|
|
11654
11962
|
consoleLog("Generating tRPC app router");
|
|
11655
|
-
const appRouter = project.createSourceFile(
|
|
11963
|
+
const appRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `index.ts`), void 0, {
|
|
11656
11964
|
overwrite: true
|
|
11657
11965
|
});
|
|
11658
11966
|
consoleLog("Generating tRPC router imports");
|
|
@@ -11681,7 +11989,7 @@ ${JSON.stringify(config)}`);
|
|
|
11681
11989
|
const plural = (0, import_pluralize.default)(lowerCaseFirst(model));
|
|
11682
11990
|
consoleLog(`Generating tRPC router for model ${model}`);
|
|
11683
11991
|
generateRouterImport(appRouter, plural, model);
|
|
11684
|
-
const modelRouter = project.createSourceFile(
|
|
11992
|
+
const modelRouter = project.createSourceFile(import_node_path6.default.resolve(outputDir, "routers", `${lowerCaseFirst(model)}.router.ts`), void 0, {
|
|
11685
11993
|
overwrite: true
|
|
11686
11994
|
});
|
|
11687
11995
|
generateCreateRouterImport({
|